๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26163

Re: [PATCH net] usbnet: don't lose rx mode updates that arrive during set_rx_mode()

#26163
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 06:08
123 lines
12459 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] On weakly ordered CPUs this fix can still lose an rx-mode
  update, because only the reader side of the bit handoff has a barrier.

--

usbnet: don't lose rx mode updates that arrive during set_rx_mode()

This patch changes usbnet_deferred_kevent() to clear EVENT_SET_RX_MODE
with test_and_clear_bit() before it calls the minidriver's set_rx_mode().
Before this, the bit was cleared after set_rx_mode() returned, and that
could wipe a request made while set_rx_mode() was sleeping in a control
transfer.

> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
> index 97a30dd22c545..74c100c0f0467 100644
> --- a/drivers/net/usb/usbnet.c
> +++ b/drivers/net/usb/usbnet.c

[ ... ]

> @@ -1295,7 +1293,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);

[Severity: Medium]

The commit message says:

  test_and_clear_bit() is fully ordered, so set_rx_mode() reads the
  netdev flags only after the bit is cleared.

Is a barrier on the reader side enough on weakly ordered architectures?
It seems to need a matching barrier on the writer side. The writer,
usbnet_defer_kevent(), sets the bit with a plain set_bit():

drivers/net/usb/usbnet.c:usbnet_defer_kevent() {
	set_bit (work, &dev->flags);
	if (!usbnet_going_away(dev)) {
		if (!schedule_work(&dev->kevent))
	...
}

Nothing orders the earlier store to the state that set_rx_mode() reads
before this set_bit(). The dev_mc_add() path is one example:

dev_mc_add()
  __dev_mc_add()
    __hw_addr_add_ex()
      list_add_tail_rcu(&ha->list, &list->list);
      __hw_addr_count_inc(list);
    __dev_set_rx_mode()
      usbnet_set_rx_mode()
        usbnet_defer_kevent()
          set_bit(EVENT_SET_RX_MODE, &dev->flags);

All of this runs under netif_addr_lock_bh(). A lock acquire does not
order the count store before the later set_bit().

On the reader side, usbnet_cdc_update_filter() reads the state without
the addr lock:

drivers/net/usb/cdc_ether.c:usbnet_cdc_update_filter() {
	...
	if (net->flags & IFF_PROMISC)
		cdc_filter |= USB_CDC_PACKET_TYPE_PROMISCUOUS;
	if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI))
		cdc_filter |= USB_CDC_PACKET_TYPE_ALL_MULTICAST;
	...
}

Suppose the kevent is already running, so PENDING has been cleared.
Could this sequence happen on arm64 or POWER?

CPU0                               CPU1 (kevent running)
__hw_addr_count_inc(list)
set_bit(EVENT_SET_RX_MODE)
  (visible before count store)
                                   test_and_clear_bit(EVENT_SET_RX_MODE)
                                     sees and clears the bit
                                   usbnet_cdc_update_filter()
                                     netdev_mc_empty() sees old count
schedule_work() succeeds,
kevent requeued
                                   rerun: EVENT_SET_RX_MODE is clear,
                                   __handle_set_rx_mode() is skipped

If so, the SET_ETHERNET_PACKET_FILTER request with ALL_MULTICAST for the
first multicast address would never be sent. That is the same lost update
this patch is meant to fix, and it would affect cdc_ether, cdc_ncm and
int51x1.

If schedule_work() fails because the work is still pending, ordering
holds. The fully ordered test_and_set_bit() on PENDING in queue_work()
pairs with the worker's barrier, so the gap seems limited to the case
where the kevent is already running. This can't happen on x86.

The IFF_PROMISC and IFF_ALLMULTI paths from the bridge scenario call
netdev_info() in __dev_set_promiscuity() and __dev_set_allmulti(). That
probably adds a full barrier as a side effect, so the mc list path looks
like the main remaining case.

Would adding smp_mb__before_atomic() before the set_bit() in
usbnet_defer_kevent() (or in usbnet_set_rx_mode()) pair with the barrier
in test_and_clear_bit() and close this gap?

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202060513.660741-1-m.yary16%40gmail.com
Technical Details
Message-ID: <179627810686.3146.17258058159289526658@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376313-linux-kernel-netdev=dewy.ru
References: <20261202060513.660741-1-m.yary16@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376313-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] usbnet: don't lose rx mode updates that arrive during
 set_rx_mode()
