net: ks8851: Reinstate disabling of BHs around IRQ handler
Subsystems (3)
PATCH v4 1/2 net: ks8851: Reinstate disabling of BHs around IRQ handler
If the driver executes ks8851_irq() AND a TX packet has been sent, then the driver enables TX queue via netif_wake_queue() which schedules TX softirq to queue packets for this device.
If CONFIG_PREEMPT_RT=y is set AND a packet has also been received by the MAC, then ks8851_rx_pkts() calls netdev_alloc_skb_ip_align() to allocate SKBs for the received packets. If netdev_alloc_skb_ip_align() is called with BH enabled, then local_bh_enable() at the end of netdev_alloc_skb_ip_align() will trigger the pending softirq processing, which may ultimately call the .xmit callback ks8851_start_xmit_par(). The ks8851_start_xmit_par() will try to lock struct ks8851_net_par .lock spinlock, which is already locked by ks8851_irq() from which ks8851_start_xmit_par() was called. This leads to a deadlock, which is reported by the kernel, including a trace listed below.
If CONFIG_PREEMPT_RT is not set, then since commit 0913ec336a6c0 ("net: ks8851: Fix deadlock with the SPI chip variant") the deadlock can also be triggered without received packet in the RX FIFO. The pending softirqs will be processed on return from spin_unlock_bh(&ks->statelock) in ks8851_irq(), which triggers the deadlock as well.
Fix the problem by disabling BH around critical sections, including the IRQ handler, thus preventing the net_tx_action() softirq from triggering during these critical sections. The net_tx_action() softirq is triggered once BH are re-enabled and at the end of the IRQ handler, once all the other IRQ handler actions have been completed.
__schedule from schedule_rtlock+0x1c/0x34 schedule_rtlock from rtlock_slowlock_locked+0x548/0x904 rtlock_slowlock_locked from rt_spin_lock+0x60/0x9c rt_spin_lock from ks8851_start_xmit_par+0x74/0x1a8 ks8851_start_xmit_par from netdev_start_xmit+0x20/0x44 netdev_start_xmit from dev_hard_start_xmit+0xd0/0x188 dev_hard_start_xmit from sch_direct_xmit+0xb8/0x25c sch_direct_xmit from __qdisc_run+0x1f8/0x4ec __qdisc_run from qdisc_run+0x1c/0x28
qdisc_run from net_tx_action+0x1f0/0x268 net_tx_action from handle_softirqs+0x1a4/0x270 handle_softirqs from __local_bh_enable_ip+0xcc/0xe0 __local_bh_enable_ip from __alloc_skb+0xd8/0x128 __alloc_skb from __netdev_alloc_skb+0x3c/0x19c __netdev_alloc_skb from ks8851_irq+0x388/0x4d4 ks8851_irq from irq_thread_fn+0x24/0x64 irq_thread_fn from irq_thread+0x178/0x28c irq_thread from kthread+0x12c/0x138
kthread from ret_from_fork+0x14/0x28
---
Cc: "David S. Miller" <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Nicolai Buchwitz <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Ronald Wahl <[email protected]>
Cc: Sebastian Andrzej Siewior <[email protected]>
Cc: Yicong Hui <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
V2: Register dedicated IRQ handler wrapper which disables BH for the
parallel variant of the MAC, the variant which uses spinlocks as the locking primitive. Use stock IRQ handler with BH unchanged for the SPI variant, which uses mutexes as locking primitive.
V3: Switch to spin_lock_bh(), update commit message
V4: Extend the commit message
Add RB from Sebastian
--- drivers/net/ethernet/micrel/ks8851.h | 6 +- drivers/net/ethernet/micrel/ks8851_common.c | 64 +++++++++------------ drivers/net/ethernet/micrel/ks8851_par.c | 15 ++--- drivers/net/ethernet/micrel/ks8851_spi.c | 11 ++-- 4 files changed, 38 insertions(+), 58 deletions(-)
drivers/net/ethernet/micrel/ks8851.h +2 -4
@@ -408,10 +408,8 @@ struct ks8851_net {struct gpio_desc *gpio;struct mii_bus *mii_bus; -void (*lock)(struct ks8851_net *ks, -unsigned long *flags); -void (*unlock)(struct ks8851_net *ks, -unsigned long *flags); +void (*lock)(struct ks8851_net *ks); +void (*unlock)(struct ks8851_net *ks);unsigned int (*rdreg16)(struct ks8851_net *ks,unsigned int reg); void (*wrreg16)(struct ks8851_net *ks,
drivers/net/ethernet/micrel/ks8851_common.c +26 -38
243 lines not on this page · raw message
drivers/net/ethernet/micrel/ks8851_par.c +6 -9
@@ -55,29 +55,27 @@ struct ks8851_net_par {/** * ks8851_lock_par - register access lock * @ks: The chip state -* @flags: Spinlock flags * * Claim chip register access lock */ -static void ks8851_lock_par (struct ks8851_net *ks,unsigned long *flags) +static void ks8851_lock_par (struct ks8851_net *ks) {struct ks8851_net_par *ksp =to_ks8851_par (ks); -spin_lock_irqsave (&ksp->lock, *flags); +spin_lock_bh (&ksp->lock); }/** * ks8851_unlock_par - register access unlock * @ks: The chip state -* @flags: Spinlock flags * * Release chip register access lock */ -static void ks8851_unlock_par (struct ks8851_net *ks,unsigned long *flags) +static void ks8851_unlock_par (struct ks8851_net *ks) {struct ks8851_net_par *ksp =to_ks8851_par (ks); -spin_unlock_irqrestore (&ksp->lock, *flags); +spin_unlock_bh (&ksp->lock); }/**
@@ -233,7 +231,6 @@ static netdev_tx_t ks8851_start_xmit_par(struct sk_buff *skb, {struct ks8851_net *ks =netdev_priv (dev);netdev_tx_t ret =NETDEV_TX_OK ; -unsigned long flags;unsigned int txqcr;u16 txmir;int err;
@@ -241,7 +238,7 @@ static netdev_tx_t ks8851_start_xmit_par(struct sk_buff *skb,netif_dbg (ks, tx_queued, ks->netdev,"%s: skb %p, %d@%p\n" , __func__, skb, skb->len, skb->data); -ks8851_lock_par (ks, &flags); +ks8851_lock_par (ks); txmir =ks8851_rdreg16_par (ks,KS_TXMIR ) &0x1fff ;
@@ -262,7 +259,7 @@ static netdev_tx_t ks8851_start_xmit_par(struct sk_buff *skb, ret =NETDEV_TX_BUSY ; } -ks8851_unlock_par (ks, &flags); +ks8851_unlock_par (ks);return ret; }
drivers/net/ethernet/micrel/ks8851_spi.c +4 -7
@@ -71,11 +71,10 @@ struct ks8851_net_spi {/** * ks8851_lock_spi - register access lock * @ks: The chip state -* @flags: Spinlock flags * * Claim chip register access lock */ -static void ks8851_lock_spi (struct ks8851_net *ks,unsigned long *flags) +static void ks8851_lock_spi (struct ks8851_net *ks) {struct ks8851_net_spi *kss =to_ks8851_spi (ks);
@@ -85,11 +84,10 @@ static void ks8851_lock_spi(struct ks8851_net *ks, unsigned long *flags)/** * ks8851_unlock_spi - register access unlock * @ks: The chip state -* @flags: Spinlock flags * * Release chip register access lock */ -static void ks8851_unlock_spi (struct ks8851_net *ks,unsigned long *flags) +static void ks8851_unlock_spi (struct ks8851_net *ks) {struct ks8851_net_spi *kss =to_ks8851_spi (ks);
@@ -309,7 +307,6 @@ static void ks8851_tx_work(struct work_struct *work)struct ks8851_net_spi *kss;unsigned short tx_space;struct ks8851_net *ks; -unsigned long flags;struct sk_buff *txb;bool last;
@@ -317,7 +314,7 @@ static void ks8851_tx_work(struct work_struct *work) ks = &kss->ks8851; last =skb_queue_empty (&ks->txq); -ks8851_lock_spi (ks, &flags); +ks8851_lock_spi (ks);while (!last) { txb =skb_dequeue (&ks->txq);
@@ -343,7 +340,7 @@ static void ks8851_tx_work(struct work_struct *work) ks->tx_space = tx_space;spin_unlock_bh (&ks->statelock); -ks8851_unlock_spi (ks, &flags); +ks8851_unlock_spi (ks); }/**
Signature · 1 line
2.53.0
PATCH v4 2/2 net: ks8851: Avoid excess softirq scheduling
The code injects a packet into netif_rx() repeatedly, which will add it to its internal NAPI and schedule a softirq, and process it. It is more efficient to queue multiple packets and process them all at the local_bh_enable() time.
---
Cc: "David S. Miller" <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Nicolai Buchwitz <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Ronald Wahl <[email protected]>
Cc: Sebastian Andrzej Siewior <[email protected]>
Cc: Yicong Hui <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
V3: New patch
V4: Add RB from Sebastian
--- drivers/net/ethernet/micrel/ks8851_common.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/micrel/ks8851_common.c +4 -1
@@ -373,9 +373,12 @@ static irqreturn_t ks8851_irq(int irq, void *_ks)if (status &IRQ_LCI )mii_check_link (&ks->mii); -if (status &IRQ_RXI ) +if (status &IRQ_RXI ) { +local_bh_disable ();while ((skb =__skb_dequeue (&rxq)))netif_rx (skb); +local_bh_enable (); + }return IRQ_HANDLED ; }
Signature · 1 line
2.53.0
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 15 lines · On Thu, 16 Apr 2026 01:09:44 +0200 you wrote:
If the driver executes
ks8851_irq()AND a TX packet has been sent, then the driver enables TX queue vianetif_wake_queue()which schedules TX softirq to queue packets for this device.If
CONFIG_PREEMPT_RT=yis set AND a packet has also been received by the MAC, thenks8851_rx_pkts()callsnetdev_alloc_skb_ip_align()to allocate SKBs for the received packets. Ifnetdev_alloc_skb_ip_align()is called with BH enabled, thenlocal_bh_enable()at the end ofnetdev_alloc_skb_ip_align()will trigger the pending softirq processing, which may ultimately call the .xmit callbackks8851_start_xmit_par(). Theks8851_start_xmit_par()will try to lock structks8851_net_par.lock spinlock, which is already locked byks8851_irq()from whichks8851_start_xmit_par()was called. This leads to a deadlock, which is reported by the kernel, including a trace listed below.
Quoted 1 line
[...]
Here is the summary with links:
- [net,v4,1/2] net: ks8851: Reinstate disabling of BHs around IRQ handler
https://git.kernel.org/netdev/net/c/5c9fcac3c872 - [net,v4,2/2] net: ks8851: Avoid excess softirq scheduling https://git.kernel.org/netdev/net/c/22230e68b2cf
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html