[PATCH net-next 3/4] psp: allow drivers to omit tx key add/del ops
From: Daniel Zahka <daniel.zahka@gmail.com>
Date: 2026-09-04 01:34:24
Also in:
lkml
Subsystem:
networking [general], psp security protocol, the rest · Maintainers:
"David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Daniel Zahka, Willem de Bruijn, Linus Torvalds
Drivers that don't use an SADB for tx key storage don't have a use for psp_dev_ops::tx_key_add and psp_dev_ops::tx_key_del. Allowing drivers to leave these as NULL gives PSP core a simple way to determine whether a driver utilizes an SADB, which in turn could affect how PSP core chooses to handle certain situations. For example: - deciding if tx key deletion needs to be delayed during a rekeying event to avoid in-flight packets using old key handles. - choosing whether or not to report device stats like SADB usage to userspace, which only make sense if the driver uses on-device key storage. Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com> --- include/net/psp/types.h | 4 ++++ net/psp/psp.h | 8 +++++++- net/psp/psp_main.c | 6 +++--- net/psp/psp_sock.c | 8 +++++--- 4 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/include/net/psp/types.h b/include/net/psp/types.h
index 87991a1ea02d..b8905efbd604 100644
--- a/include/net/psp/types.h
+++ b/include/net/psp/types.h@@ -219,12 +219,16 @@ struct psp_dev_ops { * @tx_key_add: add a Tx key to the device * Install an association in the device. Core will allocate space * for the driver to use at drv_data. + * Can be left NULL if device does not store Tx keys and @tx_key_del + * is also NULL. */ int (*tx_key_add)(struct psp_dev *psd, struct psp_assoc *pas, struct netlink_ext_ack *extack); /** * @tx_key_del: remove a Tx key from the device * Remove an association from the device. + * Can be left NULL if device does not store Tx keys and @tx_key_add + * is also NULL. */ void (*tx_key_del)(struct psp_dev *psd, struct psp_assoc *pas);
diff --git a/net/psp/psp.h b/net/psp/psp.h
index 8acf9ca84b55..bbb39e2f5b0a 100644
--- a/net/psp/psp.h
+++ b/net/psp/psp.h@@ -53,10 +53,16 @@ static inline bool psp_dev_is_registered(struct psp_dev *psd) return !!psd->ops; } +static inline bool psp_dev_has_sadb(struct psp_dev *psd) +{ + lockdep_assert_held(&psd->lock); + return !!psd->ops->tx_key_del; +} + static inline bool psp_assoc_needs_tx_key_del(struct psp_assoc *pas) { lockdep_assert_held(&pas->psd->lock); - return pas->tx.spi; + return psp_dev_has_sadb(pas->psd) && pas->tx.spi; } #endif /* __PSP_PSP_H */
diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
index 2556f0d46ef4..91473f96ad21 100644
--- a/net/psp/psp_main.c
+++ b/net/psp/psp_main.c@@ -68,9 +68,9 @@ psp_dev_create(struct net_device *netdev, !psd_ops->set_config || !psd_ops->key_rotate || !psd_ops->rx_spi_alloc || - !psd_ops->tx_key_add || - !psd_ops->tx_key_del || - !psd_ops->get_stats)) + !psd_ops->get_stats || + (!psd_ops->tx_key_add != !psd_ops->tx_key_del) || + (psd_caps->assoc_drv_spc && !psd_ops->tx_key_add))) return ERR_PTR(-EINVAL); psd = kzalloc_obj(*psd);
diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c
index 36eb06faa54a..6a4becc38b55 100644
--- a/net/psp/psp_sock.c
+++ b/net/psp/psp_sock.c@@ -181,9 +181,11 @@ static int psp_assoc_set_tx(struct psp_dev *psd, struct psp_assoc *pas, { int err; - err = psp_dev_tx_key_add(psd, pas, key, extack); - if (err) - return err; + if (psp_dev_has_sadb(psd)) { + err = psp_dev_tx_key_add(psd, pas, key, extack); + if (err) + return err; + } memcpy(&pas->tx, key, sizeof(*key)); return 0;
--
2.52.0