From: Paolo Abeni <pabeni@redhat.com>
To: Wei Wang <weibunny.kernel@gmail.com>,
netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
Daniel Zahka <daniel.zahka@gmail.com>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
David Wei <dw@davidwei.uk>, Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Simon Horman <horms@kernel.org>
Cc: Wei Wang <weibunny@fb.com>
Subject: Re: [PATCH v11 net-next 3/5] psp: add a new netdev event for dev unregister
Date: Mon, 13 Apr 2026 12:47:58 +0200 [thread overview]
Message-ID: <cb5bf340-e5fa-4866-b5c6-565709ba633c@redhat.com> (raw)
In-Reply-To: <20260408231415.522691-4-weibunny.kernel@gmail.com>
On 4/9/26 1:14 AM, Wei Wang wrote:
> +static int psp_netdev_event(struct notifier_block *nb, unsigned long event,
> + void *ptr)
> +{
> + struct net_device *dev = netdev_notifier_info_to_dev(ptr);
> + struct psp_dev *psd;
> +
> + if (event != NETDEV_UNREGISTER)
> + return NOTIFY_DONE;
> +
> + rcu_read_lock();
> + psd = rcu_dereference(dev->psp_dev);
> + if (psd && psp_dev_tryget(psd)) {
> + rcu_read_unlock();
> + mutex_lock(&psd->lock);
> + psp_dev_disassoc_one(psd, dev);
> + mutex_unlock(&psd->lock);
> + psp_dev_put(psd);
Sashiko notes that the above is racy:
---
Can this code race with psp_nl_dev_assoc_doit() and permanently leak a
net_device reference?
If CPU1 is executing psp_nl_dev_assoc_doit() and CPU2 is unregistering the
device, the following interleaving could happen:
CPU1 (psp_nl_dev_assoc_doit)
assoc_dev = dev_get_by_index(...) // acquires a reference
CPU2 (unregister_netdevice)
psp_netdev_event()
psd = rcu_dereference(dev->psp_dev); // sees NULL, returns
NOTIFY_DONE
CPU1 (psp_nl_dev_assoc_doit)
cmpxchg(&assoc_dev->psp_dev, NULL, psd); // succeeds!
list_add(...) // adds to psd->assoc_dev_list
If this occurs, the notifier misses the unregistration event since it runs
before the device is fully associated. The unregistering thread will then
enter netdev_wait_allrefs() and wait indefinitely because the reference
held in assoc_dev_list is never released.
---
/P
next prev parent reply other threads:[~2026-04-13 10:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-08 23:14 [PATCH v11 net-next 0/5] psp: Add support for dev-assoc/disassoc Wei Wang
2026-04-08 23:14 ` [PATCH v11 net-next 1/5] psp: add admin/non-admin version of psp_device_get_locked Wei Wang
2026-04-08 23:14 ` [PATCH v11 net-next 2/5] psp: add new netlink cmd for dev-assoc and dev-disassoc Wei Wang
2026-04-13 10:36 ` Paolo Abeni
2026-04-16 3:55 ` Wei Wang
2026-04-16 23:23 ` Wei Wang
2026-04-08 23:14 ` [PATCH v11 net-next 3/5] psp: add a new netdev event for dev unregister Wei Wang
2026-04-13 10:47 ` Paolo Abeni [this message]
2026-04-16 15:50 ` Wei Wang
2026-04-08 23:14 ` [PATCH v11 net-next 4/5] selftests/net: Add bpf skb forwarding program Wei Wang
2026-04-08 23:14 ` [PATCH v11 net-next 5/5] selftest/net: psp: Add test for dev-assoc/disassoc Wei Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cb5bf340-e5fa-4866-b5c6-565709ba633c@redhat.com \
--to=pabeni@redhat.com \
--cc=andrew+netdev@lunn.ch \
--cc=daniel.zahka@gmail.com \
--cc=davem@davemloft.net \
--cc=dw@davidwei.uk \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=weibunny.kernel@gmail.com \
--cc=weibunny@fb.com \
--cc=willemdebruijn.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox