Re: [PATCH net-next v4 3/5] psp: defer tx key deletions for SADB drivers

From: netdev-bot+sashiko

Date: Wed Nov 18 2026 - 01:05:14 EST


Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 2

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] The new PSP_ASSOC_DEFER_TX_KEY_DEL path in `psp_assoc_free()`
(net/psp/psp_sock.c:118-121) gives up its only psd reference before…
- [Medium] Removing the SADB check in `psp_sock_tx_rekey()` lets any non-
admin user who can reach the PSP device rekey one established TCP…
- [Low] The commit message never says that this patch turns on Tx rekey
for SADB devices.
- [Low] The patch adds a lock-context rule for SADB drivers that only the
commit message states: they must not call `psp_dev_unregister()` with…

--

psp: defer tx key deletions for SADB drivers

This commit adds a deferred deletion queue for Tx keys on SADB devices.
A key detached by a Tx rekey is removed from the device only after a
BQL-based descriptor grace period, which a delayed work item checks by
snapshotting per-queue num_queued and polling num_completed. It also
makes INET_PSP depend on BQL, requires ops-locked netdevs for SADB
drivers, and drops the check that rejected Tx rekey on SADB devices.

> diff --git a/Documentation/networking/psp.rst b/Documentation/networking/psp.rst
> index 43f222b38d3d4..ceb1e232317fc 100644
> --- a/Documentation/networking/psp.rst
> +++ b/Documentation/networking/psp.rst
> @@ -202,6 +202,48 @@ Drivers must use ``psp_skb_get_assoc_rcu()`` to check if PSP Tx offload

[ ... ]

> +* Before calling ``psp_dev_unregister()``, the driver must ensure that all
> + outstanding Tx descriptors containing key references have been completed
> + or discarded. PSP core deletes all remaining Tx keys during
> + unregistration without waiting for a grace period.

[Severity: Low]
Should this list also say that psp_dev_unregister() must not be called
with the netdev instance lock held? The commit message states that rule.
It is not in this list or in the psp_dev_unregister() kernel-doc, and
nothing asserts it.

psp_dev_unregister() now starts with:

psp_dev_unregister()
psp_deferred_del_stop()
disable_delayed_work_sync(&psd->tx_del.work)

and psp_deferred_del_work() takes the locks in this order:

mutex_lock(&psd->lock);
netdev_lock(psd->main_netdev);

Suppose a driver calls psp_dev_unregister() while holding
main_netdev->lock, and the work is blocked in netdev_lock(). Wouldn't
disable_delayed_work_sync() then wait forever?

Even with the work idle, the later mutex_lock(&psd->lock) in
psp_dev_unregister() would run under the netdev lock. That inverts the
lock order the work uses.

mlx5 complies today, because mlx5e_nic_disable() drops the netdev lock
before mlx5e_psp_unregister().

Could the rule go in this list with the other requirements? Something
like lockdep_assert_not_held(&psd->main_netdev->lock) in
psp_dev_unregister() would also match the ops-lock WARN_ON check in
psp_dev_create().

[ ... ]

> diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c
> index d497f41c483e1..48bffe088c79b 100644
> --- a/net/psp/psp_sock.c
> +++ b/net/psp/psp_sock.c
> @@ -114,8 +114,14 @@ static void psp_assoc_free(struct work_struct *work)
>
> mutex_lock(&psd->lock);
> if (psp_dev_is_registered(psd)) {
> - if (psp_assoc_needs_tx_key_del(pas))
> + if (psp_assoc_needs_tx_key_del(pas)) {
> + if (pas->flags & PSP_ASSOC_DEFER_TX_KEY_DEL) {
> + psp_deferred_del_queue(psd, pas);
> + mutex_unlock(&psd->lock);
> + return;
> + }

[Severity: Medium]
Once pas is on psd->tx_del.next, its psd reference belongs to the
deferred queue. This path keeps no reference of its own across
mutex_unlock(&psd->lock). Can psd be torn down while this thread is
still inside mutex_unlock()?

Documentation/locking/mutex-design.rst says mutex_unlock() may access the
mutex after releasing ownership, so the caller has to keep the mutex
alive until it returns. When there is a waiter, __mutex_unlock_slowpath()
releases ownership and then still takes lock->wait_lock and calls
debug_mutex_unlock(lock).

A possible sequence:

CPU1 (psp_assoc_free work) CPU2 (psp_dev_unregister)
psp_deferred_del_queue(psd, pas)
mutex_unlock(&psd->lock) mutex_lock(&psd->lock) succeeds
still in slowpath psp_deferred_del_uninit()
psp_dev_put(psd)
mutex_unlock(&psd->lock)
psp_dev_put(psd)
psp_dev_free()
mutex_destroy(&psd->lock)
kfree_rcu(psd, rcu)
debug_mutex_unlock(lock)

In the current tree, guard(preempt)() in __mutex_unlock_slowpath() and
kfree_rcu() keep the memory valid. Under CONFIG_DEBUG_MUTEXES, though,
mutex_destroy() clears lock->magic, so
DEBUG_LOCKS_WARN_ON(lock->magic != lock) can fire.

The old non-deferred path only called psp_dev_put(psd) after
mutex_unlock(). Would it work to take psp_dev_get(psd) before queueing
and call psp_dev_put(psd) after the unlock? Another option is for the
deferred queue to take its own reference.

[ ... ]

> @@ -287,10 +293,6 @@ psp_sock_tx_rekey(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,
> struct psp_assoc *new;
> int err;
>
> - if (psp_dev_has_sadb(psd)) {
> - NL_SET_ERR_MSG(extack, "Tx rekey not supported on this device");
> - return -EOPNOTSUPP;
> - }

[Severity: Low]
Removing this check turns on Tx rekey for SADB devices, but the commit
message doesn't say so. The subject is "defer tx key deletions for SADB
drivers". The only explicit mention, "allow tx rekey on SADB devices", is
in the v2 changelog below the --- line, so it won't be in the applied
commit.

The body also says:

"Rekeying introduces a code path where a psp_assoc is detached from its
socket and may be freed while the socket is still alive."

That reads as though the path was already reachable on SADB devices,
but this patch is what makes it reachable.

mlx5 is the only in-tree SADB driver: mlx5_psp_ops sets tx_key_add and
tx_key_del. With no driver changes, PSP_CMD_TX_ASSOC on an established
mlx5 socket used to return -EOPNOTSUPP and now installs a new SADB key.

Could the commit message state this behavior change directly, and say
whether mlx5 was checked against the new psp.rst driver requirements?

[Severity: Medium]
With this check gone, can a non-admin user use up the device SADB by
rekeying one socket in a loop?

PSP_CMD_TX_ASSOC has no GENL_ADMIN_PERM, and
psp_assoc_device_get_locked() calls psp_dev_check_access(psd, net, false).
Each rekey goes through:

psp_sock_tx_rekey()
psp_assoc_set_tx()
psp_dev_tx_key_add()
mlx5e_psp_assoc_add()

The old assoc is then flagged PSP_ASSOC_DEFER_TX_KEY_DEL. After RCU,
psp_deferred_del_queue() appends it to psd->tx_del.next with no count or
cap:

list_move_tail(&pas->assocs_list, &psd->tx_del.next);
schedule_delayed_work(&psd->tx_del.work, 0);

psp_deferred_del_work() frees keys only after a full BQL grace period,
polled every PSP_TX_GRACE_POLL_MS (1000 ms). Keys queued while a period
is active wait for the next one. If any queue below real_num_tx_queues
stops completing BQL bytes, the list keeps growing until
psp_dev_unregister().

Before this patch, each socket used at most one SADB Tx entry. Now one
socket can hold about rekey rate times (RCU grace period plus 1-2 s)
entries. The SADB is a hardware resource shared across namespaces, so
tx_key_add could start failing for other users. The pas allocation is
charged via GFP_KERNEL_ACCOUNT, but SADB capacity is not.

The commit message acknowledges the missing rate limit and suggests not
exposing PSP devices to untrusted users. However, devices in init_net
are reachable by all of its users, and there is no knob to restrict
tx-assoc.

Would it make sense to add a per-socket or per-device bound on
outstanding deferred keys in this change?

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-psp-v4-0-1a599df2aefa%40gmail.com