1 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3 #include <linux/export.h>
4 #include <linux/reboot.h>
5 #include <linux/init.h>
9 #include <linux/sched.h>
10 #include <linux/tboot.h>
11 #include <linux/delay.h>
12 #include <linux/frame.h>
13 #include <acpi/reboot.h>
16 #include <asm/io_apic.h>
19 #include <asm/pgtable.h>
20 #include <asm/proto.h>
21 #include <asm/reboot_fixups.h>
22 #include <asm/reboot.h>
23 #include <asm/pci_x86.h>
24 #include <asm/virtext.h>
29 #include <linux/ctype.h>
30 #include <linux/mc146818rtc.h>
31 #include <asm/realmode.h>
32 #include <asm/x86_init.h>
36 * Power off function, if any
38 void (*pm_power_off)(void);
39 EXPORT_SYMBOL(pm_power_off);
41 static const struct desc_ptr no_idt = {};
44 * This is set if we need to go through the 'emergency' path.
45 * When machine_emergency_restart() is called, we may be on
46 * an inconsistent state and won't be able to do a clean cleanup
48 static int reboot_emergency;
50 /* This is set by the PCI code if either type 1 or type 2 PCI is detected */
51 bool port_cf9_safe = false;
54 * Reboot options and system auto-detection code provided by
55 * Dell Inc. so their systems "just work". :-)
59 * Some machines require the "reboot=a" commandline options
61 static int __init set_acpi_reboot(const struct dmi_system_id *d)
63 if (reboot_type != BOOT_ACPI) {
64 reboot_type = BOOT_ACPI;
65 pr_info("%s series board detected. Selecting %s-method for reboots.\n",
72 * Some machines require the "reboot=b" or "reboot=k" commandline options,
73 * this quirk makes that automatic.
75 static int __init set_bios_reboot(const struct dmi_system_id *d)
77 if (reboot_type != BOOT_BIOS) {
78 reboot_type = BOOT_BIOS;
79 pr_info("%s series board detected. Selecting %s-method for reboots.\n",
86 * Some machines don't handle the default ACPI reboot method and
87 * require the EFI reboot method:
89 static int __init set_efi_reboot(const struct dmi_system_id *d)
91 if (reboot_type != BOOT_EFI && !efi_runtime_disabled()) {
92 reboot_type = BOOT_EFI;
93 pr_info("%s series board detected. Selecting EFI-method for reboot.\n", d->ident);
98 void __noreturn machine_real_restart(unsigned int type)
103 * Write zero to CMOS register number 0x0f, which the BIOS POST
104 * routine will recognize as telling it to do a proper reboot. (Well
105 * that's what this book in front of me says -- it may only apply to
106 * the Phoenix BIOS though, it's not clear). At the same time,
107 * disable NMIs by setting the top bit in the CMOS address register,
108 * as we're about to do peculiar things to the CPU. I'm not sure if
109 * `outb_p' is needed instead of just `outb'. Use it to be on the
110 * safe side. (Yes, CMOS_WRITE does outb_p's. - Paul G.)
112 spin_lock(&rtc_lock);
113 CMOS_WRITE(0x00, 0x8f);
114 spin_unlock(&rtc_lock);
117 * Switch back to the initial page table.
120 load_cr3(initial_page_table);
122 write_cr3(real_mode_header->trampoline_pgd);
124 /* Exiting long mode will fail if CR4.PCIDE is set. */
125 if (static_cpu_has(X86_FEATURE_PCID))
126 cr4_clear_bits(X86_CR4_PCIDE);
129 /* Jump to the identity-mapped low memory code */
131 asm volatile("jmpl *%0" : :
132 "rm" (real_mode_header->machine_real_restart_asm),
135 asm volatile("ljmpl *%0" : :
136 "m" (real_mode_header->machine_real_restart_asm),
141 #ifdef CONFIG_APM_MODULE
142 EXPORT_SYMBOL(machine_real_restart);
144 STACK_FRAME_NON_STANDARD(machine_real_restart);
147 * Some Apple MacBook and MacBookPro's needs reboot=p to be able to reboot
149 static int __init set_pci_reboot(const struct dmi_system_id *d)
151 if (reboot_type != BOOT_CF9_FORCE) {
152 reboot_type = BOOT_CF9_FORCE;
153 pr_info("%s series board detected. Selecting %s-method for reboots.\n",
159 static int __init set_kbd_reboot(const struct dmi_system_id *d)
161 if (reboot_type != BOOT_KBD) {
162 reboot_type = BOOT_KBD;
163 pr_info("%s series board detected. Selecting %s-method for reboot.\n",
170 * This is a single dmi_table handling all reboot quirks.
172 static struct dmi_system_id __initdata reboot_dmi_table[] = {
175 { /* Handle reboot issue on Acer Aspire one */
176 .callback = set_kbd_reboot,
177 .ident = "Acer Aspire One A110",
179 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
180 DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"),
183 { /* Handle reboot issue on Acer TravelMate X514-51T */
184 .callback = set_efi_reboot,
185 .ident = "Acer TravelMate X514-51T",
187 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
188 DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate X514-51T"),
193 { /* Handle problems with rebooting on Apple MacBook5 */
194 .callback = set_pci_reboot,
195 .ident = "Apple MacBook5",
197 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
198 DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5"),
201 { /* Handle problems with rebooting on Apple MacBook6,1 */
202 .callback = set_pci_reboot,
203 .ident = "Apple MacBook6,1",
205 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
206 DMI_MATCH(DMI_PRODUCT_NAME, "MacBook6,1"),
209 { /* Handle problems with rebooting on Apple MacBookPro5 */
210 .callback = set_pci_reboot,
211 .ident = "Apple MacBookPro5",
213 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
214 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro5"),
217 { /* Handle problems with rebooting on Apple Macmini3,1 */
218 .callback = set_pci_reboot,
219 .ident = "Apple Macmini3,1",
221 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
222 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini3,1"),
225 { /* Handle problems with rebooting on the iMac9,1. */
226 .callback = set_pci_reboot,
227 .ident = "Apple iMac9,1",
229 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
230 DMI_MATCH(DMI_PRODUCT_NAME, "iMac9,1"),
233 { /* Handle problems with rebooting on the iMac10,1. */
234 .callback = set_pci_reboot,
235 .ident = "Apple iMac10,1",
237 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
238 DMI_MATCH(DMI_PRODUCT_NAME, "iMac10,1"),
243 { /* Handle problems with rebooting on ASRock Q1900DC-ITX */
244 .callback = set_pci_reboot,
245 .ident = "ASRock Q1900DC-ITX",
247 DMI_MATCH(DMI_BOARD_VENDOR, "ASRock"),
248 DMI_MATCH(DMI_BOARD_NAME, "Q1900DC-ITX"),
253 { /* Handle problems with rebooting on ASUS P4S800 */
254 .callback = set_bios_reboot,
255 .ident = "ASUS P4S800",
257 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
258 DMI_MATCH(DMI_BOARD_NAME, "P4S800"),
261 { /* Handle problems with rebooting on ASUS EeeBook X205TA */
262 .callback = set_acpi_reboot,
263 .ident = "ASUS EeeBook X205TA",
265 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
266 DMI_MATCH(DMI_PRODUCT_NAME, "X205TA"),
269 { /* Handle problems with rebooting on ASUS EeeBook X205TAW */
270 .callback = set_acpi_reboot,
271 .ident = "ASUS EeeBook X205TAW",
273 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
274 DMI_MATCH(DMI_PRODUCT_NAME, "X205TAW"),
279 { /* Handle problems with rebooting on Certec BPC600 */
280 .callback = set_pci_reboot,
281 .ident = "Certec BPC600",
283 DMI_MATCH(DMI_SYS_VENDOR, "Certec"),
284 DMI_MATCH(DMI_PRODUCT_NAME, "BPC600"),
289 { /* Handle problems with rebooting on Dell DXP061 */
290 .callback = set_bios_reboot,
291 .ident = "Dell DXP061",
293 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
294 DMI_MATCH(DMI_PRODUCT_NAME, "Dell DXP061"),
297 { /* Handle problems with rebooting on Dell E520's */
298 .callback = set_bios_reboot,
299 .ident = "Dell E520",
301 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
302 DMI_MATCH(DMI_PRODUCT_NAME, "Dell DM061"),
305 { /* Handle problems with rebooting on the Latitude E5410. */
306 .callback = set_pci_reboot,
307 .ident = "Dell Latitude E5410",
309 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
310 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5410"),
313 { /* Handle problems with rebooting on the Latitude E5420. */
314 .callback = set_pci_reboot,
315 .ident = "Dell Latitude E5420",
317 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
318 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E5420"),
321 { /* Handle problems with rebooting on the Latitude E6320. */
322 .callback = set_pci_reboot,
323 .ident = "Dell Latitude E6320",
325 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
326 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6320"),
329 { /* Handle problems with rebooting on the Latitude E6420. */
330 .callback = set_pci_reboot,
331 .ident = "Dell Latitude E6420",
333 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
334 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6420"),
337 { /* Handle problems with rebooting on Dell Optiplex 330 with 0KP561 */
338 .callback = set_bios_reboot,
339 .ident = "Dell OptiPlex 330",
341 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
342 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 330"),
343 DMI_MATCH(DMI_BOARD_NAME, "0KP561"),
346 { /* Handle problems with rebooting on Dell Optiplex 360 with 0T656F */
347 .callback = set_bios_reboot,
348 .ident = "Dell OptiPlex 360",
350 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
351 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 360"),
352 DMI_MATCH(DMI_BOARD_NAME, "0T656F"),
355 { /* Handle problems with rebooting on Dell Optiplex 745's SFF */
356 .callback = set_bios_reboot,
357 .ident = "Dell OptiPlex 745",
359 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
360 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"),
363 { /* Handle problems with rebooting on Dell Optiplex 745's DFF */
364 .callback = set_bios_reboot,
365 .ident = "Dell OptiPlex 745",
367 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
368 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"),
369 DMI_MATCH(DMI_BOARD_NAME, "0MM599"),
372 { /* Handle problems with rebooting on Dell Optiplex 745 with 0KW626 */
373 .callback = set_bios_reboot,
374 .ident = "Dell OptiPlex 745",
376 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
377 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 745"),
378 DMI_MATCH(DMI_BOARD_NAME, "0KW626"),
381 { /* Handle problems with rebooting on Dell OptiPlex 760 with 0G919G */
382 .callback = set_bios_reboot,
383 .ident = "Dell OptiPlex 760",
385 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
386 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 760"),
387 DMI_MATCH(DMI_BOARD_NAME, "0G919G"),
390 { /* Handle problems with rebooting on the OptiPlex 990. */
391 .callback = set_pci_reboot,
392 .ident = "Dell OptiPlex 990 BIOS A0x",
394 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
395 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 990"),
396 DMI_MATCH(DMI_BIOS_VERSION, "A0"),
399 { /* Handle problems with rebooting on Dell 300's */
400 .callback = set_bios_reboot,
401 .ident = "Dell PowerEdge 300",
403 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
404 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 300/"),
407 { /* Handle problems with rebooting on Dell 1300's */
408 .callback = set_bios_reboot,
409 .ident = "Dell PowerEdge 1300",
411 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
412 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1300/"),
415 { /* Handle problems with rebooting on Dell 2400's */
416 .callback = set_bios_reboot,
417 .ident = "Dell PowerEdge 2400",
419 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
420 DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2400"),
423 { /* Handle problems with rebooting on the Dell PowerEdge C6100. */
424 .callback = set_pci_reboot,
425 .ident = "Dell PowerEdge C6100",
427 DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
428 DMI_MATCH(DMI_PRODUCT_NAME, "C6100"),
431 { /* Handle problems with rebooting on the Precision M6600. */
432 .callback = set_pci_reboot,
433 .ident = "Dell Precision M6600",
435 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
436 DMI_MATCH(DMI_PRODUCT_NAME, "Precision M6600"),
439 { /* Handle problems with rebooting on Dell T5400's */
440 .callback = set_bios_reboot,
441 .ident = "Dell Precision T5400",
443 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
444 DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T5400"),
447 { /* Handle problems with rebooting on Dell T7400's */
448 .callback = set_bios_reboot,
449 .ident = "Dell Precision T7400",
451 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
452 DMI_MATCH(DMI_PRODUCT_NAME, "Precision WorkStation T7400"),
455 { /* Handle problems with rebooting on Dell XPS710 */
456 .callback = set_bios_reboot,
457 .ident = "Dell XPS710",
459 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
460 DMI_MATCH(DMI_PRODUCT_NAME, "Dell XPS710"),
463 { /* Handle problems with rebooting on Dell Optiplex 7450 AIO */
464 .callback = set_acpi_reboot,
465 .ident = "Dell OptiPlex 7450 AIO",
467 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
468 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 7450 AIO"),
472 /* Hewlett-Packard */
473 { /* Handle problems with rebooting on HP laptops */
474 .callback = set_bios_reboot,
475 .ident = "HP Compaq Laptop",
477 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
478 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"),
482 { /* PCIe Wifi card isn't detected after reboot otherwise */
483 .callback = set_pci_reboot,
484 .ident = "Zotac ZBOX CI327 nano",
486 DMI_MATCH(DMI_SYS_VENDOR, "NA"),
487 DMI_MATCH(DMI_PRODUCT_NAME, "ZBOX-CI327NANO-GS-01"),
492 { /* Handle problems with rebooting on Sony VGN-Z540N */
493 .callback = set_bios_reboot,
494 .ident = "Sony VGN-Z540N",
496 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
497 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-Z540N"),
504 static int __init reboot_init(void)
509 * Only do the DMI check if reboot_type hasn't been overridden
510 * on the command line
516 * The DMI quirks table takes precedence. If no quirks entry
517 * matches and the ACPI Hardware Reduced bit is set, force EFI
520 rv = dmi_check_system(reboot_dmi_table);
522 if (!rv && efi_reboot_required())
523 reboot_type = BOOT_EFI;
527 core_initcall(reboot_init);
529 static inline void kb_wait(void)
533 for (i = 0; i < 0x10000; i++) {
534 if ((inb(0x64) & 0x02) == 0)
540 static void vmxoff_nmi(int cpu, struct pt_regs *regs)
542 cpu_emergency_vmxoff();
545 /* Use NMIs as IPIs to tell all CPUs to disable virtualization */
546 static void emergency_vmx_disable_all(void)
548 /* Just make sure we won't change CPUs while doing this */
552 * Disable VMX on all CPUs before rebooting, otherwise we risk hanging
553 * the machine, because the CPU blocks INIT when it's in VMX root.
555 * We can't take any locks and we may be on an inconsistent state, so
556 * use NMIs as IPIs to tell the other CPUs to exit VMX root and halt.
558 * Do the NMI shootdown even if VMX if off on _this_ CPU, as that
559 * doesn't prevent a different CPU from being in VMX root operation.
562 /* Safely force _this_ CPU out of VMX root operation. */
563 __cpu_emergency_vmxoff();
565 /* Halt and exit VMX root operation on the other CPUs. */
566 nmi_shootdown_cpus(vmxoff_nmi);
572 void __attribute__((weak)) mach_reboot_fixups(void)
577 * To the best of our knowledge Windows compatible x86 hardware expects
578 * the following on reboot:
580 * 1) If the FADT has the ACPI reboot register flag set, try it
581 * 2) If still alive, write to the keyboard controller
582 * 3) If still alive, write to the ACPI reboot register again
583 * 4) If still alive, write to the keyboard controller again
584 * 5) If still alive, call the EFI runtime service to reboot
585 * 6) If no EFI runtime service, call the BIOS to do a reboot
587 * We default to following the same pattern. We also have
588 * two other reboot methods: 'triple fault' and 'PCI', which
589 * can be triggered via the reboot= kernel boot option or
592 * This means that this function can never return, it can misbehave
593 * by not rebooting properly and hanging.
595 static void native_machine_emergency_restart(void)
599 int orig_reboot_type = reboot_type;
602 if (reboot_emergency)
603 emergency_vmx_disable_all();
605 tboot_shutdown(TB_SHUTDOWN_REBOOT);
607 /* Tell the BIOS if we want cold or warm reboot */
608 mode = reboot_mode == REBOOT_WARM ? 0x1234 : 0;
609 *((unsigned short *)__va(0x472)) = mode;
612 * If an EFI capsule has been registered with the firmware then
613 * override the reboot= parameter.
615 if (efi_capsule_pending(NULL)) {
616 pr_info("EFI capsule is pending, forcing EFI reboot.\n");
617 reboot_type = BOOT_EFI;
621 /* Could also try the reset bit in the Hammer NB */
622 switch (reboot_type) {
625 reboot_type = BOOT_KBD;
629 mach_reboot_fixups(); /* For board specific fixups */
631 for (i = 0; i < 10; i++) {
634 outb(0xfe, 0x64); /* Pulse reset low */
637 if (attempt == 0 && orig_reboot_type == BOOT_ACPI) {
639 reboot_type = BOOT_ACPI;
641 reboot_type = BOOT_EFI;
646 efi_reboot(reboot_mode, NULL);
647 reboot_type = BOOT_BIOS;
651 machine_real_restart(MRR_BIOS);
653 /* We're probably dead after this, but... */
654 reboot_type = BOOT_CF9_SAFE;
658 port_cf9_safe = true;
663 u8 reboot_code = reboot_mode == REBOOT_WARM ? 0x06 : 0x0E;
664 u8 cf9 = inb(0xcf9) & ~reboot_code;
665 outb(cf9|2, 0xcf9); /* Request hard reset */
667 /* Actually do the reset */
668 outb(cf9|reboot_code, 0xcf9);
671 reboot_type = BOOT_TRIPLE;
676 __asm__ __volatile__("int3");
678 /* We're probably dead after this, but... */
679 reboot_type = BOOT_KBD;
685 void native_machine_shutdown(void)
687 /* Stop the cpus and apics */
688 #ifdef CONFIG_X86_IO_APIC
690 * Disabling IO APIC before local APIC is a workaround for
691 * erratum AVR31 in "Intel Atom Processor C2000 Product Family
692 * Specification Update". In this situation, interrupts that target
693 * a Logical Processor whose Local APIC is either in the process of
694 * being hardware disabled or software disabled are neither delivered
695 * nor discarded. When this erratum occurs, the processor may hang.
697 * Even without the erratum, it still makes sense to quiet IO APIC
698 * before disabling Local APIC.
705 * Stop all of the others. Also disable the local irq to
706 * not receive the per-cpu timer interrupt which may trigger
707 * scheduler's load balance.
715 #ifdef CONFIG_HPET_TIMER
720 x86_platform.iommu_shutdown();
724 static void __machine_emergency_restart(int emergency)
726 reboot_emergency = emergency;
727 machine_ops.emergency_restart();
730 static void native_machine_restart(char *__unused)
732 pr_notice("machine restart\n");
736 __machine_emergency_restart(0);
739 static void native_machine_halt(void)
741 /* Stop other cpus and apics */
744 tboot_shutdown(TB_SHUTDOWN_HALT);
749 static void native_machine_power_off(void)
756 /* A fallback in case there is no PM info available */
757 tboot_shutdown(TB_SHUTDOWN_HALT);
760 struct machine_ops machine_ops __ro_after_init = {
761 .power_off = native_machine_power_off,
762 .shutdown = native_machine_shutdown,
763 .emergency_restart = native_machine_emergency_restart,
764 .restart = native_machine_restart,
765 .halt = native_machine_halt,
766 #ifdef CONFIG_KEXEC_CORE
767 .crash_shutdown = native_machine_crash_shutdown,
771 void machine_power_off(void)
773 machine_ops.power_off();
776 void machine_shutdown(void)
778 machine_ops.shutdown();
781 void machine_emergency_restart(void)
783 __machine_emergency_restart(1);
786 void machine_restart(char *cmd)
788 machine_ops.restart(cmd);
791 void machine_halt(void)
796 #ifdef CONFIG_KEXEC_CORE
797 void machine_crash_shutdown(struct pt_regs *regs)
799 machine_ops.crash_shutdown(regs);
804 /* This is the CPU performing the emergency shutdown work. */
805 int crashing_cpu = -1;
807 #if defined(CONFIG_SMP)
809 static nmi_shootdown_cb shootdown_callback;
811 static atomic_t waiting_for_crash_ipi;
812 static int crash_ipi_issued;
814 static int crash_nmi_callback(unsigned int val, struct pt_regs *regs)
818 cpu = raw_smp_processor_id();
821 * Don't do anything if this handler is invoked on crashing cpu.
822 * Otherwise, system will completely hang. Crashing cpu can get
823 * an NMI if system was initially booted with nmi_watchdog parameter.
825 if (cpu == crashing_cpu)
829 shootdown_callback(cpu, regs);
831 atomic_dec(&waiting_for_crash_ipi);
832 /* Assume hlt works */
840 static void smp_send_nmi_allbutself(void)
842 apic->send_IPI_allbutself(NMI_VECTOR);
846 * Halt all other CPUs, calling the specified function on each of them
848 * This function can be used to halt all other CPUs on crash
849 * or emergency reboot time. The function passed as parameter
850 * will be called inside a NMI handler on all CPUs.
852 void nmi_shootdown_cpus(nmi_shootdown_cb callback)
857 /* Make a note of crashing cpu. Will be used in NMI callback. */
858 crashing_cpu = safe_smp_processor_id();
860 shootdown_callback = callback;
862 atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
863 /* Would it be better to replace the trap vector here? */
864 if (register_nmi_handler(NMI_LOCAL, crash_nmi_callback,
865 NMI_FLAG_FIRST, "crash"))
866 return; /* Return what? */
868 * Ensure the new callback function is set before sending
873 smp_send_nmi_allbutself();
875 /* Kick CPUs looping in NMI context. */
876 WRITE_ONCE(crash_ipi_issued, 1);
878 msecs = 1000; /* Wait at most a second for the other cpus to stop */
879 while ((atomic_read(&waiting_for_crash_ipi) > 0) && msecs) {
884 /* Leave the nmi callback set */
888 * Check if the crash dumping IPI got issued and if so, call its callback
889 * directly. This function is used when we have already been in NMI handler.
892 void run_crash_ipi_callback(struct pt_regs *regs)
894 if (crash_ipi_issued)
895 crash_nmi_callback(0, regs);
898 /* Override the weak function in kernel/panic.c */
899 void nmi_panic_self_stop(struct pt_regs *regs)
902 /* If no CPU is preparing crash dump, we simply loop here. */
903 run_crash_ipi_callback(regs);
908 #else /* !CONFIG_SMP */
909 void nmi_shootdown_cpus(nmi_shootdown_cb callback)
911 /* No other CPUs to shoot down */
914 void run_crash_ipi_callback(struct pt_regs *regs)