Article View: linux.kernel.netdev
Article #26483Re: [PATCH net-next v24 06/14] virtio_net: Query and set flow filter caps
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 15:51
Date: Thu, 03 Dec 2026 15:51
278 lines
17996 bytes
17996 bytes
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
Technical Details
Message-ID:
<179631310825.3146.11702506825860990902@kernel.org>Path:
mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376734-linux-kernel-netdev=dewy.ruReferences:
<20261202150502.3350030-7-shshitrit@nvidia.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376734-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v24 06/14] virtio_net: Query and set flow filter caps Date: Thu, 03 Dec 2026 15:51:48 +0000 Organization: Usenet Network Message-ID: <179631310825.3146.11702506825860990902@kernel.org> References: <20261202150502.3350030-7-shshitrit@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2534142"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:JDXJAmaZ4quPMvPM4C4mXWV9s+Q= sha256:Y9dEjqf2/yNH8ixWfYiOe38FNJblEQt+E4GE56ylpBc= sha1:UDoSg8VsCImejW9hr/m1qKlUnO4= sha256:0bI+2S7LpVaklnc6xlijfilNmymSq3jZPfRJrgaCL30= 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 C66D41179BA; Thu, 3 Dec 2026 18:52:15 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.74 X-Spam-Status: No, score=-3.74 tagged_above=-9999 required=6.31 tests=[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 VFv8Gm81z-lD; Thu, 3 Dec 2026 18:52:12 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376734-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 381021179B6; Thu, 3 Dec 2026 18:52:00 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 36CE625A6F; Thu, 3 Dec 2026 15:51:56 +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=1796313116; b=gEYjsv4Znyz8xsJzZBrHEiJAjborDF48wg63qTGFRTtCJH0IL/Go0gRkB7MAmaxtzKgl +9fcandlaSF2QFehyrIeVy0qe0au0ATMBP6akhhGlDVU/nWuZQlosNKGpcxvWb+wrmkbb hCoHtkgYENl5Maec2ooL7DksA6FLHrROGARLwXldnqPrviTADXK2LX6+ep1Pvbhwjjshj SLFDO8PRMVqvVxafyQZ8MXfAqWme6tbqQXTf3Hef1CMXVsNXUq+w4fsO+vk8fYoe34DN3 7UGhElCu15EVeXv+nXwkAnMmT5I/hXKgJsBuBKkqqh3alPuxdxPbTMqVFTu0Q/vNJBQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796313116; 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=YjMJKf7BR7INbz7/nks7pCVYgcl5MzsBXahgUlVAet4=; b=wWXrYRp4QaIqmYwyr68nh/HAsyH2D/neXv4B1mKPHyttjjEDP1l+W/Q0AFdjgjTdulfG Gh+rg+3Ty+0UojuqLV2evTxwKBTWtbXFslJzMPErJTN+iBRdfABipHjt/MnqAfXnfdL24 MS5iue4vmI1L5OjfbHfF+FiAAB4P9qYVgvnU65miNr7/7bbSniEjasZbc/ecnSI5NW4B6 piS5Rmo4y+tP7mJFE1zv26tADX4BZIlpSgugfC3QXjlJvcrp14PCpnZ5THhsPnY1ov7YN bkrYH2qKqM48wenGAR9DT6TAnbh1Ak0aiDczJgPuNSMpdqWGFZZXzmMzJKc0cM3utpw== 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=WiEUiqRr; 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 EFB9D606A32D; Thu, 3 Dec 2026 15:51:55 +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=WiEUiqRr 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=1796313110; b=fqmb4lPCnt74ldx2FPCyaa6I+gLa7EUWstg8spQtcGwZXmai7Vwclwu/zIJ5lI2p5CjB fmdxXGOBADZfpC4AaSC9GAavfY9k18rDHDR/BeNLHv0uvaPmJoaeHjBAYmt11Gin/tOec moqNQIOVQYHl/e2P9RahIBSO9VRVppskS2EvqBY1n3jCYKz90ihc1eVvTTi64wLqzddU+ ubOVcAqFfDxHDRKsY3ThyK/+H8rO/u1ntg/ZwyJk8gX1XYmRf4572t8+vt1j3FDGUFuUt XpbFwW3mZBdNTU7QRPZVWsxnpUFwbZKsOGEHNfsi7pjzCA4s/BoTi0lOGcLfUoBdzQw== X-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== 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=WiEUiqRr; 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 184EC606A332; Thu, 3 Dec 2026 15:51:49 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B81981F00898; Thu, 3 Dec 2026 15:51:48 +0000 (UTC) X-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== 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-7-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