Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/xen: properly retrieve NMI reason

Using the native code here can't work properly, as the hypervisor would
normally have cleared the two reason bits by the time Dom0 gets to see
the NMI (if passed to it at all). There's a shared info field for this,
and there's an existing hook to use - just fit the two together. This
is particularly relevant so that NMIs intended to be handled by APEI /
GHES actually make it to the respective handler.

Note that the hook can (and should) be used irrespective of whether
being in Dom0, as accessing port 0x61 in a DomU would be even worse,
while the shared info field would just hold zero all the time. Note
further that hardware NMI handling for PVH doesn't currently work
anyway due to missing code in the hypervisor (but it is expected to
work the native rather than the PV way).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: David Vrabel <david.vrabel@citrix.com>

authored by

Jan Beulich and committed by
David Vrabel
f221b04f 9a17ad7f

+72 -1
+21 -1
arch/x86/xen/enlighten.c
··· 40 40 #include <xen/interface/physdev.h> 41 41 #include <xen/interface/vcpu.h> 42 42 #include <xen/interface/memory.h> 43 + #include <xen/interface/nmi.h> 43 44 #include <xen/interface/xen-mca.h> 44 45 #include <xen/features.h> 45 46 #include <xen/page.h> ··· 67 66 #include <asm/reboot.h> 68 67 #include <asm/stackprotector.h> 69 68 #include <asm/hypervisor.h> 69 + #include <asm/mach_traps.h> 70 70 #include <asm/mwait.h> 71 71 #include <asm/pci_x86.h> 72 72 #include <asm/pat.h> ··· 1359 1357 .emergency_restart = xen_emergency_restart, 1360 1358 }; 1361 1359 1360 + static unsigned char xen_get_nmi_reason(void) 1361 + { 1362 + unsigned char reason = 0; 1363 + 1364 + /* Construct a value which looks like it came from port 0x61. */ 1365 + if (test_bit(_XEN_NMIREASON_io_error, 1366 + &HYPERVISOR_shared_info->arch.nmi_reason)) 1367 + reason |= NMI_REASON_IOCHK; 1368 + if (test_bit(_XEN_NMIREASON_pci_serr, 1369 + &HYPERVISOR_shared_info->arch.nmi_reason)) 1370 + reason |= NMI_REASON_SERR; 1371 + 1372 + return reason; 1373 + } 1374 + 1362 1375 static void __init xen_boot_params_init_edd(void) 1363 1376 { 1364 1377 #if IS_ENABLED(CONFIG_EDD) ··· 1558 1541 pv_info = xen_info; 1559 1542 pv_init_ops = xen_init_ops; 1560 1543 pv_apic_ops = xen_apic_ops; 1561 - if (!xen_pvh_domain()) 1544 + if (!xen_pvh_domain()) { 1562 1545 pv_cpu_ops = xen_cpu_ops; 1546 + 1547 + x86_platform.get_nmi_reason = xen_get_nmi_reason; 1548 + } 1563 1549 1564 1550 if (xen_feature(XENFEAT_auto_translated_physmap)) 1565 1551 x86_init.resources.memory_setup = xen_auto_xlated_memory_setup;
+51
include/xen/interface/nmi.h
··· 1 + /****************************************************************************** 2 + * nmi.h 3 + * 4 + * NMI callback registration and reason codes. 5 + * 6 + * Copyright (c) 2005, Keir Fraser <keir@xensource.com> 7 + */ 8 + 9 + #ifndef __XEN_PUBLIC_NMI_H__ 10 + #define __XEN_PUBLIC_NMI_H__ 11 + 12 + #include <xen/interface/xen.h> 13 + 14 + /* 15 + * NMI reason codes: 16 + * Currently these are x86-specific, stored in arch_shared_info.nmi_reason. 17 + */ 18 + /* I/O-check error reported via ISA port 0x61, bit 6. */ 19 + #define _XEN_NMIREASON_io_error 0 20 + #define XEN_NMIREASON_io_error (1UL << _XEN_NMIREASON_io_error) 21 + /* PCI SERR reported via ISA port 0x61, bit 7. */ 22 + #define _XEN_NMIREASON_pci_serr 1 23 + #define XEN_NMIREASON_pci_serr (1UL << _XEN_NMIREASON_pci_serr) 24 + /* Unknown hardware-generated NMI. */ 25 + #define _XEN_NMIREASON_unknown 2 26 + #define XEN_NMIREASON_unknown (1UL << _XEN_NMIREASON_unknown) 27 + 28 + /* 29 + * long nmi_op(unsigned int cmd, void *arg) 30 + * NB. All ops return zero on success, else a negative error code. 31 + */ 32 + 33 + /* 34 + * Register NMI callback for this (calling) VCPU. Currently this only makes 35 + * sense for domain 0, vcpu 0. All other callers will be returned EINVAL. 36 + * arg == pointer to xennmi_callback structure. 37 + */ 38 + #define XENNMI_register_callback 0 39 + struct xennmi_callback { 40 + unsigned long handler_address; 41 + unsigned long pad; 42 + }; 43 + DEFINE_GUEST_HANDLE_STRUCT(xennmi_callback); 44 + 45 + /* 46 + * Deregister NMI callback for this (calling) VCPU. 47 + * arg == NULL. 48 + */ 49 + #define XENNMI_unregister_callback 1 50 + 51 + #endif /* __XEN_PUBLIC_NMI_H__ */