Skip to contentSkip to conversation

psp: use virt cookie as Rx steering hint

RFC In review Jakub Kicinski 4 participants 18 messages Aug 22 – Aug 25

Subsystems (9)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

cover psp: use virt cookie as Rx steering hint

Hi!

This PoC series uses a field of the PSP header intended for tunnels to auto-steer Rx traffic. Various attempts have been made at trying to get Rx traffic to land close to the core where the application runs. By default RSS picks the Rx queue based on the flow hash. I'm not going to cover all previous solutions in detail but broadly
- we have RFS in SW which looks on which CPU Tx happens and backlogs Rx packets there, it is quite efficient. aRFS is built on top of RFS but tries to program flows into the NIC. Some NICs have a "cache" and try to automatically remember the flow to queue association.

All those solutions are entirely local to the receiver. Ideally we would want the solution to look something like TCP timestamp option - we send an opaque cookie to the peer, and the peer echoes it back to us. Our NIC can steer based on that echoed cookie.

This patch set implements exactly that using the optional PSP Virtualization Cookie field. The PSP standard doesn't have much to say about this field:

Virtualization Cookie - 64b
An optional field, present if and only if V is set.
It may contain a Virtual Network Identifier (VNI) or other data, as defined by the implementation.

IOW it's a field in the header which can be used as VNI, so presumably most PSP-capable NICs will be able to feed it into some TCAM lookup. The main use of this field is when PSP is used for tunneling. Nothing in the standard precludes it's use in transport mode.

This patchset splits this field as follows:

63 48 47 32 31 16 15 0

  +---------------+---------------+---------------+---------------+
  |    reserved   |    req qid    |    reserved   |    dst qid    |
  +---------------+---------------+---------------+---------------+

"req" is the value we want sender to put in "dst" when they respond.

When the feature is enabled we expect the NIC to create low-priority steering rules matching on "dst" (bottom 16b of the Virt Cookie). The mapping is direct today so dst=2 means queue=2 within the receiving interface (see doc in patch 1 for more info). Any explicit steering rules (ethtool, TC etc) still take precedence over PSP steering, we are only overriding the RSS queue assignment.

