All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Zahka <daniel.zahka@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>,
	 Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	 Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	 Andrew Lunn <andrew+netdev@lunn.ch>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 3/4] psp: allow drivers to omit tx key add/del ops
Date: Thu, 03 Sep 2026 18:34:01 -0700	[thread overview]
Message-ID: <20260903-psp-prep-v1-3-d47e9c4c375d@gmail.com> (raw)
In-Reply-To: <20260903-psp-prep-v1-0-d47e9c4c375d@gmail.com>

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


  parent reply	other threads:[~2026-09-04  1:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04  1:33 [PATCH net-next 0/4] psp: make tx key ops optional for drivers Daniel Zahka
2026-09-04  1:33 ` [PATCH net-next 1/4] psp: refactor psp_dev_tx_key_del() Daniel Zahka
2026-09-06 17:08   ` Willem de Bruijn
2026-09-04  1:34 ` [PATCH net-next 2/4] psp: move code from psp_sock_assoc_set_tx() into helper functions Daniel Zahka
2026-09-06 17:09   ` Willem de Bruijn
2026-09-04  1:34 ` Daniel Zahka [this message]
2026-09-06 17:09   ` [PATCH net-next 3/4] psp: allow drivers to omit tx key add/del ops Willem de Bruijn
2026-09-04  1:34 ` [PATCH net-next 4/4] netdevsim: psp: drop tx key ops Daniel Zahka
2026-09-06 17:09   ` Willem de Bruijn
2026-09-08  0:00 ` [PATCH net-next 0/4] psp: make tx key ops optional for drivers patchwork-bot+netdevbpf
2026-09-08 14:09   ` Daniel Zahka
2026-09-08 17:33     ` Jakub Kicinski
2026-09-08 18:58       ` Daniel Zahka

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=20260903-psp-prep-v1-3-d47e9c4c375d@gmail.com \
    --to=daniel.zahka@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemdebruijn.kernel@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.