All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liang Chen <liangchen.linux@gmail.com>
To: mst@redhat.com, jasowang@redhat.com
Cc: virtualization@lists.linux-foundation.org,
	linux-kernel@vger.kernel.org, liangchen.linux@gmail.com
Subject: [PATCH] virtio_net: Support RX hash XDP hint
Date: Mon, 22 Jan 2024 18:22:56 +0800	[thread overview]
Message-ID: <20240122102256.261374-1-liangchen.linux@gmail.com> (raw)

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.

Signed-off-by: Liang Chen <liangchen.linux@gmail.com>
---
 drivers/net/virtio_net.c | 56 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index d7ce4a1011ea..1463a4709e3c 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -4579,6 +4579,60 @@ static void virtnet_set_big_packets(struct virtnet_info *vi, const int mtu)
 	}
 }
 
+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;
+
+	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);
+
+	switch (__le16_to_cpu(hdr_hash->hash_report)) {
+		case VIRTIO_NET_HASH_REPORT_TCPv4:
+			*rss_type = XDP_RSS_TYPE_L4_IPV4_TCP;
+			break;
+		case VIRTIO_NET_HASH_REPORT_UDPv4:
+			*rss_type = XDP_RSS_TYPE_L4_IPV4_UDP;
+			break;
+		case VIRTIO_NET_HASH_REPORT_TCPv6:
+			*rss_type = XDP_RSS_TYPE_L4_IPV6_TCP;
+			break;
+		case VIRTIO_NET_HASH_REPORT_UDPv6:
+			*rss_type = XDP_RSS_TYPE_L4_IPV6_UDP;
+			break;
+		case VIRTIO_NET_HASH_REPORT_TCPv6_EX:
+			*rss_type = XDP_RSS_TYPE_L4_IPV6_TCP_EX;
+			break;
+		case VIRTIO_NET_HASH_REPORT_UDPv6_EX:
+			*rss_type = XDP_RSS_TYPE_L4_IPV6_UDP_EX;
+			break;
+		case VIRTIO_NET_HASH_REPORT_IPv4:
+			*rss_type = XDP_RSS_TYPE_L3_IPV4;
+			break;
+		case VIRTIO_NET_HASH_REPORT_IPv6:
+			*rss_type = XDP_RSS_TYPE_L3_IPV6;
+			break;
+		case VIRTIO_NET_HASH_REPORT_IPv6_EX:
+			*rss_type = XDP_RSS_TYPE_L3_IPV6_EX;
+			break;
+		case VIRTIO_NET_HASH_REPORT_NONE:
+		default:
+			*rss_type = XDP_RSS_TYPE_NONE;
+	}
+
+	*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;
@@ -4613,6 +4667,8 @@ static int virtnet_probe(struct virtio_device *vdev)
 	dev->ethtool_ops = &virtnet_ethtool_ops;
 	SET_NETDEV_DEV(dev, &vdev->dev);
 
+	dev->xdp_metadata_ops = &virtnet_xdp_metadata_ops;
+
 	/* Do we support "hardware" checksums? */
 	if (virtio_has_feature(vdev, VIRTIO_NET_F_CSUM)) {
 		/* This opens up the world of extra features. */
-- 
2.40.1


             reply	other threads:[~2024-01-22 10:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22 10:22 Liang Chen [this message]
2024-01-22 11:10 ` [PATCH] virtio_net: Support RX hash XDP hint Heng Qi
2024-01-24  2:04   ` Liang Chen
2024-01-24  6:05     ` Xuan Zhuo
2024-01-24  8:04       ` Liang Chen
2024-01-23  7:02 ` Michael S. Tsirkin
2024-01-24  2:27   ` Liang Chen
2024-01-24  2:12 ` Jason Wang
2024-01-24  8:03   ` Liang Chen

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=20240122102256.261374-1-liangchen.linux@gmail.com \
    --to=liangchen.linux@gmail.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.