From: "Jan Beulich" Subject: [PATCH] x86/mcheck: do not blindly de-reference dom0 et al Date: Tue, 16 Feb 2010 11:53:11 +0000 Message-ID: <4B7A9537020000780002F9A1@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartE9C3D537.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Yunhong Jiang List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartE9C3D537.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Since machine checks and CMCIs can happen before Dom0 even gets constructed, the handlers of these events have to avoid de-referencing respective pointers without checking. Signed-off-by: Jan Beulich --- 2010-02-09.orig/xen/arch/x86/cpu/mcheck/amd_nonfatal.c 2010-01-13 = 18:58:11.000000000 +0100 +++ 2010-02-09/xen/arch/x86/cpu/mcheck/amd_nonfatal.c 2010-02-16 = 12:08:51.000000000 +0100 @@ -84,12 +84,9 @@ static void mce_amd_checkregs(void *info { mctelem_cookie_t mctc; struct mca_summary bs; - unsigned int event_enabled; =20 mctc =3D mcheck_mca_logout(MCA_POLLER, mca_allbanks, &bs, NULL); =20 - event_enabled =3D guest_enabled_event(dom0->vcpu[0], VIRQ_MCA); - if (bs.errcnt && mctc !=3D NULL) { static uint64_t dumpcount =3D 0; =20 @@ -101,7 +98,7 @@ static void mce_amd_checkregs(void *info * a simple-minded attempt to avoid spamming the console * for corrected errors in early startup. */ =20 - if (event_enabled) { + if (dom0_vmce_enabled()) { mctelem_commit(mctc); send_guest_global_virq(dom0, VIRQ_MCA); } else if (++dumpcount >=3D 10) { @@ -136,7 +133,7 @@ static void mce_amd_work_fn(void *data) on_each_cpu(mce_amd_checkregs, data, 1); =20 if (adjust > 0) { - if (!guest_enabled_event(dom0->vcpu[0], VIRQ_MCA) ) { + if (!dom0_vmce_enabled()) { /* Dom0 did not enable VIRQ_MCA, so Xen is = reporting. */ printk("MCE: polling routine found correctable = error. " " Use mcelog to parse above error = output.\n"); --- 2010-02-09.orig/xen/arch/x86/cpu/mcheck/mce.c 2010-02-09 = 09:00:50.000000000 +0100 +++ 2010-02-09/xen/arch/x86/cpu/mcheck/mce.c 2010-02-16 12:17:29.0000000= 00 +0100 @@ -414,7 +414,7 @@ void mcheck_cmn_handler(struct cpu_user_ * as terminal for any context. */ ctx_xen =3D SEG_PL(regs->cs) =3D=3D 0; - ctx_dom0 =3D !ctx_xen && (domid =3D=3D dom0->domain_id); + ctx_dom0 =3D !ctx_xen && (domid =3D=3D 0); ctx_domU =3D !ctx_xen && !ctx_dom0; =20 xen_state_lost =3D bs.uc !=3D 0 || (ctx_xen && (bs.pcc || !ripv)) = || @@ -463,7 +463,8 @@ void mcheck_cmn_handler(struct cpu_user_ * XXFM Could add some Solaris dom0 contract kill here? */ if (dom0_state_lost) { - if (guest_has_trap_callback(dom0, 0, TRAP_machine_check)) = { + if (dom0 && dom0->max_vcpus && dom0->vcpu[0] && + guest_has_trap_callback(dom0, 0, TRAP_machine_check)) = { dom_state =3D DOM0_TRAP; send_guest_trap(dom0, 0, TRAP_machine_check); /* XXFM case of return with !ripv ??? */ @@ -532,7 +533,7 @@ cmn_handler_done: if (bs.errcnt) { /* Not panicing, so forward telemetry to dom0 now if it * is interested. */ - if (guest_enabled_event(dom0->vcpu[0], VIRQ_MCA)) { + if (dom0_vmce_enabled()) { if (mctc !=3D NULL) mctelem_commit(mctc); send_guest_global_virq(dom0, VIRQ_MCA); --- 2010-02-09.orig/xen/arch/x86/cpu/mcheck/mce.h 2010-02-03 = 16:15:15.000000000 +0100 +++ 2010-02-09/xen/arch/x86/cpu/mcheck/mce.h 2010-02-16 12:32:26.0000000= 00 +0100 @@ -55,6 +55,8 @@ void mc_panic(char *s); void x86_mc_get_cpu_info(unsigned, uint32_t *, uint16_t *, uint16_t *, uint32_t *, uint32_t *, uint32_t *, uint32_t *); =20 +#define dom0_vmce_enabled() (dom0 && dom0->max_vcpus && dom0->vcpu[0] \ + && guest_enabled_event(dom0->vcpu[0], VIRQ_MCA)) =20 /* Register a handler for machine check exceptions. */ typedef void (*x86_mce_vector_t)(struct cpu_user_regs *, long); --- 2010-02-09.orig/xen/arch/x86/cpu/mcheck/mce_intel.c 2010-02-09 = 09:16:49.000000000 +0100 +++ 2010-02-09/xen/arch/x86/cpu/mcheck/mce_intel.c 2010-02-16 = 12:11:40.000000000 +0100 @@ -518,7 +518,7 @@ static void mce_softirq(void) } =20 /* Step2: Send Log to DOM0 through vIRQ */ - if (dom0 && guest_enabled_event(dom0->vcpu[0], VIRQ_MCA)) { + if (dom0_vmce_enabled()) { mce_printk(MCE_VERBOSE, "MCE: send MCE# to DOM0 through = virq\n"); send_guest_global_virq(dom0, VIRQ_MCA); } @@ -863,7 +863,7 @@ static void cmci_discover(void) MCA_CMCI_HANDLER, __get_cpu_var(mce_banks_owned), &bs, NULL); =20 if (bs.errcnt && mctc !=3D NULL) { - if (guest_enabled_event(dom0->vcpu[0], VIRQ_MCA)) { + if (dom0_vmce_enabled()) { mctelem_commit(mctc); send_guest_global_virq(dom0, VIRQ_MCA); } else { @@ -978,7 +978,7 @@ fastcall void smp_cmci_interrupt(struct=20 MCA_CMCI_HANDLER, __get_cpu_var(mce_banks_owned), &bs, NULL); =20 if (bs.errcnt && mctc !=3D NULL) { - if (guest_enabled_event(dom0->vcpu[0], VIRQ_MCA)) { + if (dom0_vmce_enabled()) { mctelem_commit(mctc); mce_printk(MCE_VERBOSE, "CMCI: send CMCI to DOM0 through = virq\n"); send_guest_global_virq(dom0, VIRQ_MCA); --- 2010-02-09.orig/xen/arch/x86/cpu/mcheck/non-fatal.c 2010-01-13 = 18:58:11.000000000 +0100 +++ 2010-02-09/xen/arch/x86/cpu/mcheck/non-fatal.c 2010-02-16 = 12:09:10.000000000 +0100 @@ -53,7 +53,7 @@ static void mce_checkregs (void *info) * for corrected errors in early startup. */ =20 - if (guest_enabled_event(dom0->vcpu[0], VIRQ_MCA)) { + if (dom0_vmce_enabled()) { mctelem_commit(mctc); send_guest_global_virq(dom0, VIRQ_MCA); } else if (++dumpcount >=3D 10) { --=__PartE9C3D537.1__= Content-Type: text/plain; name="x86-mce-dom0-check.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-mce-dom0-check.patch" Since machine checks and CMCIs can happen before Dom0 even gets=0Aconstruct= ed, the handlers of these events have to avoid de-referencing=0Arespective = pointers without checking.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- 2010-02-09.orig/xen/arch/x86/cpu/mcheck/amd_nonfatal.c = 2010-01-13 18:58:11.000000000 +0100=0A+++ 2010-02-09/xen/arch/x86/cpu/mchec= k/amd_nonfatal.c 2010-02-16 12:08:51.000000000 +0100=0A@@ -84,12 = +84,9 @@ static void mce_amd_checkregs(void *info=0A {=0A mctelem_coo= kie_t mctc;=0A struct mca_summary bs;=0A- unsigned int event_enabled;= =0A =0A mctc =3D mcheck_mca_logout(MCA_POLLER, mca_allbanks, &bs, = NULL);=0A =0A- event_enabled =3D guest_enabled_event(dom0->vcpu[0], = VIRQ_MCA);=0A-=0A if (bs.errcnt && mctc !=3D NULL) {=0A = static uint64_t dumpcount =3D 0;=0A =0A@@ -101,7 +98,7 @@ static void = mce_amd_checkregs(void *info=0A * a simple-minded attempt = to avoid spamming the console=0A * for corrected errors in = early startup. */=0A =0A- if (event_enabled) {=0A+ = if (dom0_vmce_enabled()) {=0A mctelem_commit(mctc);=0A = send_guest_global_virq(dom0, VIRQ_MCA);=0A } = else if (++dumpcount >=3D 10) {=0A@@ -136,7 +133,7 @@ static void = mce_amd_work_fn(void *data)=0A on_each_cpu(mce_amd_checkregs, data, = 1);=0A =0A if (adjust > 0) {=0A- if (!guest_enabled_event(do= m0->vcpu[0], VIRQ_MCA) ) {=0A+ if (!dom0_vmce_enabled()) {=0A = /* Dom0 did not enable VIRQ_MCA, so Xen is reporting. */=0A = printk("MCE: polling routine found correctable error. "=0A = " Use mcelog to parse above error output.\n");=0A--- = 2010-02-09.orig/xen/arch/x86/cpu/mcheck/mce.c 2010-02-09 09:00:50.0000000= 00 +0100=0A+++ 2010-02-09/xen/arch/x86/cpu/mcheck/mce.c 2010-02-16 = 12:17:29.000000000 +0100=0A@@ -414,7 +414,7 @@ void mcheck_cmn_handler(stru= ct cpu_user_=0A * as terminal for any context.=0A */=0A = ctx_xen =3D SEG_PL(regs->cs) =3D=3D 0;=0A- ctx_dom0 =3D !ctx_xen && = (domid =3D=3D dom0->domain_id);=0A+ ctx_dom0 =3D !ctx_xen && (domid = =3D=3D 0);=0A ctx_domU =3D !ctx_xen && !ctx_dom0;=0A =0A xen_state_l= ost =3D bs.uc !=3D 0 || (ctx_xen && (bs.pcc || !ripv)) ||=0A@@ -463,7 = +463,8 @@ void mcheck_cmn_handler(struct cpu_user_=0A * XXFM Could add = some Solaris dom0 contract kill here?=0A */=0A if (dom0_state_lost= ) {=0A- if (guest_has_trap_callback(dom0, 0, TRAP_machine_check)) = {=0A+ if (dom0 && dom0->max_vcpus && dom0->vcpu[0] &&=0A+ = guest_has_trap_callback(dom0, 0, TRAP_machine_check)) {=0A = dom_state =3D DOM0_TRAP;=0A send_guest_trap(dom0, 0, = TRAP_machine_check);=0A /* XXFM case of return = with !ripv ??? */=0A@@ -532,7 +533,7 @@ cmn_handler_done:=0A if = (bs.errcnt) {=0A /* Not panicing, so forward telemetry to = dom0 now if it=0A * is interested. */=0A- if = (guest_enabled_event(dom0->vcpu[0], VIRQ_MCA)) {=0A+ if = (dom0_vmce_enabled()) {=0A if (mctc !=3D NULL)=0A = mctelem_commit(mctc);=0A send_guest_= global_virq(dom0, VIRQ_MCA);=0A--- 2010-02-09.orig/xen/arch/x86/cpu/mcheck/= mce.h 2010-02-03 16:15:15.000000000 +0100=0A+++ 2010-02-09/xen/arch/x86/c= pu/mcheck/mce.h 2010-02-16 12:32:26.000000000 +0100=0A@@ -55,6 +55,8 @@ = void mc_panic(char *s);=0A void x86_mc_get_cpu_info(unsigned, uint32_t *, = uint16_t *, uint16_t *,=0A uint32_t *, uint32_t *, = uint32_t *, uint32_t *);=0A =0A+#define dom0_vmce_enabled() (dom0 && = dom0->max_vcpus && dom0->vcpu[0] \=0A+ && guest_enabled_event(dom0->vcpu[0= ], VIRQ_MCA))=0A =0A /* Register a handler for machine check exceptions. = */=0A typedef void (*x86_mce_vector_t)(struct cpu_user_regs *, long);=0A---= 2010-02-09.orig/xen/arch/x86/cpu/mcheck/mce_intel.c 2010-02-09 = 09:16:49.000000000 +0100=0A+++ 2010-02-09/xen/arch/x86/cpu/mcheck/mce_intel= .c 2010-02-16 12:11:40.000000000 +0100=0A@@ -518,7 +518,7 @@ static = void mce_softirq(void)=0A }=0A =0A /* Step2: Send Log to = DOM0 through vIRQ */=0A- if (dom0 && guest_enabled_event(dom0->vcpu[= 0], VIRQ_MCA)) {=0A+ if (dom0_vmce_enabled()) {=0A = mce_printk(MCE_VERBOSE, "MCE: send MCE# to DOM0 through virq\n");=0A = send_guest_global_virq(dom0, VIRQ_MCA);=0A }=0A@@ -863,7 = +863,7 @@ static void cmci_discover(void)=0A MCA_CMCI_HANDLER, = __get_cpu_var(mce_banks_owned), &bs, NULL);=0A =0A if (bs.errcnt && = mctc !=3D NULL) {=0A- if (guest_enabled_event(dom0->vcpu[0], = VIRQ_MCA)) {=0A+ if (dom0_vmce_enabled()) {=0A = mctelem_commit(mctc);=0A send_guest_global_virq(dom0, = VIRQ_MCA);=0A } else {=0A@@ -978,7 +978,7 @@ fastcall void = smp_cmci_interrupt(struct =0A MCA_CMCI_HANDLER, __get_cpu_var(mce_b= anks_owned), &bs, NULL);=0A =0A if (bs.errcnt && mctc !=3D NULL) {=0A- = if (guest_enabled_event(dom0->vcpu[0], VIRQ_MCA)) {=0A+ if = (dom0_vmce_enabled()) {=0A mctelem_commit(mctc);=0A = mce_printk(MCE_VERBOSE, "CMCI: send CMCI to DOM0 through virq\n");=0A = send_guest_global_virq(dom0, VIRQ_MCA);=0A--- 2010-02-09.orig/xen/a= rch/x86/cpu/mcheck/non-fatal.c 2010-01-13 18:58:11.000000000 +0100=0A+++ = 2010-02-09/xen/arch/x86/cpu/mcheck/non-fatal.c 2010-02-16 12:09:10.0000000= 00 +0100=0A@@ -53,7 +53,7 @@ static void mce_checkregs (void *info)=0A = * for corrected errors in early startup.=0A */=0A =0A- = if (guest_enabled_event(dom0->vcpu[0], VIRQ_MCA)) {=0A+ if = (dom0_vmce_enabled()) {=0A mctelem_commit(mctc);=0A = send_guest_global_virq(dom0, VIRQ_MCA);=0A } = else if (++dumpcount >=3D 10) {=0A --=__PartE9C3D537.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__PartE9C3D537.1__=--