Skip to contentSkip to conversation

usb: dwc3: gadget: Let the interrupt handler disable bottom halves.

PATCH In review Sebastian Andrzej Siewior 2 participants 2 messages Feb 18, 2022 – Feb 21, 2022

Subsystems (5)
Networking Network drivers USB BPF +1 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: dwc3: gadget: Let the interrupt handler disable bottom halves.

The interrupt service routine registered for the gadget is a primary handler which mask the interrupt source and a threaded handler which handles the source of the interrupt. Since the threaded handler is voluntary threaded, the IRQ-core does not disable bottom halves before invoke the handler like it does for the forced-threaded handler.

Due to changes in networking it became visible that a network gadget's completions handler may schedule a softirq which remains unprocessed. The gadget's completion handler is usually invoked either in hard-IRQ or soft-IRQ context. In this context it is enough to just raise the softirq because the softirq itself will be handled once that context is left. In the case of the voluntary threaded handler, there is nothing that will process pending softirqs. Which means it remain queued until another random interrupt (on this CPU) fires and handles it on its exit path or another thread locks and unlocks a lock with the bh suffix. Worst case is that the CPU goes idle and the NOHZ complains about unhandled softirqs.

Disable bottom halves before acquiring the lock (and disabling interrupts) and enable them after dropping the lock. This ensures that any pending softirqs will handled right away.

Fixes e5f68b4a3e7b0 ("Revert "usb: dwc3: gadget: remove unnecessary _irqsave()"")
---
 drivers/usb/dwc3/gadget.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/dwc3/gadget.c +2 -0
index 183b90923f51b..a0c883f19a417 100644
@@ -4160,9 +4160,11 @@ static irqreturn_t dwc3_thread_interrupt(int irq, void *_evt)
 	unsigned long flags;
 	irqreturn_t ret = IRQ_NONE;
 
+	local_bh_disable();
 	spin_lock_irqsave(&dwc->lock, flags);
 	ret = dwc3_process_event_buf(evt);
 	spin_unlock_irqrestore(&dwc->lock, flags);
+	local_bh_enable();
 
 	return ret;
 }
Signature · 1 line
2.34.1
Tested-by on v1 1/1
#1 lore raw
Quoted 18 lines · Sebastian Andrzej Siewior

The interrupt service routine registered for the gadget is a primary handler which mask the interrupt source and a threaded handler which handles the source of the interrupt. Since the threaded handler is voluntary threaded, the IRQ-core does not disable bottom halves before invoke the handler like it does for the forced-threaded handler.

Due to changes in networking it became visible that a network gadget's completions handler may schedule a softirq which remains unprocessed. The gadget's completion handler is usually invoked either in hard-IRQ or soft-IRQ context. In this context it is enough to just raise the softirq because the softirq itself will be handled once that context is left. In the case of the voluntary threaded handler, there is nothing that will process pending softirqs. Which means it remain queued until another random interrupt (on this CPU) fires and handles it on its exit path or another thread locks and unlocks a lock with the bh suffix. Worst case is that the CPU goes idle and the NOHZ complains about unhandled softirqs.

Quoted 8 lines

Disable bottom halves before acquiring the lock (and disabling interrupts) and enable them after dropping the lock. This ensures that any pending softirqs will handled right away.

Fixes e5f68b4a3e7b0 ("Revert "usb: dwc3: gadget: remove unnecessary _irqsave()"")
Quoted 10 lines
---
  drivers/usb/dwc3/gadget.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/usb/dwc3/gadget.c +0 -0
index 183b90923f51b..a0c883f19a417 100644
@@ -4160,9 +4160,11 @@ static irqreturn_t dwc3_thread_interrupt(int irq, void *_evt)
  	unsigned long flags;

drivers/usb/dwc3/gadget.c static irqreturn_t dwc3_thread_interrupt(int irq, void *_evt) · line 4170

Quoted 10 lines
drivers/usb/dwc3/gadget.c +2 -0
  	irqreturn_t ret = IRQ_NONE;
 
+	local_bh_disable();
  	spin_lock_irqsave(&dwc->lock, flags);
  	ret = dwc3_process_event_buf(evt);
  	spin_unlock_irqrestore(&dwc->lock, flags);
+	local_bh_enable();
 
  	return ret;
  }

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland