From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796296447; b=YdhEApPfFD0axwb4Zfe13ymxVDplGnMG/UZjX77PwRRxHUnWaD55qg/i9NU08p+fdjfK 1FgVOWLXvcJ74/UtFo+jo9DNuRT15TwiG3/012MO3J/tdxyu00JNlGVl2naldLEMcacgp FkqzR+Az/PGbDxADa6CtC9AePepwhHXPC29GJdKiDa+cW81tEizbI3zY0pFEE6DvUUm/f CnSnh6qQDvWrZWpl2IgbgFLmI3UbXkTLeQpKmUafKgNhmWzMSoAbp+MZFcOAXDJWRN21Y //z0Pcv3pS/vlj129Lf8YyiQLglVv4AW9OWRdYR+8jnpGc9HHhe000yRLQtBZdM7u/A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796296447; 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=BTDMsqZf5AejbF4MVxdq6HYEOS9fVgmSYV1Ob1CiZ8wt0B5DKO2byyA6CfPnjNO+y7zA /7qaYLhnDLuKPQ16U8LeENquargd6GVhPxAJDVfZXG2dKi9CHYNWx0t3yTAHesWI2Qywe KyR3iSPGgWbqAHpDOz6gy4DPViLoUUnbKHW8MuauJOR+/wLTB0No4Bk9DIXO3OtwgPU3B qpY2gYPJ3m2lslNrSxgv6g2Lifw+HRk6dx1Q7Iw241b3E7BRdBZwqMS5iLTtvPDdzCENd GDLHZg9/4OHR4O/Kp6IOyZVlL0Fj8BCh8qYbbUnryaWDqqcIP7kge2uTEa3xjGYb0zg== 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.48 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 80575606A33B for ; Thu, 3 Dec 2026 11:14:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 80575606A33B 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=TOq5DqCo Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-4aa5833c263so13508099f8f.2 for ; Thu, 03 Dec 2026 03:14:07 -0800 (PST) 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=XSDkWO7FY582G0ui6WXLf7cqVA8xTU1rllgpYbHrJskCCuh/hVy0jU9w8fZTL6tIJ3 5F85YB15tr6fEubHZrGCWh4KUL/ZJ2FQzGLTRdNxy2ReeBoZQW8WGNDujA245TzDiazG U+iqftyHFgsT6ELLwu79LGajV1Hkw5OTZg5RNxpjaSXADKVSRcV8CtncHF7XO1XUbJE6 enAUpyC3ZP02tAkBf/TzQnD8AHgnVVpaLVmSBPi38RqqtjNFngBbWrkmZMOoyrz0cQs/ mZutofLsLMSx20HkzafiFgiQyOUdUAtfmdQYO9B80ZmE4UitNUoSJcqMdNDVCvrAmGo5 xFWA== X-Forwarded-Encrypted: i=1; AL+hErGzRSW2XwT16MAfGBTnOtRKcN7DrAS+86aBMx2Q7huHt/h3pQgnW4QxD0aqC507idnOXsDPeMjmK+U=@vger.kernel.org X-Gm-Message-State: APuU4Z8s/5nM60qksCYcbSWaugDEXtGwUlV3KYChqdRTMBVmijo20M6T Ox6xXcbPUChBFhNe+cp45fFjxM1Uw3CKooOsnR8Hxa/uUT3hQkQbqFTTUbFSaMQF9Ps= X-Gm-Gg: AZFdTZe53BWSm/ZSqRyoC+ZqvuHzGB/+TfpriYb36G7U32wH7LHLz/ScApl3PY7dcoK r2WcWMSapLq2CXY+mYfmxx05uqXMmsRE6++vkL4B8k227FUAF7pPL7WBeagyoJYxeB6lMfndnkW 3qozTizNxfpxNEsLjheau17brICtmS3/yH8FcnZU4P1/aAUDAcsqWGAkGiC3FD7iZJN7/EqAQdG v+GqYnR9rWIzXpeR5RqApETxc/usnNZyJ9FLulFszJnN2NSCXI2LGtVWuZqwAe/t8rY4HQ9hEXk VlIjuab63bE/Mhd4PFOqvGJe9k//dBHqk4erVuSB6lpDAUr0rxeiu55OnZIG7VonyHzoqNNeDuO v7Z8Ni48Z9EkoFIOHKyXhKelHh7SVn8b8LfgyzMlVtwJ+G02bBd35NO2hrt9ulydwasB8lTOjoR kP2c7aGuNAtRk/zDAZYw+obIjMFRy71h2nzwebH62Xi9IXq0/bxzlYI23CNakciG95Laf0Rw0Qt aE6l8OhjJIJqq1wlxySSOqL4KxOm//aTdUOGwohPrrW3YYVXUbX6xr2536eq3cUmQ+oEm62IqSn mnyVG+uFt+Ru6CLoTQsSSiiVve8= 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) 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) From: Mahdi Yari To: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com Cc: oneukum@suse.com, netdev@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Mahdi Yari , stable@vger.kernel.org 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 Message-ID: <20261203111359.36444-1-m.yary16@gmail.com> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-usb@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 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 --- 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);