debuggers.hg

view xen/arch/x86/cpu/mcheck/mce.h @ 20908:7310235f74f8

x86 mca: Not GP fault when guest write non 0s or 1s to MCA CTL MSRs.

a) For Mci_CTL MSR, Guest can write any value to it. When read back,
it will be ANDed with the physical value. Some bit in physical value
can be 0, either because read-only in hardware (like masked by AMD's
Mci_CTL_MASK), or because Xen didn't enable it.
If guest write some bit as 0, while that bit is 1 in host, we will
not inject MCE corresponding that bank to guest, as we can't
distinguish if the MCE is caused by the guest-cleared bit.

b) For MCG_CTL MSR, guest can write any value to it. When read back,
it will be ANDed with the physical value.
If guest does not write all 1s. In mca_ctl_conflict(), we simply
not inject any vMCE to guest if some bit is set in physical MSR
while is cleared in guest 's vMCG_CTL MSR.

Signed-off-by: Jiang, Yunhong <yunhong.jiang@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jan 29 06:48:00 2010 +0000 (2010-01-29)
parents c7ee30ba186d
children 088f1b01d852
line source
1 #ifndef _MCE_H
3 #define _MCE_H
5 #include <xen/init.h>
6 #include <xen/smp.h>
7 #include <asm/types.h>
8 #include <asm/traps.h>
9 #include <asm/atomic.h>
10 #include <asm/percpu.h>
12 #include "x86_mca.h"
13 #include "mctelem.h"
15 #define MCE_QUIET 0
16 #define MCE_VERBOSE 1
18 extern int mce_verbosity;
19 /* Define the default level of machine check related print.
20 * When set mce_verbosity=verbose, all mce debug information
21 * will be printed, otherwise, those information will not be
22 * printed.
23 */
24 #define mce_printk(v, s, a...) do { \
25 if ((v) <= mce_verbosity) \
26 printk(s, ##a); \
27 } while (0)
30 /* Init functions */
31 int amd_k7_mcheck_init(struct cpuinfo_x86 *c);
32 int amd_k8_mcheck_init(struct cpuinfo_x86 *c);
33 int amd_f10_mcheck_init(struct cpuinfo_x86 *c);
35 int intel_mcheck_init(struct cpuinfo_x86 *c);
37 void intel_mcheck_timer(struct cpuinfo_x86 *c);
38 void mce_intel_feature_init(struct cpuinfo_x86 *c);
39 void amd_nonfatal_mcheck_init(struct cpuinfo_x86 *c);
41 u64 mce_cap_init(void);
42 extern int firstbank;
43 int mca_ctl_conflict(struct mcinfo_bank *bank, struct domain *d);
45 int intel_mce_rdmsr(uint32_t msr, uint64_t *val);
46 int intel_mce_wrmsr(uint32_t msr, uint64_t val);
48 int mce_available(struct cpuinfo_x86 *c);
49 int mce_firstbank(struct cpuinfo_x86 *c);
50 /* Helper functions used for collecting error telemetry */
51 struct mc_info *x86_mcinfo_getptr(void);
52 void mc_panic(char *s);
53 void x86_mc_get_cpu_info(unsigned, uint32_t *, uint16_t *, uint16_t *,
54 uint32_t *, uint32_t *, uint32_t *, uint32_t *);
57 /* Register a handler for machine check exceptions. */
58 typedef void (*x86_mce_vector_t)(struct cpu_user_regs *, long);
59 extern void x86_mce_vector_register(x86_mce_vector_t);
61 /* Common generic MCE handler that implementations may nominate
62 * via x86_mce_vector_register. */
63 extern void mcheck_cmn_handler(struct cpu_user_regs *, long, cpu_banks_t);
65 /* Register a handler for judging whether mce is recoverable. */
66 typedef int (*mce_recoverable_t)(u64 status);
67 extern void mce_recoverable_register(mce_recoverable_t);
69 /* Read an MSR, checking for an interposed value first */
70 extern struct intpose_ent *intpose_lookup(unsigned int, uint64_t,
71 uint64_t *);
72 extern void intpose_inval(unsigned int, uint64_t);
74 #define mca_rdmsrl(msr, var) do { \
75 if (intpose_lookup(smp_processor_id(), msr, &var) == NULL) \
76 rdmsrl(msr, var); \
77 } while (0)
79 /* Write an MSR, invalidating any interposed value */
80 #define mca_wrmsrl(msr, val) do { \
81 intpose_inval(smp_processor_id(), msr); \
82 wrmsrl(msr, val); \
83 } while (0)
86 /* Utility function to "logout" all architectural MCA telemetry from the MCA
87 * banks of the current processor. A cookie is returned which may be
88 * uses to reference the data so logged (the cookie can be NULL if
89 * no logout structures were available). The caller can also pass a pointer
90 * to a structure which will be completed with some summary information
91 * of the MCA data observed in the logout operation. */
93 enum mca_source {
94 MCA_MCE_HANDLER,
95 MCA_POLLER,
96 MCA_CMCI_HANDLER,
97 MCA_RESET,
98 MCA_MCE_SCAN
99 };
101 enum mca_extinfo {
102 MCA_EXTINFO_LOCAL,
103 MCA_EXTINFO_GLOBAL,
104 MCA_EXTINFO_IGNORED
105 };
107 struct mca_summary {
108 uint32_t errcnt; /* number of banks with valid errors */
109 int ripv; /* meaningful on #MC */
110 int eipv; /* meaningful on #MC */
111 uint32_t uc; /* bitmask of banks with UC */
112 uint32_t pcc; /* bitmask of banks with PCC */
113 /* bitmask of banks with software error recovery ability*/
114 uint32_t recoverable;
115 };
117 extern cpu_banks_t mca_allbanks;
118 void set_poll_bankmask(struct cpuinfo_x86 *c);
119 DECLARE_PER_CPU(cpu_banks_t, poll_bankmask);
120 DECLARE_PER_CPU(cpu_banks_t, no_cmci_banks);
121 extern int cmci_support;
122 extern int ser_support;
123 extern int is_mc_panic;
124 extern void mcheck_mca_clearbanks(cpu_banks_t);
126 extern mctelem_cookie_t mcheck_mca_logout(enum mca_source, cpu_banks_t,
127 struct mca_summary *, cpu_banks_t*);
129 /* Register a callback to be made during bank telemetry logout.
130 * This callback is only available to those machine check handlers
131 * that call to the common mcheck_cmn_handler or who use the common
132 * telemetry logout function mcheck_mca_logout in error polling.
133 *
134 * This can be used to collect additional information (typically non-
135 * architectural) provided by newer CPU families/models without the need
136 * to duplicate the whole handler resulting in various handlers each with
137 * its own tweaks and bugs. The callback receives an struct mc_info pointer
138 * which it can use with x86_mcinfo_add to add additional telemetry,
139 * the current MCA bank number we are reading telemetry from, and the
140 * MCi_STATUS value for that bank.
141 */
143 /* Register a handler for judging whether the bank need to be cleared */
144 typedef int (*mce_need_clearbank_t)(enum mca_source who, u64 status);
145 extern void mce_need_clearbank_register(mce_need_clearbank_t);
147 typedef enum mca_extinfo (*x86_mce_callback_t)
148 (struct mc_info *, uint16_t, uint64_t);
149 extern void x86_mce_callback_register(x86_mce_callback_t);
151 int x86_mcinfo_add(struct mc_info *mi, void *mcinfo);
152 void x86_mcinfo_dump(struct mc_info *mi);
154 #endif /* _MCE_H */