Skip to contentSkip to conversation

x86: ioapic needs check attr when programmed more than once

PATCH New Liu Ping Fan 2 participants 2 messages Aug 23, 2013 – Aug 26, 2013

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

PATCH 1/1 x86: ioapic needs check attr when programmed more than once

When programming ioapic pinX more than once, current code does not check whether the later attr (trigger&polarity) is the same as the former or not. This causes a broken semantic.

This can be observed in qemu q35 machine, where ioapic's ioredtbl[x] can never be set as low-active, even if the hpet driver registered it. And hpet driver may share a high-level active IRQ line with other device. So in qemu, when hpet-dev asserts low-level as kernel expects, the kernel has no response. With this patch, we can observe an ioredtbl[x] set as low-active for hpet.

Fix it by reporting -EBUSY to the caller, when attr is different.

---
 arch/x86/kernel/acpi/boot.c    | 5 ++++-
 arch/x86/kernel/apic/io_apic.c | 7 ++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
arch/x86/kernel/acpi/boot.c +4 -1
index 230c8ea..9ef2ce9 100644
@@ -1113,6 +1113,7 @@ int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
 	int ioapic;
 	int ioapic_pin;
 	struct io_apic_irq_attr irq_attr;
+	int ret;
 
 	if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
 		return gsi;
@@ -1142,7 +1143,9 @@ int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
 	set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
 			     trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
 			     polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
-	io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
+	ret = io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
+	if (ret < 0)
+		gsi = INT_MIN;
 
 	return gsi;
 }
arch/x86/kernel/apic/io_apic.c +6 -1
index 9ed796c..ce31d902 100644
@@ -3375,12 +3375,17 @@ int io_apic_setup_irq_pin_once(unsigned int irq, int node,
 {
 	unsigned int ioapic_idx = attr->ioapic, pin = attr->ioapic_pin;
 	int ret;
+	struct IO_APIC_route_entry orig;
 
 	/* Avoid redundant programming */
 	if (test_bit(pin, ioapics[ioapic_idx].pin_programmed)) {
 		pr_debug("Pin %d-%d already programmed\n",
 			 mpc_ioapic_id(ioapic_idx), pin);
-		return 0;
+		orig = ioapic_read_entry(attr->ioapic, pin);
+		if (attr->trigger == orig.trigger &&
+			attr->polarity == orig.polarity)
+			return 0;
+		return -EBUSY;
 	}
 	ret = io_apic_setup_irq_pin(irq, node, attr);
 	if (!ret)
Signature · 1 line
1.8.1.4
#1 lore raw

[tip:x86/apic] x86/ioapic: Check attr against the previous setting when programmed more than once

x86/ioapic: Check attr against the previous setting when programmed more than once
Commit-ID:  25aa2957973d361081ac6c8b6e5a0d9d7a83fef6
Gitweb:     http://git.kernel.org/tip/25aa2957973d361081ac6c8b6e5a0d9d7a83fef6
Author:     Liu Ping Fan <[email protected]>
AuthorDate: Fri, 23 Aug 2013 16:58:47 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 26 Aug 2013 12:58:00 +0200

x86/ioapic: Check attr against the previous setting when programmed more than once

When programming ioapic pinX more than once, current code does not check whether the later attr (trigger & polarity) is the same as the former or not.

This causes broken semantics which can be observed in a qemu q35 machine, where ioapic's ioredtbl[x] can never be set as low-active, even if the hpet driver registered it.

And hpet driver may share a high-level active IRQ line with other devices. So in qemu, when hpet-dev asserts low-level as kernel expects, the kernel has no response.

With this patch, we can observe an ioredtbl[x] set as low-active for hpet.

Fix it by reporting -EBUSY to the caller, when attr is different.

Cc Kevin Hao <[email protected]>
Cc Len Brown <[email protected]>
Cc Yinghai Lu <[email protected]>
[ Made small readability edits to both the changelog and the code. ]
---
 arch/x86/kernel/acpi/boot.c    | 5 ++++-
 arch/x86/kernel/apic/io_apic.c | 9 ++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)
arch/x86/kernel/acpi/boot.c +4 -1
index 872a2d2..81aa73b 100644
@@ -1120,6 +1120,7 @@ int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
 	int ioapic;
 	int ioapic_pin;
 	struct io_apic_irq_attr irq_attr;
+	int ret;
 
 	if (acpi_irq_model != ACPI_IRQ_MODEL_IOAPIC)
 		return gsi;
@@ -1149,7 +1150,9 @@ int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
 	set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
 			     trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
 			     polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
-	io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
+	ret = io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
+	if (ret < 0)
+		gsi = INT_MIN;
 
 	return gsi;
 }
arch/x86/kernel/apic/io_apic.c +6 -3
index 260abc2..e63a5bd 100644
@@ -3380,12 +3380,15 @@ int io_apic_setup_irq_pin_once(unsigned int irq, int node,
 {
 	unsigned int ioapic_idx = attr->ioapic, pin = attr->ioapic_pin;
 	int ret;
+	struct IO_APIC_route_entry orig_entry;
 
 	/* Avoid redundant programming */
 	if (test_bit(pin, ioapics[ioapic_idx].pin_programmed)) {
-		pr_debug("Pin %d-%d already programmed\n",
-			 mpc_ioapic_id(ioapic_idx), pin);
-		return 0;
+		pr_debug("Pin %d-%d already programmed\n", mpc_ioapic_id(ioapic_idx), pin);
+		orig_entry = ioapic_read_entry(attr->ioapic, pin);
+		if (attr->trigger == orig_entry.trigger && attr->polarity == orig_entry.polarity)
+			return 0;
+		return -EBUSY;
 	}
 	ret = io_apic_setup_irq_pin(irq, node, attr);
 	if (!ret)