Skip to contentSkip to conversation

add basic PSP encryption for TCP connections

PATCH Superseded Daniel Zahka 5 participants 52 messages Jul 2, 2025 – Jul 14, 2025

Subsystems (12)

v3 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Daniel Zahka

author maintainer
#0 lore raw

v3 cover add basic PSP encryption for TCP connections

This is v3 of the PSP RFC [1] posted by Jakub Kicinski one year ago. General developments since v1 include a fork of packetdrill [2] with support for PSP added, as well as some test cases, and an implementation of PSP key exchange and connection upgrade [3] integrated into the fbthrift RPC library. Both [2] and [3] have been tested on server platforms with PSP-capable CX7 NICs. Below is the cover letter from the original RFC:

Add support for PSP encryption of TCP connections.

PSP is a protocol out of Google:
https://github.com/google/psp/blob/main/doc/PSP_Arch_Spec.pdf
which shares some similarities with IPsec. I added some more info in the first patch so I'll keep it short here.

The protocol can work in multiple modes including tunneling. But I'm mostly interested in using it as TLS replacement because of its superior offload characteristics. So this patch does three things:

- it adds "core" PSP code
PSP is offload-centric, and requires some additional care and feeding, so first chunk of the code exposes device info. This part can be reused by PSP implementations in xfrm, tunneling etc.

- TCP integration TLS style
Reuse some of the existing concepts from TLS offload, such as attaching crypto state to a socket, marking skbs as "decrypted", egress validation. PSP does not prescribe key exchange protocols. To use PSP as a more efficient TLS offload we intend to perform a TLS handshake ("inline" in the same TCP connection) and negotiate switching to PSP based on capabilities of both endpoints. This is also why I'm not including a software implementation. Nobody would use it in production, software TLS is faster, it has larger crypto records.

- mlx5 implementation
That's mostly other people's work, not 100% sure those folks consider it ready hence the RFC in the title. But it works :)

Not posted, queued a branch [4] are follow up pieces:
- standard stats
- netdevsim implementation and tests