I'm sharing this as an RFC because I _think_ it's a good idea (feedback most welcome). We need some vendor cooperation to get this implemented - specifically IDK how to make mlx5 (the only PSP-capable NIC I have access to) to do the steering :(

Jakub Kicinski (6):
psp: steer Rx queues with the virtualization cookie
netdevsim: support PSP VC based queue steering
selftests: drv-net: psp: move the PSP test plumbing into psp_lib.py
selftests: drv-net: psp_steer: test PSP VC based queue steering
selftests: drv-net: psp_steer: test where PSP steering sits in the Rx
pipeline
selftests: drv-net: psp_steer: cover corner cases and races

 MAINTAINERS                                   |   1 +
 Documentation/netlink/specs/psp.yaml          |  42 ++
 Documentation/networking/psp.rst              |  75 +++
 tools/testing/selftests/drivers/net/Makefile  |   5 +
 include/net/psp/types.h                       |  93 +++-
 drivers/net/netdevsim/netdevsim.h             |   4 +-
 include/net/psp/functions.h                   |  54 +-
 include/uapi/linux/psp.h                      |  17 +
 .../mellanox/mlx5/core/en_accel/psp_rxtx.c    |   2 +-
 drivers/net/netdevsim/netdev.c                |   5 +-
 drivers/net/netdevsim/psp.c                   |  26 +-
 net/psp/psp-nl-gen.c                          |   5 +-
 net/psp/psp_main.c                            |  53 +-
 net/psp/psp_nl.c                              |  21 +-
 net/psp/psp_sock.c                            |  35 ++
 .../selftests/drivers/net/psp_responder.c     |  42 ++
 tools/testing/selftests/drivers/net/psp.py    | 287 +++--------
 .../testing/selftests/drivers/net/psp_lib.py  | 184 +++++++
 .../selftests/drivers/net/psp_steer.py        | 473 ++++++++++++++++++
 19 files changed, 1187 insertions(+), 237 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/psp_lib.py
 create mode 100644 tools/testing/selftests/drivers/net/psp_steer.py
Signature · 1 line
2.55.0
author maintainer
#1 lore raw

RFC 1/6 psp: steer Rx queues with the virtualization cookie

PSP leaves the 64b virtualization cookie undefined in transport mode. Put it to use: let both ends of a connection tell each other which Rx queue they want traffic on, so that a flow can be pinned to a queue without the receiver having to install a per-flow steering rule, and without the sender having to know anything about the receiver's queue layout. The cookie holds a queue ID the sender is asking the peer to send to ("req") and the queue ID the peer last asked for, granted ("dst"). Each ID gets a 32b word of the cookie to itself and uses only the low half of it, so that either can grow to 32b later without the fields moving.

The two directions are configured separately:

* rx asks peers to send to the queue paired with the flow's Tx queue, so traffic this host receives gets steered. The receiver installs one low priority rule per Rx queue matching "dst", which wins over RSS, so this needs vc-steer-cap.
* tx grants the requests peers make, so traffic this host sends gets steered at the far end. The queue is the peer's to pick and the rules are the peer's to install, so this needs nothing from the local device and can be turned on where vc-steer-cap is absent.

Splitting them is what makes one sided deployment work. Turn granting on everywhere, cheaply, and asking wherever the NIC can actually do it.

The steering itself is entirely a device matter, the core only has to move the two queue IDs around. That is why the Tx side hooks psp_validate_xmit(): it is the one PSP-specific callback which runs after netdev_core_pick_tx() has stamped the queue and still has the netdev at hand.

---
 Documentation/netlink/specs/psp.yaml          | 42 +++++++++
 Documentation/networking/psp.rst              | 75 +++++++++++++++
 include/net/psp/types.h                       | 93 ++++++++++++++++++-
 include/net/psp/functions.h                   | 54 ++++++++++-
 include/uapi/linux/psp.h                      | 17 ++++
 .../mellanox/mlx5/core/en_accel/psp_rxtx.c    |  2 +-
 drivers/net/netdevsim/psp.c                   |  2 +-
 net/psp/psp-nl-gen.c                          |  5 +-
 net/psp/psp_main.c                            | 53 +++++++----
 net/psp/psp_nl.c                              | 21 ++++-
 net/psp/psp_sock.c                            | 35 +++++++
 11 files changed, 373 insertions(+), 26 deletions(-)
Documentation/netlink/specs/psp.yaml +42 -0
index e9c2ee7e28e0..a65274920d21 100644
@@ -11,6 +11,24 @@ name: psp
     name: version
     entries: [hdr0-aes-gcm-128, hdr0-aes-gcm-256,
               hdr0-aes-gmac-128, hdr0-aes-gmac-256]
+  -
+    type: enum
+    name: vc-steer
+    doc: Directions of traffic which take part in VC based queue steering.
+    entries:
+      -
+        name: tx
+        doc: |
+          Grant the requests peers make, so that traffic this device
+          sends is steered at the far end. Costs nothing but the room in
+          the header, the queue is the peer's to pick, so this does not
+          need vc-steer-cap.
+      -
+        name: rx
+        doc: |
+          Ask peers to send to the Rx queue paired with the flow's Tx
+          queue, so that traffic this device receives is steered. Needs
+          vc-steer-cap, the rules doing the steering are ours.
 
 attribute-sets:
   -
@@ -72,6 +90,27 @@ name: psp
           Present when in associated namespace, absent when in primary/host
           namespace.
         type: flag
+      -
+        name: vc-steer-cap
+        doc: |
+          Device can steer received traffic on the PSP virtualization
+          cookie (VC). The VC is split into a 32b reserved part, a 16b
+          queue ID the sender is asking the peer to send to, and a 16b
+          queue ID granting the peer's own request. Steering installs low
+          priority rules matching the latter, which win over the RSS table
+          result. Only needed for the rx direction; granting a peer's
+          request is just header generation and needs no device support.
+        type: flag
+      -
+        name: vc-steer-ena
+        doc: |
+          Directions taking part in VC based queue steering. Leave the
+          attribute out of a dev-set request to keep the current setting.
+          Applies to associations created from then on, existing ones keep
+          the setting they were created with.
+        type: u32
+        enum: vc-steer
+        enum-as-flags: true
 
   -
     name: assoc
@@ -207,6 +246,8 @@ name: psp
             - psp-versions-ena
             - assoc-list
             - by-association
+            - vc-steer-cap
+            - vc-steer-ena
         pre: psp-device-get-locked
         post: psp-device-unlock
       dump:
@@ -231,6 +272,7 @@ name: psp
           attributes:
             - id
             - psp-versions-ena
+            - vc-steer-ena
         reply:
           attributes: []
         pre: psp-device-get-locked-admin
Documentation/networking/psp.rst +75 -0

87 lines not on this page · raw message

include/net/psp/types.h +92 -1

145 lines not on this page · raw message

include/net/psp/functions.h +51 -3

85 lines not on this page · raw message

include/uapi/linux/psp.h +17 -0
index 1c8899cd4da5..15e276ea84fb 100644
@@ -17,6 +17,21 @@ enum psp_version {
 	PSP_VERSION_HDR0_AES_GMAC_256,
 };
 
+/**
+ * enum psp_vc_steer - Directions of traffic which take part in VC based queue
+ *   steering.
+ * @PSP_VC_STEER_TX: Grant the requests peers make, so that traffic this device
+ *   sends is steered at the far end. Costs nothing but the room in the header,
+ *   the queue is the peer's to pick, so this does not need vc-steer-cap.
+ * @PSP_VC_STEER_RX: Ask peers to send to the Rx queue paired with the flow's
+ *   Tx queue, so that traffic this device receives is steered. Needs
+ *   vc-steer-cap, the rules doing the steering are ours.
+ */
+enum psp_vc_steer {
+	PSP_VC_STEER_TX,
+	PSP_VC_STEER_RX,
+};
+
 enum {
 	PSP_A_ASSOC_DEV_INFO_IFINDEX = 1,
 	PSP_A_ASSOC_DEV_INFO_NSID,
@@ -33,6 +48,8 @@ enum {
 	PSP_A_DEV_ASSOC_LIST,
 	PSP_A_DEV_NSID,
 	PSP_A_DEV_BY_ASSOCIATION,
+	PSP_A_DEV_VC_STEER_CAP,
+	PSP_A_DEV_VC_STEER_ENA,
 
 	__PSP_A_DEV_MAX,
 	PSP_A_DEV_MAX = (__PSP_A_DEV_MAX - 1)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c +1 -1
index 348fd7a96261..5df17efae127 100644
@@ -171,7 +171,7 @@ bool mlx5e_psp_handle_tx_skb(struct net_device *netdev,
 		return true;
 
 	/* psp_encap of the packet */
-	if (!psp_dev_encapsulate(net, skb, psp_st->spi, psp_st->ver, 0)) {
+	if (!psp_dev_encapsulate(net, skb, psp_st->spi, psp_st->ver, 0, 0)) {
 		kfree_skb_reason(skb, SKB_DROP_REASON_PSP_OUTPUT);
 		atomic_inc(&priv->psp->tx_drop);
 		return false;
drivers/net/netdevsim/psp.c +1 -1
index 6b3532b5e360..32d95205a8cc 100644
@@ -44,7 +44,7 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
 	}
 
 	net = sock_net(skb->sk);
-	if (!psp_dev_encapsulate(net, skb, pas->tx.spi, pas->version, 0)) {
+	if (!psp_dev_encapsulate(net, skb, pas->tx.spi, pas->version, 0, 0)) {
 		rc = SKB_DROP_REASON_PSP_OUTPUT;
 		goto out_unlock;
 	}
net/psp/psp-nl-gen.c +3 -2
index 0e426ffac398..743de854aca5 100644
@@ -23,9 +23,10 @@ static const struct nla_policy psp_dev_get_nl_policy[PSP_A_DEV_ID + 1] = {
 };
 
 /* PSP_CMD_DEV_SET - do */
-static const struct nla_policy psp_dev_set_nl_policy[PSP_A_DEV_PSP_VERSIONS_ENA + 1] = {
+static const struct nla_policy psp_dev_set_nl_policy[PSP_A_DEV_VC_STEER_ENA + 1] = {
 	[PSP_A_DEV_ID] = NLA_POLICY_MIN(NLA_U32, 1),
 	[PSP_A_DEV_PSP_VERSIONS_ENA] = NLA_POLICY_MASK(NLA_U32, 0xf),
+	[PSP_A_DEV_VC_STEER_ENA] = NLA_POLICY_MASK(NLA_U32, 0x3),
 };
 
 /* PSP_CMD_KEY_ROTATE - do */
@@ -89,7 +90,7 @@ static const struct genl_split_ops psp_nl_ops[] = {
 		.doit		= psp_nl_dev_set_doit,
 		.post_doit	= psp_device_unlock,
 		.policy		= psp_dev_set_nl_policy,
-		.maxattr	= PSP_A_DEV_PSP_VERSIONS_ENA,
+		.maxattr	= PSP_A_DEV_VC_STEER_ENA,
 		.flags		= GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
 	},
 	{
net/psp/psp_main.c +36 -17

112 lines not on this page · raw message

net/psp/psp_nl.c +20 -1
index f91665748dde..b5f1bfd8bdcf 100644
@@ -299,6 +299,11 @@ psp_nl_dev_fill(struct psp_dev *psd, struct sk_buff *rsp,
 	    nla_put_u32(rsp, PSP_A_DEV_PSP_VERSIONS_ENA, psd->config.versions))
 		goto err_cancel_msg;
 
+	if (psd->caps->vc_steer && nla_put_flag(rsp, PSP_A_DEV_VC_STEER_CAP))
+		goto err_cancel_msg;
+	if (nla_put_u32(rsp, PSP_A_DEV_VC_STEER_ENA, psd->config.vc_steer))
+		goto err_cancel_msg;
+
 	if (cur_net == dev_net(psd->main_netdev)) {
 		/* Primary device - dump assoc list */
 		err = psp_nl_fill_assoc_dev_list(psd, rsp, cur_net, NULL);
@@ -418,11 +423,25 @@ int psp_nl_dev_set_doit(struct sk_buff *skb, struct genl_info *info)
 			NL_SET_ERR_MSG(info->extack, "Requested PSP versions not supported by the device");
 			return -EINVAL;
 		}
-	} else {
+	} else if (!info->attrs[PSP_A_DEV_VC_STEER_ENA]) {
 		NL_SET_ERR_MSG(info->extack, "No settings present");
 		return -EINVAL;
 	}
 
+	if (info->attrs[PSP_A_DEV_VC_STEER_ENA]) {
+		new_config.vc_steer =
+			nla_get_u32(info->attrs[PSP_A_DEV_VC_STEER_ENA]);
+		/* Granting a peer's request is just header generation,
+		 * only steering our own Rx needs the device to help.
+		 */
+		if (new_config.vc_steer & (1 << PSP_VC_STEER_RX) &&
+		    !psd->caps->vc_steer) {
+			NL_SET_BAD_ATTR(info->extack,
+					info->attrs[PSP_A_DEV_VC_STEER_ENA]);
+			return -EOPNOTSUPP;
+		}
+	}
+
 	rsp = psp_nl_reply_new(info);
 	if (!rsp)
 		return -ENOMEM;
net/psp/psp_sock.c +35 -0
index 1a2a6b7516b0..1594767e5184 100644
@@ -26,6 +26,32 @@ struct psp_dev *psp_dev_get_for_sock(struct sock *sk)
 	return psd;
 }
 
+/* Refresh the local queue ID we ask the peer to send to.
+ *
+ * Rx and Tx queues are assumed to be paired by index, so the Tx queue the
+ * stack has just picked for this flow doubles as the Rx queue we expect
+ * the flow's replies to land on. This is the Tx side counterpart of an
+ * aRFS update, and runs for every skb of a steered PSP socket, so the
+ * unchanged case has to stay down to a load and a compare.
+ */
+static void psp_assoc_vc_tx_update(struct psp_assoc *pas,
+				   struct net_device *dev,
+				   struct sk_buff *skb)
+{
+	u16 qid = skb_get_queue_mapping(skb);
+
+	/* A device may have more Tx than Rx queues, in which case the top
+	 * Tx queues have no Rx queue to pair with.
+	 */
+	if (unlikely(qid >= READ_ONCE(dev->real_num_rx_queues)))
+		qid = PSP_VC_QID_NONE;
+
+	if (likely(qid == READ_ONCE(pas->vc_loc)))
+		return;
+
+	WRITE_ONCE(pas->vc_loc, qid);
+}
+
 static struct sk_buff *
 psp_validate_xmit(struct sock *sk, struct net_device *dev, struct sk_buff *skb)
 {
@@ -35,6 +61,8 @@ psp_validate_xmit(struct sock *sk, struct net_device *dev, struct sk_buff *skb)
 	rcu_read_lock();
 	pas = psp_skb_get_assoc_rcu(skb);
 	good = !pas || rcu_access_pointer(dev->psp_dev) == pas->psd;
+	if (good && pas && pas->flags & PSP_ASSOC_VC_RX)
+		psp_assoc_vc_tx_update(pas, dev, skb);
 	rcu_read_unlock();
 	if (!good) {
 		sk_skb_reason_drop(sk, skb, SKB_DROP_REASON_PSP_OUTPUT);
@@ -58,6 +86,13 @@ struct psp_assoc *psp_assoc_create(struct psp_dev *psd)
 	pas->psd = psd;
 	pas->dev_id = psd->id;
 	pas->generation = psd->generation;
+	pas->vc_loc = PSP_VC_QID_NONE;
+	pas->vc_rem = PSP_VC_QID_NONE;
+	/* Snapshot the config, the header size may not change later on */
+	if (psd->config.vc_steer & (1 << PSP_VC_STEER_TX))
+		pas->flags |= PSP_ASSOC_VC_TX;
+	if (psd->config.vc_steer & (1 << PSP_VC_STEER_RX))
+		pas->flags |= PSP_ASSOC_VC_RX;
 	psp_dev_get(psd);
 	refcount_set(&pas->refcnt, 1);
 
Signature · 1 line
2.55.0
maintainer
#2 lore raw

Re: [RFC net-next 1/6] psp: steer Rx queues with the virtualization cookie

Quoted 16 lines · Jakub Kicinski
Documentation/netlink/specs/psp.yaml +12 -0
@@ -72,6 +90,27 @@ name: psp
           Present when in associated namespace, absent when in primary/host
           namespace.
         type: flag
+      -
+        name: vc-steer-cap
+        doc: |
+          Device can steer received traffic on the PSP virtualization
+          cookie (VC). The VC is split into a 32b reserved part, a 16b
+          queue ID the sender is asking the peer to send to, and a 16b
+          queue ID granting the peer's own request. Steering installs low
+          priority rules matching the latter, which win over the RSS table
+          result. Only needed for the rx direction; granting a peer's
+          request is just header generation and needs no device support.
+        type: flag
+      -

Documentation/netlink/specs/psp.yaml name: psp · line 114

Quoted 10 lines
Documentation/netlink/specs/psp.yaml +9 -0
+        name: vc-steer-ena
+        doc: |
+          Directions taking part in VC based queue steering. Leave the
+          attribute out of a dev-set request to keep the current setting.
+          Applies to associations created from then on, existing ones keep
+          the setting they were created with.
+        type: u32
+        enum: vc-steer
+        enum-as-flags: true
 

Should vc-steer-ena be a connection level setting? Maybe it could go into rx-assoc. The way it's implemented here, the state is already per assoc.

Documentation/networking/psp.rst Drivers must use ``psp_skb_get_assoc_rcu()`` to check if PSP Tx offload · line 249

Quoted 13 lines
Documentation/networking/psp.rst +13 -0
+Every driver has to carry the cookie, not just those which advertise
+``vc-steer-cap`` - granting a peer's request needs no help from the
+device, so the ``tx`` direction of ``vc-steer-ena`` may be turned on
+anywhere. Drivers must ask ``psp_assoc_vc_tx_get()`` for the cookie to
+place in the Tx header, and report the queue IDs a received cookie held
+in ``psp_skb_ext.vc_req`` and ``vc_dst`` (``psp_dev_rcv()`` does this for
+drivers which let the core strip the headers). Reporting is what allows
+the core to grant the peer's request. The steering itself is only
+expected of drivers which advertise ``vc-steer-cap``.
+
+When VC steering is enabled GRO implementations are allowed to ignore
+changes in the cookie for transport mode PSP.
+

Makes sense. Do we would need to update __psp_skb_coalesce_diff() here then for the sw gro?

Quoted 15 lines

struct psp_assoc {

include/net/psp/types.h +8 -0
 	struct psp_dev *psd;
@@ -159,6 +233,23 @@ struct psp_assoc {
 	u8 generation;
 	u8 version;
 	u8 peer_tx;
+	/* enum psp_assoc_flags. Written under psd->lock, additionally read
+	 * on the Tx fast path without it. A snapshot of the device config
+	 * taken when the association was created, so that the header size,
+	 * and with it the MSS, cannot change under an established
+	 * connection.
+	 */
+	u8 flags;
+

include/net/psp/types.h struct psp_assoc { · line 253

Quoted 10 lines
include/net/psp/types.h +9 -0
+	/* Queue IDs for the VC, ours and the peer's. @vc_loc is refreshed
+	 * from the Tx queue selection and goes out as the cookie's request,
+	 * @vc_rem is learned from the peer's requests and goes back out as
+	 * the destination. Both are PSP_VC_QID_NONE until something is
+	 * learned. Written without the socket lock, always use
+	 * READ_ONCE()/WRITE_ONCE().
+	 */
+	u16 vc_loc;
+	u16 vc_rem;
 

Unrelated, but this reminds me: some of the other fields here:
generation, spi, peer_tx, have some reads/writes that probably require READ/WRITE_ONCE() and maybe deserve a similar comment here... Probably all bugs that I introduced :/

Quoted 12 lines
net/psp/psp_main.c +3 -2
 /* Encapsulate a TCP packet with PSP by adding the UDP+PSP headers and filling
- * them in.
+ * them in. @vc is the virtualization cookie to place in the header, 0 for
+ * a header with no optional fields.
  */
 bool psp_dev_encapsulate(struct net *net, struct sk_buff *skb, __be32 spi,
-			 u8 ver, __be16 sport)
+			 u8 ver, __be16 sport, u64 vc)
 {
 	u32 network_len = skb_network_header_len(skb);
 	u32 ethr_len = skb_mac_header_len(skb);
 	u32 bufflen = ethr_len + network_len;

net/psp/psp_main.c static void psp_write_headers(struct net *net, struct sk_buff *skb, __be32 spi, · line 267

Quoted 10 lines
net/psp/psp_main.c +4 -1
+	u32 encap_len = PSP_ENCAP_HLEN;
 
 	if (skb->protocol != htons(ETH_P_IP) &&
 	    skb->protocol != htons(ETH_P_IPV6))
 		return false;
 
-	if (skb_cow_head(skb, PSP_ENCAP_HLEN))
+	if (vc)
+		encap_len += PSP_VC_SIZE;
+

I suppose vc of 0 is probably valid. We might need something else to disambiguate "not present".

author maintainer
#3 lore raw

Re: [RFC net-next 1/6] psp: steer Rx queues with the virtualization cookie

Quoted 23 lines · On Sun, 23 Aug 2026 11:31:03 -0400 Daniel Zahka wrote:
Quoted 22 lines · Jakub Kicinski
Documentation/netlink/specs/psp.yaml +18 -0
@@ -72,6 +90,27 @@ name: psp
           Present when in associated namespace, absent when in primary/host
           namespace.
         type: flag
+      -
+        name: vc-steer-cap
+        doc: |
+          Device can steer received traffic on the PSP virtualization
+          cookie (VC). The VC is split into a 32b reserved part, a 16b
+          queue ID the sender is asking the peer to send to, and a 16b
+          queue ID granting the peer's own request. Steering installs low
+          priority rules matching the latter, which win over the RSS table
+          result. Only needed for the rx direction; granting a peer's
+          request is just header generation and needs no device support.
+        type: flag
+      -
+        name: vc-steer-ena
+        doc: |
+          Directions taking part in VC based queue steering. Leave the
+          attribute out of a dev-set request to keep the current setting.
+          Applies to associations created from then on, existing ones keep
+          the setting they were created with.
Quoted 8 lines

Documentation/netlink/specs/psp.yaml name: psp · line 114

Quoted 4 lines
Documentation/netlink/specs/psp.yaml +3 -0
+        type: u32
+        enum: vc-steer
+        enum-as-flags: true
 

Should vc-steer-ena be a connection level setting? Maybe it could go into rx-assoc. The way it's implemented here, the state is already per assoc.

That's what I started with but then given the security implications of the current simple design I could not think of a reason do configure this connection by connection. Besides the SW stack responsible for security is likely somewhat orthogonal to steering configuration. Should have put this in the cover letter as well.

Quoted 8 lines
Quoted 8 lines
Documentation/networking/psp.rst +8 -0
+Every driver has to carry the cookie, not just those which advertise
+``vc-steer-cap`` - granting a peer's request needs no help from the
+device, so the ``tx`` direction of ``vc-steer-ena`` may be turned on
+anywhere. Drivers must ask ``psp_assoc_vc_tx_get()`` for the cookie to
+place in the Tx header, and report the queue IDs a received cookie held
+in ``psp_skb_ext.vc_req`` and ``vc_dst`` (``psp_dev_rcv()`` does this for
+drivers which let the core strip the headers). Reporting is what allows
+the core to grant the peer's request. The steering itself is only
Quoted 8 lines

Documentation/networking/psp.rst Drivers must use ``psp_skb_get_assoc_rcu()`` to check if PSP Tx offload · line 249

Quoted 5 lines
Documentation/networking/psp.rst +5 -0
+expected of drivers which advertise ``vc-steer-cap``.
+
+When VC steering is enabled GRO implementations are allowed to ignore
+changes in the cookie for transport mode PSP.
+  

Makes sense. Do we would need to update __psp_skb_coalesce_diff() here then for the sw gro?

Ack.

Quoted 23 lines

Unrelated, but this reminds me: some of the other fields here:
generation, spi, peer_tx, have some reads/writes that probably require READ/WRITE_ONCE() and maybe deserve a similar comment here... Probably all bugs that I introduced :/

Quoted 18 lines

/* Encapsulate a TCP packet with PSP by adding the UDP+PSP headers and filling
- * them in.
+ * them in. @vc is the virtualization cookie to place in the header, 0 for
+ * a header with no optional fields.
*/
bool psp_dev_encapsulate(struct net *net, struct sk_buff *skb, __be32 spi,

net/psp/psp_main.c +2 -1
-			 u8 ver, __be16 sport)
+			 u8 ver, __be16 sport, u64 vc)
 {
 	u32 network_len = skb_network_header_len(skb);
 	u32 ethr_len = skb_mac_header_len(skb);
 	u32 bufflen = ethr_len + network_len;
+	u32 encap_len = PSP_ENCAP_HLEN;
 
 	if (skb->protocol != htons(ETH_P_IP) &&
 	    skb->protocol != htons(ETH_P_IPV6))
 		return false;
Quoted 7 lines

net/psp/psp_main.c static void psp_write_headers(struct net *net, struct sk_buff *skb, __be32 spi, · line 267

Quoted 4 lines
net/psp/psp_main.c +3 -1
-	if (skb_cow_head(skb, PSP_ENCAP_HLEN))
+	if (vc)
+		encap_len += PSP_VC_SIZE;
+  

I suppose vc of 0 is probably valid. We might need something else to disambiguate "not present".

Ah, good point. We should probably encode the queue as idx+1, I was going back and forth on this. Doesn't feel super clean but it solves a bunch of corner cases, so the benefits probably outweigh the slightly confusing indexing.

#4 lore raw

Re: [RFC net-next 1/6] psp: steer Rx queues with the virtualization cookie

Quoted 46 lines · Jakub Kicinski
Quoted 36 lines · On Sun, 23 Aug 2026 11:31:03 -0400 Daniel Zahka wrote:
Quoted 35 lines · Jakub Kicinski
(quoted diff) +0 -0
@@ -72,6 +90,27 @@ name: psp

           Present when in associated namespace, absent when in primary/host
           namespace.
         type: flag
+      -
+        name: vc-steer-cap
+        doc: |
+          Device can steer received traffic on the PSP virtualization
+          cookie (VC). The VC is split into a 32b reserved part, a 16b
+          queue ID the sender is asking the peer to send to, and a 16b
+          queue ID granting the peer's own request. Steering installs low
+          priority rules matching the latter, which win over the RSS table
+          result. Only needed for the rx direction; granting a peer's
+          request is just header generation and needs no device support.
+        type: flag
+      -
+        name: vc-steer-ena
+        doc: |
+          Directions taking part in VC based queue steering. Leave the
+          attribute out of a dev-set request to keep the current setting.
+          Applies to associations created from then on, existing ones keep
+          the setting they were created with.
+        type: u32
+        enum: vc-steer

Quoted 8 lines
Quoted 2 lines

+        enum-as-flags: true

Should vc-steer-ena be a connection level setting? Maybe it could go
into rx-assoc. The way it's implemented here, the state is already per
assoc.

Quoted 6 lines

That's what I started with but then given the security implications of the current simple design I could not think of a reason do configure
this connection by connection. Besides the SW stack responsible for security is likely somewhat orthogonal to steering configuration. Should have put this in the cover letter as well.

I looked at implementing the current design in mlx5 and a per-assoc setting wouldn't be enough, because flipping this on requires device- level steering changes (basically adding num_queues steering rules). For device-level settings, we conveniently have the .set_config() callback. There's no per-assoc callbacks, but theoretically, we could detect the first use of VC-based steering and do things. Doesn't feel that clean though compared to device-level.

Cosmin.

author maintainer
#5 lore raw

Re: [RFC net-next 1/6] psp: steer Rx queues with the virtualization cookie

Quoted 16 lines · On Mon, 24 Aug 2026 15:09:31 +0000 Cosmin Ratiu wrote:
Quoted 8 lines · Jakub Kicinski
Quoted 6 lines · On Sun, 23 Aug 2026 11:31:03 -0400 Daniel Zahka wrote:

On Sat Aug 22, 2026 at 6:55 PM EDT, Jakub Kicinski wrote:
Should vc-steer-ena be a connection level setting? Maybe it could go
into rx-assoc. The way it's implemented here, the state is already per
assoc.

Quoted 6 lines

That's what I started with but then given the security implications of the current simple design I could not think of a reason do configure
this connection by connection. Besides the SW stack responsible for security is likely somewhat orthogonal to steering configuration. Should have put this in the cover letter as well.

Quoted 7 lines

I looked at implementing the current design in mlx5 and a per-assoc setting wouldn't be enough, because flipping this on requires device- level steering changes (basically adding num_queues steering rules). For device-level settings, we conveniently have the .set_config() callback. There's no per-assoc callbacks, but theoretically, we could detect the first use of VC-based steering and do things. Doesn't feel that clean though compared to device-level.

To be clear - the per-assoc would be in addition to the device level setting. We'd have to enable the feature and then instead of snapshoting the device config in psp_assoc_create() we'd have explicit Netlink flags. We can do this later, the two flags I added here can be thought of as "enable for all assocs", we can add "enable per-assoc" device config later. Tho for Tx not echoing a request would be pure spite...

I implemented the per-assoc things first but then I thought about deploying this and really there's no reason to plumb this policy thru Fizz/Thrift handshaking which creates assocs.

maintainer
#6 lore raw

Re: [RFC net-next 1/6] psp: steer Rx queues with the virtualization cookie

In reply to Jakub Kicinski
Quoted 22 lines · Jakub Kicinski

PSP leaves the 64b virtualization cookie undefined in transport mode. Put it to use: let both ends of a connection tell each other which Rx queue they want traffic on, so that a flow can be pinned to a queue without the receiver having to install a per-flow steering rule, and without the sender having to know anything about the receiver's queue layout. The cookie holds a queue ID the sender is asking the peer to send to ("req") and the queue ID the peer last asked for, granted ("dst"). Each ID gets a 32b word of the cookie to itself and uses only the low half of it, so that either can grow to 32b later without the fields moving.

The two directions are configured separately:

* rx asks peers to send to the queue paired with the flow's Tx queue, so traffic this host receives gets steered. The receiver installs one low priority rule per Rx queue matching "dst", which wins over RSS, so this needs vc-steer-cap.
* tx grants the requests peers make, so traffic this host sends gets steered at the far end. The queue is the peer's to pick and the rules are the peer's to install, so this needs nothing from the local device and can be turned on where vc-steer-cap is absent.

Quoted 2 lines

Splitting them is what makes one sided deployment work. Turn granting on everywhere, cheaply, and asking wherever the NIC can actually do it.

Split the feature patch also? In three parts, one to add generic extension header support (and all zero VC), one that adds tx granting and finally one that adds rx requests.

author maintainer
#7 lore raw

RFC 2/6 netdevsim: support PSP VC based queue steering

In reply to Jakub Kicinski

Gives the PSP steering selftest something to run against without hardware. nsim_start_xmit() already mirrors the Tx queue index onto Rx, so all the cookie does is override that choice.

---
 drivers/net/netdevsim/netdevsim.h |  4 ++--
 drivers/net/netdevsim/netdev.c    |  5 +++--
 drivers/net/netdevsim/psp.c       | 26 ++++++++++++++++++++++++--
 3 files changed, 29 insertions(+), 6 deletions(-)
drivers/net/netdevsim/netdevsim.h +2 -2
index 55aec41237b9..3b1c52e43d46 100644
@@ -453,13 +453,13 @@ void nsim_psp_uninit(struct netdevsim *ns);
 void nsim_psp_handle_ext(struct sk_buff *skb, struct skb_ext *psp_ext);
 enum skb_drop_reason
 nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
-	    struct netdevsim *peer_ns, struct skb_ext **psp_ext);
+	    struct netdevsim *peer_ns, struct skb_ext **psp_ext, int *rxq);
 #else
 static inline int nsim_psp_init(struct netdevsim *ns) { return 0; }
 static inline void nsim_psp_uninit(struct netdevsim *ns) {}
 static inline enum skb_drop_reason
 nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
-	    struct netdevsim *peer_ns, struct skb_ext **psp_ext)
+	    struct netdevsim *peer_ns, struct skb_ext **psp_ext, int *rxq)
 {
 	return 0;
 }
drivers/net/netdevsim/netdev.c +3 -2
index b4a99f3ceac6..04e416d1a377 100644
@@ -147,11 +147,12 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)
 		peer_dev = peer_ns->netdev;
 	}
 
-	dr = nsim_do_psp(skb, ns, peer_ns, &psp_ext);
+	rxq = skb_get_queue_mapping(skb);
+
+	dr = nsim_do_psp(skb, ns, peer_ns, &psp_ext, &rxq);
 	if (dr)
 		goto out_drop_free;
 
-	rxq = skb_get_queue_mapping(skb);
 	if (rxq >= peer_dev->num_rx_queues)
 		rxq = rxq % peer_dev->num_rx_queues;
 	rq = peer_ns->rq[rxq];
drivers/net/netdevsim/psp.c +24 -2
index 32d95205a8cc..5aa5078889eb 100644
@@ -14,9 +14,26 @@ void nsim_psp_handle_ext(struct sk_buff *skb, struct skb_ext *psp_ext)
 		__skb_ext_set(skb, SKB_EXT_PSP, psp_ext);
 }
 
+/* Pick the Rx queue for a decapsulated frame. Devices which support
+ * PSP_VC_STEER_RX match the destination queue ID carried in the
+ * cookie ahead of consulting the RSS table.
+ */
+static int nsim_psp_steer(struct netdevsim *peer_ns, struct sk_buff *skb,
+			  int rxq)
+{
+	struct net_device *dev = peer_ns->netdev;
+	struct psp_skb_ext *pse;
+
+	pse = skb_ext_find(skb, SKB_EXT_PSP);
+	if (!pse || pse->vc_dst >= dev->real_num_rx_queues)
+		return rxq;
+
+	return pse->vc_dst;
+}
+
 enum skb_drop_reason
 nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
-	    struct netdevsim *peer_ns, struct skb_ext **psp_ext)
+	    struct netdevsim *peer_ns, struct skb_ext **psp_ext, int *rxq)
 {
 	enum skb_drop_reason rc = 0;
 	struct psp_dev *peer_psd;
@@ -44,7 +61,8 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
 	}
 
 	net = sock_net(skb->sk);
-	if (!psp_dev_encapsulate(net, skb, pas->tx.spi, pas->version, 0, 0)) {
+	if (!psp_dev_encapsulate(net, skb, pas->tx.spi, pas->version, 0,
+				 psp_assoc_vc_tx_get(pas))) {
 		rc = SKB_DROP_REASON_PSP_OUTPUT;
 		goto out_unlock;
 	}
@@ -73,6 +91,9 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
 			goto out_unlock;
 		}
 
+		if (peer_psd->config.vc_steer & (1 << PSP_VC_STEER_RX))
+			*rxq = nsim_psp_steer(peer_ns, skb, *rxq);
+
 		*psp_ext = skb->extensions;
 		refcount_inc(&(*psp_ext)->refcnt);
 		skb->decrypted = 1;
@@ -216,6 +237,7 @@ static struct psp_dev_caps nsim_psp_caps = {
 		    1 << PSP_VERSION_HDR0_AES_GCM_256 |
 		    1 << PSP_VERSION_HDR0_AES_GMAC_256,
 	.assoc_drv_spc = sizeof(void *),
+	.vc_steer = true,
 };
 
 static void __nsim_psp_uninit(struct netdevsim *ns, bool teardown)
Signature · 1 line
2.55.0
author maintainer
#8 lore raw

RFC 3/6 selftests: drv-net: psp: move the PSP test plumbing into psp_lib.py

In reply to Jakub Kicinski

Pure refactor, no behaviour change. A second PSP test is coming and would otherwise need byte-identical copies of the responder chatter, connection setup and data helpers.

Only what would be copied verbatim moves; the test cases and everything specific to them stay in psp.py. main()'s responder spawning becomes a context manager, which is the one place the shape changes.

---
 MAINTAINERS                                   |   1 +
 tools/testing/selftests/drivers/net/Makefile  |   4 +
 tools/testing/selftests/drivers/net/psp.py    | 287 +++++-------------
 .../testing/selftests/drivers/net/psp_lib.py  | 179 +++++++++++
 4 files changed, 265 insertions(+), 206 deletions(-)
 create mode 100644 tools/testing/selftests/drivers/net/psp_lib.py
MAINTAINERS +1 -0
index 460cb7268845..536fbc1d244d 100644
@@ -21770,6 +21770,7 @@ F:	include/net/psp/
 F:	include/net/psp.h
 F:	include/uapi/linux/psp.h
 F:	net/psp/
+F:	tools/testing/selftests/drivers/net/psp*
 K:	struct\ psp(_assoc|_dev|hdr)\b
 
 PSTORE FILESYSTEM
tools/testing/selftests/drivers/net/Makefile +4 -0
index d5bf4cb638a8..de6e4d7f2dda 100644
@@ -27,6 +27,10 @@ TEST_PROGS := \
 	xdp.py \
 # end of TEST_PROGS
 
+TEST_FILES := \
+	psp_lib.py \
+	#
+
 # YNL files, must be before "include ..lib.mk"
 YNL_GEN_FILES := psp_responder
 TEST_GEN_FILES += $(YNL_GEN_FILES)
tools/testing/selftests/drivers/net/psp.py +81 -206

586 lines not on this page · raw message

tools/testing/selftests/drivers/net/psp_lib.py new file +179 -0

179 lines not on this page · raw message

Signature · 1 line
2.55.0
author maintainer
#9 lore raw

RFC 4/6 selftests: drv-net: psp_steer: test PSP VC based queue steering

In reply to Jakub Kicinski

Cover the netlink interface for PSP VC steering.

---
 tools/testing/selftests/drivers/net/Makefile  |   1 +
 .../selftests/drivers/net/psp_responder.c     |  42 +++
 .../testing/selftests/drivers/net/psp_lib.py  |   5 +
 .../selftests/drivers/net/psp_steer.py        | 256 ++++++++++++++++++
 4 files changed, 304 insertions(+)
 create mode 100644 tools/testing/selftests/drivers/net/psp_steer.py
tools/testing/selftests/drivers/net/Makefile +1 -0
index de6e4d7f2dda..e8719fc106ba 100644
@@ -19,6 +19,7 @@ TEST_PROGS := \
 	netpoll_basic.py \
 	ping.py \
 	psp.py \
+	psp_steer.py \
 	queues.py \
 	ring_reconfig.py \
 	shaper.py \
tools/testing/selftests/drivers/net/psp_responder.c +42 -0

78 lines not on this page · raw message

tools/testing/selftests/drivers/net/psp_lib.py +5 -0
index 1fc4bff84fb1..b2bf205ed327 100644
@@ -58,6 +58,11 @@ from lib.py import bkg, rand_port, wait_port_listen
     s.close()
 
 
+def remote_dev_steer(cfg, mode):
+    """Set vc-steer-ena on the remote PSP device"""
+    send_with_ack(cfg, b'dev steer\0' + struct.pack('B', mode))
+
+
 def spi_xchg(s, rx):
     s.send(struct.pack('I', rx['spi']) + rx['key'])
     tx = s.recv(4 + len(rx['key']))
tools/testing/selftests/drivers/net/psp_steer.py new file +256 -0

256 lines not on this page · raw message

Signature · 1 line
2.55.0
author maintainer
#10 lore raw

RFC 5/6 selftests: drv-net: psp_steer: test where PSP steering sits in the Rx pipeline

In reply to Jakub Kicinski

Cover the steering priority / Rx pipeline ordering.

---
 .../selftests/drivers/net/psp_steer.py        | 171 +++++++++++++++++-
 1 file changed, 164 insertions(+), 7 deletions(-)
tools/testing/selftests/drivers/net/psp_steer.py +164 -7
index 0401a7c359e7..fac2d7532d61 100644
@@ -10,17 +10,35 @@ import socket
 from lib.py import defer
 from lib.py import ksft_run, ksft_exit
 from lib.py import ksft_eq, ksft_ge, ksft_in, ksft_ne, ksft_raises
-from lib.py import KsftSkipEx
+from lib.py import CmdExitFailure, KsftSkipEx
 from lib.py import NetDrvEpEnv
 from lib.py import NetdevFamily, NlError, PSPFamily
+from lib.py import ethtool
 
-from psp_lib import close_conn, init_psp_dev, make_psp_conn, psp_txrx, \
-    remote_conn_steer, remote_dev_steer, spi_xchg
+from psp_lib import close_conn, init_psp_dev, make_clr_conn, make_psp_conn, \
+    psp_txrx, remote_conn_steer, remote_dev_steer, spi_xchg
 from psp_lib import responder as psp_responder
 
 # Not exposed by the socket module
 _SO_INCOMING_NAPI_ID = 56
 
+
+# Mirrors the helpers of the same name in hw/rss_ctx.py, which lives in a
+# directory this test cannot import from.
+def ethtool_create(cfg, act, opts):
+    output = ethtool(f"{act} {cfg.ifname} {opts}").stdout
+    # "New RSS context is 1" / "Added rule with ID 7", we want the integer
+    return int(output.split()[-1])
+
+
+def require_ntuple(cfg):
+    features = ethtool(f"-k {cfg.ifname}", json=True)[0]
+    if not features["ntuple-filters"]["active"]:
+        if features["ntuple-filters"]["fixed"]:
+            raise KsftSkipEx("Device does not support ntuple-filters")
+        ethtool(f"-K {cfg.ifname} ntuple-filters on")
+        defer(ethtool, f"-K {cfg.ifname} ntuple-filters off")
+
 _VC_TX = 1 << 0
 _VC_RX = 1 << 1
 _VC_BOTH = _VC_TX | _VC_RX
@@ -92,6 +110,14 @@ _VC_SIZE = 8
     return s
 
 
+def _rx_queue(cfg, s):
+    """Rx queue the socket's last packet arrived on"""
+    napi_id = s.getsockopt(socket.SOL_SOCKET, _SO_INCOMING_NAPI_ID)
+    ksft_ne(napi_id, 0, comment="socket saw no traffic?")
+    ksft_in(napi_id, cfg.napi2queue, comment="unknown NAPI id")
+    return cfg.napi2queue[napi_id]
+
+
 def _settled_rx_queue(cfg, s, sent):
     """Run traffic until the peer picked our request up, report the queue
 
@@ -101,10 +127,52 @@ _VC_SIZE = 8
     sent = psp_txrx(cfg, s, 1, sent)
     sent = psp_txrx(cfg, s, 1, sent)
 
-    napi_id = s.getsockopt(socket.SOL_SOCKET, _SO_INCOMING_NAPI_ID)
-    ksft_ne(napi_id, 0, comment="socket saw no traffic?")
-    ksft_in(napi_id, cfg.napi2queue, comment="unknown NAPI id")
-    return cfg.napi2queue[napi_id], sent
+    return _rx_queue(cfg, s), sent
+
+
+def _rss_pin(cfg, qid, context=None):
+    """Point an RSS indirection table at a single queue"""
+    ctx = f"context {context} " if context is not None else ""
+    weights = " ".join("1" if i == qid else "0"
+                       for i in range(cfg.rx_queue_cnt))
+    ethtool(f"-X {cfg.ifname} {ctx}weight {weights}")
+
+
+def _require_rss_steering(cfg):
+    """Skip unless the Rx queue actually follows the RSS table
+
+    Steering can only be shown to outrank RSS on a device where RSS has
+    a say in the first place - netdevsim, for one, ignores the table.
+    """
+    probe = cfg.rx_queue_cnt - 1
+
+    try:
+        _rss_pin(cfg, probe)
+    except CmdExitFailure as exc:
+        raise KsftSkipEx("Device does not support RSS table updates") from exc
+    defer(ethtool, f"-X {cfg.ifname} default")
+
+    with make_clr_conn(cfg) as s:
+        psp_txrx(cfg, s, 1)
+        landed = _rx_queue(cfg, s)
+        close_conn(cfg, s)
+
+    if landed != probe:
+        raise KsftSkipEx("Rx queue does not follow the RSS table")
+
+
+def _ntuple_l3_rule(cfg, target):
+    """Steer this host's traffic with an L3 only rule, and clean it up
+
+    L3 only on purpose: whether the classifier sees the inner TCP ports
+    of a PSP packet or just the outer UDP encapsulation is up to the
+    device, the addresses are there either way.
+    """
+    flow = (f"flow-type ip{cfg.addr_ipver} "
+            f"src-ip {cfg.remote_addr} dst-ip {cfg.addr} {target}")
+    rule = ethtool_create(cfg, "-N", flow)
+    defer(ethtool, f"-N {cfg.ifname} delete {rule}")
+    return rule
 
 
 #
@@ -221,6 +289,95 @@ _VC_SIZE = 8
         close_conn(cfg, s)
 
 
+def data_steer_no_grant(cfg):
+    """ We ask and nobody grants: nothing is steered """
+    _require_steer(cfg)
+    _require_queues(cfg, 3)
+    _require_rss_steering(cfg)
+    _enable_steer(cfg, local=_VC_RX, remote=0)
+
+    # RSS says 2, we would be asking for 1 if anyone were listening
+    _rss_pin(cfg, 2)
+    defer(_force_tx_queue, cfg, -1)
+    _force_tx_queue(cfg, 1)
+
+    with _psp_conn(cfg) as s:
+        qid, _ = _settled_rx_queue(cfg, s, 0)
+        ksft_eq(qid, 2, comment="steered without the peer granting anything")
+        close_conn(cfg, s)
+
+
+def data_steer_beats_rss(cfg):
+    """ Steering has to win over the RSS table """
+    _require_steer(cfg)
+    _require_queues(cfg, 3)
+    _enable_steer(cfg)
+    _require_rss_steering(cfg)
+
+    # RSS says 2, steering is going to ask for 1
+    _rss_pin(cfg, 2)
+    defer(_force_tx_queue, cfg, -1)
+    _force_tx_queue(cfg, 1)
+
+    with _psp_conn(cfg) as s:
+        qid, _ = _settled_rx_queue(cfg, s, 0)
+        ksft_eq(qid, 1)
+        close_conn(cfg, s)
+
+
+def data_steer_beats_rss_ctx(cfg):
+    """ Steering has to win over an additional RSS context as well """
+    _require_steer(cfg)
+    _require_queues(cfg, 3)
+    _enable_steer(cfg)
+    _require_rss_steering(cfg)
+    require_ntuple(cfg)
+
+    # Three distinct answers: default RSS says 0, the context says 2,
+    # and steering is going to ask for 1.
+    _rss_pin(cfg, 0)
+    ctx = ethtool_create(cfg, "-X", "context new")
+    defer(ethtool, f"-X {cfg.ifname} context {ctx} delete")
+    _rss_pin(cfg, 2, context=ctx)
+    _ntuple_l3_rule(cfg, f"context {ctx}")
+
+    # Without a cookie the context has to be the one deciding, otherwise
+    # the check below would pass without steering doing anything.
+    with make_clr_conn(cfg) as s:
+        psp_txrx(cfg, s, 1)
+        ksft_eq(_rx_queue(cfg, s), 2, comment="RSS context not in use")
+        close_conn(cfg, s)
+
+    defer(_force_tx_queue, cfg, -1)
+    _force_tx_queue(cfg, 1)
+
+    with _psp_conn(cfg) as s:
+        qid, _ = _settled_rx_queue(cfg, s, 0)
+        ksft_eq(qid, 1, comment="steering did not escape the RSS context")
+        close_conn(cfg, s)
+
+
+def data_ntuple_beats_steer(cfg):
+    """ An ntuple rule naming a queue outranks steering """
+    _require_steer(cfg)
+    _require_queues(cfg, 3)
+    _enable_steer(cfg)
+    _require_rss_steering(cfg)
+    require_ntuple(cfg)
+
+    # RSS says 0, the rule says 2, steering is going to ask for 1
+    _rss_pin(cfg, 0)
+    _ntuple_l3_rule(cfg, "action 2")
+
+    defer(_force_tx_queue, cfg, -1)
+    _force_tx_queue(cfg, 1)
+
+    with _psp_conn(cfg) as s:
+        qid, _ = _settled_rx_queue(cfg, s, 0)
+        ksft_eq(qid, 2, comment="steering overrode an explicit ntuple rule")
+        close_conn(cfg, s)
+
+
 def _queue_info(cfg):
     """Map NAPI ids to Rx queue ids, and count the queues"""
     netnl = NetdevFamily()
Signature · 1 line
2.55.0
author maintainer
#11 lore raw

RFC 6/6 selftests: drv-net: psp_steer: cover corner cases and races

In reply to Jakub Kicinski

Test a PSP cookie naming a queue which went away.

---
 .../selftests/drivers/net/psp_steer.py        | 80 ++++++++++++++++---
 1 file changed, 70 insertions(+), 10 deletions(-)
tools/testing/selftests/drivers/net/psp_steer.py +70 -10
index fac2d7532d61..f61479befcc0 100644
@@ -6,17 +6,18 @@
 import errno
 import os
 import socket
+import time
 
 from lib.py import defer
 from lib.py import ksft_run, ksft_exit
-from lib.py import ksft_eq, ksft_ge, ksft_in, ksft_ne, ksft_raises
+from lib.py import ksft_eq, ksft_ge, ksft_in, ksft_lt, ksft_ne, ksft_raises
 from lib.py import CmdExitFailure, KsftSkipEx
 from lib.py import NetDrvEpEnv
 from lib.py import NetdevFamily, NlError, PSPFamily
 from lib.py import ethtool
 
 from psp_lib import close_conn, init_psp_dev, make_clr_conn, make_psp_conn, \
-    psp_txrx, remote_conn_steer, remote_dev_steer, spi_xchg
+    psp_txrx, remote_dev_steer, req_echo, spi_xchg
 from psp_lib import responder as psp_responder
 
 # Not exposed by the socket module
@@ -43,6 +44,8 @@ _VC_TX = 1 << 0
 _VC_RX = 1 << 1
 _VC_BOTH = _VC_TX | _VC_RX
 _VC_SIZE = 8
+_IDLE_TIME = 0.5
+_FALLBACK_QUEUE = 3
 
 
 def _require_steer(cfg):
@@ -138,18 +141,19 @@ _VC_SIZE = 8
     ethtool(f"-X {cfg.ifname} {ctx}weight {weights}")
 
 
-def _require_rss_steering(cfg):
-    """Skip unless the Rx queue actually follows the RSS table
+def _rss_steers(cfg):
+    """Does the Rx queue actually follow the RSS table?
 
-    Steering can only be shown to outrank RSS on a device where RSS has
-    a say in the first place - netdevsim, for one, ignores the table.
+    Steering can only be compared against RSS on a device where RSS has a
+    say in the first place - netdevsim, for one, ignores the table. Leaves
+    the table as it found it.
     """
     probe = cfg.rx_queue_cnt - 1
 
     try:
         _rss_pin(cfg, probe)
-    except CmdExitFailure as exc:
-        raise KsftSkipEx("Device does not support RSS table updates") from exc
+    except CmdExitFailure:
+        return False
     defer(ethtool, f"-X {cfg.ifname} default")
 
     with make_clr_conn(cfg) as s:
@@ -157,10 +161,22 @@ _VC_SIZE = 8
         landed = _rx_queue(cfg, s)
         close_conn(cfg, s)
 
-    if landed != probe:
+    ethtool(f"-X {cfg.ifname} default")
+    return landed == probe
+
+
+def _require_rss_steering(cfg):
+    """Skip unless the Rx queue follows the RSS table"""
+    if not _rss_steers(cfg):
         raise KsftSkipEx("Rx queue does not follow the RSS table")
 
 
+def _set_queue_cnt(cfg, cnt):
+    """Reconfigure the device, and re-read the NAPI ids it hands out"""
+    ethtool(f"-L {cfg.ifname} combined {cnt}")
+    _queue_info(cfg)
+
+
 def _ntuple_l3_rule(cfg, target):
     """Steer this host's traffic with an L3 only rule, and clean it up
 
@@ -378,6 +394,50 @@ _VC_SIZE = 8
         close_conn(cfg, s)
 
 
+def data_steer_stale_queue(cfg):
+    """ A cookie naming a queue which went away has to fall back to RSS """
+    _require_steer(cfg)
+    _require_queues(cfg, 8)
+    _enable_steer(cfg)
+
+    nq = cfg.rx_queue_cnt
+    rss = _rss_steers(cfg)
+    if rss:
+        # Point RSS at a queue of our choosing so that "it fell back to
+        # RSS" is a statement we can actually check. Deliberately not
+        # queue 0: plenty of devices use that as a default or error queue,
+        # and landing there would prove nothing - it would also be a
+        # thundering herd waiting to happen if every stale flow went there.
+        _rss_pin(cfg, _FALLBACK_QUEUE)
+
+    defer(_set_queue_cnt, cfg, nq)
+    defer(_force_tx_queue, cfg, -1)
+    _force_tx_queue(cfg, nq - 1)
+
+    with _psp_conn(cfg) as s:
+        qid, _ = _settled_rx_queue(cfg, s, 0)
+        ksft_eq(qid, nq - 1)
+
+        # Go properly idle first. A delayed ACK landing after the
+        # reconfiguration would carry a fresh request and teach the peer a
+        # live queue, and we would end up measuring nothing.
+        time.sleep(_IDLE_TIME)
+
+        # Take the queue away without telling the peer, which goes on
+        # asking for it in every cookie it sends.
+        _set_queue_cnt(cfg, nq - 1)
+
+        # One packet, so that our ACK cannot teach the peer a new queue
+        # before we get to look at where this one landed.
+        req_echo(cfg, s)
+        qid = _rx_queue(cfg, s)
+        close_conn(cfg, s)
+
+    ksft_lt(qid, nq - 1, comment="delivered to a queue which no longer exists")
+    if rss:
+        ksft_eq(qid, _FALLBACK_QUEUE, comment="stale request did not fall back to RSS")
+
+
 def _queue_info(cfg):
     """Map NAPI ids to Rx queue ids, and count the queues"""
     netnl = NetdevFamily()
@@ -398,7 +458,7 @@ _VC_SIZE = 8
 def main() -> None:
     """ Ksft boiler plate main """
 
-    with NetDrvEpEnv(__file__, queue_count=4) as cfg:
+    with NetDrvEpEnv(__file__, queue_count=8) as cfg:
         cfg.pspnl = PSPFamily()
         _queue_info(cfg)
 
Signature · 1 line
2.55.0
maintainer
#12 lore raw
In reply to Jakub Kicinski
Quoted 13 lines · Jakub Kicinski

Hi!

This PoC series uses a field of the PSP header intended for tunnels to auto-steer Rx traffic. Various attempts have been made at trying to get Rx traffic to land close to the core where the application runs. By default RSS picks the Rx queue based on the flow hash. I'm not going to cover all previous solutions in detail but broadly
- we have RFS in SW which looks on which CPU Tx happens and backlogs Rx packets there, it is quite efficient. aRFS is built on top of RFS but tries to program flows into the NIC. Some NICs have a "cache" and try to automatically remember the flow to queue association.

Quoted 5 lines

All those solutions are entirely local to the receiver. Ideally we would want the solution to look something like TCP timestamp option - we send an opaque cookie to the peer, and the peer echoes it back to us. Our NIC can steer based on that echoed cookie.

Another option is to reverse RSS entropy. This requires knowledge of the RSS secret.

Especially with PSP, the outer UDP source port is defined as flow hash, so can be used for this.

Have the receiver compute a 4-tuple hash such that it knows the RSS block will select the intended queue. The only free variable here in general is the source port. Then communicate this preferred source port to the sender.

Quoted 8 lines

This patch set implements exactly that using the optional PSP Virtualization Cookie field. The PSP standard doesn't have much to say about this field:

Virtualization Cookie - 64b
An optional field, present if and only if V is set.
It may contain a Virtual Network Identifier (VNI) or other data, as defined by the implementation.

If using the PSP option space, no need to (ab)use the VC:

"When the Hdr Ext Len is greater than 1, a Virtualization Cookie and/or other header extension fields may be present. The presence of a Virtualization Cookie is determined by the state of the V bit. For example, given Hdr Ext Len of 3, when V bit is set, there is an 8B VC after the IV, and another 8B extension header after the VC. The format of other header extension fields is determined by the applications and is opaque to the PSP hardware. "

Right now all use besides VC is opaque to the device.

For use-cases that should be interoperable across vendors, we should probably define a standard option space, with well defined options.

In a manner that is cheap to parse at high rate, so no arbitrary order variable length headers.

#13 lore raw
Quoted 25 lines · Willem de Bruijn
Quoted 15 lines · Jakub Kicinski

Hi!

This PoC series uses a field of the PSP header intended for tunnels to auto-steer Rx traffic. Various attempts have been made at trying to get Rx traffic to land close to the core where the application runs.
By default RSS picks the Rx queue based on the flow hash. I'm not going to cover all previous solutions in detail but broadly
- we have RFS in SW which looks on which CPU Tx happens and backlogs
Rx packets there, it is quite efficient. aRFS is built on top of RFS but tries to program flows into the NIC. Some NICs have a "cache" and try to automatically remember the flow to queue association.

Quoted 5 lines

All those solutions are entirely local to the receiver. Ideally we would want the solution to look something like TCP timestamp option - we send an opaque cookie to the peer, and the peer echoes it back to us. Our NIC can steer based on that echoed cookie.

Another option is to reverse RSS entropy. This requires knowledge of the RSS secret.

Quoted 7 lines

Especially with PSP, the outer UDP source port is defined as flow hash, so can be used for this.

Have the receiver compute a 4-tuple hash such that it knows the RSS block will select the intended queue. The only free variable here in general is the source port. Then communicate this preferred source port to the sender.

I was thinking of something along these lines as an alternative. When initializing PSP for a connection, look at what the device uses with .get_rxfh(), and find a value sport (either by linear algebra or linear probing) such that the 4-tuple hash results in the desired queue. This might require some non-trivial code changes to reimplement the hashes in SW though, but it's local to this sport selection only.

psp_dev_encapsulate() and psp_write_headers() both conveniently already have a sport argument, which is currently ignored, so plumbing this is easy.

This would result in zero RX changes for driver implementors.

An easier alternative to avoid reverse engineering RSS hash implementations would be to vary the desired sport across multiple packets and until packets start coming to the desired queue. Presumably this could converge to the desired queue in O(num_queues) TX packets + acks. Maybe could be done with TCP keep alives at connection setup?

Cosmin.

#14 lore raw
Quoted 55 lines · Cosmin Ratiu
Quoted 29 lines · Willem de Bruijn
Quoted 18 lines · Jakub Kicinski

Hi!

This PoC series uses a field of the PSP header intended for tunnels
to auto-steer Rx traffic. Various attempts have been made at trying
to get Rx traffic to land close to the core where the application runs.
By default RSS picks the Rx queue based on the flow hash. I'm not going to cover all previous solutions in detail but broadly
- we have RFS in SW which looks on which CPU Tx happens and backlogs
Rx packets there, it is quite efficient. aRFS is built on top of RFS but tries to program flows into the NIC. Some NICs have a "cache" and try to automatically remember the flow to queue association.

Quoted 5 lines

All those solutions are entirely local to the receiver. Ideally we would want the solution to look something like TCP timestamp option - we send an opaque cookie to the peer, and the peer echoes it back to us. Our NIC can steer based on that echoed cookie.

Another option is to reverse RSS entropy. This requires knowledge of
the RSS secret.

Quoted 8 lines

Especially with PSP, the outer UDP source port is defined as flow hash, so can be used for this.

Have the receiver compute a 4-tuple hash such that it knows the RSS block will select the intended queue. The only free variable here in
general is the source port. Then communicate this preferred source port to the sender.

I was thinking of something along these lines as an alternative. When initializing PSP for a connection, look at what the device uses with .get_rxfh(), and find a value sport (either by linear algebra or linear probing) such that the 4-tuple hash results in the desired queue. This might require some non-trivial code changes to reimplement
the hashes in SW though, but it's local to this sport selection only.

psp_dev_encapsulate() and psp_write_headers() both conveniently already
have a sport argument, which is currently ignored, so plumbing this is
easy.

This would result in zero RX changes for driver implementors.

Quoted 8 lines

An easier alternative to avoid reverse engineering RSS hash implementations would be to vary the desired sport across multiple packets and until packets start coming to the desired queue. Presumably
this could converge to the desired queue in O(num_queues) TX packets +
acks. Maybe could be done with TCP keep alives at connection setup?

Another issue we have with a potential mlx5 implementation is that HW GRO cannot work with this feature as proposed, but there are options.

For HW GRO, mlx5 NICs need to decapsulate packets before sending them to the HW object which does GRO. The SPI and PSP version are passed as CQE fields. There's no more CQE space to pass req_qid alongside those.

Option 1 would be to only set req_qid on _changes_ (edge transitions) and keep it 0 otherwise. Also make it mean queue = req_qid - 1 to allow the use of queue 0. Ideally, only the first packet in each direction would have req_qid != 0. These packets cannot be decapped and cannot go through HW GRO, but all subsequent ones with req_qid == 0 may. dst_qid is of course != 0 in all packets and is honored.

But then you need to make sure those packets aren't lost, and maybe retransmit req_qid until it gets received. I thought about it a bit, maybe using TCP acks as an indication? Or just trying best-effort a couple of times...

Option 2 would be to just disallow HW GRO with req_qid.

And option 3: sport selection to get the desired RSS result makes this interaction non-existent.

Cosmin.

author maintainer
#15 lore raw
Quoted 7 lines · On Tue, 25 Aug 2026 09:52:09 +0000 Cosmin Ratiu wrote:

Option 1 would be to only set req_qid on _changes_ (edge transitions) and keep it 0 otherwise. Also make it mean queue = req_qid - 1 to allow the use of queue 0. Ideally, only the first packet in each direction would have req_qid != 0. These packets cannot be decapped and cannot go through HW GRO, but all subsequent ones with req_qid == 0 may. dst_qid is of course != 0 in all packets and is honored.

Quoted 6 lines

But then you need to make sure those packets aren't lost, and maybe retransmit req_qid until it gets received. I thought about it a bit, maybe using TCP acks as an indication? Or just trying best-effort a couple of times...

Option 2 would be to just disallow HW GRO with req_qid.

I'd go with Option 2 FWIW and revisit it later if we find out that more NICs need some sort of workaround.

Quoted 2 lines

And option 3: sport selection to get the desired RSS result makes this interaction non-existent.

author maintainer
#16 lore raw
In reply to Willem de Bruijn
Quoted 21 lines · On Sun, 23 Aug 2026 13:48:05 -0400 Willem de Bruijn wrote:
Quoted 11 lines · Jakub Kicinski

This PoC series uses a field of the PSP header intended for tunnels to auto-steer Rx traffic. Various attempts have been made at trying to get Rx traffic to land close to the core where the application runs. By default RSS picks the Rx queue based on the flow hash. I'm not going to cover all previous solutions in detail but broadly
- we have RFS in SW which looks on which CPU Tx happens and backlogs Rx packets there, it is quite efficient. aRFS is built on top of RFS but tries to program flows into the NIC. Some NICs have a "cache" and try to automatically remember the flow to queue association.

Quoted 5 lines

All those solutions are entirely local to the receiver. Ideally we would want the solution to look something like TCP timestamp option - we send an opaque cookie to the peer, and the peer echoes it back to us. Our NIC can steer based on that echoed cookie.

Another option is to reverse RSS entropy. This requires knowledge of the RSS secret.

Quoted 7 lines

Especially with PSP, the outer UDP source port is defined as flow hash, so can be used for this.

Have the receiver compute a 4-tuple hash such that it knows the RSS block will select the intended queue. The only free variable here in general is the source port. Then communicate this preferred source port to the sender.

Yes, we toyed with this a little. Communicating the hash to remote is far less trivial. The thing that made me switch to the PSP idea is that modern NICs can RSS on the flow label. Which is nice for non-steering capable clients, and it conflicts with pre-computing. Maybe the benefit is not big enough to matter.

Do you have any practical experience deploying reverse RSS? Maybe I shied away from it too quickly..

Quoted 19 lines
Quoted 8 lines

This patch set implements exactly that using the optional PSP Virtualization Cookie field. The PSP standard doesn't have much to say about this field:

Virtualization Cookie - 64b
An optional field, present if and only if V is set.
It may contain a Virtual Network Identifier (VNI) or other data, as defined by the implementation.

If using the PSP option space, no need to (ab)use the VC:

"When the Hdr Ext Len is greater than 1, a Virtualization Cookie and/or other header extension fields may be present. The presence of a Virtualization Cookie is determined by the state of the V bit. For example, given Hdr Ext Len of 3, when V bit is set, there is an 8B VC after the IV, and another 8B extension header after the VC. The format of other header extension fields is determined by the applications and is opaque to the PSP hardware. "

Quoted 7 lines

Right now all use besides VC is opaque to the device.

For use-cases that should be interoperable across vendors, we should probably define a standard option space, with well defined options.

In a manner that is cheap to parse at high rate, so no arbitrary order variable length headers.

TBH I don't see the need for this at all. VC is well defined, and fed into TCAMs. IMHO classifying the use of the VC as VNI vs steering tag can be left entirely to SW / association state. The non-V options should remain completely opaque to the HW IMHO.

maintainer
#17 lore raw
Quoted 25 lines · Jakub Kicinski
Quoted 24 lines · On Sun, 23 Aug 2026 13:48:05 -0400 Willem de Bruijn wrote:
Quoted 11 lines · Jakub Kicinski

This PoC series uses a field of the PSP header intended for tunnels to auto-steer Rx traffic. Various attempts have been made at trying to get Rx traffic to land close to the core where the application runs. By default RSS picks the Rx queue based on the flow hash. I'm not going to cover all previous solutions in detail but broadly
- we have RFS in SW which looks on which CPU Tx happens and backlogs Rx packets there, it is quite efficient. aRFS is built on top of RFS but tries to program flows into the NIC. Some NICs have a "cache" and try to automatically remember the flow to queue association.

Quoted 5 lines

All those solutions are entirely local to the receiver. Ideally we would want the solution to look something like TCP timestamp option - we send an opaque cookie to the peer, and the peer echoes it back to us. Our NIC can steer based on that echoed cookie.

Another option is to reverse RSS entropy. This requires knowledge of the RSS secret.

Especially with PSP, the outer UDP source port is defined as flow hash, so can be used for this.

Quoted 7 lines
Quoted 4 lines

Have the receiver compute a 4-tuple hash such that it knows the RSS block will select the intended queue. The only free variable here in general is the source port. Then communicate this preferred source port to the sender.

Yes, we toyed with this a little. Communicating the hash to remote is far less trivial. The thing that made me switch to the PSP idea

No need to communicate the hash, just the source port.

Quoted 6 lines

is that modern NICs can RSS on the flow label. Which is nice for non-steering capable clients, and it conflicts with pre-computing. Maybe the benefit is not big enough to matter.

Do you have any practical experience deploying reverse RSS? Maybe I shied away from it too quickly..

Definitely implemented and it is quite straightforward. Using the probing approach that Cosmin mentioned. No fancy algebraic solution, though that would be preferable if has faster convergence.

Not sure whether we ever actually deployed it.

Quoted 24 lines
Quoted 24 lines
Quoted 8 lines

This patch set implements exactly that using the optional PSP Virtualization Cookie field. The PSP standard doesn't have much to say about this field:

Virtualization Cookie - 64b
An optional field, present if and only if V is set.
It may contain a Virtual Network Identifier (VNI) or other data, as defined by the implementation.

If using the PSP option space, no need to (ab)use the VC:

"When the Hdr Ext Len is greater than 1, a Virtualization Cookie and/or other header extension fields may be present. The presence of a Virtualization Cookie is determined by the state of the V bit. For example, given Hdr Ext Len of 3, when V bit is set, there is an 8B VC after the IV, and another 8B extension header after the VC. The format of other header extension fields is determined by the applications and is opaque to the PSP hardware. "

Right now all use besides VC is opaque to the device.

For use-cases that should be interoperable across vendors, we should probably define a standard option space, with well defined options.

Quoted 7 lines
Quoted 2 lines

In a manner that is cheap to parse at high rate, so no arbitrary order variable length headers.

TBH I don't see the need for this at all. VC is well defined, and fed into TCAMs. IMHO classifying the use of the VC as VNI vs steering tag can be left entirely to SW / association state. The non-V options should remain completely opaque to the HW IMHO.

The spec should have been more precise than "It may contain a Virtual Network Identifier (VNI) or other data, as defined by the implementation.". That second part is a pretty big loophole.

VNI is not clearly defined. A minimal interpretation is that no two VNIs must have the same value. Yet thay may definitely have the same queue mapping.

On TCAMs: is the assumption that the VC cookie today already, if present, is used to steer among VFs? And therefore it can also be used to select among queues? But this is a different TCAM mask, using only 16b, and as a direct queue id.