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 04/14] virtio: Expose generic device capability operations
Date: Thu, 03 Dec 2026 15:51:45 +0000 [thread overview]
Message-ID: <179631310544.3146.5070956396036675511@kernel.org> (raw)
In-Reply-To: <20261202150502.3350030-5-shshitrit@nvidia.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
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] This patch exports new admin helpers for every virtio driver:
virtio_admin_cap_id_list_query(), virtio_admin_cap_get() and…
- [Low] virtio_cap_in_list() in include/linux/virtio_admin.h is a plain
'static inline' function.
- [Low] In include/uapi/linux/virtio_pci.h the patch deletes the exported
UAPI macro MAX_CAP_ID ('#define MAX_CAP_ID…
- [Low] The kernel-doc for virtio_admin_cap_set() in
include/linux/virtio_admin.h (line 73) says '@caps: Pointer to…
--
virtio: Expose generic device capability operations
This commit adds generic helpers for virtio admin capability commands:
virtio_admin_cap_id_list_query(), virtio_admin_cap_get() and
virtio_admin_cap_set(). It also adds a virtio_cap_in_list() helper. The
UAPI struct virtio_admin_cmd_query_cap_id_result grows so that it covers
capability IDs 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
[ ... ]
> +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);
[Severity: Medium]
How does this SELF-group command get past the opcode check on virtio-pci?
virtio_admin_cap_get() and virtio_admin_cap_set() have the same pattern
with DEVICE_CAP_GET and DRIVER_CAP_SET.
On virtio-pci, virtqueue_exec_admin_cmd() checks every opcode except
LIST_QUERY and LIST_USE against a single bitmap. It does not look at
cmd->group_type:
drivers/virtio/virtio_pci_modern.c:virtqueue_exec_admin_cmd() {
...
if (opcode != VIRTIO_ADMIN_CMD_LIST_QUERY &&
opcode != VIRTIO_ADMIN_CMD_LIST_USE &&
!((1ULL << opcode) & admin_vq->supported_cmds))
return -EOPNOTSUPP;
...
}
The only place that fills supported_cmds is virtio_pci_admin_cmd_list_init(),
called from vp_modern_avq_activate() at DRIVER_OK. It negotiates only the
SRIOV group:
drivers/virtio/virtio_pci_modern.c:virtio_pci_admin_cmd_list_init() {
...
cmd.opcode = cpu_to_le16(VIRTIO_ADMIN_CMD_LIST_QUERY);
cmd.group_type = cpu_to_le16(VIRTIO_ADMIN_GROUP_TYPE_SRIOV);
...
vp_dev->admin_vq.supported_cmds = le64_to_cpu(*data);
...
}
Take a device with an admin VQ that is not an SR-IOV group owner, such as
a VF or a standalone virtio-net device. LIST_QUERY for the SRIOV group
would fail or come back empty there, so supported_cmds stays 0. Would all
three new helpers then return -EOPNOTSUPP, even when the device supports
these commands for the SELF group?
The later virtio_net patch, "virtio_net: Query and set flow filter caps",
has virtnet_ff_init() treat -EOPNOTSUPP as "not supported". So flow
filtering would be silently disabled on those devices.
On a PF, these SELF-group commands are sent without ever being declared
via LIST_USE for the SELF group. Is it intended to rely on the device
accepting that?
No later patch in the series appears to change this negotiation. Should
LIST_QUERY and LIST_USE also be done for VIRTIO_ADMIN_GROUP_TYPE_SELF,
with the check in virtqueue_exec_admin_cmd() taking group_type into
account?
> + cmd.result_sg = &result_sg;
> +
> + return vdev->config->admin_cmd_exec(vdev, &cmd);
> +}
> +EXPORT_SYMBOL_GPL(virtio_admin_cap_id_list_query);
[ ... ]
> diff --git a/include/linux/virtio_admin.h b/include/linux/virtio_admin.h
> new file mode 100644
> index 0000000000000..43ea2dbd48b7e
> --- /dev/null
> +++ b/include/linux/virtio_admin.h
[ ... ]
> +static inline bool virtio_cap_in_list(
> + const struct virtio_admin_cmd_query_cap_id_result *cap_list, u16 cap)
> +{
> + BUILD_BUG_ON(cap > VIRTIO_ADMIN_MAX_CAP);
[Severity: Low]
Can this BUILD_BUG_ON() break the build when virtio_cap_in_list() is not
inlined?
cap is a runtime u16 parameter. In the kernel, a plain inline is not
__always_inline:
include/linux/compiler_types.h:
#define inline inline __gnu_inline __inline_maybe_unused notrace
If the compiler emits an out-of-line copy, for example with
CONFIG_CC_OPTIMIZE_FOR_SIZE or with instrumentation, cap can be anything
from 0 to 0xffff there. The __compiletime_assert() error call would then
survive, and the build would fail with "BUILD_BUG_ON failed: cap >
VIRTIO_ADMIN_MAX_CAP".
Any caller that passes a cap ID that is not a compile-time constant would
also fail to build. With no runtime bounds check, the helper cannot be
used for runtime IDs at all.
The callers in virtnet_ff_init() pass constants, so normal -O2 builds work
today. Would __always_inline, or a runtime range check, be more robust
here?
> + return !!(1 & (le64_to_cpu(cap_list->supported_caps[cap / 64]) >>
> + (cap % 64)));
> +}
[ ... ]
> +/**
> + * virtio_admin_cap_set - Set capability data for a specific capability ID
> + * @vdev: The virtio device
> + * @id: Capability ID to set
> + * @caps: Pointer to capability data structure (must be heap allocated)
[Severity: Low]
This isn't a bug, but is the "must be heap allocated" requirement accurate
for virtio_admin_cap_set()?
The implementation never DMA-maps caps. It copies caps into its own
kzalloc'd buffer and maps only that buffer:
drivers/virtio/virtio_admin_commands.c:virtio_admin_cap_set() {
...
memcpy(data->cap_specific_data, caps, cap_size);
sg_init_one(&data_sg, data, data_size);
...
}
So stack or const buffers would work. In virtio_admin_cap_get(), the
caller's buffer really is DMA-mapped, so the two helpers have different
contracts while the docs describe them the same way.
Also, virtio_pci_modern.c keeps open-coded copies of the same
CAP_ID_LIST_QUERY, DEVICE_CAP_GET and DRIVER_CAP_SET sequences in
virtio_pci_admin_cmd_cap_init() and
virtio_pci_admin_cmd_dev_parts_objects_enable(). Could those be converted
to the new helpers?
> + * @cap_size: Size of the capability data structure
[ ... ]
> diff --git a/include/uapi/linux/virtio_pci.h b/include/uapi/linux/virtio_pci.h
> index e732e3456e275..96d097d3757e4 100644
> --- a/include/uapi/linux/virtio_pci.h
> +++ b/include/uapi/linux/virtio_pci.h
> @@ -315,15 +315,17 @@ struct virtio_admin_cmd_notify_info_result {
>
> #define VIRTIO_DEV_PARTS_CAP 0x0000
>
> +#define VIRTIO_ADMIN_MAX_CAP 0x0fff
> +
> struct virtio_dev_parts_cap {
> __u8 get_parts_resource_objects_limit;
> __u8 set_parts_resource_objects_limit;
> };
>
> -#define MAX_CAP_ID __KERNEL_DIV_ROUND_UP(VIRTIO_DEV_PARTS_CAP + 1, 64)
> +#define VIRTIO_ADMIN_CAP_ID_ARRAY_SIZE __KERNEL_DIV_ROUND_UP(VIRTIO_ADMIN_MAX_CAP + 1, 64)
[Severity: Low]
Could removing MAX_CAP_ID break userspace builds?
It is an exported UAPI macro, and it is dropped here without a
compatibility alias. Userspace that syncs the kernel UAPI headers and uses
MAX_CAP_ID, such as VMMs or device emulators, would stop compiling.
The commit message explains the size change of
struct virtio_admin_cmd_query_cap_id_result, but not the removal of this
name. Would it make sense to keep MAX_CAP_ID defined, or at least mention
the removal in the commit message?
>
> struct virtio_admin_cmd_query_cap_id_result {
> - __le64 supported_caps[MAX_CAP_ID];
> + __le64 supported_caps[VIRTIO_ADMIN_CAP_ID_ARRAY_SIZE];
> };
--
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
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 [this message]
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=179631310544.3146.5070956396036675511@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