* [PATCH net-next] net: mana: add XDP RX hash metadata
@ 2026-12-03 11:30 Shradha Gupta
2026-12-04 10:47 ` Jesper Dangaard Brouer
2026-12-04 11:32 ` sashiko-bot
0 siblings, 2 replies; 3+ messages in thread
From: Shradha Gupta @ 2026-12-03 11:30 UTC (permalink / raw)
To: netdev
Cc: Shradha Gupta, linux-hyperv, bpf, K . Y . Srinivasan,
Haiyang Zhang, Wei Liu, Dexuan Cui, Long Li, Andrew Lunn,
David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev
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.
Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Shradha Gupta <shradhagupta@linux.microsoft.com>
---
.../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(-)
diff --git a/drivers/net/ethernet/microsoft/mana/mana_bpf.c b/drivers/net/ethernet/microsoft/mana/mana_bpf.c
index 494267b30..5aec18b19 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_bpf.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_bpf.c
@@ -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);
diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index 95bf153c3..6bfc3cff1 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -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;
diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h
index 84afc4199..1085266e3 100644
--- a/include/net/mana/mana.h
+++ b/include/net/mana/mana.h
@@ -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.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next] net: mana: add XDP RX hash metadata
2026-12-03 11:30 [PATCH net-next] net: mana: add XDP RX hash metadata Shradha Gupta
@ 2026-12-04 10:47 ` Jesper Dangaard Brouer
2026-12-04 11:32 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: Jesper Dangaard Brouer @ 2026-12-04 10:47 UTC (permalink / raw)
To: Shradha Gupta, netdev
Cc: linux-hyperv, bpf, K . Y . Srinivasan, Haiyang Zhang, Wei Liu,
Dexuan Cui, Long Li, Andrew Lunn, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Alexei Starovoitov,
Daniel Borkmann, John Fastabend, Stanislav Fomichev
On 12/3/26 12:30, Shradha Gupta wrote:
> 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.
>
> Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
> Signed-off-by: Shradha Gupta <shradhagupta@linux.microsoft.com>
> ---
> .../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(-)
>
> diff --git a/drivers/net/ethernet/microsoft/mana/mana_bpf.c b/drivers/net/ethernet/microsoft/mana/mana_bpf.c
> index 494267b30..5aec18b19 100644
> --- a/drivers/net/ethernet/microsoft/mana/mana_bpf.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_bpf.c
> @@ -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;
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
> +
> + 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);
> diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
> index 95bf153c3..6bfc3cff1 100644
> --- a/drivers/net/ethernet/microsoft/mana/mana_en.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
> @@ -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;
> diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h
> index 84afc4199..1085266e3 100644
> --- a/include/net/mana/mana.h
> +++ b/include/net/mana/mana.h
> @@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net-next] net: mana: add XDP RX hash metadata
2026-12-03 11:30 [PATCH net-next] net: mana: add XDP RX hash metadata Shradha Gupta
2026-12-04 10:47 ` Jesper Dangaard Brouer
@ 2026-12-04 11:32 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-04 11:32 UTC (permalink / raw)
To: Shradha Gupta; +Cc: linux-hyperv, bpf
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 <shradhagupta@linux.microsoft.com>
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.
> diff --git a/drivers/net/ethernet/microsoft/mana/mana_bpf.c b/drivers/net/ethernet/microsoft/mana/mana_bpf.c
> index 494267b3069a3..5aec18b1940b3 100644
> --- a/drivers/net/ethernet/microsoft/mana/mana_bpf.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_bpf.c
> @@ -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;
[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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203113055.431519-1-shradhagupta@linux.microsoft.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 11:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 11:30 [PATCH net-next] net: mana: add XDP RX hash metadata Shradha Gupta
2026-12-04 10:47 ` Jesper Dangaard Brouer
2026-12-04 11:32 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox