From: "Jan Beulich" Subject: [PATCH] x86/ioapic: Add register level checks to detect bogus io-apic entries Date: Tue, 17 Apr 2012 13:49:32 +0100 Message-ID: <4F8D82FC020000780007E7BE@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part002ECFCC.0__=" 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 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. --=__Part002ECFCC.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline With the recent changes to clear_IO_APIC_pin() which tries to clear remoteIRR bit explicitly, some of the users started to see "Unable to reset IRR for apic .." messages. Close look shows that these are related to bogus IO-APIC entries which returns all 1s for their io-apic registers. And the above mentioned error messages are benign. But kernel should have ignored such io-apic's in the first place. Check if register 0, 1, 2 of the listed io-apic are all 1s and ignore such io-apic. [original Linux patch:] Signed-off-by: Suresh Siddha Signed-off-by: Jan Beulich --- a/xen/arch/x86/io_apic.c +++ b/xen/arch/x86/io_apic.c @@ -185,7 +185,7 @@ struct IO_APIC_route_entry **alloc_ioapi ioapic_entries[apic] =3D xmalloc_array(struct IO_APIC_route_entry, nr_ioapic_entries[apic]); - if (!ioapic_entries[apic]) + if (!ioapic_entries[apic] && nr_ioapic_entries[apic]) goto nomem; } =20 @@ -310,6 +310,9 @@ int save_IO_APIC_setup(struct IO_APIC_ro return -ENOMEM; =20 for (apic =3D 0; apic < nr_ioapics; apic++) { + if (!nr_ioapic_entries[apic]) + continue; + if (!ioapic_entries[apic]) return -ENOMEM; =20 @@ -331,6 +334,9 @@ void mask_IO_APIC_setup(struct IO_APIC_r return; =20 for (apic =3D 0; apic < nr_ioapics; apic++) { + if (!nr_ioapic_entries[apic]) + continue; + if (!ioapic_entries[apic]) break; =20 @@ -358,6 +364,9 @@ int restore_IO_APIC_setup(struct IO_APIC return -ENOMEM; =20 for (apic =3D 0; apic < nr_ioapics; apic++) { + if (!nr_ioapic_entries[apic]) + continue; + if (!ioapic_entries[apic]) return -ENOMEM; =20 @@ -610,6 +619,8 @@ static int __init find_isa_irq_apic(int=20 if (i < mp_irq_entries) { int apic; for(apic =3D 0; apic < nr_ioapics; apic++) { + if (!nr_ioapic_entries[apic]) + continue; if (mp_ioapics[apic].mpc_apicid =3D=3D mp_irqs[i].mpc_dstapic)= return apic; } @@ -1080,6 +1091,8 @@ static void /*__init*/ __print_IO_APIC(v printk(KERN_INFO "testing the IO APIC.......................\n"); =20 for (apic =3D 0; apic < nr_ioapics; apic++) { + if (!nr_ioapic_entries[apic]) + continue; =20 spin_lock_irqsave(&ioapic_lock, flags); reg_00.raw =3D io_apic_read(apic, 0); @@ -1229,6 +1242,8 @@ static void __init enable_IO_APIC(void) =20 if (directed_eoi_enabled) { for (apic =3D 0; apic < nr_ioapics; apic++) { + if (!nr_ioapic_entries[apic]) + continue; vector_map[apic] =3D xzalloc(vmask_t); BUG_ON(!vector_map[apic]); } @@ -1354,6 +1369,8 @@ static void __init setup_ioapic_ids_from * Set the IOAPIC ID to the value stored in the MPC table. */ for (apic =3D 0; apic < nr_ioapics; apic++) { + if (!nr_ioapic_entries[apic]) + continue; =20 /* Read the register 0 value */ spin_lock_irqsave(&ioapic_lock, flags); @@ -2038,6 +2055,8 @@ void ioapic_resume(void) =20 spin_lock_irqsave(&ioapic_lock, flags); for (apic =3D 0; apic < nr_ioapics; apic++){ + if (!nr_ioapic_entries[apic]) + continue; reg_00.raw =3D __io_apic_read(apic, 0); if (reg_00.bits.ID !=3D mp_ioapics[apic].mpc_apicid) { reg_00.bits.ID =3D mp_ioapics[apic].mpc_apicid; @@ -2225,8 +2244,12 @@ static int ioapic_physbase_to_id(unsigne { int apic; for ( apic =3D 0; apic < nr_ioapics; apic++ ) + { + if ( !nr_ioapic_entries[apic] ) + continue; if ( mp_ioapics[apic].mpc_apicaddr =3D=3D physbase ) return apic; + } return -EINVAL; } =20 @@ -2444,6 +2467,22 @@ void dump_ioapic_irq_info(void) static unsigned int __initdata max_gsi_irqs; integer_param("max_gsi_irqs", max_gsi_irqs); =20 +static __init bool_t bad_ioapic_register(unsigned int idx) +{ + union IO_APIC_reg_00 reg_00 =3D { .raw =3D io_apic_read(idx, 0) }; + union IO_APIC_reg_01 reg_01 =3D { .raw =3D io_apic_read(idx, 1) }; + union IO_APIC_reg_02 reg_02 =3D { .raw =3D io_apic_read(idx, 2) }; + + if ( reg_00.raw =3D=3D -1 && reg_01.raw =3D=3D -1 && reg_02.raw = =3D=3D -1 ) + { + printk(KERN_WARNING "I/O APIC %#x registers return all ones, = skipping!\n", + mp_ioapics[idx].mpc_apicaddr); + return 1; + } + + return 0; +} + void __init init_ioapic_mappings(void) { unsigned long ioapic_phys; @@ -2477,6 +2516,12 @@ void __init init_ioapic_mappings(void) __fix_to_virt(idx), ioapic_phys); idx++; =20 + if ( bad_ioapic_register(i) ) + { + __set_fixmap(idx, 0, 0); + continue; + } + if ( smp_found_config ) { /* The number of IO-APIC IRQ registers (=3D=3D #pins): */ --=__Part002ECFCC.0__= Content-Type: text/plain; name="x86-ioapic-ignore-bogus.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-ioapic-ignore-bogus.patch" x86/ioapic: Add register level checks to detect bogus io-apic entries=0A=0A= With the recent changes to clear_IO_APIC_pin() which tries to=0Aclear = remoteIRR bit explicitly, some of the users started to see=0A"Unable to = reset IRR for apic .." messages.=0A=0AClose look shows that these are = related to bogus IO-APIC entries=0Awhich returns all 1s for their io-apic = registers. And the=0Aabove mentioned error messages are benign. But kernel = should=0Ahave ignored such io-apic's in the first place.=0A=0ACheck if = register 0, 1, 2 of the listed io-apic are all 1s and=0Aignore such = io-apic.=0A=0A[original Linux patch:]=0ASigned-off-by: Suresh Siddha = =0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/io_apic.c=0A+++ b/xen/arch/x86/io_apic.c=0A@@ = -185,7 +185,7 @@ struct IO_APIC_route_entry **alloc_ioapi=0A = ioapic_entries[apic] =3D=0A xmalloc_array(struct IO_APIC_route_= entry,=0A nr_ioapic_entries[apic]);=0A- = if (!ioapic_entries[apic])=0A+ if (!ioapic_entries[apic] && = nr_ioapic_entries[apic])=0A goto nomem;=0A }=0A =0A@@ = -310,6 +310,9 @@ int save_IO_APIC_setup(struct IO_APIC_ro=0A = return -ENOMEM;=0A =0A for (apic =3D 0; apic < nr_ioapics; apic++) = {=0A+ if (!nr_ioapic_entries[apic])=0A+ continue;=0A+=0A = if (!ioapic_entries[apic])=0A return -ENOMEM;=0A =0A@@ = -331,6 +334,9 @@ void mask_IO_APIC_setup(struct IO_APIC_r=0A = return;=0A =0A for (apic =3D 0; apic < nr_ioapics; apic++) {=0A+ = if (!nr_ioapic_entries[apic])=0A+ continue;=0A+=0A if = (!ioapic_entries[apic])=0A break;=0A =0A@@ -358,6 +364,9 @@ = int restore_IO_APIC_setup(struct IO_APIC=0A return -ENOMEM;=0A =0A = for (apic =3D 0; apic < nr_ioapics; apic++) {=0A+ if (!nr_ioapic= _entries[apic])=0A+ continue;=0A+=0A if (!ioapic_entries= [apic])=0A return -ENOMEM;=0A =0A@@ -610,6 +619,8 @@ static = int __init find_isa_irq_apic(int =0A if (i < mp_irq_entries) {=0A = int apic;=0A for(apic =3D 0; apic < nr_ioapics; apic++) {=0A+ = if (!nr_ioapic_entries[apic])=0A+ continue;=0A = if (mp_ioapics[apic].mpc_apicid =3D=3D mp_irqs[i].mpc_dstapic)=0A = return apic;=0A }=0A@@ -1080,6 +1091,8 @@ static = void /*__init*/ __print_IO_APIC(v=0A printk(KERN_INFO "testing the IO = APIC.......................\n");=0A =0A for (apic =3D 0; apic < = nr_ioapics; apic++) {=0A+ if (!nr_ioapic_entries[apic])=0A+ = continue;=0A =0A spin_lock_irqsave(&ioapic_lock, flags);=0A = reg_00.raw =3D io_apic_read(apic, 0);=0A@@ -1229,6 +1242,8 @@ static void = __init enable_IO_APIC(void)=0A =0A if (directed_eoi_enabled) {=0A = for (apic =3D 0; apic < nr_ioapics; apic++) {=0A+ if = (!nr_ioapic_entries[apic])=0A+ continue;=0A = vector_map[apic] =3D xzalloc(vmask_t);=0A BUG_ON(!vector_map[ap= ic]);=0A }=0A@@ -1354,6 +1369,8 @@ static void __init setup_ioapic_= ids_from=0A * Set the IOAPIC ID to the value stored in the MPC = table.=0A */=0A for (apic =3D 0; apic < nr_ioapics; apic++) {=0A+ = if (!nr_ioapic_entries[apic])=0A+ continue;=0A =0A = /* Read the register 0 value */=0A spin_lock_irqsave(&ioapic_lock= , flags);=0A@@ -2038,6 +2055,8 @@ void ioapic_resume(void)=0A =0A = spin_lock_irqsave(&ioapic_lock, flags);=0A for (apic =3D 0; apic < = nr_ioapics; apic++){=0A+ if (!nr_ioapic_entries[apic])=0A+ = continue;=0A reg_00.raw =3D __io_apic_read(apic, 0);=0A = if (reg_00.bits.ID !=3D mp_ioapics[apic].mpc_apicid) {=0A = reg_00.bits.ID =3D mp_ioapics[apic].mpc_apicid;=0A@@ -2225,8 +2244,12 @@ = static int ioapic_physbase_to_id(unsigne=0A {=0A int apic;=0A for = ( apic =3D 0; apic < nr_ioapics; apic++ )=0A+ {=0A+ if ( = !nr_ioapic_entries[apic] )=0A+ continue;=0A if ( = mp_ioapics[apic].mpc_apicaddr =3D=3D physbase )=0A return = apic;=0A+ }=0A return -EINVAL;=0A }=0A =0A@@ -2444,6 +2467,22 @@ = void dump_ioapic_irq_info(void)=0A static unsigned int __initdata = max_gsi_irqs;=0A integer_param("max_gsi_irqs", max_gsi_irqs);=0A =0A+static= __init bool_t bad_ioapic_register(unsigned int idx)=0A+{=0A+ union = IO_APIC_reg_00 reg_00 =3D { .raw =3D io_apic_read(idx, 0) };=0A+ union = IO_APIC_reg_01 reg_01 =3D { .raw =3D io_apic_read(idx, 1) };=0A+ union = IO_APIC_reg_02 reg_02 =3D { .raw =3D io_apic_read(idx, 2) };=0A+=0A+ if = ( reg_00.raw =3D=3D -1 && reg_01.raw =3D=3D -1 && reg_02.raw =3D=3D -1 = )=0A+ {=0A+ printk(KERN_WARNING "I/O APIC %#x registers return = all ones, skipping!\n",=0A+ mp_ioapics[idx].mpc_apicaddr);=0A= + return 1;=0A+ }=0A+=0A+ return 0;=0A+}=0A+=0A void __init = init_ioapic_mappings(void)=0A {=0A unsigned long ioapic_phys;=0A@@ = -2477,6 +2516,12 @@ void __init init_ioapic_mappings(void)=0A = __fix_to_virt(idx), ioapic_phys);=0A idx++;=0A =0A+ = if ( bad_ioapic_register(i) )=0A+ {=0A+ __set_fixmap(idx,= 0, 0);=0A+ continue;=0A+ }=0A+=0A if ( = smp_found_config )=0A {=0A /* The number of IO-APIC = IRQ registers (=3D=3D #pins): */=0A --=__Part002ECFCC.0__= 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 --=__Part002ECFCC.0__=--