From: "Björn Töpel" <bjorn@kernel.org>
To: Todd Freed <toddfreed@meta.com>, netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"Boris Pismenny" <borisp@nvidia.com>,
"Cosmin Ratiu" <cratiu@nvidia.com>,
"Daniel Zahka" <daniel.zahka@gmail.com>,
"Donald Hunter" <donald.hunter@gmail.com>,
"Dragos Tatulea" <dtatulea@nvidia.com>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Jamal Hadi Salim" <jhs@mojatatu.com>,
"Jiri Pirko" <jiri@resnulli.us>,
"Leon Romanovsky" <leon@kernel.org>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-rdma@vger.kernel.org,
"Mark Bloch" <mbloch@nvidia.com>,
"Paolo Abeni" <pabeni@redhat.com>,
"Pedro Tammela" <pctammela@mojatatu.com>,
"Saeed Mahameed" <saeedm@nvidia.com>,
"Simon Horman" <horms@kernel.org>,
"Tariq Toukan" <tariqt@nvidia.com>,
"Wei Wang" <weiwan@google.com>,
"Willem de Bruijn" <willemdebruijn.kernel@gmail.com>,
"Kuniyuki Iwashima" <kuniyu@google.com>,
bpf@vger.kernel.org, "Asbjørn Sloth Tønnesen" <ast@fiberby.net>,
"Qingfang Deng" <qingfang.deng@linux.dev>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Shuah Khan" <shuah@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Matthieu Baerts" <matttbe@kernel.org>,
"David Ahern" <dsahern@kernel.org>,
"Jonas Köppeler" <j.koeppeler@tu-berlin.de>,
"Hangbin Liu" <hangbin.liu@linux.dev>
Subject: Re: [PATCH net-next v3 06/12] net/sched: add act_psp for psp transport mode
Date: Thu, 26 Nov 2026 16:45:55 +0100 [thread overview]
Message-ID: <871p87iojw.fsf@all.your.base.are.belong.to.us> (raw)
In-Reply-To: <20261124221758.3230929-7-toddfreed@meta.com>
Todd Freed <toddfreed@meta.com> writes:
> Add the tc action act_psp, for PSP transport mode encapsulation and
> encryption.
>
> encap attaches a PSP Tx association to the skb as a METADATA_PSP dst.
> The packet must then be transmitted on the main netdev of the
> association's PSP device, which encrypts it: encap on that netdev's
> egress, or a redirect there from another netdev's egress. Any other
> device drops it.
>
> Encap on ingress isn't supported. Routing replaces the dst of a packet
> entering the stack, so the packet would lose its association before it
> reaches the PSP device.
> A later series will add support for encap on ingress, in hardware
> offload only.
>
> On egress, encap sets skb->decrypted, so that sk_validate_xmit_skb()
> drops the packet if it loses the METADATA_PSP dst on the way.
>
> Some kinds of packets are not supported and are dropped:
>
> - IPv4 and IPv6 fragments. Encap inserts UDP + PSP between the L3 and
> L4 headers, and non-initial fragments don't have L4 headers, so
> transport mode can't support fragments. Tunnel mode PSP, which a later
> series adds, does support them.
> - IPv6 packets with extension headers. Some extension headers could be
> supported in the future.
> - Packets already encapsulated for a tunnel (skb->encapsulation). Some
> tunnel types could be supported in the future.
> - Packets which are too large. On transmit, packets which won't fit the
> device's MTU once encapsulated are dropped (see the METADATA_PSP
> patch). The traffic's MTU needs to leave room for the PSP encap.
> - Packets with another encryption offload. Packets of a PSP or kTLS
> offload socket, for which sk_validate_xmit_skb() would apply the
> socket's validator instead of checking the association.
>
> Decap removes the PSP Rx state of a packet the device decrypted. To
> take the packets of only one Rx SPI, a rule matches the PSP header
> fields it was decrypted with: psp_spi, psp_ver and psp_dev. Those
> flower matches are added in a subsequent patch.
>
> Signed-off-by: Todd Freed <toddfreed@meta.com>
> ---
> MAINTAINERS | 3 +
> include/net/tc_act/tc_psp.h | 23 ++
> include/uapi/linux/pkt_cls.h | 1 +
> include/uapi/linux/tc_act/tc_psp.h | 28 ++
> net/sched/Kconfig | 13 +
> net/sched/Makefile | 1 +
> net/sched/act_psp.c | 437 +++++++++++++++++++++++++++++
> 7 files changed, 506 insertions(+)
> create mode 100644 include/net/tc_act/tc_psp.h
> create mode 100644 include/uapi/linux/tc_act/tc_psp.h
> create mode 100644 net/sched/act_psp.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 97308edec53d..63c5c4c084dd 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -22573,8 +22573,11 @@ F: Documentation/netlink/specs/psp.yaml
> F: Documentation/networking/psp.rst
> F: include/net/psp/
> F: include/net/psp.h
> +F: include/net/tc_act/tc_psp.h
> F: include/uapi/linux/psp.h
> +F: include/uapi/linux/tc_act/tc_psp.h
> F: net/psp/
> +F: net/sched/act_psp.c
> K: struct\ psp(_assoc|_dev|hdr)\b
>
> PSTORE FILESYSTEM
> diff --git a/include/net/tc_act/tc_psp.h b/include/net/tc_act/tc_psp.h
> new file mode 100644
> index 000000000000..8640d7685475
> --- /dev/null
> +++ b/include/net/tc_act/tc_psp.h
> @@ -0,0 +1,23 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef __NET_TC_PSP_H
> +#define __NET_TC_PSP_H
> +
> +#include <net/act_api.h>
> +#include <net/dst_metadata.h>
> +#include <linux/tc_act/tc_psp.h>
> +
> +struct tcf_psp_params {
> + struct rcu_head rcu;
> + int action;
> + int psp_action;
> + struct metadata_dst *md;
> +};
> +
> +struct tcf_psp {
> + struct tc_action common;
> + struct tcf_psp_params __rcu *params;
> +};
> +
> +#define to_psp(a) ((struct tcf_psp *)a)
> +
> +#endif /* __NET_TC_PSP_H */
> diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h
> index 28d94b11d1aa..14cff8f5da74 100644
> --- a/include/uapi/linux/pkt_cls.h
> +++ b/include/uapi/linux/pkt_cls.h
> @@ -139,6 +139,7 @@ enum tca_id {
> TCA_ID_MPLS,
> TCA_ID_CT,
> TCA_ID_GATE,
> + TCA_ID_PSP,
> /* other actions go here */
> __TCA_ID_MAX = 255
> };
> diff --git a/include/uapi/linux/tc_act/tc_psp.h b/include/uapi/linux/tc_act/tc_psp.h
> new file mode 100644
> index 000000000000..e58ebcae77be
> --- /dev/null
> +++ b/include/uapi/linux/tc_act/tc_psp.h
> @@ -0,0 +1,28 @@
> +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
> +#ifndef __LINUX_TC_PSP_H
> +#define __LINUX_TC_PSP_H
> +
> +#include <linux/pkt_cls.h>
> +
> +#define TCA_PSP_ACT_ENCAP 1 /* attach a PSP association */
> +#define TCA_PSP_ACT_DECAP 2 /* drop PSP Rx state */
> +
> +struct tc_psp {
> + tc_gen;
> +};
> +
> +enum {
> + TCA_PSP_UNSPEC,
> + TCA_PSP_TM,
> + TCA_PSP_PARMS,
> + TCA_PSP_PAD,
> + TCA_PSP_ACTION, /* u32, TCA_PSP_ACT_* */
> + TCA_PSP_ASSOC_ID, /* u32, encap only: Tx association ID from
> + * the PSP netlink family (assoc-add)
> + */
> + __TCA_PSP_MAX,
> +};
> +
> +#define TCA_PSP_MAX (__TCA_PSP_MAX - 1)
> +
> +#endif
> diff --git a/net/sched/Kconfig b/net/sched/Kconfig
> index 6ddff028b81a..35f9d76c4cae 100644
> --- a/net/sched/Kconfig
> +++ b/net/sched/Kconfig
> @@ -939,6 +939,19 @@ config NET_ACT_GATE
> To compile this code as a module, choose M here: the
> module will be called act_gate.
>
> +config NET_ACT_PSP
> + tristate "PSP encryption tc action"
> + depends on NET_CLS_ACT && INET_PSP
> + help
> + Say Y here to allow PSP associations, created through the PSP
> + netlink family, to be attached to packets. PSP capable devices can
> + then encrypt them on transmit. Enables transparent psp tunnels for
> + forwarded traffic.
> +
> + If unsure, say N.
> + To compile this code as a module, choose M here: the
> + module will be called act_psp.
> +
> config NET_IFE_SKBMARK
> tristate "Support to encoding decoding skb mark on IFE action"
> depends on NET_ACT_IFE
> diff --git a/net/sched/Makefile b/net/sched/Makefile
> index 5078ea84e6ad..9fe8cc0abfdf 100644
> --- a/net/sched/Makefile
> +++ b/net/sched/Makefile
> @@ -31,6 +31,7 @@ obj-$(CONFIG_NET_IFE_SKBTCINDEX) += act_meta_skbtcindex.o
> obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
> obj-$(CONFIG_NET_ACT_CT) += act_ct.o
> obj-$(CONFIG_NET_ACT_GATE) += act_gate.o
> +obj-$(CONFIG_NET_ACT_PSP) += act_psp.o
> obj-$(CONFIG_NET_SCH_FIFO) += sch_fifo.o
> obj-$(CONFIG_NET_SCH_HTB) += sch_htb.o
> obj-$(CONFIG_NET_SCH_HFSC) += sch_hfsc.o
> diff --git a/net/sched/act_psp.c b/net/sched/act_psp.c
> new file mode 100644
> index 000000000000..757b15a812a2
> --- /dev/null
> +++ b/net/sched/act_psp.c
> @@ -0,0 +1,437 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * tc action that attaches a PSP association to packets.
> + *
> + * encap: attach a Tx association referenced by its ID, as a METADATA_PSP dst.
> + * The PSP device's netdev encrypts the packet on transmit. Egress
> + * only: encap on ingress isn't supported, and drops the packet.
> + * decap: drop the PSP Rx state (SKB_EXT_PSP) of a decrypted packet. It
> + * takes no association. A rule which should only take the packets
> + * of one Rx SPI matches what they were decrypted with (flower
> + * psp_spi / psp_ver / psp_dev).
> + */
> +
> +#include <linux/ip.h>
> +#include <linux/ipv6.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/skbuff.h>
> +#include <net/dst.h>
> +#include <net/inet_timewait_sock.h>
> +#include <net/ip.h>
> +#include <net/netlink.h>
> +#include <net/pkt_cls.h>
> +#include <net/pkt_sched.h>
> +#include <net/psp/functions.h>
> +#include <net/tc_act/tc_psp.h>
> +
> +static struct tc_action_ops act_psp_ops;
> +
> +/* The device inserts UDP + PSP between the IP header and the transport
> + * header, so the transport header must be right by the time the packet
> + * gets there. On a forwarded packet it may not be. Transport mode doesn't
> + * support IP fragments or IPv6 extension headers.
> + */
> +static bool tcf_psp_set_transport_header(struct sk_buff *skb)
> +{
> + unsigned int off = skb_network_offset(skb);
> + const struct iphdr *iph;
> + unsigned int hlen, len;
> +
> + switch (skb->protocol) {
> + case htons(ETH_P_IP):
> + if (!pskb_may_pull(skb, off + sizeof(*iph)))
> + return false;
> + iph = ip_hdr(skb);
> + if (iph->version != 4 || iph->ihl < 5 || ip_is_fragment(iph))
> + return false;
> + hlen = iph->ihl * 4;
> + len = ntohs(iph->tot_len);
> + if (!pskb_may_pull(skb, off + hlen))
> + return false;
> + break;
> + case htons(ETH_P_IPV6):
> + if (!pskb_may_pull(skb, off + sizeof(struct ipv6hdr)))
> + return false;
> + if (ipv6_hdr(skb)->version != 6 ||
> + ipv6_ext_hdr(ipv6_hdr(skb)->nexthdr))
> + return false;
> + hlen = sizeof(struct ipv6hdr);
> + len = hlen + ntohs(ipv6_hdr(skb)->payload_len);
> + break;
> + default:
> + return false;
> + }
> +
> + /* The device takes the length of the payload from the packet: it must
> + * hold the IP length, and L2 padding, e.g. of a minimum size frame,
> + * must not be encrypted as payload. A GSO skb's header doesn't always
> + * carry its length (BIG TCP).
> + */
> + if (!skb_is_gso(skb)) {
> + if (len < hlen || skb->len - off < len)
> + return false;
> + if (pskb_trim_rcsum(skb, off + len))
> + return false;
> + }
> +
> + skb_set_transport_header(skb, off + hlen);
> + return true;
> +}
> +
> +/* The socket of the packet has its own encryption offload, kTLS or PSP:
> + * sk_validate_xmit_skb() then applies the socket's validator instead of
> + * checking the association.
> + */
> +static bool tcf_psp_sk_offload(const struct sk_buff *skb)
> +{
> +#ifdef CONFIG_SOCK_VALIDATE_XMIT
> + struct sock *sk = skb->sk;
> +
> + if (!sk)
> + return false;
> + if (sk_fullsock(sk))
> + return !!READ_ONCE(sk->sk_validate_xmit_skb);
> + return sk_is_inet(sk) && sk->sk_state == TCP_TIME_WAIT &&
> + inet_twsk(sk)->tw_validate_xmit_skb;
> +#else
> + return false;
> +#endif
> +}
> +
> +static int tcf_psp_drop(struct tcf_psp *p, struct sk_buff *skb,
> + enum skb_drop_reason reason)
> +{
> + tcf_action_inc_drop_qstats(&p->common);
> + tcf_set_drop_reason(skb, reason);
> + return TC_ACT_SHOT;
> +}
> +
> +static int tcf_psp_act(struct sk_buff *skb, const struct tc_action *a,
> + struct tcf_result *res)
> +{
> + struct tcf_psp *p = to_psp(a);
> + struct tcf_psp_params *params;
> +
> + params = rcu_dereference_bh(p->params);
> +
> + tcf_lastuse_update(&p->tcf_tm);
> + tcf_action_update_bstats(&p->common, skb);
> +
> + switch (params->psp_action) {
> + case TCA_PSP_ACT_ENCAP:
> + /* Encap on ingress isn't supported: routing replaces the
> + * dst of a packet entering the stack, so it would lose its
> + * association before it reaches the PSP device
> + */
> + if (unlikely(skb_at_tc_ingress(skb)))
> + return tcf_psp_drop(p, skb, SKB_DROP_REASON_PSP_OUTPUT);
> + /* PSP on a tunnel isn't supported: the encap would overwrite
> + * the inner headers which the device's tunnel offloads use
> + */
> + if (unlikely(skb->encapsulation))
> + return tcf_psp_drop(p, skb, SKB_DROP_REASON_PSP_OUTPUT);
> + /* Don't mix the association with another encryption
> + * offload: the packet is already marked decrypted, or its
> + * socket has an offload of its own
> + */
> + if (unlikely(skb_is_decrypted(skb) || tcf_psp_sk_offload(skb)))
> + return tcf_psp_drop(p, skb, SKB_DROP_REASON_PSP_OUTPUT);
> + if (unlikely(!tcf_psp_set_transport_header(skb)))
> + return tcf_psp_drop(p, skb, SKB_DROP_REASON_PSP_OUTPUT);
> + skb_dst_drop(skb);
> + skb_dst_set(skb, dst_clone(¶ms->md->dst));
I'll continue my perf questions! dst_clone() -- potential contention
point/cacheline ping-pong for multiple cores sharing the assoc?
> + /* Must be encrypted: sk_validate_xmit_skb() drops it unless
> + * it still carries the association when it is transmitted
> + */
> + skb->decrypted = 1;
My Q on the previous patch -- can this flag be used as a cheaper check?
Björn
next prev parent reply other threads:[~2026-11-26 15:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 22:17 [PATCH net-next v3 00/12] psp: introduce socket-less associations Todd Freed
2026-11-24 22:17 ` [PATCH net-next v3 01/12] psp: get netns from net_device instead of sock Todd Freed
2026-11-24 22:17 ` [PATCH net-next v3 02/12] psp: take the psp nexthdr from the packet on encap Todd Freed
2026-11-26 14:32 ` Björn Töpel
2026-11-24 22:17 ` [PATCH net-next v3 03/12] psp: declare psp_assoc_set_tx() in psp.h Todd Freed
2026-11-24 22:17 ` [PATCH net-next v3 04/12] psp: add support for socket-less psp associations Todd Freed
2026-11-26 15:07 ` Björn Töpel
2026-11-24 22:17 ` [PATCH net-next v3 05/12] net: add METADATA_PSP dst to carry a psp association on an skb Todd Freed
2026-11-26 15:27 ` Björn Töpel
2026-11-24 22:17 ` [PATCH net-next v3 06/12] net/sched: add act_psp for psp transport mode Todd Freed
2026-11-26 15:45 ` Björn Töpel [this message]
2026-11-24 22:17 ` [PATCH net-next v3 07/12] net/sched: flower: add psp_spi, psp_ver, and psp_dev matches Todd Freed
2026-11-24 22:17 ` [PATCH net-next v3 08/12] selftests: drv-net: psp: test socket-less associations and the tc psp action Todd Freed
2026-11-24 22:17 ` [PATCH net-next v3 09/12] selftests: drv-net: psp: test that software encap on ingress drops Todd Freed
2026-11-24 22:17 ` [PATCH net-next v3 10/12] selftests: tc-testing: run dependsOn probes outside the test namespace Todd Freed
2026-11-24 22:17 ` [PATCH net-next v3 11/12] selftests: tc-testing: add tests for the psp action Todd Freed
2026-11-24 22:17 ` [PATCH net-next v3 12/12] Documentation: networking: psp: document socket-less associations Todd Freed
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=871p87iojw.fsf@all.your.base.are.belong.to.us \
--to=bjorn@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=ast@fiberby.net \
--cc=borisp@nvidia.com \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=cratiu@nvidia.com \
--cc=daniel.zahka@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=dsahern@kernel.org \
--cc=dtatulea@nvidia.com \
--cc=edumazet@kernel.org \
--cc=hangbin.liu@linux.dev \
--cc=horms@kernel.org \
--cc=j.koeppeler@tu-berlin.de \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=leon@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=matttbe@kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pctammela@mojatatu.com \
--cc=qingfang.deng@linux.dev \
--cc=rdunlap@infradead.org \
--cc=saeedm@nvidia.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tariqt@nvidia.com \
--cc=toddfreed@meta.com \
--cc=toke@redhat.com \
--cc=weiwan@google.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
all inboxes | Powered by JetHome®