From: sashiko-bot@kernel.org
To: "Shahar Shitrit" <shshitrit@nvidia.com>
Cc: virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH net-next v24 04/14] virtio: Expose generic device capability operations
Date: Thu, 03 Dec 2026 15:05:57 +0000 [thread overview]
Message-ID: <sashiko-outbox-248058@kernel.org> (raw)
In-Reply-To: <20261202150502.3350030-5-shshitrit@nvidia.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] virtio: duplicated capability command logic in
virtio_admin_commands.c
--
commit 433f36930ddca8a1d9168aa95c377a032729ab34
Author: Daniel Jurgens <danielj@nvidia.com>
virtio: Expose generic device capability operations
This commit adds generic helpers in virtio_admin_commands.c and
virtio_admin.h to query capability ID lists and get or set device
capabilities via admin commands, and expands the supported_caps bitmap in
struct virtio_admin_cmd_query_cap_id_result to cover up to
VIRTIO_ADMIN_MAX_CAP.
> diff --git a/drivers/virtio/virtio_admin_commands.c b/drivers/virtio/virtio_admin_commands.c
> new file mode 100644
> index 0000000000000..d4bf8c48e1d91
> --- /dev/null
> +++ b/drivers/virtio/virtio_admin_commands.c
> @@ -0,0 +1,100 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include <linux/module.h>
> +#include <linux/types.h>
> +#include <linux/slab.h>
> +#include <linux/virtio.h>
> +#include <linux/virtio_config.h>
> +#include <linux/virtio_admin.h>
> +#include <linux/overflow.h>
> +#include <uapi/linux/virtio_pci.h>
> +
> +int virtio_admin_cap_id_list_query(struct virtio_device *vdev,
> + struct virtio_admin_cmd_query_cap_id_result *data)
> +{
> + struct virtio_admin_cmd cmd = {};
> + struct scatterlist result_sg;
> +
> + if (!vdev->config->admin_cmd_exec)
> + return -EOPNOTSUPP;
> +
> + sg_init_one(&result_sg, data, sizeof(*data));
> + cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY);
> + cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SELF);
> + cmd.result_sg = &result_sg;
> +
> + return vdev->config->admin_cmd_exec(vdev, &cmd);
> +}
> +EXPORT_SYMBOL_GPL(virtio_admin_cap_id_list_query);
> +
> +int virtio_admin_cap_get(struct virtio_device *vdev,
> + u16 id,
> + void *caps,
> + size_t cap_size)
> +{
> + struct virtio_admin_cmd_cap_get_data *data;
> + struct virtio_admin_cmd cmd = {};
> + struct scatterlist result_sg;
> + struct scatterlist data_sg;
> + int err;
> +
> + if (!vdev->config->admin_cmd_exec)
> + return -EOPNOTSUPP;
> +
> + data = kzalloc_obj(*data);
> + if (!data)
> + return -ENOMEM;
> +
> + data->id = cpu_to_le16(id);
> + sg_init_one(&data_sg, data, sizeof(*data));
> + sg_init_one(&result_sg, caps, cap_size);
> + cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_DEVICE_CAP_GET);
> + cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SELF);
> + cmd.data_sg = &data_sg;
> + cmd.result_sg = &result_sg;
> +
> + err = vdev->config->admin_cmd_exec(vdev, &cmd);
> + kfree(data);
> +
> + return err;
> +}
> +EXPORT_SYMBOL_GPL(virtio_admin_cap_get);
> +
> +int virtio_admin_cap_set(struct virtio_device *vdev,
> + u16 id,
> + const void *caps,
> + size_t cap_size)
> +{
> + struct virtio_admin_cmd_cap_set_data *data;
> + struct virtio_admin_cmd cmd = {};
> + struct scatterlist data_sg;
> + size_t data_size;
> + int err;
> +
> + if (!vdev->config->admin_cmd_exec)
> + return -EOPNOTSUPP;
> +
> + if (check_add_overflow(sizeof(*data), cap_size, &data_size))
> + return -EOVERFLOW;
> +
> + data = kzalloc(data_size, GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + data->id = cpu_to_le16(id);
> + memcpy(data->cap_specific_data, caps, cap_size);
> + sg_init_one(&data_sg, data, data_size);
> + cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_DRIVER_CAP_SET);
> + cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SELF);
> + cmd.data_sg = &data_sg;
> + cmd.result_sg = NULL;
> +
> + err = vdev->config->admin_cmd_exec(vdev, &cmd);
> + kfree(data);
> +
> + return err;
> +}
> +EXPORT_SYMBOL_GPL(virtio_admin_cap_set);
[Severity: Low]
This isn't a bug, but could virtio_pci_admin_cmd_cap_init() and
virtio_pci_admin_cmd_dev_parts_objects_enable() in
drivers/virtio/virtio_pci_modern.c be converted to use
virtio_admin_cap_id_list_query(), virtio_cap_in_list(),
virtio_admin_cap_get(), and virtio_admin_cap_set()?
Both virtio_pci_config_ops and virtio_pci_config_nodev_ops already wire
admin_cmd_exec to vp_modern_admin_cmd_exec(), so leaving the open-coded
scatterlist setup and VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY,
VIRTIO_ADMIN_CMD_DEVICE_CAP_GET, and VIRTIO_ADMIN_CMD_DRIVER_CAP_SET
calls in virtio_pci_modern.c duplicates these helpers:
drivers/virtio/virtio_pci_modern.c:virtio_pci_admin_cmd_dev_parts_objects_enable() {
...
get_data->id = cpu_to_le16(VIRTIO_DEV_PARTS_CAP);
sg_init_one(&data_sg, get_data, sizeof(*get_data));
sg_init_one(&result_sg, result, sizeof(*result));
cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_DEVICE_CAP_GET);
cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SELF);
cmd.data_sg = &data_sg;
cmd.result_sg = &result_sg;
ret = vp_modern_admin_cmd_exec(virtio_dev, &cmd);
...
}
drivers/virtio/virtio_pci_modern.c:virtio_pci_admin_cmd_cap_init() {
...
sg_init_one(&result_sg, data, sizeof(*data));
cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY);
cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SELF);
cmd.result_sg = &result_sg;
ret = vp_modern_admin_cmd_exec(virtio_dev, &cmd);
...
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202150502.3350030-1-shshitrit@nvidia.com?part=4
next prev parent reply other threads:[~2026-12-03 15:05 UTC|newest]
Thread overview: 37+ 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:05 ` sashiko-bot
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:05 ` sashiko-bot [this message]
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:05 ` sashiko-bot
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:05 ` sashiko-bot
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:05 ` sashiko-bot
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:06 ` sashiko-bot
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
2026-12-03 15:06 ` sashiko-bot
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=sashiko-outbox-248058@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shshitrit@nvidia.com \
--cc=virtualization@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.