Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp258998rdb; Mon, 22 Jan 2024 03:23:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbaQdy+hkyAItjSmw1SfpIsuKTb50jmv6e9b8J+4WwYq8XfNgR+ublU7dtOpWgmDEb3BPL X-Received: by 2002:a0c:f24a:0:b0:685:4903:34b8 with SMTP id z10-20020a0cf24a000000b00685490334b8mr4161636qvl.24.1705922598534; Mon, 22 Jan 2024 03:23:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705922598; cv=pass; d=google.com; s=arc-20160816; b=o/01UwZL/q5PFVMSgOa4svWa0Q21W+cekHvgy4v207QqHZLewaP+Gvx1Ye2LQfHbkd rWapL8k42aCtSDmVsyR8YMxaQopIRMFV+9RjoFnSdnEfo902xoezWFk7l4LUdqTb2uKE uOZc2ULOz3USGVqM44s9CKiUW9RClz9ILySGw+j4hJJ5LpuQlHSebr6wFlXnUaaQrI2O YEVLKY8OV7rbW6nmyO0cCpCzPtBbyh/+t3KifohwknOKQ3VrdhYcTzBGbSjjQ8T9D3w4 wbeF1BZuJZUvu6yXBn79uyMlzH8KCsspn986+FFld5BBZDdGhdxIApH9Ijw+U+G8eKkB P8xw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id; bh=seRjGg+9thaRLe72Y86OR9YQ6/GUedcmI0+i3uSUzUg=; fh=ia9Gdo0tpgjM9HHojeh1GldCLj/LZIq1zbajyLk9A2o=; b=wY8gKRoU52jFIAm62WpyWa+9PVU50tyNMCXHSiw1ZRuAhab0/tM1V0VwmDP9hh8kPF knovGeK8Us8sAELVoTLDudIZEc5mSQb2Xp0JMYT3ZGlscR/a0k7as9L76T/7UDZRYJcI x1eBwx8lYCQsul4nHJXbnM2u/tbb/enjatCpFEt5uZLb0DY9rucGgxrJ3KYlI9213nsD zqopTxE8chWHjMdLK3fF0vH325S188sckYgvd8k0gZsMTvd6exIb0R11llkUEtmeuDQd WPpFC5XS32tvRNyl2baEPM2O2YjE+YiFVtCTNK9evqqqdbV7khGUCMPGH66pNdlyK1qs lMzQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-32872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32872-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w14-20020a0c8e4e000000b00685c947ea1dsi4434505qvb.535.2024.01.22.03.23.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 03:23:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-32872-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32872-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4DBA01C21AA4 for ; Mon, 22 Jan 2024 11:23:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49CDC3DB95; Mon, 22 Jan 2024 11:10:50 +0000 (UTC) Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE5853D99B for ; Mon, 22 Jan 2024 11:10:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705921849; cv=none; b=nWJbrqsxEMZjJO18/v7nCB4pkV2EbUxTKPJ0thbgo1kfDzm4C/jCcPbZIIuxA2JoSoYQQCG8p5ZZ7J84WJNAeKiJ8DKbC56p8fVXZ0wOKTK+tBLV7RU60yA/jlhKuJN7vMdqE7copcbAzRy8+YmJaevs0t7IIYl/FeXNOR60nwo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705921849; c=relaxed/simple; bh=cuK6dlsAqqCyuHKmfg4fbsKC82Budl4OWQwU5QWb5N8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=DEgrfGzOSc3ZfPk3or9OT2PeWyklCgI3MLa/dsRy09uh3UiPfXKI4emFCYlQ2HKKgPmWcF4qWxaIlJGZiuhN1XIio0oQsTT3sV+Dw0O/GXojBSEr64ng2wv7zjhJIwiRrAVZkAkh0EDt8B5pjwQEXbR7OexgYamyQ0+d7F0gPvg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; arc=none smtp.client-ip=115.124.30.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0W.7NcCV_1705921837; Received: from 30.221.149.111(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0W.7NcCV_1705921837) by smtp.aliyun-inc.com; Mon, 22 Jan 2024 19:10:38 +0800 Message-ID: <4ada64aa-87ec-4340-9892-be52c1f27a97@linux.alibaba.com> Date: Mon, 22 Jan 2024 19:10:36 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] virtio_net: Support RX hash XDP hint To: Liang Chen , mst@redhat.com, jasowang@redhat.com Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20240122102256.261374-1-liangchen.linux@gmail.com> From: Heng Qi In-Reply-To: <20240122102256.261374-1-liangchen.linux@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Liang Chen, 在 2024/1/22 下午6:22, 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. > > Signed-off-by: Liang Chen > --- > 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)) I think 'vi->has_rss_hash_report' should be used here. NETIF_F_RXHASH cannot guarantee that the hash report feature is negotiated, and accessing hash_report and hash_value is unsafe at this time. > + return -ENODATA; > + > + vi = netdev_priv(xdp->rxq->dev); > + hdr_hash = (struct virtio_net_hdr_v1_hash *)(xdp->data - vi->hdr_len); If the virtio-net-hdr is overrided by the XDP prog, how can this be done correctly and as expected? Thanks, Heng > + > + 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. */