xref: /openbmc/linux/arch/s390/boot/startup.c (revision 9f744abb)
18f75582aSVasily Gorbik // SPDX-License-Identifier: GPL-2.0
28f75582aSVasily Gorbik #include <linux/string.h>
3805bc0bcSGerald Schaefer #include <linux/elf.h>
473045a08SVasily Gorbik #include <asm/boot_data.h>
5a80313ffSGerald Schaefer #include <asm/sections.h>
6d7e7fbbaSVasily Gorbik #include <asm/cpu_mf.h>
715426ca4SVasily Gorbik #include <asm/setup.h>
80c4f2623SVasily Gorbik #include <asm/kasan.h>
9805bc0bcSGerald Schaefer #include <asm/kexec.h>
107516fc11SVasily Gorbik #include <asm/sclp.h>
11a80313ffSGerald Schaefer #include <asm/diag.h>
125abb9351SVasily Gorbik #include <asm/uv.h>
138f75582aSVasily Gorbik #include "compressed/decompressor.h"
148f75582aSVasily Gorbik #include "boot.h"
158f75582aSVasily Gorbik 
16d1b52a43SVasily Gorbik extern char __boot_data_start[], __boot_data_end[];
17bf9921a9SGerald Schaefer extern char __boot_data_preserved_start[], __boot_data_preserved_end[];
18b2d24b97SGerald Schaefer unsigned long __bootdata_preserved(__kaslr_offset);
190c4f2623SVasily Gorbik unsigned long __bootdata_preserved(VMALLOC_START);
200c4f2623SVasily Gorbik unsigned long __bootdata_preserved(VMALLOC_END);
210c4f2623SVasily Gorbik struct page *__bootdata_preserved(vmemmap);
220c4f2623SVasily Gorbik unsigned long __bootdata_preserved(vmemmap_size);
230c4f2623SVasily Gorbik unsigned long __bootdata_preserved(MODULES_VADDR);
240c4f2623SVasily Gorbik unsigned long __bootdata_preserved(MODULES_END);
2573045a08SVasily Gorbik unsigned long __bootdata(ident_map_size);
26*9f744abbSAlexander Egorenkov int __bootdata(is_full_image) = 1;
27d1b52a43SVasily Gorbik 
2817e89e13SSven Schnelle u64 __bootdata_preserved(stfle_fac_list[16]);
2917e89e13SSven Schnelle u64 __bootdata_preserved(alt_stfle_fac_list[16]);
3017e89e13SSven Schnelle 
31a80313ffSGerald Schaefer /*
32a80313ffSGerald Schaefer  * Some code and data needs to stay below 2 GB, even when the kernel would be
33a80313ffSGerald Schaefer  * relocated above 2 GB, because it has to use 31 bit addresses.
34a80313ffSGerald Schaefer  * Such code and data is part of the .dma section, and its location is passed
35a80313ffSGerald Schaefer  * over to the decompressed / relocated kernel via the .boot.preserved.data
36a80313ffSGerald Schaefer  * section.
37a80313ffSGerald Schaefer  */
38a80313ffSGerald Schaefer extern char _sdma[], _edma[];
39a80313ffSGerald Schaefer extern char _stext_dma[], _etext_dma[];
40a80313ffSGerald Schaefer extern struct exception_table_entry _start_dma_ex_table[];
41a80313ffSGerald Schaefer extern struct exception_table_entry _stop_dma_ex_table[];
42a80313ffSGerald Schaefer unsigned long __bootdata_preserved(__sdma) = __pa(&_sdma);
43a80313ffSGerald Schaefer unsigned long __bootdata_preserved(__edma) = __pa(&_edma);
44a80313ffSGerald Schaefer unsigned long __bootdata_preserved(__stext_dma) = __pa(&_stext_dma);
45a80313ffSGerald Schaefer unsigned long __bootdata_preserved(__etext_dma) = __pa(&_etext_dma);
46a80313ffSGerald Schaefer struct exception_table_entry *
47a80313ffSGerald Schaefer 	__bootdata_preserved(__start_dma_ex_table) = _start_dma_ex_table;
48a80313ffSGerald Schaefer struct exception_table_entry *
49a80313ffSGerald Schaefer 	__bootdata_preserved(__stop_dma_ex_table) = _stop_dma_ex_table;
50a80313ffSGerald Schaefer 
51a80313ffSGerald Schaefer int _diag210_dma(struct diag210 *addr);
52a80313ffSGerald Schaefer int _diag26c_dma(void *req, void *resp, enum diag26c_sc subcode);
53a80313ffSGerald Schaefer int _diag14_dma(unsigned long rx, unsigned long ry1, unsigned long subcode);
54a80313ffSGerald Schaefer void _diag0c_dma(struct hypfs_diag0c_entry *entry);
55a80313ffSGerald Schaefer void _diag308_reset_dma(void);
56a80313ffSGerald Schaefer struct diag_ops __bootdata_preserved(diag_dma_ops) = {
57a80313ffSGerald Schaefer 	.diag210 = _diag210_dma,
58a80313ffSGerald Schaefer 	.diag26c = _diag26c_dma,
59a80313ffSGerald Schaefer 	.diag14 = _diag14_dma,
60a80313ffSGerald Schaefer 	.diag0c = _diag0c_dma,
61a80313ffSGerald Schaefer 	.diag308_reset = _diag308_reset_dma
62a80313ffSGerald Schaefer };
6333def849SJoe Perches static struct diag210 _diag210_tmp_dma __section(".dma.data");
64a80313ffSGerald Schaefer struct diag210 *__bootdata_preserved(__diag210_tmp_dma) = &_diag210_tmp_dma;
65a80313ffSGerald Schaefer 
667516fc11SVasily Gorbik void error(char *x)
677516fc11SVasily Gorbik {
687516fc11SVasily Gorbik 	sclp_early_printk("\n\n");
697516fc11SVasily Gorbik 	sclp_early_printk(x);
707516fc11SVasily Gorbik 	sclp_early_printk("\n\n -- System halted");
717516fc11SVasily Gorbik 
7298587c2dSMartin Schwidefsky 	disabled_wait();
737516fc11SVasily Gorbik }
747516fc11SVasily Gorbik 
75d7e7fbbaSVasily Gorbik static void setup_lpp(void)
76d7e7fbbaSVasily Gorbik {
77d7e7fbbaSVasily Gorbik 	S390_lowcore.current_pid = 0;
78d7e7fbbaSVasily Gorbik 	S390_lowcore.lpp = LPP_MAGIC;
79d7e7fbbaSVasily Gorbik 	if (test_facility(40))
80d7e7fbbaSVasily Gorbik 		lpp(&S390_lowcore.lpp);
81d7e7fbbaSVasily Gorbik }
82d7e7fbbaSVasily Gorbik 
8315426ca4SVasily Gorbik #ifdef CONFIG_KERNEL_UNCOMPRESSED
8415426ca4SVasily Gorbik unsigned long mem_safe_offset(void)
8515426ca4SVasily Gorbik {
8615426ca4SVasily Gorbik 	return vmlinux.default_lma + vmlinux.image_size + vmlinux.bss_size;
8715426ca4SVasily Gorbik }
8815426ca4SVasily Gorbik #endif
8915426ca4SVasily Gorbik 
909641b8ccSMartin Schwidefsky static void rescue_initrd(unsigned long addr)
9115426ca4SVasily Gorbik {
9215426ca4SVasily Gorbik 	if (!IS_ENABLED(CONFIG_BLK_DEV_INITRD))
9315426ca4SVasily Gorbik 		return;
9415426ca4SVasily Gorbik 	if (!INITRD_START || !INITRD_SIZE)
9515426ca4SVasily Gorbik 		return;
969641b8ccSMartin Schwidefsky 	if (addr <= INITRD_START)
9715426ca4SVasily Gorbik 		return;
989641b8ccSMartin Schwidefsky 	memmove((void *)addr, (void *)INITRD_START, INITRD_SIZE);
999641b8ccSMartin Schwidefsky 	INITRD_START = addr;
10015426ca4SVasily Gorbik }
10115426ca4SVasily Gorbik 
102d1b52a43SVasily Gorbik static void copy_bootdata(void)
103d1b52a43SVasily Gorbik {
104d1b52a43SVasily Gorbik 	if (__boot_data_end - __boot_data_start != vmlinux.bootdata_size)
105d1b52a43SVasily Gorbik 		error(".boot.data section size mismatch");
106d1b52a43SVasily Gorbik 	memcpy((void *)vmlinux.bootdata_off, __boot_data_start, vmlinux.bootdata_size);
107bf9921a9SGerald Schaefer 	if (__boot_data_preserved_end - __boot_data_preserved_start != vmlinux.bootdata_preserved_size)
108bf9921a9SGerald Schaefer 		error(".boot.preserved.data section size mismatch");
109bf9921a9SGerald Schaefer 	memcpy((void *)vmlinux.bootdata_preserved_off, __boot_data_preserved_start, vmlinux.bootdata_preserved_size);
110d1b52a43SVasily Gorbik }
111d1b52a43SVasily Gorbik 
112805bc0bcSGerald Schaefer static void handle_relocs(unsigned long offset)
113805bc0bcSGerald Schaefer {
114805bc0bcSGerald Schaefer 	Elf64_Rela *rela_start, *rela_end, *rela;
115805bc0bcSGerald Schaefer 	int r_type, r_sym, rc;
116805bc0bcSGerald Schaefer 	Elf64_Addr loc, val;
117805bc0bcSGerald Schaefer 	Elf64_Sym *dynsym;
118805bc0bcSGerald Schaefer 
119805bc0bcSGerald Schaefer 	rela_start = (Elf64_Rela *) vmlinux.rela_dyn_start;
120805bc0bcSGerald Schaefer 	rela_end = (Elf64_Rela *) vmlinux.rela_dyn_end;
121805bc0bcSGerald Schaefer 	dynsym = (Elf64_Sym *) vmlinux.dynsym_start;
122805bc0bcSGerald Schaefer 	for (rela = rela_start; rela < rela_end; rela++) {
123805bc0bcSGerald Schaefer 		loc = rela->r_offset + offset;
124ac49303dSGerald Schaefer 		val = rela->r_addend;
125805bc0bcSGerald Schaefer 		r_sym = ELF64_R_SYM(rela->r_info);
126ac49303dSGerald Schaefer 		if (r_sym) {
127ac49303dSGerald Schaefer 			if (dynsym[r_sym].st_shndx != SHN_UNDEF)
128ac49303dSGerald Schaefer 				val += dynsym[r_sym].st_value + offset;
129ac49303dSGerald Schaefer 		} else {
130ac49303dSGerald Schaefer 			/*
131ac49303dSGerald Schaefer 			 * 0 == undefined symbol table index (STN_UNDEF),
132ac49303dSGerald Schaefer 			 * used for R_390_RELATIVE, only add KASLR offset
133ac49303dSGerald Schaefer 			 */
134ac49303dSGerald Schaefer 			val += offset;
135ac49303dSGerald Schaefer 		}
136805bc0bcSGerald Schaefer 		r_type = ELF64_R_TYPE(rela->r_info);
137805bc0bcSGerald Schaefer 		rc = arch_kexec_do_relocs(r_type, (void *) loc, val, 0);
138805bc0bcSGerald Schaefer 		if (rc)
139805bc0bcSGerald Schaefer 			error("Unknown relocation type");
140805bc0bcSGerald Schaefer 	}
141805bc0bcSGerald Schaefer }
142805bc0bcSGerald Schaefer 
143980d5f9aSAlexander Egorenkov /*
14473045a08SVasily Gorbik  * Merge information from several sources into a single ident_map_size value.
14573045a08SVasily Gorbik  * "ident_map_size" represents the upper limit of physical memory we may ever
14673045a08SVasily Gorbik  * reach. It might not be all online memory, but also include standby (offline)
14773045a08SVasily Gorbik  * memory. "ident_map_size" could be lower then actual standby or even online
14873045a08SVasily Gorbik  * memory present, due to limiting factors. We should never go above this limit.
14973045a08SVasily Gorbik  * It is the size of our identity mapping.
15073045a08SVasily Gorbik  *
15173045a08SVasily Gorbik  * Consider the following factors:
15273045a08SVasily Gorbik  * 1. max_physmem_end - end of physical memory online or standby.
15373045a08SVasily Gorbik  *    Always <= end of the last online memory block (get_mem_detect_end()).
15473045a08SVasily Gorbik  * 2. CONFIG_MAX_PHYSMEM_BITS - the maximum size of physical memory the
15573045a08SVasily Gorbik  *    kernel is able to support.
15673045a08SVasily Gorbik  * 3. "mem=" kernel command line option which limits physical memory usage.
15773045a08SVasily Gorbik  * 4. OLDMEM_BASE which is a kdump memory limit when the kernel is executed as
15873045a08SVasily Gorbik  *    crash kernel.
15973045a08SVasily Gorbik  * 5. "hsa" size which is a memory limit when the kernel is executed during
16073045a08SVasily Gorbik  *    zfcp/nvme dump.
16173045a08SVasily Gorbik  */
16273045a08SVasily Gorbik static void setup_ident_map_size(unsigned long max_physmem_end)
16373045a08SVasily Gorbik {
16473045a08SVasily Gorbik 	unsigned long hsa_size;
16573045a08SVasily Gorbik 
16673045a08SVasily Gorbik 	ident_map_size = max_physmem_end;
16773045a08SVasily Gorbik 	if (memory_limit)
16873045a08SVasily Gorbik 		ident_map_size = min(ident_map_size, memory_limit);
16973045a08SVasily Gorbik 	ident_map_size = min(ident_map_size, 1UL << MAX_PHYSMEM_BITS);
17073045a08SVasily Gorbik 
17173045a08SVasily Gorbik #ifdef CONFIG_CRASH_DUMP
17273045a08SVasily Gorbik 	if (OLDMEM_BASE) {
17373045a08SVasily Gorbik 		kaslr_enabled = 0;
17473045a08SVasily Gorbik 		ident_map_size = min(ident_map_size, OLDMEM_SIZE);
17573045a08SVasily Gorbik 	} else if (ipl_block_valid && is_ipl_block_dump()) {
17673045a08SVasily Gorbik 		kaslr_enabled = 0;
17773045a08SVasily Gorbik 		if (!sclp_early_get_hsa_size(&hsa_size) && hsa_size)
17873045a08SVasily Gorbik 			ident_map_size = min(ident_map_size, hsa_size);
17973045a08SVasily Gorbik 	}
18073045a08SVasily Gorbik #endif
18173045a08SVasily Gorbik }
18273045a08SVasily Gorbik 
1830c4f2623SVasily Gorbik static void setup_kernel_memory_layout(void)
1840c4f2623SVasily Gorbik {
1850c4f2623SVasily Gorbik 	bool vmalloc_size_verified = false;
1860c4f2623SVasily Gorbik 	unsigned long vmemmap_off;
1870c4f2623SVasily Gorbik 	unsigned long vspace_left;
1880c4f2623SVasily Gorbik 	unsigned long rte_size;
1890c4f2623SVasily Gorbik 	unsigned long pages;
1900c4f2623SVasily Gorbik 	unsigned long vmax;
1910c4f2623SVasily Gorbik 
1920c4f2623SVasily Gorbik 	pages = ident_map_size / PAGE_SIZE;
1930c4f2623SVasily Gorbik 	/* vmemmap contains a multiple of PAGES_PER_SECTION struct pages */
1940c4f2623SVasily Gorbik 	vmemmap_size = SECTION_ALIGN_UP(pages) * sizeof(struct page);
1950c4f2623SVasily Gorbik 
1960c4f2623SVasily Gorbik 	/* choose kernel address space layout: 4 or 3 levels. */
1970c4f2623SVasily Gorbik 	vmemmap_off = round_up(ident_map_size, _REGION3_SIZE);
1980c4f2623SVasily Gorbik 	if (IS_ENABLED(CONFIG_KASAN) ||
1990c4f2623SVasily Gorbik 	    vmalloc_size > _REGION2_SIZE ||
2000c4f2623SVasily Gorbik 	    vmemmap_off + vmemmap_size + vmalloc_size + MODULES_LEN > _REGION2_SIZE)
2010c4f2623SVasily Gorbik 		vmax = _REGION1_SIZE;
2020c4f2623SVasily Gorbik 	else
2030c4f2623SVasily Gorbik 		vmax = _REGION2_SIZE;
2040c4f2623SVasily Gorbik 
2050c4f2623SVasily Gorbik 	/* keep vmemmap_off aligned to a top level region table entry */
2060c4f2623SVasily Gorbik 	rte_size = vmax == _REGION1_SIZE ? _REGION2_SIZE : _REGION3_SIZE;
2070c4f2623SVasily Gorbik 	MODULES_END = vmax;
2080c4f2623SVasily Gorbik 	if (is_prot_virt_host()) {
2090c4f2623SVasily Gorbik 		/*
2100c4f2623SVasily Gorbik 		 * forcing modules and vmalloc area under the ultravisor
2110c4f2623SVasily Gorbik 		 * secure storage limit, so that any vmalloc allocation
2120c4f2623SVasily Gorbik 		 * we do could be used to back secure guest storage.
2130c4f2623SVasily Gorbik 		 */
2140c4f2623SVasily Gorbik 		adjust_to_uv_max(&MODULES_END);
2150c4f2623SVasily Gorbik 	}
2160c4f2623SVasily Gorbik 
2170c4f2623SVasily Gorbik #ifdef CONFIG_KASAN
2180c4f2623SVasily Gorbik 	if (MODULES_END < vmax) {
2190c4f2623SVasily Gorbik 		/* force vmalloc and modules below kasan shadow */
2200c4f2623SVasily Gorbik 		MODULES_END = min(MODULES_END, KASAN_SHADOW_START);
2210c4f2623SVasily Gorbik 	} else {
2220c4f2623SVasily Gorbik 		/*
2230c4f2623SVasily Gorbik 		 * leave vmalloc and modules above kasan shadow but make
2240c4f2623SVasily Gorbik 		 * sure they don't overlap with it
2250c4f2623SVasily Gorbik 		 */
2260c4f2623SVasily Gorbik 		vmalloc_size = min(vmalloc_size, vmax - KASAN_SHADOW_END - MODULES_LEN);
2270c4f2623SVasily Gorbik 		vmalloc_size_verified = true;
2280c4f2623SVasily Gorbik 		vspace_left = KASAN_SHADOW_START;
2290c4f2623SVasily Gorbik 	}
2300c4f2623SVasily Gorbik #endif
2310c4f2623SVasily Gorbik 	MODULES_VADDR = MODULES_END - MODULES_LEN;
2320c4f2623SVasily Gorbik 	VMALLOC_END = MODULES_VADDR;
2330c4f2623SVasily Gorbik 
2340c4f2623SVasily Gorbik 	if (vmalloc_size_verified) {
2350c4f2623SVasily Gorbik 		VMALLOC_START = VMALLOC_END - vmalloc_size;
2360c4f2623SVasily Gorbik 	} else {
2370c4f2623SVasily Gorbik 		vmemmap_off = round_up(ident_map_size, rte_size);
2380c4f2623SVasily Gorbik 
2390c4f2623SVasily Gorbik 		if (vmemmap_off + vmemmap_size > VMALLOC_END ||
2400c4f2623SVasily Gorbik 		    vmalloc_size > VMALLOC_END - vmemmap_off - vmemmap_size) {
2410c4f2623SVasily Gorbik 			/*
2420c4f2623SVasily Gorbik 			 * allow vmalloc area to occupy up to 1/2 of
2430c4f2623SVasily Gorbik 			 * the rest virtual space left.
2440c4f2623SVasily Gorbik 			 */
2450c4f2623SVasily Gorbik 			vmalloc_size = min(vmalloc_size, VMALLOC_END / 2);
2460c4f2623SVasily Gorbik 		}
2470c4f2623SVasily Gorbik 		VMALLOC_START = VMALLOC_END - vmalloc_size;
2480c4f2623SVasily Gorbik 		vspace_left = VMALLOC_START;
2490c4f2623SVasily Gorbik 	}
2500c4f2623SVasily Gorbik 
2510c4f2623SVasily Gorbik 	pages = vspace_left / (PAGE_SIZE + sizeof(struct page));
2520c4f2623SVasily Gorbik 	pages = SECTION_ALIGN_UP(pages);
2530c4f2623SVasily Gorbik 	vmemmap_off = round_up(vspace_left - pages * sizeof(struct page), rte_size);
2540c4f2623SVasily Gorbik 	/* keep vmemmap left most starting from a fresh region table entry */
2550c4f2623SVasily Gorbik 	vmemmap_off = min(vmemmap_off, round_up(ident_map_size, rte_size));
2560c4f2623SVasily Gorbik 	/* take care that identity map is lower then vmemmap */
2570c4f2623SVasily Gorbik 	ident_map_size = min(ident_map_size, vmemmap_off);
2580c4f2623SVasily Gorbik 	vmemmap_size = SECTION_ALIGN_UP(ident_map_size / PAGE_SIZE) * sizeof(struct page);
2590c4f2623SVasily Gorbik 	VMALLOC_START = max(vmemmap_off + vmemmap_size, VMALLOC_START);
2600c4f2623SVasily Gorbik 	vmemmap = (struct page *)vmemmap_off;
2610c4f2623SVasily Gorbik }
2620c4f2623SVasily Gorbik 
26373045a08SVasily Gorbik /*
264980d5f9aSAlexander Egorenkov  * This function clears the BSS section of the decompressed Linux kernel and NOT the decompressor's.
265980d5f9aSAlexander Egorenkov  */
2662e83e0ebSVasily Gorbik static void clear_bss_section(void)
2672e83e0ebSVasily Gorbik {
2682e83e0ebSVasily Gorbik 	memset((void *)vmlinux.default_lma + vmlinux.image_size, 0, vmlinux.bss_size);
2692e83e0ebSVasily Gorbik }
2702e83e0ebSVasily Gorbik 
27190178c19SHeiko Carstens /*
27290178c19SHeiko Carstens  * Set vmalloc area size to an 8th of (potential) physical memory
27390178c19SHeiko Carstens  * size, unless size has been set by kernel command line parameter.
27490178c19SHeiko Carstens  */
27590178c19SHeiko Carstens static void setup_vmalloc_size(void)
27690178c19SHeiko Carstens {
27790178c19SHeiko Carstens 	unsigned long size;
27890178c19SHeiko Carstens 
27990178c19SHeiko Carstens 	if (vmalloc_size_set)
28090178c19SHeiko Carstens 		return;
28173045a08SVasily Gorbik 	size = round_up(ident_map_size / 8, _SEGMENT_SIZE);
28290178c19SHeiko Carstens 	vmalloc_size = max(size, vmalloc_size);
28390178c19SHeiko Carstens }
28490178c19SHeiko Carstens 
2858f75582aSVasily Gorbik void startup_kernel(void)
2868f75582aSVasily Gorbik {
287b2d24b97SGerald Schaefer 	unsigned long random_lma;
2889641b8ccSMartin Schwidefsky 	unsigned long safe_addr;
289369f91c3SVasily Gorbik 	void *img;
2908f75582aSVasily Gorbik 
291d7e7fbbaSVasily Gorbik 	setup_lpp();
29249698745SVasily Gorbik 	store_ipl_parmblock();
2939641b8ccSMartin Schwidefsky 	safe_addr = mem_safe_offset();
2949641b8ccSMartin Schwidefsky 	safe_addr = read_ipl_report(safe_addr);
2959641b8ccSMartin Schwidefsky 	uv_query_info();
2969641b8ccSMartin Schwidefsky 	rescue_initrd(safe_addr);
2979641b8ccSMartin Schwidefsky 	sclp_early_read_info();
29849698745SVasily Gorbik 	setup_boot_command_line();
299b5e80459SVasily Gorbik 	parse_boot_command_line();
30073045a08SVasily Gorbik 	setup_ident_map_size(detect_memory());
30190178c19SHeiko Carstens 	setup_vmalloc_size();
3020c4f2623SVasily Gorbik 	setup_kernel_memory_layout();
303b2d24b97SGerald Schaefer 
304b2d24b97SGerald Schaefer 	random_lma = __kaslr_offset = 0;
305b2d24b97SGerald Schaefer 	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_enabled) {
306b2d24b97SGerald Schaefer 		random_lma = get_random_base(safe_addr);
307b2d24b97SGerald Schaefer 		if (random_lma) {
308b2d24b97SGerald Schaefer 			__kaslr_offset = random_lma - vmlinux.default_lma;
309b2d24b97SGerald Schaefer 			img = (void *)vmlinux.default_lma;
310b2d24b97SGerald Schaefer 			vmlinux.default_lma += __kaslr_offset;
311b2d24b97SGerald Schaefer 			vmlinux.entry += __kaslr_offset;
312b2d24b97SGerald Schaefer 			vmlinux.bootdata_off += __kaslr_offset;
313b2d24b97SGerald Schaefer 			vmlinux.bootdata_preserved_off += __kaslr_offset;
314b2d24b97SGerald Schaefer 			vmlinux.rela_dyn_start += __kaslr_offset;
315b2d24b97SGerald Schaefer 			vmlinux.rela_dyn_end += __kaslr_offset;
316b2d24b97SGerald Schaefer 			vmlinux.dynsym_start += __kaslr_offset;
317b2d24b97SGerald Schaefer 		}
318b2d24b97SGerald Schaefer 	}
319b2d24b97SGerald Schaefer 
3208f75582aSVasily Gorbik 	if (!IS_ENABLED(CONFIG_KERNEL_UNCOMPRESSED)) {
321369f91c3SVasily Gorbik 		img = decompress_kernel();
322369f91c3SVasily Gorbik 		memmove((void *)vmlinux.default_lma, img, vmlinux.image_size);
323b2d24b97SGerald Schaefer 	} else if (__kaslr_offset)
324b2d24b97SGerald Schaefer 		memcpy((void *)vmlinux.default_lma, img, vmlinux.image_size);
325b2d24b97SGerald Schaefer 
3262e83e0ebSVasily Gorbik 	clear_bss_section();
327d1b52a43SVasily Gorbik 	copy_bootdata();
328805bc0bcSGerald Schaefer 	if (IS_ENABLED(CONFIG_RELOCATABLE))
329b2d24b97SGerald Schaefer 		handle_relocs(__kaslr_offset);
330b2d24b97SGerald Schaefer 
331b2d24b97SGerald Schaefer 	if (__kaslr_offset) {
332a9f2f686SGerald Schaefer 		/*
333a9f2f686SGerald Schaefer 		 * Save KASLR offset for early dumps, before vmcore_info is set.
334a9f2f686SGerald Schaefer 		 * Mark as uneven to distinguish from real vmcore_info pointer.
335a9f2f686SGerald Schaefer 		 */
336a9f2f686SGerald Schaefer 		S390_lowcore.vmcore_info = __kaslr_offset | 0x1UL;
337b2d24b97SGerald Schaefer 		/* Clear non-relocated kernel */
338b2d24b97SGerald Schaefer 		if (IS_ENABLED(CONFIG_KERNEL_UNCOMPRESSED))
339b2d24b97SGerald Schaefer 			memset(img, 0, vmlinux.image_size);
340b2d24b97SGerald Schaefer 	}
341369f91c3SVasily Gorbik 	vmlinux.entry();
3428f75582aSVasily Gorbik }
343