From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796018220; b=m35VKDf/3nkzTpxirksBgvlVqK3Nvtvha/tQr4SUhXTLJF/Muk40pPd0tcQzpzvYsLlP r7UF9vqdyun0LC6jhJ3I+uCiTdDY70LifB/MihPWdmbY8iVAb4Nc08nFkgL0LOws2byBF S+ZxvXinkZ5tiaYSWp6eJjhr/8WjKzbUmpyeOTm7ETWL9TUlzZfsIyhZ8pa8eQE9B8PuO xzcPUopvjGZU9z671qe1eISrGS/qA/3dDscXueTKc2OBD1EhnwNH3kUjZ0xUno6+cemnI WQEowr0jYG9eaDRNK4TquHTvsqEG0fAczwkANhm62jcd0kOs+qIRCbaeH3A9HnrVZ9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796018220; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=0DneSxctMeD1brAZoI7300rdt5M+Yn55foap0lbt/XU=; b=bjDxzrS2nPS5Wr2BWX00qGitjAjuuV+3+FYlbFCRqeaTKPKA/xX1ux8lZNl6PN0K3p9L 3YjoalY4GqbFiHe1dIeEggBAYINoSYLrLGZHWA0aEGZ/OtUPfVLXOUnxanhDYNtHvHv9t CO1o0bATegI/Po8y4OSpQxzbXhO3yKp/eoaZsWYiVT43oKem+mShCkzkTAjranQl1eWxN FtzxTneTHjRW/7hxHpiJHxyl/w4CXLVJLFl/x0zJ31UDRXKCSqxSxDyp4fbqhdrb5aCEo L9uIlw5Apj826fNfSAtKJPVnNqCoWmUrTtjmNRdhj6Kfzg/rSoUpK6eCfnqE/vy3RYA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=QregmIv0; arc=none smtp.remote-ip=209.85.215.173 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1331A606A331 for ; Mon, 30 Nov 2026 05:56:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1331A606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=QregmIv0 Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-cc4be0e5351so6232161a12.0 for ; Sun, 29 Nov 2026 21:56:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796018218; x=1796623018; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0DneSxctMeD1brAZoI7300rdt5M+Yn55foap0lbt/XU=; b=QregmIv0wgNYy60MMgaaif0EB5/IzjUyUmML3yWP1v8xuL3YN/D16MpnhIjryGDfKl jrnNyOyNT1rknM5lr9Pje6PbEnWlZWSbWCOSoMH5V15sA6oFmOGfDJ0hF+wnUjW+aDin APlsPcDkSQzJAG4sJ7WbL7GSHkXK3+J8HkhxGxaIh82RF8/APehoQe5g7zf2R1Dwv1zZ udNM89/t8uwZIs20CFdYd3KOBHSwde+3FcAa/SUct4L77Br9ihwwb6o1dJ1Dv2ODBitL Xf7lvD3q3LnNbhwGtwjRksNHX7OTyrgtvLM06ri+ETt4F1UyYwf/FE3GaJysI9crBqlZ uA7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796018218; x=1796623018; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=0DneSxctMeD1brAZoI7300rdt5M+Yn55foap0lbt/XU=; b=RiSV69KsZoFhCZIJ1wymtyGmN/n+9bdrn0MUGz+ZauxWg2Qom5U7RSV6UFRcgkvHr9 /qRyHwqUQzGb57yvvzX19Hl/dyZ/3XyxA0+wqZ3OY7URCu4Q8G6iU3tOU5yzIhYHAWcK yIP/6L5p46LOVPDsiXKZcRr/U7kMYM1Hj4gFYqX/jmgrfMwc8pflilJvnDIf52WbC/Lz wC8gqt8XWXW7yugISpiPV5TJ5+BoNhdYJv6rbOmpU1+WZz4WMA5IU1dGI4XcHT7SaOxe wzRkTBj7lFGWIXaxdrvKlIZNzsQIvHIgQ1qvN1LL5XF/UjZnIxvMKmv3Q9a89zmdx6Lh Yb+A== X-Forwarded-Encrypted: i=1; AL+hErGWgqsdTcuzspLPA2Vr4nJVA6A4ses6W2zAZ1gWCKPqmUT8uI4NJxHSqIS/yKveD1bAnOKPrrpOA6c5JOA=@vger.kernel.org X-Gm-Message-State: APuU4Z/QLrKpYFo0fvhkJgo2A8rvqT6w6FG5OHT6nB03MG5SFFH3COIA rDdAV4uqi5il4vFBQTa0OpyJzRjJXTQT64jcbtsHJYNh059i6QGTH6+E X-Gm-Gg: AZFdTZdV9h48iAmzvGTCZLarORq299vxvgPqGOQSuAxBYYSh1a2yz4HpFcRR6Tn5YiJ 64QNJkX4U9Cp66doRndS6CHzKlZpSFs3178794N2gSYMbwRXFdK/7T7sB4O4Ram9Xq5ORWSx9rw V4/lucMTITOuqQiPrcOP/ZSpr0aKEsqhS3yOAYwS2x7H77alv2TVfpdHAgL6hj+lwih/euYhR1v 5t0BdXOk8Hv5uP6+NfvkyLfBk3xHYfwaWzTXH88bZGZK3BcUgwgbXA0saD2rAitLGbEZBYvtd0k +A/AnrULkDFKOUTognaVlh0h38jEN/7PL5D6h4j1CQtAYqEtRJmEFdKnQb0hYh12jxV5n89JJdz OM0TXP8Dstypzca4BNw0XLV9IfHG1nrGQmIfd24ya/elCrDAdtv9rNP8J2eYRf9IBVEKjlqzUh4 dKX5d2SqB5puG3V6+kJ8c++VyWNOBmPx6G2VJUoNgA/usKfpqdphNciGC3ms3TO3CJd2ujfUWZA JoeLd26SILbdYmC7POwF3x9bpF3HUgmHIIKOpXYKVNtRF/0xgU1M7DQ1Ml/9OEXTgD0rorlk4dp ZlR47lTG80x8oAeEyTY1xHcms+1A5KdI1vJoeIFzuuMLOgp12cui2JWECu2tXMHftyk= X-Received: by 2002:a17:90b:17cd:b0:3b0:ce1c:e74f with SMTP id 98e67ed59e1d1-3b41c8fe346mr31086105a91.27.1796018218405; Sun, 29 Nov 2026 21:56:58 -0800 (PST) Received: from d20be28ee783.tail196be.ts.net (vldb.skku.ac.kr. [115.145.173.180]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41ad0b2c4sm50685765a91.4.2026.11.29.21.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 21:56:58 -0800 (PST) From: Kyuwon Cho To: Jakub Kicinski Cc: Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Breno Leitao , Willem de Bruijn , Jiayuan Chen , 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 Message-ID: <179601706910.5004018.0001.158406812152456751@gmail.com> In-Reply-To: <179601706910.5004018.0000.310885856232254824@gmail.com> References: <179601706910.5004018.0000.310885856232254824@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: 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 Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Kyuwon Cho --- 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