Skip to contentSkip to conversation

genirq/msi: Take the per-device MSI lock before validating the control structure

PATCH In review Marc Zyngier 2 participants 2 messages Feb 20, 2023

Subsystems (3)
lore
Share & tools
lore
Tested-by on v1 1/1
#1 lore raw
In reply to Marc Zyngier
Quoted 8 lines · Marc Zyngier

Calling msi_ctrl_valid() ultimately results in calling msi_get_device_domain(), which requires holding the device MSI lock.

However, we take that lock right after having called msi_ctrl_valid(), which is just a tad too late. Taking the lock earlier solves the issue.

Fixes 40742716f294 ("genirq/msi: Make msi_add_simple_msi_descs() device domain aware")

Thanks!

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#0 lore raw

PATCH 1/1 genirq/msi: Take the per-device MSI lock before validating the control structure

Calling msi_ctrl_valid() ultimately results in calling msi_get_device_domain(), which requires holding the device MSI lock.

However, we take that lock right after having called msi_ctrl_valid(), which is just a tad too late. Taking the lock earlier solves the issue.

Fixes 40742716f294 ("genirq/msi: Make msi_add_simple_msi_descs() device domain aware")
---
 kernel/irq/msi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
kernel/irq/msi.c +6 -3
index 783a3e6a0b10..13d96495e6d0 100644
@@ -1084,10 +1084,13 @@ int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev,
 	struct xarray *xa;
 	int ret, virq;
 
-	if (!msi_ctrl_valid(dev, &ctrl))
-		return -EINVAL;
-
 	msi_lock_descs(dev);
+
+	if (!msi_ctrl_valid(dev, &ctrl)) {
+		ret = -EINVAL;
+		goto unlock;
+	}
+
 	ret = msi_domain_add_simple_msi_descs(dev, &ctrl);
 	if (ret)
 		goto unlock;
Signature · 1 line
2.34.1