[PATCH net-next v5 3/6] psp: document lock ordering with the netdev instance lock
From: Daniel Zahka
Date: Wed Nov 18 2026 - 09:10:41 EST
PSP core calls driver ops with psp_dev::lock held, and drivers may take
the netdev instance lock inside them. mlx5e_psp_set_config() has done so
since commit 1e6e0cec0dab ("net/mlx5e: psp: Make PSP steering config
dynamic"). That commit established a lock ordering that was not
documented anywhere.
Document it. psp_dev_create() and psp_dev_unregister() take
psp_devs_lock and psp_dev::lock, so assert that they are not called
with the netdev instance lock held. The next patch adds a work item to
PSP core which relies on this ordering.
Signed-off-by: Daniel Zahka <daniel.zahka@xxxxxxxxx>
---
v5:
- new patch
---
net/psp/psp_main.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
index 273b010d2355..ba44154cf8dc 100644
--- a/net/psp/psp_main.c
+++ b/net/psp/psp_main.c
@@ -19,6 +19,8 @@ struct mutex psp_devs_lock;
*
* psp_devs_lock protects the psp_devs xarray.
* Ordering is take the psp_devs_lock and then the instance lock.
+ * The PSP instance lock must be taken before its main netdev's instance
+ * lock.
* Each instance is protected by RCU, and has a refcount.
* When driver unregisters the instance gets flushed, but struct sticks around.
*/
@@ -53,6 +55,7 @@ int psp_dev_check_access(struct psp_dev *psd, struct net *net, bool admin)
* @psd_caps: device capabilities
* @priv_ptr: back-pointer to driver private data
*
+ * Context: Must not be called with the netdev instance lock held.
* Return: pointer to allocated PSP device, or ERR_PTR.
*/
struct psp_dev *
@@ -64,6 +67,8 @@ psp_dev_create(struct net_device *netdev,
static u32 last_id;
int err;
+ lockdep_assert_not_held(&netdev->lock);
+
if (WARN_ON(!psd_caps->versions ||
!psd_ops->set_config ||
!psd_ops->key_rotate ||
@@ -127,12 +132,16 @@ void psp_dev_free(struct psp_dev *psd)
/**
* psp_dev_unregister() - unregister PSP device
* @psd: PSP device structure
+ *
+ * Context: Must not be called with the netdev instance lock held.
*/
void psp_dev_unregister(struct psp_dev *psd)
{
struct psp_assoc_dev *entry, *entry_tmp;
struct psp_assoc *pas, *next;
+ lockdep_assert_not_held(&psd->main_netdev->lock);
+
mutex_lock(&psp_devs_lock);
mutex_lock(&psd->lock);
--
2.52.1