From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796313107; b=Vr0DTJDlXFU+ZFH/Z/tQfhNfiDroKFqIBrYylHdl7WPRZmC/hX87chAbP8EvjmZg2s/Y F97fylUecFGruDst9aARcvMQMIBCLdrDCZzb1ANOgZXme6T7WKDK8sPKoKg2OzGfdnIlQ ArNtk56T0yk0IBe1WcDW/GjRYN/EM1T5xsoOcgkBAEoYFprOU7ZPyNt54fUIHjZoMgO4T BzyGT4QWaX6WGY3w4wKtRtJVc2I1pR8ok5q+8QbAHoBWLUNguEFD7mf6i7d6VTK10169P 8AXB8WAJs7FseJN8aS2XMGgpVMeF2qJ1U1Bt7+Vty6IdDOsNC6neOyB30mLo5BiEdsg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796313107; 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=pZHmjVY1ad8f9kTrbNXSamqpGLxsLr/Rg+Dl3F6PYCA=; b=emvQSi6NApb3K2ti5IoYsaG0L8fUfgDQdxoZJUWt0l1SRMYYHn+LI7s8ykpcmtDm0DJc n3VXMDF8QmOblOsGkSifDF5G6UJxBEptFuux2hgAPCppb7pDOy5GbmNppFedT2ShWk9dl gDhlD5Z4U9OtRKS4dhJO3yShUqxig1wsBKk7Yzvh3F4Y6SSyjF3btDXgDTrIEfAn2TQl6 DWFADH3mu627pDxeU/6KjKV015wyw3twxNjzJIqj+m+gg7aQVUvmwziUhibrsgbXuvLJl 78xJdac/hS1YCrA4hTLsLCMmoF8DNBnllepTQQdcmGi/pDC1RjmdIWGEYI4+WUqJZyQ== 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=GbgMv3fQ; arc=none smtp.remote-ip=100.103.45.18 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 E2FC9606A339; Thu, 3 Dec 2026 15:51:46 +0000 (UTC) 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=GbgMv3fQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id D29F71F000C1; Thu, 3 Dec 2026 15:51:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796313106; bh=pZHmjVY1ad8f9kTrbNXSamqpGLxsLr/Rg+Dl3F6PYCA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=GbgMv3fQPC8Qc4cFIZKmiUk+i07R7EwRfio1aMTlAR4t2MnxEF7/qhN8KNM+YZlBo RvYfqfQhpQckdrK4fH+Y5IDj4GnI0Jw4OU5gmfK+cAHO3RNe2AvFF55ejo/X4JNqUf TYIMFodNXok1N7+LbwlYR4IpVI3mAtjh0/xrXuOJpVwVAH6TKvYUvNA/ZqCkps3jqY zVB4f23oUUInyMlOXwQDsrTsBc5LgMJ+7bZL3z3CCqXB2Fb9eASeMZk79UyFMvrdoQ xwQYIyYQSAtO7n5VOOUy8iIY46OIcjFYXhiXlo7eJuHF5fQDrkaueXn5QXfNSyhOrE I7AcX6P1e68hg== Subject: Re: [PATCH net-next v24 04/14] virtio: Expose generic device capability operations 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 Date: Thu, 03 Dec 2026 15:51:45 +0000 Message-ID: <179631310544.3146.5070956396036675511@kernel.org> In-Reply-To: <20261202150502.3350030-5-shshitrit@nvidia.com> References: <20261202150502.3350030-5-shshitrit@nvidia.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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