Skip to contentSkip to conversation

irqchip: crossbar: Fix data race in allocate_gic_irq

PATCH In review Bhargav Joshi 2 participants 3 messages Jun 10 – Jun 11 irqchip drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 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]/
---
Changes in v2:
- Fixed typo in spin_unlock
- Link to v1: https://patch.msgid.link/[email protected]

---
 drivers/irqchip/irq-crossbar.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-crossbar.c +4 -1
index cd1134101ace..3d8bb37c9141 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_unlock(&cb->lock);
+	}
 	else
 		cb->write(i, hwirq);
 

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

Best regards,

Signature · 1 line
Bhargav
maintainer
#1 lore raw

On Wed, Jun 10 2026 at 16:44, Bhargav Joshi wrote:

Subject prefix is: irqchip/crossbar: .....

allocate_git_irq is a function and wants to be denoted as such. See

https://docs.kernel.org/process/maintainer-tip.html

Quoted 3 lines

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.

That's not a useful explanation. You fail to tell what races against it and what the side effects of a racy access are.

Quoted 4 lines

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

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

Pointless newline.

Quoted 5 lines

---
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]/

Interesting. Because Sashiko said so, there is a bug, right?

Did you actually analyze whether there is a real bug or Sashiko just pointing out something what looks like a bug? I don't think so otherwise you could explain what the real problem with that unlocked access is and ideally you could explain what the lock actually protects.

It protects nothing at all because interrupt domain allocation/free operations related to a particular domain and the related hierarchy down to the root domain are serialized in the core code already. So there is _zero_ concurrency possible. The lock is a leftover from the original code which predates hierarchical interrupt domains and modern core locking and only provides voodoo protection.

So the real solution here is to remove the lock completely.

Quoted 13 lines

---
Changes in v2:
- Fixed typo in spin_unlock
- Link to v1: https://patch.msgid.link/[email protected]

---
 drivers/irqchip/irq-crossbar.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/irqchip/irq-crossbar.c +0 -0
index cd1134101ace..3d8bb37c9141 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_unlock(&cb->lock);

Not that it matters, but this should use guard() or scoped_guard()

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

Quoted 3 lines
drivers/irqchip/irq-crossbar.c +1 -0
+	}
 	else
 		cb->write(i, hwirq);

If you add brackets to the if () part, you need to add them to the else part too even if there is only a single code line. This

     if () {
        ....
     }
     else
        ...

is asymmetric and unreadable gunk.

#2 lore raw

Hi,

Quoted 23 lines · Thomas Gleixner

On Wed, Jun 10 2026 at 16:44, Bhargav Joshi wrote:

Subject prefix is: irqchip/crossbar: .....

allocate_git_irq is a function and wants to be denoted as such. See

https://docs.kernel.org/process/maintainer-tip.html

Quoted 3 lines

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.

That's not a useful explanation. You fail to tell what races against it and what the side effects of a racy access are.

Quoted 4 lines

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

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

Pointless newline.

Quoted 7 lines
Quoted 5 lines

---
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]/

Interesting. Because Sashiko said so, there is a bug, right?

No, my initial analysis considered two concurrent allocate_gic_irq() calls one failing irq_domain_alloc_irqs_parent() and writing cb->irq_map[i] = IRQ_FREE without the lock, while the other is scanning the array inside the lock in loop. That would be an unlocked write concurrent with a locked read.
But I missed that the IRQ domain core serializes .alloc()/.free(). Apologies for that. I will drop this patch.

Best Regards,
Bhargav