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 03/14] virtio: Add config_op for admin commands
Date: Thu, 03 Dec 2026 15:51:44 +0000 [thread overview]
Message-ID: <179631310407.3146.4258156462913026029@kernel.org> (raw)
In-Reply-To: <20261202150502.3350030-4-shshitrit@nvidia.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 (2) · 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] The commit message says the new op 'will allow device drivers
to issue administration commands'.
- [Low] virtqueue_exec_admin_cmd() returns cmd->ret after
wait_for_completion() (drivers/virtio/virtio_pci_modern.c:125-127),…
- [Low] The new kerneldoc says admin_cmd_exec 'Must only be called after
find_vqs() and before del_vqs()'.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch
exposes it to every virtio driver and documents a contract it breaks.
- [High] This problem wasn't introduced by this patch, but the new
kerneldoc misdescribes it and the series' new callers make it a…
--
virtio: Add config_op for admin commands
This commit adds an optional admin_cmd_exec() callback to struct
virtio_config_ops, with kerneldoc describing its contract. It wires the
callback to vp_modern_admin_cmd_exec() in both virtio-pci modern config ops
tables, so that virtio device drivers can issue admin VQ commands.
> diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
> index d5ab2c11d0842..ceb386ab3a214 100644
> --- a/drivers/virtio/virtio_pci_modern.c
> +++ b/drivers/virtio/virtio_pci_modern.c
> @@ -1254,6 +1254,7 @@ static const struct virtio_config_ops virtio_pci_config_nodev_ops = {
> .get_shm_region = vp_get_shm_region,
> .disable_vq_and_reset = vp_modern_disable_vq_and_reset,
> .enable_vq_after_reset = vp_modern_enable_vq_after_reset,
> + .admin_cmd_exec = vp_modern_admin_cmd_exec,
> };
[Severity: Medium]
The commit message says:
This will allow device drivers to issue administration commands.
Does the transport behind this op match that description?
virtqueue_exec_admin_cmd() rejects every opcode other than LIST_QUERY and
LIST_USE that is missing from supported_cmds:
if (opcode != VIRTIO_ADMIN_CMD_LIST_QUERY &&
opcode != VIRTIO_ADMIN_CMD_LIST_USE &&
!((1ULL << opcode) & admin_vq->supported_cmds))
return -EOPNOTSUPP;
Only virtio_pci_admin_cmd_list_init() writes supported_cmds. It queries and
enables commands for the SR-IOV group only, and masks the result with the
transport-private VIRTIO_ADMIN_CMD_BITMAP:
cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SRIOV);
...
*data &= cpu_to_le64(VIRTIO_ADMIN_CMD_BITMAP);
...
vp_dev->admin_vq.supported_cmds = le64_to_cpu(*data);
Later in the series, the virtio_net flow-filter user sends all of its
commands with VIRTIO_ADMIN_GROUP_TYPE_SELF. That covers
virtio_admin_cap_get(), virtio_admin_cap_set(), virtio_admin_obj_create()
and virtio_admin_obj_destroy(). The SELF group is never queried, and never
enabled with LIST_USE.
Take a device that has an admin VQ but no SR-IOV group, such as a VF or a
non-SR-IOV device assigned to a guest. If the SRIOV LIST_QUERY fails or
returns an empty list, supported_cmds stays 0. Wouldn't every SELF-group
command then fail with -EOPNOTSUPP?
One example is virtnet_ff_init()->virtio_admin_cap_id_list_query().
virtio_net treats -EOPNOTSUPP as "not supported" and drops the feature
without any message.
The op is also installed unconditionally, so a non-NULL admin_cmd_exec
doesn't mean admin commands work. vp_modern_admin_cmd_exec() returns
-EOPNOTSUPP when VIRTIO_F_ADMIN_VQ isn't negotiated.
Neither the commit message nor the new kerneldoc mentions this gating or
the -EOPNOTSUPP return. Could both be documented?
[ ... ]
> diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> index 69f84ea85d71a..c816bb6ddb474 100644
> --- a/include/linux/virtio_config.h
> +++ b/include/linux/virtio_config.h
> @@ -108,6 +108,14 @@ struct virtqueue_info {
> * Returns 0 on success or error status
> * If disable_vq_and_reset is set, then enable_vq_after_reset must also be
> * set.
> + * @admin_cmd_exec: Execute an admin VQ command (optional).
> + * vdev: the virtio_device
> + * cmd: the command to execute
> + * Returns 0 on success or error status
[Severity: Low]
Is a return of 0 on success actually guaranteed? virtqueue_exec_admin_cmd()
initializes cmd->completion itself, but it returns cmd->ret, and nothing
writes that field on the success path:
init_completion(&cmd->completion);
...
wait_for_completion(&cmd->completion);
return cmd->ret;
vp_modern_avq_work() only sets result_sg_size and calls complete(). The only
writer of cmd->ret is vp_modern_avq_cleanup(), which sets it to -EIO.
Suppose a caller kmalloc()s or stack-allocates cmd without zeroing it. A
successful command would then be reported as a random error.
vp_modern_admin_cmd_exec() would also take the err_cmd_exec path and log
"Failed to execute command on admin vq".
All current callers use struct virtio_admin_cmd cmd = {}, including the
in-series virtio_admin_commands.c helpers, so none is affected today.
Should virtqueue_exec_admin_cmd() set cmd->ret = 0 next to
init_completion(), or should the kerneldoc require a zeroed cmd?
> + * May sleep, so process context only. Blocks until the device completes
> + * the command, or until del_vqs() fails it with -EIO. Returns -EIO if
[Severity: High]
This isn't a bug introduced by this patch, but the patch exposes it to every
virtio driver and documents a contract that the kick failure path doesn't
follow.
In virtqueue_exec_admin_cmd(), once virtqueue_add_sgs() succeeds, cmd and the
hdr, status, data and result buffers are on the ring. If virtqueue_kick()
then fails, the function returns without detaching that buffer:
ret = virtqueue_add_sgs(vq, sgs, out_num, in_num, cmd, GFP_KERNEL);
...
if (!virtqueue_kick(vq))
goto unlock_err;
...
unlock_err:
mutex_unlock(&admin_vq->lock);
return -EIO;
virtqueue_kick() fails when vq->broken is set. One way that happens is
virtio_pci_remove() calling virtio_break_device() on surprise removal.
After the failure, vp_modern_admin_cmd_exec() frees va_hdr and va_status.
The caller's stack-allocated struct virtio_admin_cmd also goes out of scope,
for example in virtio_admin_obj_create().
vp_modern_avq_work() can't reap the token, because virtqueue_get_buf()
returns NULL on a broken vq. virtqueue_detach_unused_buf_split() doesn't
check broken, though, so del_vqs()->vp_modern_avq_cleanup() later runs:
while ((cmd = virtqueue_detach_unused_buf(vq))) {
cmd->ret = -EIO;
complete(&cmd->completion);
}
Can this write into a dead stack frame? complete() would also take a
spinlock and walk a wait list in that stale memory.
The final series has a concrete trigger. An ethtool -N or -U request goes
through virtio_admin_obj_create() or virtio_admin_obj_destroy() under rtnl.
If the device is surprise-removed while that request is between add_sgs and
kick, this path follows:
virtio_pci_remove()
virtio_break_device()
unregister_virtio_device()
virtnet_remove()
remove_vq_common()
del_vqs()
vp_modern_avq_cleanup()
This behaviour dates back to commit 4c3b54af907e ("virtio_pci_modern: use
completion instead of busy loop to wait on admin cmd result").
> + * the admin VQ is broken. Must only be called after find_vqs() and
[Severity: High]
This is a pre-existing issue, but does "Returns -EIO if the admin VQ is
broken" hold for commands that are already in flight?
virtqueue_exec_admin_cmd() checks virtqueue_is_broken() only before it
submits the command. After that it waits uninterruptibly with no timeout:
again:
if (virtqueue_is_broken(vq))
return -EIO;
...
wait_for_completion(&cmd->completion);
virtio_break_device() only sets vq->broken and doesn't complete outstanding
admin commands. The only wakeup is vp_modern_avq_cleanup() during del_vqs().
That seems to conflict with this comment in virtio_pci_remove():
* Device is marked broken on surprise removal so that virtio upper
* layers can abort any ongoing operation.
For comparison, the virtio_net control VQ wait polls virtqueue_is_broken().
In the final series, virtio_net issues admin commands under rtnl_lock: from
ethtool set_rxnfc, and from virtnet_ff_init() in probe and restore. If the
device stops completing a command, the caller blocks forever while holding
rtnl. That can happen on surprise removal, or with a hung device or
firmware. On surprise removal:
virtio_pci_remove()
virtio_break_device() <- no wakeup for the waiter
unregister_virtio_device()
virtnet_remove()
unregister_netdev() <- needs rtnl, held by the waiter
...
remove_vq_common() <- del_vqs(), never reached
Can this deadlock the removal path along with every other rtnl user? The
untimed wait also dates back to commit 4c3b54af907e.
> + * before del_vqs(), as the admin VQ does not exist otherwise.
[Severity: Low]
Is the find_vqs() to del_vqs() window the right precondition to document?
The comment above virtio_device_ready() says:
* Driver must call this to use vqs in the probe function.
The transport also fills in supported_cmds only at DRIVER_OK:
vp_set_status()
vp_modern_avq_activate()
virtio_pci_admin_cmd_list_init()
Suppose a driver follows this doc and calls the op in probe, between
find_vqs() and virtio_device_ready(). On first probe supported_cmds is still
0, so commands the device supports would fail with -EOPNOTSUPP.
supported_cmds is never cleared on reset or del_vqs(), so on restore it
still holds the value from before suspend. A command could then pass the
gate and be kicked before DRIVER_OK. The device isn't required to process
it, so could the restore thread block forever in wait_for_completion()
before it gets to set DRIVER_OK?
The in-series virtio_net callers run virtnet_ff_init() only after
virtio_device_ready(), so they aren't affected. Would "after DRIVER_OK" be
a more accurate precondition?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202150502.3350030-1-shshitrit%40nvidia.com
next prev 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 [this message]
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
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=179631310407.3146.4258156462913026029@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