Skip to contentSkip to conversation

acpi: fix generic acpi_register_gsi() handling of shared interrupts

PATCH In review Mark Salter 2 participants 3 messages Apr 28, 2015 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 acpi: fix generic acpi_register_gsi() handling of shared interrupts

If there are devices sharing an interrupt, acpi_register_gsi() could be called multiple times for the same gsi. Currently, it just maps the gsi without checking for a previous mapping. This patch adds a check for an existing mapping and uses that if found.

Cc Hanjun Guo <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Will Deacon <[email protected]>
---
 drivers/acpi/gsi.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/acpi/gsi.c +7 -0
index 38208f2..5698c4f 100644
@@ -76,6 +76,13 @@ int acpi_register_gsi(struct device *dev, u32 gsi, int trigger,
 	unsigned int irq_type = acpi_gsi_get_irq_type(trigger, polarity);
 
 	/*
+	 * The gsi may be shared with other devices, so check for a
+	 * previous mapping and use that if found.
+	 */
+	if (acpi_gsi_to_irq(gsi, &irq) > 0)
+		return irq;
+
+	/*
 	 * There is no way at present to look-up the IRQ domain on ACPI,
 	 * hence always create mapping referring to the default domain
 	 * by passing NULL as irq_domain parameter
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 19 lines · Mark Salter

If there are devices sharing an interrupt, acpi_register_gsi() could be called multiple times for the same gsi. Currently, it just maps the gsi without checking for a previous mapping. This patch adds a check for an existing mapping and uses that if found.

Cc Hanjun Guo <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Will Deacon <[email protected]>
---
 drivers/acpi/gsi.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/acpi/gsi.c +0 -0
index 38208f2..5698c4f 100644

drivers/acpi/gsi.c int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, · line 83

Quoted 8 lines
drivers/acpi/gsi.c +5 -0
@@ -76,6 +76,13 @@ int acpi_register_gsi(struct device *dev, u32 gsi, int trigger,
 	unsigned int irq_type = acpi_gsi_get_irq_type(trigger, polarity);
 
 	/*
+	 * The gsi may be shared with other devices, so check for a
+	 * previous mapping and use that if found.
+	 */
+	if (acpi_gsi_to_irq(gsi, &irq) > 0)
+		return irq;

I'm afraid that's completely racy, and doesn't prevent much (two CPUs can execute this at the same time and still end up executing the rest of the code).

Furthermore, irq_create_mapping is *designed* to handle that situation, and returns the same virtual IRQ for a given hwirq (and it has the proper locking...).

So maybe it would be worth explaining the actual problem you're seeing, because the code as it stands should handle the problem you seem to describe.

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#2 lore raw
Quoted 33 lines · Marc Zyngier
Quoted 19 lines · Mark Salter

If there are devices sharing an interrupt, acpi_register_gsi() could be called multiple times for the same gsi. Currently, it just maps the gsi without checking for a previous mapping. This patch adds a check for an existing mapping and uses that if found.

Cc Hanjun Guo <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Cc Will Deacon <[email protected]>
---
 drivers/acpi/gsi.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/acpi/gsi.c +0 -0
index 38208f2..5698c4f 100644

drivers/acpi/gsi.c int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, · line 83

Quoted 8 lines
drivers/acpi/gsi.c +5 -0
@@ -76,6 +76,13 @@ int acpi_register_gsi(struct device *dev, u32 gsi, int trigger,
 	unsigned int irq_type = acpi_gsi_get_irq_type(trigger, polarity);
 
 	/*
+	 * The gsi may be shared with other devices, so check for a
+	 * previous mapping and use that if found.
+	 */
+	if (acpi_gsi_to_irq(gsi, &irq) > 0)
+		return irq;

I'm afraid that's completely racy, and doesn't prevent much (two CPUs can execute this at the same time and still end up executing the rest of the code).

Quoted 1 line

Furthermore, irq_create_mapping is *designed* to handle that situation,

You're right. irq_create_mapping does that check already. But if it is truly racy, irq_create_mapping has the same problem.

Quoted 6 lines

and returns the same virtual IRQ for a given hwirq (and it has the proper locking...).

So maybe it would be worth explaining the actual problem you're seeing, because the code as it stands should handle the problem you seem to describe.

Sorry for the noise. I was experimenting with some other code in acpi_register_gsi which called __irq_domain_alloc_irqs directly which bypassed the check in irq_create_mapping. And that turns out to be a silly thing to do anyway, so nevermind.