From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 491041F00896; Thu, 3 Dec 2026 15:51:53 +0000 (UTC) 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== Subject: Re: [PATCH net-next v24 11/14] virtio_net: Implement IPv4 ethtool flow rules 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 Date: Thu, 03 Dec 2026 15:51:52 +0000 Message-ID: <179631311284.3146.4618650342552521395@kernel.org> In-Reply-To: <20261202150502.3350030-12-shshitrit@nvidia.com> References: <20261202150502.3350030-12-shshitrit@nvidia.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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