Skip to contentSkip to conversation

i386, x86_64: fix the irqbalance quirk for E7520/E7320/E7525

PATCH In review Siddha, Suresh B 2 participants 12 messages Nov 8, 2006 – Nov 11, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover i386, x86_64: fix the irqbalance quirk for E7520/E7320/E7525

Mechanism of selecting physical mode in genapic when cpu hotplug is enabled on x86_64, broke the quirk(quirk_intel_irqbalance()) introduced for working around the transposing interrupt message errata in E7520/E7320/E7525 (revision ID 0x9 and below. errata #23 in
http://download.intel.com/design/chipsets/specupdt/30304203.pdf).

This errata requires the mode to be in logical flat, so that interrupts can be directed to more than one cpu(and thus use hardware IRQ balancing enabled by BIOS on these platforms).

Following four patches fixes this by moving the quirk to early quirk and forcing the x86_64 genapic selection to logical flat on these platforms.

Thanks to Shaohua for pointing out the breakage.

#1 lore raw

PATCH 1/4 add write_pci_config_byte() to direct PCI access routines

Add write_pci_config_byte() to direct PCI access routines

---

arch/i386/pci/early.c +7 -0
index 713d6c8..42df4b6 100644
@@ -45,6 +45,13 @@ void write_pci_config(u8 bus, u8 slot, u
 	outl(val, 0xcfc);
 }
 
+void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val)
+{
+	PDprintk("%x writing to %x: %x\n", slot, offset, val);
+	outl(0x80000000 | (bus<<16) | (slot<<11) | (func<<8) | offset, 0xcf8);
+	outb(val, 0xcfc);
+}
+
 int early_pci_allowed(void)
 {
 	return (pci_probe & (PCI_PROBE_CONF1|PCI_PROBE_NOEARLY)) ==
include/asm-x86_64/pci-direct.h +1 -0
index eba9cb4..6823fa4 100644
@@ -10,6 +10,7 @@ extern u32 read_pci_config(u8 bus, u8 sl
 extern u8 read_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset);
 extern u16 read_pci_config_16(u8 bus, u8 slot, u8 func, u8 offset);
 extern void write_pci_config(u8 bus, u8 slot, u8 func, u8 offset, u32 val);
+extern void write_pci_config_byte(u8 bus, u8 slot, u8 func, u8 offset, u8 val);
 
 extern int early_pci_allowed(void);
 
#2 lore raw

Re: [patch 2/4] introduce the mechanism of disabling cpu hotplug control

Add 'cpu_hotplug_no_control' and when set, the hotplug control file("online") will not be added under /sys/devices/system/cpu/cpuX/

Next patch doing PCI quirks will use this.

---

arch/i386/kernel/topology.c +8 -0
index 07d6da3..9b766e7 100644
@@ -40,14 +40,22 @@ int arch_register_cpu(int num)
 	 * restrictions and assumptions in kernel. This basically
 	 * doesnt add a control file, one cannot attempt to offline
 	 * BSP.
+	 *
+	 * Also certain PCI quirks require to remove this control file
+	 * for all CPU's.
 	 */
+#ifdef CONFIG_HOTPLUG_CPU
+	if (!num || cpu_hotplug_no_control)
+#else
 	if (!num)
+#endif
 		cpu_devices[num].cpu.no_control = 1;
 
 	return register_cpu(&cpu_devices[num].cpu, num);
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
+int cpu_hotplug_no_control;
 
 void arch_unregister_cpu(int num) {
 	return unregister_cpu(&cpu_devices[num].cpu);
include/asm-i386/cpu.h +1 -0
index b1bc7b1..3c5da33 100644
@@ -13,6 +13,7 @@ struct i386_cpu {
 extern int arch_register_cpu(int num);
 #ifdef CONFIG_HOTPLUG_CPU
 extern void arch_unregister_cpu(int);
+extern int cpu_hotplug_no_control;
 #endif
 
 DECLARE_PER_CPU(int, cpu_state);
#3 lore raw

PATCH 3/4 x86_64: add genapic_force

Add genapic_force. Used by the next Intel quirks patch.

---

arch/x86_64/kernel/genapic.c +9 -1
index 8e78a75..236dc9e 100644
@@ -33,7 +33,7 @@ extern struct genapic apic_flat;
 extern struct genapic apic_physflat;
 
 struct genapic *genapic = &apic_flat;
-
+struct genapic *genapic_force;
 
 /*
  * Check the APIC IDs in bios_cpu_apicid and choose the APIC mode.
@@ -46,6 +46,14 @@ void __init clustered_apic_check(void)
 	u8 cluster_cnt[NUM_APIC_CLUSTERS];
 	int max_apic = 0;
 
+	/* genapic selection can be forced because of certain quirks and
+	 * in future perhaps user can select this through cmdline
+	 */
+	if (genapic_force) {
+		genapic = genapic_force;
+		goto print;
+	}
+
 #if defined(CONFIG_ACPI)
 	/*
 	 * Some x86_64 machines use physical APIC mode regardless of how many
include/asm-x86_64/genapic.h +1 -1
index a0e9a4b..b80f4bb 100644
@@ -30,6 +30,6 @@ struct genapic {
 };
 
 
-extern struct genapic *genapic;
+extern struct genapic *genapic, *genapic_force, apic_flat;
 
 #endif
#4 lore raw

PATCH 4/4 fix the irqbalance quirk for E7320/E7520/E7525

Move the irqbalance quirks for E7320/E7520/E7525(Errata 23 in
http://download.intel.com/design/chipsets/specupdt/30304203.pdf) to early quirks.

And add a PCI quirk for these platforms to check(which happens very late during the boot) if the APIC routing is indeed set to default flat mode.

This fixes the breakage(in x86_64) of this quirk due to cpu hotplug which selects physical mode instead of the logical flat(as needed for this errata workaround).

---

arch/i386/kernel/acpi/earlyquirk.c +21 -0
index fe799b1..4cdec39 100644
@@ -10,6 +10,7 @@ #include <linux/acpi.h>
 #include <asm/pci-direct.h>
 #include <asm/acpi.h>
 #include <asm/apic.h>
+#include <asm/irq.h>
 
 #ifdef CONFIG_ACPI
 
@@ -43,6 +44,24 @@ #endif
 	return 0;
 }
 
+static void check_intel(void)
+{
+	u16 vendor, device;
+
+	vendor = read_pci_config_16(0, 0, 0, PCI_VENDOR_ID);
+
+	if (vendor != PCI_VENDOR_ID_INTEL)
+		return;
+
+	device = read_pci_config_16(0, 0, 0, PCI_DEVICE_ID);
+#ifdef CONFIG_SMP
+	if (device == PCI_DEVICE_ID_INTEL_E7320_MCH ||
+	    device == PCI_DEVICE_ID_INTEL_E7520_MCH ||
+	    device == PCI_DEVICE_ID_INTEL_E7525_MCH)
+		quirk_intel_irqbalance();
+#endif
+}
+
 void __init check_acpi_pci(void)
 {
 	int num, slot, func;
@@ -54,6 +73,8 @@ void __init check_acpi_pci(void)
 	if (!early_pci_allowed())
 		return;
 
+	check_intel();
+
 	/* Poor man's PCI discovery */
 	for (num = 0; num < 32; num++) {
 		for (slot = 0; slot < 32; slot++) {
arch/i386/kernel/quirks.c +40 -11

81 lines not on this page · raw message

arch/i386/kernel/smpboot.c +8 -0
index 4bb8b77..79bc607 100644
@@ -52,6 +52,7 @@ #include <asm/tlbflush.h>
 #include <asm/desc.h>
 #include <asm/arch_hooks.h>
 #include <asm/nmi.h>
+#include <asm/genapic.h>
 
 #include <mach_apic.h>
 #include <mach_wakecpu.h>
@@ -1461,6 +1462,13 @@ #endif
 	cpu_set(cpu, smp_commenced_mask);
 	while (!cpu_isset(cpu, cpu_online_map))
 		cpu_relax();
+
+	if (num_online_cpus() > 8 && genapic == &apic_default) {
+		printk(KERN_WARNING
+		       "Default flat APIC routing can't be used with > 8 cpus\n");
+		BUG();
+	}
+
 	return 0;
 }
 
arch/x86_64/kernel/early-quirks.c +13 -0
index 2b1245d..a644663 100644
@@ -68,6 +68,18 @@ static void ati_bugs(void)
 	}
 }
 
+static void intel_bugs(void)
+{
+	u16 device = read_pci_config_16(0, 0, 0, PCI_DEVICE_ID);
+
+#ifdef CONFIG_SMP
+	if (device == PCI_DEVICE_ID_INTEL_E7320_MCH ||
+	    device == PCI_DEVICE_ID_INTEL_E7520_MCH ||
+	    device == PCI_DEVICE_ID_INTEL_E7525_MCH)
+		quirk_intel_irqbalance();
+#endif
+}
+
 struct chipset {
 	u16 vendor;
 	void (*f)(void);
@@ -77,6 +89,7 @@ static struct chipset early_qrk[] = {
 	{ PCI_VENDOR_ID_NVIDIA, nvidia_bugs },
 	{ PCI_VENDOR_ID_VIA, via_bugs },
 	{ PCI_VENDOR_ID_ATI, ati_bugs },
+	{ PCI_VENDOR_ID_INTEL, intel_bugs},
 	{}
 };
 
arch/x86_64/kernel/smpboot.c +8 -0
index 62c2e74..4c161c2 100644
@@ -60,6 +60,7 @@ #include <asm/nmi.h>
 #include <asm/irq.h>
 #include <asm/hw_irq.h>
 #include <asm/numa.h>
+#include <asm/genapic.h>
 
 /* Number of siblings per CPU package */
 int smp_num_siblings = 1;
@@ -1167,6 +1168,13 @@ int __cpuinit __cpu_up(unsigned int cpu)
 
 	while (!cpu_isset(cpu, cpu_online_map))
 		cpu_relax();
+
+	if (num_online_cpus() > 8 && genapic == &apic_flat) {
+		printk(KERN_WARNING
+		       "flat APIC routing can't be used with > 8 cpus\n");
+		BUG();
+	}
+
 	err = 0;
 
 	return err;
include/asm-i386/genapic.h +1 -1
index 8ffbb0f..fd2be59 100644
@@ -122,6 +122,6 @@ #define APIC_INIT(aname, aprobe) { \
 	APICFUNC(phys_pkg_id) \
 	}
 
-extern struct genapic *genapic;
+extern struct genapic *genapic, apic_default;
 
 #endif
include/asm-i386/irq.h +2 -0
index 331726b..c35dc8e 100644
@@ -37,6 +37,8 @@ #ifdef CONFIG_IRQBALANCE
 extern int irqbalance_disable(char *str);
 #endif
 
+extern void quirk_intel_irqbalance(void);
+
 #ifdef CONFIG_HOTPLUG_CPU
 extern void fixup_irqs(cpumask_t map);
 #endif
include/asm-x86_64/proto.h +1 -0
index e72cfcd..3b6a4ec 100644
@@ -88,6 +88,7 @@ extern void syscall32_cpu_init(void);
 extern void setup_node_bootmem(int nodeid, unsigned long start, unsigned long end);
 
 extern void early_quirks(void);
+extern void quirk_intel_irqbalance(void);
 extern void check_efer(void);
 
 extern int unhandled_signal(struct task_struct *tsk, int sig);
#5 lore raw

Re: [patch 2/4] introduce the mechanism of disabling cpu hotplug control

In reply to Siddha, Suresh B
Quoted 5 lines · Suresh B

Add 'cpu_hotplug_no_control' and when set, the hotplug control file("online") will not be added under /sys/devices/system/cpu/cpuX/

Next patch doing PCI quirks will use this.

I don't understand what this (ugly) patch has to do with the overall bugfix. We're fixing the APCI initialisation - what does that have to do with presenting cpu-hotplug files in sysfs?

Quoted 9 lines

---

arch/i386/kernel/topology.c +0 -0
index 07d6da3..9b766e7 100644
@@ -40,14 +40,22 @@ int arch_register_cpu(int num)
 	 * restrictions and assumptions in kernel. This basically
 	 * doesnt add a control file, one cannot attempt to offline

arch/i386/kernel/topology.c int arch_register_cpu(int num) · line 51

Quoted 10 lines
arch/i386/kernel/topology.c +7 -0
 	 * BSP.
+	 *
+	 * Also certain PCI quirks require to remove this control file
+	 * for all CPU's.
 	 */
+#ifdef CONFIG_HOTPLUG_CPU
+	if (!num || cpu_hotplug_no_control)
+#else
 	if (!num)
+#endif

This ifdef could be removed

Quoted 15 lines
arch/i386/kernel/topology.c +1 -0
 		cpu_devices[num].cpu.no_control = 1;
 
 	return register_cpu(&cpu_devices[num].cpu, num);
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
+int cpu_hotplug_no_control;
 
 void arch_unregister_cpu(int num) {
 	return unregister_cpu(&cpu_devices[num].cpu);
include/asm-i386/cpu.h +0 -0
index b1bc7b1..3c5da33 100644

include/asm-i386/cpu.h struct i386_cpu { · line 16

Quoted 4 lines
include/asm-i386/cpu.h +1 -0
@@ -13,6 +13,7 @@ struct i386_cpu {
 extern int arch_register_cpu(int num);
 #ifdef CONFIG_HOTPLUG_CPU
 extern void arch_unregister_cpu(int);
+extern int cpu_hotplug_no_control;

via:

#else
#define cpu_hotplug_no_control 1

here.

But does this variable _have_ to be a negative like this? The code would be simpler if it had the opposite sense and was called, say, cpu_hotplug_enable_control_file.

Are these patches considered 2.6.19 material? They look a bit big, ugly and scary for that.

#6 lore raw

Re: [patch 2/4] introduce the mechanism of disabling cpu hotplug control

Quoted 6 lines · Andrew Morton
Quoted 3 lines · Suresh B

Add 'cpu_hotplug_no_control' and when set, the hotplug control file("online") will not be added under /sys/devices/system/cpu/cpuX/

Quoted 6 lines
Quoted 2 lines

Next patch doing PCI quirks will use this.

I don't understand what this (ugly) patch has to do with the overall bugfix. We're fixing the APCI initialisation - what does that have to do with presenting cpu-hotplug files in sysfs?

This patch is adding a mechanism which will not export the cpu hotplug control file. And the quirk will use this from preventing the users doing cpu hotplug. On these platforms, we need to have atleast 2 cpus online to workaround the errata.

In future we can use this mechanism to disable cpu hotplug during bootup.

Quoted 3 lines

But does this variable _have_ to be a negative like this? The code would be simpler if it had the opposite sense and was called, say, cpu_hotplug_enable_control_file.

I wanted to add something like disable_cpu_hotplug.. but suspend code seems to be already using.. Will clean this up.

Quoted 2 lines

Are these patches considered 2.6.19 material? They look a bit big, ugly and scary for that.

Though no one reported failures so far, it would be good to get included in 2.6.19. If it is too late and sounds scary, we can consider in -stable after spending sometime in -mm..

thanks,
suresh

#7 lore raw

Re: [patch 2/4] introduce the mechanism of disabling cpu hotplug control

Quoted 1 line · Suresh B

I wanted to add something like disable_cpu_hotplug

My point is, `enable_cpu_hotplug' is nicer

	if (enable_cpu_hotplug)
		...
	if (!enable_cpu_hotplug)
		...

versus

	if (disable_cpu_hotplug)
		...
	if (!disable_cpu_hotplug)
		...			/* My brain hurts */
#8 lore raw

Re: [patch 2/4] introduce the mechanism of disabling cpu hotplug control

Quoted 6 lines · Andrew Morton
Quoted 1 line · Suresh B

I wanted to add something like disable_cpu_hotplug

My point is, `enable_cpu_hotplug' is nicer

Yep. I got it and hence my "will clean this up" assurance :)

This is all coming from the no_control' member in cpu structure and I will change that to something like hotpluggable'. That will make the patch slightly big but def clean.

thanks,
suresh

#9 lore raw

PATCH 1/1 change the 'no_control' field to 'hotpluggable' in the struct cpu

Quoted 5 lines · Suresh B
Quoted 4 lines · Andrew Morton
Quoted 1 line · Suresh B

I wanted to add something like disable_cpu_hotplug

Quoted 7 lines
Quoted 1 line

My point is, `enable_cpu_hotplug' is nicer

Yep. I got it and hence my "will clean this up" assurance :)

This is all coming from the no_control' member in cpu structure and I will change that to something like hotpluggable'. That will make the patch slightly big but def clean.

Andrew, Appended the cleanup patch which goes on top of your -mm tree. Please apply. Thanks.
---

Change the 'no_control' field in the cpu struct to a more positive and better term 'hotpluggable'. And change(/cleanup) the logic accordingly.

---

arch/i386/kernel/topology.c +2 -2
index 844c08f..79cf608 100644
@@ -44,8 +44,8 @@ int arch_register_cpu(int num)
 	 * Also certain PCI quirks require not to enable hotplug control
 	 * for all CPU's.
 	 */
-	if (!num || !enable_cpu_hotplug)
-		cpu_devices[num].cpu.no_control = 1;
+	if (num && enable_cpu_hotplug)
+		cpu_devices[num].cpu.hotpluggable = 1;
 
 	return register_cpu(&cpu_devices[num].cpu, num);
 }
arch/ia64/kernel/topology.c +4 -4
index 5629b45..687500d 100644
@@ -31,11 +31,11 @@ int arch_register_cpu(int num)
 {
 #if defined (CONFIG_ACPI) && defined (CONFIG_HOTPLUG_CPU)
 	/*
-	 * If CPEI cannot be re-targetted, and this is
-	 * CPEI target, then dont create the control file
+	 * If CPEI can be re-targetted or if this is not
+	 * CPEI target, then it is hotpluggable
 	 */
-	if (!can_cpei_retarget() && is_cpu_cpei_target(num))
-		sysfs_cpus[num].cpu.no_control = 1;
+	if (can_cpei_retarget() || !is_cpu_cpei_target(num))
+		sysfs_cpus[num].cpu.hotpluggable = 1;
 	map_cpu_to_node(num, node_cpuid[num].nid);
 #endif
 
arch/powerpc/kernel/sysfs.c +4 -4
index d45a168..bf65a15 100644
@@ -240,7 +240,7 @@ static void unregister_cpu_online(unsign
 	struct cpu *c = &per_cpu(cpu_devices, cpu);
 	struct sys_device *s = &c->sysdev;
 
-	BUG_ON(c->no_control);
+	BUG_ON(!c->hotpluggable);
 
 #ifndef CONFIG_PPC_ISERIES
 	if (cpu_has_feature(CPU_FTR_SMT))
@@ -360,10 +360,10 @@ static int __init topology_init(void)
 		 * CPU.  For instance, the boot cpu might never be valid
 		 * for hotplugging.
 		 */
-		if (!ppc_md.cpu_die)
-			c->no_control = 1;
+		if (ppc_md.cpu_die)
+			c->hotpluggable = 1;
 
-		if (cpu_online(cpu) || (c->no_control == 0)) {
+		if (cpu_online(cpu) || c->hotpluggable) {
 			register_cpu(c, cpu);
 
 			sysdev_create_file(&c->sysdev, &attr_physical_id);
drivers/base/cpu.c +3 -3
index 4bef76a..d00c67c 100644
@@ -103,8 +103,8 @@ #endif
 
 /*
  * register_cpu - Setup a driverfs device for a CPU.
- * @cpu - Callers can set the cpu->no_control field to 1, to indicate not to
- *		  generate a control file in sysfs for this CPU.
+ * @cpu - cpu->hotpluggable field set to 1 will generate a control file in
+ *	  sysfs for this CPU.
  * @num - CPU number to use when creating the device.
  *
  * Initialize and register the CPU device.
@@ -118,7 +118,7 @@ int __devinit register_cpu(struct cpu *c
 
 	error = sysdev_register(&cpu->sysdev);
 
-	if (!error && !cpu->no_control)
+	if (!error && cpu->hotpluggable)
 		register_cpu_control(cpu);
 	if (!error)
 		cpu_sys_devices[num] = &cpu->sysdev;
include/linux/cpu.h +1 -1
index 3fef7d6..a1fd791 100644
@@ -27,7 +27,7 @@ #include <asm/semaphore.h>
 
 struct cpu {
 	int node_id;		/* The node which contains the CPU */
-	int no_control;		/* Should the sysfs control file be created? */
+	int hotpluggable;	/* creates sysfs control file if hotpluggable */
 	struct sys_device sysdev;
 };
 
#10 lore raw
In reply to Siddha, Suresh B
Quoted 6 lines · Suresh B

Mechanism of selecting physical mode in genapic when cpu hotplug is enabled on x86_64, broke the quirk(quirk_intel_irqbalance()) introduced for working around the transposing interrupt message errata in E7520/E7320/E7525 (revision ID 0x9 and below. errata #23 in
http://download.intel.com/design/chipsets/specupdt/30304203.pdf).

Quoted 8 lines

This errata requires the mode to be in logical flat, so that interrupts can be directed to more than one cpu(and thus use hardware IRQ balancing enabled by BIOS on these platforms).

Following four patches fixes this by moving the quirk to early quirk and forcing the x86_64 genapic selection to logical flat on these platforms.

Thanks to Shaohua for pointing out the breakage.

It blew up with the first config I tried
(http://userweb.kernel.org/~akpm/config-vmm.txt):

arch/i386/kernel/built-in.o: In function `verify_quirk_intel_irqbalance':
arch/i386/kernel/quirks.c:19: undefined reference to genapic' arch/i386/kernel/quirks.c:19: undefined reference to apic_default' arch/i386/kernel/built-in.o: In function `__cpu_up':
arch/i386/kernel/smpboot.c:1487: undefined reference to genapic' arch/i386/kernel/smpboot.c:1487: undefined reference to apic_default'

The dependencies in the code which you're touching here are really really complex and fragile. One needs to review the change very carefully and test it exhaustively.

#11 lore raw
Quoted 10 lines · Andrew Morton

arch/i386/kernel/built-in.o: In function `verify_quirk_intel_irqbalance':
arch/i386/kernel/quirks.c:19: undefined reference to genapic' arch/i386/kernel/quirks.c:19: undefined reference to apic_default' arch/i386/kernel/built-in.o: In function `__cpu_up':
arch/i386/kernel/smpboot.c:1487: undefined reference to genapic' arch/i386/kernel/smpboot.c:1487: undefined reference to apic_default'

The dependencies in the code which you're touching here are really really complex and fragile. One needs to review the change very carefully and test it exhaustively.

oops. I did compile and boot with 6 x86/x86_64 configs.. Seems something is broken in my git test tree. Let me fix and getback to you.

thanks,
suresh