x86, crash: wrap crash dumping code into crash related ifdefs
authorBaoquan He <bhe@redhat.com>
Wed, 24 Jan 2024 05:12:46 +0000 (13:12 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 24 Feb 2024 01:48:23 +0000 (17:48 -0800)
Now crash codes under kernel/ folder has been split out from kexec
code, crash dumping can be separated from kexec reboot in config
items on x86 with some adjustments.

Here, also change some ifdefs or IS_ENABLED() check to more appropriate
ones, e,g
 - #ifdef CONFIG_KEXEC_CORE -> #ifdef CONFIG_CRASH_DUMP
 - (!IS_ENABLED(CONFIG_KEXEC_CORE)) - > (!IS_ENABLED(CONFIG_CRASH_RESERVE))

[bhe@redhat.com: don't nest CONFIG_CRASH_DUMP ifdef inside CONFIG_KEXEC_CODE ifdef scope]
Link: https://lore.kernel.org/all/SN6PR02MB4157931105FA68D72E3D3DB8D47B2@SN6PR02MB4157.namprd02.prod.outlook.com/T/#u
Link: https://lkml.kernel.org/r/20240124051254.67105-7-bhe@redhat.com
Signed-off-by: Baoquan He <bhe@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Hari Bathini <hbathini@linux.ibm.com>
Cc: Pingfan Liu <piliu@redhat.com>
Cc: Klara Modin <klarasmodin@gmail.com>
Cc: Michael Kelley <mhklinux@outlook.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Yang Li <yang.lee@linux.alibaba.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/x86/kernel/Makefile
arch/x86/kernel/cpu/mshyperv.c
arch/x86/kernel/kexec-bzimage64.c
arch/x86/kernel/kvm.c
arch/x86/kernel/machine_kexec_64.c
arch/x86/kernel/reboot.c
arch/x86/kernel/setup.c
arch/x86/kernel/smp.c
arch/x86/xen/enlighten_hvm.c
arch/x86/xen/mmu_pv.c

index 913d4022131eba924696836939d50616eb92e7d8..3668b1edef2d28c1ff09ca4fd9bb45b359f5ba69 100644 (file)
@@ -100,9 +100,9 @@ obj-$(CONFIG_TRACING)               += trace.o
 obj-$(CONFIG_RETHOOK)          += rethook.o
 obj-$(CONFIG_VMCORE_INFO)      += vmcore_info_$(BITS).o
 obj-$(CONFIG_KEXEC_CORE)       += machine_kexec_$(BITS).o
-obj-$(CONFIG_KEXEC_CORE)       += relocate_kernel_$(BITS).o crash.o
+obj-$(CONFIG_KEXEC_CORE)       += relocate_kernel_$(BITS).o
 obj-$(CONFIG_KEXEC_FILE)       += kexec-bzimage64.o
-obj-$(CONFIG_CRASH_DUMP)       += crash_dump_$(BITS).o
+obj-$(CONFIG_CRASH_DUMP)       += crash_dump_$(BITS).o crash.o
 obj-y                          += kprobes/
 obj-$(CONFIG_MODULES)          += module.o
 obj-$(CONFIG_X86_32)           += doublefault_32.o
index 01fa06dd06b66c9324c670e4847c0d503dbd5691..2e8cd5a4ae859fdf8a596b075e548a7598f4f4c6 100644 (file)
@@ -209,7 +209,9 @@ static void hv_machine_shutdown(void)
        if (kexec_in_progress)
                hyperv_cleanup();
 }
+#endif /* CONFIG_KEXEC_CORE */
 
+#ifdef CONFIG_CRASH_DUMP
 static void hv_machine_crash_shutdown(struct pt_regs *regs)
 {
        if (hv_crash_handler)
@@ -221,7 +223,7 @@ static void hv_machine_crash_shutdown(struct pt_regs *regs)
        /* Disable the hypercall page when there is only 1 active CPU. */
        hyperv_cleanup();
 }
-#endif /* CONFIG_KEXEC_CORE */
+#endif /* CONFIG_CRASH_DUMP */
 #endif /* CONFIG_HYPERV */
 
 static uint32_t  __init ms_hyperv_platform(void)
@@ -495,9 +497,13 @@ static void __init ms_hyperv_init_platform(void)
        no_timer_check = 1;
 #endif
 
-#if IS_ENABLED(CONFIG_HYPERV) && defined(CONFIG_KEXEC_CORE)
+#if IS_ENABLED(CONFIG_HYPERV)
+#if defined(CONFIG_KEXEC_CORE)
        machine_ops.shutdown = hv_machine_shutdown;
+#endif
+#if defined(CONFIG_CRASH_DUMP)
        machine_ops.crash_shutdown = hv_machine_crash_shutdown;
+#endif
 #endif
        if (ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) {
                /*
index 2a422e00ed4b42f7921c238a47702d47bf8888c5..b55737b83a841af1e487cbb1ac02a7af58dafdf8 100644 (file)
@@ -263,11 +263,13 @@ setup_boot_parameters(struct kimage *image, struct boot_params *params,
        memset(&params->hd0_info, 0, sizeof(params->hd0_info));
        memset(&params->hd1_info, 0, sizeof(params->hd1_info));
 
+#ifdef CONFIG_CRASH_DUMP
        if (image->type == KEXEC_TYPE_CRASH) {
                ret = crash_setup_memmap_entries(image, params);
                if (ret)
                        return ret;
        } else
+#endif
                setup_e820_entries(params);
 
        nr_e820_entries = params->e820_entries;
@@ -433,12 +435,14 @@ static void *bzImage64_load(struct kimage *image, char *kernel,
                return ERR_PTR(-EINVAL);
        }
 
+#ifdef CONFIG_CRASH_DUMP
        /* Allocate and load backup region */
        if (image->type == KEXEC_TYPE_CRASH) {
                ret = crash_load_segments(image);
                if (ret)
                        return ERR_PTR(ret);
        }
+#endif
 
        /*
         * Load purgatory. For 64bit entry point, purgatory  code can be
index 428ee74002e1eac63d0e269510f536ba2644c3f7..3c9c327d6706c5d333b2075fcac20f8d439193bb 100644 (file)
@@ -770,7 +770,7 @@ static struct notifier_block kvm_pv_reboot_nb = {
  * won't be valid. In cases like kexec, in which you install a new kernel, this
  * means a random memory location will be kept being written.
  */
-#ifdef CONFIG_KEXEC_CORE
+#ifdef CONFIG_CRASH_DUMP
 static void kvm_crash_shutdown(struct pt_regs *regs)
 {
        kvm_guest_cpu_offline(true);
@@ -853,7 +853,7 @@ static void __init kvm_guest_init(void)
        kvm_guest_cpu_init();
 #endif
 
-#ifdef CONFIG_KEXEC_CORE
+#ifdef CONFIG_CRASH_DUMP
        machine_ops.crash_shutdown = kvm_crash_shutdown;
 #endif
 
index bc0a5348b4a6275c4fe1d35464330eb6c69993ba..b180d8e497c317f88a9880241721818bec818174 100644 (file)
@@ -508,6 +508,8 @@ int arch_kimage_file_post_load_cleanup(struct kimage *image)
 }
 #endif /* CONFIG_KEXEC_FILE */
 
+#ifdef CONFIG_CRASH_DUMP
+
 static int
 kexec_mark_range(unsigned long start, unsigned long end, bool protect)
 {
@@ -552,6 +554,7 @@ void arch_kexec_unprotect_crashkres(void)
 {
        kexec_mark_crashkres(false);
 }
+#endif
 
 /*
  * During a traditional boot under SME, SME will encrypt the kernel,
index 830425e6d38e2f75fb9ea41f7dc042e175d98846..f3130f762784a19fb3e74e3efe2baf0b93cd2376 100644 (file)
@@ -796,7 +796,7 @@ struct machine_ops machine_ops __ro_after_init = {
        .emergency_restart = native_machine_emergency_restart,
        .restart = native_machine_restart,
        .halt = native_machine_halt,
-#ifdef CONFIG_KEXEC_CORE
+#ifdef CONFIG_CRASH_DUMP
        .crash_shutdown = native_machine_crash_shutdown,
 #endif
 };
@@ -826,7 +826,7 @@ void machine_halt(void)
        machine_ops.halt();
 }
 
-#ifdef CONFIG_KEXEC_CORE
+#ifdef CONFIG_CRASH_DUMP
 void machine_crash_shutdown(struct pt_regs *regs)
 {
        machine_ops.crash_shutdown(regs);
index 84201071dfacd186da34cdca12cbda41a39eedf1..899d839a2954a73943a2f9d0911bbb924bd35862 100644 (file)
@@ -471,7 +471,7 @@ static void __init arch_reserve_crashkernel(void)
        bool high = false;
        int ret;
 
-       if (!IS_ENABLED(CONFIG_KEXEC_CORE))
+       if (!IS_ENABLED(CONFIG_CRASH_RESERVE))
                return;
 
        ret = parse_crashkernel(cmdline, memblock_phys_mem_size(),
index 96a771f9f930a6aba1b77967169808bce3b3eace..52c3823b7211918a44dd6820cec20235d6ad42b3 100644 (file)
@@ -282,7 +282,7 @@ struct smp_ops smp_ops = {
        .smp_cpus_done          = native_smp_cpus_done,
 
        .stop_other_cpus        = native_stop_other_cpus,
-#if defined(CONFIG_KEXEC_CORE)
+#if defined(CONFIG_CRASH_DUMP)
        .crash_stop_other_cpus  = kdump_nmi_shootdown_cpus,
 #endif
        .smp_send_reschedule    = native_smp_send_reschedule,
index 3f8c34707c50014d9364f0430728446e35059d8f..0b367c1e086d612ec0c2f5599ccd832955a808a8 100644 (file)
@@ -148,7 +148,9 @@ static void xen_hvm_shutdown(void)
        if (kexec_in_progress)
                xen_reboot(SHUTDOWN_soft_reset);
 }
+#endif
 
+#ifdef CONFIG_CRASH_DUMP
 static void xen_hvm_crash_shutdown(struct pt_regs *regs)
 {
        native_machine_crash_shutdown(regs);
@@ -236,6 +238,8 @@ static void __init xen_hvm_guest_init(void)
 
 #ifdef CONFIG_KEXEC_CORE
        machine_ops.shutdown = xen_hvm_shutdown;
+#endif
+#ifdef CONFIG_CRASH_DUMP
        machine_ops.crash_shutdown = xen_hvm_crash_shutdown;
 #endif
 }
index 218773cfb009f721793ccfaac1a52cf35b52b32b..e21974f2cf2d7d33efb19641426e292fe7af0ee9 100644 (file)
@@ -2520,7 +2520,7 @@ out:
 }
 EXPORT_SYMBOL_GPL(xen_remap_pfn);
 
-#ifdef CONFIG_KEXEC_CORE
+#ifdef CONFIG_VMCORE_INFO
 phys_addr_t paddr_vmcoreinfo_note(void)
 {
        if (xen_pv_domain())