[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://github.com/danieldzahka/packetdrill
[3] https://github.com/danieldzahka/fbthrift/tree/dzahka/psp
[4] https://github.com/kuba-moo/linux/tree/psp

Comments we intend to defer to future series:
- using INDIRECT_CALL for tls/psp in sk_validate_xmit_skb(). We prefer to address this in a dedicated patch series, so that this series does not need to modify the way tls_validate_xmit_skb() is declared and stubbed out.

CHANGES:
v3:
- move psp_rcv() and psp_encapsulate() driver helpers into psp_main.c
- lift pse/pas comparison code into new function:
psp_pse_matches_pas()
- explicitly mark rcu critical section psp_reply_set_decrypted()
- use rcu_dereference_proteced() instead of rcu_read_lock() in psp_sk_assoc_free() and psp_twsk_assoc_free()
- rename psp_is_nondata() to psp_is_allowed_nondata()
- psp_reply_set_decrypted() should not call psp_sk_assoc(). Call psp_sk_get_assoc_rcu() instead.
- lift common code from timewait and regular socks into new function psp_sk_get_assoc_rcu()
- export symbols in psp_sock.c with EXPORT_IPV6_MOD_GPL()
- check for sk_is_inet() before casting to inet_twsk() in sk_validate_xmit() and in psp_get_assoc_rcu()
- psp_reply_set_decrypted() does not use stuct sock* arg. Drop it.
- reword driver requirement about double rotating keys when the device supports requesting arbitrary spi key pairs.

v2: https://lore.kernel.org/netdev/[email protected]/
- add pas->dev_id == pse->dev_id to policy checks
- __psp_sk_rx_policy_check() now allows pure ACKs, FINs, and RSTs to be non-psp authenticated before "PSP Full" state.
- assign tw_validate_skb funtion during psp_twsk_init()
- psp_skb_get_rcu() also checks if sk is a tcp timewait sock when looking for psp assocs.
- scan ofo queue non-psp data during psp_sock_recv_queue_check()
- add tcp_write_collapse_fence() to psp_sock_assoc_set_tx()
- Add psp_reply_set_decrypted() to encapsulate ACKs, FINs, and RSTs sent from control socks on behalf of full or timewait socks with PSP state.
- Add dev_id field to psp_skb_ext
- Move psp_assoc from struct tcp_timewait_sock to struct inet_timewait_sock
- Move psp_sk_assoc_free() from sk_common_release() to inet_sock_destruct()
- add documentation about MITM deletion attack, and expectation from userspace
- add information about accepting clear text ACKs, RSTs, and FINs to Securing Connections section.

v1: https://lore.kernel.org/netdev/[email protected]/

Daniel Zahka (2):
net: move sk_validate_xmit_skb() to net/core/dev.c
net: tcp: allow tcp_timewait_sock to validate skbs before handing to
device

Jakub Kicinski (8):
psp: add documentation
psp: base PSP device support
net: modify core data structures for PSP datapath support
tcp: add datapath logic for PSP with inline key exchange
psp: add op for rotation of device key
net: psp: add socket security association code
net: psp: update the TCP MSS to reflect PSP packet overhead
psp: track generations of device key

Raed Salem (9):
net/mlx5e: Support PSP offload functionality net/mlx5e: Implement PSP operations .assoc_add and .assoc_del
psp: provide encapsulation helper for drivers net/mlx5e: Implement PSP Tx data path
net/mlx5e: Add PSP steering in local NIC RX net/mlx5e: Configure PSP Rx flow steering rules
psp: provide decapsulation and receive helper for drivers net/mlx5e: Add Rx data path offload
net/mlx5e: Implement PSP key_rotate operation

 Documentation/netlink/specs/psp.yaml          | 188 +++++
 Documentation/networking/index.rst            |   1 +
 Documentation/networking/psp.rst              | 183 +++++
 .../net/ethernet/mellanox/mlx5/core/Kconfig   |  11 +
 .../net/ethernet/mellanox/mlx5/core/Makefile  |   5 +-
 drivers/net/ethernet/mellanox/mlx5/core/en.h  |   6 +-
 .../net/ethernet/mellanox/mlx5/core/en/fs.h   |   2 +-
 .../ethernet/mellanox/mlx5/core/en/params.c   |   4 +-
 .../mellanox/mlx5/core/en_accel/en_accel.h    |  50 +-
 .../mellanox/mlx5/core/en_accel/ipsec_rxtx.h  |   2 +-
 .../mellanox/mlx5/core/en_accel/psp.c         | 209 +++++
 .../mellanox/mlx5/core/en_accel/psp.h         |  55 ++
 .../mellanox/mlx5/core/en_accel/psp_fs.c      | 736 ++++++++++++++++++
 .../mellanox/mlx5/core/en_accel/psp_fs.h      |  30 +
 .../mellanox/mlx5/core/en_accel/psp_offload.c |  52 ++
 .../mellanox/mlx5/core/en_accel/psp_rxtx.c    | 204 +++++
 .../mellanox/mlx5/core/en_accel/psp_rxtx.h    | 125 +++
 .../net/ethernet/mellanox/mlx5/core/en_main.c |   9 +
 .../net/ethernet/mellanox/mlx5/core/en_rx.c   |  50 +-
 .../net/ethernet/mellanox/mlx5/core/en_tx.c   |  10 +-
 drivers/net/ethernet/mellanox/mlx5/core/fw.c  |   6 +
 .../ethernet/mellanox/mlx5/core/lib/crypto.h  |   1 +
 .../net/ethernet/mellanox/mlx5/core/main.c    |   5 +
 drivers/net/ethernet/mellanox/mlx5/core/psp.c |  24 +
 drivers/net/ethernet/mellanox/mlx5/core/psp.h |  15 +
 include/linux/mlx5/device.h                   |   4 +
 include/linux/mlx5/driver.h                   |   2 +
 include/linux/mlx5/mlx5_ifc.h                 |  94 ++-
 include/linux/netdevice.h                     |   4 +
 include/linux/skbuff.h                        |   3 +
 include/net/dropreason-core.h                 |   6 +
 include/net/inet_timewait_sock.h              |   8 +
 include/net/psp.h                             |  12 +
 include/net/psp/functions.h                   | 203 +++++
 include/net/psp/types.h                       | 187 +++++
 include/net/sock.h                            |  26 +-
 include/uapi/linux/psp.h                      |  66 ++
 net/Kconfig                                   |   1 +
 net/Makefile                                  |   1 +
 net/core/dev.c                                |  32 +
 net/core/gro.c                                |   2 +
 net/core/skbuff.c                             |   4 +
 net/ipv4/af_inet.c                            |   2 +
 net/ipv4/inet_timewait_sock.c                 |   6 +-
 net/ipv4/ip_output.c                          |   5 +-
 net/ipv4/tcp.c                                |   2 +
 net/ipv4/tcp_ipv4.c                           |  14 +-
 net/ipv4/tcp_minisocks.c                      |  16 +
 net/ipv4/tcp_output.c                         |  17 +-
 net/ipv6/ipv6_sockglue.c                      |   6 +-
 net/ipv6/tcp_ipv6.c                           |  17 +-
 net/psp/Kconfig                               |  15 +
 net/psp/Makefile                              |   5 +
 net/psp/psp-nl-gen.c                          | 119 +++
 net/psp/psp-nl-gen.h                          |  39 +
 net/psp/psp.h                                 |  54 ++
 net/psp/psp_main.c                            | 254 ++++++
 net/psp/psp_nl.c                              | 517 ++++++++++++
 net/psp/psp_sock.c                            | 297 +++++++
 tools/net/ynl/Makefile.deps                   |   1 +
 60 files changed, 3962 insertions(+), 62 deletions(-)
 create mode 100644 Documentation/netlink/specs/psp.yaml
 create mode 100644 Documentation/networking/psp.rst
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.h
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_offload.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/psp.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/psp.h
 create mode 100644 include/net/psp.h
 create mode 100644 include/net/psp/functions.h
 create mode 100644 include/net/psp/types.h
 create mode 100644 include/uapi/linux/psp.h
 create mode 100644 net/psp/Kconfig
 create mode 100644 net/psp/Makefile
 create mode 100644 net/psp/psp-nl-gen.c
 create mode 100644 net/psp/psp-nl-gen.h
 create mode 100644 net/psp/psp.h
 create mode 100644 net/psp/psp_main.c
 create mode 100644 net/psp/psp_nl.c
 create mode 100644 net/psp/psp_sock.c
Signature · 1 line
2.47.1
author maintainer
#1 lore raw

PATCH v3 1/19 psp: add documentation

From: Jakub Kicinski <[email protected]>

Add documentation of things which belong in the docs rather than commit messages.

---

Notes:
v3:
- reword driver requirement about double rotating keys when the device supports requesting arbitrary spi key pairs.
v2:
- add note about MITM deletion attack, and expectation from userspace
- add information about accepting clear text ACKs, RSTs, and FINs to Securing Connections section.
v1:
- https://lore.kernel.org/netdev/[email protected]/

 Documentation/networking/index.rst |   1 +
 Documentation/networking/psp.rst   | 183 +++++++++++++++++++++++++++++
 2 files changed, 184 insertions(+)
 create mode 100644 Documentation/networking/psp.rst
Documentation/networking/index.rst +1 -0
index ac90b82f3ce9..23382ff52285 100644
@@ -101,6 +101,7 @@ Contents:
    ppp_generic
    proc_net_tcp
    pse-pd/index
+   psp
    radiotap-headers
    rds
    regulatory
Documentation/networking/psp.rst new file +183 -0

183 lines not on this page · raw message

Signature · 1 line
2.47.1
author maintainer
#3 lore raw

PATCH v3 2/19 psp: base PSP device support

In reply to Daniel Zahka

From: Jakub Kicinski <[email protected]>

Add a netlink family for PSP and allow drivers to register support.

The "PSP device" is its own object. This allows us to perform more flexible reference counting / lifetime control than if PSP information was part of net_device. In the future we should also be able to "delegate" PSP access to software devices, such as *vlan, veth or netkit more easily.

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 Documentation/netlink/specs/psp.yaml |  96 ++++++++++++
 include/linux/netdevice.h            |   4 +
 include/net/psp.h                    |  12 ++
 include/net/psp/functions.h          |  14 ++
 include/net/psp/types.h              | 102 ++++++++++++
 include/uapi/linux/psp.h             |  42 +++++
 net/Kconfig                          |   1 +
 net/Makefile                         |   1 +
 net/psp/Kconfig                      |  13 ++
 net/psp/Makefile                     |   5 +
 net/psp/psp-nl-gen.c                 |  65 ++++++++
 net/psp/psp-nl-gen.h                 |  30 ++++
 net/psp/psp.h                        |  31 ++++
 net/psp/psp_main.c                   | 134 ++++++++++++++++
 net/psp/psp_nl.c                     | 223 +++++++++++++++++++++++++++
 tools/net/ynl/Makefile.deps          |   1 +
 16 files changed, 774 insertions(+)
 create mode 100644 Documentation/netlink/specs/psp.yaml
 create mode 100644 include/net/psp.h
 create mode 100644 include/net/psp/functions.h
 create mode 100644 include/net/psp/types.h
 create mode 100644 include/uapi/linux/psp.h
 create mode 100644 net/psp/Kconfig
 create mode 100644 net/psp/Makefile
 create mode 100644 net/psp/psp-nl-gen.c
 create mode 100644 net/psp/psp-nl-gen.h
 create mode 100644 net/psp/psp.h
 create mode 100644 net/psp/psp_main.c
 create mode 100644 net/psp/psp_nl.c
Documentation/netlink/specs/psp.yaml new file +96 -0
new file mode 100644
index 000000000000..706f4baf8764
@@ -0,0 +1,96 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+---
+name: psp
+
+doc:
+  PSP Security Protocol Generic Netlink family.
+
+definitions:
+  -
+    type: enum
+    name: version
+    entries: [hdr0-aes-gcm-128, hdr0-aes-gcm-256,
+              hdr0-aes-gmac-128, hdr0-aes-gmac-256]
+
+attribute-sets:
+  -
+    name: dev
+    attributes:
+      -
+        name: id
+        doc: PSP device ID.
+        type: u32
+        checks:
+          min: 1
+      -
+        name: ifindex
+        doc: ifindex of the main netdevice linked to the PSP device.
+        type: u32
+      -
+        name: psp-versions-cap
+        doc: Bitmask of PSP versions supported by the device.
+        type: u32
+        enum: version
+        enum-as-flags: true
+      -
+        name: psp-versions-ena
+        doc: Bitmask of currently enabled (accepted on Rx) PSP versions.
+        type: u32
+        enum: version
+        enum-as-flags: true
+
+operations:
+  list:
+    -
+      name: dev-get
+      doc: Get / dump information about PSP capable devices on the system.
+      attribute-set: dev
+      do:
+        request:
+          attributes:
+            - id
+        reply: &dev-all
+          attributes:
+            - id
+            - ifindex
+            - psp-versions-cap
+            - psp-versions-ena
+        pre: psp-device-get-locked
+        post: psp-device-unlock
+      dump:
+        reply: *dev-all
+    -
+      name: dev-add-ntf
+      doc: Notification about device appearing.
+      notify: dev-get
+      mcgrp: mgmt
+    -
+      name: dev-del-ntf
+      doc: Notification about device disappearing.
+      notify: dev-get
+      mcgrp: mgmt
+    -
+      name: dev-set
+      doc: Set the configuration of a PSP device.
+      attribute-set: dev
+      do:
+        request:
+          attributes:
+            - id
+            - psp-versions-ena
+        reply:
+          attributes: []
+        pre: psp-device-get-locked
+        post: psp-device-unlock
+    -
+      name: dev-change-ntf
+      doc: Notification about device configuration being changed.
+      notify: dev-get
+      mcgrp: mgmt
+
+mcast-groups:
+  list:
+    -
+      name: mgmt
+
+...
include/linux/netdevice.h +4 -0
index 03c26bb0fbbe..0a8255331631 100644
@@ -1902,6 +1902,7 @@ enum netdev_reg_state {
  *			 device struct
  *	@mpls_ptr:	mpls_dev struct pointer
  *	@mctp_ptr:	MCTP specific data
+ *	@psp_dev:	PSP crypto device registered for this netdev
  *
  *	@dev_addr:	Hw address (before bcast,
  *			because most packets are unicast)
@@ -2305,6 +2306,9 @@ struct net_device {
 #if IS_ENABLED(CONFIG_MCTP)
 	struct mctp_dev __rcu	*mctp_ptr;
 #endif
+#if IS_ENABLED(CONFIG_INET_PSP)
+	struct psp_dev __rcu	*psp_dev;
+#endif
 
 /*
  * Cache lines mostly used on receive path (including eth_type_trans())
include/net/psp.h new file +12 -0
new file mode 100644
index 000000000000..33bb4d1dc46e
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __NET_PSP_ALL_H
+#define __NET_PSP_ALL_H
+
+#include <uapi/linux/psp.h>
+#include <net/psp/functions.h>
+#include <net/psp/types.h>
+
+/* Do not add any code here. Put it in the sub-headers instead. */
+
+#endif /* __NET_PSP_ALL_H */
include/net/psp/functions.h new file +14 -0
new file mode 100644
index 000000000000..074f9df9afc3
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __NET_PSP_HELPERS_H
+#define __NET_PSP_HELPERS_H
+
+#include <net/psp/types.h>
+
+/* Driver-facing API */
+struct psp_dev *
+psp_dev_create(struct net_device *netdev, struct psp_dev_ops *psd_ops,
+	       struct psp_dev_caps *psd_caps, void *priv_ptr);
+void psp_dev_unregister(struct psp_dev *psd);
+
+#endif /* __NET_PSP_HELPERS_H */
include/net/psp/types.h new file +102 -0

102 lines not on this page · raw message

include/uapi/linux/psp.h new file +42 -0

42 lines not on this page · raw message

net/Kconfig +1 -0
index ebc80a98fc91..0269a4ba8a9d 100644
@@ -82,6 +82,7 @@ config NET_CRC32C
 menu "Networking options"
 
 source "net/packet/Kconfig"
+source "net/psp/Kconfig"
 source "net/unix/Kconfig"
 source "net/tls/Kconfig"
 source "net/xfrm/Kconfig"
net/Makefile +1 -0
index aac960c41db6..90e3d72bf58b 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_INET)		+= ipv4/
 obj-$(CONFIG_TLS)		+= tls/
 obj-$(CONFIG_XFRM)		+= xfrm/
 obj-$(CONFIG_UNIX)		+= unix/
+obj-$(CONFIG_INET_PSP)		+= psp/
 obj-y				+= ipv6/
 obj-$(CONFIG_PACKET)		+= packet/
 obj-$(CONFIG_NET_KEY)		+= key/
net/psp/Kconfig new file +13 -0
new file mode 100644
index 000000000000..55f9dd87446b
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# PSP configuration
+#
+config INET_PSP
+	bool "PSP Security Protocol support"
+	depends on INET
+	help
+	Enable kernel support for the PSP protocol.
+	For more information see:
+	  https://raw.githubusercontent.com/google/psp/main/doc/PSP_Arch_Spec.pdf
+
+	If unsure, say N.
net/psp/Makefile new file +5 -0
new file mode 100644
index 000000000000..41b51d06e560
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_INET_PSP) += psp.o
+
+psp-y := psp_main.o psp_nl.o psp-nl-gen.o
net/psp/psp-nl-gen.c new file +65 -0

65 lines not on this page · raw message

net/psp/psp-nl-gen.h new file +30 -0
new file mode 100644
index 000000000000..a099686cab5d
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
+/* Do not edit directly, auto-generated from: */
+/*	Documentation/netlink/specs/psp.yaml */
+/* YNL-GEN kernel header */
+
+#ifndef _LINUX_PSP_GEN_H
+#define _LINUX_PSP_GEN_H
+
+#include <net/netlink.h>
+#include <net/genetlink.h>
+
+#include <uapi/linux/psp.h>
+
+int psp_device_get_locked(const struct genl_split_ops *ops,
+			  struct sk_buff *skb, struct genl_info *info);
+void
+psp_device_unlock(const struct genl_split_ops *ops, struct sk_buff *skb,
+		  struct genl_info *info);
+
+int psp_nl_dev_get_doit(struct sk_buff *skb, struct genl_info *info);
+int psp_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
+int psp_nl_dev_set_doit(struct sk_buff *skb, struct genl_info *info);
+
+enum {
+	PSP_NLGRP_MGMT,
+};
+
+extern struct genl_family psp_nl_family;
+
+#endif /* _LINUX_PSP_GEN_H */
net/psp/psp.h new file +31 -0
new file mode 100644
index 000000000000..94d0cc31a61f
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __PSP_PSP_H
+#define __PSP_PSP_H
+
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <net/netns/generic.h>
+#include <net/psp.h>
+#include <net/sock.h>
+
+extern struct xarray psp_devs;
+extern struct mutex psp_devs_lock;
+
+void psp_dev_destroy(struct psp_dev *psd);
+int psp_dev_check_access(struct psp_dev *psd, struct net *net);
+
+void psp_nl_notify_dev(struct psp_dev *psd, u32 cmd);
+
+static inline void psp_dev_get(struct psp_dev *psd)
+{
+	refcount_inc(&psd->refcnt);
+}
+
+static inline void psp_dev_put(struct psp_dev *psd)
+{
+	if (refcount_dec_and_test(&psd->refcnt))
+		psp_dev_destroy(psd);
+}
+
+#endif /* __PSP_PSP_H */
net/psp/psp_main.c new file +134 -0

134 lines not on this page · raw message

net/psp/psp_nl.c new file +223 -0

223 lines not on this page · raw message

tools/net/ynl/Makefile.deps +1 -0
index 90686e241157..865fd2e8519e 100644
@@ -31,6 +31,7 @@ CFLAGS_ovpn:=$(call get_hdr_inc,_LINUX_OVPN_H,ovpn.h)
 CFLAGS_ovs_datapath:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
 CFLAGS_ovs_flow:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
 CFLAGS_ovs_vport:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
+CFLAGS_psp:=$(call get_hdr_inc,_LINUX_PSP_H,psp.h)
 CFLAGS_rt-addr:=$(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h) \
 	$(call get_hdr_inc,__LINUX_IF_ADDR_H,if_addr.h)
 CFLAGS_rt-link:=$(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h) \
Signature · 1 line
2.47.1
maintainer Reviewed-by on v3 2/19
#4 lore raw

Re: [PATCH v3 02/19] psp: base PSP device support

Quoted 4 lines · Daniel Zahka

From: Jakub Kicinski <[email protected]>

Add a netlink family for PSP and allow drivers to register support.

Quoted 8 lines

The "PSP device" is its own object. This allows us to perform more flexible reference counting / lifetime control than if PSP information was part of net_device. In the future we should also be able to "delegate" PSP access to software devices, such as *vlan, veth or netkit more easily.

Minor points only

Quoted 9 lines
include/net/psp/types.h new file +9 -0
+/**
+ * struct psp_dev - PSP device struct
+ * @main_netdev: original netdevice of this PSP device
+ * @ops:	driver callbacks
+ * @caps:	device capabilities
+ * @drv_priv:	driver priv pointer
+ * @lock:	instance lock, protects all fields
+ * @refcnt:	reference count for the instance
+ * @id:		instance id

include/net/psp/types.h line 62

Quoted 10 lines
include/net/psp/types.h new file +10 -0
+ * @config:	current device configuration
+ *
+ * @rcu:	RCU head for freeing the structure
+ */
+struct psp_dev {
+	struct net_device *main_netdev;
+
+	struct psp_dev_ops *ops;
+	struct psp_dev_caps *caps;
+	void *drv_priv;

not used?

Quoted 14 lines
include/net/psp/types.h new file +14 -0
+
+	struct mutex lock;
+	refcount_t refcnt;
+
+	u32 id;
+
+	struct psp_dev_config config;
+
+	struct rcu_head rcu;
+};
+
+/**
+ * struct psp_dev_caps - PSP device capabilities
+ */

include/net/psp/types.h line 86

Quoted 10 lines
include/net/psp/types.h new file +10 -0
+struct psp_dev_caps {
+	/**
+	 * @versions: mask of supported PSP versions
+	 * Set this field to 0 to indicate PSP is not supported at all.
+	 */
+	u32 versions;
+};
+
+#define PSP_V0_KEY	16
+#define PSP_V1_KEY	32

Above two not used? And these and the following are are KEY_LEN

Quoted 1 line

+#define PSP_MAX_KEY 32

maintainer
#5 lore raw

Re: [PATCH v3 02/19] psp: base PSP device support

Quoted 13 lines · On Sun, 06 Jul 2025 11:31:57 -0400 Willem de Bruijn wrote:
Quoted 13 lines

+/**
+ * struct psp_dev - PSP device struct
+ * @main_netdev: original netdevice of this PSP device
+ * @ops: driver callbacks
+ * @caps: device capabilities
+ * @drv_priv: driver priv pointer
+ * @lock: instance lock, protects all fields
+ * @refcnt: reference count for the instance
+ * @id: instance id
+ * @config: current device configuration
+ *
+ * @rcu: RCU head for freeing the structure
+ */

Quoted 8 lines

include/net/psp/types.h line 62

Quoted 6 lines
include/net/psp/types.h new file +6 -0
+struct psp_dev {
+	struct net_device *main_netdev;
+
+	struct psp_dev_ops *ops;
+	struct psp_dev_caps *caps;
+	void *drv_priv;  

not used?

I'd rather keep it from the start. The driver-facing API needs to be relatively complete otherwise drive authors will work around what's missing rather than adding it :(

maintainer
#6 lore raw

Re: [PATCH v3 02/19] psp: base PSP device support

Quoted 23 lines · Jakub Kicinski
Quoted 13 lines · On Sun, 06 Jul 2025 11:31:57 -0400 Willem de Bruijn wrote:
Quoted 13 lines

+/**
+ * struct psp_dev - PSP device struct
+ * @main_netdev: original netdevice of this PSP device
+ * @ops: driver callbacks
+ * @caps: device capabilities
+ * @drv_priv: driver priv pointer
+ * @lock: instance lock, protects all fields
+ * @refcnt: reference count for the instance
+ * @id: instance id
+ * @config: current device configuration
+ *
+ * @rcu: RCU head for freeing the structure
+ */

Quoted 8 lines

include/net/psp/types.h line 62

Quoted 6 lines
include/net/psp/types.h new file +6 -0
+struct psp_dev {
+	struct net_device *main_netdev;
+
+	struct psp_dev_ops *ops;
+	struct psp_dev_caps *caps;
+	void *drv_priv;  

not used?

Quoted 3 lines

I'd rather keep it from the start. The driver-facing API needs to be relatively complete otherwise drive authors will work around what's missing rather than adding it :(

Sounds good.

author maintainer
#7 lore raw

PATCH v3 3/19 net: modify core data structures for PSP datapath support

In reply to Daniel Zahka

From: Jakub Kicinski <[email protected]>

Add pointers to psp data structures to core networking structs, and an SKB extension to carry the PSP information from the drivers to the socket layer.

---

Notes:
v2:
- Add dev_id field to psp_skb_ext
- Move psp_assoc from struct tcp_timewait_sock to struct inet_timewait_sock
- Move psp_sk_assoc_free() from sk_common_release() to inet_sock_destruct()
v1:
- https://lore.kernel.org/netdev/[email protected]/

 include/linux/skbuff.h           | 3 +++
 include/net/inet_timewait_sock.h | 3 +++
 include/net/psp/functions.h      | 6 ++++++
 include/net/psp/types.h          | 7 +++++++
 include/net/sock.h               | 4 ++++
 net/core/skbuff.c                | 4 ++++
 net/ipv4/af_inet.c               | 2 ++
 net/ipv4/tcp_minisocks.c         | 2 ++
 8 files changed, 31 insertions(+)
include/linux/skbuff.h +3 -0
index 4f6dcb37bae8..0a9a3ce91226 100644
@@ -4835,6 +4835,9 @@ enum skb_ext_id {
 #endif
 #if IS_ENABLED(CONFIG_MCTP_FLOWS)
 	SKB_EXT_MCTP,
+#endif
+#if IS_ENABLED(CONFIG_INET_PSP)
+	SKB_EXT_PSP,
 #endif
 	SKB_EXT_NUM, /* must be last */
 };
include/net/inet_timewait_sock.h +3 -0
index 67a313575780..c1295246216c 100644
@@ -81,6 +81,9 @@ struct inet_timewait_sock {
 	struct timer_list	tw_timer;
 	struct inet_bind_bucket	*tw_tb;
 	struct inet_bind2_bucket	*tw_tb2;
+#if IS_ENABLED(CONFIG_INET_PSP)
+	struct psp_assoc __rcu	  *psp_assoc;
+#endif
 };
 #define tw_tclass tw_tos
 
include/net/psp/functions.h +6 -0
index 074f9df9afc3..d0043bd14299 100644
@@ -5,10 +5,16 @@
 
 #include <net/psp/types.h>
 
+struct inet_timewait_sock;
+
 /* Driver-facing API */
 struct psp_dev *
 psp_dev_create(struct net_device *netdev, struct psp_dev_ops *psd_ops,
 	       struct psp_dev_caps *psd_caps, void *priv_ptr);
 void psp_dev_unregister(struct psp_dev *psd);
 
+/* Kernel-facing API */
+static inline void psp_sk_assoc_free(struct sock *sk) { }
+static inline void psp_twsk_assoc_free(struct inet_timewait_sock *tw) { }
+
 #endif /* __NET_PSP_HELPERS_H */
include/net/psp/types.h +7 -0
index dbc5423a53df..ba7e5c36975c 100644
@@ -86,6 +86,13 @@ struct psp_dev_caps {
 #define PSP_V1_KEY	32
 #define PSP_MAX_KEY	32
 
+struct psp_skb_ext {
+	__be32 spi;
+	u16 dev_id;
+	u8 generation;
+	u8 version;
+};
+
 /**
  * struct psp_dev_ops - netdev driver facing PSP callbacks
  */
include/net/sock.h +4 -0
index 0f2443d4ec58..19a898846b08 100644
@@ -249,6 +249,7 @@ struct sk_filter;
   *	@sk_dst_cache: destination cache
   *	@sk_dst_pending_confirm: need to confirm neighbour
   *	@sk_policy: flow policy
+  *	@psp_assoc: PSP association, if socket is PSP-secured
   *	@sk_receive_queue: incoming packets
   *	@sk_wmem_alloc: transmit queue bytes committed
   *	@sk_tsq_flags: TCP Small Queues flags
@@ -446,6 +447,9 @@ struct sock {
 	struct mem_cgroup	*sk_memcg;
 #ifdef CONFIG_XFRM
 	struct xfrm_policy __rcu *sk_policy[2];
+#endif
+#if IS_ENABLED(CONFIG_INET_PSP)
+	struct psp_assoc __rcu	*psp_assoc;
 #endif
 	__cacheline_group_end(sock_read_rxtx);
 
net/core/skbuff.c +4 -0
index d6420b74ea9c..689f7c6f5744 100644
@@ -79,6 +79,7 @@
 #include <net/mptcp.h>
 #include <net/mctp.h>
 #include <net/page_pool/helpers.h>
+#include <net/psp/types.h>
 #include <net/dropreason.h>
 
 #include <linux/uaccess.h>
@@ -5060,6 +5061,9 @@ static const u8 skb_ext_type_len[] = {
 #if IS_ENABLED(CONFIG_MCTP_FLOWS)
 	[SKB_EXT_MCTP] = SKB_EXT_CHUNKSIZEOF(struct mctp_flow),
 #endif
+#if IS_ENABLED(CONFIG_INET_PSP)
+	[SKB_EXT_PSP] = SKB_EXT_CHUNKSIZEOF(struct psp_skb_ext),
+#endif
 };
 
 static __always_inline unsigned int skb_ext_total_length(void)
net/ipv4/af_inet.c +2 -0
index 76e38092cd8a..e298dacb4a06 100644
@@ -102,6 +102,7 @@
 #include <net/gro.h>
 #include <net/gso.h>
 #include <net/tcp.h>
+#include <net/psp.h>
 #include <net/udp.h>
 #include <net/udplite.h>
 #include <net/ping.h>
@@ -158,6 +159,7 @@ void inet_sock_destruct(struct sock *sk)
 	kfree(rcu_dereference_protected(inet->inet_opt, 1));
 	dst_release(rcu_dereference_protected(sk->sk_dst_cache, 1));
 	dst_release(rcu_dereference_protected(sk->sk_rx_dst, 1));
+	psp_sk_assoc_free(sk);
 }
 EXPORT_SYMBOL(inet_sock_destruct);
 
net/ipv4/tcp_minisocks.c +2 -0
index 43d7852ce07e..d0f49e6e3e35 100644
@@ -23,6 +23,7 @@
 #include <net/xfrm.h>
 #include <net/busy_poll.h>
 #include <net/rstreason.h>
+#include <net/psp.h>
 
 static bool tcp_in_window(u32 seq, u32 end_seq, u32 s_win, u32 e_win)
 {
@@ -400,6 +401,7 @@ void tcp_twsk_destructor(struct sock *sk)
 	}
 #endif
 	tcp_ao_destroy_sock(sk, true);
+	psp_twsk_assoc_free(inet_twsk(sk));
 }
 EXPORT_IPV6_MOD_GPL(tcp_twsk_destructor);
 
Signature · 1 line
2.47.1
maintainer Reviewed-by on v3 3/19
#8 lore raw

Re: [PATCH v3 03/19] net: modify core data structures for PSP datapath support

Quoted 9 lines · Daniel Zahka

From: Jakub Kicinski <[email protected]>

Add pointers to psp data structures to core networking structs, and an SKB extension to carry the PSP information from the drivers to the socket layer.

author maintainer
#9 lore raw

PATCH v3 4/19 tcp: add datapath logic for PSP with inline key exchange

In reply to Daniel Zahka

From: Jakub Kicinski <[email protected]>

Add validation points and state propagation to support PSP key exchange inline, on TCP connections. The expectation is that application will use some well established mechanism like TLS handshake to establish a secure channel over the connection and if both endpoints are PSP-capable - exchange and install PSP keys. Because the connection can existing in PSP-unsecured and PSP-secured state we need to make sure that there are no race conditions or retransmission leaks.

On Tx - mark packets with the skb->decrypted bit when PSP key is at the enqueue time. Drivers should only encrypt packets with this bit set. This prevents retransmissions getting encrypted when original transmission was not. Similarly to TLS, we'll use sk->sk_validate_xmit_skb to make sure PSP skbs can't "escape" via a PSP-unaware device without being encrypted.

On Rx - validation is done under socket lock. This moves the validation point later than xfrm, for example. Please see the documentation patch for more details on the flow of securing a connection, but for the purpose of this patch what's important is that we want to enforce the invariant that once connection is secured any skb in the receive queue has been encrypted with PSP.

Add trivialities like GRO and coalescing checks.

This change only adds the validation points, for ease of review. Subsequent change will add the ability to install keys, and flesh the enforcement logic out

---

Notes:
v3:
- psp_reply_set_decrypted() does not use stuct sock* arg. Drop it. v2:
- Add psp_reply_set_decrypted() to encapsulate ACKs, FINs, and RSTs sent from control socks on behalf of full or timewait socks with PSP state.
v1:
- https://lore.kernel.org/netdev/[email protected]/

 include/net/dropreason-core.h |  6 +++
 include/net/psp/functions.h   | 77 +++++++++++++++++++++++++++++++++++
 net/core/gro.c                |  2 +
 net/ipv4/inet_timewait_sock.c |  3 +-
 net/ipv4/ip_output.c          |  5 ++-
 net/ipv4/tcp.c                |  2 +
 net/ipv4/tcp_ipv4.c           | 10 ++++-
 net/ipv4/tcp_minisocks.c      | 14 +++++++
 net/ipv4/tcp_output.c         | 17 +++++---
 net/ipv6/tcp_ipv6.c           | 11 +++++
 net/psp/Kconfig               |  1 +
 11 files changed, 139 insertions(+), 9 deletions(-)
include/net/dropreason-core.h +6 -0
index b9e78290269e..559b4f01b77c 100644
@@ -124,6 +124,8 @@
 	FN(CAN_RX_INVALID_FRAME)	\
 	FN(CANFD_RX_INVALID_FRAME)	\
 	FN(CANXL_RX_INVALID_FRAME)	\
+	FN(PSP_INPUT)			\
+	FN(PSP_OUTPUT)			\
 	FNe(MAX)
 
 /**
@@ -591,6 +593,10 @@ enum skb_drop_reason {
 	 * non conform CAN-XL frame (or device is unable to receive CAN frames)
 	 */
 	SKB_DROP_REASON_CANXL_RX_INVALID_FRAME,
+	/** @SKB_DROP_REASON_PSP_INPUT: PSP input checks failed */
+	SKB_DROP_REASON_PSP_INPUT,
+	/** @SKB_DROP_REASON_PSP_OUTPUT: PSP output checks failed */
+	SKB_DROP_REASON_PSP_OUTPUT,
 	/**
 	 * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which
 	 * shouldn't be used as a real 'reason' - only for tracing code gen
include/net/psp/functions.h +77 -0

90 lines not on this page · raw message

net/core/gro.c +2 -0
index b350e5b69549..5ba4504cfd28 100644
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
+#include <net/psp.h>
 #include <net/gro.h>
 #include <net/dst_metadata.h>
 #include <net/busy_poll.h>
@@ -376,6 +377,7 @@ static void gro_list_prepare(const struct list_head *head,
 			diffs |= skb_get_nfct(p) ^ skb_get_nfct(skb);
 
 			diffs |= gro_list_prepare_tc_ext(skb, p, diffs);
+			diffs |= __psp_skb_coalesce_diff(skb, p, diffs);
 		}
 
 		NAPI_GRO_CB(p)->same_flow = !diffs;
net/ipv4/inet_timewait_sock.c +2 -1
index 875ff923a8ed..dfde7895d8f2 100644
@@ -15,7 +15,7 @@
 #include <net/inet_hashtables.h>
 #include <net/inet_timewait_sock.h>
 #include <net/ip.h>
-
+#include <net/psp.h>
 
 /**
  *	inet_twsk_bind_unhash - unhash a timewait socket from bind hash
@@ -218,6 +218,7 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk,
 		refcount_set(&tw->tw_refcnt, 0);
 
 		__module_get(tw->tw_prot->owner);
+		psp_twsk_init(tw, (struct sock *)sk);
 	}
 
 	return tw;
net/ipv4/ip_output.c +4 -1
index a2705d454fd6..b8912e072f14 100644
@@ -83,6 +83,7 @@
 #include <linux/netfilter_bridge.h>
 #include <linux/netlink.h>
 #include <linux/tcp.h>
+#include <net/psp.h>
 
 static int
 ip_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
@@ -1660,8 +1661,10 @@ void ip_send_unicast_reply(struct sock *sk, const struct sock *orig_sk,
 			  arg->csumoffset) = csum_fold(csum_add(nskb->csum,
 								arg->csum));
 		nskb->ip_summed = CHECKSUM_NONE;
-		if (orig_sk)
+		if (orig_sk) {
 			skb_set_owner_edemux(nskb, (struct sock *)orig_sk);
+			psp_reply_set_decrypted(nskb);
+		}
 		if (transmit_time)
 			nskb->tstamp_type = SKB_CLOCK_MONOTONIC;
 		if (txhash)
net/ipv4/tcp.c +2 -0
index 8a3c99246d2e..1089087002ab 100644
@@ -275,6 +275,7 @@
 #include <net/proto_memory.h>
 #include <net/xfrm.h>
 #include <net/ip.h>
+#include <net/psp.h>
 #include <net/sock.h>
 #include <net/rstreason.h>
 
@@ -689,6 +690,7 @@ void tcp_skb_entail(struct sock *sk, struct sk_buff *skb)
 	tcb->seq     = tcb->end_seq = tp->write_seq;
 	tcb->tcp_flags = TCPHDR_ACK;
 	__skb_header_release(skb);
+	psp_enqueue_set_decrypted(sk, skb);
 	tcp_add_write_queue_tail(sk, skb);
 	sk_wmem_queued_add(sk, skb->truesize);
 	sk_mem_charge(sk, skb->truesize);
net/ipv4/tcp_ipv4.c +9 -1
index 429fb34b075e..0f290e6dca2b 100644
@@ -72,6 +72,7 @@
 #include <net/secure_seq.h>
 #include <net/busy_poll.h>
 #include <net/rstreason.h>
+#include <net/psp.h>
 
 #include <linux/inet.h>
 #include <linux/ipv6.h>
@@ -1906,6 +1907,10 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
 	enum skb_drop_reason reason;
 	struct sock *rsk;
 
+	reason = psp_sk_rx_policy_check(sk, skb);
+	if (reason)
+		goto err_discard;
+
 	if (sk->sk_state == TCP_ESTABLISHED) { /* Fast path */
 		struct dst_entry *dst;
 
@@ -1967,6 +1972,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
 	reason = SKB_DROP_REASON_TCP_CSUM;
 	trace_tcp_bad_csum(skb);
 	TCP_INC_STATS(sock_net(sk), TCP_MIB_CSUMERRORS);
+err_discard:
 	TCP_INC_STATS(sock_net(sk), TCP_MIB_INERRS);
 	goto discard;
 }
@@ -2068,7 +2074,9 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb,
 	     (TCPHDR_ECE | TCPHDR_CWR | TCPHDR_AE)) ||
 	    !tcp_skb_can_collapse_rx(tail, skb) ||
 	    thtail->doff != th->doff ||
-	    memcmp(thtail + 1, th + 1, hdrlen - sizeof(*th)))
+	    memcmp(thtail + 1, th + 1, hdrlen - sizeof(*th)) ||
+	    /* prior to PSP Rx policy check, retain exact PSP metadata */
+	    psp_skb_coalesce_diff(tail, skb))
 		goto no_coalesce;
 
 	__skb_pull(skb, hdrlen);
net/ipv4/tcp_minisocks.c +14 -0
index d0f49e6e3e35..79337028f3a5 100644
@@ -104,9 +104,12 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 	struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
 	u32 rcv_nxt = READ_ONCE(tcptw->tw_rcv_nxt);
 	struct tcp_options_received tmp_opt;
+	enum skb_drop_reason psp_drop;
 	bool paws_reject = false;
 	int ts_recent_stamp;
 
+	psp_drop = psp_twsk_rx_policy_check(tw, skb);
+
 	tmp_opt.saw_tstamp = 0;
 	ts_recent_stamp = READ_ONCE(tcptw->tw_ts_recent_stamp);
 	if (th->doff > (sizeof(*th) >> 2) && ts_recent_stamp) {
@@ -124,6 +127,9 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 	if (READ_ONCE(tw->tw_substate) == TCP_FIN_WAIT2) {
 		/* Just repeat all the checks of tcp_rcv_state_process() */
 
+		if (psp_drop)
+			goto out_put;
+
 		/* Out of window, send ACK */
 		if (paws_reject ||
 		    !tcp_in_window(TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq,
@@ -194,6 +200,9 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 	     (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq || th->rst))) {
 		/* In window segment, it may be only reset or bare ack. */
 
+		if (psp_drop)
+			goto out_put;
+
 		if (th->rst) {
 			/* This is TIME_WAIT assassination, in two flavors.
 			 * Oh well... nobody has a sufficient solution to this
@@ -247,6 +256,9 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 		return TCP_TW_SYN;
 	}
 
+	if (psp_drop)
+		goto out_put;
+
 	if (paws_reject) {
 		*drop_reason = SKB_DROP_REASON_TCP_RFC7323_TW_PAWS;
 		__NET_INC_STATS(twsk_net(tw), LINUX_MIB_PAWS_TW_REJECTED);
@@ -265,6 +277,8 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 		return tcp_timewait_check_oow_rate_limit(
 			tw, skb, LINUX_MIB_TCPACKSKIPPEDTIMEWAIT);
 	}
+
+out_put:
 	inet_twsk_put(tw);
 	return TCP_TW_SUCCESS;
 }
net/ipv4/tcp_output.c +11 -6
index 28f840724fe8..e21c654bf637 100644
@@ -40,6 +40,7 @@
 #include <net/tcp.h>
 #include <net/mptcp.h>
 #include <net/proto_memory.h>
+#include <net/psp.h>
 
 #include <linux/compiler.h>
 #include <linux/gfp.h>
@@ -403,13 +404,15 @@ static void tcp_ecn_send(struct sock *sk, struct sk_buff *skb,
 /* Constructs common control bits of non-data skb. If SYN/FIN is present,
  * auto increment end seqno.
  */
-static void tcp_init_nondata_skb(struct sk_buff *skb, u32 seq, u16 flags)
+static void tcp_init_nondata_skb(struct sk_buff *skb, struct sock *sk,
+				 u32 seq, u16 flags)
 {
 	skb->ip_summed = CHECKSUM_PARTIAL;
 
 	TCP_SKB_CB(skb)->tcp_flags = flags;
 
 	tcp_skb_pcount_set(skb, 1);
+	psp_enqueue_set_decrypted(sk, skb);
 
 	TCP_SKB_CB(skb)->seq = seq;
 	if (flags & (TCPHDR_SYN | TCPHDR_FIN))
@@ -1510,6 +1513,7 @@ static void tcp_queue_skb(struct sock *sk, struct sk_buff *skb)
 	/* Advance write_seq and place onto the write_queue. */
 	WRITE_ONCE(tp->write_seq, TCP_SKB_CB(skb)->end_seq);
 	__skb_header_release(skb);
+	psp_enqueue_set_decrypted(sk, skb);
 	tcp_add_write_queue_tail(sk, skb);
 	sk_wmem_queued_add(sk, skb->truesize);
 	sk_mem_charge(sk, skb->truesize);
@@ -3613,7 +3617,7 @@ void tcp_send_fin(struct sock *sk)
 		skb_reserve(skb, MAX_TCP_HEADER);
 		sk_forced_mem_schedule(sk, skb->truesize);
 		/* FIN eats a sequence byte, write_seq advanced by tcp_queue_skb(). */
-		tcp_init_nondata_skb(skb, tp->write_seq,
+		tcp_init_nondata_skb(skb, sk, tp->write_seq,
 				     TCPHDR_ACK | TCPHDR_FIN);
 		tcp_queue_skb(sk, skb);
 	}
@@ -3641,7 +3645,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority,
 
 	/* Reserve space for headers and prepare control bits. */
 	skb_reserve(skb, MAX_TCP_HEADER);
-	tcp_init_nondata_skb(skb, tcp_acceptable_seq(sk),
+	tcp_init_nondata_skb(skb, sk, tcp_acceptable_seq(sk),
 			     TCPHDR_ACK | TCPHDR_RST);
 	tcp_mstamp_refresh(tcp_sk(sk));
 	/* Send it off. */
@@ -4136,7 +4140,7 @@ int tcp_connect(struct sock *sk)
 	/* SYN eats a sequence byte, write_seq updated by
 	 * tcp_connect_queue_skb().
 	 */
-	tcp_init_nondata_skb(buff, tp->write_seq, TCPHDR_SYN);
+	tcp_init_nondata_skb(buff, sk, tp->write_seq, TCPHDR_SYN);
 	tcp_mstamp_refresh(tp);
 	tp->retrans_stamp = tcp_time_stamp_ts(tp);
 	tcp_connect_queue_skb(sk, buff);
@@ -4261,7 +4265,8 @@ void __tcp_send_ack(struct sock *sk, u32 rcv_nxt, u16 flags)
 
 	/* Reserve space for headers and prepare control bits. */
 	skb_reserve(buff, MAX_TCP_HEADER);
-	tcp_init_nondata_skb(buff, tcp_acceptable_seq(sk), TCPHDR_ACK | flags);
+	tcp_init_nondata_skb(buff, sk,
+			     tcp_acceptable_seq(sk), TCPHDR_ACK | flags);
 
 	/* We do not want pure acks influencing TCP Small Queues or fq/pacing
 	 * too much.
@@ -4307,7 +4312,7 @@ static int tcp_xmit_probe_skb(struct sock *sk, int urgent, int mib)
 	 * end to send an ack.  Don't queue or clone SKB, just
 	 * send it.
 	 */
-	tcp_init_nondata_skb(skb, tp->snd_una - !urgent, TCPHDR_ACK);
+	tcp_init_nondata_skb(skb, sk, tp->snd_una - !urgent, TCPHDR_ACK);
 	NET_INC_STATS(sock_net(sk), mib);
 	return tcp_transmit_skb(sk, skb, 0, (__force gfp_t)0);
 }
net/ipv6/tcp_ipv6.c +11 -0
index f0ce62549d90..b1ab44ddb487 100644
@@ -61,6 +61,7 @@
 #include <net/hotdata.h>
 #include <net/busy_poll.h>
 #include <net/rstreason.h>
+#include <net/psp.h>
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
@@ -973,6 +974,7 @@ static void tcp_v6_send_response(const struct sock *sk, struct sk_buff *skb, u32
 	if (sk) {
 		/* unconstify the socket only to attach it to buff with care. */
 		skb_set_owner_edemux(buff, (struct sock *)sk);
+		psp_reply_set_decrypted(buff);
 
 		if (sk->sk_state == TCP_TIME_WAIT)
 			mark = inet_twsk(sk)->tw_mark;
@@ -1608,6 +1610,10 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
 	if (skb->protocol == htons(ETH_P_IP))
 		return tcp_v4_do_rcv(sk, skb);
 
+	reason = psp_sk_rx_policy_check(sk, skb);
+	if (reason)
+		goto err_discard;
+
 	/*
 	 *	socket locking is here for SMP purposes as backlog rcv
 	 *	is currently called with bh processing disabled.
@@ -1687,6 +1693,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
 	reason = SKB_DROP_REASON_TCP_CSUM;
 	trace_tcp_bad_csum(skb);
 	TCP_INC_STATS(sock_net(sk), TCP_MIB_CSUMERRORS);
+err_discard:
 	TCP_INC_STATS(sock_net(sk), TCP_MIB_INERRS);
 	goto discard;
 
@@ -1995,6 +2002,10 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
 			__this_cpu_write(tcp_tw_isn, isn);
 			goto process;
 		}
+
+		drop_reason = psp_twsk_rx_policy_check(inet_twsk(sk), skb);
+		if (drop_reason)
+			break;
 	}
 		/* to ACK */
 		fallthrough;
net/psp/Kconfig +1 -0
index 55f9dd87446b..5e3908a40945 100644
@@ -5,6 +5,7 @@
 config INET_PSP
 	bool "PSP Security Protocol support"
 	depends on INET
+	select SKB_DECRYPTED
 	help
 	Enable kernel support for the PSP protocol.
 	For more information see:
Signature · 1 line
2.47.1
maintainer
#10 lore raw

Re: [PATCH v3 04/19] tcp: add datapath logic for PSP with inline key exchange

Quoted 38 lines · Daniel Zahka

From: Jakub Kicinski <[email protected]>

Add validation points and state propagation to support PSP key exchange inline, on TCP connections. The expectation is that application will use some well established mechanism like TLS handshake to establish a secure channel over the connection and if both endpoints are PSP-capable - exchange and install PSP keys. Because the connection can existing in PSP-unsecured and PSP-secured state we need to make sure that there are no race conditions or retransmission leaks.

On Tx - mark packets with the skb->decrypted bit when PSP key is at the enqueue time. Drivers should only encrypt packets with this bit set. This prevents retransmissions getting encrypted when original transmission was not. Similarly to TLS, we'll use sk->sk_validate_xmit_skb to make sure PSP skbs can't "escape" via a PSP-unaware device without being encrypted.

On Rx - validation is done under socket lock. This moves the validation point later than xfrm, for example. Please see the documentation patch for more details on the flow of securing a connection, but for the purpose of this patch what's important is that we want to enforce the invariant that once connection is secured any skb in the receive queue has been encrypted with PSP.

Add trivialities like GRO and coalescing checks.

This change only adds the validation points, for ease of review. Subsequent change will add the ability to install keys, and flesh the enforcement logic out

/**
* inet_twsk_bind_unhash - unhash a timewait socket from bind hash

net/ipv4/inet_timewait_sock.c struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, · line 221

Quoted 4 lines
net/ipv4/inet_timewait_sock.c +1 -0
@@ -218,6 +218,7 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk,
 		refcount_set(&tw->tw_refcnt, 0);
 
 		__module_get(tw->tw_prot->owner);
+		psp_twsk_init(tw, (struct sock *)sk);

Is it possible to avoid the need for a cast here? Can psp_sk_assoc take a const pointer?

net/ipv4/tcp.c void tcp_skb_entail(struct sock *sk, struct sk_buff *skb) · line 693

Quoted 5 lines
net/ipv4/tcp.c +1 -0
@@ -689,6 +690,7 @@ void tcp_skb_entail(struct sock *sk, struct sk_buff *skb)
 	tcb->seq     = tcb->end_seq = tp->write_seq;
 	tcb->tcp_flags = TCPHDR_ACK;
 	__skb_header_release(skb);
+	psp_enqueue_set_decrypted(sk, skb);

If touching the tcp hot path, maybe a static branch.

Quoted 5 lines
net/ipv4/tcp_minisocks.c +0 -0
index d0f49e6e3e35..79337028f3a5 100644

net/ipv4/tcp_minisocks.c tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, · line 112

Quoted 9 lines
net/ipv4/tcp_minisocks.c +3 -0
@@ -104,9 +104,12 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 	struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
 	u32 rcv_nxt = READ_ONCE(tcptw->tw_rcv_nxt);
 	struct tcp_options_received tmp_opt;
+	enum skb_drop_reason psp_drop;
 	bool paws_reject = false;
 	int ts_recent_stamp;
 
+	psp_drop = psp_twsk_rx_policy_check(tw, skb);
+

Why not return immediately here if the policy check fails, similar to the non-timewait path?

Quoted 42 lines
net/ipv4/tcp_minisocks.c +11 -0
 	tmp_opt.saw_tstamp = 0;
 	ts_recent_stamp = READ_ONCE(tcptw->tw_ts_recent_stamp);
 	if (th->doff > (sizeof(*th) >> 2) && ts_recent_stamp) {
@@ -124,6 +127,9 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 	if (READ_ONCE(tw->tw_substate) == TCP_FIN_WAIT2) {
 		/* Just repeat all the checks of tcp_rcv_state_process() */
 
+		if (psp_drop)
+			goto out_put;
+
 		/* Out of window, send ACK */
 		if (paws_reject ||
 		    !tcp_in_window(TCP_SKB_CB(skb)->seq, TCP_SKB_CB(skb)->end_seq,
@@ -194,6 +200,9 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 	     (TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq || th->rst))) {
 		/* In window segment, it may be only reset or bare ack. */
 
+		if (psp_drop)
+			goto out_put;
+
 		if (th->rst) {
 			/* This is TIME_WAIT assassination, in two flavors.
 			 * Oh well... nobody has a sufficient solution to this
@@ -247,6 +256,9 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 		return TCP_TW_SYN;
 	}
 
+	if (psp_drop)
+		goto out_put;
+
 	if (paws_reject) {
 		*drop_reason = SKB_DROP_REASON_TCP_RFC7323_TW_PAWS;
 		__NET_INC_STATS(twsk_net(tw), LINUX_MIB_PAWS_TW_REJECTED);
@@ -265,6 +277,8 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 		return tcp_timewait_check_oow_rate_limit(
 			tw, skb, LINUX_MIB_TCPACKSKIPPEDTIMEWAIT);
 	}
+
+out_put:
 	inet_twsk_put(tw);
 	return TCP_TW_SUCCESS;
 }
author maintainer
#11 lore raw

Re: [PATCH v3 04/19] tcp: add datapath logic for PSP with inline key exchange

Quoted 12 lines · Willem de Bruijn
Quoted 12 lines
net/ipv4/tcp_minisocks.c +1 -0
index d0f49e6e3e35..79337028f3a5 100644
@@ -104,9 +104,12 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
  	struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
  	u32 rcv_nxt = READ_ONCE(tcptw->tw_rcv_nxt);
  	struct tcp_options_received tmp_opt;
+	enum skb_drop_reason psp_drop;
  	bool paws_reject = false;
  	int ts_recent_stamp;
 
Quoted 4 lines

net/ipv4/tcp_minisocks.c tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, · line 112

Quoted 2 lines
net/ipv4/tcp_minisocks.c +2 -0
+	psp_drop = psp_twsk_rx_policy_check(tw, skb);
+

Why not return immediately here if the policy check fails, similar to the non-timewait path?

The placement is so that we can accept a non psp encapsulated syn in the case where TCP_TW_SYN is returned from tcp_timewait_state_process().

maintainer
#12 lore raw

Re: [PATCH v3 04/19] tcp: add datapath logic for PSP with inline key exchange

Quoted 15 lines · Daniel Zahka
Quoted 12 lines · Willem de Bruijn
Quoted 12 lines
net/ipv4/tcp_minisocks.c +1 -0
index d0f49e6e3e35..79337028f3a5 100644
@@ -104,9 +104,12 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
  	struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
  	u32 rcv_nxt = READ_ONCE(tcptw->tw_rcv_nxt);
  	struct tcp_options_received tmp_opt;
+	enum skb_drop_reason psp_drop;
  	bool paws_reject = false;
  	int ts_recent_stamp;
 
Quoted 7 lines
Quoted 4 lines

net/ipv4/tcp_minisocks.c tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, · line 112

Quoted 2 lines
net/ipv4/tcp_minisocks.c +2 -0
+	psp_drop = psp_twsk_rx_policy_check(tw, skb);
+

Why not return immediately here if the policy check fails, similar to the non-timewait path?

The placement is so that we can accept a non psp encapsulated syn in the case where TCP_TW_SYN is returned from tcp_timewait_state_process().

Ah I see. Maybe worth a brief comment.

author maintainer
#13 lore raw

Re: [PATCH v3 04/19] tcp: add datapath logic for PSP with inline key exchange

In reply to Willem de Bruijn
Quoted 6 lines · Willem de Bruijn

net/ipv4/tcp.c void tcp_skb_entail(struct sock *sk, struct sk_buff *skb) · line 693

Quoted 5 lines
net/ipv4/tcp.c +1 -0
@@ -689,6 +690,7 @@ void tcp_skb_entail(struct sock *sk, struct sk_buff *skb)
  	tcb->seq     = tcb->end_seq = tp->write_seq;
  	tcb->tcp_flags = TCPHDR_ACK;
  	__skb_header_release(skb);
+	psp_enqueue_set_decrypted(sk, skb);

If touching the tcp hot path, maybe a static branch.

Ack. Do you imagine we would key the branch on pas creation or on psd creation? Our preference would be to defer the change to its own series if the code is acceptable as is.

maintainer
#14 lore raw

Re: [PATCH v3 04/19] tcp: add datapath logic for PSP with inline key exchange

Quoted 10 lines · Daniel Zahka
Quoted 6 lines · Willem de Bruijn

net/ipv4/tcp.c void tcp_skb_entail(struct sock *sk, struct sk_buff *skb) · line 693

Quoted 5 lines
net/ipv4/tcp.c +1 -0
@@ -689,6 +690,7 @@ void tcp_skb_entail(struct sock *sk, struct sk_buff *skb)
  	tcb->seq     = tcb->end_seq = tp->write_seq;
  	tcb->tcp_flags = TCPHDR_ACK;
  	__skb_header_release(skb);
+	psp_enqueue_set_decrypted(sk, skb);

If touching the tcp hot path, maybe a static branch.

Quoted 2 lines

Ack. Do you imagine we would key the branch on pas creation or on psd creation?

That's kind of immaterial, as long as it gets set before the majority of hot patch calls.

Since psp_dev is the first object created, that is the more precise starting point for when PSP as a whole becomes active.

Quoted 2 lines

Our preference would be to defer the change to its own series if the code is acceptable as is.

I would also defer it to a stand-alone patch or set of patches, to avoid complicating existing patches.

And as the series is already over 15, fine to move to a follow-on series too.

author maintainer
#15 lore raw

PATCH v3 5/19 psp: add op for rotation of device key

In reply to Daniel Zahka

From: Jakub Kicinski <[email protected]>

Rotating the device key is a key part of the PSP protocol design. Some external daemon needs to do it once a day, or so. Add a netlink op to perform this operation.
Add a notification group for informing users that key has been rotated and they should rekey (next rotation will cut them off).

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 Documentation/netlink/specs/psp.yaml | 21 +++++++++++++++
 include/net/psp/types.h              |  5 ++++
 include/uapi/linux/psp.h             |  3 +++
 net/psp/psp-nl-gen.c                 | 15 +++++++++++
 net/psp/psp-nl-gen.h                 |  2 ++
 net/psp/psp_main.c                   |  3 ++-
 net/psp/psp_nl.c                     | 40 ++++++++++++++++++++++++++++
 7 files changed, 88 insertions(+), 1 deletion(-)
Documentation/netlink/specs/psp.yaml +21 -0
index 706f4baf8764..054cc02b65ad 100644
@@ -88,9 +88,30 @@ operations:
       notify: dev-get
       mcgrp: mgmt
 
+    -
+      name: key-rotate
+      doc: Rotate the device key.
+      attribute-set: dev
+      do:
+        request:
+          attributes:
+            - id
+        reply:
+          attributes:
+            - id
+        pre: psp-device-get-locked
+        post: psp-device-unlock
+    -
+      name: key-rotate-ntf
+      doc: Notification about device key getting rotated.
+      notify: key-rotate
+      mcgrp: use
+
 mcast-groups:
   list:
     -
       name: mgmt
+    -
+      name: use
 
 ...
include/net/psp/types.h +5 -0
index ba7e5c36975c..9191a88c349e 100644
@@ -104,6 +104,11 @@ struct psp_dev_ops {
 	 */
 	int (*set_config)(struct psp_dev *psd, struct psp_dev_config *conf,
 			  struct netlink_ext_ack *extack);
+
+	/**
+	 * @key_rotate: rotate the device key
+	 */
+	int (*key_rotate)(struct psp_dev *psd, struct netlink_ext_ack *extack);
 };
 
 #endif /* __NET_PSP_H */
include/uapi/linux/psp.h +3 -0
index 4a404f085190..cbfbf3f0f364 100644
@@ -32,11 +32,14 @@ enum {
 	PSP_CMD_DEV_DEL_NTF,
 	PSP_CMD_DEV_SET,
 	PSP_CMD_DEV_CHANGE_NTF,
+	PSP_CMD_KEY_ROTATE,
+	PSP_CMD_KEY_ROTATE_NTF,
 
 	__PSP_CMD_MAX,
 	PSP_CMD_MAX = (__PSP_CMD_MAX - 1)
 };
 
 #define PSP_MCGRP_MGMT	"mgmt"
+#define PSP_MCGRP_USE	"use"
 
 #endif /* _UAPI_LINUX_PSP_H */
net/psp/psp-nl-gen.c +15 -0
index 859712e7c2c1..7f49577ac72f 100644
@@ -21,6 +21,11 @@ static const struct nla_policy psp_dev_set_nl_policy[PSP_A_DEV_PSP_VERSIONS_ENA
 	[PSP_A_DEV_PSP_VERSIONS_ENA] = NLA_POLICY_MASK(NLA_U32, 0xf),
 };
 
+/* PSP_CMD_KEY_ROTATE - do */
+static const struct nla_policy psp_key_rotate_nl_policy[PSP_A_DEV_ID + 1] = {
+	[PSP_A_DEV_ID] = NLA_POLICY_MIN(NLA_U32, 1),
+};
+
 /* Ops table for psp */
 static const struct genl_split_ops psp_nl_ops[] = {
 	{
@@ -46,10 +51,20 @@ static const struct genl_split_ops psp_nl_ops[] = {
 		.maxattr	= PSP_A_DEV_PSP_VERSIONS_ENA,
 		.flags		= GENL_CMD_CAP_DO,
 	},
+	{
+		.cmd		= PSP_CMD_KEY_ROTATE,
+		.pre_doit	= psp_device_get_locked,
+		.doit		= psp_nl_key_rotate_doit,
+		.post_doit	= psp_device_unlock,
+		.policy		= psp_key_rotate_nl_policy,
+		.maxattr	= PSP_A_DEV_ID,
+		.flags		= GENL_CMD_CAP_DO,
+	},
 };
 
 static const struct genl_multicast_group psp_nl_mcgrps[] = {
 	[PSP_NLGRP_MGMT] = { "mgmt", },
+	[PSP_NLGRP_USE] = { "use", },
 };
 
 struct genl_family psp_nl_family __ro_after_init = {
net/psp/psp-nl-gen.h +2 -0
index a099686cab5d..00a2d4ec59e4 100644
@@ -20,9 +20,11 @@ psp_device_unlock(const struct genl_split_ops *ops, struct sk_buff *skb,
 int psp_nl_dev_get_doit(struct sk_buff *skb, struct genl_info *info);
 int psp_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
 int psp_nl_dev_set_doit(struct sk_buff *skb, struct genl_info *info);
+int psp_nl_key_rotate_doit(struct sk_buff *skb, struct genl_info *info);
 
 enum {
 	PSP_NLGRP_MGMT,
+	PSP_NLGRP_USE,
 };
 
 extern struct genl_family psp_nl_family;
net/psp/psp_main.c +2 -1
index 35f69fe3d1a2..7f1a6cda6a7a 100644
@@ -54,7 +54,8 @@ psp_dev_create(struct net_device *netdev,
 	int err;
 
 	if (WARN_ON(!psd_caps->versions ||
-		    !psd_ops->set_config))
+		    !psd_ops->set_config ||
+		    !psd_ops->key_rotate))
 		return ERR_PTR(-EINVAL);
 
 	psd = kzalloc(sizeof(*psd), GFP_KERNEL);
net/psp/psp_nl.c +40 -0
index fda5ce800f82..b7006e50dc87 100644
@@ -221,3 +221,43 @@ int psp_nl_dev_set_doit(struct sk_buff *skb, struct genl_info *info)
 	nlmsg_free(rsp);
 	return err;
 }
+
+int psp_nl_key_rotate_doit(struct sk_buff *skb, struct genl_info *info)
+{
+	struct psp_dev *psd = info->user_ptr[0];
+	struct genl_info ntf_info;
+	struct sk_buff *ntf, *rsp;
+	int err;
+
+	rsp = psp_nl_reply_new(info);
+	if (!rsp)
+		return -ENOMEM;
+
+	genl_info_init_ntf(&ntf_info, &psp_nl_family, PSP_CMD_KEY_ROTATE);
+	ntf = psp_nl_reply_new(&ntf_info);
+	if (!ntf) {
+		err = -ENOMEM;
+		goto err_free_rsp;
+	}
+
+	if (nla_put_u32(rsp, PSP_A_DEV_ID, psd->id) ||
+	    nla_put_u32(ntf, PSP_A_DEV_ID, psd->id)) {
+		err = -EMSGSIZE;
+		goto err_free_ntf;
+	}
+
+	err = psd->ops->key_rotate(psd, info->extack);
+	if (err)
+		goto err_free_ntf;
+
+	nlmsg_end(ntf, (struct nlmsghdr *)ntf->data);
+	genlmsg_multicast_netns(&psp_nl_family, dev_net(psd->main_netdev), ntf,
+				0, PSP_NLGRP_USE, GFP_KERNEL);
+	return psp_nl_reply_send(rsp, info);
+
+err_free_ntf:
+	nlmsg_free(ntf);
+err_free_rsp:
+	nlmsg_free(rsp);
+	return err;
+}
Signature · 1 line
2.47.1
maintainer Reviewed-by on v3 5/19
#16 lore raw

Re: [PATCH v3 05/19] psp: add op for rotation of device key

Quoted 10 lines · Daniel Zahka

From: Jakub Kicinski <[email protected]>

Rotating the device key is a key part of the PSP protocol design. Some external daemon needs to do it once a day, or so. Add a netlink op to perform this operation.
Add a notification group for informing users that key has been rotated and they should rekey (next rotation will cut them off).

author maintainer
#17 lore raw

PATCH v3 6/19 net: move sk_validate_xmit_skb() to net/core/dev.c

In reply to Daniel Zahka

Move definition of sk_validate_xmit_skb() from net/core/sock.c to net/core/dev.c.

This change is in preparation of the next patch, where sk_validate_xmit_skb() will need to cast sk to a tcp_timewait_sock *, and access member fields. Including linux/tcp.h from linux/sock.h creates a circular dependency, and dev.c is the only current call site of this function.

---

Notes:
v2:
- patch introduced in v2

 include/net/sock.h | 22 ----------------------
 net/core/dev.c     | 22 ++++++++++++++++++++++
 2 files changed, 22 insertions(+), 22 deletions(-)
include/net/sock.h +0 -22
index 19a898846b08..0ae9a6d8b53e 100644
@@ -2870,28 +2870,6 @@ sk_requests_wifi_status(struct sock *sk)
 	return sk && sk_fullsock(sk) && sock_flag(sk, SOCK_WIFI_STATUS);
 }
 
-/* Checks if this SKB belongs to an HW offloaded socket
- * and whether any SW fallbacks are required based on dev.
- * Check decrypted mark in case skb_orphan() cleared socket.
- */
-static inline struct sk_buff *sk_validate_xmit_skb(struct sk_buff *skb,
-						   struct net_device *dev)
-{
-#ifdef CONFIG_SOCK_VALIDATE_XMIT
-	struct sock *sk = skb->sk;
-
-	if (sk && sk_fullsock(sk) && sk->sk_validate_xmit_skb) {
-		skb = sk->sk_validate_xmit_skb(sk, dev, skb);
-	} else if (unlikely(skb_is_decrypted(skb))) {
-		pr_warn_ratelimited("unencrypted skb with no associated socket - dropping\n");
-		kfree_skb(skb);
-		skb = NULL;
-	}
-#endif
-
-	return skb;
-}
-
 /* This helper checks if a socket is a LISTEN or NEW_SYN_RECV
  * SYNACK messages can be attached to either ones (depending on SYNCOOKIE)
  */
net/core/dev.c +22 -0
index 7ee808eb068e..b825b3f5b7db 100644
@@ -3896,6 +3896,28 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,
 }
 EXPORT_SYMBOL(skb_csum_hwoffload_help);
 
+/* Checks if this SKB belongs to an HW offloaded socket
+ * and whether any SW fallbacks are required based on dev.
+ * Check decrypted mark in case skb_orphan() cleared socket.
+ */
+static struct sk_buff *sk_validate_xmit_skb(struct sk_buff *skb,
+					    struct net_device *dev)
+{
+#ifdef CONFIG_SOCK_VALIDATE_XMIT
+	struct sock *sk = skb->sk;
+
+	if (sk && sk_fullsock(sk) && sk->sk_validate_xmit_skb) {
+		skb = sk->sk_validate_xmit_skb(sk, dev, skb);
+	} else if (unlikely(skb_is_decrypted(skb))) {
+		pr_warn_ratelimited("unencrypted skb with no associated socket - dropping\n");
+		kfree_skb(skb);
+		skb = NULL;
+	}
+#endif
+
+	return skb;
+}
+
 static struct sk_buff *validate_xmit_unreadable_skb(struct sk_buff *skb,
 						    struct net_device *dev)
 {
Signature · 1 line
2.47.1
maintainer Reviewed-by on v3 6/19
#18 lore raw

Re: [PATCH v3 06/19] net: move sk_validate_xmit_skb() to net/core/dev.c

Quoted 10 lines · Daniel Zahka

Move definition of sk_validate_xmit_skb() from net/core/sock.c to net/core/dev.c.

This change is in preparation of the next patch, where sk_validate_xmit_skb() will need to cast sk to a tcp_timewait_sock *, and access member fields. Including linux/tcp.h from linux/sock.h creates a circular dependency, and dev.c is the only current call site of this function.

author maintainer
#19 lore raw

PATCH v3 7/19 net: tcp: allow tcp_timewait_sock to validate skbs before handing to device

In reply to Daniel Zahka

Provide a callback to validate skb's originating from tcp timewait socks before passing to the device layer. Full socks have a sk_validate_xmit_skb member for checking that a device is capable of performing offloads required for transmitting an skb. With psp, tcp timewait socks will inherit the crypto state from their corresponding full socks. Any ACKs or RSTs that originate from a tcp timewait sock carrying psp state should be psp encapsulated.

---

Notes:
v3:
- check for sk_is_inet() before casting to inet_twsk()

v2:
- patch introduced in v2

 include/net/inet_timewait_sock.h |  5 +++++
 net/core/dev.c                   | 14 ++++++++++++--
 net/ipv4/inet_timewait_sock.c    |  3 +++
 3 files changed, 20 insertions(+), 2 deletions(-)
include/net/inet_timewait_sock.h +5 -0
index c1295246216c..3a31c74c9e15 100644
@@ -84,6 +84,11 @@ struct inet_timewait_sock {
 #if IS_ENABLED(CONFIG_INET_PSP)
 	struct psp_assoc __rcu	  *psp_assoc;
 #endif
+#ifdef CONFIG_SOCK_VALIDATE_XMIT
+	struct sk_buff*		(*tw_validate_xmit_skb)(struct sock *sk,
+							struct net_device *dev,
+							struct sk_buff *skb);
+#endif
 };
 #define tw_tclass tw_tos
 
net/core/dev.c +12 -2
index b825b3f5b7db..4eddea8dcb82 100644
@@ -3904,10 +3904,20 @@ static struct sk_buff *sk_validate_xmit_skb(struct sk_buff *skb,
 					    struct net_device *dev)
 {
 #ifdef CONFIG_SOCK_VALIDATE_XMIT
+	struct sk_buff *(*sk_validate)(struct sock *sk, struct net_device *dev,
+				       struct sk_buff *skb);
 	struct sock *sk = skb->sk;
 
-	if (sk && sk_fullsock(sk) && sk->sk_validate_xmit_skb) {
-		skb = sk->sk_validate_xmit_skb(sk, dev, skb);
+	sk_validate = NULL;
+	if (sk) {
+		if (sk_fullsock(sk))
+			sk_validate = sk->sk_validate_xmit_skb;
+		else if (sk_is_inet(sk) && sk->sk_state == TCP_TIME_WAIT)
+			sk_validate = inet_twsk(sk)->tw_validate_xmit_skb;
+	}
+
+	if (sk_validate) {
+		skb = sk_validate(sk, dev, skb);
 	} else if (unlikely(skb_is_decrypted(skb))) {
 		pr_warn_ratelimited("unencrypted skb with no associated socket - dropping\n");
 		kfree_skb(skb);
net/ipv4/inet_timewait_sock.c +3 -0
index dfde7895d8f2..859c03e07466 100644
@@ -210,6 +210,9 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk,
 		atomic64_set(&tw->tw_cookie, atomic64_read(&sk->sk_cookie));
 		twsk_net_set(tw, sock_net(sk));
 		timer_setup(&tw->tw_timer, tw_timer_handler, 0);
+#ifdef CONFIG_SOCK_VALIDATE_XMIT
+		tw->tw_validate_xmit_skb = NULL;
+#endif
 		/*
 		 * Because we use RCU lookups, we should not set tw_refcnt
 		 * to a non null value before everything is setup for this
Signature · 1 line
2.47.1
maintainer Reviewed-by on v3 7/19
#20 lore raw

Re: [PATCH v3 07/19] net: tcp: allow tcp_timewait_sock to validate skbs before handing to device

Quoted 9 lines · Daniel Zahka

Provide a callback to validate skb's originating from tcp timewait socks before passing to the device layer. Full socks have a sk_validate_xmit_skb member for checking that a device is capable of performing offloads required for transmitting an skb. With psp, tcp timewait socks will inherit the crypto state from their corresponding full socks. Any ACKs or RSTs that originate from a tcp timewait sock carrying psp state should be psp encapsulated.

author maintainer
#21 lore raw

PATCH v3 8/19 net: psp: add socket security association code

In reply to Daniel Zahka

From: Jakub Kicinski <[email protected]>

Add the ability to install PSP Rx and Tx crypto keys on TCP connections. Netlink ops are provided for both operations. Rx side combines allocating a new Rx key and installing it on the socket. Theoretically these are separate actions, but in practice they will always be used one after the other. We can add distinct "alloc" and "install" ops later.

---

Notes:
v3:
- lift pse/pas comparison code into new function:
psp_pse_matches_pas().
- explicitly mark rcu critical section psp_reply_set_decrypted()
- use rcu_dereference_proteced() instead of rcu_read_lock() in psp_sk_assoc_free() and psp_twsk_assoc_free()
- rename psp_is_nondata() to psp_is_allowed_nondata()
- check for sk_is_inet() before casting to inet_twsk()
- psp_reply_set_decrypted() should not call psp_sk_assoc()
- lift common code into psp_sk_get_assoc_rcu()
- Fix exports with EXPORT_IPV6_MOD_GPL()

v2:
- add pas->dev_id == pse->dev_id to policy checks
- __psp_sk_rx_policy_check() now allows pure ACKs, FINs, and RSTs to be non-psp authenticated before "PSP Full" state.
- assign tw_validate_skb funtion during psp_twsk_init()
- psp_skb_get_rcu() also checks if sk is a tcp timewait sock when looking for psp assocs.
- scan ofo queue non-psp data during psp_sock_recv_queue_check()
- add tcp_write_collapse_fence() to psp_sock_assoc_set_tx() v1:
- https://lore.kernel.org/netdev/[email protected]/

 Documentation/netlink/specs/psp.yaml |  71 +++++++
 include/net/psp/functions.h          | 113 +++++++++--
 include/net/psp/types.h              |  58 ++++++
 include/uapi/linux/psp.h             |  21 ++
 net/psp/Kconfig                      |   1 +
 net/psp/Makefile                     |   2 +-
 net/psp/psp-nl-gen.c                 |  39 ++++
 net/psp/psp-nl-gen.h                 |   7 +
 net/psp/psp.h                        |  22 +++
 net/psp/psp_main.c                   |  11 +-
 net/psp/psp_nl.c                     | 244 +++++++++++++++++++++++
 net/psp/psp_sock.c                   | 276 +++++++++++++++++++++++++++
 12 files changed, 852 insertions(+), 13 deletions(-)
 create mode 100644 net/psp/psp_sock.c
Documentation/netlink/specs/psp.yaml +71 -0
index 054cc02b65ad..57b24cd6f3f1 100644
@@ -38,6 +38,44 @@ attribute-sets:
         type: u32
         enum: version
         enum-as-flags: true
+  -
+    name: assoc
+    attributes:
+      -
+        name: dev-id
+        doc: PSP device ID.
+        type: u32
+        checks:
+          min: 1
+      -
+        name: version
+        doc: |
+          PSP versions (AEAD and protocol version) used by this association,
+          dictates the size of the key.
+        type: u32
+        enum: version
+      -
+        name: rx-key
+        type: nest
+        nested-attributes: keys
+      -
+        name: tx-key
+        type: nest
+        nested-attributes: keys
+      -
+        name: sock-fd
+        doc: Sockets which should be bound to the association immediately.
+        type: u32
+  -
+    name: keys
+    attributes:
+      -
+        name: key
+        type: binary
+      -
+        name: spi
+        doc: Security Parameters Index (SPI) of the association.
+        type: u32
 
 operations:
   list:
@@ -107,6 +145,39 @@ operations:
       notify: key-rotate
       mcgrp: use
 
+    -
+      name: rx-assoc
+      doc: Allocate a new Rx key + SPI pair, associate it with a socket.
+      attribute-set: assoc
+      do:
+        request:
+          attributes:
+            - dev-id
+            - version
+            - sock-fd
+        reply:
+          attributes:
+            - dev-id
+            - version
+            - rx-key
+        pre: psp-assoc-device-get-locked
+        post: psp-device-unlock
+    -
+      name: tx-assoc
+      doc: Add a PSP Tx association.
+      attribute-set: assoc
+      do:
+        request:
+          attributes:
+            - dev-id
+            - version
+            - tx-key
+            - sock-fd
+        reply:
+          attributes: []
+        pre: psp-assoc-device-get-locked
+        post: psp-device-unlock
+
 mcast-groups:
   list:
     -
include/net/psp/functions.h +102 -11

156 lines not on this page · raw message

include/net/psp/types.h +58 -0

88 lines not on this page · raw message

include/uapi/linux/psp.h +21 -0
index cbfbf3f0f364..607c42c39ba5 100644
@@ -26,6 +26,25 @@ enum {
 	PSP_A_DEV_MAX = (__PSP_A_DEV_MAX - 1)
 };
 
+enum {
+	PSP_A_ASSOC_DEV_ID = 1,
+	PSP_A_ASSOC_VERSION,
+	PSP_A_ASSOC_RX_KEY,
+	PSP_A_ASSOC_TX_KEY,
+	PSP_A_ASSOC_SOCK_FD,
+
+	__PSP_A_ASSOC_MAX,
+	PSP_A_ASSOC_MAX = (__PSP_A_ASSOC_MAX - 1)
+};
+
+enum {
+	PSP_A_KEYS_KEY = 1,
+	PSP_A_KEYS_SPI,
+
+	__PSP_A_KEYS_MAX,
+	PSP_A_KEYS_MAX = (__PSP_A_KEYS_MAX - 1)
+};
+
 enum {
 	PSP_CMD_DEV_GET = 1,
 	PSP_CMD_DEV_ADD_NTF,
@@ -34,6 +53,8 @@ enum {
 	PSP_CMD_DEV_CHANGE_NTF,
 	PSP_CMD_KEY_ROTATE,
 	PSP_CMD_KEY_ROTATE_NTF,
+	PSP_CMD_RX_ASSOC,
+	PSP_CMD_TX_ASSOC,
 
 	__PSP_CMD_MAX,
 	PSP_CMD_MAX = (__PSP_CMD_MAX - 1)
net/psp/Kconfig +1 -0
index 5e3908a40945..a7d24691a7e1 100644
@@ -6,6 +6,7 @@ config INET_PSP
 	bool "PSP Security Protocol support"
 	depends on INET
 	select SKB_DECRYPTED
+	select SOCK_VALIDATE_XMIT
 	help
 	Enable kernel support for the PSP protocol.
 	For more information see:
net/psp/Makefile +1 -1
index 41b51d06e560..eb5ff3c5bfb2 100644
@@ -2,4 +2,4 @@
 
 obj-$(CONFIG_INET_PSP) += psp.o
 
-psp-y := psp_main.o psp_nl.o psp-nl-gen.o
+psp-y := psp_main.o psp_nl.o psp_sock.o psp-nl-gen.o
net/psp/psp-nl-gen.c +39 -0
index 7f49577ac72f..9fdd6f831803 100644
@@ -10,6 +10,12 @@
 
 #include <uapi/linux/psp.h>
 
+/* Common nested types */
+const struct nla_policy psp_keys_nl_policy[PSP_A_KEYS_SPI + 1] = {
+	[PSP_A_KEYS_KEY] = { .type = NLA_BINARY, },
+	[PSP_A_KEYS_SPI] = { .type = NLA_U32, },
+};
+
 /* PSP_CMD_DEV_GET - do */
 static const struct nla_policy psp_dev_get_nl_policy[PSP_A_DEV_ID + 1] = {
 	[PSP_A_DEV_ID] = NLA_POLICY_MIN(NLA_U32, 1),
@@ -26,6 +32,21 @@ static const struct nla_policy psp_key_rotate_nl_policy[PSP_A_DEV_ID + 1] = {
 	[PSP_A_DEV_ID] = NLA_POLICY_MIN(NLA_U32, 1),
 };
 
+/* PSP_CMD_RX_ASSOC - do */
+static const struct nla_policy psp_rx_assoc_nl_policy[PSP_A_ASSOC_SOCK_FD + 1] = {
+	[PSP_A_ASSOC_DEV_ID] = NLA_POLICY_MIN(NLA_U32, 1),
+	[PSP_A_ASSOC_VERSION] = NLA_POLICY_MAX(NLA_U32, 3),
+	[PSP_A_ASSOC_SOCK_FD] = { .type = NLA_U32, },
+};
+
+/* PSP_CMD_TX_ASSOC - do */
+static const struct nla_policy psp_tx_assoc_nl_policy[PSP_A_ASSOC_SOCK_FD + 1] = {
+	[PSP_A_ASSOC_DEV_ID] = NLA_POLICY_MIN(NLA_U32, 1),
+	[PSP_A_ASSOC_VERSION] = NLA_POLICY_MAX(NLA_U32, 3),
+	[PSP_A_ASSOC_TX_KEY] = NLA_POLICY_NESTED(psp_keys_nl_policy),
+	[PSP_A_ASSOC_SOCK_FD] = { .type = NLA_U32, },
+};
+
 /* Ops table for psp */
 static const struct genl_split_ops psp_nl_ops[] = {
 	{
@@ -60,6 +81,24 @@ static const struct genl_split_ops psp_nl_ops[] = {
 		.maxattr	= PSP_A_DEV_ID,
 		.flags		= GENL_CMD_CAP_DO,
 	},
+	{
+		.cmd		= PSP_CMD_RX_ASSOC,
+		.pre_doit	= psp_assoc_device_get_locked,
+		.doit		= psp_nl_rx_assoc_doit,
+		.post_doit	= psp_device_unlock,
+		.policy		= psp_rx_assoc_nl_policy,
+		.maxattr	= PSP_A_ASSOC_SOCK_FD,
+		.flags		= GENL_CMD_CAP_DO,
+	},
+	{
+		.cmd		= PSP_CMD_TX_ASSOC,
+		.pre_doit	= psp_assoc_device_get_locked,
+		.doit		= psp_nl_tx_assoc_doit,
+		.post_doit	= psp_device_unlock,
+		.policy		= psp_tx_assoc_nl_policy,
+		.maxattr	= PSP_A_ASSOC_SOCK_FD,
+		.flags		= GENL_CMD_CAP_DO,
+	},
 };
 
 static const struct genl_multicast_group psp_nl_mcgrps[] = {
net/psp/psp-nl-gen.h +7 -0
index 00a2d4ec59e4..25268ed11fb5 100644
@@ -11,8 +11,13 @@
 
 #include <uapi/linux/psp.h>
 
+/* Common nested types */
+extern const struct nla_policy psp_keys_nl_policy[PSP_A_KEYS_SPI + 1];
+
 int psp_device_get_locked(const struct genl_split_ops *ops,
 			  struct sk_buff *skb, struct genl_info *info);
+int psp_assoc_device_get_locked(const struct genl_split_ops *ops,
+				struct sk_buff *skb, struct genl_info *info);
 void
 psp_device_unlock(const struct genl_split_ops *ops, struct sk_buff *skb,
 		  struct genl_info *info);
@@ -21,6 +26,8 @@ int psp_nl_dev_get_doit(struct sk_buff *skb, struct genl_info *info);
 int psp_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
 int psp_nl_dev_set_doit(struct sk_buff *skb, struct genl_info *info);
 int psp_nl_key_rotate_doit(struct sk_buff *skb, struct genl_info *info);
+int psp_nl_rx_assoc_doit(struct sk_buff *skb, struct genl_info *info);
+int psp_nl_tx_assoc_doit(struct sk_buff *skb, struct genl_info *info);
 
 enum {
 	PSP_NLGRP_MGMT,
net/psp/psp.h +22 -0
index 94d0cc31a61f..b4092936bc64 100644
@@ -4,6 +4,7 @@
 #define __PSP_PSP_H
 
 #include <linux/list.h>
+#include <linux/lockdep.h>
 #include <linux/mutex.h>
 #include <net/netns/generic.h>
 #include <net/psp.h>
@@ -17,15 +18,36 @@ int psp_dev_check_access(struct psp_dev *psd, struct net *net);
 
 void psp_nl_notify_dev(struct psp_dev *psd, u32 cmd);
 
+struct psp_assoc *psp_assoc_create(struct psp_dev *psd);
+struct psp_dev *psd_get_for_sock(struct sock *sk);
+void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas);
+int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
+			  struct psp_key_parsed *key,
+			  struct netlink_ext_ack *extack);
+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);
+
 static inline void psp_dev_get(struct psp_dev *psd)
 {
 	refcount_inc(&psd->refcnt);
 }
 
+static inline bool psp_dev_tryget(struct psp_dev *psd)
+{
+	return refcount_inc_not_zero(&psd->refcnt);
+}
+
 static inline void psp_dev_put(struct psp_dev *psd)
 {
 	if (refcount_dec_and_test(&psd->refcnt))
 		psp_dev_destroy(psd);
 }
 
+static inline bool psp_dev_is_registered(struct psp_dev *psd)
+{
+	lockdep_assert_held(&psd->lock);
+	return !!psd->ops;
+}
+
 #endif /* __PSP_PSP_H */
net/psp/psp_main.c +10 -1
index 7f1a6cda6a7a..bf1c704a1a40 100644
@@ -55,7 +55,10 @@ psp_dev_create(struct net_device *netdev,
 
 	if (WARN_ON(!psd_caps->versions ||
 		    !psd_ops->set_config ||
-		    !psd_ops->key_rotate))
+		    !psd_ops->key_rotate ||
+		    !psd_ops->rx_spi_alloc ||
+		    !psd_ops->tx_key_add ||
+		    !psd_ops->tx_key_del))
 		return ERR_PTR(-EINVAL);
 
 	psd = kzalloc(sizeof(*psd), GFP_KERNEL);
@@ -68,6 +71,7 @@ psp_dev_create(struct net_device *netdev,
 	psd->drv_priv = priv_ptr;
 
 	mutex_init(&psd->lock);
+	INIT_LIST_HEAD(&psd->active_assocs);
 	refcount_set(&psd->refcnt, 1);
 
 	mutex_lock(&psp_devs_lock);
@@ -107,6 +111,8 @@ void psp_dev_destroy(struct psp_dev *psd)
  */
 void psp_dev_unregister(struct psp_dev *psd)
 {
+	struct psp_assoc *pas, *next;
+
 	mutex_lock(&psp_devs_lock);
 	mutex_lock(&psd->lock);
 
@@ -114,6 +120,9 @@ void psp_dev_unregister(struct psp_dev *psd)
 	xa_store(&psp_devs, psd->id, NULL, GFP_KERNEL);
 	mutex_unlock(&psp_devs_lock);
 
+	list_for_each_entry_safe(pas, next, &psd->active_assocs, assocs_list)
+		psp_dev_tx_key_del(psd, pas);
+
 	rcu_assign_pointer(psd->main_netdev->psp_dev, NULL);
 
 	psd->ops = NULL;
net/psp/psp_nl.c +244 -0

256 lines not on this page · raw message

net/psp/psp_sock.c new file +276 -0

276 lines not on this page · raw message

Signature · 1 line
2.47.1
maintainer
#22 lore raw

Re: [PATCH v3 08/19] net: psp: add socket security association code

Quoted 111 lines · Daniel Zahka

From: Jakub Kicinski <[email protected]>

Add the ability to install PSP Rx and Tx crypto keys on TCP connections. Netlink ops are provided for both operations. Rx side combines allocating a new Rx key and installing it on the socket. Theoretically these are separate actions, but in practice they will always be used one after the other. We can add distinct "alloc" and "install" ops later.

---

Notes:
v3:
- lift pse/pas comparison code into new function:
psp_pse_matches_pas().
- explicitly mark rcu critical section psp_reply_set_decrypted()
- use rcu_dereference_proteced() instead of rcu_read_lock() in psp_sk_assoc_free() and psp_twsk_assoc_free()
- rename psp_is_nondata() to psp_is_allowed_nondata()
- check for sk_is_inet() before casting to inet_twsk()
- psp_reply_set_decrypted() should not call psp_sk_assoc()
- lift common code into psp_sk_get_assoc_rcu()
- Fix exports with EXPORT_IPV6_MOD_GPL()

v2:
- add pas->dev_id == pse->dev_id to policy checks
- __psp_sk_rx_policy_check() now allows pure ACKs, FINs, and RSTs to be non-psp authenticated before "PSP Full" state.
- assign tw_validate_skb funtion during psp_twsk_init()
- psp_skb_get_rcu() also checks if sk is a tcp timewait sock when looking for psp assocs.
- scan ofo queue non-psp data during psp_sock_recv_queue_check()
- add tcp_write_collapse_fence() to psp_sock_assoc_set_tx() v1:
- https://lore.kernel.org/netdev/[email protected]/

 Documentation/netlink/specs/psp.yaml |  71 +++++++
 include/net/psp/functions.h          | 113 +++++++++--
 include/net/psp/types.h              |  58 ++++++
 include/uapi/linux/psp.h             |  21 ++
 net/psp/Kconfig                      |   1 +
 net/psp/Makefile                     |   2 +-
 net/psp/psp-nl-gen.c                 |  39 ++++
 net/psp/psp-nl-gen.h                 |   7 +
 net/psp/psp.h                        |  22 +++
 net/psp/psp_main.c                   |  11 +-
 net/psp/psp_nl.c                     | 244 +++++++++++++++++++++++
 net/psp/psp_sock.c                   | 276 +++++++++++++++++++++++++++
 12 files changed, 852 insertions(+), 13 deletions(-)
 create mode 100644 net/psp/psp_sock.c
Documentation/netlink/specs/psp.yaml +42 -0
index 054cc02b65ad..57b24cd6f3f1 100644
@@ -38,6 +38,44 @@ attribute-sets:
         type: u32
         enum: version
         enum-as-flags: true
+  -
+    name: assoc
+    attributes:
+      -
+        name: dev-id
+        doc: PSP device ID.
+        type: u32
+        checks:
+          min: 1
+      -
+        name: version
+        doc: |
+          PSP versions (AEAD and protocol version) used by this association,
+          dictates the size of the key.
+        type: u32
+        enum: version
+      -
+        name: rx-key
+        type: nest
+        nested-attributes: keys
+      -
+        name: tx-key
+        type: nest
+        nested-attributes: keys
+      -
+        name: sock-fd
+        doc: Sockets which should be bound to the association immediately.
+        type: u32
+  -
+    name: keys
+    attributes:
+      -
+        name: key
+        type: binary
+      -
+        name: spi
+        doc: Security Parameters Index (SPI) of the association.
+        type: u32
 
 operations:
   list:
@@ -107,6 +145,39 @@ operations:
       notify: key-rotate
       mcgrp: use
 
+    -
+      name: rx-assoc
+      doc: Allocate a new Rx key + SPI pair, associate it with a socket.
+      attribute-set: assoc

Documentation/netlink/specs/psp.yaml operations: · line 161

Quoted 10 lines
Documentation/netlink/specs/psp.yaml +10 -0
+      do:
+        request:
+          attributes:
+            - dev-id
+            - version
+            - sock-fd
+        reply:
+          attributes:
+            - dev-id
+            - version

Why return the same values as passed in the request?

Documentation/netlink/specs/psp.yaml operations: · line 173

Quoted 12 lines
Documentation/netlink/specs/psp.yaml +12 -0
+            - rx-key
+        pre: psp-assoc-device-get-locked
+        post: psp-device-unlock
+    -
+      name: tx-assoc
+      doc: Add a PSP Tx association.
+      attribute-set: assoc
+      do:
+        request:
+          attributes:
+            - dev-id
+            - version

Version must be the same for rx and tx alloc. It is already set for rx, so no need to pass explicitly. Just adds the need to for a sanity check in the handler.

Quoted 8 lines
Documentation/netlink/specs/psp.yaml +7 -0
+            - tx-key
+            - sock-fd
+        reply:
+          attributes: []
+        pre: psp-assoc-device-get-locked
+        post: psp-device-unlock
+
 mcast-groups:

Documentation/netlink/specs/psp.yaml operations:

Quoted 10 lines
Documentation/netlink/specs/psp.yaml +7 -0
   list:
     -
 
+static inline bool
+psp_pse_matches_pas(struct psp_skb_ext *pse, struct psp_assoc *pas)
+{
+	return pse && pas->rx.spi == pse->spi &&
+	       pas->generation == pse->generation &&
+	       pas->version == pse->version &&
+	       pas->dev_id == pse->dev_id;

Since struct psp_skb_ext is 64 bits, could almost implement this as a single 64-bit match. The only outlier is spi, which is rx.spi.

Which also indicates that this is psp_pse_matches_pas_rx.

Still, the other three fields could be a single 32b comparison. Not sure if worth the effort (using a union or cast, say).

Documentation/netlink/specs/psp.yaml

Quoted 7 lines
Documentation/netlink/specs/psp.yaml +7 -0
+struct psp_assoc {
+	struct psp_dev *psd;
+
+	u16 dev_id;
+	u8 generation;
+	u8 version;
+	u8 key_sz;

implied by version?

Quoted 28 lines
Documentation/netlink/specs/psp.yaml +27 -0
+	u8 peer_tx;
+
+	u32 upgrade_seq;
+
+	struct psp_key_parsed tx;
+	struct psp_key_parsed rx;
+
+	refcount_t refcnt;
+	struct rcu_head rcu;
+	struct work_struct work;
+	struct list_head assocs_list;
+
+	u8 drv_data[] __aligned(8);
+};
+
 
+int psp_assoc_device_get_locked(const struct genl_split_ops *ops,
+				struct sk_buff *skb, struct genl_info *info)
+{
+	struct socket *socket;
+	struct psp_dev *psd;
+	struct nlattr *id;
+	struct sock *sk;
+	int fd, err;
+
+	if (GENL_REQ_ATTR_CHECK(info, PSP_A_ASSOC_SOCK_FD))
+		return -EINVAL;
+

Documentation/netlink/specs/psp.yaml

Quoted 10 lines
Documentation/netlink/specs/psp.yaml +10 -0
+	fd = nla_get_u32(info->attrs[PSP_A_ASSOC_SOCK_FD]);
+	socket = sockfd_lookup(fd, &err);
+	if (!socket)
+		return err;
+
+	sk = socket->sk;
+	if (sk->sk_family != AF_INET && sk->sk_family != AF_INET6) {
+		NL_SET_ERR_MSG_ATTR(info->extack,
+				    info->attrs[PSP_A_ASSOC_SOCK_FD],
+				    "Unsupported socket family");

Should this also check sk_type?

Documentation/netlink/specs/psp.yaml

Quoted 2 lines
Documentation/netlink/specs/psp.yaml +2 -0
+
+struct psp_dev *psd_get_for_sock(struct sock *sk)

Same as other support functions, consider spelling it out fully as psp_dev_get_for_sock.

Quoted 20 lines
Documentation/netlink/specs/psp.yaml +19 -0
+{
+	struct dst_entry *dst;
+	struct psp_dev *psd;
+
+	dst = sk_dst_get(sk);
+	if (!dst)
+		return NULL;
+
+	rcu_read_lock();
+	psd = rcu_dereference(dst->dev->psp_dev);
+	if (psd && !psp_dev_tryget(psd))
+		psd = NULL;
+	rcu_read_unlock();
+
+	dst_release(dst);
+
+	return psd;
+}
 
+void psp_reply_set_decrypted(struct sk_buff *skb)

Documentation/netlink/specs/psp.yaml

Quoted 10 lines
Documentation/netlink/specs/psp.yaml +10 -0
+{
+	struct psp_assoc *pas;
+
+	rcu_read_lock();
+	pas = psp_sk_get_assoc_rcu(skb->sk);
+	if (pas && pas->tx.spi)
+		skb->decrypted = 1;
+	rcu_read_unlock();
+}
+EXPORT_IPV6_MOD_GPL(psp_reply_set_decrypted)

semicolon

Quoted 3 lines
Signature · 1 line
2.47.1
maintainer
#23 lore raw

Re: [PATCH v3 08/19] net: psp: add socket security association code

Quoted 13 lines · On Sun, 06 Jul 2025 12:47:16 -0400 Willem de Bruijn wrote:

Documentation/netlink/specs/psp.yaml operations: · line 173

Quoted 12 lines
Documentation/netlink/specs/psp.yaml +12 -0
+            - rx-key
+        pre: psp-assoc-device-get-locked
+        post: psp-device-unlock
+    -
+      name: tx-assoc
+      doc: Add a PSP Tx association.
+      attribute-set: assoc
+      do:
+        request:
+          attributes:
+            - dev-id
+            - version  
Quoted 3 lines

Version must be the same for rx and tx alloc. It is already set for rx, so no need to pass explicitly. Just adds the need to for a sanity check in the handler.

I think because version implies the key size. No strong preference but without the version it's harder to split the request processing into pure parsing and operating on kernel objects (under relevant locks).

author maintainer
#24 lore raw

Re: [PATCH v3 08/19] net: psp: add socket security association code

In reply to Willem de Bruijn
Quoted 14 lines · Willem de Bruijn
Quoted 4 lines
Documentation/netlink/specs/psp.yaml +4 -0
+    -
+      name: rx-assoc
+      doc: Allocate a new Rx key + SPI pair, associate it with a socket.
+      attribute-set: assoc

Documentation/netlink/specs/psp.yaml operations: · line 161

Quoted 10 lines
Documentation/netlink/specs/psp.yaml +10 -0
+      do:
+        request:
+          attributes:
+            - dev-id
+            - version
+            - sock-fd
+        reply:
+          attributes:
+            - dev-id
+            - version
Quoted 1 line

Why return the same values as passed in the request?

version provides no information to the caller here because it is echoed back from the request. I will eliminate it in the next version. dev-id is optional in the request and looked up based on sk_dst_get() if not provided, so it does provide information to the caller. This socket to device mapping will probably be needed to respond to key rotation notifications, so I think keeping it around makes sense.

maintainer
#25 lore raw

Re: [PATCH v3 08/19] net: psp: add socket security association code

In reply to Daniel Zahka
Quoted 1 line · On Wed, 2 Jul 2025 10:13:13 -0700 Daniel Zahka wrote:

+EXPORT_IPV6_MOD_GPL(psp_reply_set_decrypted)

Please make sure it passes an allmodconfig build

Signature · 1 line
pw-bot: cr
author maintainer
#26 lore raw

PATCH v3 9/19 net: psp: update the TCP MSS to reflect PSP packet overhead

In reply to Daniel Zahka

From: Jakub Kicinski <[email protected]>

PSP eats 32B of header space. Adjust MSS appropriately.

We can either modify tcp_mtu_to_mss() / tcp_mss_to_mtu() or reuse icsk_ext_hdr_len. The former option is more TCP specific and has runtime overhead. The latter is a bit of a hack as PSP is not an ext_hdr. If one squints hard enough, UDP encap is just a more practical version of IPv6 exthdr, so go with the latter. Happy to change.

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 include/net/psp/functions.h | 12 ++++++++++++
 include/net/psp/types.h     |  3 +++
 net/ipv4/tcp_ipv4.c         |  4 ++--
 net/ipv6/ipv6_sockglue.c    |  6 +++++-
 net/ipv6/tcp_ipv6.c         |  6 +++---
 net/psp/psp_sock.c          |  5 +++++
 6 files changed, 30 insertions(+), 6 deletions(-)
include/net/psp/functions.h +12 -0
index 442fed11ebe4..1b414692504b 100644
@@ -138,6 +138,13 @@ static inline struct psp_assoc *psp_skb_get_assoc_rcu(struct sk_buff *skb)
 
 	return psp_sk_get_assoc_rcu(skb->sk);
 }
+
+static inline unsigned int psp_sk_overhead(const struct sock *sk)
+{
+	bool has_psp = rcu_access_pointer(sk->psp_assoc);
+
+	return has_psp ? PSP_HDR_SIZE + PSP_TRL_SIZE : 0;
+}
 #else
 static inline void psp_sk_assoc_free(struct sock *sk) { }
 static inline void
@@ -177,6 +184,11 @@ static inline struct psp_assoc *psp_skb_get_assoc_rcu(struct sk_buff *skb)
 {
 	return NULL;
 }
+
+static inline unsigned int psp_sk_overhead(const struct sock *sk)
+{
+	return 0;
+}
 #endif
 
 static inline unsigned long
include/net/psp/types.h +3 -0
index 3b7b977e62a3..5b0c2474a042 100644
@@ -95,6 +95,9 @@ struct psp_dev_caps {
 #define PSP_V1_KEY	32
 #define PSP_MAX_KEY	32
 
+#define PSP_HDR_SIZE	16	/* We don't support optional fields, yet */
+#define PSP_TRL_SIZE	16	/* AES-GCM/GMAC trailer size */
+
 struct psp_skb_ext {
 	__be32 spi;
 	u16 dev_id;
net/ipv4/tcp_ipv4.c +2 -2
index 0f290e6dca2b..6286cf31a3ed 100644
@@ -291,9 +291,9 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
 	inet->inet_dport = usin->sin_port;
 	sk_daddr_set(sk, daddr);
 
-	inet_csk(sk)->icsk_ext_hdr_len = 0;
+	inet_csk(sk)->icsk_ext_hdr_len = psp_sk_overhead(sk);
 	if (inet_opt)
-		inet_csk(sk)->icsk_ext_hdr_len = inet_opt->opt.optlen;
+		inet_csk(sk)->icsk_ext_hdr_len += inet_opt->opt.optlen;
 
 	tp->rx_opt.mss_clamp = TCP_MSS_DEFAULT;
 
net/ipv6/ipv6_sockglue.c +5 -1
index 1e225e6489ea..94b9ffd35e80 100644
@@ -49,6 +49,7 @@
 #include <net/xfrm.h>
 #include <net/compat.h>
 #include <net/seg6.h>
+#include <net/psp.h>
 
 #include <linux/uaccess.h>
 
@@ -107,7 +108,10 @@ struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
 		    !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
 		    inet_sk(sk)->inet_daddr != LOOPBACK4_IPV6) {
 			struct inet_connection_sock *icsk = inet_csk(sk);
-			icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen;
+
+			icsk->icsk_ext_hdr_len =
+				psp_sk_overhead(sk) +
+				opt->opt_flen + opt->opt_nflen;
 			icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
 		}
 	}
net/ipv6/tcp_ipv6.c +3 -3
index b1ab44ddb487..c34f7266457f 100644
@@ -301,10 +301,10 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
 	sk->sk_gso_type = SKB_GSO_TCPV6;
 	ip6_dst_store(sk, dst, NULL, NULL);
 
-	icsk->icsk_ext_hdr_len = 0;
+	icsk->icsk_ext_hdr_len = psp_sk_overhead(sk);
 	if (opt)
-		icsk->icsk_ext_hdr_len = opt->opt_flen +
-					 opt->opt_nflen;
+		icsk->icsk_ext_hdr_len += opt->opt_flen +
+					  opt->opt_nflen;
 
 	tp->rx_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr);
 
net/psp/psp_sock.c +5 -0
index 9fa20bcc5e30..f97441935d12 100644
@@ -180,6 +180,7 @@ 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;
 	int err;
 
@@ -231,6 +232,10 @@ int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,
 	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);
 exit_unlock:
Signature · 1 line
2.47.1
maintainer
#27 lore raw

Re: [PATCH v3 09/19] net: psp: update the TCP MSS to reflect PSP packet overhead

Quoted 29 lines · Daniel Zahka

From: Jakub Kicinski <[email protected]>

PSP eats 32B of header space. Adjust MSS appropriately.

We can either modify tcp_mtu_to_mss() / tcp_mss_to_mtu() or reuse icsk_ext_hdr_len. The former option is more TCP specific and has runtime overhead. The latter is a bit of a hack as PSP is not an ext_hdr. If one squints hard enough, UDP encap is just a more practical version of IPv6 exthdr, so go with the latter. Happy to change.

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 include/net/psp/functions.h | 12 ++++++++++++
 include/net/psp/types.h     |  3 +++
 net/ipv4/tcp_ipv4.c         |  4 ++--
 net/ipv6/ipv6_sockglue.c    |  6 +++++-
 net/ipv6/tcp_ipv6.c         |  6 +++---
 net/psp/psp_sock.c          |  5 +++++
 6 files changed, 30 insertions(+), 6 deletions(-)

include/net/psp/types.h struct psp_dev_caps { · line 98

Quoted 4 lines
include/net/psp/types.h +1 -0
@@ -95,6 +95,9 @@ struct psp_dev_caps {
 #define PSP_V1_KEY	32
 #define PSP_MAX_KEY	32
 
+#define PSP_HDR_SIZE	16	/* We don't support optional fields, yet */

Duplicate of PSP_HDRLEN_NOOPT?

Quoted 5 lines
include/net/psp/types.h +2 -0
+#define PSP_TRL_SIZE	16	/* AES-GCM/GMAC trailer size */
+
 struct psp_skb_ext {
 	__be32 spi;
 	u16 dev_id;
maintainer
#28 lore raw

Re: [PATCH v3 09/19] net: psp: update the TCP MSS to reflect PSP packet overhead

Quoted 29 lines · Willem de Bruijn
Quoted 27 lines · Daniel Zahka

From: Jakub Kicinski <[email protected]>

PSP eats 32B of header space. Adjust MSS appropriately.

We can either modify tcp_mtu_to_mss() / tcp_mss_to_mtu() or reuse icsk_ext_hdr_len. The former option is more TCP specific and has runtime overhead. The latter is a bit of a hack as PSP is not an ext_hdr. If one squints hard enough, UDP encap is just a more practical version of IPv6 exthdr, so go with the latter. Happy to change.

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 include/net/psp/functions.h | 12 ++++++++++++
 include/net/psp/types.h     |  3 +++
 net/ipv4/tcp_ipv4.c         |  4 ++--
 net/ipv6/ipv6_sockglue.c    |  6 +++++-
 net/ipv6/tcp_ipv6.c         |  6 +++---
 net/psp/psp_sock.c          |  5 +++++
 6 files changed, 30 insertions(+), 6 deletions(-)
Quoted 7 lines

include/net/psp/types.h struct psp_dev_caps { · line 98

Quoted 5 lines
include/net/psp/types.h +1 -0
@@ -95,6 +95,9 @@ struct psp_dev_caps {
 #define PSP_V1_KEY	32
 #define PSP_MAX_KEY	32
 
+#define PSP_HDR_SIZE	16	/* We don't support optional fields, yet */

Duplicate of PSP_HDRLEN_NOOPT?

Oh no it is not: that is the length in 64b words.

author maintainer
#29 lore raw

PATCH v3 10/19 psp: track generations of device key

In reply to Daniel Zahka

From: Jakub Kicinski <[email protected]>

There is a (somewhat theoretical in absence of multi-host support) possibility that another entity will rotate the key and we won't know. This may lead to accepting packets with matching SPI but which used different crypto keys than we expected. Maintain and compare "key generation" per PSP spec.

Since we're tracking "key generations" more explicitly now, maintain different lists for associations from different generations. This way we can catch stale associations (the user space should listen to rotation notifications and change the keys).

Drivers can "opt out" of generation tracking by setting the generation value to 0.

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 include/net/psp/types.h | 10 ++++++++++
 net/psp/psp.h           |  1 +
 net/psp/psp_main.c      |  6 +++++-
 net/psp/psp_nl.c        | 10 ++++++++++
 net/psp/psp_sock.c      | 16 ++++++++++++++++
 5 files changed, 42 insertions(+), 1 deletion(-)
include/net/psp/types.h +10 -0
index 5b0c2474a042..383a1afab46d 100644
@@ -50,8 +50,12 @@ struct psp_dev_config {
  * @lock:	instance lock, protects all fields
  * @refcnt:	reference count for the instance
  * @id:		instance id
+ * @generation:	current generation of the device key
  * @config:	current device configuration
  * @active_assocs:	list of registered associations
+ * @prev_assocs:	associations which use old (but still usable)
+ *			device key
+ * @stale_assocs:	associations which use a rotated out key
  *
  * @rcu:	RCU head for freeing the structure
  */
@@ -67,13 +71,19 @@ struct psp_dev {
 
 	u32 id;
 
+	u8 generation;
+
 	struct psp_dev_config config;
 
 	struct list_head active_assocs;
+	struct list_head prev_assocs;
+	struct list_head stale_assocs;
 
 	struct rcu_head rcu;
 };
 
+#define PSP_GEN_VALID_MASK	0x7f
+
 /**
  * struct psp_dev_caps - PSP device capabilities
  */
net/psp/psp.h +1 -0
index b4092936bc64..a511ec85e1c7 100644
@@ -27,6 +27,7 @@ int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
 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);
+void psp_assocs_key_rotated(struct psp_dev *psd);
 
 static inline void psp_dev_get(struct psp_dev *psd)
 {
net/psp/psp_main.c +5 -1
index bf1c704a1a40..99facb158abb 100644
@@ -72,6 +72,8 @@ psp_dev_create(struct net_device *netdev,
 
 	mutex_init(&psd->lock);
 	INIT_LIST_HEAD(&psd->active_assocs);
+	INIT_LIST_HEAD(&psd->prev_assocs);
+	INIT_LIST_HEAD(&psd->stale_assocs);
 	refcount_set(&psd->refcnt, 1);
 
 	mutex_lock(&psp_devs_lock);
@@ -120,7 +122,9 @@ void psp_dev_unregister(struct psp_dev *psd)
 	xa_store(&psp_devs, psd->id, NULL, GFP_KERNEL);
 	mutex_unlock(&psp_devs_lock);
 
-	list_for_each_entry_safe(pas, next, &psd->active_assocs, assocs_list)
+	list_splice_init(&psd->active_assocs, &psd->prev_assocs);
+	list_splice_init(&psd->prev_assocs, &psd->stale_assocs);
+	list_for_each_entry_safe(pas, next, &psd->stale_assocs, assocs_list)
 		psp_dev_tx_key_del(psd, pas);
 
 	rcu_assign_pointer(psd->main_netdev->psp_dev, NULL);
net/psp/psp_nl.c +10 -0
index 58508e642185..7b8a1d390cde 100644
@@ -230,6 +230,7 @@ int psp_nl_key_rotate_doit(struct sk_buff *skb, struct genl_info *info)
 	struct psp_dev *psd = info->user_ptr[0];
 	struct genl_info ntf_info;
 	struct sk_buff *ntf, *rsp;
+	u8 prev_gen;
 	int err;
 
 	rsp = psp_nl_reply_new(info);
@@ -249,10 +250,19 @@ int psp_nl_key_rotate_doit(struct sk_buff *skb, struct genl_info *info)
 		goto err_free_ntf;
 	}
 
+	/* suggest the next gen number, driver can override */
+	prev_gen = psd->generation;
+	psd->generation = (prev_gen + 1) & PSP_GEN_VALID_MASK;
+
 	err = psd->ops->key_rotate(psd, info->extack);
 	if (err)
 		goto err_free_ntf;
 
+	WARN_ON_ONCE((psd->generation && psd->generation == prev_gen) ||
+		     psd->generation & ~PSP_GEN_VALID_MASK);
+
+	psp_assocs_key_rotated(psd);
+
 	nlmsg_end(ntf, (struct nlmsghdr *)ntf->data);
 	genlmsg_multicast_netns(&psp_nl_family, dev_net(psd->main_netdev), ntf,
 				0, PSP_NLGRP_USE, GFP_KERNEL);
net/psp/psp_sock.c +16 -0
index f97441935d12..8b5cb31c2836 100644
@@ -60,6 +60,7 @@ struct psp_assoc *psp_assoc_create(struct psp_dev *psd)
 
 	pas->psd = psd;
 	pas->dev_id = psd->id;
+	pas->generation = psd->generation;
 	psp_dev_get(psd);
 	refcount_set(&pas->refcnt, 1);
 
@@ -243,6 +244,21 @@ int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,
 	return err;
 }
 
+void psp_assocs_key_rotated(struct psp_dev *psd)
+{
+	struct psp_assoc *pas, *next;
+
+	/* Mark the stale associations as invalid, they will no longer
+	 * be able to Rx any traffic.
+	 */
+	list_for_each_entry_safe(pas, next, &psd->prev_assocs, assocs_list)
+		pas->generation |= ~PSP_GEN_VALID_MASK;
+	list_splice_init(&psd->prev_assocs, &psd->stale_assocs);
+	list_splice_init(&psd->active_assocs, &psd->prev_assocs);
+
+	/* TODO: we should inform the sockets that got shut down */
+}
+
 void psp_twsk_init(struct inet_timewait_sock *tw, struct sock *sk)
 {
 	struct psp_assoc *pas = psp_sk_assoc(sk);
Signature · 1 line
2.47.1
maintainer
#30 lore raw

Re: [PATCH v3 10/19] psp: track generations of device key

Quoted 6 lines · Daniel Zahka

From: Jakub Kicinski <[email protected]>

There is a (somewhat theoretical in absence of multi-host support) possibility that another entity will rotate the key and we won't know. This may lead to accepting packets with matching SPI but which used different crypto keys than we expected.

The device would not have decrypted those? As it only has two keys, one for each MSB of the SPI.

Except for a narrow window during rotation, where a key for generation N is decrypted and queued to the host, then a rotation happens, so that the host updates its valid keys to { N+1, N+2 }. These will now get dropped. That is not strictly necessary.

Quoted 2 lines

Maintain and
compare "key generation" per PSP spec.

Where does the spec state this?

I know this generation bit is present in the Google PSP implementation, I'm just right now drawing a blank as to its exact purpose -- and whether the above explanation matches that.

Quoted 165 lines

Since we're tracking "key generations" more explicitly now, maintain different lists for associations from different generations. This way we can catch stale associations (the user space should listen to rotation notifications and change the keys).

Drivers can "opt out" of generation tracking by setting the generation value to 0.

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 include/net/psp/types.h | 10 ++++++++++
 net/psp/psp.h           |  1 +
 net/psp/psp_main.c      |  6 +++++-
 net/psp/psp_nl.c        | 10 ++++++++++
 net/psp/psp_sock.c      | 16 ++++++++++++++++
 5 files changed, 42 insertions(+), 1 deletion(-)
include/net/psp/types.h +10 -0
index 5b0c2474a042..383a1afab46d 100644
@@ -50,8 +50,12 @@ struct psp_dev_config {
  * @lock:	instance lock, protects all fields
  * @refcnt:	reference count for the instance
  * @id:		instance id
+ * @generation:	current generation of the device key
  * @config:	current device configuration
  * @active_assocs:	list of registered associations
+ * @prev_assocs:	associations which use old (but still usable)
+ *			device key
+ * @stale_assocs:	associations which use a rotated out key
  *
  * @rcu:	RCU head for freeing the structure
  */
@@ -67,13 +71,19 @@ struct psp_dev {
 
 	u32 id;
 
+	u8 generation;
+
 	struct psp_dev_config config;
 
 	struct list_head active_assocs;
+	struct list_head prev_assocs;
+	struct list_head stale_assocs;
 
 	struct rcu_head rcu;
 };
 
+#define PSP_GEN_VALID_MASK	0x7f
+
 /**
  * struct psp_dev_caps - PSP device capabilities
  */
net/psp/psp.h +1 -0
index b4092936bc64..a511ec85e1c7 100644
@@ -27,6 +27,7 @@ int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
 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);
+void psp_assocs_key_rotated(struct psp_dev *psd);
 
 static inline void psp_dev_get(struct psp_dev *psd)
 {
net/psp/psp_main.c +5 -1
index bf1c704a1a40..99facb158abb 100644
@@ -72,6 +72,8 @@ psp_dev_create(struct net_device *netdev,
 
 	mutex_init(&psd->lock);
 	INIT_LIST_HEAD(&psd->active_assocs);
+	INIT_LIST_HEAD(&psd->prev_assocs);
+	INIT_LIST_HEAD(&psd->stale_assocs);
 	refcount_set(&psd->refcnt, 1);
 
 	mutex_lock(&psp_devs_lock);
@@ -120,7 +122,9 @@ void psp_dev_unregister(struct psp_dev *psd)
 	xa_store(&psp_devs, psd->id, NULL, GFP_KERNEL);
 	mutex_unlock(&psp_devs_lock);
 
-	list_for_each_entry_safe(pas, next, &psd->active_assocs, assocs_list)
+	list_splice_init(&psd->active_assocs, &psd->prev_assocs);
+	list_splice_init(&psd->prev_assocs, &psd->stale_assocs);
+	list_for_each_entry_safe(pas, next, &psd->stale_assocs, assocs_list)
 		psp_dev_tx_key_del(psd, pas);
 
 	rcu_assign_pointer(psd->main_netdev->psp_dev, NULL);
net/psp/psp_nl.c +10 -0
index 58508e642185..7b8a1d390cde 100644
@@ -230,6 +230,7 @@ int psp_nl_key_rotate_doit(struct sk_buff *skb, struct genl_info *info)
 	struct psp_dev *psd = info->user_ptr[0];
 	struct genl_info ntf_info;
 	struct sk_buff *ntf, *rsp;
+	u8 prev_gen;
 	int err;
 
 	rsp = psp_nl_reply_new(info);
@@ -249,10 +250,19 @@ int psp_nl_key_rotate_doit(struct sk_buff *skb, struct genl_info *info)
 		goto err_free_ntf;
 	}
 
+	/* suggest the next gen number, driver can override */
+	prev_gen = psd->generation;
+	psd->generation = (prev_gen + 1) & PSP_GEN_VALID_MASK;
+
 	err = psd->ops->key_rotate(psd, info->extack);
 	if (err)
 		goto err_free_ntf;
 
+	WARN_ON_ONCE((psd->generation && psd->generation == prev_gen) ||
+		     psd->generation & ~PSP_GEN_VALID_MASK);
+
+	psp_assocs_key_rotated(psd);
+
 	nlmsg_end(ntf, (struct nlmsghdr *)ntf->data);
 	genlmsg_multicast_netns(&psp_nl_family, dev_net(psd->main_netdev), ntf,
 				0, PSP_NLGRP_USE, GFP_KERNEL);
net/psp/psp_sock.c +16 -0
index f97441935d12..8b5cb31c2836 100644
@@ -60,6 +60,7 @@ struct psp_assoc *psp_assoc_create(struct psp_dev *psd)
 
 	pas->psd = psd;
 	pas->dev_id = psd->id;
+	pas->generation = psd->generation;
 	psp_dev_get(psd);
 	refcount_set(&pas->refcnt, 1);
 
@@ -243,6 +244,21 @@ int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,
 	return err;
 }
 
+void psp_assocs_key_rotated(struct psp_dev *psd)
+{
+	struct psp_assoc *pas, *next;
+
+	/* Mark the stale associations as invalid, they will no longer
+	 * be able to Rx any traffic.
+	 */
+	list_for_each_entry_safe(pas, next, &psd->prev_assocs, assocs_list)
+		pas->generation |= ~PSP_GEN_VALID_MASK;
+	list_splice_init(&psd->prev_assocs, &psd->stale_assocs);
+	list_splice_init(&psd->active_assocs, &psd->prev_assocs);
+
+	/* TODO: we should inform the sockets that got shut down */
+}
+
 void psp_twsk_init(struct inet_timewait_sock *tw, struct sock *sk)
 {
 	struct psp_assoc *pas = psp_sk_assoc(sk);
Signature · 1 line
2.47.1
maintainer
#31 lore raw

Re: [PATCH v3 10/19] psp: track generations of device key

Quoted 5 lines · On Sun, 06 Jul 2025 12:56:37 -0400 Willem de Bruijn wrote:
Quoted 4 lines

There is a (somewhat theoretical in absence of multi-host support) possibility that another entity will rotate the key and we won't know. This may lead to accepting packets with matching SPI but which used different crypto keys than we expected.

Quoted 7 lines

The device would not have decrypted those? As it only has two keys, one for each MSB of the SPI.

Except for a narrow window during rotation, where a key for generation N is decrypted and queued to the host, then a rotation happens, so that the host updates its valid keys to { N+1, N+2 }. These will now get dropped. That is not strictly necessary.

Yes, it's optional to avoid any races.

Quoted 7 lines
Quoted 1 line

Maintain and compare "key generation" per PSP spec.

Where does the spec state this?

I know this generation bit is present in the Google PSP implementation, I'm just right now drawing a blank as to its exact purpose -- and whether the above explanation matches that.

I think this:

Cryptography and key management status:
● Key generation (a counter incremented each time a master key
rotation occurs), when master keys are managed on the NIC.

maintainer
#32 lore raw

Re: [PATCH v3 10/19] psp: track generations of device key

Quoted 9 lines · Jakub Kicinski
Quoted 8 lines · On Sun, 06 Jul 2025 12:56:37 -0400 Willem de Bruijn wrote:
Quoted 4 lines

There is a (somewhat theoretical in absence of multi-host support) possibility that another entity will rotate the key and we won't know. This may lead to accepting packets with matching SPI but which used different crypto keys than we expected.

The device would not have decrypted those? As it only has two keys, one for each MSB of the SPI.

Quoted 6 lines
Quoted 4 lines

Except for a narrow window during rotation, where a key for generation N is decrypted and queued to the host, then a rotation happens, so that the host updates its valid keys to { N+1, N+2 }. These will now get dropped. That is not strictly necessary.

Yes, it's optional to avoid any races.

Ok. I think on respin the commit can be revised a bit to make clearer that it is an optional good, no packets will accidentally be accepted with matching SPI but wrong key.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Maintain and compare "key generation" per PSP spec.

Where does the spec state this?

I know this generation bit is present in the Google PSP implementation, I'm just right now drawing a blank as to its exact purpose -- and whether the above explanation matches that.

Quoted 5 lines

I think this:

Cryptography and key management status:
● Key generation (a counter incremented each time a master key
rotation occurs), when master keys are managed on the NIC.

Ack. I saw that too. Unfortunately it has explanation why it's there.

author maintainer
#33 lore raw

PATCH v3 11/19 net/mlx5e: Support PSP offload functionality

In reply to Daniel Zahka

From: Raed Salem <[email protected]>

Add PSP offload related IFC structs, layouts, and enumerations. Implement .set_config and .rx_spi_alloc PSP device operations. Driver does not need to make use of the .set_config operation. Stub .assoc_add and .assoc_del PSP operations.

Introduce the MLX5_EN_PSP configuration option for enabling PSP offload support on mlx5 devices.

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 .../net/ethernet/mellanox/mlx5/core/Kconfig   |  11 ++
 .../net/ethernet/mellanox/mlx5/core/Makefile  |   4 +-
 drivers/net/ethernet/mellanox/mlx5/core/en.h  |   3 +
 .../ethernet/mellanox/mlx5/core/en/params.c   |   4 +-
 .../mellanox/mlx5/core/en_accel/psp.c         | 149 ++++++++++++++++++
 .../mellanox/mlx5/core/en_accel/psp.h         |  53 +++++++
 .../mellanox/mlx5/core/en_accel/psp_offload.c |  52 ++++++
 .../net/ethernet/mellanox/mlx5/core/en_main.c |   9 ++
 drivers/net/ethernet/mellanox/mlx5/core/fw.c  |   6 +
 .../net/ethernet/mellanox/mlx5/core/main.c    |   5 +
 drivers/net/ethernet/mellanox/mlx5/core/psp.c |  24 +++
 drivers/net/ethernet/mellanox/mlx5/core/psp.h |  15 ++
 include/linux/mlx5/device.h                   |   4 +
 include/linux/mlx5/driver.h                   |   2 +
 include/linux/mlx5/mlx5_ifc.h                 |  94 ++++++++++-
 15 files changed, 428 insertions(+), 7 deletions(-)
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_offload.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/psp.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/psp.h
drivers/net/ethernet/mellanox/mlx5/core/Kconfig +11 -0
index 6ec7d6e0181d..79a64489da89 100644
@@ -208,3 +208,14 @@ config MLX5_DPLL
 	help
 	  DPLL support in Mellanox Technologies ConnectX NICs.
 
+config MLX5_EN_PSP
+	bool "Mellanox Technologies support for PSP cryptography-offload acceleration"
+	depends on INET_PSP
+	depends on MLX5_CORE_EN
+	default y
+	help
+	  mlx5 device offload support for Google PSP Security Protocol offload.
+	  Adds support for PSP encryption offload and for SPI and key generation
+	  interfaces to PSP Stack which supports PSP crypto offload.
+
+	  If unsure, say Y.
drivers/net/ethernet/mellanox/mlx5/core/Makefile +3 -1
index d292e6a9e22c..e27de74ef028 100644
@@ -17,7 +17,7 @@ mlx5_core-y :=	main.o cmd.o debugfs.o fw.o eq.o uar.o pagealloc.o \
 		fs_counters.o fs_ft_pool.o rl.o lag/debugfs.o lag/lag.o dev.o events.o wq.o lib/gid.o \
 		lib/devcom.o lib/pci_vsc.o lib/dm.o lib/fs_ttc.o diag/fs_tracepoint.o \
 		diag/fw_tracer.o diag/crdump.o devlink.o diag/rsc_dump.o diag/reporter_vnic.o \
-		fw_reset.o qos.o lib/tout.o lib/aso.o wc.o fs_pool.o
+		fw_reset.o qos.o lib/tout.o lib/aso.o wc.o fs_pool.o psp.o
 
 #
 # Netdev basic
@@ -110,6 +110,8 @@ mlx5_core-$(CONFIG_MLX5_EN_TLS) += en_accel/ktls_stats.o \
 				   en_accel/fs_tcp.o en_accel/ktls.o en_accel/ktls_txrx.o \
 				   en_accel/ktls_tx.o en_accel/ktls_rx.o
 
+mlx5_core-$(CONFIG_MLX5_EN_PSP) += en_accel/psp.o en_accel/psp_offload.o
+
 #
 # SW Steering
 #
drivers/net/ethernet/mellanox/mlx5/core/en.h +3 -0
index 65a73913b9a2..9078becfd710 100644
@@ -934,6 +934,9 @@ struct mlx5e_priv {
 #ifdef CONFIG_MLX5_EN_IPSEC
 	struct mlx5e_ipsec        *ipsec;
 #endif
+#ifdef CONFIG_MLX5_EN_PSP
+	struct mlx5e_psp          *psp;
+#endif
 #ifdef CONFIG_MLX5_EN_TLS
 	struct mlx5e_tls          *tls;
 #endif
drivers/net/ethernet/mellanox/mlx5/core/en/params.c +3 -1
index fc945bce933a..68970f96fc7c 100644
@@ -6,6 +6,7 @@
 #include "en/port.h"
 #include "en_accel/en_accel.h"
 #include "en_accel/ipsec.h"
+#include "en_accel/psp.h"
 #include <linux/dim.h>
 #include <net/page_pool/types.h>
 #include <net/xdp_sock_drv.h>
@@ -1017,7 +1018,8 @@ void mlx5e_build_sq_param(struct mlx5_core_dev *mdev,
 	bool allow_swp;
 
 	allow_swp = mlx5_geneve_tx_allowed(mdev) ||
-		    (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_CRYPTO);
+		    (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_CRYPTO) ||
+		    mlx5_is_psp_device(mdev);
 	mlx5e_build_sq_param_common(mdev, param);
 	MLX5_SET(wq, wq, log_wq_sz, params->log_sq_size);
 	MLX5_SET(sqc, sqc, allow_swp, allow_swp);
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c new file +149 -0

149 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h new file +53 -0

53 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_offload.c new file +52 -0

52 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_main.c +9 -0
index dca5ca51a470..b651827e5321 100644
@@ -52,6 +52,7 @@
 #include "en_tc.h"
 #include "en_rep.h"
 #include "en_accel/ipsec.h"
+#include "en_accel/psp.h"
 #include "en_accel/macsec.h"
 #include "en_accel/en_accel.h"
 #include "en_accel/ktls.h"
@@ -5835,6 +5836,7 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev,
 	if (take_rtnl)
 		rtnl_lock();
 
+	mlx5e_psp_register(priv);
 	/* update XDP supported features */
 	mlx5e_set_xdp_feature(netdev);
 
@@ -5847,6 +5849,7 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev,
 static void mlx5e_nic_cleanup(struct mlx5e_priv *priv)
 {
 	mlx5e_health_destroy_reporters(priv);
+	mlx5e_psp_unregister(priv);
 	mlx5e_ktls_cleanup(priv);
 	mlx5e_fs_cleanup(priv->fs);
 	debugfs_remove_recursive(priv->dfs_root);
@@ -5974,6 +5977,10 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
 	if (err)
 		mlx5_core_err(mdev, "MACsec initialization failed, %d\n", err);
 
+	err = mlx5e_psp_init(priv);
+	if (err)
+		mlx5_core_err(mdev, "PSP initialization failed, %d\n", err);
+
 	/* Marking the link as currently not needed by the Driver */
 	if (!netif_running(netdev))
 		mlx5e_modify_admin_state(mdev, MLX5_PORT_DOWN);
@@ -6035,6 +6042,7 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv)
 	mlx5e_disable_async_events(priv);
 	mlx5_lag_remove_netdev(mdev, priv->netdev);
 	mlx5_vxlan_reset_to_default(mdev->vxlan);
+	mlx5e_psp_cleanup(priv);
 	mlx5e_macsec_cleanup(priv);
 	mlx5e_ipsec_cleanup(priv);
 }
@@ -6693,6 +6701,7 @@ static void _mlx5e_remove(struct auxiliary_device *adev)
 	 * is already unregistered before changing to NIC profile.
 	 */
 	if (priv->netdev->reg_state == NETREG_REGISTERED) {
+		mlx5e_psp_unregister(priv);
 		unregister_netdev(priv->netdev);
 		_mlx5e_suspend(adev, false);
 	} else {
drivers/net/ethernet/mellanox/mlx5/core/fw.c +6 -0
index 57476487e31f..eeb4437975f2 100644
@@ -294,6 +294,12 @@ int mlx5_query_hca_caps(struct mlx5_core_dev *dev)
 			return err;
 	}
 
+	if (MLX5_CAP_GEN(dev, psp)) {
+		err = mlx5_core_get_caps(dev, MLX5_CAP_PSP);
+		if (err)
+			return err;
+	}
+
 	return 0;
 }
 
drivers/net/ethernet/mellanox/mlx5/core/main.c +5 -0
index 41e8660c819c..1890e4b09ffe 100644
@@ -74,6 +74,7 @@
 #include "mlx5_irq.h"
 #include "hwmon.h"
 #include "lag/lag.h"
+#include "psp.h"
 
 MODULE_AUTHOR("Eli Cohen <[email protected]>");
 MODULE_DESCRIPTION("Mellanox 5th generation network adapters (ConnectX series) core driver");
@@ -1046,6 +1047,7 @@ static int mlx5_init_once(struct mlx5_core_dev *dev)
 
 	dev->vxlan = mlx5_vxlan_create(dev);
 	dev->geneve = mlx5_geneve_create(dev);
+	dev->psp = mlx5_psp_create(dev);
 
 	err = mlx5_init_rl_table(dev);
 	if (err) {
@@ -1128,6 +1130,7 @@ static int mlx5_init_once(struct mlx5_core_dev *dev)
 err_rl_cleanup:
 	mlx5_cleanup_rl_table(dev);
 err_clock_cleanup:
+	mlx5_psp_destroy(dev->psp);
 	mlx5_geneve_destroy(dev->geneve);
 	mlx5_vxlan_destroy(dev->vxlan);
 	mlx5_cleanup_clock(dev);
@@ -1163,6 +1166,7 @@ static void mlx5_cleanup_once(struct mlx5_core_dev *dev)
 	mlx5_sriov_cleanup(dev);
 	mlx5_mpfs_cleanup(dev);
 	mlx5_cleanup_rl_table(dev);
+	mlx5_psp_destroy(dev->psp);
 	mlx5_geneve_destroy(dev->geneve);
 	mlx5_vxlan_destroy(dev->vxlan);
 	mlx5_cleanup_clock(dev);
@@ -1799,6 +1803,7 @@ static const int types[] = {
 	MLX5_CAP_VDPA_EMULATION,
 	MLX5_CAP_IPSEC,
 	MLX5_CAP_PORT_SELECTION,
+	MLX5_CAP_PSP,
 	MLX5_CAP_MACSEC,
 	MLX5_CAP_ADV_VIRTUALIZATION,
 	MLX5_CAP_CRYPTO,
drivers/net/ethernet/mellanox/mlx5/core/psp.c new file +24 -0
new file mode 100644
index 000000000000..15df8bde3632
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
+
+#include "psp.h"
+
+struct mlx5_psp *mlx5_psp_create(struct mlx5_core_dev *mdev)
+{
+	struct mlx5_psp *psp = kzalloc(sizeof(*psp), GFP_KERNEL);
+
+	if (!psp)
+		return ERR_PTR(-ENOMEM);
+
+	psp->mdev = mdev;
+
+	return psp;
+}
+
+void mlx5_psp_destroy(struct mlx5_psp *psp)
+{
+	if (IS_ERR_OR_NULL(psp))
+		return;
+
+	kfree(psp);
+}
drivers/net/ethernet/mellanox/mlx5/core/psp.h new file +15 -0
new file mode 100644
index 000000000000..1d7927c4ea72
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
+
+#ifndef __MLX5_PSP_H__
+#define __MLX5_PSP_H__
+#include <linux/mlx5/driver.h>
+
+struct mlx5_psp {
+	struct mlx5_core_dev *mdev;
+};
+
+struct mlx5_psp *mlx5_psp_create(struct mlx5_core_dev *mdev);
+void mlx5_psp_destroy(struct mlx5_psp *psp);
+
+#endif /* __MLX5_PSP_H__ */
include/linux/mlx5/device.h +4 -0
index 6822cfa5f4ad..c2809d3b094c 100644
@@ -1247,6 +1247,7 @@ enum mlx5_cap_type {
 	MLX5_CAP_IPSEC,
 	MLX5_CAP_CRYPTO = 0x1a,
 	MLX5_CAP_SHAMPO = 0x1d,
+	MLX5_CAP_PSP = 0x1e,
 	MLX5_CAP_MACSEC = 0x1f,
 	MLX5_CAP_GENERAL_2 = 0x20,
 	MLX5_CAP_PORT_SELECTION = 0x25,
@@ -1486,6 +1487,9 @@ enum mlx5_qcam_feature_groups {
 #define MLX5_CAP_SHAMPO(mdev, cap) \
 	MLX5_GET(shampo_cap, mdev->caps.hca[MLX5_CAP_SHAMPO]->cur, cap)
 
+#define MLX5_CAP_PSP(mdev, cap)\
+	MLX5_GET(psp_cap, (mdev)->caps.hca[MLX5_CAP_PSP]->cur, cap)
+
 enum {
 	MLX5_CMD_STAT_OK			= 0x0,
 	MLX5_CMD_STAT_INT_ERR			= 0x1,
include/linux/mlx5/driver.h +2 -0
index e6ba8f4f4bd1..671512699a92 100644
@@ -491,6 +491,7 @@ struct mlx5_sf_dev_table;
 struct mlx5_sf_hw_table;
 struct mlx5_sf_table;
 struct mlx5_crypto_dek_priv;
+struct mlx5_psp;
 
 struct mlx5_rate_limit {
 	u32			rate;
@@ -786,6 +787,7 @@ struct mlx5_core_dev {
 	enum mlx5_wc_state wc_state;
 	/* sync write combining state */
 	struct mutex wc_state_lock;
+	struct mlx5_psp         *psp;
 };
 
 struct mlx5_db {
include/linux/mlx5/mlx5_ifc.h +89 -5

168 lines not on this page · raw message

Signature · 1 line
2.47.1
#34 lore raw

Re: [PATCH v3 11/19] net/mlx5e: Support PSP offload functionality

Quoted 88 lines · Daniel Zahka

From: Raed Salem <[email protected]>

Add PSP offload related IFC structs, layouts, and enumerations. Implement
.set_config and .rx_spi_alloc PSP device operations. Driver does not need
to make use of the .set_config operation. Stub .assoc_add and .assoc_del
PSP operations.

Introduce the MLX5_EN_PSP configuration option for enabling PSP offload
support on mlx5 devices.

---

Notes:
    v1:
    -
https://lore.kernel.org/netdev/[email protected]/

 .../net/ethernet/mellanox/mlx5/core/Kconfig   |  11 ++ .../net/ethernet/mellanox/mlx5/core/Makefile  |   4 +- drivers/net/ethernet/mellanox/mlx5/core/en.h  |   3 + .../ethernet/mellanox/mlx5/core/en/params.c   |   4 +- .../mellanox/mlx5/core/en_accel/psp.c         | 149
++++++++++++++++++
 .../mellanox/mlx5/core/en_accel/psp.h         |  53 +++++++ .../mellanox/mlx5/core/en_accel/psp_offload.c |  52 ++++++ .../net/ethernet/mellanox/mlx5/core/en_main.c |   9 ++ drivers/net/ethernet/mellanox/mlx5/core/fw.c  |   6 + .../net/ethernet/mellanox/mlx5/core/main.c    |   5 + drivers/net/ethernet/mellanox/mlx5/core/psp.c |  24 +++ drivers/net/ethernet/mellanox/mlx5/core/psp.h |  15 ++ include/linux/mlx5/device.h                   |   4 + include/linux/mlx5/driver.h                   |   2 + include/linux/mlx5/mlx5_ifc.h                 |  94 ++++++++++-

 15 files changed, 428 insertions(+), 7 deletions(-)

 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_offload.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/psp.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/psp.h

drivers/net/ethernet/mellanox/mlx5/core/Kconfig +0 -0
index 6ec7d6e0181d..79a64489da89 100644
@@ -208,3 +208,14 @@ config MLX5_DPLL

  help
    DPLL support in Mellanox Technologies ConnectX NICs.

drivers/net/ethernet/mellanox/mlx5/core/Kconfig +2 -0
+config MLX5_EN_PSP
+	bool "Mellanox Technologies support for PSP cryptography-

offload acceleration"

drivers/net/ethernet/mellanox/mlx5/core/Kconfig +5 -0
+	depends on INET_PSP
+	depends on MLX5_CORE_EN
+	default y
+	help
+	  mlx5 device offload support for Google PSP Security

Protocol offload.

drivers/net/ethernet/mellanox/mlx5/core/Kconfig +1 -0
+	  Adds support for PSP encryption offload and for SPI and

key generation

drivers/net/ethernet/mellanox/mlx5/core/Kconfig +3 -0
+	  interfaces to PSP Stack which supports PSP crypto offload.
+
+	  If unsure, say Y.
drivers/net/ethernet/mellanox/mlx5/core/Makefile +0 -0
index d292e6a9e22c..e27de74ef028 100644
@@ -17,7 +17,7 @@ mlx5_core-y :=	main.o cmd.o debugfs.o fw.o
 eq.o uar.o pagealloc.o \

  fs_counters.o fs_ft_pool.o rl.o lag/debugfs.o lag/lag.o dev.o events.o wq.o lib/gid.o \
  lib/devcom.o lib/pci_vsc.o lib/dm.o lib/fs_ttc.o diag/fs_tracepoint.o \
  diag/fw_tracer.o diag/crdump.o devlink.o diag/rsc_dump.o diag/reporter_vnic.o \

drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -1
-		fw_reset.o qos.o lib/tout.o lib/aso.o wc.o fs_pool.o
+		fw_reset.o qos.o lib/tout.o lib/aso.o wc.o fs_pool.o
Quoted 1 line

psp.o

Turns out, psp.c/psp.h and struct mlx5_psp aren't needed at all. Please remove them, to avoid maintaining unnecessary boilerplate. Here's a fixup patch which does this:

From ca3310c747dca55f7a139828e71457ac27b77889 Mon Sep 17 00:00:00 2001
From: Cosmin Ratiu <[email protected]>
Date: Fri, 11 Jul 2025 15:35:15 +0300
Subject: [PATCH 1/3] net/mlx5: fixup for unneded struct mlx5_psp

Change-Id I8fcef314c53db25c0f3a73ff2daecf34d4d28fce
---
 .../net/ethernet/mellanox/mlx5/core/Makefile  |  2 +-
 .../net/ethernet/mellanox/mlx5/core/main.c    |  4 ----
 drivers/net/ethernet/mellanox/mlx5/core/psp.c | 24 -------------------
 drivers/net/ethernet/mellanox/mlx5/core/psp.h | 15 ------------
 include/linux/mlx5/driver.h                   |  2 --
 5 files changed, 1 insertion(+), 46 deletions(-)
 delete mode 100644 drivers/net/ethernet/mellanox/mlx5/core/psp.c
 delete mode 100644 drivers/net/ethernet/mellanox/mlx5/core/psp.h
(quoted diff) +0 -0

b/drivers/net/ethernet/mellanox/mlx5/core/Makefile index 3761f5c104d3..ab35efdb7052 100644

drivers/net/ethernet/mellanox/mlx5/core/Makefile +0 -0
@@ -17,7 +17,7 @@ mlx5_core-y :=	main.o cmd.o debugfs.o fw.o

eq.o uar.o pagealloc.o \
fs_counters.o fs_ft_pool.o rl.o lag/debugfs.o
lag/lag.o dev.o events.o wq.o lib/gid.o \
lib/devcom.o lib/pci_vsc.o lib/dm.o lib/fs_ttc.o
diag/fs_tracepoint.o \
diag/fw_tracer.o diag/crdump.o devlink.o
diag/rsc_dump.o diag/reporter_vnic.o \
- fw_reset.o qos.o lib/tout.o lib/aso.o wc.o fs_pool.o
psp.o
+ fw_reset.o qos.o lib/tout.o lib/aso.o wc.o fs_pool.o

#
# Netdev basic

(quoted diff) +0 -0

b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index 1890e4b09ffe..dc37b410799f 100644

drivers/net/ethernet/mellanox/mlx5/core/main.c +0 -1
@@ -74,7 +74,6 @@
 #include "mlx5_irq.h"
 #include "hwmon.h"
 #include "lag/lag.h"
-#include "psp.h"
 
 MODULE_AUTHOR("Eli Cohen <[email protected]>");
 MODULE_DESCRIPTION("Mellanox 5th generation network adapters (ConnectX

series) core driver");
@@ -1047,7 +1046,6 @@ static int mlx5_init_once(struct mlx5_core_dev *dev)

dev->vxlan = mlx5_vxlan_create(dev);
dev->geneve = mlx5_geneve_create(dev);
- dev->psp = mlx5_psp_create(dev);

err = mlx5_init_rl_table(dev);
if (err) {
@@ -1130,7 +1128,6 @@ static int mlx5_init_once(struct mlx5_core_dev *dev)
err_rl_cleanup:
mlx5_cleanup_rl_table(dev);
err_clock_cleanup:
- mlx5_psp_destroy(dev->psp);
mlx5_geneve_destroy(dev->geneve); mlx5_vxlan_destroy(dev->vxlan); mlx5_cleanup_clock(dev);
@@ -1166,7 +1163,6 @@ static void mlx5_cleanup_once(struct mlx5_core_dev *dev)
mlx5_sriov_cleanup(dev);
mlx5_mpfs_cleanup(dev); mlx5_cleanup_rl_table(dev);
- mlx5_psp_destroy(dev->psp);
mlx5_geneve_destroy(dev->geneve); mlx5_vxlan_destroy(dev->vxlan); mlx5_cleanup_clock(dev);

(quoted diff) +0 -0

b/drivers/net/ethernet/mellanox/mlx5/core/psp.c
deleted file mode 100644
index 15df8bde3632..000000000000

drivers/net/ethernet/mellanox/mlx5/core/psp.c deleted +0 -2
@@ -1,24 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
-/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights

reserved. */
-
-#include "psp.h"
-
-struct mlx5_psp *mlx5_psp_create(struct mlx5_core_dev *mdev) -{
- struct mlx5_psp *psp = kzalloc(sizeof(*psp), GFP_KERNEL);
-
- if (!psp)
- return ERR_PTR(-ENOMEM);
-
- psp->mdev = mdev;
-
- return psp;
-}
-
-void mlx5_psp_destroy(struct mlx5_psp *psp)
-{
- if (IS_ERR_OR_NULL(psp))
- return;
-
- kfree(psp);
-}

(quoted diff) +0 -0

b/drivers/net/ethernet/mellanox/mlx5/core/psp.h
deleted file mode 100644
index 1d7927c4ea72..000000000000

drivers/net/ethernet/mellanox/mlx5/core/psp.h deleted +0 -2
@@ -1,15 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
-/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights

reserved. */
-
-#ifndef __MLX5_PSP_H__
-#define __MLX5_PSP_H__
-#include <linux/mlx5/driver.h>
-
-struct mlx5_psp {
- struct mlx5_core_dev *mdev;
-};
-
-struct mlx5_psp *mlx5_psp_create(struct mlx5_core_dev *mdev); -void mlx5_psp_destroy(struct mlx5_psp *psp);
-
-#endif /* __MLX5_PSP_H__ */

include/linux/mlx5/driver.h +0 -2
index 671512699a92..e6ba8f4f4bd1 100644
@@ -491,7 +491,6 @@ struct mlx5_sf_dev_table;
 struct mlx5_sf_hw_table;
 struct mlx5_sf_table;
 struct mlx5_crypto_dek_priv;
-struct mlx5_psp;
 
 struct mlx5_rate_limit {
 	u32			rate;
@@ -787,7 +786,6 @@ struct mlx5_core_dev {
 	enum mlx5_wc_state wc_state;
 	/* sync write combining state */
 	struct mutex wc_state_lock;
-	struct mlx5_psp         *psp;
 };
 
 struct mlx5_db {
Signature · 1 line
2.45.0
Quoted 17 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h new file +2 -0
new file mode 100644
index 000000000000..9707f50029ed
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights

reserved. */

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h new file +7 -0
+
+#ifndef __MLX5E_ACCEL_PSP_H__
+#define __MLX5E_ACCEL_PSP_H__
+#if IS_ENABLED(CONFIG_MLX5_EN_PSP)
+#include <net/psp/types.h>
+#include "en.h"
+

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h new file +10 -0
+struct mlx5e_psp {
+	struct psp_dev *psp;
+	struct psp_dev_caps caps;
+};
+
+struct psp_key_spi {
+	u32 spi;
+	__be32 key[PSP_MAX_KEY / sizeof(u32)];
+	u16 keysz;
+};

This intermediate structure doesn't help much, it's only used during key generation and psp_key_parsed could be used directly. Here's a fixup patch which simplifies things, and avoids boilerplate:

From 1ea9823416548f6ec673ed51ec05590fc4f910ab Mon Sep 17 00:00:00 2001
From: Cosmin Ratiu <[email protected]>
Date: Fri, 11 Jul 2025 15:37:00 +0300
Subject: [PATCH 2/2] net/mlx5e: fixup for mlx5e_psp_generate_key_spi

- use psp_key_parsed directly

Change-Id Ie26552386fc415d23c0fbddb2408e8c7ecc05d8f
---
 .../mellanox/mlx5/core/en_accel/psp.c         | 12 ++------
 .../mellanox/mlx5/core/en_accel/psp.h         |  8 +----
 .../mellanox/mlx5/core/en_accel/psp_offload.c | 29 +++++++------------
 3 files changed, 13 insertions(+), 36 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index 288ed296b74c..cb429abc6b4b 100644

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +0 -0
@@ -23,9 +23,7 @@ mlx5e_psp_rx_spi_alloc(struct psp_dev *psd, u32

version,
{
struct mlx5e_priv *priv = netdev_priv(psd->main_netdev); enum mlx5_psp_gen_spi_in_key_size keysz;
- struct psp_key_spi key_spi = {};
u8 keysz_bytes;
- int err;

switch (version) {
case PSP_VERSION_HDR0_AES_GCM_128:
@@ -40,14 +38,8 @@ mlx5e_psp_rx_spi_alloc(struct psp_dev *psd, u32 version,
return -EINVAL;
}

- err = mlx5e_psp_generate_key_spi(priv->mdev, keysz,
keysz_bytes,
- &key_spi);
- if (err)
- return err;
-
- assoc->spi = cpu_to_be32(key_spi.spi);
- memcpy(assoc->key, key_spi.key, keysz_bytes);
- return 0;
+ return mlx5e_psp_generate_key_spi(priv->mdev, keysz,
keysz_bytes,
+ assoc);
}

struct psp_key {

(quoted diff) +0 -0

b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h index 16e5ba591307..3f64a162f503 100644

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h +0 -6
@@ -14,12 +14,6 @@ struct mlx5e_psp {
 	atomic_t tx_key_cnt;
 };
 
-struct psp_key_spi {
-	u32 spi;
-	__be32 key[PSP_MAX_KEY / sizeof(u32)];
-	u16 keysz;
-};
-
 static inline bool mlx5_is_psp_device(struct mlx5_core_dev *mdev)
 {
 	if (!MLX5_CAP_GEN(mdev, psp))
@@ -40,7 +34,7 @@ int mlx5e_psp_rotate_key(struct mlx5_core_dev *mdev);
 int mlx5e_psp_generate_key_spi(struct mlx5_core_dev *mdev,
 			       enum mlx5_psp_gen_spi_in_key_size

keysz,
unsigned int keysz_bytes,
- struct psp_key_spi *keys);
+ struct psp_key_parsed *key);
#else
static inline bool mlx5_is_psp_device(struct mlx5_core_dev *mdev) {
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_offload.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_offload.c index c3c21a99a92b..a158ae407455 100644

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_offload.c +0 -0
@@ -19,34 +19,25 @@ int mlx5e_psp_rotate_key(struct mlx5_core_dev

*mdev)
int mlx5e_psp_generate_key_spi(struct mlx5_core_dev *mdev,
enum mlx5_psp_gen_spi_in_key_size
keysz,
unsigned int keysz_bytes,
- struct psp_key_spi *keys)
+ struct psp_key_parsed *key)
{
+ u32 out[MLX5_ST_SZ_DW(psp_gen_spi_out) +
MLX5_ST_SZ_DW(key_spi)] = {};
u32 in[MLX5_ST_SZ_DW(psp_gen_spi_in)] = {};
- int err, outlen, i;
- void *out, *outkey;
+ void *outkey;
+ int err;

WARN_ON_ONCE(keysz_bytes > PSP_MAX_KEY);

- outlen = MLX5_ST_SZ_BYTES(psp_gen_spi_out) +
MLX5_ST_SZ_BYTES(key_spi);
- out = kzalloc(outlen, GFP_KERNEL);
- if (!out)
- return -ENOMEM;
-
MLX5_SET(psp_gen_spi_in, in, opcode, MLX5_CMD_OP_PSP_GEN_SPI); MLX5_SET(psp_gen_spi_in, in, key_size, keysz); MLX5_SET(psp_gen_spi_in, in, num_of_spi, 1);
- err = mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
+ err = mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
if (err)
- goto out;
+ return err;

outkey = MLX5_ADDR_OF(psp_gen_spi_out, out, key_spi);
- keys->keysz = keysz_bytes * BITS_PER_BYTE;
- keys->spi = MLX5_GET(key_spi, outkey, spi);
- for (i = 0; i < keysz_bytes / sizeof(*keys->key); ++i)
- keys->key[i] = cpu_to_be32(MLX5_GET(key_spi,
- outkey + (32 -
keysz_bytes), key[i]));
-
-out:
- kfree(out);
- return err;
+ key->spi = cpu_to_be32(MLX5_GET(key_spi, outkey, spi));
+ memcpy(key->key, MLX5_ADDR_OF(key_spi, outkey, key),
keysz_bytes);
+
+ return 0;
}

Signature · 3 lines
2.45.0

Cosmin.
author maintainer
#35 lore raw

Re: [PATCH v3 11/19] net/mlx5e: Support PSP offload functionality

Quoted 45 lines · Cosmin Ratiu

int mlx5e_psp_generate_key_spi(struct mlx5_core_dev *mdev,
enum mlx5_psp_gen_spi_in_key_size
keysz,
unsigned int keysz_bytes,
- struct psp_key_spi *keys)
+ struct psp_key_parsed *key)
{
+ u32 out[MLX5_ST_SZ_DW(psp_gen_spi_out) + MLX5_ST_SZ_DW(key_spi)] = {};
u32 in[MLX5_ST_SZ_DW(psp_gen_spi_in)] = {};
- int err, outlen, i;
- void *out, *outkey;
+ void *outkey;
+ int err;

  	WARN_ON_ONCE(keysz_bytes > PSP_MAX_KEY);

- outlen = MLX5_ST_SZ_BYTES(psp_gen_spi_out) + MLX5_ST_SZ_BYTES(key_spi);
- out = kzalloc(outlen, GFP_KERNEL);
- if (!out)
- return -ENOMEM;
-
MLX5_SET(psp_gen_spi_in, in, opcode, MLX5_CMD_OP_PSP_GEN_SPI); MLX5_SET(psp_gen_spi_in, in, key_size, keysz); MLX5_SET(psp_gen_spi_in, in, num_of_spi, 1);
- err = mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
+ err = mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out)); if (err)
- goto out;
+ return err;

outkey = MLX5_ADDR_OF(psp_gen_spi_out, out, key_spi);
- keys->keysz = keysz_bytes * BITS_PER_BYTE;
- keys->spi = MLX5_GET(key_spi, outkey, spi);
- for (i = 0; i < keysz_bytes / sizeof(*keys->key); ++i)
- keys->key[i] = cpu_to_be32(MLX5_GET(key_spi,
- outkey + (32 -
keysz_bytes), key[i]));

(quoted diff) +2 -4
-
-out:
- kfree(out);
- return err;
+ key->spi = cpu_to_be32(MLX5_GET(key_spi, outkey, spi));
+ memcpy(key->key, MLX5_ADDR_OF(key_spi, outkey, key),
Quoted 3 lines

keysz_bytes);
+

Thanks for the updates, Cosmin. I did notice a small problem after applying these, where v1 keys were ok, but not v0. This seems to fix it for me, but it was a bit of a guess. Let me know what the proper adjustment is:

        outkey = MLX5_ADDR_OF(psp_gen_spi_out, out, key_spi);
        key->spi = cpu_to_be32(MLX5_GET(key_spi, outkey, spi));
-       memcpy(key->key, MLX5_ADDR_OF(key_spi, outkey, key), keysz_bytes);
+       memcpy(key->key, MLX5_ADDR_OF(key_spi, outkey, key) + (32 - keysz_bytes), keysz_bytes);

author maintainer
#36 lore raw

PATCH v3 12/19 net/mlx5e: Implement PSP operations .assoc_add and .assoc_del

In reply to Daniel Zahka

From: Raed Salem <[email protected]>

Implement .assoc_add and .assoc_del PSP operations used in the tx control path. Allocate the relevant hardware resources when a new key is registered using .assoc_add. Destroy the key when .assoc_del is called. Use a atomic counter to keep track of the current number of keys being used by the device.

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 .../net/ethernet/mellanox/mlx5/core/Makefile  |   2 +-
 .../mellanox/mlx5/core/en_accel/en_accel.h    |   8 +
 .../mellanox/mlx5/core/en_accel/psp.c         |  55 ++++-
 .../mellanox/mlx5/core/en_accel/psp.h         |   2 +
 .../mellanox/mlx5/core/en_accel/psp_fs.c      | 233 ++++++++++++++++++
 .../mellanox/mlx5/core/en_accel/psp_fs.h      |  23 ++
 .../net/ethernet/mellanox/mlx5/core/en_main.c |  10 +-
 .../ethernet/mellanox/mlx5/core/lib/crypto.h  |   1 +
 8 files changed, 325 insertions(+), 9 deletions(-)
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.h
drivers/net/ethernet/mellanox/mlx5/core/Makefile +1 -1
index e27de74ef028..5d2783f2e82f 100644
@@ -110,7 +110,7 @@ mlx5_core-$(CONFIG_MLX5_EN_TLS) += en_accel/ktls_stats.o \
 				   en_accel/fs_tcp.o en_accel/ktls.o en_accel/ktls_txrx.o \
 				   en_accel/ktls_tx.o en_accel/ktls_rx.o
 
-mlx5_core-$(CONFIG_MLX5_EN_PSP) += en_accel/psp.o en_accel/psp_offload.o
+mlx5_core-$(CONFIG_MLX5_EN_PSP) += en_accel/psp.o en_accel/psp_offload.o en_accel/psp_fs.o
 
 #
 # SW Steering
drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +8 -0
index 33e32584b07f..bd990e7a6a79 100644
@@ -42,6 +42,7 @@
 #include <en_accel/macsec.h>
 #include "en.h"
 #include "en/txrx.h"
+#include "en_accel/psp_fs.h"
 
 #if IS_ENABLED(CONFIG_GENEVE)
 #include <net/geneve.h>
@@ -218,11 +219,18 @@ static inline void mlx5e_accel_cleanup_rx(struct mlx5e_priv *priv)
 
 static inline int mlx5e_accel_init_tx(struct mlx5e_priv *priv)
 {
+	int err;
+
+	err = mlx5_accel_psp_fs_init_tx_tables(priv);
+	if (err)
+		return err;
+
 	return mlx5e_ktls_init_tx(priv);
 }
 
 static inline void mlx5e_accel_cleanup_tx(struct mlx5e_priv *priv)
 {
 	mlx5e_ktls_cleanup_tx(priv);
+	mlx5_accel_psp_fs_cleanup_tx_tables(priv);
 }
 #endif /* __MLX5E_EN_ACCEL_H__ */
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +52 -3

98 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h +2 -0
index 9707f50029ed..16e5ba591307 100644
@@ -10,6 +10,8 @@
 struct mlx5e_psp {
 	struct psp_dev *psp;
 	struct psp_dev_caps caps;
+	struct mlx5e_psp_fs *fs;
+	atomic_t tx_key_cnt;
 };
 
 struct psp_key_spi {
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c new file +233 -0

233 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.h new file +23 -0
new file mode 100644
index 000000000000..d81aeea43505
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
+
+#ifndef __MLX5_PSP_FS_H__
+#define __MLX5_PSP_FS_H__
+
+#ifdef CONFIG_MLX5_EN_PSP
+
+struct mlx5e_psp_fs;
+
+struct mlx5e_psp_fs *mlx5e_accel_psp_fs_init(struct mlx5e_priv *priv);
+void mlx5e_accel_psp_fs_cleanup(struct mlx5e_psp_fs *fs);
+int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv);
+void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv);
+#else
+static inline int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv)
+{
+	return 0;
+}
+
+static inline void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv) { }
+#endif /* CONFIG_MLX5_EN_PSP */
+#endif /* __MLX5_PSP_FS_H__ */
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +5 -5
index b651827e5321..cf10d43abc25 100644
@@ -5824,6 +5824,10 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev,
 	}
 	priv->fs = fs;
 
+	err = mlx5e_psp_init(priv);
+	if (err)
+		mlx5_core_err(mdev, "PSP initialization failed, %d\n", err);
+
 	err = mlx5e_ktls_init(priv);
 	if (err)
 		mlx5_core_err(mdev, "TLS initialization failed, %d\n", err);
@@ -5851,6 +5855,7 @@ static void mlx5e_nic_cleanup(struct mlx5e_priv *priv)
 	mlx5e_health_destroy_reporters(priv);
 	mlx5e_psp_unregister(priv);
 	mlx5e_ktls_cleanup(priv);
+	mlx5e_psp_cleanup(priv);
 	mlx5e_fs_cleanup(priv->fs);
 	debugfs_remove_recursive(priv->dfs_root);
 	priv->fs = NULL;
@@ -5977,10 +5982,6 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv)
 	if (err)
 		mlx5_core_err(mdev, "MACsec initialization failed, %d\n", err);
 
-	err = mlx5e_psp_init(priv);
-	if (err)
-		mlx5_core_err(mdev, "PSP initialization failed, %d\n", err);
-
 	/* Marking the link as currently not needed by the Driver */
 	if (!netif_running(netdev))
 		mlx5e_modify_admin_state(mdev, MLX5_PORT_DOWN);
@@ -6042,7 +6043,6 @@ static void mlx5e_nic_disable(struct mlx5e_priv *priv)
 	mlx5e_disable_async_events(priv);
 	mlx5_lag_remove_netdev(mdev, priv->netdev);
 	mlx5_vxlan_reset_to_default(mdev->vxlan);
-	mlx5e_psp_cleanup(priv);
 	mlx5e_macsec_cleanup(priv);
 	mlx5e_ipsec_cleanup(priv);
 }
drivers/net/ethernet/mellanox/mlx5/core/lib/crypto.h +1 -0
index c819c047bb9c..4821163a547f 100644
@@ -8,6 +8,7 @@ enum {
 	MLX5_ACCEL_OBJ_TLS_KEY = MLX5_GENERAL_OBJECT_TYPE_ENCRYPTION_KEY_PURPOSE_TLS,
 	MLX5_ACCEL_OBJ_IPSEC_KEY = MLX5_GENERAL_OBJECT_TYPE_ENCRYPTION_KEY_PURPOSE_IPSEC,
 	MLX5_ACCEL_OBJ_MACSEC_KEY = MLX5_GENERAL_OBJECT_TYPE_ENCRYPTION_KEY_PURPOSE_MACSEC,
+	MLX5_ACCEL_OBJ_PSP_KEY = MLX5_GENERAL_OBJECT_TYPE_ENCRYPTION_KEY_PURPOSE_PSP,
 	MLX5_ACCEL_OBJ_TYPE_KEY_NUM,
 };
 
Signature · 1 line
2.47.1
#37 lore raw

Re: [PATCH v3 12/19] net/mlx5e: Implement PSP operations .assoc_add and .assoc_del

Quoted 95 lines · Daniel Zahka

From: Raed Salem <[email protected]>

Implement .assoc_add and .assoc_del PSP operations used in the tx control
path. Allocate the relevant hardware resources when a new key is registered
using .assoc_add. Destroy the key when .assoc_del is called. Use a atomic
counter to keep track of the current number of keys being used by the device.

---

Notes:
    v1:
    -
https://lore.kernel.org/netdev/[email protected]/

 .../net/ethernet/mellanox/mlx5/core/Makefile  |   2 +- .../mellanox/mlx5/core/en_accel/en_accel.h    |   8 + .../mellanox/mlx5/core/en_accel/psp.c         |  55 ++++- .../mellanox/mlx5/core/en_accel/psp.h         |   2 + .../mellanox/mlx5/core/en_accel/psp_fs.c      | 233
++++++++++++++++++
 .../mellanox/mlx5/core/en_accel/psp_fs.h      |  23 ++ .../net/ethernet/mellanox/mlx5/core/en_main.c |  10 +- .../ethernet/mellanox/mlx5/core/lib/crypto.h  |   1 +

 8 files changed, 325 insertions(+), 9 deletions(-)

 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.h

drivers/net/ethernet/mellanox/mlx5/core/Makefile +0 -0
index e27de74ef028..5d2783f2e82f 100644
@@ -110,7 +110,7 @@ mlx5_core-$(CONFIG_MLX5_EN_TLS) +=
 en_accel/ktls_stats.o \

     en_accel/fs_tcp.o en_accel/ktls.o en_accel/ktls_txrx.o \
     en_accel/ktls_tx.o en_accel/ktls_rx.o

-mlx5_core-$(CONFIG_MLX5_EN_PSP) += en_accel/psp.o en_accel/psp_offload.o
+mlx5_core-$(CONFIG_MLX5_EN_PSP) += en_accel/psp.o en_accel/psp_offload.o en_accel/psp_fs.o

 #
 # SW Steering
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h index 33e32584b07f..bd990e7a6a79 100644

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +1 -0
@@ -42,6 +42,7 @@
  #include <en_accel/macsec.h>
  #include "en.h"
  #include "en/txrx.h"
+#include "en_accel/psp_fs.h"


 #if IS_ENABLED(CONFIG_GENEVE)
 #include <net/geneve.h>

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +0 -0
@@ -218,11 +219,18 @@ static inline void
 mlx5e_accel_cleanup_rx(struct mlx5e_priv *priv)


 static inline int mlx5e_accel_init_tx(struct mlx5e_priv *priv) {

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +6 -0
+	int err;
+
+	err = mlx5_accel_psp_fs_init_tx_tables(priv);
+	if (err)
+		return err;
+

  return mlx5e_ktls_init_tx(priv);
 }

 static inline void mlx5e_accel_cleanup_tx(struct mlx5e_priv *priv) {
  mlx5e_ktls_cleanup_tx(priv);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +1 -0
+	mlx5_accel_psp_fs_cleanup_tx_tables(priv);

 }
 #endif /* __MLX5E_EN_ACCEL_H__ */

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +0 -0
index 482e2cdabdae..fb2b7e4e2f06 100644

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c line 15

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +6 -0
@@ -7,6 +7,12 @@
  #include "psp.h"
  #include "lib/crypto.h"
  #include "en_accel/psp.h"
+#include "en_accel/psp_fs.h"
+
+struct mlx5e_psp_sa_entry {
+	struct mlx5e_accel_psp_rule *psp_rule;
+	u32 enc_key_id;
+};

This is unused, please remove. It's probably a leftover from previous versions.

author maintainer
#38 lore raw

PATCH v3 13/19 psp: provide encapsulation helper for drivers

In reply to Daniel Zahka

From: Raed Salem <[email protected]>

Create a new function psp_encapsulate(), which takes a TCP packet and PSP encapsulates it according to the "Transport Mode Packet Format" section of the PSP Architecture Specification.

psp_encapsulate() does not push a PSP trailer onto the skb. Only IPv6 is supported. Virtualization cookie is not included.

---

Notes:
v3:
- patch introduced

 include/net/psp/functions.h |  2 ++
 include/net/psp/types.h     |  2 ++
 net/psp/psp_main.c          | 57 +++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
include/net/psp/functions.h +2 -0
index 1b414692504b..afb4f5929eec 100644
@@ -16,6 +16,8 @@ struct psp_dev *
 psp_dev_create(struct net_device *netdev, struct psp_dev_ops *psd_ops,
 	       struct psp_dev_caps *psd_caps, void *priv_ptr);
 void psp_dev_unregister(struct psp_dev *psd);
+bool psp_encapsulate(struct net *net, struct sk_buff *skb,
+		     __be32 spi, u8 ver, __be16 sport);
 
 /* Kernel-facing API */
 void psp_assoc_put(struct psp_assoc *pas);
include/net/psp/types.h +2 -0
index 383a1afab46d..fb8a31cbaae7 100644
@@ -20,6 +20,8 @@ struct psphdr {
 	__be64	vc[]; /* optional */
 };
 
+#define PSP_ENCAP_HLEN (sizeof(struct udphdr) + sizeof(struct psphdr))
+
 #define PSP_SPI_KEY_ID		GENMASK(30, 0)
 #define PSP_SPI_KEY_PHASE	BIT(31)
 
net/psp/psp_main.c +57 -0

73 lines not on this page · raw message

Signature · 1 line
2.47.1
maintainer Reviewed-by on v3 13/19
#39 lore raw

Re: [PATCH v3 13/19] psp: provide encapsulation helper for drivers

Quoted 6 lines · Daniel Zahka

From: Raed Salem <[email protected]>

Create a new function psp_encapsulate(), which takes a TCP packet and PSP encapsulates it according to the "Transport Mode Packet Format" section of the PSP Architecture Specification.

Quoted 6 lines

psp_encapsulate() does not push a PSP trailer onto the skb. Only IPv6 is supported. Virtualization cookie is not included.

Thanks for moving these helpers out of the driver.

author maintainer
#40 lore raw

PATCH v3 14/19 net/mlx5e: Implement PSP Tx data path

In reply to Daniel Zahka

From: Raed Salem <[email protected]>

Setup PSP offload on Tx data path based on whether skb indicates that it is intended for PSP or not. Support driver side encapsulation of the UDP headers, PSP headers, and PSP trailer for the PSP traffic that will be encrypted by the NIC.

---

Notes:
v3:
- move psp_encapsulate() into psp_main.c in a separate commit v1:
- https://lore.kernel.org/netdev/[email protected]/

 .../net/ethernet/mellanox/mlx5/core/Makefile  |   3 +-
 drivers/net/ethernet/mellanox/mlx5/core/en.h  |   3 +-
 .../mellanox/mlx5/core/en_accel/en_accel.h    |  28 +++
 .../mellanox/mlx5/core/en_accel/psp_rxtx.c    | 170 ++++++++++++++++++
 .../mellanox/mlx5/core/en_accel/psp_rxtx.h    |  96 ++++++++++
 .../net/ethernet/mellanox/mlx5/core/en_tx.c   |  10 +-
 6 files changed, 306 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c
 create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h
drivers/net/ethernet/mellanox/mlx5/core/Makefile +2 -1
index 5d2783f2e82f..3761f5c104d3 100644
@@ -110,7 +110,8 @@ mlx5_core-$(CONFIG_MLX5_EN_TLS) += en_accel/ktls_stats.o \
 				   en_accel/fs_tcp.o en_accel/ktls.o en_accel/ktls_txrx.o \
 				   en_accel/ktls_tx.o en_accel/ktls_rx.o
 
-mlx5_core-$(CONFIG_MLX5_EN_PSP) += en_accel/psp.o en_accel/psp_offload.o en_accel/psp_fs.o
+mlx5_core-$(CONFIG_MLX5_EN_PSP) += en_accel/psp.o en_accel/psp_offload.o en_accel/psp_fs.o \
+				   en_accel/psp_rxtx.o
 
 #
 # SW Steering
drivers/net/ethernet/mellanox/mlx5/core/en.h +2 -1
index 9078becfd710..69abe17902ed 100644
@@ -47,6 +47,7 @@
 #include <linux/rhashtable.h>
 #include <net/udp_tunnel.h>
 #include <net/switchdev.h>
+#include <net/psp/types.h>
 #include <net/xdp.h>
 #include <linux/dim.h>
 #include <linux/bits.h>
@@ -68,7 +69,7 @@ struct page_pool;
 #define MLX5E_METADATA_ETHER_TYPE (0x8CE4)
 #define MLX5E_METADATA_ETHER_LEN 8
 
-#define MLX5E_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN)
+#define MLX5E_ETH_HARD_MTU (ETH_HLEN + PSP_ENCAP_HLEN + PSP_TRL_SIZE + VLAN_HLEN + ETH_FCS_LEN)
 
 #define MLX5E_HW2SW_MTU(params, hwmtu) ((hwmtu) - ((params)->hard_mtu))
 #define MLX5E_SW2HW_MTU(params, swmtu) ((swmtu) + ((params)->hard_mtu))
drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +28 -0
index bd990e7a6a79..86496e332b03 100644
@@ -43,6 +43,7 @@
 #include "en.h"
 #include "en/txrx.h"
 #include "en_accel/psp_fs.h"
+#include "en_accel/psp_rxtx.h"
 
 #if IS_ENABLED(CONFIG_GENEVE)
 #include <net/geneve.h>
@@ -120,6 +121,9 @@ struct mlx5e_accel_tx_state {
 #ifdef CONFIG_MLX5_EN_IPSEC
 	struct mlx5e_accel_tx_ipsec_state ipsec;
 #endif
+#ifdef CONFIG_MLX5_EN_PSP
+	struct mlx5e_accel_tx_psp_state psp_st;
+#endif
 };
 
 static inline bool mlx5e_accel_tx_begin(struct net_device *dev,
@@ -138,6 +142,13 @@ static inline bool mlx5e_accel_tx_begin(struct net_device *dev,
 			return false;
 #endif
 
+#ifdef CONFIG_MLX5_EN_PSP
+	if (mlx5e_psp_is_offload(skb, dev)) {
+		if (unlikely(!mlx5e_psp_handle_tx_skb(dev, skb, &state->psp_st)))
+			return false;
+	}
+#endif
+
 #ifdef CONFIG_MLX5_EN_IPSEC
 	if (test_bit(MLX5E_SQ_STATE_IPSEC, &sq->state) && xfrm_offload(skb)) {
 		if (unlikely(!mlx5e_ipsec_handle_tx_skb(dev, skb, &state->ipsec)))
@@ -158,8 +169,14 @@ static inline bool mlx5e_accel_tx_begin(struct net_device *dev,
 }
 
 static inline unsigned int mlx5e_accel_tx_ids_len(struct mlx5e_txqsq *sq,
+						  struct sk_buff *skb,
 						  struct mlx5e_accel_tx_state *state)
 {
+#ifdef CONFIG_MLX5_EN_PSP
+	if (mlx5e_psp_is_offload_state(&state->psp_st))
+		return mlx5e_psp_tx_ids_len(&state->psp_st);
+#endif
+
 #ifdef CONFIG_MLX5_EN_IPSEC
 	if (test_bit(MLX5E_SQ_STATE_IPSEC, &sq->state))
 		return mlx5e_ipsec_tx_ids_len(&state->ipsec);
@@ -173,8 +190,14 @@ static inline unsigned int mlx5e_accel_tx_ids_len(struct mlx5e_txqsq *sq,
 
 static inline void mlx5e_accel_tx_eseg(struct mlx5e_priv *priv,
 				       struct sk_buff *skb,
+				       struct mlx5e_accel_tx_state *accel,
 				       struct mlx5_wqe_eth_seg *eseg, u16 ihs)
 {
+#ifdef CONFIG_MLX5_EN_PSP
+	if (mlx5e_psp_is_offload_state(&accel->psp_st))
+		mlx5e_psp_tx_build_eseg(priv, skb, &accel->psp_st, eseg);
+#endif
+
 #ifdef CONFIG_MLX5_EN_IPSEC
 	if (xfrm_offload(skb))
 		mlx5e_ipsec_tx_build_eseg(priv, skb, eseg);
@@ -200,6 +223,11 @@ static inline void mlx5e_accel_tx_finish(struct mlx5e_txqsq *sq,
 	mlx5e_ktls_handle_tx_wqe(&wqe->ctrl, &state->tls);
 #endif
 
+#ifdef CONFIG_MLX5_EN_PSP
+	if (mlx5e_psp_is_offload_state(&state->psp_st))
+		mlx5e_psp_handle_tx_wqe(wqe, &state->psp_st, inlseg);
+#endif
+
 #ifdef CONFIG_MLX5_EN_IPSEC
 	if (test_bit(MLX5E_SQ_STATE_IPSEC, &sq->state) &&
 	    state->ipsec.xo && state->ipsec.tailen)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c new file +170 -0

170 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h new file +96 -0

96 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +8 -2
index 55a8629f0792..fd9969ce5e0f 100644
@@ -39,6 +39,7 @@
 #include "ipoib/ipoib.h"
 #include "en_accel/en_accel.h"
 #include "en_accel/ipsec_rxtx.h"
+#include "en_accel/psp_rxtx.h"
 #include "en_accel/macsec.h"
 #include "en/ptp.h"
 #include <net/ipv6.h>
@@ -120,6 +121,11 @@ mlx5e_txwqe_build_eseg_csum(struct mlx5e_txqsq *sq, struct sk_buff *skb,
 			    struct mlx5e_accel_tx_state *accel,
 			    struct mlx5_wqe_eth_seg *eseg)
 {
+#ifdef CONFIG_MLX5_EN_PSP
+	if (unlikely(mlx5e_psp_txwqe_build_eseg_csum(sq, skb, &accel->psp_st, eseg)))
+		return;
+#endif
+
 	if (unlikely(mlx5e_ipsec_txwqe_build_eseg_csum(sq, skb, eseg)))
 		return;
 
@@ -298,7 +304,7 @@ static void mlx5e_sq_xmit_prepare(struct mlx5e_txqsq *sq, struct sk_buff *skb,
 		stats->packets++;
 	}
 
-	attr->insz = mlx5e_accel_tx_ids_len(sq, accel);
+	attr->insz = mlx5e_accel_tx_ids_len(sq, skb, accel);
 	stats->bytes += attr->num_bytes;
 }
 
@@ -668,7 +674,7 @@ static void mlx5e_txwqe_build_eseg(struct mlx5e_priv *priv, struct mlx5e_txqsq *
 				   struct sk_buff *skb, struct mlx5e_accel_tx_state *accel,
 				   struct mlx5_wqe_eth_seg *eseg, u16 ihs)
 {
-	mlx5e_accel_tx_eseg(priv, skb, eseg, ihs);
+	mlx5e_accel_tx_eseg(priv, skb, accel, eseg, ihs);
 	mlx5e_txwqe_build_eseg_csum(sq, skb, accel, eseg);
 	if (unlikely(sq->ptpsq))
 		mlx5e_cqe_ts_id_eseg(sq->ptpsq, skb, eseg);
Signature · 1 line
2.47.1
#41 lore raw

Re: [PATCH v3 14/19] net/mlx5e: Implement PSP Tx data path

Quoted 7 lines · Daniel Zahka

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c new file mode 100644
index 000000000000..e85b5db56fff

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c new file +0 -0

[...]

Quoted 18 lines
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c new file +3 -0
+static bool mlx5e_psp_set_state(struct mlx5e_priv *priv,
+				struct sk_buff *skb,
+				struct mlx5e_accel_tx_psp_state

*psp_st)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c new file +14 -0
+{
+	struct psp_assoc *pas;
+	bool ret = false;
+
+	rcu_read_lock();
+	pas = psp_skb_get_assoc_rcu(skb);
+	if (!pas)
+		goto out;
+
+	ret = true;
+	psp_st->tailen = PSP_TRL_SIZE;
+	psp_st->spi = pas->tx.spi;
+	psp_st->ver = pas->version;
+	memcpy(&psp_st->keyid, pas->drv_data, sizeof(psp_st-
Quoted 1 line
Quoted 1 line

keyid));

This should be a simple u32 assignment instead of a memcpy. So something like:
psp_st->keyid = *(u32*)pas->drv_data;

Cosmin.

author maintainer
#42 lore raw

PATCH v3 15/19 net/mlx5e: Add PSP steering in local NIC RX

In reply to Daniel Zahka

From: Raed Salem <[email protected]>

Introduce decrypt FT, the RX error FT, and the default rules.

The PSP (PSP) RX decrypt flow table is pointed by the TTC (Traffic Type Classifier) UDP steering rules.
The decrypt flow table has two flow groups. The first flow group keeps the decrypt steering rule programmed always when PSP packet is recognized using the dedicated udp destination port number 1000, if packet is decrypted then a PSP marker is set in metadata_regB[30]. The second flow group has a default rule to forward all non-offloaded PSP packet to the TTC UDP default RSS TIR.

The RX error flow table is the destination of the decrypt steering rules in the PSP RX decrypt flow table. It has two fixed rule one with single copy action that copies psp_syndrome to metadata_regB[23:29]. The PSP marker and syndrome is used to filter out non-psp packet and to return the PSP crypto offload status in Rx flow. The marker is used to identify such packet in driver so the driver could set SKB PSP metadata. The destination of RX error flow table is the TTC UDP default RSS TIR. The second rule will drop packets that failed to be decrypted (like in case illegal SPI or expired SPI is used).

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 .../net/ethernet/mellanox/mlx5/core/en/fs.h   |   2 +-
 .../mellanox/mlx5/core/en_accel/psp_fs.c      | 481 +++++++++++++++++-
 2 files changed, 476 insertions(+), 7 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +1 -1
index b5c3a2a9d2a5..35a7b2af83d9 100644
@@ -83,7 +83,7 @@ enum {
 #ifdef CONFIG_MLX5_EN_ARFS
 	MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
 #endif
-#ifdef CONFIG_MLX5_EN_IPSEC
+#if defined(CONFIG_MLX5_EN_IPSEC) || defined(CONFIG_MLX5_EN_PSP)
 	MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
 	MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
 	MLX5E_ACCEL_FS_POL_FT_LEVEL,
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +475 -6

521 lines not on this page · raw message

Signature · 1 line
2.47.1
#43 lore raw

Re: [PATCH v3 15/19] net/mlx5e: Add PSP steering in local NIC RX

Quoted 455 lines · Daniel Zahka

From: Raed Salem <[email protected]>

Introduce decrypt FT, the RX error FT, and the default rules.

The PSP (PSP) RX decrypt flow table is pointed by the TTC (Traffic Type Classifier) UDP steering rules.
The decrypt flow table has two flow groups. The first flow group keeps the decrypt steering rule programmed always when PSP packet is recognized using the dedicated udp destination port number 1000, if packet is decrypted then a PSP marker is set in metadata_regB[30]. The second flow group has a default rule to forward all non-offloaded PSP packet to the TTC UDP default RSS TIR.

The RX error flow table is the destination of the decrypt steering rules in
the PSP RX decrypt flow table. It has two fixed rule one with single copy
action that copies psp_syndrome to metadata_regB[23:29]. The PSP marker
and syndrome is used to filter out non-psp packet and to return the PSP
crypto offload status in Rx flow. The marker is used to identify such packet in driver so the driver could set SKB PSP metadata. The destination
of RX error flow table is the TTC UDP default RSS TIR. The second rule will
drop packets that failed to be decrypted (like in case illegal SPI or expired SPI is used).

---

Notes:
    v1:
    -
https://lore.kernel.org/netdev/[email protected]/

 .../net/ethernet/mellanox/mlx5/core/en/fs.h   |   2 +- .../mellanox/mlx5/core/en_accel/psp_fs.c      | 481
+++++++++++++++++-

 2 files changed, 476 insertions(+), 7 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +1 -1
index b5c3a2a9d2a5..35a7b2af83d9 100644
@@ -83,7 +83,7 @@ enum {
  #ifdef CONFIG_MLX5_EN_ARFS
  	MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
  #endif
-#ifdef CONFIG_MLX5_EN_IPSEC
+#if defined(CONFIG_MLX5_EN_IPSEC) || defined(CONFIG_MLX5_EN_PSP)
  	MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1,
  	MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL,
  	MLX5E_ACCEL_FS_POL_FT_LEVEL,

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c index cabbc8f0d84a..789d4373c1ad 100644

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +0 -0
@@ -8,6 +8,12 @@
  #include "en_accel/psp_fs.h"
  #include "en_accel/psp.h"

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +6 -0
+enum accel_fs_psp_type {
+	ACCEL_FS_PSP4,
+	ACCEL_FS_PSP6,
+	ACCEL_FS_PSP_NUM_TYPES,
+};
+

 struct mlx5e_psp_tx {
  struct mlx5_flow_namespace *ns;
  struct mlx5_flow_table *ft;

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +0 -0
@@ -17,14 +23,15 @@ struct mlx5e_psp_tx {
  	u32 refcnt;
  };

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +0 -6
-struct mlx5e_psp_fs {
-	struct mlx5_core_dev *mdev;
-	struct mlx5e_psp_tx *tx_fs;
-	struct mlx5e_flow_steering *fs;
-};
-

 enum accel_psp_rule_action {
  ACCEL_PSP_RULE_ACTION_ENCRYPT,

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +7 -0
+	ACCEL_PSP_RULE_ACTION_DECRYPT,
+};
+
+enum accel_psp_syndrome {
+	PSP_OK = 0,
+	PSP_ICV_FAIL,
+	PSP_BAD_TRAILER,

 };

 struct mlx5e_accel_psp_rule {

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +0 -0
@@ -32,6 +39,216 @@ struct mlx5e_accel_psp_rule {
  	u8 action;
  };

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +20 -0
+struct mlx5e_psp_rx_err {
+	struct mlx5_flow_table *ft;
+	struct mlx5_flow_handle *rule;
+	struct mlx5_flow_handle *drop_rule;
+	struct mlx5_modify_hdr *copy_modify_hdr;
+};
+
+struct mlx5e_accel_fs_psp_prot {
+	struct mlx5_flow_table *ft;
+	struct mlx5_flow_group *miss_group;
+	struct mlx5_flow_handle *miss_rule;
+	struct mlx5_flow_destination default_dest;
+	struct mlx5e_psp_rx_err rx_err;
+	u32 refcnt;
+	struct mutex prot_mutex; /* protect ESP4/ESP6 protocol */
+	struct mlx5_flow_handle *def_rule;
+};
+
+struct mlx5e_accel_fs_psp {
+	struct mlx5e_accel_fs_psp_prot

fs_prot[ACCEL_FS_PSP_NUM_TYPES];

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +21 -0
+};
+
+struct mlx5e_psp_fs {
+	struct mlx5_core_dev *mdev;
+	struct mlx5e_psp_tx *tx_fs;
+	/* Rx manage */
+	struct mlx5e_flow_steering *fs;
+	struct mlx5e_accel_fs_psp *rx_fs;
+};
+
+/* PSP RX flow steering */
+static enum mlx5_traffic_types fs_psp2tt(enum accel_fs_psp_type i)
+{
+	if (i == ACCEL_FS_PSP4)
+		return MLX5_TT_IPV4_UDP;
+
+	return MLX5_TT_IPV6_UDP;
+}
+
+static void accel_psp_fs_rx_err_del_rules(struct mlx5e_psp_fs *fs,
+					  struct mlx5e_psp_rx_err

*rx_err)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +13 -0
+{
+	if (rx_err->drop_rule) {
+		mlx5_del_flow_rules(rx_err->drop_rule);
+		rx_err->drop_rule = NULL;
+	}
+
+	if (rx_err->rule) {
+		mlx5_del_flow_rules(rx_err->rule);
+		rx_err->rule = NULL;
+	}
+
+	if (rx_err->copy_modify_hdr) {
+		mlx5_modify_header_dealloc(fs->mdev, rx_err-
Quoted 1 line

copy_modify_hdr);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +6 -0
+		rx_err->copy_modify_hdr = NULL;
+	}
+}
+
+static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs,
+					   struct mlx5e_psp_rx_err

*rx_err)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +10 -0
+{
+	accel_psp_fs_rx_err_del_rules(fs, rx_err);
+
+	if (rx_err->ft) {
+		mlx5_destroy_flow_table(rx_err->ft);
+		rx_err->ft = NULL;
+	}
+}
+
+static void accel_psp_setup_syndrome_match(struct mlx5_flow_spec

*spec,

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +1 -0
+					   enum accel_psp_syndrome

syndrome)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +5 -0
+{
+	void *misc_params_2;
+
+	spec->match_criteria_enable |= MLX5_MATCH_MISC_PARAMETERS_2;
+	misc_params_2 = MLX5_ADDR_OF(fte_match_param, spec-
Quoted 1 line

match_criteria, misc_parameters_2);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +1 -0
+	MLX5_SET_TO_ONES(fte_match_set_misc2, misc_params_2,

psp_syndrome);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +1 -0
+	misc_params_2 = MLX5_ADDR_OF(fte_match_param, spec-
Quoted 1 line

match_value, misc_parameters_2);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +1 -0
+	MLX5_SET(fte_match_set_misc2, misc_params_2, psp_syndrome,

syndrome);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +4 -0
+}
+
+static int accel_psp_fs_rx_err_add_rule(struct mlx5e_psp_fs *fs,
+					struct

mlx5e_accel_fs_psp_prot *fs_prot,

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +1 -0
+					struct mlx5e_psp_rx_err

*rx_err)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +2 -0
+{
+	u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] =

{};

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +13 -0
+	struct mlx5_core_dev *mdev = fs->mdev;
+	struct mlx5_flow_act flow_act = {};
+	struct mlx5_modify_hdr *modify_hdr;
+	struct mlx5_flow_handle *fte;
+	struct mlx5_flow_spec *spec;
+	int err = 0;
+
+	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
+	if (!spec)
+		return -ENOMEM;
+
+	/* Action to copy 7 bit psp_syndrome to regB[23:29] */
+	MLX5_SET(copy_action_in, action, action_type,

MLX5_ACTION_TYPE_COPY);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +1 -0
+	MLX5_SET(copy_action_in, action, src_field,

MLX5_ACTION_IN_FIELD_PSP_SYNDROME);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +3 -0
+	MLX5_SET(copy_action_in, action, src_offset, 0);
+	MLX5_SET(copy_action_in, action, length, 7);
+	MLX5_SET(copy_action_in, action, dst_field,

MLX5_ACTION_IN_FIELD_METADATA_REG_B);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +3 -0
+	MLX5_SET(copy_action_in, action, dst_offset, 23);
+
+	modify_hdr = mlx5_modify_header_alloc(mdev,

MLX5_FLOW_NAMESPACE_KERNEL,

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +5 -0
+					      1, action);
+	if (IS_ERR(modify_hdr)) {
+		err = PTR_ERR(modify_hdr);
+		mlx5_core_err(mdev,
+			      "fail to alloc psp copy

modify_header_id err=%d\n", err);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +13 -0
+		goto out_spec;
+	}
+
+	accel_psp_setup_syndrome_match(spec, PSP_OK);
+	/* create fte */
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_MOD_HDR |
+		MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
+	flow_act.modify_hdr = modify_hdr;
+	fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act,
+				  &fs_prot->default_dest, 1);
+	if (IS_ERR(fte)) {
+		err = PTR_ERR(fte);
+		mlx5_core_err(mdev, "fail to add psp rx err copy

rule err=%d\n", err);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +10 -0
+		goto out;
+	}
+	rx_err->rule = fte;
+
+	/* add default drop rule */
+	memset(spec, 0, sizeof(*spec));
+	memset(&flow_act, 0, sizeof(flow_act));
+	/* create fte */
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP;
+	fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act, NULL,

0);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +3 -0
+	if (IS_ERR(fte)) {
+		err = PTR_ERR(fte);
+		mlx5_core_err(mdev, "fail to add psp rx err drop

rule err=%d\n", err);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +19 -0
+		goto out_drop_rule;
+	}
+	rx_err->drop_rule = fte;
+	rx_err->copy_modify_hdr = modify_hdr;
+
+	goto out_spec;
+
+out_drop_rule:
+	mlx5_del_flow_rules(rx_err->rule);
+	rx_err->rule = NULL;
+out:
+	mlx5_modify_header_dealloc(mdev, modify_hdr);
+out_spec:
+	kfree(spec);
+	return err;
+}
+
+static int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs,
+					 struct

mlx5e_accel_fs_psp_prot *fs_prot,

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +1 -0
+					 struct mlx5e_psp_rx_err

*rx_err)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +2 -0
+{
+	struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs,

false);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +7 -0
+	struct mlx5_flow_table_attr ft_attr = {};
+	struct mlx5_flow_table *ft;
+	int err;
+
+	ft_attr.max_fte = 2;
+	ft_attr.autogroup.max_num_groups = 2;
+	ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL; //

MLX5E_ACCEL_FS_TCP_FT_LEVEL

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +5 -0
+	ft_attr.prio = MLX5E_NIC_PRIO;
+	ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
+	if (IS_ERR(ft)) {
+		err = PTR_ERR(ft);
+		mlx5_core_err(fs->mdev, "fail to create psp rx

inline ft err=%d\n", err);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +17 -0
+		return err;
+	}
+
+	rx_err->ft = ft;
+	err = accel_psp_fs_rx_err_add_rule(fs, fs_prot, rx_err);
+	if (err)
+		goto out_err;
+
+	return 0;
+
+out_err:
+	mlx5_destroy_flow_table(ft);
+	rx_err->ft = NULL;
+	return err;
+}
+
+static void accel_psp_fs_rx_fs_destroy(struct

mlx5e_accel_fs_psp_prot *fs_prot)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +22 -0
+{
+	if (fs_prot->def_rule) {
+		mlx5_del_flow_rules(fs_prot->def_rule);
+		fs_prot->def_rule = NULL;
+	}
+
+	if (fs_prot->miss_rule) {
+		mlx5_del_flow_rules(fs_prot->miss_rule);
+		fs_prot->miss_rule = NULL;
+	}
+
+	if (fs_prot->miss_group) {
+		mlx5_destroy_flow_group(fs_prot->miss_group);
+		fs_prot->miss_group = NULL;
+	}
+
+	if (fs_prot->ft) {
+		mlx5_destroy_flow_table(fs_prot->ft);
+		fs_prot->ft = NULL;
+	}
+}
+

 static void setup_fte_udp_psp(struct mlx5_flow_spec *spec, u16 udp_port)
 {
  spec->match_criteria_enable |= MLX5_MATCH_OUTER_HEADERS;

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +0 -0
@@ -41,6 +258,251 @@ static void setup_fte_udp_psp(struct
 mlx5_flow_spec *spec, u16 udp_port)
  	MLX5_SET(fte_match_set_lyr_2_4, spec->match_value,
 ip_protocol, IPPROTO_UDP);
  }

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +2 -0
+static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs,
+				     struct mlx5e_accel_fs_psp_prot

*fs_prot)

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +2 -0
+{
+	struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs,

false);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +1 -0
+	u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] =

{};

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +30 -0
+	int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in);
+	struct mlx5_modify_hdr *modify_hdr = NULL;
+	struct mlx5_flow_table_attr ft_attr = {};
+	struct mlx5_flow_destination dest = {};
+	struct mlx5_core_dev *mdev = fs->mdev;
+	struct mlx5_flow_group *miss_group;
+	MLX5_DECLARE_FLOW_ACT(flow_act);
+	struct mlx5_flow_handle *rule;
+	struct mlx5_flow_spec *spec;
+	struct mlx5_flow_table *ft;
+	u32 *flow_group_in;
+	int err = 0;
+
+	flow_group_in = kvzalloc(inlen, GFP_KERNEL);
+	spec = kvzalloc(sizeof(*spec), GFP_KERNEL);
+	if (!flow_group_in || !spec) {
+		err = -ENOMEM;
+		goto out;
+	}
+
+	/* Create FT */
+	ft_attr.max_fte = 2;
+	ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_LEVEL;
+	ft_attr.prio = MLX5E_NIC_PRIO;
+	ft_attr.autogroup.num_reserved_entries = 1;
+	ft_attr.autogroup.max_num_groups = 1;
+	ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr);
+	if (IS_ERR(ft)) {
+		err = PTR_ERR(ft);
+		mlx5_core_err(mdev, "fail to create psp rx ft

err=%d\n", err);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +6 -0
+		goto out_err;
+	}
+	fs_prot->ft = ft;
+
+	/* Create miss_group */
+	MLX5_SET(create_flow_group_in, flow_group_in,

start_flow_index, ft->max_fte - 1);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +1 -0
+	MLX5_SET(create_flow_group_in, flow_group_in,

end_flow_index, ft->max_fte - 1);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +4 -0
+	miss_group = mlx5_create_flow_group(ft, flow_group_in);
+	if (IS_ERR(miss_group)) {
+		err = PTR_ERR(miss_group);
+		mlx5_core_err(mdev, "fail to create psp rx

miss_group err=%d\n", err);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +6 -0
+		goto out_err;
+	}
+	fs_prot->miss_group = miss_group;
+
+	/* Create miss rule */
+	rule = mlx5_add_flow_rules(ft, spec, &flow_act, &fs_prot-
Quoted 1 line

default_dest, 1);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +3 -0
+	if (IS_ERR(rule)) {
+		err = PTR_ERR(rule);
+		mlx5_core_err(mdev, "fail to create psp rx miss_rule

err=%d\n", err);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +7 -0
+		goto out_err;
+	}
+	fs_prot->miss_rule = rule;
+
+	/* Add default Rx psp rule */
+	setup_fte_udp_psp(spec, PSP_DEFAULT_UDP_PORT);
+	flow_act.crypto.type =

MLX5_FLOW_CONTEXT_ENCRYPT_DECRYPT_TYPE_PSP;

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +4 -0
+	/* Set bit[31, 30] PSP marker */
+	/* Set bit[29-23] psp_syndrome is set in error FT */
+#define MLX5E_PSP_MARKER_BIT (BIT(30) | BIT(31))
+	MLX5_SET(set_action_in, action, action_type,

MLX5_ACTION_TYPE_SET);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +1 -0
+	MLX5_SET(set_action_in, action, field,

MLX5_ACTION_IN_FIELD_METADATA_REG_B);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +5 -0
+	MLX5_SET(set_action_in, action, data, MLX5E_PSP_MARKER_BIT);
+	MLX5_SET(set_action_in, action, offset, 0);
+	MLX5_SET(set_action_in, action, length, 32);
+
+	modify_hdr = mlx5_modify_header_alloc(mdev,

MLX5_FLOW_NAMESPACE_KERNEL, 1, action);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +3 -0
+	if (IS_ERR(modify_hdr)) {
+		err = PTR_ERR(modify_hdr);
+		mlx5_core_err(mdev, "fail to alloc psp set

modify_header_id err=%d\n", err);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +11 -0
+		modify_hdr = NULL;
+		goto out_err;
+	}
+
+	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST |
+			  MLX5_FLOW_CONTEXT_ACTION_CRYPTO_DECRYPT |
+			  MLX5_FLOW_CONTEXT_ACTION_MOD_HDR;
+	flow_act.modify_hdr = modify_hdr;
+	dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
+	dest.ft = fs_prot->rx_err.ft;
+	rule = mlx5_add_flow_rules(fs_prot->ft, spec, &flow_act,

&dest, 1);

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +4 -0
+	if (IS_ERR(rule)) {
+		err = PTR_ERR(rule);
+		mlx5_core_err(mdev,
+			      "fail to add psp rule Rx dycrption,
Quoted 1 line

err=%d, flow_act.action = %#04X\n",

Nit: Typo here, s/dycrption/decryption/

author maintainer
#44 lore raw

PATCH v3 16/19 net/mlx5e: Configure PSP Rx flow steering rules

In reply to Daniel Zahka

From: Raed Salem <[email protected]>

Set the Rx PSP flow steering rule where PSP packet is identified and decrypted using the dedicated UDP destination port number 1000. If packet is decrypted then a PSP marker and syndrome are added to metadata so SW can use it later on in Rx data path.

The rule is set as part of init_rx netdev profile implementation.

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 .../mellanox/mlx5/core/en_accel/en_accel.h    | 14 +++++-
 .../mellanox/mlx5/core/en_accel/psp_fs.c      | 44 ++++++++++++++++---
 .../mellanox/mlx5/core/en_accel/psp_fs.h      |  7 +++
 3 files changed, 59 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +13 -1
index 86496e332b03..f1ff79c863d0 100644
@@ -237,12 +237,24 @@ static inline void mlx5e_accel_tx_finish(struct mlx5e_txqsq *sq,
 
 static inline int mlx5e_accel_init_rx(struct mlx5e_priv *priv)
 {
-	return mlx5e_ktls_init_rx(priv);
+	int err;
+
+	err = mlx5_accel_psp_fs_init_rx_tables(priv);
+	if (err)
+		goto out;
+
+	err = mlx5e_ktls_init_rx(priv);
+	if (err)
+		mlx5_accel_psp_fs_cleanup_rx_tables(priv);
+
+out:
+	return err;
 }
 
 static inline void mlx5e_accel_cleanup_rx(struct mlx5e_priv *priv)
 {
 	mlx5e_ktls_cleanup_rx(priv);
+	mlx5_accel_psp_fs_cleanup_rx_tables(priv);
 }
 
 static inline int mlx5e_accel_init_tx(struct mlx5e_priv *priv)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c +39 -5

59 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.h +7 -0
index d81aeea43505..02215ea67a2d 100644
@@ -12,6 +12,8 @@ struct mlx5e_psp_fs *mlx5e_accel_psp_fs_init(struct mlx5e_priv *priv);
 void mlx5e_accel_psp_fs_cleanup(struct mlx5e_psp_fs *fs);
 int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv);
 void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv);
+int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv);
+void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv);
 #else
 static inline int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv)
 {
@@ -19,5 +21,10 @@ static inline int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv)
 }
 
 static inline void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv) { }
+static inline int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv)
+{
+	return 0;
+}
+static inline void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv) { }
 #endif /* CONFIG_MLX5_EN_PSP */
 #endif /* __MLX5_PSP_FS_H__ */
Signature · 1 line
2.47.1
author maintainer
#45 lore raw

PATCH v3 17/19 psp: provide decapsulation and receive helper for drivers

In reply to Daniel Zahka

From: Raed Salem <[email protected]>

Create psp_rcv(), which drivers can call to psp decapsulate and attach a psp_skb_ext to an skb.

psp_rcv() only supports what the PSP architecture specification refers to as "transport mode" packets, where the L3 header is IPv6. psp_rcv() also assumes that a psp trailer is present and should be pulled from the skb.

---

Notes:
v3:
- patch introduced

 include/net/psp/functions.h |  1 +
 net/psp/psp_main.c          | 49 +++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
include/net/psp/functions.h +1 -0
index afb4f5929eec..8ecc396bcfff 100644
@@ -18,6 +18,7 @@ psp_dev_create(struct net_device *netdev, struct psp_dev_ops *psd_ops,
 void psp_dev_unregister(struct psp_dev *psd);
 bool psp_encapsulate(struct net *net, struct sk_buff *skb,
 		     __be32 spi, u8 ver, __be16 sport);
+int psp_rcv(struct sk_buff *skb, u16 dev_id, u8 generation);
 
 /* Kernel-facing API */
 void psp_assoc_put(struct psp_assoc *pas);
net/psp/psp_main.c +49 -0

55 lines not on this page · raw message

Signature · 1 line
2.47.1
maintainer
#46 lore raw

Re: [PATCH v3 17/19] psp: provide decapsulation and receive helper for drivers

Quoted 28 lines · Daniel Zahka

From: Raed Salem <[email protected]>

Create psp_rcv(), which drivers can call to psp decapsulate and attach a psp_skb_ext to an skb.

psp_rcv() only supports what the PSP architecture specification refers to as "transport mode" packets, where the L3 header is IPv6. psp_rcv() also assumes that a psp trailer is present and should be pulled from the skb.

---

Notes:
v3:
- patch introduced

 include/net/psp/functions.h |  1 +
 net/psp/psp_main.c          | 49 +++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
include/net/psp/functions.h +0 -0
index afb4f5929eec..8ecc396bcfff 100644

include/net/psp/functions.h psp_dev_create(struct net_device *netdev, struct psp_dev_ops *psd_ops, · line 21

Quoted 4 lines
include/net/psp/functions.h +1 -0
@@ -18,6 +18,7 @@ psp_dev_create(struct net_device *netdev, struct psp_dev_ops *psd_ops,
 void psp_dev_unregister(struct psp_dev *psd);
 bool psp_encapsulate(struct net *net, struct sk_buff *skb,
 		     __be32 spi, u8 ver, __be16 sport);
+int psp_rcv(struct sk_buff *skb, u16 dev_id, u8 generation);

If respinning, maybe prefix these device datapath helpers as psp_dev_.

Quoted 36 lines
include/net/psp/functions.h +0 -0
 /* Kernel-facing API */
 void psp_assoc_put(struct psp_assoc *pas);
net/psp/psp_main.c +25 -0
index 8229a004ba6e..ec60e06cdf69 100644
@@ -195,6 +195,55 @@ bool psp_encapsulate(struct net *net, struct sk_buff *skb,
 }
 EXPORT_SYMBOL(psp_encapsulate);
 
+/* Receive handler for PSP packets.
+ *
+ * Presently it accepts only already-authenticated packets and does not
+ * support optional fields, such as virtualization cookies.
+ */
+int psp_rcv(struct sk_buff *skb, u16 dev_id, u8 generation)
+{
+	const struct psphdr *psph;
+	int depth = 0, end_depth;
+	struct psp_skb_ext *pse;
+	struct ipv6hdr *ipv6h;
+	struct ethhdr *eth;
+	__be16 proto;
+	u32 spi;
+
+	eth = (struct ethhdr *)(skb->data);
+	proto = __vlan_get_protocol(skb, eth->h_proto, &depth);
+	if (proto != htons(ETH_P_IPV6))
+		return -EINVAL;
+
+	ipv6h = (struct ipv6hdr *)(skb->data + depth);
+	depth += sizeof(*ipv6h);
+	end_depth = depth + sizeof(struct udphdr) + sizeof(struct psphdr);
+
+	if (unlikely(end_depth > skb_headlen(skb)))

net/psp/psp_main.c bool psp_encapsulate(struct net *net, struct sk_buff *skb, · line 232

Quoted 10 lines
net/psp/psp_main.c +10 -0
+		return -EINVAL;
+
+	pse = skb_ext_add(skb, SKB_EXT_PSP);
+	if (!pse)
+		return -EINVAL;
+
+	psph = (const struct psphdr *)(skb->data + depth + sizeof(struct udphdr));
+	pse->spi = psph->spi;
+	pse->dev_id = dev_id;
+	spi = ntohl(psph->spi);

unused

net/psp/psp_main.c bool psp_encapsulate(struct net *net, struct sk_buff *skb, · line 238

Quoted 6 lines
net/psp/psp_main.c +6 -0
+	pse->generation = generation;
+	pse->version = FIELD_GET(PSPHDR_VERFL_VERSION, psph->verfl);
+
+	ipv6h->nexthdr = psph->nexthdr;
+	ipv6h->payload_len =
+		htons(ntohs(ipv6h->payload_len) - PSP_ENCAP_HLEN - PSP_TRL_SIZE);

Whether the trailer is removed by the device is device specific.

Quoted 14 lines
net/psp/psp_main.c +8 -0
+
+	memmove(skb->data + PSP_ENCAP_HLEN, skb->data, depth);
+	skb_pull(skb, PSP_ENCAP_HLEN);
+
+	return 0;
+}
+EXPORT_SYMBOL(psp_rcv);
+
 static int __init psp_init(void)
 {
 	mutex_init(&psp_devs_lock);
Signature · 1 line
2.47.1
author maintainer
#47 lore raw

PATCH v3 18/19 net/mlx5e: Add Rx data path offload

In reply to Daniel Zahka

From: Raed Salem <[email protected]>

On receive flow inspect received packets for PSP offload indication using the cqe, for PSP offloaded packets set SKB PSP metadata i.e spi, header length and key generation number to stack for further processing.

---

Notes:
v3:
- move psp_rcv() into psp_main.c in a separate commit
v2:
- fill out new pse::dev_id field in psp_rcv()
v1:
- https://lore.kernel.org/netdev/[email protected]/

 .../mellanox/mlx5/core/en_accel/ipsec_rxtx.h  |  2 +-
 .../mellanox/mlx5/core/en_accel/psp_rxtx.c    | 34 +++++++++++++
 .../mellanox/mlx5/core/en_accel/psp_rxtx.h    | 29 +++++++++++
 .../net/ethernet/mellanox/mlx5/core/en_rx.c   | 50 ++++++++++++++-----
 4 files changed, 102 insertions(+), 13 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_rxtx.h +1 -1
index 3cc640669247..45b0d19e735c 100644
@@ -40,7 +40,7 @@
 #include "en/txrx.h"
 
 /* Bit31: IPsec marker, Bit30: reserved, Bit29-24: IPsec syndrome, Bit23-0: IPsec obj id */
-#define MLX5_IPSEC_METADATA_MARKER(metadata)  (((metadata) >> 31) & 0x1)
+#define MLX5_IPSEC_METADATA_MARKER(metadata)  ((((metadata) >> 30) & 0x3) == 0x2)
 #define MLX5_IPSEC_METADATA_SYNDROM(metadata) (((metadata) >> 24) & GENMASK(5, 0))
 #define MLX5_IPSEC_METADATA_HANDLE(metadata)  ((metadata) & GENMASK(23, 0))
 
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c +34 -0
index e85b5db56fff..86ca9b940a4f 100644
@@ -14,6 +14,12 @@
 #include "en_accel/psp_rxtx.h"
 #include "en_accel/psp.h"
 
+enum {
+	MLX5E_PSP_OFFLOAD_RX_SYNDROME_DECRYPTED,
+	MLX5E_PSP_OFFLOAD_RX_SYNDROME_AUTH_FAILED,
+	MLX5E_PSP_OFFLOAD_RX_SYNDROME_BAD_TRAILER,
+};
+
 static void mlx5e_psp_set_swp(struct sk_buff *skb,
 			      struct mlx5e_accel_tx_psp_state *psp_st,
 			      struct mlx5_wqe_eth_seg *eseg)
@@ -113,6 +119,34 @@ static bool mlx5e_psp_set_state(struct mlx5e_priv *priv,
 	return ret;
 }
 
+void mlx5e_psp_csum_complete(struct net_device *netdev, struct sk_buff *skb)
+{
+	pskb_trim(skb, skb->len - PSP_TRL_SIZE);
+}
+
+bool mlx5e_psp_offload_handle_rx_skb(struct net_device *netdev, struct sk_buff *skb,
+				     struct mlx5_cqe64 *cqe)
+{
+	u32 psp_meta_data = be32_to_cpu(cqe->ft_metadata);
+	struct mlx5e_priv *priv = netdev_priv(netdev);
+	u16 dev_id = priv->psp->psp->id;
+	u8 generation = 0;
+
+	/* TBD: report errors as SW counters to ethtool, any further handling ? */
+	if (MLX5_PSP_METADATA_SYNDROM(psp_meta_data) != MLX5E_PSP_OFFLOAD_RX_SYNDROME_DECRYPTED)
+		goto drop;
+
+	if (psp_rcv(skb, dev_id, generation))
+		goto drop;
+
+	skb->decrypted = 1;
+	return false;
+
+drop:
+	kfree_skb(skb);
+	return true;
+}
+
 void mlx5e_psp_tx_build_eseg(struct mlx5e_priv *priv, struct sk_buff *skb,
 			     struct mlx5e_accel_tx_psp_state *psp_st,
 			     struct mlx5_wqe_eth_seg *eseg)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h +29 -0
index 521b2c3620e6..e3cf34bafc24 100644
@@ -10,6 +10,11 @@
 #include "en.h"
 #include "en/txrx.h"
 
+/* Bit30: PSP marker, Bit29-23: PSP syndrome, Bit22-0: PSP obj id */
+#define MLX5_PSP_METADATA_MARKER(metadata)  ((((metadata) >> 30) & 0x3) == 0x3)
+#define MLX5_PSP_METADATA_SYNDROM(metadata) (((metadata) >> 23) & GENMASK(6, 0))
+#define MLX5_PSP_METADATA_HANDLE(metadata)  ((metadata) & GENMASK(22, 0))
+
 struct mlx5e_accel_tx_psp_state {
 	u32 tailen;
 	u32 keyid;
@@ -75,6 +80,16 @@ static inline unsigned int mlx5e_psp_tx_ids_len(struct mlx5e_accel_tx_psp_state
 {
 	return psp_st->tailen;
 }
+
+static inline bool mlx5e_psp_is_rx_flow(struct mlx5_cqe64 *cqe)
+{
+	return MLX5_PSP_METADATA_MARKER(be32_to_cpu(cqe->ft_metadata));
+}
+
+bool mlx5e_psp_offload_handle_rx_skb(struct net_device *netdev, struct sk_buff *skb,
+				     struct mlx5_cqe64 *cqe);
+
+void mlx5e_psp_csum_complete(struct net_device *netdev, struct sk_buff *skb);
 #else
 static inline bool mlx5e_psp_is_offload_state(struct mlx5e_accel_tx_psp_state *psp_state)
 {
@@ -92,5 +107,19 @@ static inline bool mlx5e_psp_txwqe_build_eseg_csum(struct mlx5e_txqsq *sq, struc
 {
 	return false;
 }
+
+static inline bool mlx5e_psp_is_rx_flow(struct mlx5_cqe64 *cqe)
+{
+	return false;
+}
+
+static inline bool mlx5e_psp_offload_handle_rx_skb(struct net_device *netdev,
+						   struct sk_buff *skb,
+						   struct mlx5_cqe64 *cqe)
+{
+	return false;
+}
+
+static inline void mlx5e_psp_csum_complete(struct net_device *netdev, struct sk_buff *skb) { }
 #endif /* CONFIG_MLX5_EN_PSP */
 #endif /* __MLX5E_PSP_RXTX_H__ */
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +38 -12

137 lines not on this page · raw message

Signature · 1 line
2.47.1
#48 lore raw

Re: [PATCH v3 18/19] net/mlx5e: Add Rx data path offload

Quoted 12 lines · Daniel Zahka

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h index 521b2c3620e6..e3cf34bafc24 100644

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h +0 -0
@@ -10,6 +10,11 @@
  #include "en.h"
  #include "en/txrx.h"

drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h +2 -0
+/* Bit30: PSP marker, Bit29-23: PSP syndrome, Bit22-0: PSP obj id */
+#define MLX5_PSP_METADATA_MARKER(metadata)  ((((metadata) >> 30) &
Quoted 3 lines

0x3) == 0x3)
+#define MLX5_PSP_METADATA_SYNDROM(metadata) (((metadata) >> 23) & GENMASK(6, 0))

Nit: This should be named MLX5_PSP_METADATA_SYNDROME, with an E.

Cosmin.

author maintainer
#49 lore raw

PATCH v3 19/19 net/mlx5e: Implement PSP key_rotate operation

In reply to Daniel Zahka

From: Raed Salem <[email protected]>

Implement .key_rotate operation where when invoked will cause the HW to use a new master key to derive PSP spi/key pairs with complience with PSP spec.

---

Notes:
v1:
- https://lore.kernel.org/netdev/[email protected]/

 .../net/ethernet/mellanox/mlx5/core/en_accel/psp.c    | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +11 -0
index fb2b7e4e2f06..f35e3b381c95 100644
@@ -96,11 +96,22 @@ static void mlx5e_psp_assoc_del(struct psp_dev *psd, struct psp_assoc *pas)
 	atomic_dec(&psp->tx_key_cnt);
 }
 
+static int mlx5e_psp_key_rotate(struct psp_dev *psd, struct netlink_ext_ack *exack)
+{
+	struct mlx5e_priv *priv = netdev_priv(psd->main_netdev);
+
+	/* no support for protecting against external rotations */
+	psd->generation = 0;
+
+	return mlx5e_psp_rotate_key(priv->mdev);
+}
+
 static struct psp_dev_ops mlx5_psp_ops = {
 	.set_config   = mlx5e_psp_set_config,
 	.rx_spi_alloc = mlx5e_psp_rx_spi_alloc,
 	.tx_key_add   = mlx5e_psp_assoc_add,
 	.tx_key_del   = mlx5e_psp_assoc_del,
+	.key_rotate   = mlx5e_psp_key_rotate,
 };
 
 void mlx5e_psp_unregister(struct mlx5e_priv *priv)
Signature · 1 line
2.47.1
Acked-by on the v3 series
#50 lore raw
In reply to Daniel Zahka
Quoted 115 lines · Daniel Zahka

This is v3 of the PSP RFC [1] posted by Jakub Kicinski one year ago. General developments since v1 include a fork of packetdrill [2] with support for PSP added, as well as some test cases, and an implementation of PSP key exchange and connection upgrade [3] integrated into the fbthrift RPC library. Both [2] and [3] have been tested on server platforms with PSP-capable CX7 NICs. Below is the cover letter from the original RFC:

Add support for PSP encryption of TCP connections.

PSP is a protocol out of Google:
https://github.com/google/psp/blob/main/doc/PSP_Arch_Spec.pdf
which shares some similarities with IPsec. I added some more info in the first patch so I'll keep it short here.

The protocol can work in multiple modes including tunneling. But I'm mostly interested in using it as TLS replacement because of its superior offload characteristics. So this patch does three things:

- it adds "core" PSP code
PSP is offload-centric, and requires some additional care and feeding, so first chunk of the code exposes device info. This part can be reused by PSP implementations in xfrm, tunneling etc.

- TCP integration TLS style
Reuse some of the existing concepts from TLS offload, such as attaching crypto state to a socket, marking skbs as "decrypted", egress validation. PSP does not prescribe key exchange protocols. To use PSP as a more efficient TLS offload we intend to perform a TLS handshake ("inline" in the same TCP connection) and negotiate switching to PSP based on capabilities of both endpoints. This is also why I'm not including a software implementation. Nobody would use it in production, software TLS is faster, it has larger crypto records.

- mlx5 implementation
That's mostly other people's work, not 100% sure those folks consider it ready hence the RFC in the title. But it works :)

Not posted, queued a branch [4] are follow up pieces:
- standard stats
- netdevsim implementation and tests

[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://github.com/danieldzahka/packetdrill
[3] https://github.com/danieldzahka/fbthrift/tree/dzahka/psp
[4] https://github.com/kuba-moo/linux/tree/psp

Comments we intend to defer to future series:
- using INDIRECT_CALL for tls/psp in sk_validate_xmit_skb(). We prefer to address this in a dedicated patch series, so that this series does not need to modify the way tls_validate_xmit_skb() is declared and stubbed out.

CHANGES:
v3:
- move psp_rcv() and psp_encapsulate() driver helpers into psp_main.c
- lift pse/pas comparison code into new function:
psp_pse_matches_pas()
- explicitly mark rcu critical section psp_reply_set_decrypted()
- use rcu_dereference_proteced() instead of rcu_read_lock() in psp_sk_assoc_free() and psp_twsk_assoc_free()
- rename psp_is_nondata() to psp_is_allowed_nondata()
- psp_reply_set_decrypted() should not call psp_sk_assoc(). Call psp_sk_get_assoc_rcu() instead.
- lift common code from timewait and regular socks into new function psp_sk_get_assoc_rcu()
- export symbols in psp_sock.c with EXPORT_IPV6_MOD_GPL()
- check for sk_is_inet() before casting to inet_twsk() in sk_validate_xmit() and in psp_get_assoc_rcu()
- psp_reply_set_decrypted() does not use stuct sock* arg. Drop it.
- reword driver requirement about double rotating keys when the device supports requesting arbitrary spi key pairs.

v2: https://lore.kernel.org/netdev/[email protected]/
- add pas->dev_id == pse->dev_id to policy checks
- __psp_sk_rx_policy_check() now allows pure ACKs, FINs, and RSTs to be non-psp authenticated before "PSP Full" state.
- assign tw_validate_skb funtion during psp_twsk_init()
- psp_skb_get_rcu() also checks if sk is a tcp timewait sock when looking for psp assocs.
- scan ofo queue non-psp data during psp_sock_recv_queue_check()
- add tcp_write_collapse_fence() to psp_sock_assoc_set_tx()
- Add psp_reply_set_decrypted() to encapsulate ACKs, FINs, and RSTs sent from control socks on behalf of full or timewait socks with PSP state.
- Add dev_id field to psp_skb_ext
- Move psp_assoc from struct tcp_timewait_sock to struct inet_timewait_sock
- Move psp_sk_assoc_free() from sk_common_release() to inet_sock_destruct()
- add documentation about MITM deletion attack, and expectation from userspace
- add information about accepting clear text ACKs, RSTs, and FINs to Securing Connections section.

v1: https://lore.kernel.org/netdev/[email protected]/

Daniel Zahka (2):
net: move sk_validate_xmit_skb() to net/core/dev.c
net: tcp: allow tcp_timewait_sock to validate skbs before handing to
device

Jakub Kicinski (8):
psp: add documentation
psp: base PSP device support
net: modify core data structures for PSP datapath support
tcp: add datapath logic for PSP with inline key exchange
psp: add op for rotation of device key
net: psp: add socket security association code
net: psp: update the TCP MSS to reflect PSP packet overhead
psp: track generations of device key

Quoted 11 lines

Raed Salem (9):
net/mlx5e: Support PSP offload functionality net/mlx5e: Implement PSP operations .assoc_add and .assoc_del
psp: provide encapsulation helper for drivers net/mlx5e: Implement PSP Tx data path
net/mlx5e: Add PSP steering in local NIC RX net/mlx5e: Configure PSP Rx flow steering rules
psp: provide decapsulation and receive helper for drivers net/mlx5e: Add Rx data path offload
net/mlx5e: Implement PSP key_rotate operation

For the mlx5 parts:

Thanks.

Quoted 85 lines
  Documentation/netlink/specs/psp.yaml          | 188 +++++
  Documentation/networking/index.rst            |   1 +
  Documentation/networking/psp.rst              | 183 +++++
  .../net/ethernet/mellanox/mlx5/core/Kconfig   |  11 +
  .../net/ethernet/mellanox/mlx5/core/Makefile  |   5 +-
  drivers/net/ethernet/mellanox/mlx5/core/en.h  |   6 +-
  .../net/ethernet/mellanox/mlx5/core/en/fs.h   |   2 +-
  .../ethernet/mellanox/mlx5/core/en/params.c   |   4 +-
  .../mellanox/mlx5/core/en_accel/en_accel.h    |  50 +-
  .../mellanox/mlx5/core/en_accel/ipsec_rxtx.h  |   2 +-
  .../mellanox/mlx5/core/en_accel/psp.c         | 209 +++++
  .../mellanox/mlx5/core/en_accel/psp.h         |  55 ++
  .../mellanox/mlx5/core/en_accel/psp_fs.c      | 736 ++++++++++++++++++
  .../mellanox/mlx5/core/en_accel/psp_fs.h      |  30 +
  .../mellanox/mlx5/core/en_accel/psp_offload.c |  52 ++
  .../mellanox/mlx5/core/en_accel/psp_rxtx.c    | 204 +++++
  .../mellanox/mlx5/core/en_accel/psp_rxtx.h    | 125 +++
  .../net/ethernet/mellanox/mlx5/core/en_main.c |   9 +
  .../net/ethernet/mellanox/mlx5/core/en_rx.c   |  50 +-
  .../net/ethernet/mellanox/mlx5/core/en_tx.c   |  10 +-
  drivers/net/ethernet/mellanox/mlx5/core/fw.c  |   6 +
  .../ethernet/mellanox/mlx5/core/lib/crypto.h  |   1 +
  .../net/ethernet/mellanox/mlx5/core/main.c    |   5 +
  drivers/net/ethernet/mellanox/mlx5/core/psp.c |  24 +
  drivers/net/ethernet/mellanox/mlx5/core/psp.h |  15 +
  include/linux/mlx5/device.h                   |   4 +
  include/linux/mlx5/driver.h                   |   2 +
  include/linux/mlx5/mlx5_ifc.h                 |  94 ++-
  include/linux/netdevice.h                     |   4 +
  include/linux/skbuff.h                        |   3 +
  include/net/dropreason-core.h                 |   6 +
  include/net/inet_timewait_sock.h              |   8 +
  include/net/psp.h                             |  12 +
  include/net/psp/functions.h                   | 203 +++++
  include/net/psp/types.h                       | 187 +++++
  include/net/sock.h                            |  26 +-
  include/uapi/linux/psp.h                      |  66 ++
  net/Kconfig                                   |   1 +
  net/Makefile                                  |   1 +
  net/core/dev.c                                |  32 +
  net/core/gro.c                                |   2 +
  net/core/skbuff.c                             |   4 +
  net/ipv4/af_inet.c                            |   2 +
  net/ipv4/inet_timewait_sock.c                 |   6 +-
  net/ipv4/ip_output.c                          |   5 +-
  net/ipv4/tcp.c                                |   2 +
  net/ipv4/tcp_ipv4.c                           |  14 +-
  net/ipv4/tcp_minisocks.c                      |  16 +
  net/ipv4/tcp_output.c                         |  17 +-
  net/ipv6/ipv6_sockglue.c                      |   6 +-
  net/ipv6/tcp_ipv6.c                           |  17 +-
  net/psp/Kconfig                               |  15 +
  net/psp/Makefile                              |   5 +
  net/psp/psp-nl-gen.c                          | 119 +++
  net/psp/psp-nl-gen.h                          |  39 +
  net/psp/psp.h                                 |  54 ++
  net/psp/psp_main.c                            | 254 ++++++
  net/psp/psp_nl.c                              | 517 ++++++++++++
  net/psp/psp_sock.c                            | 297 +++++++
  tools/net/ynl/Makefile.deps                   |   1 +
  60 files changed, 3962 insertions(+), 62 deletions(-)

create mode 100644 Documentation/netlink/specs/psp.yaml
create mode 100644 Documentation/networking/psp.rst
create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_fs.h create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_offload.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/psp.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/psp.h create mode 100644 include/net/psp.h
create mode 100644 include/net/psp/functions.h
create mode 100644 include/net/psp/types.h
create mode 100644 include/uapi/linux/psp.h
create mode 100644 net/psp/Kconfig
create mode 100644 net/psp/Makefile
create mode 100644 net/psp/psp-nl-gen.c
create mode 100644 net/psp/psp-nl-gen.h
create mode 100644 net/psp/psp.h
create mode 100644 net/psp/psp_main.c
create mode 100644 net/psp/psp_nl.c
create mode 100644 net/psp/psp_sock.c

#51 lore raw
Quoted 5 lines · Tariq Toukan

For the mlx5 parts:

Thanks.

Hi Daniel,

I left a few comments from my old TODOs regarding this series. There were more, but some of them were addressed since I wrote them down and I only commented on the trivial cleanups/improvements that could be done now, I didn't want to hold up the series for too long. There are a few things which are more involved and could be changed later once this is merged.

Also, since I ended up massaging these patches in the past (similar to Rahul), perhaps it makes sense to add me to the mlx5 parts as "Signed- off-by"?

Cosmin.