Support virtio cross-device resources
Subsystems (5)
cover Support virtio cross-device resources
This patchset implements the current proposal for virtio cross-device resource sharing [1], with minor changes based on recent comments (i.e. renumbering the new virtio gpu command and adding a feature flag).
The patchset adds a new flavor of dma-bufs that supports querying the underlying virtio object UUID, as well as adding support for exporting resources from virtgpu. It is expected that this will be used to import virtgpu resources into the virtio-video driver currently under discussion [2].
[1] https://markmail.org/thread/jsaoqy7phrqdcpqu
[2] https://markmail.org/thread/p5d3k566srtdtute
David Stevens (2):
virtio: add dma-buf support for exported objects drm/virtio: Support virtgpu exported resources
drivers/gpu/drm/virtio/virtgpu_drv.c | 3 + drivers/gpu/drm/virtio/virtgpu_drv.h | 21 +++++ drivers/gpu/drm/virtio/virtgpu_kms.c | 4 + drivers/gpu/drm/virtio/virtgpu_prime.c | 109 ++++++++++++++++++++++++- drivers/gpu/drm/virtio/virtgpu_vq.c | 58 +++++++++++++ drivers/virtio/Makefile | 2 +- drivers/virtio/virtio.c | 6 ++ drivers/virtio/virtio_dma_buf.c | 97 ++++++++++++++++++++++ include/linux/virtio.h | 1 + include/linux/virtio_dma_buf.h | 62 ++++++++++++++ include/uapi/linux/virtio_gpu.h | 19 +++++ 11 files changed, 378 insertions(+), 4 deletions(-) create mode 100644 drivers/virtio/virtio_dma_buf.c create mode 100644 include/linux/virtio_dma_buf.h
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 1/2 virtio: add dma-buf support for exported objects
This change adds a new flavor of dma-bufs that can be used by virtio drivers to share exported objects. A virtio dma-buf can be queried by virtio drivers to obtain the UUID which identifies the underlying exported object.
--- drivers/virtio/Makefile | 2 +- drivers/virtio/virtio.c | 6 ++ drivers/virtio/virtio_dma_buf.c | 97 +++++++++++++++++++++++++++++++++ include/linux/virtio.h | 1 + include/linux/virtio_dma_buf.h | 62 +++++++++++++++++++++ 5 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 drivers/virtio/virtio_dma_buf.c create mode 100644 include/linux/virtio_dma_buf.h
drivers/virtio/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o +obj-$(CONFIG_VIRTIO) += virtio.o virtio_ring.o virtio_dma_buf.o obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o virtio_pci-y := virtio_pci_modern.o virtio_pci_common.o
drivers/virtio/virtio.c +6 -0
@@ -357,6 +357,12 @@ int register_virtio_device(struct virtio_device *dev) }EXPORT_SYMBOL_GPL (register_virtio_device); +bool is_virtio_device (struct device *dev) +{ +return dev->bus == &virtio_bus; +} +EXPORT_SYMBOL_GPL (is_virtio_device); +void unregister_virtio_device (struct virtio_device *dev) {int index = dev->index;/* save for after device release */
drivers/virtio/virtio_dma_buf.c new file +97 -0
97 lines not on this page · raw message
include/linux/virtio.h +1 -0
@@ -128,6 +128,7 @@ static inline struct virtio_device *dev_to_virtio(struct device *_dev)void virtio_add_status (struct virtio_device *dev,unsigned int status);int register_virtio_device (struct virtio_device *dev);void unregister_virtio_device (struct virtio_device *dev); +bool is_virtio_device (struct device *dev);void virtio_break_device (struct virtio_device *dev);
include/linux/virtio_dma_buf.h new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
PATCH 2/2 drm/virtio: Support virtgpu exported resources
In reply to David StevensAdd support for exported resources to virtgpu. This includes adding support for the new virtgpu command as well as well as switching from regular prime dma-bufs to virtio dma-bufs.
--- drivers/gpu/drm/virtio/virtgpu_drv.c | 3 + drivers/gpu/drm/virtio/virtgpu_drv.h | 21 +++++ drivers/gpu/drm/virtio/virtgpu_kms.c | 4 + drivers/gpu/drm/virtio/virtgpu_prime.c | 109 ++++++++++++++++++++++++- drivers/gpu/drm/virtio/virtgpu_vq.c | 58 +++++++++++++ include/uapi/linux/virtio_gpu.h | 19 +++++ 6 files changed, 211 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.c +3 -0
@@ -165,6 +165,7 @@ static unsigned int features[] = { VIRTIO_GPU_F_VIRGL, #endif VIRTIO_GPU_F_EDID, + VIRTIO_GPU_F_CROSS_DEVICE, }; static struct virtio_driver virtio_gpu_driver = { .feature_table = features,
@@ -201,6 +202,8 @@ static struct drm_driver driver = {#endif .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, + .gem_prime_export = virtgpu_gem_prime_export, + .gem_prime_import = virtgpu_gem_prime_import, .gem_prime_mmap = drm_gem_prime_mmap, .gem_prime_import_sg_table = virtgpu_gem_prime_import_sg_table,
drivers/gpu/drm/virtio/virtgpu_drv.h +21 -0
@@ -27,6 +27,7 @@#define VIRTIO_DRV_H #include <linux/virtio.h> +#include <linux/virtio_dma_buf.h> #include <linux/virtio_ids.h> #include <linux/virtio_config.h> #include <linux/virtio_gpu.h>
@@ -49,6 +50,11 @@#define DRIVER_MINOR 1#define DRIVER_PATCHLEVEL 0 +#define UUID_NOT_INITIALIZED 0 +#define UUID_INITIALIZING 1 +#define UUID_INITIALIZED 2 +#define UUID_INITIALIZATION_FAILED 3 +struct virtio_gpu_object_params {uint32_t format;uint32_t width;
@@ -75,6 +81,9 @@ struct virtio_gpu_object {bool dumb;bool created; + +int uuid_state; +uuid_t uuid; };#define gem_to_virtio_gpu_obj (gobj) \ container_of((gobj), struct virtio_gpu_object, base.base)
@@ -196,6 +205,7 @@ struct virtio_gpu_device {bool has_virgl_3d;bool has_edid;bool has_indirect; +bool has_resource_assign_uuid;struct work_struct config_changed_work;
@@ -206,6 +216,8 @@ struct virtio_gpu_device {struct virtio_gpu_drv_capset *capsets;uint32_t num_capsets;struct list_head cap_cache; + +spinlock_t resource_export_lock; };struct virtio_gpu_fpriv {
@@ -338,6 +350,10 @@ void virtio_gpu_dequeue_fence_func(struct work_struct *work);void virtio_gpu_disable_notify (struct virtio_gpu_device *vgdev);void virtio_gpu_enable_notify (struct virtio_gpu_device *vgdev); +int +virtio_gpu_cmd_resource_assign_uuid (struct virtio_gpu_device *vgdev, +struct virtio_gpu_object *bo); +/* virtio_gpu_display.c */ void virtio_gpu_modeset_init (struct virtio_gpu_device *vgdev);void virtio_gpu_modeset_fini (struct virtio_gpu_device *vgdev);
@@ -366,6 +382,11 @@ int virtio_gpu_object_create(struct virtio_gpu_device *vgdev,struct virtio_gpu_object **bo_ptr, struct virtio_gpu_fence *fence);/* virtgpu_prime.c */ +extern const struct virtio_dma_buf_ops virtgpu_dmabuf_ops; +struct dma_buf *virtgpu_gem_prime_export (struct drm_gem_object *obj, +int flags); +struct drm_gem_object *virtgpu_gem_prime_import (struct drm_device *dev, +struct dma_buf *buf);struct drm_gem_object *virtgpu_gem_prime_import_sg_table (struct drm_device *dev,struct dma_buf_attachment *attach,struct sg_table *sgt);
drivers/gpu/drm/virtio/virtgpu_kms.c +4 -0
@@ -134,6 +134,7 @@ int virtio_gpu_init(struct drm_device *dev) vgdev->dev = dev->dev;spin_lock_init (&vgdev->display_info_lock); +spin_lock_init (&vgdev->resource_export_lock);ida_init (&vgdev->ctx_id_ida);ida_init (&vgdev->resource_ida);init_waitqueue_head (&vgdev->resp_wq);
@@ -159,6 +160,9 @@ int virtio_gpu_init(struct drm_device *dev)if (virtio_has_feature (vgdev->vdev,VIRTIO_GPU_F_EDID )) { vgdev->has_edid = true; } +if (virtio_has_feature (vgdev->vdev,VIRTIO_GPU_F_CROSS_DEVICE )) { + vgdev->has_resource_assign_uuid = true; + }if (virtio_has_feature (vgdev->vdev,VIRTIO_RING_F_INDIRECT_DESC )) { vgdev->has_indirect = true; }
drivers/gpu/drm/virtio/virtgpu_prime.c +106 -3
119 lines not on this page · raw message
drivers/gpu/drm/virtio/virtgpu_vq.c +58 -0
61 lines not on this page · raw message
include/uapi/linux/virtio_gpu.h +19 -0
@@ -50,6 +50,10 @@* VIRTIO_GPU_CMD_GET_EDID */ #define VIRTIO_GPU_F_EDID 1 +/* +* VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID +*/ +#define VIRTIO_GPU_F_CROSS_DEVICE 2enum virtio_gpu_ctrl_type {VIRTIO_GPU_UNDEFINED =0 ,
@@ -66,6 +70,7 @@ enum virtio_gpu_ctrl_type {VIRTIO_GPU_CMD_GET_CAPSET_INFO ,VIRTIO_GPU_CMD_GET_CAPSET ,VIRTIO_GPU_CMD_GET_EDID , +VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID ,/* 3d commands */ VIRTIO_GPU_CMD_CTX_CREATE = 0x0200,
@@ -87,6 +92,7 @@ enum virtio_gpu_ctrl_type {VIRTIO_GPU_RESP_OK_CAPSET_INFO ,VIRTIO_GPU_RESP_OK_CAPSET ,VIRTIO_GPU_RESP_OK_EDID , +VIRTIO_GPU_RESP_OK_RESOURCE_ASSIGN_UUID ,/* error responses */ VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200,
@@ -340,4 +346,17 @@ enum virtio_gpu_formats { VIRTIO_GPU_FORMAT_R8G8B8X8_UNORM = 134, }; +/* VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID */ +struct virtio_gpu_resource_assign_uuid { +struct virtio_gpu_ctrl_hdr hdr; +__le32 resource_id; +__le32 padding; +}; + +/* VIRTIO_GPU_RESP_OK_RESOURCE_ASSIGN_UUID */ +struct virtio_gpu_resp_resource_assign_uuid { +struct virtio_gpu_ctrl_hdr hdr; +__u8 uuid[16 ]; +}; +#endif
Signature · 1 line
2.25.0.265.gbab2e86ba0-goog
Gerd Hoffmann
maintainerRe: [PATCH 1/2] virtio: add dma-buf support for exported objects
In reply to David StevensQuoted 4 lines · David Stevens
This change adds a new flavor of dma-bufs that can be used by virtio drivers to share exported objects. A virtio dma-buf can be queried by virtio drivers to obtain the UUID which identifies the underlying exported object.
That duplicates a bunch of code from dma-buf.c in virtio_dma_buf.c.
How about dma_buf_{get,set}_uuid, simliar to dma_buf_set_name?
cheers,
Gerd
Gerd Hoffmann
maintainerRe: [PATCH 2/2] drm/virtio: Support virtgpu exported resources
In reply to David StevensHi,
Quoted 3 lines
drivers/gpu/drm/virtio/virtgpu_prime.c +3
-0+struct dma_buf *virtgpu_gem_prime_export (struct drm_gem_object *obj, +int flags) +{
[ ... ]
Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_prime.c +5
-0+} + +struct drm_gem_object *virtgpu_gem_prime_import (struct drm_device *dev, +struct dma_buf *buf) +{
[ ... ]
Quoted 1 line
+}
More code duplication.
include/uapi/linux/virtio_gpu.h
Quoted 4 lines
include/uapi/linux/virtio_gpu.h +0
-0
API change should go to a separate patch.
include/uapi/linux/virtio_gpu.h line 56
Quoted 4 lines
include/uapi/linux/virtio_gpu.h +4
-0+/* +* VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID +*/ +#define VIRTIO_GPU_F_CROSS_DEVICE 2
Hmm, how about VIRTIO_GPU_F_RESOURCE_UUID ?
include/uapi/linux/virtio_gpu.h enum virtio_gpu_ctrl_type { · line 95
Quoted 5 lines
include/uapi/linux/virtio_gpu.h +1
-0@@ -87,6 +92,7 @@ enum virtio_gpu_ctrl_type {VIRTIO_GPU_RESP_OK_CAPSET_INFO ,VIRTIO_GPU_RESP_OK_CAPSET ,VIRTIO_GPU_RESP_OK_EDID , + VIRTIO_GPU_RESP_OK_RESOURCE_ASSIGN_UUID,
The "assign" doesn't make sense in the reply. I'd name that VIRTIO_GPU_RESP_OK_RESOURCE_UUID or just VIRTIO_GPU_RESP_OK_UUID,
include/uapi/linux/virtio_gpu.h enum virtio_gpu_formats { · line 360
Quoted 5 lines
include/uapi/linux/virtio_gpu.h +5
-0+/* VIRTIO_GPU_RESP_OK_RESOURCE_ASSIGN_UUID */ +struct virtio_gpu_resp_resource_assign_uuid { +struct virtio_gpu_ctrl_hdr hdr; +__u8 uuid[16 ]; +};
Same here.
cheers,
Gerd
Re: [virtio-dev] Re: [PATCH 1/2] virtio: add dma-buf support for exported objects
In reply to Gerd HoffmannQuoted 10 lines · Gerd Hoffmann
Quoted 4 lines · David Stevens
This change adds a new flavor of dma-bufs that can be used by virtio drivers to share exported objects. A virtio dma-buf can be queried by virtio drivers to obtain the UUID which identifies the underlying exported object.
That duplicates a bunch of code from
dma-buf.cinvirtio_dma_buf.c.How about dma_buf_{get,set}_uuid, simliar to
dma_buf_set_name?
While I'm not opposed to such an API, I'm also hesitant to make changes to the dma-buf API for a single use case.
As for the duplicated code around virtio_dma_buf_export_info, it can be removed by sacrificing a little bit of type safety, if that's preferable.
-David
Gerd Hoffmann
maintainerRe: [virtio-dev] Re: [PATCH 1/2] virtio: add dma-buf support for exported objects
Quoted 6 lines · David Stevens
Quoted 2 lines · Gerd Hoffmann
How about dma_buf_{get,set}_uuid, simliar to
dma_buf_set_name?While I'm not opposed to such an API, I'm also hesitant to make changes to the dma-buf API for a single use case.
See virtio-wayland discussion. I expect we will see more cases show up. Maybe this should even go one level up, to struct file.
cheers,
Gerd