Netdev List
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Wei Wang <weibunny.kernel@gmail.com>
Cc: netdev@vger.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>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	Wei Wang <weibunny@fb.com>
Subject: Re: [PATCH v14 net-next 3/5] psp: add a new netdev event for dev unregister
Date: Wed, 13 May 2026 18:41:55 -0700	[thread overview]
Message-ID: <20260513184155.0b5f71f6@kernel.org> (raw)
In-Reply-To: <20260508042611.130945-4-weibunny.kernel@gmail.com>

On Thu,  7 May 2026 21:26:08 -0700 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);

Let's check here if psp_dev_is_registered(psd) before
calling the notify. The list should be empty on a dead device
so psp_dev_disassoc_one() is fine, but it will be easy to forget
and add some code that doesn't expect dead devices in notify.

> +		psp_nl_notify_dev(psd, PSP_CMD_DEV_CHANGE_NTF);
> +		psp_dev_disassoc_one(psd, dev);
> +		mutex_unlock(&psd->lock);
> +		psp_dev_put(psd);
> +	} else {
> +		rcu_read_unlock();
> +	}
> +
> +	return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block psp_netdev_notifier = {
> +	.notifier_call = psp_netdev_event,
> +};
> +
> +static DEFINE_MUTEX(psp_notifier_lock);
> +static bool psp_notifier_registered;
> +
> +/*
> + * psp_attach_netdev_notifier() - register netdev notifier on first use
> + *
> + * Register the netdevice notifier when the first device association
> + * is created. In many installations no associations will be created and
> + * the notifier won't be needed.
> + *
> + * Must be called without psd->lock held, due to lock ordering:
> + * rtnl_lock -> psd->lock (the notifier callback runs under rtnl_lock
> + * and takes psd->lock).
> + */

This is so almost kdoc :) Either remove the top line with the function
name, or add Returns: and make it a real kdoc (slight preference towards
former)

> +int psp_attach_netdev_notifier(void)

  reply	other threads:[~2026-05-14  1:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-08  4:26 [PATCH v14 net-next 0/5] psp: Add support for dev-assoc/disassoc Wei Wang
2026-05-08  4:26 ` [PATCH v14 net-next 1/5] psp: add admin/non-admin version of psp_device_get_locked Wei Wang
2026-05-08  4:26 ` [PATCH v14 net-next 2/5] psp: add new netlink cmd for dev-assoc and dev-disassoc Wei Wang
2026-05-14  1:31   ` Jakub Kicinski
2026-05-08  4:26 ` [PATCH v14 net-next 3/5] psp: add a new netdev event for dev unregister Wei Wang
2026-05-14  1:41   ` Jakub Kicinski [this message]
2026-05-08  4:26 ` [PATCH v14 net-next 4/5] selftests/net: Add bpf skb forwarding program Wei Wang
2026-05-08  4:26 ` [PATCH v14 net-next 5/5] selftests/net: psp: Add test for dev-assoc/disassoc Wei Wang
2026-05-14  1:46   ` Jakub Kicinski
2026-05-12  8:30 ` [PATCH v14 net-next 0/5] psp: Add support " Simon Horman

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=20260513184155.0b5f71f6@kernel.org \
    --to=kuba@kernel.org \
    --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=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --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