MCA injection (debug) code
PATCH 1/1 MCA injection (debug) code
The attached patch adds the capability for dom0 to inject MCA errors into Xen. The basic idea is to add specific MSR values that will be read by the polling code or the #MC handler. On AMD cpus, the MSRs can actually be written, on Intel CPUs, interpose code is used to fake the MSR values.
Since actual hardware problems are rare, it's convenient to be able to test the code like this. We run our testsuite using this code. Others have expressed some interest in this, so that's why I'm submitting this patch.
- Frank
Provide MCA "injection" hypervisor services.
xen/arch/x86/cpu/mcheck/amd_f10.c +3 -3
@@ -74,9 +74,9 @@ amd_f10_handler(struct mc_info *mi, uint mc_ext.mc_msr[1 ].reg =MSR_F10_MC4_MISC2 ; mc_ext.mc_msr[2 ].reg =MSR_F10_MC4_MISC3 ; -rdmsrl (MSR_F10_MC4_MISC1 , mc_ext.mc_msr[0 ].value); -rdmsrl (MSR_F10_MC4_MISC2 , mc_ext.mc_msr[1 ].value); -rdmsrl (MSR_F10_MC4_MISC3 , mc_ext.mc_msr[2 ].value); +mca_rdmsrl (MSR_F10_MC4_MISC1 , mc_ext.mc_msr[0 ].value); +mca_rdmsrl (MSR_F10_MC4_MISC2 , mc_ext.mc_msr[1 ].value); +mca_rdmsrl (MSR_F10_MC4_MISC3 , mc_ext.mc_msr[2 ].value);x86_mcinfo_add (mi, &mc_ext);return MCA_EXTINFO_LOCAL ;
xen/arch/x86/cpu/mcheck/amd_nonfatal.c +2 -2
@@ -147,7 +147,7 @@ static void mce_amd_work_fn(void *data)uint64_t value;uint32_t counter; -rdmsrl (MSR_IA32_MC4_MISC , value); +mca_rdmsrl (MSR_IA32_MC4_MISC , value);/* Only the error counter field is of interest * Bit field is described in AMD K8 BKDG chapter 6.4.5.5 */
@@ -172,7 +172,7 @@ static void mce_amd_work_fn(void *data) value &= ~(0x60FFF00000000ULL );/* Counter enable */ value |= (1ULL <<51 ); -wrmsrl (MSR_IA32_MC4_MISC , value); +mca_wrmsrl (MSR_IA32_MC4_MISC , value);wmb (); } }
xen/arch/x86/cpu/mcheck/mce.c +265 -9
353 lines not on this page · raw message
xen/arch/x86/cpu/mcheck/mce.h +17 -0
@@ -41,6 +41,23 @@ extern void x86_mce_vector_register(x86_/* Common generic MCE handler that implementations may nominate * via x86_mce_vector_register. */ extern void mcheck_cmn_handler (struct cpu_user_regs *,long ,cpu_banks_t ); + +/* Read an MSR, checking for an interposed value first */ +extern struct intpose_ent *intpose_lookup (unsigned int ,uint64_t , +uint64_t *); +extern void intpose_inval (unsigned int ,uint64_t ); + +#define mca_rdmsrl (msr, var) do { \ + if (intpose_lookup(smp_processor_id(), msr, &var) == NULL) \ + rdmsrl(msr, var); \ +} while (0) + +/* Write an MSR, invalidating any interposed value */ +#define mca_wrmsrl (msr, val) do { \ + intpose_inval(smp_processor_id(), msr); \ + wrmsrl(msr, val); \ +} while (0) +/* Utility function to "logout" all architectural MCA telemetry from the MCA * banks of the current processor. A cookie is returned which may be
xen/include/public/arch-x86/xen-mca.h +21 -0
@@ -324,10 +324,31 @@ struct xen_mc_physcpuinfo {XEN_GUEST_HANDLE (xen_mc_logical_cpu_t) info; }; +#define XEN_MC_msrinject 4 +#define MC_MSRINJ_MAXMSRS 8 +struct xen_mc_msrinject { +/* IN */ +unsigned int mcinj_cpunr;/* target processor id */ +uint32_t mcinj_flags;/* see MC_MSRINJ_F_* below */ +uint32_t mcinj_count;/* 0 .. count-1 in array are valid */ +uint32_t mcinj_pad0; +struct mcinfo_msr mcinj_msr[MC_MSRINJ_MAXMSRS ]; +}; + +/* Flags for mcinj_flags above; bits 16-31 are reserved */ +#define MC_MSRINJ_F_INTERPOSE 0x1 + +#define XEN_MC_mceinject 5 +struct xen_mc_mceinject { +unsigned int mceinj_cpunr;/* target processor id */ +}; +typedef union {struct xen_mc_fetch mc_fetch;struct xen_mc_notifydomain mc_notifydomain;struct xen_mc_physcpuinfo mc_physcpuinfo; +struct xen_mc_msrinject mc_msrinject; +struct xen_mc_mceinject mc_mceinject; }xen_mc_arg_t ;struct xen_mc {
xen/include/xen/lib.h +1 -0
@@ -95,6 +95,7 @@ unsigned long long parse_size_and_unit(c#define TAINT_MACHINE_CHECK (1<<1)#define TAINT_BAD_PAGE (1<<2)#define TAINT_SYNC_CONSOLE (1<<3) +#define TAINT_ERROR_INJECT (1<<4)extern int tainted;#define TAINT_STRING_MAX_LEN 20extern char *print_tainted (char *str);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 5 lines · Frank van der Linden
The attached patch adds the capability for dom0 to inject MCA errors into Xen. The basic idea is to add specific MSR values that will be read by the polling code or the #MC handler. On AMD cpus, the MSRs can actually be written, on Intel CPUs, interpose code is used to fake the MSR values.
Since actual hardware problems are rare, it's convenient to be able to test the code like this. We run our testsuite using this code. Others have expressed some interest in this, so that's why I'm submitting this patch.
- Frank
Btw, this patch is on top of the main patch, but since that one is a bit big, it looks like it's stuck in the mailing list queue (probably waiting for approval).
- Frank