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 05/14] virtio: Expose object create and destroy API
Date: Thu, 03 Dec 2026 15:51:46 +0000	[thread overview]
Message-ID: <179631310681.3146.6051559073048802776@kernel.org> (raw)
In-Reply-To: <20261202150502.3350030-6-shshitrit@nvidia.com>

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

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