🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26477

Re: [PATCH net-next v24 03/14] virtio: Add config_op for admin commands

#26477
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 15:51
261 lines
18408 bytes
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
Technical Details
Message-ID: <179631310407.3146.4258156462913026029@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-376731-linux-kernel-netdev=dewy.ru
References: <20261202150502.3350030-4-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-376731-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v24 03/14] virtio: Add config_op for admin commands
Date: Thu, 03 Dec 2026 15:51:44 +0000
Organization: Usenet Network
Message-ID: <179631310407.3146.4258156462913026029@kernel.org>
References: <20261202150502.3350030-4-shshitrit@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2533711"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:GP4CMgaasN4DuoD95luWpw3j48c= sha256:Gpo86ST4R61qe2CV5fzfT0ewOad18AaAsHP0CTZgNws=
	sha1:+QY6/jbGs+W8usJBR5+BSwPXA/E= sha256:6FQrOMSGSzwm5AOav4exa7bgRxFT2qB+nkwyL5sB33U=
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 3024D1179C2; Thu,  3 Dec 2026 18:52:02 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.64
X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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 IiBKHqPnXzJS;
	Thu,  3 Dec 2026 18:51:58 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376731-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id C97371179BA; Thu,  3 Dec 2026 18:51:48 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 9B4402ABC1; Thu,  3 Dec 2026 15:51:46 +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=1796313106;
	b=o2tCEqVU+DmfoZxJjtFh1yjzf0yqgEnGS7LZcwTd9FTEVotCaw9Pe53y97tnes3vzrIw
	 xXFVU+VjW3FZMq3zrFA/fA3F16uyZ2YtuIHLc8QnCCxCuWdJ46lhviYjqn7j+SI+SBd4x
	 1wa4C+caGgePq0zcG7l4fpfHpGIri398Im0ouKOWRf0uf30ygynOhpXGZw+EyBFXDJ6zH
	 tNQ+bsM9yRVc20XXUfv3FYMZEGp/mPmkbLfDU/2laKr/OncR9e4kLzwcVLicWKWn/OFfn
	 oKq4A0XNHUPc2ChodtpyvlN1t8wJDsC/nyCPN/KbxpiR9drCksD92muvAH/dAbVlAzA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796313106;
	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=VjUHhBduMSfQcCdf/lPRBAR83xlG1i1niYzyWTVqPvM=;
	b=TELHIkFxuzZPAPf0/V1Bm+69O59nUsx4XYrU8uXp8xAGMiImLrYotFocF+TsQHXz3QVN
	 PQuL53ZsmtazzaDOEmMwtF2hGeE24wgkYsXFPXUAtcOJFhdtuBVD4d3siioySE37Ngs9V
	 DE65zSMagJBbkyPd9jao5HGALSEUcJpVOBH7jg6RqqhStyD3IlzNxzZwpnyMzAxXmFKNn
	 cqAll0WfBg6JhmiuzKFuN2+aylRzwpYYLLU0z8K0t13doNFxOG1tfIDrDWn6AL1Qv2sdj
	 Kpk7rjfzGBp0UPc/pA+0hLVZS+JSxrkxc/9AsnS+ktlDf+Fefw5kjKy+WX1U7n36xEA==
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=TvpS0dgL;
	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 72FF9606A336;
	Thu,  3 Dec 2026 15:51:46 +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=TvpS0dgL
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=1796313105;
	b=pDHYYgtU1CtRvhslWk/a9CibImPUpmKEzzhNLf6Ky3dwPX8n6HGDL6WodUjXgZGlUPlz
	 hG23dVW9yj3wSHcqo72SVkDHu1tFK/MAF4zj40Of5lmKZXzRoazjfp9zNGYj9PEqupXdu
	 x08+Hv45rWHJmtqNenVlZWm8LgtZMjTbjYsGCKJRCQfGvoFtfBiYFVYHSfDT4GAwftjy0
	 fzIAbqCcKsMoqqrzoxUei+TB+yLpO4jguERpzWZl8JdAnqlojyhGpqpZyfuh4hEeBkI0m
	 eHZvKLltL+CS2dBIH5u1leTY2mA4yRXdy8n35HIWfaDtjsHg2bUhH5Tg1siLPwbFdGA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796313105;
	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=VjUHhBduMSfQcCdf/lPRBAR83xlG1i1niYzyWTVqPvM=;
	b=koR/XeKG8nh71GmcCNLtfntKl4yOI1ouJBRkCJlGotR/lvsD5imGomrH5NxDTktZhOQR
	 DGNOUa8q769wyKfyYnre1enIGwg5UH/IMH39tRLYnZwFg6EEPzx/dQQxI5S80jD5wI/5w
	 MhBS35keWwBP3tLnXlIV7b0xAyJYoN+Jp4mtpbYkuZRuD6XBh5X1u2mHeX0/QF7bYcZKf
	 d70VzRh7NEu5CgB6n41+T2Vo5LyuDZwwsgbOkNA1yLJYCyAyijbe7XtzANY/mJD/S4v6X
	 GAQe4TJxcOjFip6mLJ9cO9j+MeZUmhQYkbo4CDKua109aJTTjKVx41GIEzT1+sjiILw==
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=TvpS0dgL;
	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 92747606A32D;
	Thu,  3 Dec 2026 15:51:45 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 780F41F000C1;
	Thu,  3 Dec 2026 15:51:44 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796313105;
	bh=VjUHhBduMSfQcCdf/lPRBAR83xlG1i1niYzyWTVqPvM=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=TvpS0dgL2giR/0bjHBVpqfBRjvtQNPRt2hGEB9hOxQ1+X63VHA58pMvAx648HEaXq
	 pdi7NCpq1T1yQpe4u2ci+PwjQ1LqkO0jZVbbDyuOiBr/YLLBwGlNo1XY280F78zkvY
	 JixNMEMQya3WkiS3lzs7OPQwLOlGit5mvc0JxGXnHs8xuTnz/cdcCFlFgj8ygNJ7Ff
	 F7OwHWTPkSsUJ1avWfzHQRRAVUh5yMqE5bbbM2d1w3bD6HgZ7/Pi02G1l31KA80c76
	 8yW60t3zbgjH5siEi80UMauurk5z3Qe2DGUi98PJqxtEE1T6PjfxDqeflKiJ3Ii9Pd
	 y6NNp+sb+QFLw==
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-4-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