* [net-next 0/2] psp: Support PSP Tx on logical devices like VLAN
@ 2026-01-21 7:35 Kiran Kella
2026-01-21 7:35 ` [net-next 1/2] psp: Support for transmit on logical device when the underlying transport device supports PSP Kiran Kella
2026-01-21 7:35 ` [net-next 2/2] selftests: drv-net: psp: add test for VLAN sub-interface Kiran Kella
0 siblings, 2 replies; 5+ messages in thread
From: Kiran Kella @ 2026-01-21 7:35 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, andrew+netdev, horms
Cc: netdev, linux-kernel, jayakrishnan.udayavarma, ajit.khaparde,
akhilesh.samineni, Kiran Kella
This patch adds support to allow transmit if the bottom most underlying
transport device matches the PSP device associated with the
transmitting application socket.
python ./psp.py
TAP version 13
1..29
ok 1 psp.data_basic_send_v0_ip4
ok 2 psp.data_basic_send_v0_ip6
ok 3 psp.data_basic_send_v1_ip4
ok 4 psp.data_basic_send_v1_ip6
ok 5 psp.data_basic_send_v2_ip4
ok 6 psp.data_basic_send_v2_ip6
ok 7 psp.data_basic_send_v3_ip4
ok 8 psp.data_basic_send_v3_ip6
ok 9 psp.data_mss_adjust_ip4
ok 10 psp.data_mss_adjust_ip6
ok 11 psp.dev_list_devices
ok 12 psp.dev_get_device
ok 13 psp.dev_get_device_bad
ok 14 psp.dev_rotate
ok 15 psp.dev_rotate_spi
ok 16 psp.assoc_basic
ok 17 psp.assoc_bad_dev
ok 18 psp.assoc_sk_only_conn
ok 19 psp.assoc_sk_only_mismatch
ok 20 psp.assoc_sk_only_mismatch_tx
ok 21 psp.assoc_sk_only_unconn
ok 22 psp.assoc_version_mismatch
ok 23 psp.assoc_twice
ok 24 psp.data_send_bad_key
ok 25 psp.data_send_disconnect
ok 26 psp.data_stale_key
ok 27 psp.removal_device_rx
ok 28 psp.removal_device_bi
ok 29 psp.vlan_basic_send
# Totals: pass:29 fail:0 xfail:0 xpass:0 skip:0 error:0
#
# Responder logs (0):
# STDERR:
# Set PSP enable on device 6 to 0xf
# Set PSP enable on device 6 to 0x0
Kiran Kella (2):
psp: Support for transmit on logical device when the underlying
transport device supports PSP.
selftests: drv-net: psp: add test for VLAN sub-interface
net/psp/psp_main.c | 114 ++++++++++++++++++++
tools/testing/selftests/drivers/net/psp.py | 117 ++++++++++++++++++++-
2 files changed, 229 insertions(+), 2 deletions(-)
--
2.45.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [net-next 1/2] psp: Support for transmit on logical device when the underlying transport device supports PSP.
2026-01-21 7:35 [net-next 0/2] psp: Support PSP Tx on logical devices like VLAN Kiran Kella
@ 2026-01-21 7:35 ` Kiran Kella
2026-01-22 4:19 ` [net-next,1/2] " Jakub Kicinski
2026-01-21 7:35 ` [net-next 2/2] selftests: drv-net: psp: add test for VLAN sub-interface Kiran Kella
1 sibling, 1 reply; 5+ messages in thread
From: Kiran Kella @ 2026-01-21 7:35 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, andrew+netdev, horms
Cc: netdev, linux-kernel, jayakrishnan.udayavarma, ajit.khaparde,
akhilesh.samineni, Kiran Kella
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 stack are linked on that lowest device at a
later point of time.
In case of bond devices:
- If an upper device has multiple lower devices, the psp_dev is
not propogated as it would be ambiguous which slave will be used
for transmission.
- If a bond device transitions from having one slave device to
multiple slaves, any previously borrowed psp_dev pointer is
cleared to avoid ambiguity.
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 | 114 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 114 insertions(+)
diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
index a8534124f626..0bff50c9314d 100644
--- a/net/psp/psp_main.c
+++ b/net/psp/psp_main.c
@@ -313,10 +313,124 @@ 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).
+ */
+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 (info->linking) {
+ bool has_multiple_lowers = false;
+ struct list_head *iter;
+
+ /* 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.
+ *
+ * However, if the upper device has multiple lower devices,
+ * don't propagate psp_dev as it would be ambiguous
+ * which slave will be used for transmission (eg., bond device).
+ * If the upper device already has psp_dev set and is getting
+ * a second lower device, clear the psp_dev.
+ */
+
+ rcu_read_lock();
+ iter = &upper_dev->adj_list.lower;
+ /* Check if there's a second lower device */
+ if (netdev_next_lower_dev_rcu(upper_dev, &iter))
+ if (netdev_next_lower_dev_rcu(upper_dev, &iter))
+ has_multiple_lowers = true;
+
+ /* If upper device now has multiple lower devices, clear psp_dev
+ * if it was previously set (from when it had only one slave).
+ */
+ if (has_multiple_lowers) {
+ psd = rcu_dereference(upper_dev->psp_dev);
+ rcu_read_unlock();
+ if (psd)
+ rcu_assign_pointer(upper_dev->psp_dev, NULL);
+
+ return NOTIFY_DONE;
+ }
+
+ /* Get psp_dev from the immediate lower device */
+ psd = rcu_dereference(dev->psp_dev);
+ rcu_read_unlock();
+
+ /* Propagate psp_dev to upper device if found */
+ if (psd)
+ rcu_assign_pointer(upper_dev->psp_dev, psd);
+ } else {
+ struct net_device *remaining_lower = NULL;
+ bool has_single_lower = false;
+ struct list_head *iter;
+
+ /* Lower device is being unlinked from an upper device.
+ * After unlinking, check if the upper device now has exactly
+ * one lower device remaining. If so, propagate psp_dev from
+ * that remaining lower device to the upper device.
+ */
+
+ rcu_read_lock();
+ iter = &upper_dev->adj_list.lower;
+ remaining_lower = netdev_next_lower_dev_rcu(upper_dev, &iter);
+ /* Check if there's a second lower device */
+ if (remaining_lower)
+ if (!netdev_next_lower_dev_rcu(upper_dev, &iter))
+ has_single_lower = true;
+
+ if (has_single_lower) {
+ /* Upper device now has exactly one lower device.
+ * Propagate psp_dev from the remaining lower device.
+ */
+ psd = rcu_dereference(remaining_lower->psp_dev);
+ rcu_read_unlock();
+ if (psd)
+ rcu_assign_pointer(upper_dev->psp_dev, psd);
+ } else {
+ /* Upper device has zero or multiple lower devices.
+ * Clear psp_dev if it was previously set.
+ */
+ psd = rcu_dereference(upper_dev->psp_dev);
+ rcu_read_unlock();
+ 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)
{
mutex_init(&psp_devs_lock);
+ register_netdevice_notifier(&psp_netdevice_notifier);
+
return genl_register_family(&psp_nl_family);
}
--
2.45.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [net-next 2/2] selftests: drv-net: psp: add test for VLAN sub-interface
2026-01-21 7:35 [net-next 0/2] psp: Support PSP Tx on logical devices like VLAN Kiran Kella
2026-01-21 7:35 ` [net-next 1/2] psp: Support for transmit on logical device when the underlying transport device supports PSP Kiran Kella
@ 2026-01-21 7:35 ` Kiran Kella
2026-01-22 4:18 ` Jakub Kicinski
1 sibling, 1 reply; 5+ messages in thread
From: Kiran Kella @ 2026-01-21 7:35 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, andrew+netdev, horms
Cc: netdev, linux-kernel, jayakrishnan.udayavarma, ajit.khaparde,
akhilesh.samineni, Kiran Kella
Add test to validate that the psp device information is propagated
properly from the lower device to the upper devices so that
the PSP transmit validation passes.
Signed-off-by: Kiran Kella <kiran.kella@broadcom.com>
Reviewed-by: Akhilesh Samineni <akhilesh.samineni@broadcom.com>
---
tools/testing/selftests/drivers/net/psp.py | 117 ++++++++++++++++++++-
1 file changed, 115 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/psp.py b/tools/testing/selftests/drivers/net/psp.py
index 528a421ecf76..b0373d6b4998 100755
--- a/tools/testing/selftests/drivers/net/psp.py
+++ b/tools/testing/selftests/drivers/net/psp.py
@@ -17,7 +17,7 @@ from lib.py import ksft_not_none
from lib.py import KsftSkipEx
from lib.py import NetDrvEpEnv, PSPFamily, NlError
from lib.py import bkg, rand_port, wait_port_listen
-
+from lib.py import ip
def _get_outq(s):
one = b'\0' * 4
@@ -568,6 +568,119 @@ def removal_device_bi(cfg):
finally:
_close_conn(cfg, s)
+def vlan_basic_send(cfg):
+ """
+ Test PSP over VLAN-to-VLAN traffic
+
+ Network topology:
+ Local VLAN (nsim0.100) <---> Remote VLAN (nsim1.100)
+ | |
+ Local Physical (nsim0) <---> Remote Physical (nsim1)
+ [PSP configured here]
+ """
+ cfg.require_nsim()
+ _init_psp_dev(cfg)
+
+ # Store original interface names and addresses
+ orig_local_ifname = cfg.ifname
+ orig_local_ifindex = cfg.ifindex
+ orig_remote_ifname = cfg.remote_ifname
+ orig_local_addr_v4 = cfg.addr_v["4"]
+ orig_local_addr_v6 = cfg.addr_v["6"]
+ orig_remote_addr_v4 = cfg.remote_addr_v["4"]
+ orig_remote_addr_v6 = cfg.remote_addr_v["6"]
+
+ # VLAN configuration
+ vlan_id = 100
+ local_vlan_ifname = f"{orig_local_ifname}.{vlan_id}"
+ remote_vlan_ifname = f"{orig_remote_ifname}.{vlan_id}"
+
+ local_vlan_addr_v4 = "192.0.2.21"
+ remote_vlan_addr_v4 = "192.0.2.22"
+ local_vlan_addr_v6 = "2001:db8::21"
+ remote_vlan_addr_v6 = "2001:db8::22"
+
+ try:
+ # Create VLAN interface on LOCAL side
+ ip(f"link add link {orig_local_ifname} name {local_vlan_ifname} type vlan id {vlan_id}")
+ ip(f"addr add {local_vlan_addr_v4}/24 dev {local_vlan_ifname}")
+ ip(f"-6 addr add {local_vlan_addr_v6}/64 dev {local_vlan_ifname} nodad")
+ ip(f"link set {local_vlan_ifname} up")
+
+ # Create VLAN interface on REMOTE side
+ ip(f"link add link {orig_remote_ifname} name {remote_vlan_ifname} type vlan id {vlan_id}", host=cfg.remote)
+ ip(f"addr add {remote_vlan_addr_v4}/24 dev {remote_vlan_ifname}", host=cfg.remote)
+ ip(f"-6 addr add {remote_vlan_addr_v6}/64 dev {remote_vlan_ifname} nodad", host=cfg.remote)
+ ip(f"link set {remote_vlan_ifname} up", host=cfg.remote)
+
+ # Get VLAN interface indices
+ local_vlan_info = ip(f"-j link show {local_vlan_ifname}", json=True)[0]
+ local_vlan_ifindex = local_vlan_info['ifindex']
+
+ remote_vlan_info = ip(f"-j link show {remote_vlan_ifname}", json=True, host=cfg.remote)[0]
+ remote_vlan_ifindex = remote_vlan_info['ifindex']
+
+ # Temporarily switch cfg to use VLAN interfaces
+ # The PSP device is still on the physical interface, but
+ # the socket will be bound to the VLAN interface
+ cfg.ifname = local_vlan_ifname
+ cfg.ifindex = local_vlan_ifindex
+ cfg.remote_ifname = remote_vlan_ifname
+ cfg.addr_v["4"] = local_vlan_addr_v4
+ cfg.addr_v["6"] = local_vlan_addr_v6
+ cfg.remote_addr_v["4"] = remote_vlan_addr_v4
+ cfg.remote_addr_v["6"] = remote_vlan_addr_v6
+ cfg.addr = local_vlan_addr_v4
+ cfg.remote_addr = remote_vlan_addr_v4
+
+ s = _make_psp_conn(cfg, version=0)
+
+ try:
+ # Create PSP associations
+ # The socket's device is VLAN, but PSP device is on physical NIC
+ rx_assoc = cfg.pspnl.rx_assoc({
+ "version": 0,
+ "dev-id": cfg.psp_dev_id, # PSP device on physical interface
+ "sock-fd": s.fileno()
+ })
+ rx = rx_assoc['rx-key']
+ tx = _spi_xchg(s, rx)
+
+ cfg.pspnl.tx_assoc({
+ "dev-id": cfg.psp_dev_id,
+ "version": 0,
+ "tx-key": tx,
+ "sock-fd": s.fileno()
+ })
+
+ # Send data through VLAN interface (VLAN-to-VLAN traffic!)
+ data_len = _send_careful(cfg, s, 100)
+ _check_data_rx(cfg, data_len)
+
+ finally:
+ _close_psp_conn(cfg, s)
+
+ finally:
+ # Restore original interface configuration
+ cfg.ifname = orig_local_ifname
+ cfg.ifindex = orig_local_ifindex
+ cfg.remote_ifname = orig_remote_ifname
+ cfg.addr_v["4"] = orig_local_addr_v4
+ cfg.addr_v["6"] = orig_local_addr_v6
+ cfg.remote_addr_v["4"] = orig_remote_addr_v4
+ cfg.remote_addr_v["6"] = orig_remote_addr_v6
+ cfg.addr = orig_local_addr_v4
+ cfg.remote_addr = orig_remote_addr_v4
+
+ # Clean up VLAN interfaces
+ try:
+ ip(f"link del {local_vlan_ifname}")
+ except Exception:
+ pass
+ try:
+ ip(f"link del {remote_vlan_ifname}", host=cfg.remote)
+ except Exception:
+ pass
def psp_ip_ver_test_builder(name, test_func, psp_ver, ipver):
"""Build test cases for each combo of PSP version and IP version"""
@@ -622,7 +735,7 @@ def main() -> None:
]
ksft_run(cases=cases, globs=globals(),
- case_pfx={"dev_", "data_", "assoc_", "removal_"},
+ case_pfx={"dev_", "data_", "assoc_", "removal_", "vlan_"},
args=(cfg, ))
cfg.comm_sock.send(b"exit\0")
--
2.45.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [net-next 2/2] selftests: drv-net: psp: add test for VLAN sub-interface
2026-01-21 7:35 ` [net-next 2/2] selftests: drv-net: psp: add test for VLAN sub-interface Kiran Kella
@ 2026-01-22 4:18 ` Jakub Kicinski
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2026-01-22 4:18 UTC (permalink / raw)
To: Kiran Kella
Cc: davem, edumazet, pabeni, andrew+netdev, horms, netdev,
linux-kernel, jayakrishnan.udayavarma, ajit.khaparde,
akhilesh.samineni
On Tue, 20 Jan 2026 23:35:17 -0800 Kiran Kella wrote:
> --- a/tools/testing/selftests/drivers/net/psp.py
> +++ b/tools/testing/selftests/drivers/net/psp.py
> @@ -17,7 +17,7 @@ from lib.py import ksft_not_none
> from lib.py import KsftSkipEx
> from lib.py import NetDrvEpEnv, PSPFamily, NlError
> from lib.py import bkg, rand_port, wait_port_listen
> -
> +from lib.py import ip
>
don't clean up this white space, double new line is a thing in Python
for some reason
> def _get_outq(s):
> one = b'\0' * 4
> @@ -568,6 +568,119 @@ def removal_device_bi(cfg):
> finally:
> _close_conn(cfg, s)
>
> +def vlan_basic_send(cfg):
> + """
> + Test PSP over VLAN-to-VLAN traffic
> +
> + Network topology:
> + Local VLAN (nsim0.100) <---> Remote VLAN (nsim1.100)
> + | |
> + Local Physical (nsim0) <---> Remote Physical (nsim1)
> + [PSP configured here]
> + """
> + cfg.require_nsim()
why would this only work on nsim?
> + _init_psp_dev(cfg)
> +
> + # Store original interface names and addresses
> + orig_local_ifname = cfg.ifname
> + orig_local_ifindex = cfg.ifindex
> + orig_remote_ifname = cfg.remote_ifname
> + orig_local_addr_v4 = cfg.addr_v["4"]
> + orig_local_addr_v6 = cfg.addr_v["6"]
> + orig_remote_addr_v4 = cfg.remote_addr_v["4"]
> + orig_remote_addr_v6 = cfg.remote_addr_v["6"]
maybe instead of all this saving and restoring just make and object and
give it all the attributes so that it looks like cfg? Instead of
modifying the real cfg I mean.
> + # VLAN configuration
> + vlan_id = 100
> + local_vlan_ifname = f"{orig_local_ifname}.{vlan_id}"
> + remote_vlan_ifname = f"{orig_remote_ifname}.{vlan_id}"
> +
> + local_vlan_addr_v4 = "192.0.2.21"
> + remote_vlan_addr_v4 = "192.0.2.22"
> + local_vlan_addr_v6 = "2001:db8::21"
> + remote_vlan_addr_v6 = "2001:db8::22"
> +
> + try:
> + # Create VLAN interface on LOCAL side
> + ip(f"link add link {orig_local_ifname} name {local_vlan_ifname} type vlan id {vlan_id}")
please use defer()
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [net-next,1/2] psp: Support for transmit on logical device when the underlying transport device supports PSP.
2026-01-21 7:35 ` [net-next 1/2] psp: Support for transmit on logical device when the underlying transport device supports PSP Kiran Kella
@ 2026-01-22 4:19 ` Jakub Kicinski
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2026-01-22 4:19 UTC (permalink / raw)
To: kiran.kella
Cc: Jakub Kicinski, davem, ajit.khaparde, jayakrishnan.udayavarma,
netdev, akhilesh.samineni, pabeni, edumazet, andrew+netdev,
linux-kernel, horms
Haven't had the time to think about this TBH but FWIW:
This is an AI-generated review of your patch.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
psp: Support for transmit on logical device when the underlying transport
device supports PSP.
This patch propagates psp_dev pointers from lower devices to upper devices
(e.g., VLANs) via a netdevice notifier. Upper devices borrow the pointer
without taking a reference, and the borrowed pointer is cleared when the
link changes.
> diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
> index a8534124f626..0bff50c9314d 100644
> --- a/net/psp/psp_main.c
> +++ b/net/psp/psp_main.c
> @@ -313,10 +313,124 @@ 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
[ ... ]
> + * Propagates psp_dev pointer from lower devices to upper devices when
> + * upper devices are created (e.g., VLAN subinterfaces).
> + */
> +static int psp_netdevice_event(struct notifier_block *nb,
> + unsigned long event, void *ptr)
> +{
[ ... ]
> + /* Get psp_dev from the immediate lower device */
> + psd = rcu_dereference(dev->psp_dev);
> + rcu_read_unlock();
> +
> + /* Propagate psp_dev to upper device if found */
> + if (psd)
> + rcu_assign_pointer(upper_dev->psp_dev, psd);
The commit message states that borrowed pointers are cleared when the lower
device is "unlinked". However, what happens if psp_dev_unregister() is
called on the lower device without first unlinking the upper devices?
Looking at nsim_psp_rereg_write() in drivers/net/netdevsim/psp.c, it calls
nsim_psp_uninit()->psp_dev_unregister() without unregistering the netdevice.
If there are upper devices (e.g., VLANs) that have borrowed the psp_dev
pointer, would they be left with a dangling pointer after the RCU grace
period completes?
Similarly, nsim_destroy() calls nsim_psp_uninit() before calling
unregister_netdevice(), so the upper devices would still have borrowed
pointers when psp_dev_unregister() frees the psp_dev structure.
Could this lead to use-after-free if an upper device's psp_dev pointer is
accessed after the underlying psp_dev has been freed?
Would it make sense to either:
(a) Document that netdevice must be unregistered before psp_dev_unregister()
is called, or
(b) Walk the upper device stack in psp_dev_unregister() to clear borrowed
pointers, or
(c) Update existing callers (netdevsim) to ensure proper ordering?
> + } else {
[ ... ]
> + return NOTIFY_DONE;
> +}
--
pw-bot: cr
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-01-22 4:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-21 7:35 [net-next 0/2] psp: Support PSP Tx on logical devices like VLAN Kiran Kella
2026-01-21 7:35 ` [net-next 1/2] psp: Support for transmit on logical device when the underlying transport device supports PSP Kiran Kella
2026-01-22 4:19 ` [net-next,1/2] " Jakub Kicinski
2026-01-21 7:35 ` [net-next 2/2] selftests: drv-net: psp: add test for VLAN sub-interface Kiran Kella
2026-01-22 4:18 ` Jakub Kicinski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox