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=1796313108; b=uGf9E+UcrWt/ysQ/ZQrIxelmC0mHecbppqEOJhlEpbSSWjlytLI+UM3b5zWv3bML7yq7 kFYy8dzQXd8VA5FpRnuo/xZFH0wMLHtD4vUWCOB2j0YD4pj1mhlp3wOecXhgOxlXIuezZ 9vm12Z385DJfNq3Pq4fsbeAWwV+ZLgwI9CUbqQWDc7c2IvAl87XuV3ZzT5ydPAvvanYRt 2dmIZtJ38/SZhZTUDPHygxKNoayP8NspFUqxudgxkqbnbBZyONJ0Wi/6wn4aoPB/3c6Hd 0Ou/JsPtrn0OckKD/Jgevucyg7/ABqwOVTRTeyo6dGiZPQtnlhNNgQuH61IDM7MvTNQ== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E8441F00898; Thu, 3 Dec 2026 15:51:47 +0000 (UTC) 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== Subject: Re: [PATCH net-next v24 05/14] virtio: Expose object create and destroy API 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:46 +0000 Message-ID: <179631310681.3146.6051559073048802776@kernel.org> In-Reply-To: <20261202150502.3350030-6-shshitrit@nvidia.com> References: <20261202150502.3350030-6-shshitrit@nvidia.com> X-sashiko-severity: Low 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 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