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 06/14] virtio_net: Query and set flow filter caps
Date: Thu, 03 Dec 2026 15:51:48 +0000	[thread overview]
Message-ID: <179631310825.3146.11702506825860990902@kernel.org> (raw)
In-Reply-To: <20261202150502.3350030-7-shshitrit@nvidia.com>

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

  parent 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 [this message]
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
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=179631310825.3146.11702506825860990902@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