Skip to contentSkip to conversation

irqchip: crossbar: Fix data race in allocate_gic_irq

RFC PATCH Superseded Bhargav Joshi 2 participants 5 messages Jun 9 – Jun 10 irqchip drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 irqchip: crossbar: Fix data race in allocate_gic_irq

In allocate_gic_irq(), if irq_domain_alloc_irqs_parent() fails, the error path resets cb->irq_map[i] to IRQ_FREE. It modifies cb->irq_map[] without holding cb->lock. modifying without lock could cause data race.

Fix this by acquiring raw_spin_lock around cb->irq_map[] modification.

Fixes 783d31863fb8 ("irqchip: crossbar: Convert dra7 crossbar to stacked domains")

---
This bug was flagged by the Sashiko AI bot during the review process for the DT schema conversion of ti,irq-crossbar binding.
https://lore.kernel.org/linux-devicetree/[email protected]/

---
 drivers/irqchip/irq-crossbar.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-crossbar.c +4 -1
index cd1134101ace..9b809e711009 100644
@@ -100,8 +100,11 @@ static int allocate_gic_irq(struct irq_domain *domain, unsigned virq,
 	fwspec.param[2] = IRQ_TYPE_LEVEL_HIGH;
 
 	err = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
-	if (err)
+	if (err) {
+		raw_spin_lock(&cb->lock);
 		cb->irq_map[i] = IRQ_FREE;
+		raw_spin_lock(&cb->lock);
+	}
 	else
 		cb->write(i, hwirq);
 

---
base-commit: 2d3090a8aeb596a26935db0955d46c9a5db5c6ce
change-id: 20260610-irq-spinlock-fix-1c90d8bc0f13

Best regards,

Signature · 1 line
Bhargav
#1 lore raw
Quoted 23 lines · Bhargav Joshi

In allocate_gic_irq(), if irq_domain_alloc_irqs_parent() fails, the error path resets cb->irq_map[i] to IRQ_FREE. It modifies cb->irq_map[] without holding cb->lock. modifying without lock could cause data race.

Fix this by acquiring raw_spin_lock around cb->irq_map[] modification.

Fixes 783d31863fb8 ("irqchip: crossbar: Convert dra7 crossbar to stacked domains")

---
This bug was flagged by the Sashiko AI bot during the review process for the DT schema conversion of ti,irq-crossbar binding.
https://lore.kernel.org/linux-devicetree/[email protected]/

---
 drivers/irqchip/irq-crossbar.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-crossbar.c +0 -0
index cd1134101ace..9b809e711009 100644

drivers/irqchip/irq-crossbar.c static int allocate_gic_irq(struct irq_domain *domain, unsigned virq, · line 106

Quoted 8 lines
drivers/irqchip/irq-crossbar.c +3 -1
@@ -100,8 +100,11 @@ static int allocate_gic_irq(struct irq_domain *domain, unsigned virq,
 	fwspec.param[2] = IRQ_TYPE_LEVEL_HIGH;
 
 	err = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
-	if (err)
+	if (err) {
+		raw_spin_lock(&cb->lock);
 		cb->irq_map[i] = IRQ_FREE;
+		raw_spin_lock(&cb->lock);

Really?

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#2 lore raw
Quoted 28 lines · Marc Zyngier
Quoted 25 lines · Bhargav Joshi

In allocate_gic_irq(), if irq_domain_alloc_irqs_parent() fails, the error path resets cb->irq_map[i] to IRQ_FREE. It modifies cb->irq_map[] without holding cb->lock. modifying without lock could cause data race.

Fix this by acquiring raw_spin_lock around cb->irq_map[] modification.

Fixes 783d31863fb8 ("irqchip: crossbar: Convert dra7 crossbar to stacked domains")

---
This bug was flagged by the Sashiko AI bot during the review process for the DT schema conversion of ti,irq-crossbar binding.
https://lore.kernel.org/linux-devicetree/[email protected]/

---
 drivers/irqchip/irq-crossbar.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-crossbar.c +0 -0
index cd1134101ace..9b809e711009 100644
@@ -100,8 +100,11 @@ static int allocate_gic_irq(struct irq_domain *domain, unsigned virq,
      fwspec.param[2] = IRQ_TYPE_LEVEL_HIGH;
 
Quoted 9 lines

drivers/irqchip/irq-crossbar.c static int allocate_gic_irq(struct irq_domain *domain, unsigned virq, · line 106

Quoted 6 lines
drivers/irqchip/irq-crossbar.c +3 -1
      err = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
-     if (err)
+     if (err) {
+             raw_spin_lock(&cb->lock);
              cb->irq_map[i] = IRQ_FREE;
+             raw_spin_lock(&cb->lock);

Really?

Apologies for the typo, Should I send a v2 with the proper raw_spin_unlock(), or do you feel this specific error path doesn't warrant the fix?

Quoted 4 lines
        M.

--
Without deviation from the norm, progress is not possible.

Best Regards,
Bhargav

#3 lore raw
Quoted 39 lines · Bhargav Joshi
Quoted 28 lines · Marc Zyngier
Quoted 25 lines · Bhargav Joshi

In allocate_gic_irq(), if irq_domain_alloc_irqs_parent() fails, the error path resets cb->irq_map[i] to IRQ_FREE. It modifies cb->irq_map[] without holding cb->lock. modifying without lock could cause data race.

Fix this by acquiring raw_spin_lock around cb->irq_map[] modification.

Fixes 783d31863fb8 ("irqchip: crossbar: Convert dra7 crossbar to stacked domains")

---
This bug was flagged by the Sashiko AI bot during the review process for the DT schema conversion of ti,irq-crossbar binding.
https://lore.kernel.org/linux-devicetree/[email protected]/

---
 drivers/irqchip/irq-crossbar.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-crossbar.c +0 -0
index cd1134101ace..9b809e711009 100644
@@ -100,8 +100,11 @@ static int allocate_gic_irq(struct irq_domain *domain, unsigned virq,
      fwspec.param[2] = IRQ_TYPE_LEVEL_HIGH;
 
Quoted 9 lines

drivers/irqchip/irq-crossbar.c static int allocate_gic_irq(struct irq_domain *domain, unsigned virq, · line 106

Quoted 6 lines
drivers/irqchip/irq-crossbar.c +3 -1
      err = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
-     if (err)
+     if (err) {
+             raw_spin_lock(&cb->lock);
              cb->irq_map[i] = IRQ_FREE;
+             raw_spin_lock(&cb->lock);

Really?

Quoted 3 lines

Apologies for the typo, Should I send a v2 with the proper raw_spin_unlock(), or do you feel this specific error path doesn't warrant the fix?

I don't know what to answer to that question. Surely *you* have done the necessary analysis before sending a patch, right?

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#4 lore raw
Quoted 42 lines · Marc Zyngier
Quoted 39 lines · Bhargav Joshi
Quoted 37 lines · Marc Zyngier
Quoted 23 lines · Bhargav Joshi

In allocate_gic_irq(), if irq_domain_alloc_irqs_parent() fails, the error path resets cb->irq_map[i] to IRQ_FREE. It modifies cb->irq_map[] without holding cb->lock. modifying without lock could cause data race.

Fix this by acquiring raw_spin_lock around cb->irq_map[] modification.

Fixes 783d31863fb8 ("irqchip: crossbar: Convert dra7 crossbar to stacked domains")

---
This bug was flagged by the Sashiko AI bot during the review process for the DT schema conversion of ti,irq-crossbar binding.
https://lore.kernel.org/linux-devicetree/[email protected]/

---
 drivers/irqchip/irq-crossbar.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-crossbar.c +0 -0
index cd1134101ace..9b809e711009 100644

drivers/irqchip/irq-crossbar.c static int allocate_gic_irq(struct irq_domain *domain, unsigned virq, · line 106

Quoted 8 lines
drivers/irqchip/irq-crossbar.c +3 -1
@@ -100,8 +100,11 @@ static int allocate_gic_irq(struct irq_domain *domain, unsigned virq,
      fwspec.param[2] = IRQ_TYPE_LEVEL_HIGH;
 
      err = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
-     if (err)
+     if (err) {
+             raw_spin_lock(&cb->lock);
              cb->irq_map[i] = IRQ_FREE;
+             raw_spin_lock(&cb->lock);

Really?

Quoted 6 lines
Quoted 3 lines

Apologies for the typo, Should I send a v2 with the proper raw_spin_unlock(), or do you feel this specific error path doesn't warrant the fix?

I don't know what to answer to that question. Surely *you* have done the necessary analysis before sending a patch, right?

Yes, modifying cb->irq_map without the lock can create a data race. If irq_domain_alloc_irqs_parent() fails it could cause an unlocked write that is concurrent with locked reads. I'll send the v2 with the corrected raw_spin_unlock.

Quoted 5 lines
        M.

--
Without deviation from the norm, progress is not possible.

Best Regards,
Bhargav