0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/device.h>
0010 #include <linux/mm.h>
0011 #include <linux/kexec.h>
0012 #include <linux/delay.h>
0013 #include <linux/reboot.h>
0014 #include <linux/ftrace.h>
0015 #include <linux/debug_locks.h>
0016 #include <asm/cio.h>
0017 #include <asm/setup.h>
0018 #include <asm/smp.h>
0019 #include <asm/ipl.h>
0020 #include <asm/diag.h>
0021 #include <asm/elf.h>
0022 #include <asm/asm-offsets.h>
0023 #include <asm/cacheflush.h>
0024 #include <asm/os_info.h>
0025 #include <asm/set_memory.h>
0026 #include <asm/stacktrace.h>
0027 #include <asm/switch_to.h>
0028 #include <asm/nmi.h>
0029 #include <asm/sclp.h>
0030
0031 typedef void (*relocate_kernel_t)(kimage_entry_t *, unsigned long,
0032 unsigned long);
0033
0034 extern const unsigned char relocate_kernel[];
0035 extern const unsigned long long relocate_kernel_len;
0036
0037 #ifdef CONFIG_CRASH_DUMP
0038
0039
0040
0041
0042
0043 static void __do_machine_kdump(void *image)
0044 {
0045 int (*start_kdump)(int);
0046 unsigned long prefix;
0047
0048
0049 prefix = (unsigned long) S390_lowcore.prefixreg_save_area;
0050
0051
0052 s390_reset_system();
0053
0054
0055
0056
0057
0058
0059 memcpy(absolute_pointer(__LC_FPREGS_SAVE_AREA),
0060 (void *)(prefix + __LC_FPREGS_SAVE_AREA), 512);
0061
0062 __load_psw_mask(PSW_MASK_BASE | PSW_DEFAULT_KEY | PSW_MASK_EA | PSW_MASK_BA);
0063 start_kdump = (void *)((struct kimage *) image)->start;
0064 start_kdump(1);
0065
0066
0067 disabled_wait();
0068 }
0069
0070
0071
0072
0073
0074 static noinline void __machine_kdump(void *image)
0075 {
0076 struct mcesa *mcesa;
0077 union ctlreg2 cr2_old, cr2_new;
0078 int this_cpu, cpu;
0079
0080 lgr_info_log();
0081
0082 this_cpu = smp_find_processor_id(stap());
0083 for_each_online_cpu(cpu) {
0084 if (cpu == this_cpu)
0085 continue;
0086 if (smp_store_status(cpu))
0087 continue;
0088 }
0089
0090 mcesa = __va(S390_lowcore.mcesad & MCESA_ORIGIN_MASK);
0091 if (MACHINE_HAS_VX)
0092 save_vx_regs((__vector128 *) mcesa->vector_save_area);
0093 if (MACHINE_HAS_GS) {
0094 __ctl_store(cr2_old.val, 2, 2);
0095 cr2_new = cr2_old;
0096 cr2_new.gse = 1;
0097 __ctl_load(cr2_new.val, 2, 2);
0098 save_gs_cb((struct gs_cb *) mcesa->guarded_storage_save_area);
0099 __ctl_load(cr2_old.val, 2, 2);
0100 }
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 store_status(__do_machine_kdump, image);
0111 }
0112
0113 static unsigned long do_start_kdump(unsigned long addr)
0114 {
0115 struct kimage *image = (struct kimage *) addr;
0116 int (*start_kdump)(int) = (void *)image->start;
0117 int rc;
0118
0119 __arch_local_irq_stnsm(0xfb);
0120 rc = start_kdump(0);
0121 __arch_local_irq_stosm(0x04);
0122 return rc;
0123 }
0124
0125 #endif
0126
0127
0128
0129
0130 static bool kdump_csum_valid(struct kimage *image)
0131 {
0132 #ifdef CONFIG_CRASH_DUMP
0133 int rc;
0134
0135 preempt_disable();
0136 rc = call_on_stack(1, S390_lowcore.nodat_stack, unsigned long, do_start_kdump,
0137 unsigned long, (unsigned long)image);
0138 preempt_enable();
0139 return rc == 0;
0140 #else
0141 return false;
0142 #endif
0143 }
0144
0145 #ifdef CONFIG_CRASH_DUMP
0146
0147 void crash_free_reserved_phys_range(unsigned long begin, unsigned long end)
0148 {
0149 unsigned long addr, size;
0150
0151 for (addr = begin; addr < end; addr += PAGE_SIZE)
0152 free_reserved_page(pfn_to_page(addr >> PAGE_SHIFT));
0153 size = begin - crashk_res.start;
0154 if (size)
0155 os_info_crashkernel_add(crashk_res.start, size);
0156 else
0157 os_info_crashkernel_add(0, 0);
0158 }
0159
0160 static void crash_protect_pages(int protect)
0161 {
0162 unsigned long size;
0163
0164 if (!crashk_res.end)
0165 return;
0166 size = resource_size(&crashk_res);
0167 if (protect)
0168 set_memory_ro(crashk_res.start, size >> PAGE_SHIFT);
0169 else
0170 set_memory_rw(crashk_res.start, size >> PAGE_SHIFT);
0171 }
0172
0173 void arch_kexec_protect_crashkres(void)
0174 {
0175 crash_protect_pages(1);
0176 }
0177
0178 void arch_kexec_unprotect_crashkres(void)
0179 {
0180 crash_protect_pages(0);
0181 }
0182
0183 #endif
0184
0185
0186
0187
0188 static int machine_kexec_prepare_kdump(void)
0189 {
0190 #ifdef CONFIG_CRASH_DUMP
0191 if (MACHINE_IS_VM)
0192 diag10_range(PFN_DOWN(crashk_res.start),
0193 PFN_DOWN(crashk_res.end - crashk_res.start + 1));
0194 return 0;
0195 #else
0196 return -EINVAL;
0197 #endif
0198 }
0199
0200 int machine_kexec_prepare(struct kimage *image)
0201 {
0202 void *reboot_code_buffer;
0203
0204 if (image->type == KEXEC_TYPE_CRASH)
0205 return machine_kexec_prepare_kdump();
0206
0207
0208 if (image->type != KEXEC_TYPE_DEFAULT)
0209 return -EINVAL;
0210
0211
0212 reboot_code_buffer = (void *) page_to_phys(image->control_code_page);
0213
0214
0215 memcpy(reboot_code_buffer, relocate_kernel, relocate_kernel_len);
0216 return 0;
0217 }
0218
0219 void machine_kexec_cleanup(struct kimage *image)
0220 {
0221 }
0222
0223 void arch_crash_save_vmcoreinfo(void)
0224 {
0225 VMCOREINFO_SYMBOL(lowcore_ptr);
0226 VMCOREINFO_SYMBOL(high_memory);
0227 VMCOREINFO_LENGTH(lowcore_ptr, NR_CPUS);
0228 vmcoreinfo_append_str("SAMODE31=%lx\n", __samode31);
0229 vmcoreinfo_append_str("EAMODE31=%lx\n", __eamode31);
0230 vmcoreinfo_append_str("KERNELOFFSET=%lx\n", kaslr_offset());
0231 put_abs_lowcore(vmcore_info, paddr_vmcoreinfo_note());
0232 }
0233
0234 void machine_shutdown(void)
0235 {
0236 }
0237
0238 void machine_crash_shutdown(struct pt_regs *regs)
0239 {
0240 set_os_info_reipl_block();
0241 }
0242
0243
0244
0245
0246 static void __do_machine_kexec(void *data)
0247 {
0248 unsigned long diag308_subcode;
0249 relocate_kernel_t data_mover;
0250 struct kimage *image = data;
0251
0252 s390_reset_system();
0253 data_mover = (relocate_kernel_t) page_to_phys(image->control_code_page);
0254
0255 __arch_local_irq_stnsm(0xfb);
0256
0257 diag308_subcode = DIAG308_CLEAR_RESET;
0258 if (sclp.has_iplcc)
0259 diag308_subcode |= DIAG308_FLAG_EI;
0260 (*data_mover)(&image->head, image->start, diag308_subcode);
0261
0262
0263 disabled_wait();
0264 }
0265
0266
0267
0268
0269 static void __machine_kexec(void *data)
0270 {
0271 pfault_fini();
0272 tracing_off();
0273 debug_locks_off();
0274 #ifdef CONFIG_CRASH_DUMP
0275 if (((struct kimage *) data)->type == KEXEC_TYPE_CRASH)
0276 __machine_kdump(data);
0277 #endif
0278 __do_machine_kexec(data);
0279 }
0280
0281
0282
0283
0284
0285 void machine_kexec(struct kimage *image)
0286 {
0287 if (image->type == KEXEC_TYPE_CRASH && !kdump_csum_valid(image))
0288 return;
0289 tracer_disable();
0290 smp_send_stop();
0291 smp_call_ipl_cpu(__machine_kexec, image);
0292 }