Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1898155lqp; Tue, 16 Apr 2024 00:35:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVwbIPt34a7W4fvwbJZUB0dSLsrv0WSWVoGCOsznvToGNPRoMIUQytLuaO4JFoJ7QdFeY1Lfm1gn0GT83V4+5aPwgwkH6YTjqutyDBiEA== X-Google-Smtp-Source: AGHT+IE8aIi4rDHam5wdQesTeFrCCMLNjBw9hpxJwsAgErcuhLdITjyQLOV5j9i32HiOJirKuHn1 X-Received: by 2002:a17:907:97d1:b0:a52:2a65:cf2 with SMTP id js17-20020a17090797d100b00a522a650cf2mr2075507ejc.13.1713252919054; Tue, 16 Apr 2024 00:35:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713252919; cv=pass; d=google.com; s=arc-20160816; b=gYZDDC06BlRpqDxwtl44aiqIQM8EpqRlvEtkns/QEhWcg3caZIIVj1ACeFxQ5ai+qf xpVu90wA6/aG3GWBs520xvSAAGpzXj8Sh9EwSM4TpGaLtuKme+t83S98FjRDamUZO7Q4 NF0oydhpIUVWJ4zWFPlH1is06h1WzqX/lvyrglqEi8sGuLNA5qMpp71pkD2+zLOqH+I1 4y3jcg6rAHdbdMQwd+PF0lWM48CRg9StmHqehY5+LK63XPcCyq3KbwDbXlWqtW8g7w5E GsFjEx5YauhYYuOMmkbTsuGxFBxjlsl3Cnl/s5BaOJv702oazTVRiQZG/2Oq+RxS0YBp +ROQ== 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:dkim-signature; bh=9meh8oyY29GyYPeAQDY+XOsQifc0/vEfvP4YeEQ/6s4=; fh=jBD0d96fmlkU+iAlHNxhPXSzJn1EpdUroszwCH5R2Os=; b=zC/IclY4CJRdIdvmYluokNtLclxxb91sVWFccYcnQdWGFGG98iCPYtp7mcG21Ov8Nh Z/lF8IRHMLe5ce2sYGtVuxewCA0PDS5A5wpv59+R0GipFj8Y66kSh9p0zM+9UvhSa0dz l1CyBqyPWl/JxAz4tRYCLi63oGGsfBhCCs3f3gsT1KZVAWiURUMl4zfc5Xd9l06L2Z89 s4iZ4EGmChKCH8TL/1YLwUWXnleUHeceqPv62Twd46lP9vlY2RO42aVdlWt5IpHw+xdP n2iZsZoIDf+XRyyrRgIq/JpvFyqWcu8CcCuQbNwwQmDps5Rnkp90Ha/pmbcWDIdCacaM zecg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=lEcc89Ad; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-146433-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146433-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d3-20020a170906c20300b00a524404631asi3652806ejz.275.2024.04.16.00.35.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 00:35:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146433-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=lEcc89Ad; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-146433-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146433-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 86DE61F22626 for ; Tue, 16 Apr 2024 07:35:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2175084D22; Tue, 16 Apr 2024 07:35:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="lEcc89Ad" Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (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 1A2A56EB76; Tue, 16 Apr 2024 07:35:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713252905; cv=none; b=CXx+fxn0bBDjm+y5vnvb+7tI4ZZt6LxrCgt9CcHqziWrTNzG/tnWeMRaUPwCq3KuVZPaCLGU7fja523i0S/fYaqVYSbouNM/8LjIJyBL2ylBeAy2YcFeqLUbzZBLR4yeMt0g9KegprHbtw6C6POjKDc5gGuTgOJaoetVKVqqvgU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713252905; c=relaxed/simple; bh=YZPpjFD2h0BWhFauzUKmPOsfcH02IyKQ+EGYXS83Mwk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Yy84q3hpMtuTXeN005Q7amK9Ipprf0SDOSwscY+dzH+eu99xLGtDlkfM7MYMP57yA+tSE9cDjvLG2cFnlpxA7sjtV+BWcInblJs57X/dxCo97e1KmYt2XiInhMafiKezTj/VKX/SYMTBuyb+3rdtDZz4FStY1JiOUDAdtTM7GWs= 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; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=lEcc89Ad; arc=none smtp.client-ip=115.124.30.97 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 DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1713252894; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=9meh8oyY29GyYPeAQDY+XOsQifc0/vEfvP4YeEQ/6s4=; b=lEcc89AdvBT62ld7EXPuakApOtoY8wi9L2dfGTAAELpjzdiJ4w6MQKgj5NxsT2IR3JhBAgOmwoMwjUxg4xZ1f7Knh6TEczICU0zHM2YuKnL0Hlx4uSSI3NFCCzW39FmaWyCHqHg1EP5s+hSnzqtkUs9XnBMPda9xnGxOzKxpQvw= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=hengqi@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0W4gwW5N_1713252892; Received: from 30.221.148.212(mailfrom:hengqi@linux.alibaba.com fp:SMTPD_---0W4gwW5N_1713252892) by smtp.aliyun-inc.com; Tue, 16 Apr 2024 15:34:53 +0800 Message-ID: <04dcbbcd-7079-42d4-b77c-3bbf55cfc823@linux.alibaba.com> Date: Tue, 16 Apr 2024 15:34:51 +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 net-next v8] virtio_net: Support RX hash XDP hint To: Liang Chen 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" , Jason Wang , Xuan Zhuo , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesper Dangaard Brouer , John Fastabend References: <20240416061943.407082-1-liangchen.linux@gmail.com> From: Heng Qi In-Reply-To: <20240416061943.407082-1-liangchen.linux@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2024/4/16 下午2:19, 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 > --- > 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 | 42 +++++++++++++++++++++++++++++++++ > include/uapi/linux/virtio_net.h | 1 + > 2 files changed, 43 insertions(+) > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index c22d1118a133..1d750009f615 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -4621,6 +4621,47 @@ static void virtnet_set_big_packets(struct virtnet_info *vi, const int mtu) > } > } > > +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; When this happens, it may mean an error or user modification of the header occurred. Should the following *hash* value be cleared to 0? Thanks, Heng > + > + *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 +4788,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) > diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h > index cc65ef0f3c3e..3ee695450096 100644 > --- a/include/uapi/linux/virtio_net.h > +++ b/include/uapi/linux/virtio_net.h > @@ -176,6 +176,7 @@ struct virtio_net_hdr_v1_hash { > #define VIRTIO_NET_HASH_REPORT_IPv6_EX 7 > #define VIRTIO_NET_HASH_REPORT_TCPv6_EX 8 > #define VIRTIO_NET_HASH_REPORT_UDPv6_EX 9 > +#define VIRTIO_NET_HASH_REPORT_MAX_TABLE 10 > __le16 hash_report; > __le16 padding; > };