Article View: linux.kernel.netdev
Article #26291[PATCH net v2] usbnet: don't lose rx mode updates that arrive during set_rx_mode()
From: Mahdi Yari
Date: Thu, 03 Dec 2026 11:13
Date: Thu, 03 Dec 2026 11:13
106 lines
15402 bytes
15402 bytes
usbnet_deferred_kevent() tests EVENT_SET_RX_MODE, calls the
minidriver's set_rx_mode() and only then clears the bit. set_rx_mode()
may sleep in a control transfer. If the rx mode changes meanwhile,
usbnet_set_rx_mode() sets the bit and requeues the kevent, but the
trailing clear_bit() wipes that request, so the rerun finds the bit
clear and the new filter is never sent.
This was observed on a machine in real use: an OpenWrt router whose LAN
port, an ASIX AX88179A (0b95:1790) on cdc_ncm, is bridged with a WiFi
AP. After boot or a USB replug, WiFi clients could not reach hosts
behind the USB port. The bridge enables allmulti and promisc while the
first SET_ETHERNET_PACKET_FILTER is in flight, and usbmon shows that
request as the only one, without promisc:
S Co:1:009:0 s 21 43 000e 0000 0000 0
so the adapter keeps dropping unicast for other MACs. Setting promisc
by hand afterwards (ip link set eth1 promisc on) sends 000f and fixes
it. The cause was found by reading usbmon traces and the code, with
the help of an AI coding assistant (Claude), which also helped write
and test this patch.
Reproducing it needs no kernel changes: add the cdc_ncm port to a
bridge, replug the adapter (or reload the usbnet modules) and watch
usbmon for "s 21 43" requests. The race does not hit every time.
Clear the bit with test_and_clear_bit() before calling set_rx_mode(),
so a request made while it runs is handled by the requeued kevent.
No retry is lost: the bit was already cleared whether or not
set_rx_mode() succeeded.
test_and_clear_bit() is fully ordered, but the set_bit() in
usbnet_defer_kevent() is not. On weakly ordered CPUs a kevent that is
already running could see the bit before the rx mode change behind it,
such as a new multicast address, clear the bit and send the old
filter, and the requeued kevent would then skip the update. Add
smp_mb__before_atomic() in usbnet_set_rx_mode() to pair with
test_and_clear_bit(). It goes there rather than in
usbnet_defer_kevent() so the other events are unchanged.
usbnet_defer_kevent() starts with the set_bit(), so no access sits
between the barrier and the atomic.
Tested with that reproducer on the same hardware (Intel Atom x5-Z8350,
AX88179A on cdc_ncm) running OpenWrt 25.12.5, kernel 6.12.94, with
this change backported. In runs where the race hit, the unpatched
kernel never sent promisc (4 of 4 module reloads) and bridged traffic
failed. With the fix the requeued kevent sent it (3 of 3 reloads, 2 of
2 replugs) and bridged traffic worked. Those runs were without the
barrier, which compiles to nothing on x86. Not tested on a
weakly ordered CPU, not run-tested on net and not tested with kernel
selftests. On net, usbnet.o builds with W=1 for allmodconfig and
allyesconfig without new warnings.
Fixes: 1efed2d06c70 ("usbnet: add a callback for set_rx_mode")
Cc: stable@vger.kernel.org
Signed-off-by: Mahdi Yari <m.yary16@gmail.com>
---
v2:
- Add smp_mb__before_atomic() in usbnet_set_rx_mode() so the fix also
holds on weakly ordered CPUs (Sashiko review). herd7 with the LKMM
allows the lost update without the barrier and forbids it with it.
- Dropped Oliver's Acked-by because of that code change.
v1: https://lore.kernel.org/netdev/20261202060513.660741-1-m.yary16@gmail.com/
Note: in net-next, commit 7d573278f9a5 ("ax88179_178a: Add HW support
for AX179A-based chips") moves the AX88179A off cdc_ncm. The race
still affects every usbnet minidriver using set_rx_mode: cdc_ether,
cdc_ncm and int51x1.
drivers/net/usb/usbnet.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 97a30dd22..5f39e54cc 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1176,6 +1176,10 @@ void usbnet_set_rx_mode(struct net_device *net)
{
struct usbnet *dev = netdev_priv(net);
+ /* order the rx mode change before the bit, pairs with
+ * test_and_clear_bit() in usbnet_deferred_kevent()
+ */
+ smp_mb__before_atomic();
usbnet_defer_kevent(dev, EVENT_SET_RX_MODE);
}
EXPORT_SYMBOL_GPL(usbnet_set_rx_mode);
@@ -1184,8 +1188,6 @@ static void __handle_set_rx_mode(struct usbnet *dev)
{
if (dev->driver_info->set_rx_mode)
(dev->driver_info->set_rx_mode)(dev);
-
- clear_bit(EVENT_SET_RX_MODE, &dev->flags);
}
/* work that cannot be done in interrupt context uses keventd.
@@ -1295,7 +1297,7 @@ usbnet_deferred_kevent(struct work_struct *work)
if (test_bit(EVENT_LINK_CHANGE, &dev->flags))
__handle_link_change(dev);
- if (test_bit(EVENT_SET_RX_MODE, &dev->flags))
+ if (test_and_clear_bit(EVENT_SET_RX_MODE, &dev->flags))
__handle_set_rx_mode(dev);
Technical Details
Message-ID:
<20261203111359.36444-1-m.yary16@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376507-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376507-linux-kernel-netdev=dewy.ru
From: m.yary16@gmail.com (Mahdi Yari)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2] usbnet: don't lose rx mode updates that arrive during set_rx_mode()
Date: Thu, 3 Dec 2026 14:43:59 +0330
Organization: Usenet Network
Message-ID: <20261203111359.36444-1-m.yary16@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2469458"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:etQgRdLpY0rN9vQD6YJPuuwLoU4= sha256:2IJrYOF9iZEg/VSNRSy5X0KGGrYx4CL7boLR8KKXdac=
sha1:KSsy9XxZIEmRn7FKgeA4K8GM3GE= sha256:cAkBOxsEElRj5jhXx3S0gAY5S9a02tzU24fyQx6TbtM=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 4CEC11178E5; Thu, 3 Dec 2026 14:14:26 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.397
X-Spam-Status: No, score=-3.397 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id bvOlVdx17CyE;
Thu, 3 Dec 2026 14:14:23 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376507-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 085E01178E4; Thu, 3 Dec 2026 14:14:15 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id AC4D42713E; Thu, 3 Dec 2026 11:14:11 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796296449;
b=b/85VAd4EMeolSK/kGdap2N/PfeFiTiUSqpCkfovIsNgkJ3+GHgzwCio3O/tG5eFYXdi
glyrolwbofTMgIcnZx5X/WqzrMfexpIIxz/GjD3JDEnlihSTs9x0RcQ4aGCfzfSH5fjrk
Vbwu9xLnSWaENl7Ug300ILC2X0gTLr2O11G3I+z35taMVZCtQvc/ytIOOOxwkvUabQ2CT
srYVmDxfVqrMQockpuZf3vjp4TckBbqDu1TFoqzubkqqApBYguyekL3HZU7pr/lh5/EqF
UsgS5JoiiOyHXZIYOzyvqR+gqJV6QHgxyiZpAiDVhOkdCqkcGShc3etTe5rdvRVtPaw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796296449;
h=X-Original-To:Received: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:
X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=zAeJQX2iEw5f7h2uf7/VwhuTDh2Ya624vYMM+fgp/zM=;
b=NZVt3q7UeJI+f6yE64Kk7ObAKLS70wsKcnnXI7A2BlxZRR8l0of35LWYauFHz0Zcwl3D
mhFR5O8u10ShiIHNuQHzB9yOMAbXz//uJ301K5JSQy2Zl54Jh3aDow5MU2wxkprctAQ8L
wZ38ui0xM62zSQ0t+cygv/OD0twC3DY+lIe+tLbhLv2+SBjszPP4ZTld5JUfBqgT7hpJG
ncHrIP9VZji29YnbHgD8b27bU+INsvvLVqxPk3/kXn1Ml2mr8srA9/s3+2VeGixgrk/jN
AnsQBHfRZ1bKmPjr5RfnPzhJkiDYbMoSX+nSbfsfx/ddFLZ+N4viC+93NJyi7u9+htw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=TOq5DqCo;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id E62EB606A32F;
Thu, 3 Dec 2026 11:14:08 +0000 (UTC)
X-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=TOq5DqCo
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.54
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796296448;
b=D8WZZr31E3UPgaYZ9WvgB/o4/uGDEO6du/Ezm9WCCKZvvNtGEpdScTSdDdqyXTqxbm8e
DTsQ7cJ2lM64u+5q5Tnud1apLZz23a4KMWAfTwTazUlzEM6+eahIvF+u223P7oEMMNHP7
F0LOJHbg56RXKI5iRcpeDV9DMArBJeFiQ8BreY2H+ig+xKm/iwi4fCh18N5o0anxtB9TH
4t+ya6V9R2/JjCMwawvAD0/rHS8/1q7WBruie9KgiZ00BzZfWNJk0crNnFkuLY0vXwaR4
MjLTVLbGImKB3AhSp3Fy17W5/V5wz41GDG8aMCnzgMpk0kaOyIdA81NZjI+k2FA+BSw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796296448;
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:X-Mailer:MIME-Version:
Content-Transfer-Encoding;
bh=zAeJQX2iEw5f7h2uf7/VwhuTDh2Ya624vYMM+fgp/zM=;
b=HCiZbXZ5B2/Jfm3GFS+MiUdrhz5RhuXAfzBMVwvUgGZx0lUeHLrNvxt9tWqS+05lOfgW
TThWQv7iTC0n9ucqAxspvgWWR0XliXMBRV6inJKHRvs9AkILEi29dLk9Jp1XAi6AuvbqP
pHm+AQtil5ooZ5KbwcAw0aHWf4aUEzABGhgj4tciououKxhgkAlz9RfVC2WcGOkIIjKej
JY62zxw588G20VVP5wQWfNpb1CwryaDMB/iux4vab9Rggaw5245BRmjcpJRmNYnqBKZ3A
llICLgStoQ3OUtYrNbz7cIcd4dGX8WKU5glzvt+ZkqsgkJ7yX9TWzyqz9VUZeQcps3A==
X-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=TOq5DqCo;
arc=none smtp.remote-ip=209.85.221.54
X-Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54])
(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 7409C606A333
for <netdev@vger.kernel.org>; Thu, 3 Dec 2026 11:14:07 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7409C606A333
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-4acb44dcd7bso12432160f8f.0
for <netdev@vger.kernel.org>; Thu, 03 Dec 2026 03:14:07 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796296446; x=1796901246; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=zAeJQX2iEw5f7h2uf7/VwhuTDh2Ya624vYMM+fgp/zM=;
b=TOq5DqCo4ws1RaDunLC65QHgjnOKtqBUOa3IqrDg9VeEvJCI5f4qtsVFcUp95cWJIr
de/y230Srbbq6df1zHHT+uUAAG1j997NG1/fwJ9nTv/EWv5Q8HphbeT4cdwh9W7PWOdg
xmI61Hn1flxIdcPKcukcYPu68+thECd5DRZM2V4CQF2Z7ixz7s41JHSjoNPHBWTxY3U4
ONPxyOSXH4AcQBS6J298z8w2YgsNqa+yy3lnL9XmyMTbCJA3ZFV1ciMqv2aivBj+ucTs
c5zH3uL2tF6deJgIEoSRYdBPQeVb6DUbj1qtnt/24BbX3Q4L8kCiJKeqz0Il8QazG+Yj
Myzg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796296446; x=1796901246;
h=content-transfer-encoding:mime-version: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=zAeJQX2iEw5f7h2uf7/VwhuTDh2Ya624vYMM+fgp/zM=;
b=m8kx0IufkLodWchbBKgBh3JElyUK6zRlDmLyuXYXjXN6gbZCpGO/g85ANEXy1hnscy
nKUoM/ddJ381c1N00jWmCpTo/xX1e7jOkFqbS6waZsiQzO4Jb/EftfnGugVXObcc6jKm
GMKTcUFlyLSSj6VdUisZyfIWApfBSLoeOEmCAdfF/lsxUMbWC8RC3Xw3EvpjnhkJfVaB
7HHUirCsvpur0QbS01WlcRHZRDNylMhz7iNVHTn0//Tif0po92rIzagHMyJPr/ePmcb+
3HxBX3yqiLtrhgkveRQwrqcCva37Zlsul6smysY+fEcP6x2hNmlwzOsxRMHj3SPLVZp5
xmJg==
X-Forwarded-Encrypted: i=1; AL+hErGjjit3z55pHVhOvGHgzR9PXfinUfUBxLwaoxia1hrGhfq6jbUh/dEsR1dRljyliE++3QMc+Nk=@vger.kernel.org
X-Gm-Message-State: APuU4Z/6jcnp0DPUxjsloeI2ZdNW7C7XU36gW9lfZq6mqpNAyxZJs2Vn
ACQwu07bbRNMod+iT2H3v42bYi15rtUc+MCfQGYf4yYVI22m+m2/Sn6Z
X-Gm-Gg: AZFdTZdKB76xy0KNo2DnzfUOOxj2AdcOwDkw2XayOIbUSaxFpkFwp5kqatPXeQGqWOr
0Go9qc2HGkLO1vaj0sC+Obdra+hSqwMJf5mafZ85+RMWpxHeF8aRor52GowMSPSFDTRM46S0J/g
y1yC6c746DP0vmBio2ubL5SS6aCdKs44RKMispdi/ywR64oGRipKfMPCrm9WWpVwFfZVWJuvB/E
Y6xr+hRTFm8vis55KP/fZk/ABsZiECyfKv7RJ3Kfyk1YoS2uy2qiWehC6vmxv2eABnjUrwFoPDp
/O3gzDjiCpvZgiTNAV1EL2GisrvIriHOknm5clxB8R8jN7hVEJ60+JEfhsxVGPZCN3JPN40aEyJ
1yyzq8eiuB6wy3lXb26mpbhc9uEEAO6tKQOWR9/wJKheSXHQpar9IuXEywJjDTr0a0F/McqMz8z
f6V3GeyPVinWdQaedIsuV1NU73hNgEkUuPxWWgZK4d3xeEz5+MiI3fVmaItzHPuY8mtvAweAR4w
mvLem+oWiPqdR2TZVZn414M8s+jy0qr9ydAqCEC15BMY/4iiA2+VfwAde/QiA2x77EzT/FKgtwY
rBcEdJIO0jzAldl1axi/hfIDf+o=
X-Received: by 2002:a05:6000:4b19:b0:48e:3bc4:a367 with SMTP id ffacd0b85a97d-4abb3678d71mr78665861f8f.33.1796296445791;
Thu, 03 Dec 2026 03:14:05 -0800 (PST)
X-Received: from federation.lan ([194.105.5.28])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b110c3csm80591955f8f.36.2026.12.03.03.14.03
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 03 Dec 2026 03:14:05 -0800 (PST)
X-Cc: oneukum@suse.com,
netdev@vger.kernel.org,
linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org,
Mahdi Yari <m.yary16@gmail.com>,
stable@vger.kernel.org
X-Mailer: git-send-email 2.56.1
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list