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 2/4] psp: move code from psp_sock_assoc_set_tx() into helper functions
Date: Thu, 03 Sep 2026 18:34:00 -0700 [thread overview]
Message-ID: <20260903-psp-prep-v1-2-d47e9c4c375d@gmail.com> (raw)
In-Reply-To: <20260903-psp-prep-v1-0-d47e9c4c375d@gmail.com>
No functional changes.
Lift code that needs to be called from both initial tx establishment
and tx rekeying into functions that can be reused in both paths.
The plaintext in recv queue checks and mss adjustment only run on
initial tx keying. The dummy psp_assoc machinery will be used in both
paths.
psp_dev_tx_key_add() absorbs the dummy assoc machinery, as its main
purpose is to populate the device specific psp_assoc:drv_data.
psp_assoc_set_tx() exists so that a future change can allow
psp_dev_tx_key_add() to be skipped entirely for devices that don't use
an SADB, while copying of the tx spi and key into the assoc needs to
happen regardless of SADB vs. no SADB.
Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
---
net/psp/psp_sock.c | 102 ++++++++++++++++++++++++++++++++++-------------------
1 file changed, 65 insertions(+), 37 deletions(-)
diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c
index 045389671d7f..36eb06faa54a 100644
--- a/net/psp/psp_sock.c
+++ b/net/psp/psp_sock.c
@@ -78,9 +78,28 @@ static struct psp_assoc *psp_assoc_dummy(struct psp_assoc *pas)
}
static int psp_dev_tx_key_add(struct psp_dev *psd, struct psp_assoc *pas,
+ struct psp_key_parsed *key,
struct netlink_ext_ack *extack)
{
- return psd->ops->tx_key_add(psd, pas, extack);
+ struct psp_assoc *dummy;
+ int err;
+
+ /* Pass a fake association to drivers to make sure they don't
+ * try to store pointers to it. For re-keying we'll need to
+ * re-allocate the assoc structures.
+ */
+ dummy = psp_assoc_dummy(pas);
+ if (!dummy)
+ return -ENOMEM;
+
+ memcpy(&dummy->tx, key, sizeof(*key));
+ err = psd->ops->tx_key_add(psd, dummy, extack);
+ if (!err)
+ memcpy(pas->drv_data, dummy->drv_data,
+ psd->caps->assoc_drv_spc);
+
+ kfree(dummy);
+ return err;
}
void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas)
@@ -156,6 +175,20 @@ int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
return err;
}
+static int psp_assoc_set_tx(struct psp_dev *psd, struct psp_assoc *pas,
+ struct psp_key_parsed *key,
+ struct netlink_ext_ack *extack)
+{
+ int err;
+
+ err = psp_dev_tx_key_add(psd, pas, key, extack);
+ if (err)
+ return err;
+
+ memcpy(&pas->tx, key, sizeof(*key));
+ return 0;
+}
+
static int psp_sock_recv_queue_check(struct sock *sk, struct psp_assoc *pas)
{
struct psp_skb_ext *pse;
@@ -175,12 +208,40 @@ static int psp_sock_recv_queue_check(struct sock *sk, struct psp_assoc *pas)
return 0;
}
+static int
+psp_sock_set_tx_key(struct sock *sk, struct psp_dev *psd, struct psp_assoc *pas,
+ struct psp_key_parsed *key, struct netlink_ext_ack *extack)
+{
+ struct inet_connection_sock *icsk;
+ int err;
+
+ err = psp_sock_recv_queue_check(sk, pas);
+ if (err) {
+ NL_SET_ERR_MSG(extack,
+ "Socket has incompatible segments already in the recv queue");
+ return err;
+ }
+
+ err = psp_assoc_set_tx(psd, pas, key, extack);
+ if (err)
+ return err;
+
+ WRITE_ONCE(sk->sk_validate_xmit_skb, psp_validate_xmit);
+ tcp_write_collapse_fence(sk);
+ pas->upgrade_seq = tcp_sk(sk)->rcv_nxt;
+
+ icsk = inet_csk(sk);
+ icsk->icsk_ext_hdr_len += psp_sk_overhead(sk);
+ icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
+
+ return err;
+}
+
int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,
u32 version, struct psp_key_parsed *key,
struct netlink_ext_ack *extack)
{
- struct inet_connection_sock *icsk;
- struct psp_assoc *pas, *dummy;
+ struct psp_assoc *pas;
int err;
lock_sock(sk);
@@ -208,40 +269,7 @@ int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,
goto exit_unlock;
}
- err = psp_sock_recv_queue_check(sk, pas);
- if (err) {
- NL_SET_ERR_MSG(extack, "Socket has incompatible segments already in the recv queue");
- goto exit_unlock;
- }
-
- /* Pass a fake association to drivers to make sure they don't
- * try to store pointers to it. For re-keying we'll need to
- * re-allocate the assoc structures.
- */
- dummy = psp_assoc_dummy(pas);
- if (!dummy) {
- err = -ENOMEM;
- goto exit_unlock;
- }
-
- memcpy(&dummy->tx, key, sizeof(*key));
- err = psp_dev_tx_key_add(psd, dummy, extack);
- if (err)
- goto exit_free_dummy;
-
- memcpy(pas->drv_data, dummy->drv_data, psd->caps->assoc_drv_spc);
- memcpy(&pas->tx, key, sizeof(*key));
-
- WRITE_ONCE(sk->sk_validate_xmit_skb, psp_validate_xmit);
- tcp_write_collapse_fence(sk);
- pas->upgrade_seq = tcp_sk(sk)->rcv_nxt;
-
- icsk = inet_csk(sk);
- icsk->icsk_ext_hdr_len += psp_sk_overhead(sk);
- icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
-
-exit_free_dummy:
- kfree(dummy);
+ err = psp_sock_set_tx_key(sk, psd, pas, key, extack);
exit_unlock:
release_sock(sk);
return err;
--
2.52.0
next prev parent reply other threads:[~2026-09-04 1:34 UTC|newest]
Thread overview: 5+ 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-04 1:34 ` Daniel Zahka [this message]
2026-09-04 1:34 ` [PATCH net-next 3/4] psp: allow drivers to omit tx key add/del ops Daniel Zahka
2026-09-04 1:34 ` [PATCH net-next 4/4] netdevsim: psp: drop tx key ops 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-2-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox