Skip to contentSkip to conversation

virtio-gpu: Support Venus Vulkan driver

PATCH In review Antonio Caggiano 3 participants 18 messages Jul 28, 2021 – Jul 30, 2021 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v2 cover virtio-gpu: Support Venus Vulkan driver

This series of patches enables support for the Venus VirtIO-GPU Vulkan driver by adding some features required by the driver:

- CONTEXT_INIT
- HOSTMEM
- RESOURCE_UUID
- BLOB_RESOURCES

In addition to these features, Venus capset support was required together with the implementation for Virgl blob resource commands.

With this in place, QEMU can take advantage of GPU acceleration to render a simple program such as vkcube [0] in headless mode [1]. Further work is needed to enable rendering with other kinds of surfaces.

Tested with Chia-I Wu kernel venus-5 branch [2], Mesa v21.1 [3], and my WIP virglrenderer res-mapping branch [4].

Relevant QEMU command line parameters:

-m 4G \
-object memory-backend-memfd,id=mem1,size=4G \
-machine memory-backend=mem1 \
-display gtk,gl=on,show-cursor=on \
-vga none \
-device virtio-vga-gl,blob=true,hostmem=1G \

v2: Split shared memory capability commit.

[0] https://github.com/krh/vkcube
[1] https://share.collabora.com/index.php/s/RM5igzZMH2o749W/preview
[2] https://gitlab.freedesktop.org/olv/drm-misc-next/-/tree/venus-5
[3] https://gitlab.freedesktop.org/mesa/mesa/-/tree/21.1
[4] https://gitlab.freedesktop.org/Fahien/virglrenderer/-/tree/res-mapping

Antonio Caggiano (6):
virtio-gpu: CONTEXT_INIT feature
virtio-gpu: Shared memory capability
virtio-gpu: Resource UUID
virtio-gpu: Support Venus capset
virtio-gpu: Initialize Venus
virtio-gpu: Handle resource blob commands

Dr. David Alan Gilbert (1):
virtio: Add shared memory capability

Gerd Hoffmann (1):
virtio-gpu: hostmem [wip]

 hw/display/trace-events                     |   1 +
 hw/display/virtio-gpu-base.c                |   8 +
 hw/display/virtio-gpu-pci.c                 |  14 ++
 hw/display/virtio-gpu-virgl.c               | 184 +++++++++++++++++++-
 hw/display/virtio-gpu.c                     |  36 +++-
 hw/display/virtio-vga.c                     |  32 +++-
 hw/virtio/virtio-pci.c                      |  19 ++
 hw/virtio/virtio-pci.h                      |   4 +
 include/hw/virtio/virtio-gpu-bswap.h        |  20 ++-
 include/hw/virtio/virtio-gpu.h              |  10 ++
 include/standard-headers/linux/virtio_gpu.h |  16 +-
 meson.build                                 |   1 +
 12 files changed, 318 insertions(+), 27 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/8 virtio-gpu: CONTEXT_INIT feature

Create virgl renderer context with flags using context_id when valid.

---
 hw/display/virtio-gpu-base.c                |  2 ++
 hw/display/virtio-gpu-virgl.c               | 10 ++++++++--
 include/hw/virtio/virtio-gpu-bswap.h        |  2 +-
 include/standard-headers/linux/virtio_gpu.h |  9 +++++++--
 4 files changed, 18 insertions(+), 5 deletions(-)
hw/display/virtio-gpu-base.c +2 -0
index c8da4806e0..619185a9d2 100644
@@ -212,6 +212,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
         features |= (1 << VIRTIO_GPU_F_RESOURCE_BLOB);
     }
 
+    features |= (1 << VIRTIO_GPU_F_CONTEXT_INIT);
+
     return features;
 }
 
hw/display/virtio-gpu-virgl.c +8 -2
index 18d054922f..5a184cf445 100644
@@ -97,8 +97,14 @@ static void virgl_cmd_context_create(VirtIOGPU *g,
     trace_virtio_gpu_cmd_ctx_create(cc.hdr.ctx_id,
                                     cc.debug_name);
 
-    virgl_renderer_context_create(cc.hdr.ctx_id, cc.nlen,
-                                  cc.debug_name);
+    if (cc.context_init) {
+        virgl_renderer_context_create_with_flags(cc.hdr.ctx_id,
+                                                 cc.context_init,
+                                                 cc.nlen,
+                                                 cc.debug_name);
+    } else {
+        virgl_renderer_context_create(cc.hdr.ctx_id, cc.nlen, cc.debug_name);
+    }
 }
 
 static void virgl_cmd_context_destroy(VirtIOGPU *g,
include/hw/virtio/virtio-gpu-bswap.h +1 -1
index e2bee8f595..6267cb57e5 100644
@@ -24,7 +24,7 @@ virtio_gpu_ctrl_hdr_bswap(struct virtio_gpu_ctrl_hdr *hdr)
     le32_to_cpus(&hdr->flags);
     le64_to_cpus(&hdr->fence_id);
     le32_to_cpus(&hdr->ctx_id);
-    le32_to_cpus(&hdr->padding);
+    le32_to_cpus(&hdr->info);
 }
 
 static inline void
include/standard-headers/linux/virtio_gpu.h +7 -2
index 1357e4774e..c9f9c24d6a 100644
@@ -59,6 +59,11 @@
  * VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB
  */
 #define VIRTIO_GPU_F_RESOURCE_BLOB       3
+/*
+ * VIRTIO_GPU_CMD_CREATE_CONTEXT with
+ * context_init
+ */
+#define VIRTIO_GPU_F_CONTEXT_INIT        4
 
 enum virtio_gpu_ctrl_type {
 	VIRTIO_GPU_UNDEFINED = 0,
@@ -129,7 +134,7 @@ struct virtio_gpu_ctrl_hdr {
 	uint32_t flags;
 	uint64_t fence_id;
 	uint32_t ctx_id;
-	uint32_t padding;
+	uint32_t info;
 };
 
 /* data passed in the cursor vq */
@@ -272,7 +277,7 @@ struct virtio_gpu_resource_create_3d {
 struct virtio_gpu_ctx_create {
 	struct virtio_gpu_ctrl_hdr hdr;
 	uint32_t nlen;
-	uint32_t padding;
+	uint32_t context_init;
 	char debug_name[64];
 };
 
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH v2 1/8] virtio-gpu: CONTEXT_INIT feature

Hi,

include/standard-headers/linux/virtio_gpu.h line 66

Quoted 5 lines
include/standard-headers/linux/virtio_gpu.h +5 -0
+/*
+ * VIRTIO_GPU_CMD_CREATE_CONTEXT with
+ * context_init
+ */
+#define VIRTIO_GPU_F_CONTEXT_INIT        4

Where is the virtio spec update for this?

take care,
Gerd

#3 lore raw

PATCH v2 2/8 virtio-gpu: hostmem [wip]

In reply to Antonio Caggiano

From: Gerd Hoffmann <[email protected]>

---
 hw/display/virtio-gpu-base.c                |  4 +++
 hw/display/virtio-gpu-pci.c                 | 14 +++++++++
 hw/display/virtio-gpu.c                     |  1 +
 hw/display/virtio-vga.c                     | 32 +++++++++++++++------
 include/hw/virtio/virtio-gpu.h              |  5 ++++
 include/standard-headers/linux/virtio_gpu.h |  5 ++++
 6 files changed, 52 insertions(+), 9 deletions(-)
hw/display/virtio-gpu-base.c +4 -0
index 619185a9d2..31b430664f 100644
@@ -214,6 +214,10 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
 
     features |= (1 << VIRTIO_GPU_F_CONTEXT_INIT);
 
+    if (virtio_gpu_hostmem_enabled(g->conf)) {
+        features |= (1 << VIRTIO_GPU_F_HOSTMEM);
+    }
+
     return features;
 }
 
hw/display/virtio-gpu-pci.c +14 -0
index e36eee0c40..9808663d05 100644
@@ -33,6 +33,20 @@ static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
     DeviceState *vdev = DEVICE(g);
     int i;
 
+    if (virtio_gpu_hostmem_enabled(g->conf)) {
+        vpci_dev->msix_bar_idx = 1;
+        vpci_dev->modern_mem_bar_idx = 2;
+        memory_region_init(&g->hostmem, OBJECT(g), "virtio-gpu-hostmem",
+                           g->conf.hostmem);
+        pci_register_bar(&vpci_dev->pci_dev, 4,
+                         PCI_BASE_ADDRESS_SPACE_MEMORY |
+                         PCI_BASE_ADDRESS_MEM_PREFETCH |
+                         PCI_BASE_ADDRESS_MEM_TYPE_64,
+                         &g->hostmem);
+        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0);
+    }
+
+    qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus), errp);
     virtio_pci_force_virtio_1(vpci_dev);
     if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) {
         return;
hw/display/virtio-gpu.c +1 -0
index 990e71fd40..9686f17d79 100644
@@ -1392,6 +1392,7 @@ static Property virtio_gpu_properties[] = {
                      256 * MiB),
     DEFINE_PROP_BIT("blob", VirtIOGPU, parent_obj.conf.flags,
                     VIRTIO_GPU_FLAG_BLOB_ENABLED, false),
+    DEFINE_PROP_SIZE("hostmem", VirtIOGPU, parent_obj.conf.hostmem, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/display/virtio-vga.c +23 -9
index 9e57f61e9e..61993dd3f2 100644
@@ -125,16 +125,30 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
     pci_register_bar(&vpci_dev->pci_dev, 0,
                      PCI_BASE_ADDRESS_MEM_PREFETCH, &vga->vram);
 
-    /*
-     * Configure virtio bar and regions
-     *
-     * We use bar #2 for the mmio regions, to be compatible with stdvga.
-     * virtio regions are moved to the end of bar #2, to make room for
-     * the stdvga mmio registers at the start of bar #2.
-     */
-    vpci_dev->modern_mem_bar_idx = 2;
-    vpci_dev->msix_bar_idx = 4;
     vpci_dev->modern_io_bar_idx = 5;
+  
+    if (!virtio_gpu_hostmem_enabled(g->conf)) {
+        /*
+        * Configure virtio bar and regions
+        *
+        * We use bar #2 for the mmio regions, to be compatible with stdvga.
+        * virtio regions are moved to the end of bar #2, to make room for
+        * the stdvga mmio registers at the start of bar #2.
+        */
+        vpci_dev->modern_mem_bar_idx = 2;
+        vpci_dev->msix_bar_idx = 4;
+    } else {
+        vpci_dev->msix_bar_idx = 1;
+        vpci_dev->modern_mem_bar_idx = 2;
+        memory_region_init(&g->hostmem, OBJECT(g), "virtio-gpu-hostmem",
+                           g->conf.hostmem);
+        pci_register_bar(&vpci_dev->pci_dev, 4,
+                         PCI_BASE_ADDRESS_SPACE_MEMORY |
+                         PCI_BASE_ADDRESS_MEM_PREFETCH |
+                         PCI_BASE_ADDRESS_MEM_TYPE_64,
+                         &g->hostmem);
+        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0);
+    }
 
     if (!(vpci_dev->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)) {
         /*
include/hw/virtio/virtio-gpu.h +5 -0
index 24c6628944..835ebcb1a0 100644
@@ -102,12 +102,15 @@ enum virtio_gpu_base_conf_flags {
     (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED))
 #define virtio_gpu_blob_enabled(_cfg) \
     (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED))
+#define virtio_gpu_hostmem_enabled(_cfg) \
+    (_cfg.hostmem > 0)
 
 struct virtio_gpu_base_conf {
     uint32_t max_outputs;
     uint32_t flags;
     uint32_t xres;
     uint32_t yres;
+    uint64_t hostmem;
 };
 
 struct virtio_gpu_ctrl_command {
@@ -131,6 +134,8 @@ struct VirtIOGPUBase {
     int renderer_blocked;
     int enable;
 
+    MemoryRegion hostmem;
+
     struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS];
 
     int enabled_output_bitmask;
include/standard-headers/linux/virtio_gpu.h +5 -0
index c9f9c24d6a..85898d41a7 100644
@@ -65,6 +65,11 @@
  */
 #define VIRTIO_GPU_F_CONTEXT_INIT        4
 
+/*
+ * shared memory
+ */
+#define VIRTIO_GPU_F_HOSTMEM             5
+
 enum virtio_gpu_ctrl_type {
 	VIRTIO_GPU_UNDEFINED = 0,
 
Signature · 1 line
2.30.2
#4 lore raw

Re: [PATCH v2 2/8] virtio-gpu: hostmem [wip]

Quoted 10 lines · Antonio Caggiano

From: Gerd Hoffmann <[email protected]>

---
 hw/display/virtio-gpu-base.c                |  4 +++
 hw/display/virtio-gpu-pci.c                 | 14 +++++++++
 hw/display/virtio-gpu.c                     |  1 +
 hw/display/virtio-vga.c                     | 32 +++++++++++++++------
 include/hw/virtio/virtio-gpu.h              |  5 ++++
 include/standard-headers/linux/virtio_gpu.h |  5 ++++
 6 files changed, 52 insertions(+), 9 deletions(-)

WIP aims for a RFC series.

#5 lore raw

Re: [PATCH v2 2/8] virtio-gpu: hostmem [wip]

In reply to Antonio Caggiano

Hi,

include/standard-headers/linux/virtio_gpu.h line 71

Quoted 4 lines
include/standard-headers/linux/virtio_gpu.h +4 -0
+/*
+ * shared memory
+ */
+#define VIRTIO_GPU_F_HOSTMEM             5

Leftover from early interface design attempts.

The blob resources (with VIRTIO_GPU_BLOB_MEM_HOST3D_GUEST) should cover that now.

take care,
Gerd

#6 lore raw

PATCH v2 3/8 virtio: Add shared memory capability

In reply to Antonio Caggiano

From: "Dr. David Alan Gilbert" <[email protected]>

Define a new capability type 'VIRTIO_PCI_CAP_SHARED_MEMORY_CFG' and the data structure 'virtio_pci_shm_cap' to go with it. They allow defining shared memory regions with sizes and offsets of 2^32 and more.
Multiple instances of the capability are allowed and distinguished by a device-specific 'id'.

(cherry picked from commit a5d628a3a3c5e60b98b15ffff197c36a77056115)
---
 hw/virtio/virtio-pci.c                      | 19 +++++++++++++++++++
 hw/virtio/virtio-pci.h                      |  4 ++++
 include/standard-headers/linux/virtio_pci.h |  7 +++++++
 3 files changed, 30 insertions(+)
hw/virtio/virtio-pci.c +19 -0
index 433060ac02..3589386412 100644
@@ -1149,6 +1149,25 @@ static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,
     return offset;
 }
 
+int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy,
+                           uint8_t bar, uint64_t offset, uint64_t length,
+                           uint8_t id)
+{
+    struct virtio_pci_shm_cap cap = {
+        .cap.cap_len = sizeof cap,
+        .cap.cfg_type = VIRTIO_PCI_CAP_SHARED_MEMORY_CFG,
+    };
+    uint32_t mask32 = ~0;
+
+    cap.cap.bar = bar;
+    cap.cap.length = cpu_to_le32(length & mask32);
+    cap.length_hi = cpu_to_le32((length >> 32) & mask32);
+    cap.cap.offset = cpu_to_le32(offset & mask32);
+    cap.offset_hi = cpu_to_le32((offset >> 32) & mask32);
+    cap.id = id;
+    return virtio_pci_add_mem_cap(proxy, &cap.cap);
+}
+
 static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr,
                                        unsigned size)
 {
hw/virtio/virtio-pci.h +4 -0
index 2446dcd9ae..5e5c4a4c6d 100644
@@ -252,4 +252,8 @@ void virtio_pci_types_register(const VirtioPCIDeviceTypeInfo *t);
  */
 unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues);
 
+int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy,
+                           uint8_t bar, uint64_t offset, uint64_t length,
+                           uint8_t id);
+
 #endif
include/standard-headers/linux/virtio_pci.h +7 -0
index db7a8e2fcb..85d1420d29 100644
@@ -172,6 +172,13 @@ struct virtio_pci_cfg_cap {
 	uint8_t pci_cfg_data[4]; /* Data for BAR access. */
 };
 
+struct virtio_pci_shm_cap {
+	struct virtio_pci_cap cap;
+	uint32_t offset_hi;             /* Most sig 32 bits of offset */
+	uint32_t length_hi;             /* Most sig 32 bits of length */
+	uint8_t  id;                    /* To distinguish shm chunks */
+};
+
 /* Macro versions of offsets for the Old Timers! */
 #define VIRTIO_PCI_CAP_VNDR		0
 #define VIRTIO_PCI_CAP_NEXT		1
Signature · 1 line
2.30.2
#7 lore raw

PATCH v2 4/8 virtio-gpu: Shared memory capability

In reply to Antonio Caggiano

Use VIRTIO_GPU_SHM_ID_HOST_VISIBLE as id for virtio-gpu. Also, remove struct virtio_pci_shm_cap as virtio_pci_cap64 can be used instead.

---
 hw/display/virtio-gpu-pci.c                 | 2 +-
 hw/display/virtio-vga.c                     | 2 +-
 hw/virtio/virtio-pci.c                      | 4 ++--
 include/standard-headers/linux/virtio_pci.h | 7 -------
 4 files changed, 4 insertions(+), 11 deletions(-)
hw/display/virtio-gpu-pci.c +1 -1
index 9808663d05..a79bd751b2 100644
@@ -43,7 +43,7 @@ static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
                          PCI_BASE_ADDRESS_MEM_PREFETCH |
                          PCI_BASE_ADDRESS_MEM_TYPE_64,
                          &g->hostmem);
-        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0);
+        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, VIRTIO_GPU_SHM_ID_HOST_VISIBLE);
     }
 
     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus), errp);
hw/display/virtio-vga.c +1 -1
index 61993dd3f2..ca841a0799 100644
@@ -147,7 +147,7 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
                          PCI_BASE_ADDRESS_MEM_PREFETCH |
                          PCI_BASE_ADDRESS_MEM_TYPE_64,
                          &g->hostmem);
-        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0);
+        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, VIRTIO_GPU_SHM_ID_HOST_VISIBLE);
     }
 
     if (!(vpci_dev->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)) {
hw/virtio/virtio-pci.c +2 -2
index 3589386412..37a50b4658 100644
@@ -1153,7 +1153,7 @@ int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy,
                            uint8_t bar, uint64_t offset, uint64_t length,
                            uint8_t id)
 {
-    struct virtio_pci_shm_cap cap = {
+    struct virtio_pci_cap64 cap = {
         .cap.cap_len = sizeof cap,
         .cap.cfg_type = VIRTIO_PCI_CAP_SHARED_MEMORY_CFG,
     };
@@ -1164,7 +1164,7 @@ int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy,
     cap.length_hi = cpu_to_le32((length >> 32) & mask32);
     cap.cap.offset = cpu_to_le32(offset & mask32);
     cap.offset_hi = cpu_to_le32((offset >> 32) & mask32);
-    cap.id = id;
+    cap.cap.id = id;
     return virtio_pci_add_mem_cap(proxy, &cap.cap);
 }
 
include/standard-headers/linux/virtio_pci.h +0 -7
index 85d1420d29..db7a8e2fcb 100644
@@ -172,13 +172,6 @@ struct virtio_pci_cfg_cap {
 	uint8_t pci_cfg_data[4]; /* Data for BAR access. */
 };
 
-struct virtio_pci_shm_cap {
-	struct virtio_pci_cap cap;
-	uint32_t offset_hi;             /* Most sig 32 bits of offset */
-	uint32_t length_hi;             /* Most sig 32 bits of length */
-	uint8_t  id;                    /* To distinguish shm chunks */
-};
-
 /* Macro versions of offsets for the Old Timers! */
 #define VIRTIO_PCI_CAP_VNDR		0
 #define VIRTIO_PCI_CAP_NEXT		1
Signature · 1 line
2.30.2
#8 lore raw

Re: [PATCH v2 4/8] virtio-gpu: Shared memory capability

Review

Quoted 2 lines
(quoted diff) +1 -1
-        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, 0);
+        virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, VIRTIO_GPU_SHM_ID_HOST_VISIBLE);

Squash that into patch #2

include/standard-headers/linux/virtio_pci.h struct virtio_pci_cfg_cap { · line 181

Quoted 13 lines
include/standard-headers/linux/virtio_pci.h +0 -7
@@ -172,13 +172,6 @@ struct virtio_pci_cfg_cap {
 	uint8_t pci_cfg_data[4]; /* Data for BAR access. */
 };
 
-struct virtio_pci_shm_cap {
-	struct virtio_pci_cap cap;
-	uint32_t offset_hi;             /* Most sig 32 bits of offset */
-	uint32_t length_hi;             /* Most sig 32 bits of length */
-	uint8_t  id;                    /* To distinguish shm chunks */
-};
-

Hmm? I doubt this is correct ...

take care,
Gerd

#9 lore raw

PATCH v2 5/8 virtio-gpu: Resource UUID

In reply to Antonio Caggiano

Enable resource UUID feature and implement command resource assign UUID. For the moment, use the resource ID as UUID.

---
 hw/display/trace-events        |  1 +
 hw/display/virtio-gpu-base.c   |  2 ++
 hw/display/virtio-gpu-virgl.c  |  3 +++
 hw/display/virtio-gpu.c        | 26 ++++++++++++++++++++++++++
 include/hw/virtio/virtio-gpu.h |  2 ++
 5 files changed, 34 insertions(+)
hw/display/trace-events +1 -0
index f03f6655bc..6b178fa75d 100644
@@ -37,6 +37,7 @@ virtio_gpu_cmd_res_create_blob(uint32_t res, uint64_t size) "res 0x%x, size %" P
 virtio_gpu_cmd_res_unref(uint32_t res) "res 0x%x"
 virtio_gpu_cmd_res_back_attach(uint32_t res) "res 0x%x"
 virtio_gpu_cmd_res_back_detach(uint32_t res) "res 0x%x"
+virtio_gpu_cmd_res_assign_uuid(uint32_t res) "res 0x%x"
 virtio_gpu_cmd_res_xfer_toh_2d(uint32_t res) "res 0x%x"
 virtio_gpu_cmd_res_xfer_toh_3d(uint32_t res) "res 0x%x"
 virtio_gpu_cmd_res_xfer_fromh_3d(uint32_t res) "res 0x%x"
hw/display/virtio-gpu-base.c +2 -0
index 31b430664f..263a888922 100644
@@ -218,6 +218,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,
         features |= (1 << VIRTIO_GPU_F_HOSTMEM);
     }
 
+    features |= (1 << VIRTIO_GPU_F_RESOURCE_UUID);
+
     return features;
 }
 
hw/display/virtio-gpu-virgl.c +3 -0
index 5a184cf445..38e5ca6c72 100644
@@ -458,6 +458,9 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
         /* TODO add security */
         virgl_cmd_ctx_detach_resource(g, cmd);
         break;
+    case VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID:
+        virtio_gpu_resource_assign_uuid(g, cmd);
+        break;
     case VIRTIO_GPU_CMD_GET_CAPSET_INFO:
         virgl_cmd_get_capset_info(g, cmd);
         break;
hw/display/virtio-gpu.c +26 -0
index 9686f17d79..26b819dd3d 100644
@@ -932,6 +932,29 @@ virtio_gpu_resource_detach_backing(VirtIOGPU *g,
     virtio_gpu_cleanup_mapping(g, res);
 }
 
+void virtio_gpu_resource_assign_uuid(VirtIOGPU *g,
+                                     struct virtio_gpu_ctrl_command *cmd)
+{
+    struct virtio_gpu_simple_resource *res;
+    struct virtio_gpu_resource_assign_uuid assign;
+    struct virtio_gpu_resp_resource_uuid resp;
+
+    VIRTIO_GPU_FILL_CMD(assign);
+    virtio_gpu_bswap_32(&assign, sizeof(assign));
+    trace_virtio_gpu_cmd_res_assign_uuid(assign.resource_id);
+
+    res = virtio_gpu_find_check_resource(g, assign.resource_id, false, __func__, &cmd->error);
+    if (!res) {
+        return;
+    }
+
+    memset(&resp, 0, sizeof(resp));
+    resp.hdr.type = VIRTIO_GPU_RESP_OK_RESOURCE_UUID;
+    /* FIXME: for the moment use the resource id as UUID */
+    *((uint32_t*)(resp.uuid + 12)) = assign.resource_id;
+    virtio_gpu_ctrl_response(g, cmd, &resp.hdr, sizeof(resp));
+}
+
 void virtio_gpu_simple_process_cmd(VirtIOGPU *g,
                                    struct virtio_gpu_ctrl_command *cmd)
 {
@@ -980,6 +1003,9 @@ void virtio_gpu_simple_process_cmd(VirtIOGPU *g,
     case VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING:
         virtio_gpu_resource_detach_backing(g, cmd);
         break;
+    case VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID:
+        virtio_gpu_resource_assign_uuid(g, cmd);
+        break;
     default:
         cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
         break;
include/hw/virtio/virtio-gpu.h +2 -0
index 835ebcb1a0..5cab5f42ac 100644
@@ -263,6 +263,8 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g,
                                   uint32_t *niov);
 void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g,
                                     struct iovec *iov, uint32_t count);
+void virtio_gpu_resource_assign_uuid(VirtIOGPU *g,
+                                     struct virtio_gpu_ctrl_command *cmd);
 void virtio_gpu_process_cmdq(VirtIOGPU *g);
 void virtio_gpu_device_realize(DeviceState *qdev, Error **errp);
 void virtio_gpu_reset(VirtIODevice *vdev);
Signature · 1 line
2.30.2
#10 lore raw

Re: [PATCH v2 5/8] virtio-gpu: Resource UUID

Quoted 2 lines · Antonio Caggiano

Enable resource UUID feature and implement command resource assign UUID. For the moment, use the resource ID as UUID.

No, please do that properly right from start.

Needs a uuid -> resource-id table or hash in qemu. Alternatively have virglrenderer manage uuids too (which then probably needs some api changes). Not sure which is better, also depends on how you are going to use that (i.e. who will lookup resources by uuid).

take care,
Gerd

#11 lore raw

PATCH v2 6/8 virtio-gpu: Support Venus capset

In reply to Antonio Caggiano
---
 hw/display/virtio-gpu-virgl.c               | 21 +++++++++++++++++----
 include/standard-headers/linux/virtio_gpu.h |  2 ++
 2 files changed, 19 insertions(+), 4 deletions(-)
hw/display/virtio-gpu-virgl.c +17 -4
index 38e5ca6c72..beb4b7d106 100644
@@ -372,6 +372,11 @@ static void virgl_cmd_get_capset_info(VirtIOGPU *g,
         virgl_renderer_get_cap_set(resp.capset_id,
                                    &resp.capset_max_version,
                                    &resp.capset_max_size);
+    } else if (info.capset_index == 2) {
+        resp.capset_id = VIRTIO_GPU_CAPSET_VENUS;
+        virgl_renderer_get_cap_set(resp.capset_id,
+                                   &resp.capset_max_version,
+                                   &resp.capset_max_size);
     } else {
         resp.capset_max_version = 0;
         resp.capset_max_size = 0;
@@ -634,10 +639,18 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
 
 int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g)
 {
-    uint32_t capset2_max_ver, capset2_max_size;
+    uint32_t capset2_max_ver, capset2_max_size, num_capsets;
+    num_capsets = 1;
+
     virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_VIRGL2,
-                              &capset2_max_ver,
-                              &capset2_max_size);
+                               &capset2_max_ver,
+                               &capset2_max_size);
+    num_capsets += capset2_max_ver ? 1 : 0;
+
+    virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_VENUS,
+                               &capset2_max_ver,
+                               &capset2_max_size);
+    num_capsets += capset2_max_size ? 1 : 0;
 
-    return capset2_max_ver ? 2 : 1;
+    return num_capsets;
 }
include/standard-headers/linux/virtio_gpu.h +2 -0
index 85898d41a7..28e863cd08 100644
@@ -307,6 +307,8 @@ struct virtio_gpu_cmd_submit {
 
 #define VIRTIO_GPU_CAPSET_VIRGL 1
 #define VIRTIO_GPU_CAPSET_VIRGL2 2
+/* 3 is reserved for gfxstream */
+#define VIRTIO_GPU_CAPSET_VENUS 4
 
 /* VIRTIO_GPU_CMD_GET_CAPSET_INFO */
 struct virtio_gpu_get_capset_info {
Signature · 1 line
2.30.2
#12 lore raw

Re: [PATCH v2 6/8] virtio-gpu: Support Venus capset

Looks sane on a quick glance, but please have a more verbose commit message. I can only guess this is a capset for vulkan support, but readers of the patch should not need guess in the first place ;)

take care,
Gerd

#13 lore raw

PATCH v2 7/8 virtio-gpu: Initialize Venus

In reply to Antonio Caggiano

Enable VirGL unstable APIs and request Venus when initializing VirGL.

---
 hw/display/virtio-gpu-virgl.c | 2 +-
 meson.build                   | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-virgl.c +1 -1
index beb4b7d106..ea903172dd 100644
@@ -621,7 +621,7 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
 {
     int ret;
 
-    ret = virgl_renderer_init(g, 0, &virtio_gpu_3d_cbs);
+    ret = virgl_renderer_init(g, VIRGL_RENDERER_VENUS, &virtio_gpu_3d_cbs);
     if (ret != 0) {
         return ret;
     }
meson.build +1 -0
index f2e148eaf9..31b65050b7 100644
@@ -483,6 +483,7 @@ if not get_option('virglrenderer').auto() or have_system
                      method: 'pkg-config',
                      required: get_option('virglrenderer'),
                      kwargs: static_kwargs)
+  add_project_arguments('-DVIRGL_RENDERER_UNSTABLE_APIS', language : 'c')
 endif
 curl = not_found
 if not get_option('curl').auto() or have_block
Signature · 1 line
2.30.2
#14 lore raw

Re: [PATCH v2 7/8] virtio-gpu: Initialize Venus

Quoted 13 lines · Antonio Caggiano

Enable VirGL unstable APIs and request Venus when initializing VirGL.

---
 hw/display/virtio-gpu-virgl.c | 2 +-
 meson.build                   | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
meson.build +0 -0
index f2e148eaf9..31b65050b7 100644

meson.build if not get_option('virglrenderer').auto() or have_system · line 486

Quoted 4 lines
meson.build +1 -0
@@ -483,6 +483,7 @@ if not get_option('virglrenderer').auto() or have_system
                      method: 'pkg-config',
                      required: get_option('virglrenderer'),
                      kwargs: static_kwargs)
+  add_project_arguments('-DVIRGL_RENDERER_UNSTABLE_APIS', language : 'c')

Unstable in mainstream repository doesn't sound right. What is the plan for the project to stabilize it?

#15 lore raw

Re: [PATCH v2 7/8] virtio-gpu: Initialize Venus

In reply to Antonio Caggiano
Quoted 1 line · Antonio Caggiano

Enable VirGL unstable APIs and request Venus when initializing VirGL.

I guess having a runtime switch for that would be a good idea, and probably have default it off while the API is unstable still.

take care,
Gerd

#16 lore raw

PATCH v2 8/8 virtio-gpu: Handle resource blob commands

In reply to Antonio Caggiano

Support BLOB resources creation by calling virgl_renderer_resource_create_blob.

---
 hw/display/virtio-gpu-virgl.c        | 148 +++++++++++++++++++++++++++
 hw/display/virtio-gpu.c              |   9 +-
 include/hw/virtio/virtio-gpu-bswap.h |  18 ++++
 include/hw/virtio/virtio-gpu.h       |   3 +
 4 files changed, 170 insertions(+), 8 deletions(-)
hw/display/virtio-gpu-virgl.c +148 -0
index ea903172dd..62ca9bacbf 100644
@@ -16,6 +16,8 @@
 #include "trace.h"
 #include "hw/virtio/virtio.h"
 #include "hw/virtio/virtio-gpu.h"
+#include "hw/virtio/virtio-gpu-bswap.h"
+#include "hw/virtio/virtio-iommu.h"
 
 #include <virglrenderer.h>
 
@@ -409,6 +411,143 @@ static void virgl_cmd_get_capset(VirtIOGPU *g,
     g_free(resp);
 }
 
+static void virgl_cmd_resource_create_blob(VirtIOGPU *g,
+                                           struct virtio_gpu_ctrl_command *cmd)
+{
+    struct virtio_gpu_simple_resource *res;
+    struct virtio_gpu_resource_create_blob cblob;
+    int ret;
+
+    VIRTIO_GPU_FILL_CMD(cblob);
+    virtio_gpu_create_blob_bswap(&cblob);
+    trace_virtio_gpu_cmd_res_create_blob(cblob.resource_id, cblob.size);
+
+    if (cblob.resource_id == 0) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource id 0 is not allowed\n",
+                      __func__);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    res = virtio_gpu_find_resource(g, cblob.resource_id);
+    if (res) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource already exists %d\n",
+                      __func__, cblob.resource_id);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    res = g_new0(struct virtio_gpu_simple_resource, 1);
+    res->resource_id = cblob.resource_id;
+    res->blob_size = cblob.size;
+
+    if (res->iov) {
+        cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
+        return;
+    }
+
+    if (cblob.blob_mem != VIRTIO_GPU_BLOB_MEM_HOST3D) {
+        ret = virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(cblob),
+                                            cmd, &res->addrs, &res->iov,
+                                            &res->iov_cnt);
+        if (ret != 0) {
+            cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
+            return;
+        }
+    }
+
+    if (cblob.blob_mem == VIRTIO_GPU_BLOB_MEM_GUEST) {
+        virtio_gpu_init_udmabuf(res);
+    }
+    QTAILQ_INSERT_HEAD(&g->reslist, res, next);
+
+    const struct virgl_renderer_resource_create_blob_args virgl_args = {
+        .res_handle = cblob.resource_id,
+        .ctx_id = cblob.hdr.ctx_id,
+        .blob_mem = cblob.blob_mem,
+        .blob_id = cblob.blob_id,
+        .blob_flags = cblob.blob_flags,
+        .size = cblob.size,
+        .iovecs = res->iov,
+        .num_iovs = res->iov_cnt,
+    };
+    ret = virgl_renderer_resource_create_blob(&virgl_args);
+    if (ret) {
+        g_print("Virgl blob create error: %s\n", strerror(-ret));
+    }
+}
+
+static void virgl_cmd_resource_map_blob(VirtIOGPU *g,
+                                        struct virtio_gpu_ctrl_command *cmd)
+{
+    struct virtio_gpu_simple_resource *res;
+    struct virtio_gpu_resource_map_blob mblob;
+    int ret;
+    void *data;
+    uint64_t size;
+    MemoryRegion *region;
+    struct virtio_gpu_resp_map_info resp;
+
+    VIRTIO_GPU_FILL_CMD(mblob);
+    virtio_gpu_map_blob_bswap(&mblob);
+
+    if (mblob.resource_id == 0) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource id 0 is not allowed\n",
+                      __func__);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    res = virtio_gpu_find_resource(g, mblob.resource_id);
+    if (!res) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource does not exist %d\n",
+                      __func__, mblob.resource_id);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    ret = virgl_renderer_resource_map(mblob.hdr.ctx_id, res->resource_id, &data, &size);
+    if (ret) {
+        g_print("Virgl blob resource map error: %s\n", strerror(-ret));
+    }
+
+    region = g_new0(MemoryRegion, 1);
+    memory_region_init_ram_device_ptr(region, OBJECT(g), NULL, size, data);
+    memory_region_add_subregion(&g->parent_obj.hostmem, mblob.offset, region);
+    memory_region_set_enabled(region, true);
+
+    memset(&resp, 0, sizeof(resp));
+    resp.hdr.type = VIRTIO_GPU_RESP_OK_MAP_INFO;
+    virgl_renderer_resource_get_map_info(mblob.resource_id, &resp.map_info);
+    virtio_gpu_ctrl_response(g, cmd, &resp.hdr, sizeof(resp));
+}
+
+static void virgl_cmd_resource_unmap_blob(VirtIOGPU *g,
+                                        struct virtio_gpu_ctrl_command *cmd)
+{
+    struct virtio_gpu_simple_resource *res;
+    struct virtio_gpu_resource_unmap_blob ublob;
+    VIRTIO_GPU_FILL_CMD(ublob);
+    virtio_gpu_unmap_blob_bswap(&ublob);
+
+    if (ublob.resource_id == 0) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource id 0 is not allowed\n",
+                      __func__);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    res = virtio_gpu_find_resource(g, ublob.resource_id);
+    if (!res) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: resource does not exist %d\n",
+                      __func__, ublob.resource_id);
+        cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID;
+        return;
+    }
+
+    virgl_renderer_resource_unmap(ublob.hdr.ctx_id, ublob.resource_id);
+}
+
 void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
                                       struct virtio_gpu_ctrl_command *cmd)
 {
@@ -478,6 +617,15 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
     case VIRTIO_GPU_CMD_GET_EDID:
         virtio_gpu_get_edid(g, cmd);
         break;
+    case VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB:
+        virgl_cmd_resource_create_blob(g, cmd);
+        break;
+    case VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB:
+        virgl_cmd_resource_map_blob(g, cmd);
+        break;
+    case VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB:
+        virgl_cmd_resource_unmap_blob(g, cmd);
+        break;
     default:
         cmd->error = VIRTIO_GPU_RESP_ERR_UNSPEC;
         break;
hw/display/virtio-gpu.c +1 -8
index 26b819dd3d..c7ee584063 100644
@@ -33,8 +33,6 @@
 
 #define VIRTIO_GPU_VM_VERSION 1
 
-static struct virtio_gpu_simple_resource*
-virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id);
 static struct virtio_gpu_simple_resource *
 virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t resource_id,
                                bool require_backing,
@@ -115,7 +113,7 @@ static void update_cursor(VirtIOGPU *g, struct virtio_gpu_update_cursor *cursor)
                   cursor->resource_id ? 1 : 0);
 }
 
-static struct virtio_gpu_simple_resource *
+struct virtio_gpu_simple_resource *
 virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id)
 {
     struct virtio_gpu_simple_resource *res;
@@ -1316,11 +1314,6 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
             error_setg(errp, "cannot enable blob resources without udmabuf");
             return;
         }
-
-        if (virtio_gpu_virgl_enabled(g->parent_obj.conf)) {
-            error_setg(errp, "blobs and virgl are not compatible (yet)");
-            return;
-        }
     }
 
     if (!virtio_gpu_base_device_realize(qdev,
include/hw/virtio/virtio-gpu-bswap.h +18 -0
index 6267cb57e5..0d868f56f9 100644
@@ -64,10 +64,28 @@ virtio_gpu_create_blob_bswap(struct virtio_gpu_resource_create_blob *cblob)
 {
     virtio_gpu_ctrl_hdr_bswap(&cblob->hdr);
     le32_to_cpus(&cblob->resource_id);
+    le32_to_cpus(&cblob->blob_mem);
     le32_to_cpus(&cblob->blob_flags);
+    le32_to_cpus(&cblob->nr_entries);
+    le64_to_cpus(&cblob->blob_id);
     le64_to_cpus(&cblob->size);
 }
 
+static inline void
+virtio_gpu_map_blob_bswap(struct virtio_gpu_resource_map_blob *mblob)
+{
+    virtio_gpu_ctrl_hdr_bswap(&mblob->hdr);
+    le32_to_cpus(&mblob->resource_id);
+    le64_to_cpus(&mblob->offset);
+}
+
+static inline void
+virtio_gpu_unmap_blob_bswap(struct virtio_gpu_resource_unmap_blob *ublob)
+{
+    virtio_gpu_ctrl_hdr_bswap(&ublob->hdr);
+    le32_to_cpus(&ublob->resource_id);
+}
+
 static inline void
 virtio_gpu_scanout_blob_bswap(struct virtio_gpu_set_scanout_blob *ssb)
 {
include/hw/virtio/virtio-gpu.h +3 -0
index 5cab5f42ac..050c8ee372 100644
@@ -245,6 +245,9 @@ void virtio_gpu_base_fill_display_info(VirtIOGPUBase *g,
                         struct virtio_gpu_resp_display_info *dpy_info);
 
 /* virtio-gpu.c */
+struct virtio_gpu_simple_resource *
+virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id);
+
 void virtio_gpu_ctrl_response(VirtIOGPU *g,
                               struct virtio_gpu_ctrl_command *cmd,
                               struct virtio_gpu_ctrl_hdr *resp,
Signature · 1 line
2.30.2
#17 lore raw

Re: [PATCH v2 8/8] virtio-gpu: Handle resource blob commands

Hi,

hw/display/virtio-gpu-virgl.c static void virgl_cmd_get_capset(VirtIOGPU *g, · line 517

Quoted 4 lines
hw/display/virtio-gpu-virgl.c +4 -0
+    region = g_new0(MemoryRegion, 1);
+    memory_region_init_ram_device_ptr(region, OBJECT(g), NULL, size, data);
+    memory_region_add_subregion(&g->parent_obj.hostmem, mblob.offset, region);
+    memory_region_set_enabled(region, true);

You leak the region instead of properly cleaning it up on unmap.

take care,
Gerd