Skip to contentSkip to conversation

net: mana: add XDP RX hash metadata

PATCH In review Shradha Gupta 3 participants 3 messages Dec 3 – Dec 4

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: mana: add XDP RX hash metadata

XDP programs attached to a MANA netdevice currently cannot access the receive RSS hash or its protocol type. They must either recompute the hash or operate without metadata that the hardware has already provided.

Expose the hardware RSS hash and type through xdp_metadata_ops so XDP programs can use the same receive-hash information as the skb path. Keep the hash value packet-local for coalesced receive completions, and decode the NDIS hash-type bitmask with protocol-specific L4 types taking precedence over L3-only types. Return -ENODATA when no recognized hash type is present.

---
 .../net/ethernet/microsoft/mana/mana_bpf.c    | 48 +++++++++++++++++++
 drivers/net/ethernet/microsoft/mana/mana_en.c | 11 +++--
 include/net/mana/mana.h                       |  7 +++
 3 files changed, 63 insertions(+), 3 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_bpf.c +48 -0
index 494267b30..5aec18b19 100644
@@ -10,6 +10,54 @@
 
 #include <net/mana/mana.h>
 
+static enum xdp_rss_hash_type mana_xdp_rss_type(u16 hash_type)
+{
+	if (hash_type & NDIS_HASH_TCP_IPV4)
+		return XDP_RSS_TYPE_L4_IPV4_TCP;
+	if (hash_type & NDIS_HASH_UDP_IPV4)
+		return XDP_RSS_TYPE_L4_IPV4_UDP;
+	if (hash_type & NDIS_HASH_TCP_IPV6_EX)
+		return XDP_RSS_TYPE_L4_IPV6_TCP_EX;
+	if (hash_type & NDIS_HASH_UDP_IPV6_EX)
+		return XDP_RSS_TYPE_L4_IPV6_UDP_EX;
+	if (hash_type & NDIS_HASH_TCP_IPV6)
+		return XDP_RSS_TYPE_L4_IPV6_TCP;
+	if (hash_type & NDIS_HASH_UDP_IPV6)
+		return XDP_RSS_TYPE_L4_IPV6_UDP;
+	if (hash_type & NDIS_HASH_IPV4)
+		return XDP_RSS_TYPE_L3_IPV4;
+	if (hash_type & NDIS_HASH_IPV6)
+		return XDP_RSS_TYPE_L3_IPV6;
+	if (hash_type & NDIS_HASH_IPV6_EX)
+		return XDP_RSS_TYPE_L3_IPV6_EX;
+
+	return XDP_RSS_TYPE_NONE;
+}
+
+static int mana_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
+			    enum xdp_rss_hash_type *rss_type)
+{
+	const struct mana_xdp_buff *mxdp = (const void *)ctx;
+	enum xdp_rss_hash_type hash_type;
+
+	if (!(mxdp->xdp.rxq->dev->features & NETIF_F_RXHASH) ||
+	    !mxdp->cqe->rx_hashtype)
+		return -ENODATA;
+
+	hash_type = mana_xdp_rss_type(mxdp->cqe->rx_hashtype);
+	if (hash_type == XDP_RSS_TYPE_NONE)
+		return -ENODATA;
+
+	*hash = mxdp->pkt_hash;
+	*rss_type = hash_type;
+
+	return 0;
+}
+
+const struct xdp_metadata_ops mana_xdp_metadata_ops = {
+	.xmo_rx_hash		= mana_xdp_rx_hash,
+};
+
 void mana_xdp_tx(struct sk_buff *skb, struct net_device *ndev)
 {
 	u16 txq_idx = skb_get_queue_mapping(skb);
drivers/net/ethernet/microsoft/mana/mana_en.c +8 -3
index 95bf153c3..6bfc3cff1 100644
@@ -2145,7 +2145,11 @@ static void mana_rx_skb(void *buf_va, bool from_pool,
 	struct net_device *ndev = rxq->ndev;
 	u16 rxq_idx = rxq->rxq_idx;
 	struct napi_struct *napi;
-	struct xdp_buff xdp = {};
+	struct mana_xdp_buff mxdp = {
+		.cqe = cqe,
+		.pkt_hash = pkt_hash,
+	};
+	struct xdp_buff *xdp = &mxdp.xdp;
 	struct sk_buff *skb;
 	u32 act;
 
@@ -2157,7 +2161,7 @@ static void mana_rx_skb(void *buf_va, bool from_pool,
 		return;
 	}
 
-	act = mana_run_xdp(ndev, rxq, &xdp, buf_va, from_pool, pkt_len);
+	act = mana_run_xdp(ndev, rxq, xdp, buf_va, from_pool, pkt_len);
 
 	if (act == XDP_REDIRECT && !rxq->xdp_rc)
 		return;
@@ -2165,7 +2169,7 @@ static void mana_rx_skb(void *buf_va, bool from_pool,
 	if (act != XDP_PASS && act != XDP_TX)
 		goto drop_xdp;
 
-	skb = mana_build_skb(rxq, buf_va, pkt_len, &xdp);
+	skb = mana_build_skb(rxq, buf_va, pkt_len, xdp);
 
 	if (!skb)
 		goto drop;
@@ -3968,6 +3972,7 @@ static int mana_probe_port(struct mana_context *ac, int port_idx,
 
 	ndev->netdev_ops = &mana_devops;
 	ndev->ethtool_ops = &mana_ethtool_ops;
+	ndev->xdp_metadata_ops = &mana_xdp_metadata_ops;
 	ndev->mtu = ETH_DATA_LEN;
 	ndev->max_mtu = gc->adapter_mtu - ETH_HLEN;
 	ndev->min_mtu = ETH_MIN_MTU;
include/net/mana/mana.h +7 -0
index 84afc4199..1085266e3 100644
@@ -297,6 +297,12 @@ struct mana_rxcomp_oob {
 	u32 rx_wqe_offset;
 }; /* HW DATA */
 
+struct mana_xdp_buff {
+	struct xdp_buff xdp;
+	const struct mana_rxcomp_oob *cqe;
+	u32 pkt_hash;
+};
+
 struct mana_tx_comp_oob {
 	struct mana_cqe_header cqe_hdr;
 
@@ -717,6 +723,7 @@ void mana_pre_dealloc_rxbufs(struct mana_port_context *apc);
 void mana_unmap_skb(struct sk_buff *skb, struct mana_port_context *apc);
 
 extern const struct ethtool_ops mana_ethtool_ops;
+extern const struct xdp_metadata_ops mana_xdp_metadata_ops;
 extern struct dentry *mana_debugfs_root;
 
 /* A CQ can be created not associated with any EQ */

base-commit: ed3135d0881a926de56a7f490dea3d51698ba118

Signature · 1 line
2.43.0
#1 lore raw
Quoted 38 lines · Shradha Gupta

XDP programs attached to a MANA netdevice currently cannot access the receive RSS hash or its protocol type. They must either recompute the hash or operate without metadata that the hardware has already provided.

Expose the hardware RSS hash and type through xdp_metadata_ops so XDP programs can use the same receive-hash information as the skb path. Keep the hash value packet-local for coalesced receive completions, and decode the NDIS hash-type bitmask with protocol-specific L4 types taking precedence over L3-only types. Return -ENODATA when no recognized hash type is present.

---
  .../net/ethernet/microsoft/mana/mana_bpf.c    | 48 +++++++++++++++++++
  drivers/net/ethernet/microsoft/mana/mana_en.c | 11 +++--
  include/net/mana/mana.h                       |  7 +++
  3 files changed, 63 insertions(+), 3 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_bpf.c +10 -0
index 494267b30..5aec18b19 100644
@@ -10,6 +10,54 @@
 
  #include <net/mana/mana.h>
 
+static enum xdp_rss_hash_type mana_xdp_rss_type(u16 hash_type)
+{
+	if (hash_type & NDIS_HASH_TCP_IPV4)
+		return XDP_RSS_TYPE_L4_IPV4_TCP;
+	if (hash_type & NDIS_HASH_UDP_IPV4)
+		return XDP_RSS_TYPE_L4_IPV4_UDP;
+	if (hash_type & NDIS_HASH_TCP_IPV6_EX)
+		return XDP_RSS_TYPE_L4_IPV6_TCP_EX;
+	if (hash_type & NDIS_HASH_UDP_IPV6_EX)
+		return XDP_RSS_TYPE_L4_IPV6_UDP_EX;

drivers/net/ethernet/microsoft/mana/mana_bpf.c line 32

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/mana_bpf.c +10 -0
+	if (hash_type & NDIS_HASH_TCP_IPV6)
+		return XDP_RSS_TYPE_L4_IPV6_TCP;
+	if (hash_type & NDIS_HASH_UDP_IPV6)
+		return XDP_RSS_TYPE_L4_IPV6_UDP;
+	if (hash_type & NDIS_HASH_IPV4)
+		return XDP_RSS_TYPE_L3_IPV4;
+	if (hash_type & NDIS_HASH_IPV6)
+		return XDP_RSS_TYPE_L3_IPV6;
+	if (hash_type & NDIS_HASH_IPV6_EX)
+		return XDP_RSS_TYPE_L3_IPV6_EX;

Why does NDIS_HASH_IPV6 take precedence over NDIS_HASH_IPV6_EX?

Especially when above NDIS_HASH_TCP_IPV6_EX takes precedence over NDIS_HASH_TCP_IPV6.

Other drivers have a lookup table to avoid this kind of if-statements, but I assume you have some good reason for not doing a lookup table(?)

--Jesper

Quoted 101 lines
drivers/net/ethernet/microsoft/mana/mana_bpf.c +28 -0
+
+	return XDP_RSS_TYPE_NONE;
+}
+
+static int mana_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
+			    enum xdp_rss_hash_type *rss_type)
+{
+	const struct mana_xdp_buff *mxdp = (const void *)ctx;
+	enum xdp_rss_hash_type hash_type;
+
+	if (!(mxdp->xdp.rxq->dev->features & NETIF_F_RXHASH) ||
+	    !mxdp->cqe->rx_hashtype)
+		return -ENODATA;
+
+	hash_type = mana_xdp_rss_type(mxdp->cqe->rx_hashtype);
+	if (hash_type == XDP_RSS_TYPE_NONE)
+		return -ENODATA;
+
+	*hash = mxdp->pkt_hash;
+	*rss_type = hash_type;
+
+	return 0;
+}
+
+const struct xdp_metadata_ops mana_xdp_metadata_ops = {
+	.xmo_rx_hash		= mana_xdp_rx_hash,
+};
+
  void mana_xdp_tx(struct sk_buff *skb, struct net_device *ndev)
  {
  	u16 txq_idx = skb_get_queue_mapping(skb);
drivers/net/ethernet/microsoft/mana/mana_en.c +8 -3
index 95bf153c3..6bfc3cff1 100644
@@ -2145,7 +2145,11 @@ static void mana_rx_skb(void *buf_va, bool from_pool,
  	struct net_device *ndev = rxq->ndev;
  	u16 rxq_idx = rxq->rxq_idx;
  	struct napi_struct *napi;
-	struct xdp_buff xdp = {};
+	struct mana_xdp_buff mxdp = {
+		.cqe = cqe,
+		.pkt_hash = pkt_hash,
+	};
+	struct xdp_buff *xdp = &mxdp.xdp;
  	struct sk_buff *skb;
  	u32 act;
 
@@ -2157,7 +2161,7 @@ static void mana_rx_skb(void *buf_va, bool from_pool,
  		return;
  	}
 
-	act = mana_run_xdp(ndev, rxq, &xdp, buf_va, from_pool, pkt_len);
+	act = mana_run_xdp(ndev, rxq, xdp, buf_va, from_pool, pkt_len);
 
  	if (act == XDP_REDIRECT && !rxq->xdp_rc)
  		return;
@@ -2165,7 +2169,7 @@ static void mana_rx_skb(void *buf_va, bool from_pool,
  	if (act != XDP_PASS && act != XDP_TX)
  		goto drop_xdp;
 
-	skb = mana_build_skb(rxq, buf_va, pkt_len, &xdp);
+	skb = mana_build_skb(rxq, buf_va, pkt_len, xdp);
 
  	if (!skb)
  		goto drop;
@@ -3968,6 +3972,7 @@ static int mana_probe_port(struct mana_context *ac, int port_idx,
 
  	ndev->netdev_ops = &mana_devops;
  	ndev->ethtool_ops = &mana_ethtool_ops;
+	ndev->xdp_metadata_ops = &mana_xdp_metadata_ops;
  	ndev->mtu = ETH_DATA_LEN;
  	ndev->max_mtu = gc->adapter_mtu - ETH_HLEN;
  	ndev->min_mtu = ETH_MIN_MTU;
include/net/mana/mana.h +7 -0
index 84afc4199..1085266e3 100644
@@ -297,6 +297,12 @@ struct mana_rxcomp_oob {
  	u32 rx_wqe_offset;
  }; /* HW DATA */
 
+struct mana_xdp_buff {
+	struct xdp_buff xdp;
+	const struct mana_rxcomp_oob *cqe;
+	u32 pkt_hash;
+};
+
  struct mana_tx_comp_oob {
  	struct mana_cqe_header cqe_hdr;
 
@@ -717,6 +723,7 @@ void mana_pre_dealloc_rxbufs(struct mana_port_context *apc);
  void mana_unmap_skb(struct sk_buff *skb, struct mana_port_context *apc);
 
  extern const struct ethtool_ops mana_ethtool_ops;
+extern const struct xdp_metadata_ops mana_xdp_metadata_ops;
  extern struct dentry *mana_debugfs_root;
 
  /* A CQ can be created not associated with any EQ */

base-commit: ed3135d0881a926de56a7f490dea3d51698ba118

#2 lore raw
In reply to Shradha Gupta
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] net: mana: NDIS_HASH_IPV6 shadows NDIS_HASH_IPV6_EX in mana_xdp_rss_type() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] net: mana: NDIS_HASH_IPV6 shadows NDIS_HASH_IPV6_EX in mana_xdp_rss_type()
--

commit a23000e64af6f7600430222158d1aa0f1d0fc454
Author: Shradha Gupta <[email protected]>

net: mana: add XDP RX hash metadata

This commit exposes the hardware RSS hash and hash type to XDP programs on MANA devices via xdp_metadata_ops.

Quoted 18 lines
drivers/net/ethernet/microsoft/mana/mana_bpf.c +10 -0
index 494267b3069a3..5aec18b1940b3 100644
@@ -10,6 +10,54 @@
 
 #include <net/mana/mana.h>
 
+static enum xdp_rss_hash_type mana_xdp_rss_type(u16 hash_type)
+{
+	if (hash_type & NDIS_HASH_TCP_IPV4)
+		return XDP_RSS_TYPE_L4_IPV4_TCP;
+	if (hash_type & NDIS_HASH_UDP_IPV4)
+		return XDP_RSS_TYPE_L4_IPV4_UDP;
+	if (hash_type & NDIS_HASH_TCP_IPV6_EX)
+		return XDP_RSS_TYPE_L4_IPV6_TCP_EX;
+	if (hash_type & NDIS_HASH_UDP_IPV6_EX)
+		return XDP_RSS_TYPE_L4_IPV6_UDP_EX;

drivers/net/ethernet/microsoft/mana/mana_bpf.c line 32

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/mana_bpf.c +10 -0
+	if (hash_type & NDIS_HASH_TCP_IPV6)
+		return XDP_RSS_TYPE_L4_IPV6_TCP;
+	if (hash_type & NDIS_HASH_UDP_IPV6)
+		return XDP_RSS_TYPE_L4_IPV6_UDP;
+	if (hash_type & NDIS_HASH_IPV4)
+		return XDP_RSS_TYPE_L3_IPV4;
+	if (hash_type & NDIS_HASH_IPV6)
+		return XDP_RSS_TYPE_L3_IPV6;
+	if (hash_type & NDIS_HASH_IPV6_EX)
+		return XDP_RSS_TYPE_L3_IPV6_EX;

[Severity: Low]
Should NDIS_HASH_IPV6_EX be checked before NDIS_HASH_IPV6 here?

For L4 IPv6 above, the _EX bits are tested before the base bits. Checking NDIS_HASH_IPV6 first shadows NDIS_HASH_IPV6_EX whenever both bits are set in cqe->rx_hashtype, returning XDP_RSS_TYPE_L3_IPV6 and dropping XDP_RSS_L3_DYNHDR from the hash type reported to XDP programs.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1