Article View: linux.kernel.netdev
Article #26480Re: [PATCH net-next v24 05/14] virtio: Expose object create and destroy API
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 15:51
Date: Thu, 03 Dec 2026 15:51
169 lines
13629 bytes
13629 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The new helpers virtio_admin_obj_create() and
virtio_admin_obj_destroy() in drivers/virtio/virtio_admin_commands.cโฆ
- [Low] virtio_admin_obj_create()/destroy() accept any obj_type and
obj_id.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the new
helpers add two more exposed callers.
--
virtio: Expose object create and destroy API
This commit adds virtio_admin_obj_create() and virtio_admin_obj_destroy()
to drivers/virtio/virtio_admin_commands.c. They build the
RESOURCE_OBJ_CREATE and RESOURCE_OBJ_DESTROY admin commands from an object
type, id and group fields passed in by the caller. This lets upper layer
drivers use them outside the existing dev parts code.
> diff --git a/drivers/virtio/virtio_admin_commands.c b/drivers/virtio/virtio_admin_commands.c
> index d4bf8c48e1d91..c53c26de91975 100644
> --- a/drivers/virtio/virtio_admin_commands.c
> +++ b/drivers/virtio/virtio_admin_commands.c
> @@ -96,5 +96,82 @@ int virtio_admin_cap_set(struct virtio_device *vdev,
> }
> EXPORT_SYMBOL_GPL(virtio_admin_cap_set);
>
> +int virtio_admin_obj_create(struct virtio_device *vdev,
> + u16 obj_type,
> + u32 obj_id,
> + u16 group_type,
> + u64 group_member_id,
> + const void *obj_specific_data,
> + size_t obj_specific_data_size)
> +{
[ ... ]
> + obj_create_data = data;
> + obj_create_data->hdr.type = cpu_to_le16(obj_type);
> + obj_create_data->hdr.id = cpu_to_le32(obj_id);
[Severity: Low]
Should these helpers reject VIRTIO_RESOURCE_OBJ_DEV_PARTS, or at least
document that it must not be passed?
virtio_pci_admin_obj_create() and virtio_pci_admin_obj_destroy() in
drivers/virtio/virtio_pci_modern.c track ids for that object type in
admin_vq.dev_parts_ida:
virtio_pci_admin_obj_create() {
...
id = ida_alloc_range(&avq->dev_parts_ida, 0,
avq->max_dev_parts_objects - 1, GFP_KERNEL);
...
}
virtio_pci_admin_obj_destroy() {
...
if (!ret) {
vp_dev = to_vp_device(virtio_dev);
ida_free(&vp_dev->admin_vq.dev_parts_ida, id);
}
...
}
The new generic helpers accept any obj_type and obj_id. If a caller used
them with VIRTIO_RESOURCE_OBJ_DEV_PARTS, dev_parts_ida could fall out of
sync. A duplicate id could be handed out later, or ida_free() could warn
about an id it never allocated.
No caller in this series does this. The virtio_net users pass the
VIRTIO_NET_RESOURCE_OBJ_FF_* types with VIRTIO_ADMIN_GROUP_TYPE_SELF, so
this only affects the API contract.
> + memcpy(obj_create_data->resource_obj_specific_data, obj_specific_data,
> + obj_specific_data_size);
> + sg_init_one(&data_sg, data, data_size);
> +
> + cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_RESOURCE_OBJ_CREATE);
> + cmd.group_type = cpu_to_le16(group_type);
> + cmd.group_member_id = cpu_to_le64(group_member_id);
> + cmd.data_sg = &data_sg;
[Severity: Low]
This isn't a bug, but this builds the same RESOURCE_OBJ_CREATE payload
that virtio_pci_admin_obj_create() in drivers/virtio/virtio_pci_modern.c
already builds:
virtio_pci_admin_obj_create() {
...
cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_RESOURCE_OBJ_CREATE);
cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SRIOV);
cmd.group_member_id = cpu_to_le64(vf_id + 1);
...
}
virtio_pci_admin_obj_destroy() overlaps with virtio_admin_obj_destroy() in
the same way. The only extra work it does is the ida_free().
Could the PCI dev parts helpers call the new generic ones, passing
VIRTIO_ADMIN_GROUP_TYPE_SRIOV and vf_id + 1? At the end of the series,
both copies of the command-building code are still there.
> +
> + err = vdev->config->admin_cmd_exec(vdev, &cmd);
> + kfree(data);
[Severity: High]
This is a pre-existing issue, but these helpers add two more callers that
can hit it. What happens to cmd and data if virtqueue_kick() fails after
virtqueue_add_sgs() has succeeded?
drivers/virtio/virtio_pci_modern.c:virtqueue_exec_admin_cmd() {
...
if (!virtqueue_kick(vq))
goto unlock_err;
...
unlock_err:
mutex_unlock(&admin_vq->lock);
return -EIO;
}
On this path the descriptors stay published in the admin vq. They still
point at data, at va_hdr and va_status (which vp_modern_admin_cmd_exec()
frees), and at the token cmd, which lives on this function's stack.
virtqueue_kick() returns false when vq->broken is set. virtio_break_device()
sets that flag without taking admin_vq->lock. One example is
virtio_pci_remove() on surprise removal, so the flag can be set between
the add and the kick.
After the -EIO return, this function frees data and returns, so the stack
frame holding cmd is gone. Later, on the remove path:
virtio_pci_remove()
unregister_virtio_device()
driver remove -> del_vqs()
vp_modern_del_vqs()
vp_modern_avq_cleanup()
vp_modern_avq_cleanup() {
...
while ((cmd = virtqueue_detach_unused_buf(vq))) {
cmd->ret = -EIO;
complete(&cmd->completion);
}
...
}
Doesn't this write to a stack frame that has already returned, and take
the completion spinlock inside it?
If the device is still alive after the break, could it also read or write
descriptors that now point at freed memory?
virtio_admin_obj_destroy() follows the same pattern. Should the kick
failure path in virtqueue_exec_admin_cmd() detach the buffer it just added
before returning -EIO?
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202150502.3350030-1-shshitrit%40nvidia.com
Technical Details
Message-ID:
<179631310681.3146.6051559073048802776@kernel.org>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376733-linux-kernel-netdev=dewy.ruReferences:
<20261202150502.3350030-6-shshitrit@nvidia.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376733-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v24 05/14] virtio: Expose object create and destroy API Date: Thu, 03 Dec 2026 15:51:46 +0000 Organization: Usenet Network Message-ID: <179631310681.3146.6051559073048802776@kernel.org> References: <20261202150502.3350030-6-shshitrit@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2533954"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:ffvW+M2XbXB8V2mNrfOoSCBf83A= sha256:RsTpua9xwBG2yu+b/mC6NlKjc91v6S7+h48AOcnhmkI= sha1:2YV68xQzrVjMpebsLs32E8kiWl0= sha256:62OsJHnuJ9No6XF45iL5P6d/jg+Nk4BSAUcvhHcpqkQ= 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 232931179C2; Thu, 3 Dec 2026 18:52:10 +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 CiMXURK9edYx; Thu, 3 Dec 2026 18:52:07 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376733-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 E64901179C0; Thu, 3 Dec 2026 18:51:57 +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 BA84724A51; Thu, 3 Dec 2026 15:51:54 +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=1796313114; b=G6nLeRA4S0EJ6XFc1io8swpHUqIzJ/1Xe+u51UxgcOsOgMbbaDT1c6glQT2eEGPWO5vA I5zWFrRRFv+Hc8m1oeKjn7bw1lYoMvHc2c5zK96/8BtnZ4tsarpHRm3V6aY9Gr1/6UKeu BZzSy3gOF4Um4/oKMery8oGcJ0v3OaNU3UIgbJ63RNelkd7WhIKdd3M1fILufQwHHb1xO jejtjxIztwBOBhbkhwAmmo3w03KJjlZkMifqmjx/mqEKL3gcrg5TpfLKRpQiYxELipgOb 1h9Ay71EMDDNPF5bFWy2Mgnz4Fa2PaVIl2HAXyTtL9DX4A0KWeuD7nJ/hcWFSXN7YOw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796313114; 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=be2MiQFITUNCZuQL4W20dMyyL4lNgUOEIg+s/pBHKfU=; b=rfGEwtmwM0qDt/Yb6zyp44NpeEOVFDbAUeuMh/muoEuUB8nA7YACrDrXb/0WYPcXdrC1 MZfTJbzma7Wxb2RXuwomwi5emNgkGQJmi+WneEIJ9qtuwi/IIVEvCmZfopHMQBE6gkTPC cmG6RViF4qSpImysVX5USMdG2AM1j2ZOkqMzPeD2hyoiWK3i5kufHQ3ZJeuMG0K+ty5+U nVLKCNuo3YkCDkNivZ7olEwkk9krnzrOcYNomAdLUjGOQ6/vjSs6pEUCF/jlVqIdHo6LR zzHy1+eiwOAtKSskxRvC8XDirk1EK2s+y7vU8SdUXbX78Rf1FrZpOLFHU+Ph3V5M7jQ== 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="PXar/LGx"; 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 63707606A32D; Thu, 3 Dec 2026 15:51:54 +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=PXar/LGx 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=1796313108; b=uGf9E+UcrWt/ysQ/ZQrIxelmC0mHecbppqEOJhlEpbSSWjlytLI+UM3b5zWv3bML7yq7 kFYy8dzQXd8VA5FpRnuo/xZFH0wMLHtD4vUWCOB2j0YD4pj1mhlp3wOecXhgOxlXIuezZ 9vm12Z385DJfNq3Pq4fsbeAWwV+ZLgwI9CUbqQWDc7c2IvAl87XuV3ZzT5ydPAvvanYRt 2dmIZtJ38/SZhZTUDPHygxKNoayP8NspFUqxudgxkqbnbBZyONJ0Wi/6wn4aoPB/3c6Hd 0Ou/JsPtrn0OckKD/Jgevucyg7/ABqwOVTRTeyo6dGiZPQtnlhNNgQuH61IDM7MvTNQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796313108; 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=be2MiQFITUNCZuQL4W20dMyyL4lNgUOEIg+s/pBHKfU=; b=EJrn76+mXgEk9bXF9rWQAqcG+lX54WpW07GXnv9ikCJH+RugeJcdl7kjlHFsl3TvJHF0 YzqmkJsZSf9PzCOVZMzh7iGmtO/lCGanT3J/zTiDi4lVwjVc7s5hgR+CAef2cwpO3aIyS 3aq/9qHq6FKBiGkjjY6T+jJAyuJHWajt+RxRp+aZDrPFM2XEG6sSUKHi7YdKGjWT34DAu uz52xs34WoRNq6oWJ+hLZW6nf8KaBFcfm+VEE0pn4sFbalLF35/f+TLZGg28gdL3/0/Gh B5n0KQ5WLcjyH6ta9hvgS9rMwP5w4/RIqABwNzbktKi9SdiGQQ/mE6oqDlRMCF/WaCA== 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="PXar/LGx"; 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 828A2606A337; Thu, 3 Dec 2026 15:51:48 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E8441F00898; Thu, 3 Dec 2026 15:51:47 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796313108; bh=be2MiQFITUNCZuQL4W20dMyyL4lNgUOEIg+s/pBHKfU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=PXar/LGxeqGb37WjHA6L5iTCRY3n6XTp1MtCve16JYaJvEk99a2c5iCOsuCtngk4R Ymexm2N858PiRFRQTOHKzJVo1lNGD+23BIs8XoO3k5Hzz4O2AsKM2gXw/9yiOhKkTy rqD4Yt9SqiiDDmefkea6zVb8JrJnHWPQmsek1fvGn5+OV3HMAHZ+XGn8P1+3D6Oxyt D4loMBekyg+fqMEosSlTY+zM6mnG/bphglRU8oDEnZeGLKYaHkT3VEDh7zrbiJR2oh WDCM273NBdhrqmx6YqJQn6aY+pViTD5pLv4r5vfUyPskbgcedSgLLCqp4LaW1ZnR9O aHa3OWQQZCygA== 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-6-shshitrit@nvidia.com> X-sashiko-severity: Low 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