Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: shshitrit@nvidia.com
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
Subject: Re: [PATCH net-next v24 11/14] virtio_net: Implement IPv4 ethtool flow rules
Date: Thu, 03 Dec 2026 15:51:52 +0000	[thread overview]
Message-ID: <179631311284.3146.4618650342552521395@kernel.org> (raw)
In-Reply-To: <20261202150502.3350030-12-shshitrit@nvidia.com>

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

  reply	other threads:[~2026-12-03 15:51 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 15:04 [PATCH net-next v24 00/14] virtio_net: Add ethtool flow rules support Shahar Shitrit
2026-12-02 15:04 ` [PATCH net-next v24 01/14] virtio_pci: Remove supported_caps cache and build assert Shahar Shitrit
2026-12-02 15:04 ` [PATCH net-next v24 02/14] virtio_pci: Fix sleeping under spinlock in admin command path Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 03/14] virtio: Add config_op for admin commands Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 04/14] virtio: Expose generic device capability operations Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 05/14] virtio: Expose object create and destroy API Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 06/14] virtio_net: Query and set flow filter caps Shahar Shitrit
2026-12-03 13:16   ` Michael S. Tsirkin
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 07/14] virtio_net: Create a FF group for ethtool steering Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 08/14] ethtool: Introduce ethtool_flow_type_mask() Shahar Shitrit
2026-12-02 15:04 ` [PATCH net-next v24 09/14] virtio_net: Implement layer 2 ethtool flow rules Shahar Shitrit
2026-12-03 13:19   ` Michael S. Tsirkin
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 10/14] virtio_net: Use existing classifier if possible Shahar Shitrit
2026-12-03 13:20   ` Michael S. Tsirkin
2026-12-02 15:04 ` [PATCH net-next v24 11/14] virtio_net: Implement IPv4 ethtool flow rules Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko [this message]
2026-12-02 15:05 ` [PATCH net-next v24 12/14] virtio_net: Add support for IPv6 ethtool steering Shahar Shitrit
2026-12-02 15:05 ` [PATCH net-next v24 13/14] virtio_net: Add support for TCP and UDP ethtool rules Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:05 ` [PATCH net-next v24 14/14] virtio_net: Add get ethtool flow rules ops Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:08 ` [PATCH net-next v24 00/14] virtio_net: Add ethtool flow rules support netdev-bot+sinfo
     [not found]   ` <BL0PR12MB5505B05C081539D249C49DCCDA4B2@BL0PR12MB5505.namprd12.prod.outlook.com>
2026-12-03 11:06     ` Shahar Shitrit

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=179631311284.3146.4618650342552521395@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=danielj@nvidia.com \
    --cc=edumazet@google.com \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=kevin.tian@intel.com \
    --cc=kuba@kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=parav@nvidia.com \
    --cc=shshitrit@nvidia.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    --cc=yohadt@nvidia.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox