From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796191680; b=gQQU2HH6XgR4pacjqJdsQMAnXoVhXs1Y3PokPRAj4ZXaDR02gnu7i7JYVJ6KHkOpYWSN cdlXON/7lBc5DU6kGQ77klXv5lPKwNiGgyGZJ+Xv/MA0/dgZZtHAun73ywOEwitvinIsI yzma/HR/tqIn6Ov7x452lQaOt77WxnZ11Cvt3qegaiZ4sW6QxlXAcE0xsGz5aE7qDVXHJ yQd+2rDxt1jGldYFPqyEljlRiiKfvpZtrlJUrd/dzNG6Xv4rF7Hh0dZnyAXRrgC+AT8Hc yRB4r10Vb9tGAXL6zB7TbsUovLD8CSJ7qerNHs+EWmdtsKJL5+swqMpM3in9RWf/l8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796191680; 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=Y0cZaVhzHE157HwI02HB5SAotteDxM6C2ULM3SD6T7E=; b=iBcl/bFfmrC/iN7GunV8mCjNSy/bnQpQOmjtXXQxCZOkGE79bfo2wIMoQOVVli3Ta7+v Bmw4Wg7Vo9dyItNPS2zrDakQXQz/qfQCp/cJlr0jDWHDFcn7Re33BxnG/brg5gA6IG309 NK7Aw/6A6SazOzRFXRejdXRswyKuZiuCcf2P/0/khCiyW/KVkQyAgw9bSe8VROSt2hH2u bAbFA0zNJgL9zvhm+zlKtOZcaaGIqGH17dBxg+WFcoxj8XL0QYIyrlyNswjdJeglJFdly Yb4yz92/VwgyqqPZSWHCEHSx122O7dEeCF5Uizb/y9C89pnrsoFnHeXpR1npiE+Vqxw== 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=qJNi5Eot; arc=none smtp.remote-ip=209.85.128.51 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 F1162606A325 for ; Wed, 2 Dec 2026 06:07:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F1162606A325 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=qJNi5Eot Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4a1fbd52ab6so88261265e9.0 for ; Tue, 01 Dec 2026 22:07:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796191678; x=1796796478; 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=Y0cZaVhzHE157HwI02HB5SAotteDxM6C2ULM3SD6T7E=; b=qJNi5EotbYLqiTscihChQwXSNTzfYSKt5pH2oq2DFdbcWPr9P46lfUG6M182ix2xBM vqAoC8Z/a49lEuhGo9TfZnYKgpqQLSaWPaZGybHUks8oVsroK1x5JjvlChDdYCnYCdi3 oikn4PCm/KYR1Ry8NB8m6bWqfyvAvRtc/fBZ4A+fQea6tGjwsZw2a7nJQERVkuoahf7M DuK+67a5Zs6/Fn8DomNtsoNem5gFaF3iPbRXEGTtTiyU5fVH2w7bnJNWAZP+iNNww64p 3Hub/YdLk+8uPM4eHqmAwKkv7oglF6+t1YWJWJ6U3qwvK+ve1RTZZuAi5lXASDKLb9lY miQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796191678; x=1796796478; 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=Y0cZaVhzHE157HwI02HB5SAotteDxM6C2ULM3SD6T7E=; b=rZUmbxONqXw6pJ/qEsfwM1DjGtg38U99QSM7c7p0TledhRrB2lvhb0bfvbHZD8TzIE qVxtBved1veY4ybtwIkZ+jV0d7l1VF3+j8bWiC+ZZlpLXlVe9My+lUUFvJxvjwcfdYH3 RSBYE5usVqTjWbCAI/zpYQncSBz3KEvsK+6J5QOgO53kWK09CLMD3ozkdmpgkcWJf7B/ p9nxRZ0qiVi/C8h0K0wc72Xn/cjfjdqNk+NJWnPy/kfebYqoZkolfYK0yKbj2vectT0G 3blFKcroV0fRnrHjN0Fa2VRN644LCurAaONZ+0sOvFKcBiP4DjSYIfCWW0tN/s6+ezt5 taTA== X-Forwarded-Encrypted: i=1; AL+hErEtBpGp2LRKe9pCOg1dVCTw2VkDWNKnS/S4stgMZxqa/vYyG0y7tntr9L6KSp4pJf5DKwHWWhK58U2wopM=@vger.kernel.org X-Gm-Message-State: APuU4Z8cDwRARaIjiO4A7B7SfmiOiQJdBRFLUMbGg3Tara4ROn+2FgUd tz9HvM1CByFCWUiUeFz9gatOuFGcl23t9zUlEkHzGxCNk8Nb/hsJsheI X-Gm-Gg: AZFdTZc8WQyO/go9U4QFofgDdbnT+p29Qu46TT86aLTnXELgLXYRAbOuUR/uu+mgYJz FTUrHw2rNe8Jvx3p6Kxv/4ac7vpRGiA/xdYN45hcuiWRIvEVaR5zAeMmpOGfU2+13xLVUCbfDxg fZljd1jBlHLDA/ZSJyF/dGOGuoCuEayA1yF88ELTJHafqFP6P8QrpdrUIA3z56aR+kMbm5Qz4My jJXWmg1T13RSHn7ydYumEk2DHRZbzsL6c/Kk10Z06BR79zux70jErGX+wxsQonjGOvPq746SEP5 C6ovL1XQ2Vf1TpqmaudIChHbltNhm8xdOapQ0PT3qPGUp6BdYfMhwpvccaOPed0hFKeorFMXw9H FmDqGCdFvKXfLN6WxUe4MynyUgALbUXEtOugfWk/SDg9kQuW1mE6/2dSE/xgG71sCrZXsn4O4No DSepa6OP+OQBArX1V56RGGVWH/TBg12sUsbxWK/mCIZaY3+hLnPXSoYYUXuNMzC1mTO/vSVJMQt 8e41AMUt5lXpcIzSdLLo2m7Xxytirnd7IoLBNRE/n62ZEl06P+pp2bv1BExA4/YxHNqh4gaY7im eyvFpeR+aip+g+rbiaqo+JV45ec= X-Received: by 2002:a05:600c:6290:b0:4bb:741d:eba with SMTP id 5b1f17b1804b1-4bb88824a5bmr752355365e9.13.1796191678147; Tue, 01 Dec 2026 22:07:58 -0800 (PST) Received: from federation.lan ([194.105.5.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb906817ccsm688956195e9.5.2026.12.01.22.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 22:07:57 -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] usbnet: don't lose rx mode updates that arrive during set_rx_mode() Date: Wed, 2 Dec 2026 09:35:13 +0330 Message-ID: <20261202060513.660741-1-m.yary16@gmail.com> X-Mailer: git-send-email 2.56.1 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 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. test_and_clear_bit() is fully ordered, so set_rx_mode() reads the netdev flags only after the bit is cleared. No retry is lost: the bit was already cleared whether or not set_rx_mode() succeeded. 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. 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 --- 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 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index 97a30dd..74c100c 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c @@ -1184,8 +1184,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 +1293,7 @@ skip_reset: 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);