xref: /openbmc/linux/arch/s390/boot/startup.c (revision bb1520d5)
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>
134df29d2bSAlexander Gordeev #include <asm/abs_lowcore.h>
14*bb1520d5SAlexander Gordeev #include <asm/mem_detect.h>
15edd4a866SHeiko Carstens #include "decompressor.h"
168f75582aSVasily Gorbik #include "boot.h"
17c5cf5054SAlexander Egorenkov #include "uv.h"
188f75582aSVasily Gorbik 
19b2d24b97SGerald Schaefer unsigned long __bootdata_preserved(__kaslr_offset);
204df29d2bSAlexander Gordeev unsigned long __bootdata_preserved(__abs_lowcore);
212f0e8aaeSAlexander Gordeev unsigned long __bootdata_preserved(__memcpy_real_area);
22e3ec8e0fSAlexander Gordeev unsigned long __bootdata(__amode31_base);
230c4f2623SVasily Gorbik unsigned long __bootdata_preserved(VMALLOC_START);
240c4f2623SVasily Gorbik unsigned long __bootdata_preserved(VMALLOC_END);
250c4f2623SVasily Gorbik struct page *__bootdata_preserved(vmemmap);
260c4f2623SVasily Gorbik unsigned long __bootdata_preserved(vmemmap_size);
270c4f2623SVasily Gorbik unsigned long __bootdata_preserved(MODULES_VADDR);
280c4f2623SVasily Gorbik unsigned long __bootdata_preserved(MODULES_END);
2973045a08SVasily Gorbik unsigned long __bootdata(ident_map_size);
309f744abbSAlexander Egorenkov int __bootdata(is_full_image) = 1;
3184733284SAlexander Egorenkov struct initrd_data __bootdata(initrd_data);
32d1b52a43SVasily Gorbik 
3317e89e13SSven Schnelle u64 __bootdata_preserved(stfle_fac_list[16]);
3417e89e13SSven Schnelle u64 __bootdata_preserved(alt_stfle_fac_list[16]);
35e9e7870fSAlexander Egorenkov struct oldmem_data __bootdata_preserved(oldmem_data);
3617e89e13SSven Schnelle 
37bd50b743SAlexander Gordeev struct machine_info machine;
38bd50b743SAlexander Gordeev 
397516fc11SVasily Gorbik void error(char *x)
407516fc11SVasily Gorbik {
417516fc11SVasily Gorbik 	sclp_early_printk("\n\n");
427516fc11SVasily Gorbik 	sclp_early_printk(x);
437516fc11SVasily Gorbik 	sclp_early_printk("\n\n -- System halted");
447516fc11SVasily Gorbik 
4598587c2dSMartin Schwidefsky 	disabled_wait();
467516fc11SVasily Gorbik }
477516fc11SVasily Gorbik 
48bd50b743SAlexander Gordeev static void detect_facilities(void)
49bd50b743SAlexander Gordeev {
50bd50b743SAlexander Gordeev 	if (test_facility(8)) {
51bd50b743SAlexander Gordeev 		machine.has_edat1 = 1;
52bd50b743SAlexander Gordeev 		__ctl_set_bit(0, 23);
53bd50b743SAlexander Gordeev 	}
54bd50b743SAlexander Gordeev 	if (test_facility(78))
55bd50b743SAlexander Gordeev 		machine.has_edat2 = 1;
56bd50b743SAlexander Gordeev 	if (!noexec_disabled && test_facility(130)) {
57bd50b743SAlexander Gordeev 		machine.has_nx = 1;
58bd50b743SAlexander Gordeev 		__ctl_set_bit(0, 20);
59bd50b743SAlexander Gordeev 	}
60bd50b743SAlexander Gordeev }
61bd50b743SAlexander Gordeev 
62d7e7fbbaSVasily Gorbik static void setup_lpp(void)
63d7e7fbbaSVasily Gorbik {
64d7e7fbbaSVasily Gorbik 	S390_lowcore.current_pid = 0;
65d7e7fbbaSVasily Gorbik 	S390_lowcore.lpp = LPP_MAGIC;
66d7e7fbbaSVasily Gorbik 	if (test_facility(40))
67d7e7fbbaSVasily Gorbik 		lpp(&S390_lowcore.lpp);
68d7e7fbbaSVasily Gorbik }
69d7e7fbbaSVasily Gorbik 
7015426ca4SVasily Gorbik #ifdef CONFIG_KERNEL_UNCOMPRESSED
7115426ca4SVasily Gorbik unsigned long mem_safe_offset(void)
7215426ca4SVasily Gorbik {
7315426ca4SVasily Gorbik 	return vmlinux.default_lma + vmlinux.image_size + vmlinux.bss_size;
7415426ca4SVasily Gorbik }
7515426ca4SVasily Gorbik #endif
7615426ca4SVasily Gorbik 
779641b8ccSMartin Schwidefsky static void rescue_initrd(unsigned long addr)
7815426ca4SVasily Gorbik {
7915426ca4SVasily Gorbik 	if (!IS_ENABLED(CONFIG_BLK_DEV_INITRD))
8015426ca4SVasily Gorbik 		return;
8184733284SAlexander Egorenkov 	if (!initrd_data.start || !initrd_data.size)
8215426ca4SVasily Gorbik 		return;
8384733284SAlexander Egorenkov 	if (addr <= initrd_data.start)
8415426ca4SVasily Gorbik 		return;
8584733284SAlexander Egorenkov 	memmove((void *)addr, (void *)initrd_data.start, initrd_data.size);
8684733284SAlexander Egorenkov 	initrd_data.start = addr;
8715426ca4SVasily Gorbik }
8815426ca4SVasily Gorbik 
89d1b52a43SVasily Gorbik static void copy_bootdata(void)
90d1b52a43SVasily Gorbik {
91d1b52a43SVasily Gorbik 	if (__boot_data_end - __boot_data_start != vmlinux.bootdata_size)
92d1b52a43SVasily Gorbik 		error(".boot.data section size mismatch");
93d1b52a43SVasily Gorbik 	memcpy((void *)vmlinux.bootdata_off, __boot_data_start, vmlinux.bootdata_size);
94bf9921a9SGerald Schaefer 	if (__boot_data_preserved_end - __boot_data_preserved_start != vmlinux.bootdata_preserved_size)
95bf9921a9SGerald Schaefer 		error(".boot.preserved.data section size mismatch");
96bf9921a9SGerald Schaefer 	memcpy((void *)vmlinux.bootdata_preserved_off, __boot_data_preserved_start, vmlinux.bootdata_preserved_size);
97d1b52a43SVasily Gorbik }
98d1b52a43SVasily Gorbik 
99805bc0bcSGerald Schaefer static void handle_relocs(unsigned long offset)
100805bc0bcSGerald Schaefer {
101805bc0bcSGerald Schaefer 	Elf64_Rela *rela_start, *rela_end, *rela;
102805bc0bcSGerald Schaefer 	int r_type, r_sym, rc;
103805bc0bcSGerald Schaefer 	Elf64_Addr loc, val;
104805bc0bcSGerald Schaefer 	Elf64_Sym *dynsym;
105805bc0bcSGerald Schaefer 
106805bc0bcSGerald Schaefer 	rela_start = (Elf64_Rela *) vmlinux.rela_dyn_start;
107805bc0bcSGerald Schaefer 	rela_end = (Elf64_Rela *) vmlinux.rela_dyn_end;
108805bc0bcSGerald Schaefer 	dynsym = (Elf64_Sym *) vmlinux.dynsym_start;
109805bc0bcSGerald Schaefer 	for (rela = rela_start; rela < rela_end; rela++) {
110805bc0bcSGerald Schaefer 		loc = rela->r_offset + offset;
111ac49303dSGerald Schaefer 		val = rela->r_addend;
112805bc0bcSGerald Schaefer 		r_sym = ELF64_R_SYM(rela->r_info);
113ac49303dSGerald Schaefer 		if (r_sym) {
114ac49303dSGerald Schaefer 			if (dynsym[r_sym].st_shndx != SHN_UNDEF)
115ac49303dSGerald Schaefer 				val += dynsym[r_sym].st_value + offset;
116ac49303dSGerald Schaefer 		} else {
117ac49303dSGerald Schaefer 			/*
118ac49303dSGerald Schaefer 			 * 0 == undefined symbol table index (STN_UNDEF),
119ac49303dSGerald Schaefer 			 * used for R_390_RELATIVE, only add KASLR offset
120ac49303dSGerald Schaefer 			 */
121ac49303dSGerald Schaefer 			val += offset;
122ac49303dSGerald Schaefer 		}
123805bc0bcSGerald Schaefer 		r_type = ELF64_R_TYPE(rela->r_info);
124805bc0bcSGerald Schaefer 		rc = arch_kexec_do_relocs(r_type, (void *) loc, val, 0);
125805bc0bcSGerald Schaefer 		if (rc)
126805bc0bcSGerald Schaefer 			error("Unknown relocation type");
127805bc0bcSGerald Schaefer 	}
128805bc0bcSGerald Schaefer }
129805bc0bcSGerald Schaefer 
130980d5f9aSAlexander Egorenkov /*
13173045a08SVasily Gorbik  * Merge information from several sources into a single ident_map_size value.
13273045a08SVasily Gorbik  * "ident_map_size" represents the upper limit of physical memory we may ever
13373045a08SVasily Gorbik  * reach. It might not be all online memory, but also include standby (offline)
13473045a08SVasily Gorbik  * memory. "ident_map_size" could be lower then actual standby or even online
13573045a08SVasily Gorbik  * memory present, due to limiting factors. We should never go above this limit.
13673045a08SVasily Gorbik  * It is the size of our identity mapping.
13773045a08SVasily Gorbik  *
13873045a08SVasily Gorbik  * Consider the following factors:
13973045a08SVasily Gorbik  * 1. max_physmem_end - end of physical memory online or standby.
14073045a08SVasily Gorbik  *    Always <= end of the last online memory block (get_mem_detect_end()).
14173045a08SVasily Gorbik  * 2. CONFIG_MAX_PHYSMEM_BITS - the maximum size of physical memory the
14273045a08SVasily Gorbik  *    kernel is able to support.
14373045a08SVasily Gorbik  * 3. "mem=" kernel command line option which limits physical memory usage.
14473045a08SVasily Gorbik  * 4. OLDMEM_BASE which is a kdump memory limit when the kernel is executed as
14573045a08SVasily Gorbik  *    crash kernel.
14673045a08SVasily Gorbik  * 5. "hsa" size which is a memory limit when the kernel is executed during
14773045a08SVasily Gorbik  *    zfcp/nvme dump.
14873045a08SVasily Gorbik  */
14973045a08SVasily Gorbik static void setup_ident_map_size(unsigned long max_physmem_end)
15073045a08SVasily Gorbik {
15173045a08SVasily Gorbik 	unsigned long hsa_size;
15273045a08SVasily Gorbik 
15373045a08SVasily Gorbik 	ident_map_size = max_physmem_end;
15473045a08SVasily Gorbik 	if (memory_limit)
15573045a08SVasily Gorbik 		ident_map_size = min(ident_map_size, memory_limit);
15673045a08SVasily Gorbik 	ident_map_size = min(ident_map_size, 1UL << MAX_PHYSMEM_BITS);
15773045a08SVasily Gorbik 
15873045a08SVasily Gorbik #ifdef CONFIG_CRASH_DUMP
159e9e7870fSAlexander Egorenkov 	if (oldmem_data.start) {
16073045a08SVasily Gorbik 		kaslr_enabled = 0;
161e9e7870fSAlexander Egorenkov 		ident_map_size = min(ident_map_size, oldmem_data.size);
16273045a08SVasily Gorbik 	} else if (ipl_block_valid && is_ipl_block_dump()) {
16373045a08SVasily Gorbik 		kaslr_enabled = 0;
16473045a08SVasily Gorbik 		if (!sclp_early_get_hsa_size(&hsa_size) && hsa_size)
16573045a08SVasily Gorbik 			ident_map_size = min(ident_map_size, hsa_size);
16673045a08SVasily Gorbik 	}
16773045a08SVasily Gorbik #endif
16873045a08SVasily Gorbik }
16973045a08SVasily Gorbik 
170*bb1520d5SAlexander Gordeev static unsigned long setup_kernel_memory_layout(void)
1710c4f2623SVasily Gorbik {
1729a39abb7SVasily Gorbik 	unsigned long vmemmap_start;
173*bb1520d5SAlexander Gordeev 	unsigned long asce_limit;
1740c4f2623SVasily Gorbik 	unsigned long rte_size;
1750c4f2623SVasily Gorbik 	unsigned long pages;
17657ad19bcSAlexander Gordeev 	unsigned long vmax;
1770c4f2623SVasily Gorbik 
1780c4f2623SVasily Gorbik 	pages = ident_map_size / PAGE_SIZE;
1790c4f2623SVasily Gorbik 	/* vmemmap contains a multiple of PAGES_PER_SECTION struct pages */
1800c4f2623SVasily Gorbik 	vmemmap_size = SECTION_ALIGN_UP(pages) * sizeof(struct page);
1810c4f2623SVasily Gorbik 
1820c4f2623SVasily Gorbik 	/* choose kernel address space layout: 4 or 3 levels. */
1839a39abb7SVasily Gorbik 	vmemmap_start = round_up(ident_map_size, _REGION3_SIZE);
1840c4f2623SVasily Gorbik 	if (IS_ENABLED(CONFIG_KASAN) ||
1850c4f2623SVasily Gorbik 	    vmalloc_size > _REGION2_SIZE ||
1869a39abb7SVasily Gorbik 	    vmemmap_start + vmemmap_size + vmalloc_size + MODULES_LEN >
1879a39abb7SVasily Gorbik 		    _REGION2_SIZE) {
188*bb1520d5SAlexander Gordeev 		asce_limit = _REGION1_SIZE;
1899a39abb7SVasily Gorbik 		rte_size = _REGION2_SIZE;
1909a39abb7SVasily Gorbik 	} else {
191*bb1520d5SAlexander Gordeev 		asce_limit = _REGION2_SIZE;
1929a39abb7SVasily Gorbik 		rte_size = _REGION3_SIZE;
1939a39abb7SVasily Gorbik 	}
1940c4f2623SVasily Gorbik 	/*
1950c4f2623SVasily Gorbik 	 * forcing modules and vmalloc area under the ultravisor
1960c4f2623SVasily Gorbik 	 * secure storage limit, so that any vmalloc allocation
1970c4f2623SVasily Gorbik 	 * we do could be used to back secure guest storage.
1980c4f2623SVasily Gorbik 	 */
199*bb1520d5SAlexander Gordeev 	vmax = adjust_to_uv_max(asce_limit);
2000c4f2623SVasily Gorbik #ifdef CONFIG_KASAN
2010c4f2623SVasily Gorbik 	/* force vmalloc and modules below kasan shadow */
20257ad19bcSAlexander Gordeev 	vmax = min(vmax, KASAN_SHADOW_START);
2030c4f2623SVasily Gorbik #endif
2042f0e8aaeSAlexander Gordeev 	__memcpy_real_area = round_down(vmax - PAGE_SIZE, PAGE_SIZE);
2052f0e8aaeSAlexander Gordeev 	__abs_lowcore = round_down(__memcpy_real_area - ABS_LOWCORE_MAP_SIZE,
2062f0e8aaeSAlexander Gordeev 				   sizeof(struct lowcore));
2074df29d2bSAlexander Gordeev 	MODULES_END = round_down(__abs_lowcore, _SEGMENT_SIZE);
2080c4f2623SVasily Gorbik 	MODULES_VADDR = MODULES_END - MODULES_LEN;
2090c4f2623SVasily Gorbik 	VMALLOC_END = MODULES_VADDR;
2100c4f2623SVasily Gorbik 
2119a39abb7SVasily Gorbik 	/* allow vmalloc area to occupy up to about 1/2 of the rest virtual space left */
2129a39abb7SVasily Gorbik 	vmalloc_size = min(vmalloc_size, round_down(VMALLOC_END / 2, _REGION3_SIZE));
2130c4f2623SVasily Gorbik 	VMALLOC_START = VMALLOC_END - vmalloc_size;
2140c4f2623SVasily Gorbik 
2159a39abb7SVasily Gorbik 	/* split remaining virtual space between 1:1 mapping & vmemmap array */
2169a39abb7SVasily Gorbik 	pages = VMALLOC_START / (PAGE_SIZE + sizeof(struct page));
2170c4f2623SVasily Gorbik 	pages = SECTION_ALIGN_UP(pages);
2189a39abb7SVasily Gorbik 	/* keep vmemmap_start aligned to a top level region table entry */
2199a39abb7SVasily Gorbik 	vmemmap_start = round_down(VMALLOC_START - pages * sizeof(struct page), rte_size);
2209a39abb7SVasily Gorbik 	/* vmemmap_start is the future VMEM_MAX_PHYS, make sure it is within MAX_PHYSMEM */
2219a39abb7SVasily Gorbik 	vmemmap_start = min(vmemmap_start, 1UL << MAX_PHYSMEM_BITS);
2229a39abb7SVasily Gorbik 	/* make sure identity map doesn't overlay with vmemmap */
2239a39abb7SVasily Gorbik 	ident_map_size = min(ident_map_size, vmemmap_start);
2240c4f2623SVasily Gorbik 	vmemmap_size = SECTION_ALIGN_UP(ident_map_size / PAGE_SIZE) * sizeof(struct page);
2259a39abb7SVasily Gorbik 	/* make sure vmemmap doesn't overlay with vmalloc area */
2269a39abb7SVasily Gorbik 	VMALLOC_START = max(vmemmap_start + vmemmap_size, VMALLOC_START);
2279a39abb7SVasily Gorbik 	vmemmap = (struct page *)vmemmap_start;
228*bb1520d5SAlexander Gordeev 
229*bb1520d5SAlexander Gordeev 	return asce_limit;
2300c4f2623SVasily Gorbik }
2310c4f2623SVasily Gorbik 
23273045a08SVasily Gorbik /*
233980d5f9aSAlexander Egorenkov  * This function clears the BSS section of the decompressed Linux kernel and NOT the decompressor's.
234980d5f9aSAlexander Egorenkov  */
2352e83e0ebSVasily Gorbik static void clear_bss_section(void)
2362e83e0ebSVasily Gorbik {
2372e83e0ebSVasily Gorbik 	memset((void *)vmlinux.default_lma + vmlinux.image_size, 0, vmlinux.bss_size);
2382e83e0ebSVasily Gorbik }
2392e83e0ebSVasily Gorbik 
24090178c19SHeiko Carstens /*
24190178c19SHeiko Carstens  * Set vmalloc area size to an 8th of (potential) physical memory
24290178c19SHeiko Carstens  * size, unless size has been set by kernel command line parameter.
24390178c19SHeiko Carstens  */
24490178c19SHeiko Carstens static void setup_vmalloc_size(void)
24590178c19SHeiko Carstens {
24690178c19SHeiko Carstens 	unsigned long size;
24790178c19SHeiko Carstens 
24890178c19SHeiko Carstens 	if (vmalloc_size_set)
24990178c19SHeiko Carstens 		return;
25073045a08SVasily Gorbik 	size = round_up(ident_map_size / 8, _SEGMENT_SIZE);
25190178c19SHeiko Carstens 	vmalloc_size = max(size, vmalloc_size);
25290178c19SHeiko Carstens }
25390178c19SHeiko Carstens 
254e8f06683SAlexander Gordeev static void offset_vmlinux_info(unsigned long offset)
255e8f06683SAlexander Gordeev {
256e8f06683SAlexander Gordeev 	vmlinux.default_lma += offset;
257e8f06683SAlexander Gordeev 	*(unsigned long *)(&vmlinux.entry) += offset;
258e8f06683SAlexander Gordeev 	vmlinux.bootdata_off += offset;
259e8f06683SAlexander Gordeev 	vmlinux.bootdata_preserved_off += offset;
260e8f06683SAlexander Gordeev 	vmlinux.rela_dyn_start += offset;
261e8f06683SAlexander Gordeev 	vmlinux.rela_dyn_end += offset;
262e8f06683SAlexander Gordeev 	vmlinux.dynsym_start += offset;
263*bb1520d5SAlexander Gordeev 	vmlinux.init_mm_off += offset;
264*bb1520d5SAlexander Gordeev 	vmlinux.swapper_pg_dir_off += offset;
265*bb1520d5SAlexander Gordeev 	vmlinux.invalid_pg_dir_off += offset;
266e8f06683SAlexander Gordeev }
267e8f06683SAlexander Gordeev 
268e3ec8e0fSAlexander Gordeev static unsigned long reserve_amode31(unsigned long safe_addr)
269e3ec8e0fSAlexander Gordeev {
270e3ec8e0fSAlexander Gordeev 	__amode31_base = PAGE_ALIGN(safe_addr);
271e3ec8e0fSAlexander Gordeev 	return safe_addr + vmlinux.amode31_size;
272e3ec8e0fSAlexander Gordeev }
273e3ec8e0fSAlexander Gordeev 
2748f75582aSVasily Gorbik void startup_kernel(void)
2758f75582aSVasily Gorbik {
276b2d24b97SGerald Schaefer 	unsigned long random_lma;
2779641b8ccSMartin Schwidefsky 	unsigned long safe_addr;
278*bb1520d5SAlexander Gordeev 	unsigned long asce_limit;
279*bb1520d5SAlexander Gordeev 	unsigned long online_end;
280369f91c3SVasily Gorbik 	void *img;
281*bb1520d5SAlexander Gordeev 	psw_t psw;
2828f75582aSVasily Gorbik 
283bd50b743SAlexander Gordeev 	detect_facilities();
284bd50b743SAlexander Gordeev 
28584733284SAlexander Egorenkov 	initrd_data.start = parmarea.initrd_start;
28684733284SAlexander Egorenkov 	initrd_data.size = parmarea.initrd_size;
287e9e7870fSAlexander Egorenkov 	oldmem_data.start = parmarea.oldmem_base;
288e9e7870fSAlexander Egorenkov 	oldmem_data.size = parmarea.oldmem_size;
28984733284SAlexander Egorenkov 
290d7e7fbbaSVasily Gorbik 	setup_lpp();
29149698745SVasily Gorbik 	store_ipl_parmblock();
2929641b8ccSMartin Schwidefsky 	safe_addr = mem_safe_offset();
293e3ec8e0fSAlexander Gordeev 	safe_addr = reserve_amode31(safe_addr);
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();
30042c89439SAlexander Egorenkov 	sanitize_prot_virt_host();
30173045a08SVasily Gorbik 	setup_ident_map_size(detect_memory());
30290178c19SHeiko Carstens 	setup_vmalloc_size();
303*bb1520d5SAlexander Gordeev 	asce_limit = setup_kernel_memory_layout();
304*bb1520d5SAlexander Gordeev 	online_end = min(get_mem_detect_end(), ident_map_size);
305b2d24b97SGerald Schaefer 
306b2d24b97SGerald Schaefer 	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_enabled) {
307b2d24b97SGerald Schaefer 		random_lma = get_random_base(safe_addr);
308b2d24b97SGerald Schaefer 		if (random_lma) {
309b2d24b97SGerald Schaefer 			__kaslr_offset = random_lma - vmlinux.default_lma;
310b2d24b97SGerald Schaefer 			img = (void *)vmlinux.default_lma;
311e8f06683SAlexander Gordeev 			offset_vmlinux_info(__kaslr_offset);
312b2d24b97SGerald Schaefer 		}
313b2d24b97SGerald Schaefer 	}
314b2d24b97SGerald Schaefer 
3158f75582aSVasily Gorbik 	if (!IS_ENABLED(CONFIG_KERNEL_UNCOMPRESSED)) {
316369f91c3SVasily Gorbik 		img = decompress_kernel();
317369f91c3SVasily Gorbik 		memmove((void *)vmlinux.default_lma, img, vmlinux.image_size);
318b2d24b97SGerald Schaefer 	} else if (__kaslr_offset)
319b2d24b97SGerald Schaefer 		memcpy((void *)vmlinux.default_lma, img, vmlinux.image_size);
320b2d24b97SGerald Schaefer 
321*bb1520d5SAlexander Gordeev 	/*
322*bb1520d5SAlexander Gordeev 	 * The order of the following operations is important:
323*bb1520d5SAlexander Gordeev 	 *
324*bb1520d5SAlexander Gordeev 	 * - handle_relocs() must follow clear_bss_section() to establish static
325*bb1520d5SAlexander Gordeev 	 *   memory references to data in .bss to be used by setup_vmem()
326*bb1520d5SAlexander Gordeev 	 *   (i.e init_mm.pgd)
327*bb1520d5SAlexander Gordeev 	 *
328*bb1520d5SAlexander Gordeev 	 * - setup_vmem() must follow handle_relocs() to be able using
329*bb1520d5SAlexander Gordeev 	 *   static memory references to data in .bss (i.e init_mm.pgd)
330*bb1520d5SAlexander Gordeev 	 *
331*bb1520d5SAlexander Gordeev 	 * - copy_bootdata() must follow setup_vmem() to propagate changes to
332*bb1520d5SAlexander Gordeev 	 *   bootdata made by setup_vmem()
333*bb1520d5SAlexander Gordeev 	 */
3342e83e0ebSVasily Gorbik 	clear_bss_section();
335b2d24b97SGerald Schaefer 	handle_relocs(__kaslr_offset);
336*bb1520d5SAlexander Gordeev 	setup_vmem(online_end, asce_limit);
337*bb1520d5SAlexander Gordeev 	copy_bootdata();
338b2d24b97SGerald Schaefer 
339b2d24b97SGerald Schaefer 	if (__kaslr_offset) {
340a9f2f686SGerald Schaefer 		/*
341a9f2f686SGerald Schaefer 		 * Save KASLR offset for early dumps, before vmcore_info is set.
342a9f2f686SGerald Schaefer 		 * Mark as uneven to distinguish from real vmcore_info pointer.
343a9f2f686SGerald Schaefer 		 */
344a9f2f686SGerald Schaefer 		S390_lowcore.vmcore_info = __kaslr_offset | 0x1UL;
345b2d24b97SGerald Schaefer 		/* Clear non-relocated kernel */
346b2d24b97SGerald Schaefer 		if (IS_ENABLED(CONFIG_KERNEL_UNCOMPRESSED))
347b2d24b97SGerald Schaefer 			memset(img, 0, vmlinux.image_size);
348b2d24b97SGerald Schaefer 	}
349*bb1520d5SAlexander Gordeev 
350*bb1520d5SAlexander Gordeev 	/*
351*bb1520d5SAlexander Gordeev 	 * Jump to the decompressed kernel entry point and switch DAT mode on.
352*bb1520d5SAlexander Gordeev 	 */
353*bb1520d5SAlexander Gordeev 	psw.addr = vmlinux.entry;
354*bb1520d5SAlexander Gordeev 	psw.mask = PSW_KERNEL_BITS;
355*bb1520d5SAlexander Gordeev 	__load_psw(psw);
3568f75582aSVasily Gorbik }
357