BPF List
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <hawk@kernel.org>
To: Shradha Gupta <shradhagupta@linux.microsoft.com>, netdev@vger.kernel.org
Cc: linux-hyperv@vger.kernel.org, bpf@vger.kernel.org,
	"K . Y . Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
	Long Li <longli@microsoft.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Stanislav Fomichev <sdf@fomichev.me>
Subject: Re: [PATCH net-next] net: mana: add XDP RX hash metadata
Date: Fri, 4 Dec 2026 11:47:35 +0100	[thread overview]
Message-ID: <58dfd816-19ab-4340-a8b1-646405b07609@kernel.org> (raw)
In-Reply-To: <20261203113055.431519-1-shradhagupta@linux.microsoft.com>



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


  reply	other threads:[~2026-12-04 10:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-12-04 11:32 ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=58dfd816-19ab-4340-a8b1-646405b07609@kernel.org \
    --to=hawk@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=decui@microsoft.com \
    --cc=edumazet@google.com \
    --cc=haiyangz@microsoft.com \
    --cc=horms@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=longli@microsoft.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=shradhagupta@linux.microsoft.com \
    --cc=wei.liu@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox