Skip to contentSkip to conversation

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

tip: irq/urgent tip-bot2 for Marc Zyngier 1 participant 1 message Feb 20, 2023 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

tip-bot2 for Marc Zyngier

author merge bot Applied
#1 lore raw
In reply to a message not in the archive

The following commit has been merged into the irq/urgent branch of tip:

Commit-ID:     0af2795f936f1ea1f9f1497447145dfcc7ed2823
Gitweb:        https://git.kernel.org/tip/0af2795f936f1ea1f9f1497447145dfcc7ed2823
Author:        Marc Zyngier <[email protected]>
AuthorDate:    Mon, 20 Feb 2023 19:01:01 
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Mon, 20 Feb 2023 22:29:54 +01:00

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, in msi_domain_populate_irqs() the lock is taken right after having called msi_ctrl_valid(), which is just a tad too late.

Take the lock before invoking msi_ctrl_valid().

---
 kernel/irq/msi.c |  9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
kernel/irq/msi.c +6 -3
index 783a3e6..13d9649 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;