| 1 | |
| 2 | |
| 3 | * Copyright IBM Corp. 2007, 2009
|
| 4 | * Author(s): Hongjie Yang <[email protected]>,
|
| 5 |
|
| 6 |
|
| 7 | #define pr_fmt(fmt) "setup: " fmt
|
| 8 |
|
| 9 | #include <linux/sched/debug.h>
|
| 10 | #include <linux/cpufeature.h>
|
| 11 | #include <linux/compiler.h>
|
| 12 | #include <linux/init.h>
|
| 13 | #include <linux/errno.h>
|
| 14 | #include <linux/string.h>
|
| 15 | #include <linux/ctype.h>
|
| 16 | #include <linux/lockdep.h>
|
| 17 | #include <linux/extable.h>
|
| 18 | #include <linux/pfn.h>
|
| 19 | #include <linux/uaccess.h>
|
| 20 | #include <linux/kernel.h>
|
| 21 | #include <asm/asm-extable.h>
|
| 22 | #include <linux/memblock.h>
|
| 23 | #include <linux/kasan.h>
|
| 24 | #include <asm/access-regs.h>
|
| 25 | #include <asm/asm-offsets.h>
|
| 26 | #include <asm/machine.h>
|
| 27 | #include <asm/diag.h>
|
| 28 | #include <asm/ebcdic.h>
|
| 29 | #include <asm/fpu.h>
|
| 30 | #include <asm/ipl.h>
|
| 31 | #include <asm/lowcore.h>
|
| 32 | #include <asm/processor.h>
|
| 33 | #include <asm/sections.h>
|
| 34 | #include <asm/setup.h>
|
| 35 | #include <asm/sysinfo.h>
|
| 36 | #include <asm/cpcmd.h>
|
| 37 | #include <asm/sclp.h>
|
| 38 | #include <asm/facility.h>
|
| 39 | #include <asm/boot_data.h>
|
| 40 | #include "entry.h"
|
| 41 |
|
| 42 | #define __decompressor_handled_param(func, param) \
|
| 43 | static int __init ignore_decompressor_param_##func(char *s) \
|
| 44 | { \
|
| 45 | return 0; \
|
| 46 | } \
|
| 47 | early_param(#param, ignore_decompressor_param_##func)
|
| 48 |
|
| 49 | #define decompressor_handled_param(param) __decompressor_handled_param(param, param)
|
| 50 |
|
| 51 | decompressor_handled_param(mem);
|
| 52 | decompressor_handled_param(vmalloc);
|
| 53 | decompressor_handled_param(dfltcc);
|
| 54 | decompressor_handled_param(facilities);
|
| 55 | decompressor_handled_param(nokaslr);
|
| 56 | decompressor_handled_param(cmma);
|
| 57 | decompressor_handled_param(relocate_lowcore);
|
| 58 | decompressor_handled_param(bootdebug);
|
| 59 | __decompressor_handled_param(debug_alternative, debug-alternative);
|
| 60 | #if IS_ENABLED(CONFIG_KVM)
|
| 61 | decompressor_handled_param(prot_virt);
|
| 62 | #endif
|
| 63 |
|
| 64 | static void __init kasan_early_init(void)
|
| 65 | {
|
| 66 | #ifdef CONFIG_KASAN
|
| 67 | init_task.kasan_depth = 0;
|
| 68 | kasan_init_generic();
|
| 69 | #endif
|
| 70 | }
|
| 71 |
|
| 72 | |
| 73 | * Initialize storage key for kernel pages
|
| 74 |
|
| 75 | static noinline __init void init_kernel_storage_key(void)
|
| 76 | {
|
| 77 | #if PAGE_DEFAULT_KEY
|
| 78 | unsigned long end_pfn, init_pfn;
|
| 79 |
|
| 80 | end_pfn = PFN_UP(__pa(_end));
|
| 81 |
|
| 82 | for (init_pfn = 0 ; init_pfn < end_pfn; init_pfn++)
|
| 83 | page_set_storage_key(init_pfn << PAGE_SHIFT,
|
| 84 | PAGE_DEFAULT_KEY, 0);
|
| 85 | #endif
|
| 86 | }
|
| 87 |
|
| 88 | static __initdata char sysinfo_page[PAGE_SIZE] __aligned(PAGE_SIZE);
|
| 89 |
|
| 90 |
|
| 91 | static inline void strim_all(char *str)
|
| 92 | {
|
| 93 | char *s;
|
| 94 |
|
| 95 | s = strim(str);
|
| 96 | if (s != str)
|
| 97 | memmove(str, s, strlen(s));
|
| 98 | while (*str) {
|
| 99 | if (!isspace(*str++))
|
| 100 | continue;
|
| 101 | if (isspace(*str)) {
|
| 102 | s = skip_spaces(str);
|
| 103 | memmove(str, s, strlen(s) + 1);
|
| 104 | }
|
| 105 | }
|
| 106 | }
|
| 107 |
|
| 108 | char arch_hw_string[128];
|
| 109 |
|
| 110 | static noinline __init void setup_arch_string(void)
|
| 111 | {
|
| 112 | struct sysinfo_1_1_1 *mach = (struct sysinfo_1_1_1 *)&sysinfo_page;
|
| 113 | struct sysinfo_3_2_2 *vm = (struct sysinfo_3_2_2 *)&sysinfo_page;
|
| 114 | char mstr[80], hvstr[17];
|
| 115 |
|
| 116 | if (stsi(mach, 1, 1, 1))
|
| 117 | return;
|
| 118 | EBCASC(mach->manufacturer, sizeof(mach->manufacturer));
|
| 119 | EBCASC(mach->type, sizeof(mach->type));
|
| 120 | EBCASC(mach->model, sizeof(mach->model));
|
| 121 | EBCASC(mach->model_capacity, sizeof(mach->model_capacity));
|
| 122 | scnprintf(mstr, sizeof(mstr), "%-16.16s %-4.4s %-16.16s %-16.16s",
|
| 123 | mach->manufacturer, mach->type,
|
| 124 | mach->model, mach->model_capacity);
|
| 125 | strim_all(mstr);
|
| 126 | if (stsi(vm, 3, 2, 2) == 0 && vm->count) {
|
| 127 | EBCASC(vm->vm[0].cpi, sizeof(vm->vm[0].cpi));
|
| 128 | scnprintf(hvstr, sizeof(hvstr), "%-16.16s", vm->vm[0].cpi);
|
| 129 | strim_all(hvstr);
|
| 130 | } else {
|
| 131 | scnprintf(hvstr, sizeof(hvstr), "%s",
|
| 132 | machine_is_lpar() ? "LPAR" :
|
| 133 | machine_is_vm() ? "z/VM" :
|
| 134 | machine_is_kvm() ? "KVM" : "unknown");
|
| 135 | }
|
| 136 | scnprintf(arch_hw_string, sizeof(arch_hw_string), "HW: %s (%s)", mstr, hvstr);
|
| 137 | dump_stack_set_arch_desc("%s (%s)", mstr, hvstr);
|
| 138 | }
|
| 139 |
|
| 140 | static __init void setup_topology(void)
|
| 141 | {
|
| 142 | int max_mnest;
|
| 143 |
|
| 144 | if (!cpu_has_topology())
|
| 145 | return;
|
| 146 | for (max_mnest = 6; max_mnest > 1; max_mnest--) {
|
| 147 | if (stsi(&sysinfo_page, 15, 1, max_mnest) == 0)
|
| 148 | break;
|
| 149 | }
|
| 150 | topology_max_mnest = max_mnest;
|
| 151 | }
|
| 152 |
|
| 153 | void __init __do_early_pgm_check(struct pt_regs *regs)
|
| 154 | {
|
| 155 | struct lowcore *lc = get_lowcore();
|
| 156 |
|
| 157 | regs->flags = 0;
|
| 158 | regs->int_code = lc->pgm_int_code;
|
| 159 | regs->int_parm_long = lc->trans_exc_code;
|
| 160 | regs->last_break = lc->pgm_last_break;
|
| 161 | regs->monitor_code = lc->monitor_code;
|
| 162 | set_pt_regs_flag(regs, PIF_PGM_CHECK);
|
| 163 |
|
| 164 |
|
| 165 | if ((regs->int_code & PGM_INT_CODE_MASK) == 0x40) {
|
| 166 | enum bug_trap_type btt;
|
| 167 | unsigned long ip;
|
| 168 |
|
| 169 | if (regs->monitor_code == MONCODE_BUG_ARG) {
|
| 170 | regs->psw.addr = regs->gprs[14];
|
| 171 | set_pt_regs_flag(regs, PIF_WARN_TRAP_SKIPPED);
|
| 172 | btt = report_bug_entry((struct bug_entry *)regs->gprs[2], regs);
|
| 173 | } else {
|
| 174 | ip = __rewind_psw(regs->psw, regs->int_code >> 16);
|
| 175 | btt = report_bug(ip, regs);
|
| 176 | }
|
| 177 | if (btt == BUG_TRAP_TYPE_WARN)
|
| 178 | return;
|
| 179 | }
|
| 180 | if (fixup_exception(regs))
|
| 181 | return;
|
| 182 | |
| 183 | * Unhandled exception - system cannot continue but try to get some
|
| 184 | * helpful messages to the console. Use early_printk() to print
|
| 185 | * some basic information in case it is too early for printk().
|
| 186 |
|
| 187 | register_early_console();
|
| 188 | if (test_pt_regs_flag(regs, PIF_WARN_TRAP_SKIPPED))
|
| 189 | early_printk("PANIC: early exception PSW: %016lx %016lx\n",
|
| 190 | regs->psw.mask, regs->psw.addr);
|
| 191 | else
|
| 192 | early_printk("PANIC: early exception %04x PSW: %016lx %016lx\n",
|
| 193 | regs->int_code & 0xffff, regs->psw.mask, regs->psw.addr);
|
| 194 | show_regs(regs);
|
| 195 | disabled_wait();
|
| 196 | }
|
| 197 |
|
| 198 | static noinline __init void setup_lowcore_early(void)
|
| 199 | {
|
| 200 | struct lowcore *lc = get_lowcore();
|
| 201 | psw_t psw;
|
| 202 |
|
| 203 | psw.addr = (unsigned long)early_pgm_check_handler;
|
| 204 | psw.mask = PSW_KERNEL_BITS;
|
| 205 | lc->program_new_psw = psw;
|
| 206 | lc->preempt_count = INIT_PREEMPT_COUNT;
|
| 207 | lc->return_lpswe = gen_lpswe(__LC_RETURN_PSW);
|
| 208 | lc->return_mcck_lpswe = gen_lpswe(__LC_RETURN_MCCK_PSW);
|
| 209 | }
|
| 210 |
|
| 211 | static inline void save_vector_registers(void)
|
| 212 | {
|
| 213 | #ifdef CONFIG_CRASH_DUMP
|
| 214 | if (cpu_has_vx())
|
| 215 | save_vx_regs(boot_cpu_vector_save_area);
|
| 216 | #endif
|
| 217 | }
|
| 218 |
|
| 219 | static inline void setup_low_address_protection(void)
|
| 220 | {
|
| 221 | system_ctl_set_bit(0, CR0_LOW_ADDRESS_PROTECTION_BIT);
|
| 222 | }
|
| 223 |
|
| 224 | static inline void setup_access_registers(void)
|
| 225 | {
|
| 226 | unsigned int acrs[NUM_ACRS] = { 0 };
|
| 227 |
|
| 228 | restore_access_regs(acrs);
|
| 229 | }
|
| 230 |
|
| 231 | char __bootdata(early_command_line)[COMMAND_LINE_SIZE];
|
| 232 | static void __init setup_boot_command_line(void)
|
| 233 | {
|
| 234 |
|
| 235 | strscpy(boot_command_line, early_command_line, COMMAND_LINE_SIZE);
|
| 236 | }
|
| 237 |
|
| 238 | static void __init sort_amode31_extable(void)
|
| 239 | {
|
| 240 | sort_extable(__start_amode31_ex_table, __stop_amode31_ex_table);
|
| 241 | }
|
| 242 |
|
| 243 | void __init startup_init(void)
|
| 244 | {
|
| 245 | kasan_early_init();
|
| 246 | time_early_init();
|
| 247 | init_kernel_storage_key();
|
| 248 | lockdep_off();
|
| 249 | sort_amode31_extable();
|
| 250 | setup_lowcore_early();
|
| 251 | setup_arch_string();
|
| 252 | setup_boot_command_line();
|
| 253 | save_vector_registers();
|
| 254 | setup_topology();
|
| 255 | sclp_early_detect();
|
| 256 | setup_low_address_protection();
|
| 257 | setup_access_registers();
|
| 258 | lockdep_on();
|
| 259 | }
|