Re: [PATCH net] usbnet: don't lose rx mode updates that arrive during set_rx_mode()
From: Oliver Neukum
Date: Wed Dec 02 2026 - 04:14:44 EST
On 02.12.26 07:05, Mahdi Yari wrote:
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@xxxxxxxxxxxxxxx
Signed-off-by: Mahdi Yari <m.yary16@xxxxxxxxx>Acked-by: Oliver Neukum <oneukum@xxxxxxxx>