🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26485

Re: [PATCH net-next v24 11/14] virtio_net: Implement IPv4 ethtool flow rules

#26485
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 15:51
183 lines
14182 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] parse_ip4() in drivers/net/virtio_net.c copies the raw ethtool
  h_u.usr_ip4_spec values (ip4src, ip4dst, tos) into the device rule key…
- [Low] In drivers/net/virtio_net.c, setup_ip_key_mask() (lines
  6193-6199) returns -EINVAL whenever h_u.usr_ip4_spec.proto or…
- [Low] calculate_flow_sizes() in drivers/net/virtio_net.c adds a runtime
  `BUG_ON(size > 0xff)` (line 6151) to guard the u8 key_size, which…

--

virtio_net: Implement IPv4 ethtool flow rules

This commit adds support for IP_USER_FLOW ethtool rules to the virtio_net
flow filter code. It builds a classifier with two selectors (Ethernet and
IPv4) and fills the IPv4 key and mask from the ethtool usr_ip4_spec fields.

> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 43c3e6750ad01..8456ae3010200 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c

[ ... ]

> @@ -5890,11 +5924,41 @@ static bool validate_mask(const struct virtnet_ff *ff,

[ ... ]

> +static void parse_ip4(struct iphdr *mask, struct iphdr *key,
> +		      const struct ethtool_rx_flow_spec *fs)
> +{
> +	const struct ethtool_usrip4_spec *l3_mask = &fs->m_u.usr_ip4_spec;
> +	const struct ethtool_usrip4_spec *l3_val  = &fs->h_u.usr_ip4_spec;
> +
> +	if (l3_mask->ip4src) {
> +		put_unaligned(l3_mask->ip4src, &mask->saddr);
> +		put_unaligned(l3_val->ip4src, &key->saddr);
> +	}
> +
> +	if (l3_mask->ip4dst) {
> +		put_unaligned(l3_mask->ip4dst, &mask->daddr);
> +		put_unaligned(l3_val->ip4dst, &key->daddr);
> +	}
> +
> +	if (l3_mask->tos) {
> +		mask->tos = l3_mask->tos;
> +		key->tos = l3_val->tos;
> +	}
> +}

[Severity: Medium]
Should the key values be ANDed with the mask here?

The ethtool uAPI doesn't require h_u bits outside of m_u to be zero, and the
ethtool CLI passes the value through unmasked. For example:

  ethtool -U dev flow-type ip4 src-ip 192.168.51.101 m 0.0.0.255 action N

reaches the driver with ip4src mask 255.255.255.0 and value 192.168.51.101.

If the device advertises VIRTIO_NET_FF_MASK_F_PARTIAL_MASK,
validate_ip4_mask() accepts this partial mask. insert_rule() then sends a
key that has bits set where the classifier mask is zero.

The device contract in include/uapi/linux/virtio_net_ff.h only says:

  The key bytes are compared against packet headers using the
  masks provided by the classifier's selectors.

It doesn't say whether key bits outside the mask are ignored. If a device
matches with (pkt & mask) == key, would these rules silently never match?
Rules that are equivalent after masking would also be stored as distinct
keys.

The ETHER_FLOW path in setup_eth_hdr_key_mask(), added earlier in this
series, follows the same pattern with its memcpy() of fs->h_u.ether_spec.

Would writing (val & mask) into the key remove the dependency on device
behaviour? parse_ip4() is unchanged at the end of the series, so no later
patch in the series addresses this.

[ ... ]

> @@ -6073,8 +6138,18 @@ static void calculate_flow_sizes(struct ethtool_rx_flow_spec *fs,
>  				 u8 *key_size, size_t *classifier_size,
>  				 int *num_hdrs)
>  {
> +	size_t size = sizeof(struct ethhdr);
> +
>  	*num_hdrs = 1;
> -	*key_size = sizeof(struct ethhdr);
> +
> +	if (fs->flow_type != ETHER_FLOW) {
> +		++(*num_hdrs);
> +		if (has_ipv4(fs->flow_type))
> +			size += sizeof(struct iphdr);
> +	}
> +
> +	BUG_ON(size > 0xff);

[Severity: Low]
This isn't a bug, but does this need a runtime BUG_ON() on the ethtool
ioctl path?

The size comes only from compile-time constants: 14 bytes for ethhdr, plus
20 for iphdr. The largest case at the end of the series is eth + ipv6 + tcp
= 74 bytes, so the condition can't be true today.

Could this be a BUILD_BUG_ON() on the largest header combination instead?
Another option is WARN_ON_ONCE() with an -EINVAL return, so that a future
flow type pushing the size past 255 can't panic the kernel.

> +	*key_size = size;

[ ... ]

> @@ -6095,8 +6171,36 @@ static void setup_eth_hdr_key_mask(struct virtio_net_ff_selector *selector,

[ ... ]

> +static int setup_ip_key_mask(struct virtio_net_ff_selector *selector,
> +			     u8 *key,
> +			     const struct ethtool_rx_flow_spec *fs)
> +{
> +	struct iphdr *v4_m = (struct iphdr *)&selector->mask;
> +	struct iphdr *v4_k = (struct iphdr *)key;
> +
> +	selector->type = VIRTIO_NET_FF_MASK_TYPE_IPV4;
> +	selector->length = sizeof(struct iphdr);
> +
> +	if (fs->h_u.usr_ip4_spec.l4_4_bytes ||
> +	    fs->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4 ||
> +	    fs->m_u.usr_ip4_spec.l4_4_bytes ||
> +	    fs->m_u.usr_ip4_spec.ip_ver ||
> +	    fs->h_u.usr_ip4_spec.proto ||
> +	    fs->m_u.usr_ip4_spec.proto)
> +		return -EINVAL;

[Severity: Low]
Is this stricter than the ethtool uAPI requires?

In the rxnfc uAPI a zero mask means "don't care". struct
ethtool_usrip4_spec only places a rule on the mask:

  @proto: Transport protocol number; mask must be 0

l4_4_bytes has no rule that its value must be zero either.

Because of the checks on h_u.usr_ip4_spec.proto and
h_u.usr_ip4_spec.l4_4_bytes, a request like this returns -EINVAL:

  ethtool -U dev flow-type ip4 src-ip X l4proto 6 m 0xff action N

ethtool inverts the user mask, so this arrives as m_u.proto = 0 and
h_u.proto = 6. The proto field should just be ignored. The same thing
happens with "l4data V m 0xffffffff".

Other drivers, such as mlx5 and ice, check only the mask fields plus the
ip_ver value. Could the h_u.proto and h_u.l4_4_bytes checks be dropped?

At the end of the series, the num_hdrs == 2 branch of setup_ip_key_mask()
still has the same check.

> +
> +	parse_ip4(v4_m, v4_k, fs);
> +
> +	return 0;
>  }

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202150502.3350030-1-shshitrit%40nvidia.com
Technical Details
Message-ID: <179631311284.3146.4618650342552521395@kernel.org>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376737-linux-kernel-netdev=dewy.ru
References: <20261202150502.3350030-12-shshitrit@nvidia.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376737-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v24 11/14] virtio_net: Implement IPv4 ethtool flow rules
Date: Thu, 03 Dec 2026 15:51:52 +0000
Organization: Usenet Network
Message-ID: <179631311284.3146.4618650342552521395@kernel.org>
References: <20261202150502.3350030-12-shshitrit@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2534290"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:RTRcor64N4GHXtS1F+pu2z8hOis= sha256:6JCUokgydSDXVOTK8YLbTP3IiPXRh8V4agYxHfYCAZc=
	sha1:nwRvt+70XQEoZsQt42WIAbqs8QM= sha256:/1yts3qV9XDYXpI4sdShv44VF3d9tEZaSWTtz0nkLbM=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 1F3651179C4; Thu,  3 Dec 2026 18:52:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.64
X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id kiVmhr0Ok0ig;
	Thu,  3 Dec 2026 18:52:25 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376737-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id BA5F81179B6; Thu,  3 Dec 2026 18:52:16 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 7E11C2C68D; Thu,  3 Dec 2026 15:52:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796313120;
	b=3iVBnZHTE+RV/QTe3mGR5uOZjWFPWo0Xm2ZCD+p/5ofJhgGzInJukYN3JOwLajQsobdc
	 XrdFSBNGREJ2UzKDqECH/VN8NE3/tS+C+46180ohiKFHPWBGWkq5KOPfEaK/v0PIlX3+I
	 X4J7ut1Q+ZcWwiZvQ+n4qq/er/qcVDTA5qm0WpZUi2t9ysCmwJeOnfGy/OAEhqvqWrljo
	 5CZAX65SLmaTuQyjH16zXKxJaECtGyh6SVmWAKfn6qQygOKoTJEVy7ybEp1coafi4okWW
	 5bS3pgTTE497akCQZBhGzXH3Q2YjUq26wX/vq1kYfCFD3ilb8adMc9PPB51pV/9fKuQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796313120;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=NYGtvr+E3Wx4szPm5oiI4lj8EoZNqizFqfrEHqGQsZY=;
	b=yz8uiIoimXKuRYLuSvMcIiUMolG+Pg8Fq8Xf67tolYTH2WIwcw6sYU4w8Hoeiyn6z8qq
	 xgTtOQfbhSUYupSRflR2jsePomCLGkgPaSeRDZ9Pu2FDqxkj7/mjYx02WJKVlNKWdR/7Y
	 O2GjEXyxOn3ABNZmAP19/3FPEAWNPGlJbTk9NdRb39MrD5WaHyW8+W0mEPAWSDY6jWwMM
	 F4m6jVGkPyZmI1SZQkq0PpUT/RzFkZmt3kDATwtvgiEJwkVYFBkmE0phWAjGSB7utv6b5
	 H2Pqil3NgnSfqs7zuqbZQ1ZCh7a0GrpXS3n+dj8Gkf4o4fMvFDXKCa4tTbjApyZuANg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=f7DFmnOy;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 55EE8606A32C;
	Thu,  3 Dec 2026 15:52:00 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=f7DFmnOy
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796313114;
	b=JZpamkwg+b+ISDvMLXA3qCHd6kZG0TIYj58fZdKJAG1K5Cv8a20Zj51V82KPl2llfOAL
	 oWdvFJ6+7m8+uu11hrTR9nLdHi9vvYnquVavmj/DWDUgNgd66SYoZZtgQguRZSk2BWDVm
	 OgtcZAlKI6S+EVXkGVUC+dKbv0RLJf+uraulyM0LKtpNWj0raR/rrGAUw37cmaeJ9nXh2
	 9W0d5SFH0zkAUSQ0FW9kUG0oOsZVmp1LiE+XfjQvkm5rBEockw2Tzgp0zaK/PcB7A6Nw3
	 BLJqzp2pleHM2wwez0ijdK17rDCEwUQT5Pb9GCC/Ewor3na6RcL9FCYPhevG0wmy0dg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796313114;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=NYGtvr+E3Wx4szPm5oiI4lj8EoZNqizFqfrEHqGQsZY=;
	b=gQbEheTE7BVgWX1SWCIfUYlb//cSaJjCukte39Ff5OHxCa5UgrHvcLAStBhHtrZPkv7G
	 1XWiTxYQKP+64mqhJw+hKL9nIbZ1qjiide5TSHjkzsB9faBuRt1vBCDSUKYna94OtM+p+
	 AAm6aHIg3OQ7+QnMRW7eLoy/LNci3UEmcDx0ENfn77srybo/xMZMUJzSlt/UvbDweAG6U
	 8FLSRe5cMRR/47EPR4dii/tAhkipJpRALjtVteVuj4YhPtVYfyIMfCLck17ZLBKqa0fGN
	 u04w/3rGujfQsy4uu1yMApI91gxWBSSdjlhA+90/iWYjjzwaNjODVk0XWrulmOUHxyA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=f7DFmnOy;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73E85606A684;
	Thu,  3 Dec 2026 15:51:54 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 491041F00896;
	Thu,  3 Dec 2026 15:51:53 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796313114;
	bh=NYGtvr+E3Wx4szPm5oiI4lj8EoZNqizFqfrEHqGQsZY=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=f7DFmnOyRcHrsCFkeipi7RVaoYSeYpO4C8Kx4o+mnR76NAcYowx8n35e2q1l+InWA
	 5970WXlGimAD0ETbNqgv76xsWGmEnCqhMU2R8ITyMb3RTf2OmDojg9FZlSKSUpYT2Z
	 KwdiMeeSaTipSk7jpGkUdaF1HKxXfAiwfHjaq7uBp0MJUNsxUe9N2pUR2j79fUGK+Y
	 AElgrDejBoCRNyAN9B65+jyM3P+i11cAOOHJ3VM2kXgXU232zaYecRHgn/C94iXn2x
	 /teTdfK4/14Exzbte820324wgLEI+F7qHFmFRUPn6Xo/+qCHyVlL9mHlHcGQ+Tp9cI
	 tCE/z8LWy1jyA==
X-Cc: netdev@vger.kernel.org, mst@redhat.com, jasowang@redhat.com,
 pabeni@redhat.com, virtualization@lists.linux.dev, parav@nvidia.com,
 yohadt@nvidia.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com,
 jgg@ziepe.ca, kevin.tian@intel.com, kuba@kernel.org, andrew+netdev@lunn.ch,
 edumazet@google.com, danielj@nvidia.com
X-In-Reply-To: <20261202150502.3350030-12-shshitrit@nvidia.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list