mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kyuwon Cho <kyuwoncho18@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>, Breno Leitao <leitao@debian.org>,
	Willem de Bruijn <willemb@google.com>,
	Jiayuan Chen <jiayuan.chen@linux.dev>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net v3 1/1] netdevsim: fix the inverted queue count check in flow control
Date: Mon, 30 Nov 2026 14:56:50 +0900	[thread overview]
Message-ID: <179601706910.5004018.0001.158406812152456751@gmail.com> (raw)
In-Reply-To: <179601706910.5004018.0000.310885856232254824@gmail.com>

nsim_start_xmit() maps the TX queues of the sending device onto the RX
queues of its peer, and flow control relies on one TX queue per RX
queue: nsim_stop_tx_queue() stops TX queue N when RX queue N is full,
and nsim_start_peer_tx_queue() wakes TX queue N after polling RX queue
N. Both skip this unless the queue counts match, but they compare the
wrong pair, the RX device's real_num_tx_queues with the TX device's
num_rx_queues.

A device with 8 queues whose channels were reduced to 1 with ethtool -L
passes this check once it is relinked to a peer with a single queue. If
one of its upper RX queues still holds traffic from the old peer,
nsim_start_peer_tx_queue() wakes a TX queue that the peer does not have:

  BUG: KASAN: slab-out-of-bounds in nsim_poll (include/linux/netdevice.h:3834 drivers/net/netdevsim/netdev.c:60)
  Read of size 8
  Call Trace:
   <IRQ>
   nsim_poll (drivers/net/netdevsim/netdev.c:409)
   __napi_poll.constprop.0 (net/core/dev.c:7997)
   net_rx_action (net/core/dev.c:8217)

Compare the TX device's real_num_tx_queues with the RX device's
num_rx_queues in both places. The polled RX queue index is below the RX
device's num_rx_queues, so the queue woken is then always inside the
peer's TX queue array. nsim_set_channels() can change
real_num_tx_queues of the other device at the same time, so read it
with READ_ONCE().

Fixes: ff2ac4df58ad ("netdevsim: implement peer queue flow control")
Suggested-by: Willem de Bruijn <willemb@google.com>
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
---
 drivers/net/netdevsim/netdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c
index eebc02ccc4a9..b0c4c00577e9 100644
--- a/drivers/net/netdevsim/netdev.c
+++ b/drivers/net/netdevsim/netdev.c
@@ -53,7 +53,7 @@ static void nsim_start_peer_tx_queue(struct net_device *dev, struct nsim_rq *rq)
 
 	/* TX device */
 	peer_dev = peer_ns->netdev;
-	if (dev->real_num_tx_queues != peer_dev->num_rx_queues)
+	if (READ_ONCE(peer_dev->real_num_tx_queues) != dev->num_rx_queues)
 		goto out;
 
 	txq = netdev_get_tx_queue(peer_dev, idx);
@@ -73,7 +73,7 @@ static void nsim_stop_tx_queue(struct net_device *tx_dev,
 	/* If different queues size, do not stop, since it is not
 	 * easy to find which TX queue is mapped here
 	 */
-	if (rx_dev->real_num_tx_queues != tx_dev->num_rx_queues)
+	if (READ_ONCE(tx_dev->real_num_tx_queues) != rx_dev->num_rx_queues)
 		return;
 
 	/* rq is the queue on the receive side */
-- 
2.43.0


      reply	other threads:[~2026-11-30  5:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  5:56 [PATCH net v3 0/1] " Kyuwon Cho
2026-11-30  5:56 ` Kyuwon Cho [this message]

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=179601706910.5004018.0001.158406812152456751@gmail.com \
    --to=kyuwoncho18@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jiayuan.chen@linux.dev \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /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®