From: Shahar Shitrit <shshitrit@nvidia.com>
To: netdev-bot+sashiko@kernel.org
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: [net-next,v23,11/14] virtio_net: Implement IPv4 ethtool flow rules
Date: Tue, 1 Dec 2026 16:57:04 +0200 [thread overview]
Message-ID: <cee6177f-853c-4ee5-b7b7-bf4119877bd6@nvidia.com> (raw)
In-Reply-To: <178835474877.3394541.3251614086995049997@kernel.org>
On 02/09/2026 16:12, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider:
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 1
>
> - [Medium] IP_USER_FLOW support silently ignores the ethtool `proto`
> match field.
> - [Low] While adding the `int num_hdrs` parameter, the patch also de-
> indents the two pre-existing continuation lines of…
>
> --
>
> virtio_net: Implement IPv4 ethtool flow rules
>
> This adds support for ethtool IP_USER_FLOW rules to the virtio_net flow
> filter code, building an extra IPv4 selector after the ethernet selector
> and matching on source/destination address and tos. The ethernet selector
> is forced to match ethertype IPv4 whenever an IPv4 header follows.
>
> (No Link: tags in the commit header.)
>
>> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
>> index 6c07eab047afe..c33bbdda75590 100644
>> --- a/drivers/net/virtio_net.c
>> +++ b/drivers/net/virtio_net.c
>
> [ ... ]
>
>> @@ -5809,6 +5810,39 @@ static bool validate_eth_mask(const struct virtnet_ff *ff,
>> return true;
>> }
>>
>> +static bool validate_ip4_mask(const struct virtnet_ff *ff,
>> + const struct virtio_net_ff_selector *sel,
>> + const struct virtio_net_ff_selector *sel_cap)
>> +{
>
> [ ... ]
>
>> + if (mask->protocol &&
>> + !check_mask_vs_cap(&mask->protocol, &cap->protocol,
>> + sizeof(u8), partial_mask))
>> + return false;
>> +
>
> [ ... ]
>
>> @@ -5820,11 +5854,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;
>> + }
>> +}
>
> [ ... ]
>
>> @@ -6016,8 +6091,9 @@ static void calculate_flow_sizes(struct ethtool_rx_flow_spec *fs,
>> }
>>
>> static void setup_eth_hdr_key_mask(struct virtio_net_ff_selector *selector,
>> - u8 *key,
>> - const struct ethtool_rx_flow_spec *fs)
>> + u8 *key,
>> + const struct ethtool_rx_flow_spec *fs,
>> + int num_hdrs)
>
> [Severity: Low]
> This isn't a bug, but the two pre-existing continuation lines lost one
> space of indentation here while the new num_hdrs parameter was added.
> "static void setup_eth_hdr_key_mask(" puts the open parenthesis one column
> further right, so the continuation lines no longer line up with it and
> checkpatch reports "Alignment should match open parenthesis". Was the
> re-indent intentional? Only the "int num_hdrs" line seems to need
> touching. The same alignment persists through the end of the series.
>
>> {
>> struct ethhdr *eth_m = (struct ethhdr *)&selector->mask;
>> struct ethhdr *eth_k = (struct ethhdr *)key;
>> @@ -6025,8 +6101,35 @@ 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->m_u.usr_ip4_spec.proto)
>> + return -EINVAL;
>> +
>> + parse_ip4(v4_m, v4_k, fs);
>> +
>> + return 0;
>> }
>
> [Severity: Medium]
> What happens to h_u.usr_ip4_spec.proto here? Every other unsupported
> IPv4 field is rejected, but a non-zero h_u.usr_ip4_spec.proto is neither
> rejected nor programmed.
>
> include/uapi/linux/ethtool.h documents the field for struct
> ethtool_usrip4_spec as:
>
> * @proto: Transport protocol number; mask must be 0
>
> So a conforming userspace passes the protocol in h_u with a zero mask in
> m_u, which is exactly the combination that passes all five checks above.
> parse_ip4() then only copies ip4src, ip4dst and tos, leaving
> key->protocol and mask->protocol zero in the zeroed key/classifier
> buffers.
>
> Does this mean
>
> ethtool -U ethX flow-type ip4 src-ip 192.168.51.101 l4proto 6 action -1
>
> installs a rule that matches ethertype IPv4 plus src-ip only, and
> therefore drops every protocol from that address rather than just TCP,
> without returning an error? Would it be better to either program
> iphdr->protocol from h_u.usr_ip4_spec.proto, or return -EINVAL when it is
> non-zero?
>
> There also seems to be a disagreement between the two new functions: the
> protocol check in validate_ip4_mask()
>
> if (mask->protocol &&
> !check_mask_vs_cap(&mask->protocol, &cap->protocol,
> sizeof(u8), partial_mask))
> return false;
>
> looks unreachable for IP_USER_FLOW, since a non-zero
> m_u.usr_ip4_spec.proto always returns -EINVAL in setup_ip_key_mask()
> first and parse_ip4() never sets mask->protocol. Is that intended?
>
> Checking the rest of the series, at 04f0a1ab the behaviour looks
> unchanged: setup_ip_key_mask() still returns -EINVAL for
> m_u.usr_ip4_spec.proto with num_hdrs == 2, parse_ip4() still never writes
> iphdr->protocol, and the protocol key is only filled in for
> TCP_V4_FLOW/UDP_V4_FLOW.
Will fix by rejecting a non-zero h_u.usr_ip4_spec.proto for ip4 rules
with -EINVAL, since the protocol was silently ignored and the rule
matched all protocols; use tcp4/udp4 for protocol matching.
>
> [ ... ]
>
next prev parent reply other threads:[~2026-12-01 14:57 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 16:10 [PATCH net-next v23 00/14] virtio_net: Add ethtool flow rules support Shahar Shitrit
2026-08-31 16:10 ` [PATCH net-next v23 01/14] virtio_pci: Remove supported_caps cache and build assert Shahar Shitrit
2026-08-31 16:10 ` [PATCH net-next v23 02/14] virtio_pci: Fix sleeping under spinlock in admin command path Shahar Shitrit
2026-09-02 13:12 ` [net-next,v23,02/14] " netdev-bot+sashiko
2026-09-03 9:25 ` Paolo Abeni
2026-12-01 14:27 ` Shahar Shitrit
2026-08-31 16:10 ` [PATCH net-next v23 03/14] virtio: Add config_op for admin commands Shahar Shitrit
2026-09-02 13:12 ` [net-next,v23,03/14] " netdev-bot+sashiko
2026-12-01 14:35 ` Shahar Shitrit
2026-08-31 16:10 ` [PATCH net-next v23 04/14] virtio: Expose generic device capability operations Shahar Shitrit
2026-09-02 13:12 ` [net-next,v23,04/14] " netdev-bot+sashiko
2026-08-31 16:11 ` [PATCH net-next v23 05/14] virtio: Expose object create and destroy API Shahar Shitrit
2026-09-02 13:12 ` [net-next,v23,05/14] " netdev-bot+sashiko
2026-08-31 16:11 ` [PATCH net-next v23 06/14] virtio_net: Query and set flow filter caps Shahar Shitrit
2026-09-02 13:12 ` [net-next,v23,06/14] " netdev-bot+sashiko
2026-12-01 14:39 ` Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 07/14] virtio_net: Create a FF group for ethtool steering Shahar Shitrit
2026-09-02 13:12 ` [net-next,v23,07/14] " netdev-bot+sashiko
2026-12-01 14:40 ` Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 08/14] ethtool: Introduce ethtool_flow_type_mask() Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 09/14] virtio_net: Implement layer 2 ethtool flow rules Shahar Shitrit
2026-09-02 13:12 ` [net-next,v23,09/14] " netdev-bot+sashiko
2026-12-01 14:51 ` Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 10/14] virtio_net: Use existing classifier if possible Shahar Shitrit
2026-09-02 13:12 ` [net-next,v23,10/14] " netdev-bot+sashiko
2026-12-01 14:56 ` Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 11/14] virtio_net: Implement IPv4 ethtool flow rules Shahar Shitrit
2026-09-02 13:12 ` [net-next,v23,11/14] " netdev-bot+sashiko
2026-12-01 14:57 ` Shahar Shitrit [this message]
2026-08-31 16:11 ` [PATCH net-next v23 12/14] virtio_net: Add support for IPv6 ethtool steering Shahar Shitrit
2026-09-02 13:12 ` [net-next,v23,12/14] " netdev-bot+sashiko
2026-12-01 14:57 ` Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 13/14] virtio_net: Add support for TCP and UDP ethtool rules Shahar Shitrit
2026-08-31 16:11 ` [PATCH net-next v23 14/14] virtio_net: Add get ethtool flow rules ops Shahar Shitrit
2026-09-02 13:12 ` [net-next,v23,14/14] " netdev-bot+sashiko
2026-12-01 14:58 ` Shahar Shitrit
2026-08-31 16:37 ` [PATCH net-next v23 00/14] virtio_net: Add ethtool flow rules support Michael S. Tsirkin
2026-08-31 19:45 ` Michael S. Tsirkin
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=cee6177f-853c-4ee5-b7b7-bf4119877bd6@nvidia.com \
--to=shshitrit@nvidia.com \
--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-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=parav@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