From: "Jan Beulich" Subject: [PATCH] x86: fix CMCI injection Date: Mon, 25 Feb 2013 16:49:26 +0000 Message-ID: <512BA42602000078000C0D64@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part82B2F506.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Jinsong Liu , Yongjie Ren 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. --=__Part82B2F506.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This fixes the wrong use of literal vector 0xF7 with an "int" instruction (invalidated by 25113:14609be41f36) and the fact that doing the injection via a software interrupt was never valid anyway (because cmci_interrupt() acks the LAPIC, which does the wrong thing if the interrupt didn't get delivered though it). In order to do latter, the patch introduces send_IPI_self(), at once removing two opend coded uses of "genapic" in the IRQ handling code. Reported-by: Yongjie Ren Signed-off-by: Jan Beulich --- a/xen/arch/x86/cpu/mcheck/mce.c +++ b/xen/arch/x86/cpu/mcheck/mce.c @@ -34,6 +34,7 @@ bool_t __read_mostly mce_broadcast =3D 0; bool_t is_mc_panic; unsigned int __read_mostly nr_mce_banks; unsigned int __read_mostly firstbank; +uint8_t __read_mostly cmci_apic_vector; =20 DEFINE_PER_CPU_READ_MOSTLY(struct mca_banks *, poll_bankmask); DEFINE_PER_CPU_READ_MOSTLY(struct mca_banks *, no_cmci_banks); @@ -1198,12 +1199,6 @@ static void x86_mc_mceinject(void *data) __asm__ __volatile__("int $0x12"); } =20 -static void x86_cmci_inject(void *data) -{ - printk("Simulating CMCI on cpu %d\n", smp_processor_id()); - __asm__ __volatile__("int $0xf7"); -} - #if BITS_PER_LONG =3D=3D 64 =20 #define ID2COOKIE(id) ((mctelem_cookie_t)(id)) @@ -1479,11 +1474,15 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_m on_selected_cpus(cpumap, x86_mc_mceinject, NULL, 1); break; case XEN_MC_INJECT_TYPE_CMCI: - if ( !cmci_support ) + if ( !cmci_apic_vector ) ret =3D x86_mcerr( "No CMCI supported in platform\n", -EINVAL); else - on_selected_cpus(cpumap, x86_cmci_inject, NULL, 1); + { + if ( cpumask_test_cpu(smp_processor_id(), cpumap) ) + send_IPI_self(cmci_apic_vector); + send_IPI_mask(cpumap, cmci_apic_vector); + } break; default: ret =3D x86_mcerr("Wrong mca type\n", -EINVAL); --- a/xen/arch/x86/cpu/mcheck/mce.h +++ b/xen/arch/x86/cpu/mcheck/mce.h @@ -37,6 +37,8 @@ enum mcheck_type { mcheck_intel }; =20 +extern uint8_t cmci_apic_vector; + /* Init functions */ enum mcheck_type amd_mcheck_init(struct cpuinfo_x86 *c); enum mcheck_type intel_mcheck_init(struct cpuinfo_x86 *c, bool_t bsp); --- a/xen/arch/x86/cpu/mcheck/mce_intel.c +++ b/xen/arch/x86/cpu/mcheck/mce_intel.c @@ -644,7 +644,6 @@ static void intel_init_cmci(struct cpuin { u32 l, apic; int cpu =3D smp_processor_id(); - static uint8_t cmci_apic_vector; =20 if (!mce_available(c) || !cmci_support) { if (opt_cpu_info) --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -646,7 +646,7 @@ void irq_move_cleanup_interrupt(struct c * to myself. */ if (irr & (1 << (vector % 32))) { - genapic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR); + send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR); TRACE_3D(TRC_HW_IRQ_MOVE_CLEANUP_DELAY, irq, vector, smp_processor_id()); goto unlock; @@ -692,7 +692,7 @@ static void send_cleanup_vector(struct i =20 cpumask_and(&cleanup_mask, desc->arch.old_cpu_mask, &cpu_online_map); desc->arch.move_cleanup_count =3D cpumask_weight(&cleanup_mask); - genapic->send_IPI_mask(&cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR); + send_IPI_mask(&cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR); =20 desc->arch.move_in_progress =3D 0; } --- a/xen/arch/x86/smp.c +++ b/xen/arch/x86/smp.c @@ -38,6 +38,11 @@ void send_IPI_mask(const cpumask_t *mask genapic->send_IPI_mask(mask, vector); } =20 +void send_IPI_self(int vector) +{ + genapic->send_IPI_self(vector); +} + /* * Some notes on x86 processor bugs affecting SMP operation: * --- a/xen/include/asm-x86/smp.h +++ b/xen/include/asm-x86/smp.h @@ -29,7 +29,8 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_ =20 void smp_send_nmi_allbutself(void); =20 -void send_IPI_mask(const cpumask_t *mask, int vector); +void send_IPI_mask(const cpumask_t *, int vector); +void send_IPI_self(int vector); =20 extern void (*mtrr_hook) (void); =20 --=__Part82B2F506.1__= Content-Type: text/plain; name="x86-CMCI-inject.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-CMCI-inject.patch" x86: fix CMCI injection=0A=0AThis fixes the wrong use of literal vector = 0xF7 with an "int"=0Ainstruction (invalidated by 25113:14609be41f36) and = the fact that doing=0Athe injection via a software interrupt was never = valid anyway (because=0Acmci_interrupt() acks the LAPIC, which does the = wrong thing if the=0Ainterrupt didn't get delivered though it).=0A=0AIn = order to do latter, the patch introduces send_IPI_self(), at once=0Aremovin= g two opend coded uses of "genapic" in the IRQ handling code.=0A=0AReported= -by: Yongjie Ren =0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/arch/x86/cpu/mcheck/mce.c=0A+++ = b/xen/arch/x86/cpu/mcheck/mce.c=0A@@ -34,6 +34,7 @@ bool_t __read_mostly = mce_broadcast =3D 0;=0A bool_t is_mc_panic;=0A unsigned int __read_mostly = nr_mce_banks;=0A unsigned int __read_mostly firstbank;=0A+uint8_t = __read_mostly cmci_apic_vector;=0A =0A DEFINE_PER_CPU_READ_MOSTLY(struct = mca_banks *, poll_bankmask);=0A DEFINE_PER_CPU_READ_MOSTLY(struct = mca_banks *, no_cmci_banks);=0A@@ -1198,12 +1199,6 @@ static void = x86_mc_mceinject(void *data)=0A __asm__ __volatile__("int $0x12");=0A = }=0A =0A-static void x86_cmci_inject(void *data)=0A-{=0A- printk("Simula= ting CMCI on cpu %d\n", smp_processor_id());=0A- __asm__ __volatile__("i= nt $0xf7");=0A-}=0A-=0A #if BITS_PER_LONG =3D=3D 64=0A =0A #define = ID2COOKIE(id) ((mctelem_cookie_t)(id))=0A@@ -1479,11 +1474,15 @@ long = do_mca(XEN_GUEST_HANDLE_PARAM(xen_m=0A on_selected_cpus(cpumap,= x86_mc_mceinject, NULL, 1);=0A break;=0A case = XEN_MC_INJECT_TYPE_CMCI:=0A- if ( !cmci_support )=0A+ = if ( !cmci_apic_vector )=0A ret =3D x86_mcerr(=0A = "No CMCI supported in platform\n", -EINVAL);=0A = else=0A- on_selected_cpus(cpumap, x86_cmci_inject, NULL, = 1);=0A+ {=0A+ if ( cpumask_test_cpu(smp_processor= _id(), cpumap) )=0A+ send_IPI_self(cmci_apic_vector);=0A= + send_IPI_mask(cpumap, cmci_apic_vector);=0A+ = }=0A break;=0A default:=0A ret =3D = x86_mcerr("Wrong mca type\n", -EINVAL);=0A--- a/xen/arch/x86/cpu/mcheck/mce= .h=0A+++ b/xen/arch/x86/cpu/mcheck/mce.h=0A@@ -37,6 +37,8 @@ enum = mcheck_type {=0A mcheck_intel=0A };=0A =0A+extern uint8_t cmci_apic_= vector;=0A+=0A /* Init functions */=0A enum mcheck_type amd_mcheck_init(str= uct cpuinfo_x86 *c);=0A enum mcheck_type intel_mcheck_init(struct = cpuinfo_x86 *c, bool_t bsp);=0A--- a/xen/arch/x86/cpu/mcheck/mce_intel.c=0A= +++ b/xen/arch/x86/cpu/mcheck/mce_intel.c=0A@@ -644,7 +644,6 @@ static = void intel_init_cmci(struct cpuin=0A {=0A u32 l, apic;=0A int cpu = =3D smp_processor_id();=0A- static uint8_t cmci_apic_vector;=0A =0A = if (!mce_available(c) || !cmci_support) {=0A if (opt_cpu_info)=0A--= - a/xen/arch/x86/irq.c=0A+++ b/xen/arch/x86/irq.c=0A@@ -646,7 +646,7 @@ = void irq_move_cleanup_interrupt(struct c=0A * to myself.=0A = */=0A if (irr & (1 << (vector % 32))) {=0A- = genapic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);=0A+ send_IPI_se= lf(IRQ_MOVE_CLEANUP_VECTOR);=0A TRACE_3D(TRC_HW_IRQ_MOVE_CLEANU= P_DELAY,=0A irq, vector, smp_processor_id());=0A = goto unlock;=0A@@ -692,7 +692,7 @@ static void send_cleanup_vector(s= truct i=0A =0A cpumask_and(&cleanup_mask, desc->arch.old_cpu_mask, = &cpu_online_map);=0A desc->arch.move_cleanup_count =3D cpumask_weight(&= cleanup_mask);=0A- genapic->send_IPI_mask(&cleanup_mask, IRQ_MOVE_CLEANU= P_VECTOR);=0A+ send_IPI_mask(&cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);=0A= =0A desc->arch.move_in_progress =3D 0;=0A }=0A--- a/xen/arch/x86/smp.c= =0A+++ b/xen/arch/x86/smp.c=0A@@ -38,6 +38,11 @@ void send_IPI_mask(const = cpumask_t *mask=0A genapic->send_IPI_mask(mask, vector);=0A }=0A = =0A+void send_IPI_self(int vector)=0A+{=0A+ genapic->send_IPI_self(vecto= r);=0A+}=0A+=0A /*=0A * Some notes on x86 processor bugs affecting = SMP operation:=0A *=0A--- a/xen/include/asm-x86/smp.h=0A+++ b/xen/include/= asm-x86/smp.h=0A@@ -29,7 +29,8 @@ DECLARE_PER_CPU(cpumask_var_t, = cpu_core_=0A =0A void smp_send_nmi_allbutself(void);=0A =0A-void = send_IPI_mask(const cpumask_t *mask, int vector);=0A+void send_IPI_mask(con= st cpumask_t *, int vector);=0A+void send_IPI_self(int vector);=0A =0A = extern void (*mtrr_hook) (void);=0A =0A --=__Part82B2F506.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.xen.org http://lists.xen.org/xen-devel --=__Part82B2F506.1__=--