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=1796313110; b=fqmb4lPCnt74ldx2FPCyaa6I+gLa7EUWstg8spQtcGwZXmai7Vwclwu/zIJ5lI2p5CjB fmdxXGOBADZfpC4AaSC9GAavfY9k18rDHDR/BeNLHv0uvaPmJoaeHjBAYmt11Gin/tOec moqNQIOVQYHl/e2P9RahIBSO9VRVppskS2EvqBY1n3jCYKz90ihc1eVvTTi64wLqzddU+ ubOVcAqFfDxHDRKsY3ThyK/+H8rO/u1ntg/ZwyJk8gX1XYmRf4572t8+vt1j3FDGUFuUt XpbFwW3mZBdNTU7QRPZVWsxnpUFwbZKsOGEHNfsi7pjzCA4s/BoTi0lOGcLfUoBdzQw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796313110; 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=YjMJKf7BR7INbz7/nks7pCVYgcl5MzsBXahgUlVAet4=; b=g4gCKzQ8m3Pqi8j3VfOp472gD9RDnq1HBvutjmG0WFF0SLXPPNVmEVq5NG+yg0dzhdHb 23ZF9tzYxVjgOIGxOgGBtx3yttG7cHt3omYunr1k513TihtFfst228NX/42vfO1DrJP5L IMuJjwlrKsav7Dm6DUFE5SJBwkMQ4JTSvk4Qoi7urj2ercT87fJ4DlbVirMB0KflVE7pO Qwmw1Be4G3aH5wXQW+MIlrtVJ3lKoLss5hpH8zWGTowH9rmhvCvEyEV/C+hahrx35LGXs PvTXIjPuu/3NZf36jc20IR4s1GdVUvZEkoDJdnaseVeZaKQmsKWCip4q7+ERnVQkJvg== 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=WiEUiqRr; 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 184EC606A332; Thu, 3 Dec 2026 15:51:49 +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=WiEUiqRr Received: by smtp.kernel.org (Postfix) with ESMTPSA id B81981F00898; Thu, 3 Dec 2026 15:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796313109; bh=YjMJKf7BR7INbz7/nks7pCVYgcl5MzsBXahgUlVAet4=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=WiEUiqRrbBh5wIMnqvamen159RWol4rmLXZt7S0P8W3kwKP7w1fdyUqItekSwMzul fG668/qevUQEHaEhCsamYS/ER238w7CYuiyvAF0QHQX56xJJ2ImY7rTMIAtd7/YhwI iocuOp6hZChw5ecq3k5HKhVWrVM1cXKWn+gAlgZvjN7E+BBFpWbP3QT2xb+gEfY5ji R5QVI0QrZL7Cw9CtgSoQ8Rqp/W5pK2OOMywAA+V8wKioUXPxhyU3kYrBoOI3CwUq9o LLTFLWYDwPZrR/QrkXPMO/zGGFnZNwSxsmsjTAtsG9YbApvP7nENluWKtj0ifU78+c HAAQW3RjCcmCg== Subject: Re: [PATCH net-next v24 06/14] virtio_net: Query and set flow filter caps 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:48 +0000 Message-ID: <179631310825.3146.11702506825860990902@kernel.org> In-Reply-To: <20261202150502.3350030-7-shshitrit@nvidia.com> References: <20261202150502.3350030-7-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 4 potential issue(s) to consider. Critical: 0 · High: 0 (1) · Medium: 3 · Low: 1 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] Flow filters are optional and nothing in this patch uses them, yet a failed flow-filter init now aborts probe and resume. - [Medium] In virtnet_ff_init() (drivers/net/virtio_net.c:5904-5925, 5965-5968) the action capability list from the device is echoed back… - [Medium] virtio_net: unbalanced disable_rx_mode_work() in virtnet_restore_up() - [Low] virtnet_ff_init() reads the three FF capability structures with DEVICE_CAP_GET into ff->ff_caps, ff->ff_mask and ff->ff_actions. Pre-existing issues: - [High] This problem wasn't introduced by this patch, but the patch adds a new path that a device can trigger. -- virtio_net: Query and set flow filter caps This commit adds virtnet_ff_init(). During probe and restore it reads the flow filter resource, selector and action capabilities with virtio admin commands, then sets the same capabilities back on the device. It also adds the uapi header virtio_net_ff.h, with the flow filter definitions from version 1.4 of the VirtIO spec. > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index 5eef2c3159638..03aea14da492e 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c [ ... ] > @@ -5794,6 +5809,199 @@ static const struct netdev_stat_ops virtnet_stat_ops = { [ ... ] > + err = virtio_admin_cap_get(vdev, > + VIRTIO_NET_FF_ACTION_CAP, > + ff->ff_actions, > + sizeof(*ff->ff_actions) + VIRTIO_NET_FF_ACTION_MAX); > + > + if (err) > + goto err_ff_action; > + > + ff->ff_actions->count = min_t(u8, ff->ff_actions->count, > + VIRTIO_NET_FF_ACTION_MAX); [Severity: Medium] Is this clamp checking the right thing in virtnet_ff_init()? VIRTIO_NET_FF_ACTION_MAX is an action identifier, but here it is used as a count. The entries are cut off by position, and nothing checks that each entry is VIRTIO_NET_FF_ACTION_DROP or VIRTIO_NET_FF_ACTION_RX_VQ. Say a newer device reports actions [3, 1, 2]. The driver keeps [3, 1] and later sends that back with virtio_admin_cap_set(). It claims action 3, which it doesn't implement, and drops RX_VQ, which it does implement. Duplicate action IDs also get through. Later in the series, RX_VQ rules look in ff_actions->actions[] for the action they need. Would those rules be refused in this case? The selector loop further down has a similar problem: if (!sel->type || sel->type > VIRTIO_NET_FF_MASK_TYPE_MAX) break; The comment above it expects spec revisions that add new selector types. However, the loop stops at the first unknown entry instead of skipping it by sel->length. If an unknown type comes first, ff_mask->count becomes 0. An empty selector set is then sent to the device, and ff_supported is still set to true. Should unknown actions and selectors be filtered out individually, and should an empty selector set be rejected? This code is the same at the end of the series. > + if (!ff->ff_actions->count) { > + err = -EINVAL; > + goto err_ff_action; > + } [ ... ] > + ff->ff_mask->count = i; > + > + err = virtio_admin_cap_set(vdev, > + VIRTIO_NET_FF_SELECTOR_CAP, > + ff->ff_mask, > + real_ff_mask_size); [Severity: Low] The buffers filled by virtio_admin_cap_get() go back to the device unchanged through virtio_admin_cap_set(), which does: memcpy(data->cap_specific_data, caps, cap_size); So any value the device wrote into ff_mask->reserved[], each sel->reserved[] and sel->reserved1[], ff_actions->reserved[] and ff_caps->reserved[] is echoed back. The new uapi header says these fields "must be set to 0 by the driver". Should they be cleared before the set commands? sel->flags is also echoed back without masking it to VIRTIO_NET_FF_MASK_F_PARTIAL_MASK. If a device reports a future flag bit, would the driver end up claiming support for it? The resource and action cap sets in virtnet_ff_init() follow the same pattern. This code is the same at the end of the series. > + if (err) > + goto err_ff_action; > + > + err = virtio_admin_cap_set(vdev, > + VIRTIO_NET_FF_ACTION_CAP, > + ff->ff_actions, > + sizeof(*ff->ff_actions) + ff->ff_actions->count); > + if (err) > + goto err_ff_action; [ ... ] > @@ -5838,6 +6050,20 @@ static int virtnet_restore_up(struct virtio_device *vdev) > goto err_destroy_pools; > } > > + /* > + * Initialize flow filters. Not supported is an acceptable and common > + * return code > + */ > + rtnl_lock(); > + err = virtnet_ff_init(&vi->ff, vi->vdev); > + if (err && err != -EOPNOTSUPP) { > + rtnl_unlock(); > + virtnet_freeze_down(vi->vdev); > + remove_vq_common(vi); > + return err; > + } [Severity: Medium] Does calling virtnet_freeze_down() on this error path leave vi->rx_mode_work disabled twice? virtnet_freeze() has already run virtnet_freeze_down(). That called disable_rx_mode_work(), which does disable_work_sync() on vi->rx_mode_work. The matching enable_rx_mode_work() only runs at the end of virtnet_restore_up(), after this new block. So when virtnet_ff_init() fails, the work is still disabled from the freeze, and it gets disabled again: virtnet_freeze() virtnet_freeze_down() disable_rx_mode_work() <- disable count 0 -> 1 virtnet_restore() virtnet_restore_up() virtnet_open() virtnet_ff_init() fails virtnet_freeze_down() disable_rx_mode_work() <- disable count 1 -> 2 Nothing removes that extra disable. A later enable_rx_mode_work() only brings the count back to 1. Queueing a disabled work item does nothing, so rx mode changes requested through ndo_set_rx_mode would be dropped silently from then on. virtnet_freeze_down() also repeats netif_device_detach() and virtnet_ff_cleanup(), which already ran at freeze time. It was written to quiesce a running device. It was not written to undo a partial restore. Could virtnet_ff_init() be called before the netif_running() and virtnet_open() block instead, with failures unwinding through err_destroy_pools? virtnet_probe() already does this right after virtio_device_ready(). The netdev would then not be opened and closed again here, and the disable/enable of rx_mode_work would stay balanced. [Severity: High] This is a pre-existing issue and was not introduced by this patch, but this new error path reaches it. remove_vq_common() ends up in virtnet_del_vqs()->virtnet_free_queues(), which does this without clearing the pointers: kfree(vi->rq); kfree(vi->sq); kfree(vi->ctrl); virtnet_restore() then returns the error. virtio_device_restore_priv() only marks the device as failed, so the driver stays bound: err: virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED); return ret; On a later unbind, rmmod or hot-unplug: virtnet_remove() remove_vq_common() free_unused_bufs() struct virtqueue *vq = vi->sq[i].vq; <- vi->sq already freed virtnet_del_vqs() virtnet_free_queues() <- second kfree() Can this cause a use-after-free and then a double free of vi->sq, vi->rq and vi->ctrl? The restore failure paths for virtnet_cpu_notif_add() and for the open and page pool failures already have this problem. With this patch, any flow filter init failure on resume also reaches it, for example -ENOMEM, a device error status, -EIO, zero limits or malformed selectors. The problem is still there at the end of the series. > + rtnl_unlock(); [ ... ] > @@ -7142,6 +7368,15 @@ static int virtnet_probe(struct virtio_device *vdev) > > virtio_device_ready(vdev); > > + /* Initialize flow filters. Not supported is an acceptable and common > + * return code > + */ > + err = virtnet_ff_init(&vi->ff, vi->vdev); > + if (err && err != -EOPNOTSUPP) { > + rtnl_unlock(); > + goto free_unregister_netdev; > + } [Severity: Medium] Flow filters are optional, and nothing in this patch uses them yet. Should a failure here make the whole probe fail? Only -EOPNOTSUPP is treated as harmless. virtnet_ff_init() can return other errors when the feature just can't be used. vp_modern_admin_cmd_exec() turns any non-OK device status into an error with "ret = -status". A device that rejects the command therefore gives -EINVAL, not -EOPNOTSUPP. A broken vq or an add/kick failure gives -EIO. The -EOPNOTSUPP check in the admin path looks at admin_vq.supported_cmds. That list comes from the SR-IOV group query in virtio_pci_admin_cmd_list_init(). The flow filter cap commands use VIRTIO_ADMIN_GROUP_TYPE_SELF instead, so a device can pass that check and still reject the command. The sanity checks in virtnet_ff_init() return -EINVAL for zero limits or zero actions, and -EPROTO for a bad selector length or a duplicate selector type. Allocation failures return -ENOMEM. virtio_pci_admin_cmd_cap_init() sends the same SELF group cap id list query and treats a failure as non-fatal: ret = vp_modern_admin_cmd_exec(virtio_dev, &cmd); if (ret) goto end; Could a device that probed fine before this patch now fail probe here? virtnet_restore_up() has the same problem: resume fails and the vqs are torn down. Later in the series this handling stays the same and gains more fatal cases: -ENOSPC when groups_limit < VIRTNET_FF_MAX_GROUPS, and a failure of virtio_admin_obj_create() for the ethtool group. Would it be better to log the failure and continue without flow filters? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202150502.3350030-1-shshitrit%40nvidia.com