mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
virtio_net: Support RX hash XDP hint
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> Acked-by: Jesper Dangaard Brouer <hawk@kernel.org> Reviewed-by: Heng Qi <hengqi@linux.alibaba.com> Acked-by: Jason Wang <jasowang@redhat.com> Link: https://lore.kernel.org/r/20240417071822.27831-1-liangchen.linux@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
parent
576fedf87b
commit
aa37f8916d
1 changed files with 43 additions and 0 deletions
|
@ -4637,6 +4637,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;
|
||||
|
@ -4765,6 +4807,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)
|
||||
|
|
Loading…
Add table
Reference in a new issue