Date: Thu, 03 Dec 2026 06:08:26 +0000
Organization: Usenet Network
Message-ID: <179627810686.3146.17258058159289526658@kernel.org>
References: <20261202060513.660741-1-m.yary16@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2188060"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:nd/3PaucbzS3zduzOvPCXvuhA7E= sha256:/bed4rr0nAbTtKSq5LEjGtJ7VMcqAbMT+trQ6yCEKVU=
	sha1:HY+xA3bzkCrgAlOWiK8UoZE5OP4= sha256:Pc2oOr7Lspqamu3IFFNf+JTdcCHxjDJ9PEasm9JEy9I=
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 1B0EB117830; Thu,  3 Dec 2026 09:08:47 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.401
X-Spam-Status: No, score=-2.401 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	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=kernel.org
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 r76fs_jCTi7Z;
	Thu,  3 Dec 2026 09:08:39 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-376313-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id A197011782A; Thu,  3 Dec 2026 09:08:31 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 57C5260294C; Thu,  3 Dec 2026 06:08:30 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail;
	t=1796278109;
	b=CF3jn6KWivqgdvwB1dSESeRUqsbc441sEbMx7l42y+9MsnAYbP1s6e2pj7o6uzjVin/k
	 ur56B8GOp57ifX5TKLd0zl9G+ZdU8E5Je4QyfxYfgIQpwlN+KYbZjd6rk5Q1Exfm8W3Mk
	 rM4a1hwPWsV9sf/Js4+hL6QMeasijEwjybvobAA4keXdo+9QHuky9Aw8KTrPCNxRcSCSQ
	 Mbh8+ldlUhGDARD4shXpjRctv/xSLwicYWNPijBJr+gxarQn9VLDIU9dz2uXXwMGgNDNe
	 GuWzbPycssb4wfVZacAOjCORGxD/F1lup1yXH2JzjUXg1OUM8LORZFkpakVSi+tw8ZA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796278109;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=LMMvWOZn7/lTaMbVtjEUYK+E12AUx39dw/RPBTZcqJk=;
	b=GWqaAhswO3tcylSczzwbAvsAcY5+dttJM0lgpDxeMBcXGKnlDVERSAOPj9ffUlmX5UCz
	 s68TBHj8F/B1Ea1YbnqC/oNpnmIgC9wWRu6TYWvm/XokEAHOflzVLEUWWwVwBm+qHd7VP
	 e5IgOnJRwBTjaf3iQs6hQIvXkGMt4VF4NCuAR8P6QbBNvkTvyviFP2oLmUpE/fYFc5CL7
	 bmfiQc53wiv6jhm0TnCWhLlF0dxi6us9n5dSGNxKqNEsttgfrydlkEM0Cc9+MLTALZKvi
	 ke/yhwjECoIUa/vpgBxqo89TSpygTdRjWjgEe8yN936a6HhtGtqLIvDAWnm+m0yiCOQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jiBIdaJH;
	arc=fail 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 38E24606A33B;
	Thu,  3 Dec 2026 06:08:29 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jiBIdaJH
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796278108;
	b=fGBppLXnVI0mhsoPqBiVysrWbLfDMye26dXdCk/uPsHBe6R4sZFLw1dI37+BYJtAa5Q+
	 rGpsUdBFsS6+Qsf6NTZJ6ilO/VqntDeYaP+2ykYtollvBoygvIatiQ1JB3tUw5OW7e+6e
	 2O+KDjOn4yfi8GSB5fKuZtJJpDKIpGHjTRpvTnLu9XRqSNONzXPAaQnLXQwmpHB3LmSM1
	 +/hP8V8BihfAqTXfOqKLorCPsZ3o6XbG7DjgxEVsGaL9qytaLPyTA0JPgw0qjUzeexRkr
	 AkSzEm+lvfusLDFQ4qc28ZH/1NI6RiKspMqpcS1QMWwx8Db/ODCvSdQ+UgNex06a98Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796278108;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=LMMvWOZn7/lTaMbVtjEUYK+E12AUx39dw/RPBTZcqJk=;
	b=g3XC9Tw4iZpQy0O55rJ/IDsZLkdII7diLK0U8DzW4HL02HJBmjqXXNhcJZxikJ4rHviz
	 9KC/8DbMvQsD0LDUGkqf2W8KM6V9OwRlNB1FizpNrnIwLbl1tdZ/sH8HDCm+TwCYqpdvE
	 nGhG8xzMOADdimJi/sqY7CjVkjUSJO80l2GoyT4Jcmo3UO7Uy96y+80YoakSUqLv+A7/W
	 IBesMrc+CSftXVDnSWHBRLgdhRxxyjSuwF3nihOiMcNnaM/4FBRFp/gi9gjCm3c0j8QNd
	 gHFUbRosZOJZjTaqr+aptiw3dj/hOX1z38cYNFZYNZOuZ1wTGOL141KQK2VTN6VmLDw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jiBIdaJH;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56D1C606A322;
	Thu,  3 Dec 2026 06:08:28 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A1941F00893;
	Thu,  3 Dec 2026 06:08:27 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796278108;
	bh=LMMvWOZn7/lTaMbVtjEUYK+E12AUx39dw/RPBTZcqJk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=jiBIdaJHjzSBdrE1YONtJYHPgc9O0MTAgkHFcfA4pnhZIxg4kLs4ynGvCUOKkMUr+
	 vU7dd+JU17OQjzMzyqrHBzkGnfZmpsPYsiq/BxVA0jhs8WELDo/vO04au6raC8UMo7
	 ENKFPpywxbDpyRnlnWpoikM6KN9dEEeXGGwY2ZHPMVqO6UsuRzUD9Me0N0L+MrLxRj
	 VNQAPR3SGMEmTmwOfdidViX2pCWR2ge37XqSOgmZSMkv/0YBK/qS9pwgg5gbNbFC4I
	 H8tSqn6KKAEFldvnpbxMKoyfSjt6fRK58H3CSzjEbX6LnrzFxoDsX0rD6Tcm2KLfJ2
	 ejsmusSrmfsQg==
X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, oneukum@suse.com, netdev@vger.kernel.org,
 linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
 stable@vger.kernel.org
X-In-Reply-To: <20261202060513.660741-1-m.yary16@gmail.com>
X-sashiko-severity: Medium
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