From: Karl Mehltretter <kmehltretter@gmail.com>
To: netdev@vger.kernel.org
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Stephen Hemminger <stephen@networkplumber.org>,
linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev,
stable@vger.kernel.org
Subject: [PATCH net 1/2] netpoll: use a raw lock for the deferred transmit queue
Date: Mon, 28 Sep 2026 08:42:38 +0200 [thread overview]
Message-ID: <20260928064239.32456-2-kmehltretter@gmail.com> (raw)
In-Reply-To: <20260928064239.32456-1-kmehltretter@gmail.com>
netpoll_send_skb() calls __netpoll_send_skb() with hard interrupts
disabled. When direct transmission cannot complete, the latter queues
the skb with skb_queue_tail(). The sk_buff_head lock may sleep on
PREEMPT_RT:
BUG: sleeping function called from invalid context
in_atomic(): 0, irqs_disabled(): 1, non_block: 0
rt_spin_lock
skb_queue_tail
netpoll_send_skb
The delayed transmit worker has the same problem when it requeues a busy
skb with skb_queue_head() after disabling interrupts.
Add a dedicated raw spinlock and use the unlocked skb queue helpers under
it. Keep raw critical sections limited to queue operations. During
cleanup, splice the queue to a private list before freeing its skbs.
Fixes: b6cd27ed3388 ("netpoll per device txq")
Cc: stable@vger.kernel.org # 6.12+
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
include/linux/netpoll.h | 1 +
net/core/netpoll.c | 75 +++++++++++++++++++++++++++++++++++++----
2 files changed, 70 insertions(+), 6 deletions(-)
diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h
index 1c6b1eec5efd6..e20e0592e9349 100644
--- a/include/linux/netpoll.h
+++ b/include/linux/netpoll.h
@@ -47,6 +47,7 @@ struct netpoll_info {
struct semaphore dev_lock;
struct sk_buff_head txq;
+ raw_spinlock_t txq_lock;
struct delayed_work tx_work;
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index fe1e0cda5d6bf..e0cfcb05468e2 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -79,6 +79,68 @@ static netdev_tx_t netpoll_start_xmit(struct sk_buff *skb,
return status;
}
+/*
+ * Transmit paths can access txq with hard IRQs disabled. Use a raw lock
+ * because the skb queue lock may sleep on PREEMPT_RT.
+ */
+static bool netpoll_txq_empty(struct netpoll_info *npinfo)
+{
+ unsigned long flags;
+ bool empty;
+
+ raw_spin_lock_irqsave(&npinfo->txq_lock, flags);
+ empty = skb_queue_empty(&npinfo->txq);
+ raw_spin_unlock_irqrestore(&npinfo->txq_lock, flags);
+
+ return empty;
+}
+
+static struct sk_buff *netpoll_txq_dequeue(struct netpoll_info *npinfo)
+{
+ unsigned long flags;
+ struct sk_buff *skb;
+
+ raw_spin_lock_irqsave(&npinfo->txq_lock, flags);
+ skb = __skb_dequeue(&npinfo->txq);
+ raw_spin_unlock_irqrestore(&npinfo->txq_lock, flags);
+
+ return skb;
+}
+
+static void netpoll_txq_queue_head(struct netpoll_info *npinfo,
+ struct sk_buff *skb)
+{
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&npinfo->txq_lock, flags);
+ __skb_queue_head(&npinfo->txq, skb);
+ raw_spin_unlock_irqrestore(&npinfo->txq_lock, flags);
+}
+
+static void netpoll_txq_queue_tail(struct netpoll_info *npinfo,
+ struct sk_buff *skb)
+{
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&npinfo->txq_lock, flags);
+ __skb_queue_tail(&npinfo->txq, skb);
+ raw_spin_unlock_irqrestore(&npinfo->txq_lock, flags);
+}
+
+static void netpoll_txq_purge(struct netpoll_info *npinfo)
+{
+ struct sk_buff_head purge;
+ unsigned long flags;
+
+ __skb_queue_head_init(&purge);
+
+ raw_spin_lock_irqsave(&npinfo->txq_lock, flags);
+ skb_queue_splice_init(&npinfo->txq, &purge);
+ raw_spin_unlock_irqrestore(&npinfo->txq_lock, flags);
+
+ __skb_queue_purge(&purge);
+}
+
static void queue_process(struct work_struct *work)
{
struct netpoll_info *npinfo =
@@ -86,7 +148,7 @@ static void queue_process(struct work_struct *work)
struct sk_buff *skb;
unsigned long flags;
- while ((skb = skb_dequeue(&npinfo->txq))) {
+ while ((skb = netpoll_txq_dequeue(npinfo))) {
struct net_device *dev = skb->dev;
struct netdev_queue *txq;
unsigned int q_index;
@@ -107,7 +169,7 @@ static void queue_process(struct work_struct *work)
HARD_TX_LOCK(dev, txq, smp_processor_id());
if (netif_xmit_frozen_or_stopped(txq) ||
!dev_xmit_complete(netpoll_start_xmit(skb, dev, txq))) {
- skb_queue_head(&npinfo->txq, skb);
+ netpoll_txq_queue_head(npinfo, skb);
HARD_TX_UNLOCK(dev, txq);
local_irq_restore(flags);
@@ -282,7 +344,7 @@ static netdev_tx_t __netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
}
/* don't get messages out of order, and no recursion */
- if (skb_queue_len(&npinfo->txq) == 0 && !netpoll_owner_active(dev)) {
+ if (netpoll_txq_empty(npinfo) && !netpoll_owner_active(dev)) {
struct netdev_queue *txq;
txq = netdev_core_pick_tx(dev, skb, NULL);
@@ -314,7 +376,7 @@ static netdev_tx_t __netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
}
if (!dev_xmit_complete(status)) {
- skb_queue_tail(&npinfo->txq, skb);
+ netpoll_txq_queue_tail(npinfo, skb);
schedule_delayed_work(&npinfo->tx_work,0);
}
ret = NETDEV_TX_OK;
@@ -362,7 +424,8 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
}
sema_init(&npinfo->dev_lock, 1);
- skb_queue_head_init(&npinfo->txq);
+ __skb_queue_head_init(&npinfo->txq);
+ raw_spin_lock_init(&npinfo->txq_lock);
INIT_DELAYED_WORK(&npinfo->tx_work, queue_process);
refcount_set(&npinfo->refcnt, 1);
@@ -397,7 +460,7 @@ static void rcu_cleanup_netpoll_info(struct rcu_head *rcu_head)
struct netpoll_info *npinfo =
container_of(rcu_head, struct netpoll_info, rcu);
- skb_queue_purge(&npinfo->txq);
+ netpoll_txq_purge(npinfo);
kfree(npinfo);
}
--
2.53.0
next prev parent reply other threads:[~2026-09-28 6:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 6:42 [PATCH net 0/2] netpoll: fix PREEMPT_RT deferred transmit locking Karl Mehltretter
2026-09-28 6:42 ` Karl Mehltretter [this message]
2026-09-28 6:42 ` [PATCH net 2/2] netpoll: avoid blocking on the transmit lock in queue_process Karl Mehltretter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260928064239.32456-2-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=bigeasy@linutronix.de \
--cc=clrkwllms@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rostedt@goodmis.org \
--cc=stable@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®