From: Daniel Zahka <daniel.zahka@gmail.com>
To: Kiran Kella <kiran.kella@broadcom.com>,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
willemb@google.com, pabeni@redhat.com, andrew+netdev@lunn.ch,
horms@kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
jayakrishnan.udayavarma@broadcom.com, ajit.khaparde@broadcom.com,
akhilesh.samineni@broadcom.com
Subject: Re: [net-next, v2 1/2] psp: Support for transmit on logical device when the underlying transport device supports PSP.
Date: Tue, 24 Feb 2026 15:58:27 -0500 [thread overview]
Message-ID: <0a850f65-be67-4a66-941f-17d8440e987b@gmail.com> (raw)
In-Reply-To: <20260223191154.2800616-2-kiran.kella@broadcom.com>
On 2/23/26 2:11 PM, Kiran Kella wrote:
> This is achieved by propagating the psp_dev from the lower device
> to the upper devices in the device stack via a netdevice notifier.
> The lowest device owns the psp_dev pointer while the upper devices
> just borrow the pointer. When the lower device is unlinked, the
> borrowed pointer is cleared in the upper device.
> Assumption being that psp_dev is set on the lowest device before
> any upper devices are stacked on that lowest device.
>
> Signed-off-by: Kiran Kella <kiran.kella@broadcom.com>
> Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde@broadcom.com>
> Reviewed-by: Akhilesh Samineni <akhilesh.samineni@broadcom.com>
> ---
> net/psp/psp_main.c | 109 ++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 108 insertions(+), 1 deletion(-)
>
> diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
> index a8534124f626..fac785dcfa0f 100644
> --- a/net/psp/psp_main.c
> +++ b/net/psp/psp_main.c
> @@ -3,6 +3,7 @@
> #include <linux/bitfield.h>
> #include <linux/list.h>
> #include <linux/netdevice.h>
> +#include <linux/rtnetlink.h>
> #include <linux/xarray.h>
> #include <net/net_namespace.h>
> #include <net/psp.h>
> @@ -110,13 +111,45 @@ void psp_dev_free(struct psp_dev *psd)
> kfree_rcu(psd, rcu);
> }
>
> +/**
> + * psp_clear_upper_dev_psp_dev() - Clear borrowed psp_dev pointer on upper
> + * device
> + * @upper_dev: Upper device that may have borrowed psp_dev pointer
> + * @priv: netdev_nested_priv containing the psp_dev being unregistered
> + *
> + * Callback for netdev_walk_all_upper_dev_rcu() to clear borrowed psp_dev
> + * pointers on upper devices when the underlying psp_dev is being unregistered.
> + *
> + * Return: 0 to continue walking, non-zero to stop.
> + */
> +static int psp_clear_upper_dev_psp_dev(struct net_device *upper_dev,
> + struct netdev_nested_priv *priv)
> +{
> + struct psp_dev *psd = priv->data;
> + struct psp_dev *upper_psd;
> +
> + upper_psd = rcu_dereference(upper_dev->psp_dev);
> + if (upper_psd == psd)
> + rcu_assign_pointer(upper_dev->psp_dev, NULL);
> +
> + return 0;
> +}
> +
> /**
> * psp_dev_unregister() - unregister PSP device
> * @psd: PSP device structure
> + *
> + * Unregisters a PSP device and clears all borrowed psp_dev pointers on
> + * upper devices (e.g., VLAN subinterfaces) that reference this device.
> + * This prevents use-after-free if upper devices still have borrowed
> + * pointers when the psp_dev structure is freed.
> */
> void psp_dev_unregister(struct psp_dev *psd)
> {
> struct psp_assoc *pas, *next;
> + struct netdev_nested_priv priv = {
> + .data = psd,
> + };
>
> mutex_lock(&psp_devs_lock);
> mutex_lock(&psd->lock);
> @@ -137,6 +170,12 @@ void psp_dev_unregister(struct psp_dev *psd)
>
> rcu_assign_pointer(psd->main_netdev->psp_dev, NULL);
>
> + /* Clear borrowed psp_dev pointers on all upper devices */
> + rcu_read_lock();
> + netdev_walk_all_upper_dev_rcu(psd->main_netdev,
> + psp_clear_upper_dev_psp_dev, &priv);
> + rcu_read_unlock();
> +
> psd->ops = NULL;
> psd->drv_priv = NULL;
>
> @@ -313,11 +352,79 @@ int psp_dev_rcv(struct sk_buff *skb, u16 dev_id, u8 generation, bool strip_icv)
> }
> EXPORT_SYMBOL(psp_dev_rcv);
>
> +/**
> + * psp_netdevice_event() - Handle netdevice events for PSP device propagation
> + * @nb: notifier block
> + * @event: netdevice event
> + * @ptr: netdevice notifier info
> + *
> + * Propagates psp_dev pointer from lower devices to upper devices when
> + * upper devices are created (e.g., VLAN subinterfaces).
> + * Excluding from this logic, the upper devices that have multiple lower
> + * devices eg., bond devices.
> + *
> + * Return: NOTIFY_DONE
> + */
> +static int psp_netdevice_event(struct notifier_block *nb,
> + unsigned long event, void *ptr)
> +{
> + struct netdev_notifier_changeupper_info *info;
> + struct net_device *dev, *upper_dev;
> + struct psp_dev *psd;
> +
> + if (event != NETDEV_CHANGEUPPER)
> + return NOTIFY_DONE;
> +
> + info = ptr;
> + dev = netdev_notifier_info_to_dev(ptr);
> + upper_dev = info->upper_dev;
> +
> + if (netif_is_lag_master(upper_dev))
> + return NOTIFY_DONE;
> +
> + if (info->linking) {
> + /* Lower device is being linked to an upper device.
> + * Propagate psp_dev from the immediate lower device to the
> + * upper device. The immediate lower device would have already
> + * got the psp_dev pointer set in a previous notification (or
> + * owns it if it's the lowest device).
> + * Upper devices just borrow the pointer.
> + */
> + psd = rtnl_dereference(dev->psp_dev);
> + if (psd)
> + rcu_assign_pointer(upper_dev->psp_dev, psd);
> + } else {
> + /* Lower device is being unlinked from an upper device.
> + * Clear the borrowed psp_dev pointer.
> + */
> + psd = rtnl_dereference(upper_dev->psp_dev);
> + if (psd)
> + rcu_assign_pointer(upper_dev->psp_dev, NULL);
> + }
> +
> + return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block psp_netdevice_notifier = {
> + .notifier_call = psp_netdevice_event,
> +};
> +
> static int __init psp_init(void)
> {
> + int err;
> +
> mutex_init(&psp_devs_lock);
>
> - return genl_register_family(&psp_nl_family);
> + err = register_netdevice_notifier(&psp_netdevice_notifier);
> + if (err)
> + return err;
> +
> + err = genl_register_family(&psp_nl_family);
> + if (err) {
> + unregister_netdevice_notifier(&psp_netdevice_notifier);
> + return err;
> + }
> + return 0;
> }
>
> subsys_initcall(psp_init);
The lack of support for netns is a bit of a gap for this feature. It may
make sense to see if what was posted in
https://lore.kernel.org/netdev/20260224002410.1553838-1-weibunny@fb.com/
is sufficient for your use case, as it handles cases where upper devices
are in a different netns from psd->main_netdev.
next prev parent reply other threads:[~2026-02-24 20:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 19:11 [net-next, v2 0/2] psp: Support PSP Tx on logical devices like VLAN Kiran Kella
2026-02-23 19:11 ` [net-next, v2 1/2] psp: Support for transmit on logical device when the underlying transport device supports PSP Kiran Kella
2026-02-24 20:58 ` Daniel Zahka [this message]
2026-02-26 11:38 ` Kiran Kella
2026-02-26 11:46 ` Kiran Kella
2026-02-26 14:11 ` Daniel Zahka
2026-02-26 15:11 ` Kiran Kella
2026-02-27 1:06 ` Jakub Kicinski
2026-02-23 19:11 ` [net-next, v2 2/2] selftests: drv-net: psp: add test for VLAN sub-interface Kiran Kella
2026-02-23 21:58 ` Jakub Kicinski
2026-02-25 7:22 ` Kiran Kella
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=0a850f65-be67-4a66-941f-17d8440e987b@gmail.com \
--to=daniel.zahka@gmail.com \
--cc=ajit.khaparde@broadcom.com \
--cc=akhilesh.samineni@broadcom.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jayakrishnan.udayavarma@broadcom.com \
--cc=kiran.kella@broadcom.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemb@google.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