From: Heng Qi <hengqi@linux.alibaba.com>
To: Liang Chen <liangchen.linux@gmail.com>
Cc: netdev@vger.kernel.org, virtualization@lists.linux.dev,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
daniel@iogearbox.net, ast@kernel.org,
"Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>
Subject: Re: [PATCH net-next v9] virtio_net: Support RX hash XDP hint
Date: Wed, 17 Apr 2024 15:59:44 +0800 [thread overview]
Message-ID: <ae00d109-403f-46f5-9b70-19fd7a94d3cf@linux.alibaba.com> (raw)
In-Reply-To: <20240417071822.27831-1-liangchen.linux@gmail.com>
在 2024/4/17 下午3:18, Liang Chen 写道:
> The RSS hash report is a feature that's part of the virtio specification.
> Currently, virtio backends like qemu, vdpa (mlx5), and potentially vhost
> (still a work in progress as per [1]) support this feature. While the
> capability to obtain the RSS hash has been enabled in the normal path,
> it's currently missing in the XDP path. Therefore, we are introducing
> XDP hints through kfuncs to allow XDP programs to access the RSS hash.
>
> 1.
> https://lore.kernel.org/all/20231015141644.260646-1-akihiko.odaki@daynix.com/#r
>
> Signed-off-by: Liang Chen <liangchen.linux@gmail.com>
Reviewed-by: Heng Qi <hengqi@linux.alibaba.com>
Thanks.
> ---
> Changes from v8:
> - move max table macro out of uAPI
> Changes from v7:
> - use table lookup for rss hash type
> Changes from v6:
> - fix a coding style issue
> Changes from v5:
> - Preservation of the hash value has been dropped, following the conclusion
> from discussions in V3 reviews. The virtio_net driver doesn't
> accessing/using the virtio_net_hdr after the XDP program execution, so
> nothing tragic should happen. As to the xdp program, if it smashes the
> entry in virtio header, it is likely buggy anyways. Additionally, looking
> up the Intel IGC driver, it also does not bother with this particular
> aspect.
> ---
> drivers/net/virtio_net.c | 43 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 43 insertions(+)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index c22d1118a133..eb99bf6c555e 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -4621,6 +4621,48 @@ static void virtnet_set_big_packets(struct virtnet_info *vi, const int mtu)
> }
> }
>
> +#define VIRTIO_NET_HASH_REPORT_MAX_TABLE 10
> +static enum xdp_rss_hash_type
> +virtnet_xdp_rss_type[VIRTIO_NET_HASH_REPORT_MAX_TABLE] = {
> + [VIRTIO_NET_HASH_REPORT_NONE] = XDP_RSS_TYPE_NONE,
> + [VIRTIO_NET_HASH_REPORT_IPv4] = XDP_RSS_TYPE_L3_IPV4,
> + [VIRTIO_NET_HASH_REPORT_TCPv4] = XDP_RSS_TYPE_L4_IPV4_TCP,
> + [VIRTIO_NET_HASH_REPORT_UDPv4] = XDP_RSS_TYPE_L4_IPV4_UDP,
> + [VIRTIO_NET_HASH_REPORT_IPv6] = XDP_RSS_TYPE_L3_IPV6,
> + [VIRTIO_NET_HASH_REPORT_TCPv6] = XDP_RSS_TYPE_L4_IPV6_TCP,
> + [VIRTIO_NET_HASH_REPORT_UDPv6] = XDP_RSS_TYPE_L4_IPV6_UDP,
> + [VIRTIO_NET_HASH_REPORT_IPv6_EX] = XDP_RSS_TYPE_L3_IPV6_EX,
> + [VIRTIO_NET_HASH_REPORT_TCPv6_EX] = XDP_RSS_TYPE_L4_IPV6_TCP_EX,
> + [VIRTIO_NET_HASH_REPORT_UDPv6_EX] = XDP_RSS_TYPE_L4_IPV6_UDP_EX
> +};
> +
> +static int virtnet_xdp_rx_hash(const struct xdp_md *_ctx, u32 *hash,
> + enum xdp_rss_hash_type *rss_type)
> +{
> + const struct xdp_buff *xdp = (void *)_ctx;
> + struct virtio_net_hdr_v1_hash *hdr_hash;
> + struct virtnet_info *vi;
> + u16 hash_report;
> +
> + if (!(xdp->rxq->dev->features & NETIF_F_RXHASH))
> + return -ENODATA;
> +
> + vi = netdev_priv(xdp->rxq->dev);
> + hdr_hash = (struct virtio_net_hdr_v1_hash *)(xdp->data - vi->hdr_len);
> + hash_report = __le16_to_cpu(hdr_hash->hash_report);
> +
> + if (hash_report >= VIRTIO_NET_HASH_REPORT_MAX_TABLE)
> + hash_report = VIRTIO_NET_HASH_REPORT_NONE;
> +
> + *rss_type = virtnet_xdp_rss_type[hash_report];
> + *hash = __le32_to_cpu(hdr_hash->hash_value);
> + return 0;
> +}
> +
> +static const struct xdp_metadata_ops virtnet_xdp_metadata_ops = {
> + .xmo_rx_hash = virtnet_xdp_rx_hash,
> +};
> +
> static int virtnet_probe(struct virtio_device *vdev)
> {
> int i, err = -ENOMEM;
> @@ -4747,6 +4789,7 @@ static int virtnet_probe(struct virtio_device *vdev)
> VIRTIO_NET_RSS_HASH_TYPE_UDP_EX);
>
> dev->hw_features |= NETIF_F_RXHASH;
> + dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops;
> }
>
> if (vi->has_rss_hash_report)
next prev parent reply other threads:[~2024-04-17 7:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-17 7:18 [PATCH net-next v9] virtio_net: Support RX hash XDP hint Liang Chen
2024-04-17 7:51 ` Jesper Dangaard Brouer
2024-04-17 7:59 ` Heng Qi [this message]
2024-04-18 0:24 ` Jason Wang
2024-04-18 12:00 ` patchwork-bot+netdevbpf
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=ae00d109-403f-46f5-9b70-19fd7a94d3cf@linux.alibaba.com \
--to=hengqi@linux.alibaba.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=jasowang@redhat.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=liangchen.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/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