Support blob memory and venus on qemu
v5 cover Support blob memory and venus on qemu
Hi all,
Antonio Caggiano made the venus with QEMU on KVM platform last September[1]. This series are inherited from his original work to support the features of context init, hostmem, resource uuid, and blob resources for venus.
At March of this year, we sent out the V1 version[2] for the review. But those series are included both xen and virtio gpu. Right now, we would like to divide into two parts, one is to continue the Antonio's work to upstream virtio-gpu support for blob memory and venus, and another is to upstream xen specific patches. This series is focusing on virtio-gpu, so we are marking as V4 version here to continue Antonio's patches[1]. And we will send xen specific patches separately, because they are hypervisor specific. Besides of QEMU, these supports also included virglrenderer[3][4] and mesa[5][6] as well. Right now, virglrenderer and mesa parts are all accepted by upstream. In this qemu version, we try to address the concerns around not proper cleanup during blob resource unmap and unref. Appreciate it if you have any commments.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
[2] V1: https://lore.kernel.org/qemu-devel/[email protected]
[3] https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1068
[4] https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1180
[5] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22108
[6] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23680
Please note the first 4 patches 1 -> 4 are inlcuded in these series because the series depends on them and not because we want them to be reviewed since they are already in the process of review through the "rutabaga_gfx + gfxstream" series.
- https://lore.kernel.org/qemu-devel/[email protected]/
V4: https://lore.kernel.org/qemu-devel/[email protected]
Changes from V4 (virtio gpu V4) to V5
- Inverted patch 5 and 6 because we should configure HAVE_VIRGL_CONTEXT_INIT firstly.
- Validate owner of memory region to avoid slowing down DMA.
- Use memory_region_init_ram_ptr() instead of
memory_region_init_ram_device_ptr().
- Adjust sequence to allocate gpu resource before virglrender resource creation
- Add virtio migration handling for uuid.
- Send kernel patch to define VIRTIO_GPU_CAPSET_VENUS.
https://lore.kernel.org/lkml/[email protected]/
- Add meson check to make sure unstable APIs defined from 0.9.0.
Changes from V1 to V2 (virtio gpu V4)
- Remove unused #include "hw/virtio/virtio-iommu.h"
- Add a local function, called virgl_resource_destroy(), that is used to release a vgpu resource on error paths and in resource_unref.
- Remove virtio_gpu_virgl_resource_unmap from virtio_gpu_cleanup_mapping(),
since this function won't be called on blob resources and also because blob resources are unmapped via virgl_cmd_resource_unmap_blob().
- In virgl_cmd_resource_create_blob(), do proper cleanup in error paths and move QTAILQ_INSERT_HEAD(&g->reslist, res, next) after the resource has been fully initialized.
- Memory region has a different life-cycle from virtio gpu resources i.e. cannot be released synchronously along with the vgpu resource. So, here the field "region" was changed to a pointer and is allocated dynamically when the blob is mapped.
Also, since the pointer can be used to indicate whether the blob is mapped, the explicite field "mapped" was removed.
- In virgl_cmd_resource_map_blob(), add check on the value of res->region, to prevent beeing called twice on the same resource.
- Add a patch to enable automatic deallocation of memory regions to resolve use-after-free memory corruption with a reference.
References
Demo with Venus:
- https://static.sched.com/hosted_files/xen2023/3f/xen_summit_2023_virtgpu_demo.mp4
QEMU repository:
- https://gitlab.freedesktop.org/rui/qemu-xen/-/commits/upstream-for-virtio-gpu
Thanks,
Ray
Antonio Caggiano (6):
virtio-gpu: CONTEXT_INIT feature
virtio-gpu: blob prep
virtio-gpu: Handle resource blob commands
virtio-gpu: Resource UUID
virtio-gpu: Support Venus capset
virtio-gpu: Initialize Venus
Dmitry Osipenko (1):
virtio-gpu: Don't require udmabuf when blobs and virgl are enabled
Dr. David Alan Gilbert (1):
virtio: Add shared memory capability
Gerd Hoffmann (1):
virtio-gpu: hostmem
Huang Rui (3):
virtio-gpu: Configure context init for virglrenderer
virtio-gpu: Support context init feature with virglrenderer
virtio-gpu: Enable virglrenderer render server flag for venus
Xenia Ragiadakou (1):
softmmu/memory: enable automatic deallocation of memory regions
hw/display/trace-events | 1 + hw/display/virtio-gpu-base.c | 5 + hw/display/virtio-gpu-pci.c | 14 ++ hw/display/virtio-gpu-virgl.c | 272 ++++++++++++++++++++++++++- hw/display/virtio-gpu.c | 78 +++++++- hw/display/virtio-vga.c | 33 +++- hw/virtio/virtio-pci.c | 18 ++ include/hw/virtio/virtio-gpu-bswap.h | 15 ++ include/hw/virtio/virtio-gpu.h | 24 +++ include/hw/virtio/virtio-pci.h | 4 + meson.build | 13 ++ softmmu/memory.c | 5 + 12 files changed, 458 insertions(+), 24 deletions(-)
Signature · 1 line
2.34.1
PATCH v5 1/13 virtio: Add shared memory capability
From: "Dr. David Alan Gilbert" <[email protected]>
Define a new capability type 'VIRTIO_PCI_CAP_SHARED_MEMORY_CFG' to 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'.
---
This patch is already under review as part of the "rutabaga_gfx + gfxstream" series (already in v13) and has been included here because of dependency.
hw/virtio/virtio-pci.c | 18 ++++++++++++++++++ include/hw/virtio/virtio-pci.h | 4 ++++ 2 files changed, 22 insertions(+)
hw/virtio/virtio-pci.c +18 -0
@@ -1435,6 +1435,24 @@ 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_cap64 cap = { + .cap.cap_len =sizeof cap, + .cap.cfg_type =VIRTIO_PCI_CAP_SHARED_MEMORY_CFG , + }; + + cap.cap.bar = bar; + cap.cap.length =cpu_to_le32 (length); + cap.length_hi =cpu_to_le32 (length >>32 ); + cap.cap.offset =cpu_to_le32 (offset); + cap.offset_hi =cpu_to_le32 (offset >>32 ); + cap.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) {
include/hw/virtio/virtio-pci.h +4 -0
@@ -264,4 +264,8 @@ unsigned virtio_pci_optimal_num_queues(unsigned fixed_queues);void virtio_pci_set_guest_notifier_fd_handler (VirtIODevice *vdev,VirtQueue *vq,int n,bool assign,bool with_irqfd); + +int virtio_pci_add_shm_cap (VirtIOPCIProxy *proxy,uint8_t bar,uint64_t offset, +uint64_t length,uint8_t id); +#endif
Signature · 1 line
2.34.1
PATCH v5 2/13 virtio-gpu: CONTEXT_INIT feature
In reply to Huang RuiFrom: Antonio Caggiano <[email protected]>
The feature can be enabled when a backend wants it.
---
This patch is already under review as part of the "rutabaga_gfx + gfxstream" series (already in v13) and has been included here because of dependency.
hw/display/virtio-gpu-base.c | 3 +++ include/hw/virtio/virtio-gpu.h | 3 +++ 2 files changed, 6 insertions(+)
hw/display/virtio-gpu-base.c +3 -0
@@ -232,6 +232,9 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,if (virtio_gpu_blob_enabled (g->conf)) { features |= (1 <<VIRTIO_GPU_F_RESOURCE_BLOB ); } +if (virtio_gpu_context_init_enabled (g->conf)) { + features |= (1 <<VIRTIO_GPU_F_CONTEXT_INIT ); + }return features; }
include/hw/virtio/virtio-gpu.h +3 -0
@@ -93,6 +93,7 @@ enum virtio_gpu_base_conf_flags {VIRTIO_GPU_FLAG_EDID_ENABLED ,VIRTIO_GPU_FLAG_DMABUF_ENABLED ,VIRTIO_GPU_FLAG_BLOB_ENABLED , + VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, };#define virtio_gpu_virgl_enabled (_cfg) \
@@ -105,6 +106,8 @@ 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_context_init_enabled (_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED))struct virtio_gpu_base_conf {uint32_t max_outputs;
Signature · 1 line
2.34.1
PATCH v5 3/13 virtio-gpu: hostmem
In reply to Huang RuiFrom: Gerd Hoffmann <[email protected]>
Use VIRTIO_GPU_SHM_ID_HOST_VISIBLE as id for virtio-gpu.
---
This patch is already under review as part of the "rutabaga_gfx + gfxstream" series (already in v13) and has been included here because of dependency.
hw/display/virtio-gpu-pci.c | 14 ++++++++++++++ hw/display/virtio-gpu.c | 1 + hw/display/virtio-vga.c | 33 ++++++++++++++++++++++++--------- include/hw/virtio/virtio-gpu.h | 5 +++++ 4 files changed, 44 insertions(+), 9 deletions(-)
hw/display/virtio-gpu-pci.c +14 -0
@@ -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, +VIRTIO_GPU_SHM_ID_HOST_VISIBLE ); + } +virtio_pci_force_virtio_1 (vpci_dev);if (!qdev_realize (vdev,BUS (&vpci_dev->bus), errp)) {return ;
hw/display/virtio-gpu.c +1 -0
@@ -1509,6 +1509,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 +24 -9
@@ -115,17 +115,32 @@ 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, +VIRTIO_GPU_SHM_ID_HOST_VISIBLE ); + } +if (!(vpci_dev->flags &VIRTIO_PCI_FLAG_PAGE_PER_VQ )) {/* * with page-per-vq=off there is no padding space we can use
include/hw/virtio/virtio-gpu.h +5 -0
@@ -108,12 +108,15 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED))#define virtio_gpu_context_init_enabled (_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_CONTEXT_INIT_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 {
@@ -137,6 +140,8 @@ struct VirtIOGPUBase {int renderer_blocked;int enable; +MemoryRegion hostmem; +struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS ];int enabled_output_bitmask;
Signature · 1 line
2.34.1
PATCH v5 4/13 virtio-gpu: blob prep
In reply to Huang RuiFrom: Antonio Caggiano <[email protected]>
This adds preparatory functions needed to:
- decode blob cmds
- tracking iovecs
---
This patch is already under review as part of the "rutabaga_gfx + gfxstream" series (already in v13) and has been included here because of dependency.
hw/display/virtio-gpu.c | 10 +++------- include/hw/virtio/virtio-gpu-bswap.h | 15 +++++++++++++++ include/hw/virtio/virtio-gpu.h | 5 +++++ 3 files changed, 23 insertions(+), 7 deletions(-)
hw/display/virtio-gpu.c +3 -7
@@ -33,15 +33,11 @@#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,const char *caller,uint32_t *error); -static void virtio_gpu_cleanup_mapping (VirtIOGPU *g, -struct virtio_gpu_simple_resource *res);static void virtio_gpu_reset_bh (void *opaque); void virtio_gpu_update_cursor_data(VirtIOGPU *g,
@@ -116,7 +112,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;
@@ -904,8 +900,8 @@ void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g,g_free (iov); } -static void virtio_gpu_cleanup_mapping (VirtIOGPU *g, -struct virtio_gpu_simple_resource *res) +void virtio_gpu_cleanup_mapping (VirtIOGPU *g, +struct virtio_gpu_simple_resource *res) {virtio_gpu_cleanup_mapping_iov (g, res->iov, res->iov_cnt); res->iov =NULL ;
include/hw/virtio/virtio-gpu-bswap.h +15 -0
@@ -70,6 +70,21 @@ virtio_gpu_create_blob_bswap(struct virtio_gpu_resource_create_blob *cblob)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 +5 -0
@@ -257,6 +257,9 @@ void virtio_gpu_base_fill_display_info(VirtIOGPUBase *g,void virtio_gpu_base_generate_edid (VirtIOGPUBase *g,int scanout,struct virtio_gpu_resp_edid *edid);/* 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,
@@ -275,6 +278,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_cleanup_mapping (VirtIOGPU *g, +struct virtio_gpu_simple_resource *res);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.34.1
PATCH v5 5/13 virtio-gpu: Configure context init for virglrenderer
In reply to Huang RuiConfigure context init feature flag for virglrenderer.
---
V4 -> V5:
- Inverted patch 5 and 6 because we should configure HAVE_VIRGL_CONTEXT_INIT firstly. (Philippe)
meson.build | 4 ++++ 1 file changed, 4 insertions(+)
meson.build +4 -0
@@ -1068,6 +1068,10 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu prefix: '#include <virglrenderer.h>', dependencies: virgl)) endif + config_host_data.set('HAVE_VIRGL_CONTEXT_INIT', + cc.has_function('virgl_renderer_context_create_with_flags', + prefix: '#include <virglrenderer.h>', + dependencies: virgl)) endif blkio = not_found if not get_option('blkio').auto() or have_block
Signature · 1 line
2.34.1
Re: [QEMU PATCH v5 05/13] virtio-gpu: Configure context init for virglrenderer
Hi
Quoted 19 lines · Huang Rui
Configure context init feature flag for virglrenderer.
Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)meson.build | 4 ++++ 1 file changed, 4 insertions(+)meson.build +0
-0
meson.build if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu · line 1074
Quoted 7 lines
meson.build +4
-0@@ -1068,6 +1068,10 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu prefix: '#include <virglrenderer.h>', dependencies: virgl)) endif + config_host_data.set('HAVE_VIRGL_CONTEXT_INIT', + cc.has_function('virgl_renderer_context_create_with_flags', + prefix: '#include <virglrenderer.h>', + dependencies: virgl))
Move it under the "if virgl.found()" block above.
I suggest to name it after what is actually checked:HAVE_VIRGL_CONTEXT_CREATE_WITH_FLAGS for ex
Quoted 7 lines
meson.build +0
-1endif blkio = not_found if not get_option('blkio').auto() or have_block --2.34.1
Signature · 1 line
Marc-André Lureau
Re: [QEMU PATCH v5 05/13] virtio-gpu: Configure context init for virglrenderer
Quoted 32 lines · Marc-André Lureau
Hi
Quoted 19 lines · Huang Rui
Configure context init feature flag for virglrenderer.
Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)meson.build | 4 ++++ 1 file changed, 4 insertions(+)meson.build +0
-0meson.build if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu · line 1074
Quoted 7 lines
meson.build +4
-0@@ -1068,6 +1068,10 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu prefix: '#include <virglrenderer.h>', dependencies: virgl)) endif + config_host_data.set('HAVE_VIRGL_CONTEXT_INIT', + cc.has_function('virgl_renderer_context_create_with_flags', + prefix: '#include <virglrenderer.h>', + dependencies: virgl))Move it under the "if
virgl.found()" block above.
Quoted 3 lines
I suggest to name it after what is actually checked:
HAVE_VIRGL_CONTEXT_CREATE_WITH_FLAGSfor ex
OK, will update it in V6.
Thanks,
Ray
Quoted 11 lines
Quoted 7 lines
meson.build +0
-1endif blkio = not_found if not get_option('blkio').auto() or have_block --2.34.1
Signature · 1 line
Marc-André Lureau
Re: [QEMU PATCH v5 05/13] virtio-gpu: Configure context init for virglrenderer
In reply to Huang RuiQuoted 18 lines · Huang Rui
Configure context init feature flag for virglrenderer.
Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)meson.build | 4 ++++ 1 file changed, 4 insertions(+)meson.build +0
-0
meson.build if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu · line 1074
Quoted 7 lines
meson.build +4
-0@@ -1068,6 +1068,10 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu prefix: '#include <virglrenderer.h>', dependencies: virgl)) endif + config_host_data.set('HAVE_VIRGL_CONTEXT_INIT', + cc.has_function('virgl_renderer_context_create_with_flags', + prefix: '#include <virglrenderer.h>', + dependencies: virgl))
The "cc.has_function" doesn't work properly with PKG_CONFIG_PATH. It ignores the the given pkg and uses system includes. Antonio was aware about that problem [1].
[1] https://gitlab.freedesktop.org/Fahien/qemu/-/commit/ea1c252a707940983ccce71e92a292b49496bfcd
Given that virglrenderer 1.0 has been released couple weeks ago, can we make the v1.0 a mandatory requirement for qemu and remove all the ifdefs? I doubt that anyone is going to test newer qemu using older libviglrenderer, all that ifdef code will be bitrotting.
@@ -1060,6 +1060,7 @@ virgl = not_found
have_vhost_user_gpu = have_tools and targetos == 'linux' and pixman.found() if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu
virgl = dependency('virglrenderer',
+ version: '>=1.0.0',
method: 'pkg-config',
required: get_option('virglrenderer'))
if virgl.found()
Best regards,
Dmitry
Re: [QEMU PATCH v5 05/13] virtio-gpu: Configure context init for virglrenderer
Quoted 28 lines · Dmitry Osipenko
Quoted 18 lines · Huang Rui
Configure context init feature flag for virglrenderer.
Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)meson.build | 4 ++++ 1 file changed, 4 insertions(+)meson.build +0
-0meson.build if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu · line 1074
Quoted 7 lines
meson.build +4
-0@@ -1068,6 +1068,10 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu prefix: '#include <virglrenderer.h>', dependencies: virgl)) endif + config_host_data.set('HAVE_VIRGL_CONTEXT_INIT', + cc.has_function('virgl_renderer_context_create_with_flags', + prefix: '#include <virglrenderer.h>', + dependencies: virgl))The "cc.has_function" doesn't work properly with
PKG_CONFIG_PATH. It ignores the the given pkg and uses system includes. Antonio was aware about that problem [1].
Quoted 6 lines
[1] https://gitlab.freedesktop.org/Fahien/qemu/-/commit/ea1c252a707940983ccce71e92a292b49496bfcd
Given that virglrenderer 1.0 has been released couple weeks ago, can we make the v1.0 a mandatory requirement for qemu and remove all the ifdefs? I doubt that anyone is going to test newer qemu using older libviglrenderer, all that ifdef code will be bitrotting.
We cannot do that. If is is only weeks old, no distro will have virglrenderer 1.0 present. QEMU has a defined set of platforms that it targets compatibility with:
https://www.qemu.org/docs/master/about/build-platforms.html
For newly added functionality we can set the min version to something newer than the oldest QEMU target platform.
For existing functionality though, we must not regress wrt the currently supported set of target platforms. So we can only bump the min version to that present in the oldest platform we target.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [QEMU PATCH v5 05/13] virtio-gpu: Configure context init for virglrenderer
Quoted 42 lines · Daniel P. Berrangé
Quoted 28 lines · Dmitry Osipenko
Quoted 18 lines · Huang Rui
Configure context init feature flag for virglrenderer.
Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)meson.build | 4 ++++ 1 file changed, 4 insertions(+)meson.build +0
-0meson.build if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu · line 1074
Quoted 7 lines
meson.build +4
-0@@ -1068,6 +1068,10 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu prefix: '#include <virglrenderer.h>', dependencies: virgl)) endif + config_host_data.set('HAVE_VIRGL_CONTEXT_INIT', + cc.has_function('virgl_renderer_context_create_with_flags', + prefix: '#include <virglrenderer.h>', + dependencies: virgl))The "cc.has_function" doesn't work properly with
PKG_CONFIG_PATH. It ignores the the given pkg and uses system includes. Antonio was aware about that problem [1].Quoted 6 lines
[1] https://gitlab.freedesktop.org/Fahien/qemu/-/commit/ea1c252a707940983ccce71e92a292b49496bfcd
Given that virglrenderer 1.0 has been released couple weeks ago, can we make the v1.0 a mandatory requirement for qemu and remove all the ifdefs? I doubt that anyone is going to test newer qemu using older libviglrenderer, all that ifdef code will be bitrotting.
We cannot do that. If is is only weeks old, no distro will have virglrenderer 1.0 present. QEMU has a defined set of platforms that it targets compatibility with:
Quoted 7 lines
For newly added functionality we can set the min version to something newer than the oldest QEMU target platform.
For existing functionality though, we must not regress wrt the currently supported set of target platforms. So we can only bump the min version to that present in the oldest platform we target.
Well, then alternatively we could specify supported libvirglrender features based on the lib version to avoid those pkgconfig+meson troubles.
Signature · 2 lines
Best regards, Dmitry
PATCH v5 6/13 virtio-gpu: Support context init feature with virglrenderer
In reply to Huang RuiPatch "virtio-gpu: CONTEXT_INIT feature" has added the context_init feature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags using context_id when valid.
---
V4 -> V5:
- Inverted patch 5 and 6 because we should configure HAVE_VIRGL_CONTEXT_INIT firstly. (Philippe)
hw/display/virtio-gpu-virgl.c | 13 +++++++++++-- hw/display/virtio-gpu.c | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-)
hw/display/virtio-gpu-virgl.c +11 -2
@@ -106,8 +106,17 @@ 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) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif + } + +virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, cc.debug_name); } static void virgl_cmd_context_destroy(VirtIOGPU *g,
hw/display/virtio-gpu.c +2 -0
@@ -1506,6 +1506,8 @@ static Property virtio_gpu_properties[] = {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_BIT ("context_init" , VirtIOGPU, parent_obj.conf.flags, +VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED , false), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
2.34.1
Re: [QEMU PATCH v5 06/13] virtio-gpu: Support context init feature with virglrenderer
Quoted 25 lines · Huang Rui
Patch "virtio-gpu:
CONTEXT_INITfeature" has added thecontext_initfeature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags usingcontext_idwhen valid.Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)hw/display/virtio-gpu-virgl.c | 13 +++++++++++-- hw/display/virtio-gpu.c | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-)hw/display/virtio-gpu-virgl.c +0
-0@@ -106,8 +106,17 @@ static void virgl_cmd_context_create(VirtIOGPU *g,trace_virtio_gpu_cmd_ctx_create (cc.hdr.ctx_id, cc.debug_name);
hw/display/virtio-gpu-virgl.c static void virgl_cmd_context_create(VirtIOGPU *g, · line 116
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +8
-2-virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, - cc.debug_name); +if (cc.context_init) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif
This should deal with the case when context_init is set while HAVE_VIRGL_CONTEXT_INIT is not defined.
Re: [QEMU PATCH v5 06/13] virtio-gpu: Support context init feature with virglrenderer
Quoted 26 lines · Akihiko Odaki
Quoted 25 lines · Huang Rui
Patch "virtio-gpu:
CONTEXT_INITfeature" has added thecontext_initfeature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags usingcontext_idwhen valid.Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)hw/display/virtio-gpu-virgl.c | 13 +++++++++++-- hw/display/virtio-gpu.c | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-)hw/display/virtio-gpu-virgl.c +0
-0@@ -106,8 +106,17 @@ static void virgl_cmd_context_create(VirtIOGPU *g,trace_virtio_gpu_cmd_ctx_create (cc.hdr.ctx_id, cc.debug_name);
Quoted 13 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_context_create(VirtIOGPU *g, · line 116
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +8
-2-virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, - cc.debug_name); +if (cc.context_init) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif This should deal with the case when
context_initis set whileHAVE_VIRGL_CONTEXT_INITis not defined.
Actually, I received the comment below before:
https://lore.kernel.org/qemu-devel/[email protected]/
At original patch set, I have the case while HAVE_VIRGL_CONTEXT_INIT is set but HAVE_VIRGL_CONTEXT_INIT is not defined. But I think we may encounter the case that virgl_renderer_context_create_with_flags is not defined in virglrenderer early version. Should I bring the error message back?
Thanks,
Ray
Re: [QEMU PATCH v5 06/13] virtio-gpu: Support context init feature with virglrenderer
Quoted 45 lines · Huang Rui
Quoted 26 lines · Akihiko Odaki
Quoted 25 lines · Huang Rui
Patch "virtio-gpu:
CONTEXT_INITfeature" has added thecontext_initfeature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags usingcontext_idwhen valid.Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)hw/display/virtio-gpu-virgl.c | 13 +++++++++++-- hw/display/virtio-gpu.c | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-)hw/display/virtio-gpu-virgl.c +0
-0@@ -106,8 +106,17 @@ static void virgl_cmd_context_create(VirtIOGPU *g,trace_virtio_gpu_cmd_ctx_create (cc.hdr.ctx_id, cc.debug_name);Quoted 13 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_context_create(VirtIOGPU *g, · line 116
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +8
-2-virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, - cc.debug_name); +if (cc.context_init) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif This should deal with the case when
context_initis set whileHAVE_VIRGL_CONTEXT_INITis not defined.Actually, I received the comment below before:
Quoted 7 lines
At original patch set, I have the case while
HAVE_VIRGL_CONTEXT_INITis set butHAVE_VIRGL_CONTEXT_INITis not defined. But I think we may encounter the case thatvirgl_renderer_context_create_with_flagsis not defined in virglrenderer early version. Should I bring the error message back?Thanks,
Ray
I suggest checking VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED instead of reporting an error here. Perhaps it may be easier to add #ifdef around:
Quoted 2 lines
hw/display/virtio-gpu.c +2
-0+DEFINE_PROP_BIT ("context_init" , VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, false),
Re: [QEMU PATCH v5 06/13] virtio-gpu: Support context init feature with virglrenderer
Quoted 51 lines · Akihiko Odaki
Quoted 50 lines · Huang Rui
Quoted 26 lines · Akihiko Odaki
Quoted 25 lines · Huang Rui
Patch "virtio-gpu:
CONTEXT_INITfeature" has added thecontext_initfeature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags usingcontext_idwhen valid.Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)hw/display/virtio-gpu-virgl.c | 13 +++++++++++-- hw/display/virtio-gpu.c | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-)hw/display/virtio-gpu-virgl.c +0
-0@@ -106,8 +106,17 @@ static void virgl_cmd_context_create(VirtIOGPU *g,trace_virtio_gpu_cmd_ctx_create (cc.hdr.ctx_id, cc.debug_name);Quoted 13 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_context_create(VirtIOGPU *g, · line 116
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +8
-2-virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, - cc.debug_name); +if (cc.context_init) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif This should deal with the case when
context_initis set whileHAVE_VIRGL_CONTEXT_INITis not defined.Actually, I received the comment below before:
https://lore.kernel.org/qemu-devel/[email protected]/
At original patch set, I have the case while
HAVE_VIRGL_CONTEXT_INITis set butHAVE_VIRGL_CONTEXT_INITis not defined. But I think we may encounter the case thatvirgl_renderer_context_create_with_flagsis not defined in virglrenderer early version. Should I bring the error message back?
Quoted 7 lines
Quoted 2 lines
Thanks,
RayI suggest checking
VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLEDinstead of reporting an error here. Perhaps it may be easier to add #ifdef around:Quoted 2 lines
(quoted diff) +2
-0+ DEFINE_PROP_BIT("context_init", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, false),
How about below changes:
---
hw/display/virtio-gpu-virgl.c +9 -2
@@ -106,8 +106,15 @@ 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 &&virtio_gpu_context_init_enabled (g->conf)) { +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; + } + +virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, cc.debug_name); } static void virgl_cmd_context_destroy(VirtIOGPU *g,
hw/display/virtio-gpu.c +4 -0
@@ -1508,6 +1508,10 @@ static Property virtio_gpu_properties[] = {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 ), +#ifdef HAVE_VIRGL_CONTEXT_INIT +DEFINE_PROP_BIT ("context_init" , VirtIOGPU, parent_obj.conf.flags, +VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED , true), +#endif DEFINE_PROP_END_OF_LIST(), };
Re: [QEMU PATCH v5 06/13] virtio-gpu: Support context init feature with virglrenderer
Quoted 89 lines · Huang Rui
Quoted 51 lines · Akihiko Odaki
Quoted 50 lines · Huang Rui
Quoted 26 lines · Akihiko Odaki
Quoted 25 lines · Huang Rui
Patch "virtio-gpu:
CONTEXT_INITfeature" has added thecontext_initfeature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags usingcontext_idwhen valid.Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)
hw/display/virtio-gpu-virgl.c| 13 +++++++++++--
hw/display/virtio-gpu.c| 2 ++
2 files changed, 13 insertions(+), 2 deletions(-)hw/display/virtio-gpu-virgl.c +0
-0@@ -106,8 +106,17 @@ static void virgl_cmd_context_create(VirtIOGPU *g,trace_virtio_gpu_cmd_ctx_create (cc.hdr.ctx_id, cc.debug_name);Quoted 13 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_context_create(VirtIOGPU *g,
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +8
-2-virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, - cc.debug_name); +if (cc.context_init) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif This should deal with the case when
context_initis set whileHAVE_VIRGL_CONTEXT_INITis not defined.Actually, I received the comment below before:
https://lore.kernel.org/qemu-devel/[email protected]/
At original patch set, I have the case while
HAVE_VIRGL_CONTEXT_INITis set butHAVE_VIRGL_CONTEXT_INITis not defined. But I think we may encounter the case thatvirgl_renderer_context_create_with_flagsis not defined in virglrenderer early version. Should I bring the error message back?Quoted 7 lines
Quoted 2 lines
Thanks,
RayI suggest checking
VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLEDinstead of reporting an error here. Perhaps it may be easier to add #ifdef around:Quoted 2 lines
(quoted diff) +2
-0+ DEFINE_PROP_BIT("context_init", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, false),How about below changes: >
---hw/display/virtio-gpu-virgl.c +9
-2@@ -106,8 +106,15 @@ 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 &&virtio_gpu_context_init_enabled (g->conf)) { +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; + } + +virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, cc.debug_name); } static void virgl_cmd_context_destroy(VirtIOGPU *g,hw/display/virtio-gpu.c +0
-0
hw/display/virtio-gpu.c static Property virtio_gpu_properties[] = { · line 1517
Quoted 10 lines
hw/display/virtio-gpu.c +4
-0@@ -1508,6 +1508,10 @@ static Property virtio_gpu_properties[] = {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 ), +#ifdef HAVE_VIRGL_CONTEXT_INIT +DEFINE_PROP_BIT ("context_init" , VirtIOGPU, parent_obj.conf.flags, +VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED , true), +#endif DEFINE_PROP_END_OF_LIST(), };
It looks better, but not having #ifdef around virgl_renderer_context_create_with_flags() will result in a link error with old virglrenderer.
Re: [QEMU PATCH v5 06/13] virtio-gpu: Support context init feature with virglrenderer
Quoted 96 lines · Akihiko Odaki
Quoted 95 lines · Huang Rui
Quoted 51 lines · Akihiko Odaki
Quoted 50 lines · Huang Rui
Quoted 26 lines · Akihiko Odaki
Quoted 25 lines · Huang Rui
Patch "virtio-gpu:
CONTEXT_INITfeature" has added thecontext_initfeature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags usingcontext_idwhen valid.Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)
hw/display/virtio-gpu-virgl.c| 13 +++++++++++--
hw/display/virtio-gpu.c| 2 ++
2 files changed, 13 insertions(+), 2 deletions(-)hw/display/virtio-gpu-virgl.c +0
-0@@ -106,8 +106,17 @@ static void virgl_cmd_context_create(VirtIOGPU *g,trace_virtio_gpu_cmd_ctx_create (cc.hdr.ctx_id, cc.debug_name);Quoted 13 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_context_create(VirtIOGPU *g,
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +8
-2-virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, - cc.debug_name); +if (cc.context_init) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif This should deal with the case when
context_initis set whileHAVE_VIRGL_CONTEXT_INITis not defined.Actually, I received the comment below before:
https://lore.kernel.org/qemu-devel/[email protected]/
At original patch set, I have the case while
HAVE_VIRGL_CONTEXT_INITis set butHAVE_VIRGL_CONTEXT_INITis not defined. But I think we may encounter the case thatvirgl_renderer_context_create_with_flagsis not defined in virglrenderer early version. Should I bring the error message back?Quoted 7 lines
Quoted 2 lines
Thanks,
RayI suggest checking
VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLEDinstead of reporting an error here. Perhaps it may be easier to add #ifdef around:Quoted 2 lines
(quoted diff) +2
-0+ DEFINE_PROP_BIT("context_init", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, false),How about below changes: >
---hw/display/virtio-gpu-virgl.c +9
-2@@ -106,8 +106,15 @@ 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 &&virtio_gpu_context_init_enabled (g->conf)) { +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; + } + +virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, cc.debug_name); } static void virgl_cmd_context_destroy(VirtIOGPU *g,hw/display/virtio-gpu.c +3
-0@@ -1508,6 +1508,10 @@ static Property virtio_gpu_properties[] = {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 ), +#ifdef HAVE_VIRGL_CONTEXT_INIT +DEFINE_PROP_BIT ("context_init" , VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, true),
Quoted 8 lines
hw/display/virtio-gpu.c static Property virtio_gpu_properties[] = { · line 1517
Quoted 4 lines
hw/display/virtio-gpu.c +1
-0+#endif DEFINE_PROP_END_OF_LIST(), };It looks better, but not having #ifdef around
virgl_renderer_context_create_with_flags()will result in a link error with old virglrenderer.
Hmm, right, it seems that we have to have a "#ifdef" around here. Or do you have any better idea?
Thanks,
Ray
Re: [QEMU PATCH v5 06/13] virtio-gpu: Support context init feature with virglrenderer
Quoted 106 lines · Huang Rui
Quoted 96 lines · Akihiko Odaki
Quoted 95 lines · Huang Rui
Quoted 51 lines · Akihiko Odaki
Quoted 50 lines · Huang Rui
Quoted 26 lines · Akihiko Odaki
Quoted 25 lines · Huang Rui
Patch "virtio-gpu:
CONTEXT_INITfeature" has added thecontext_initfeature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags usingcontext_idwhen valid.Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)
hw/display/virtio-gpu-virgl.c| 13 +++++++++++--
hw/display/virtio-gpu.c| 2 ++
2 files changed, 13 insertions(+), 2 deletions(-)hw/display/virtio-gpu-virgl.c +0
-0@@ -106,8 +106,17 @@ static void virgl_cmd_context_create(VirtIOGPU *g,trace_virtio_gpu_cmd_ctx_create (cc.hdr.ctx_id, cc.debug_name);Quoted 13 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_context_create(VirtIOGPU *g,
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +8
-2-virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, - cc.debug_name); +if (cc.context_init) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif This should deal with the case when
context_initis set whileHAVE_VIRGL_CONTEXT_INITis not defined.Actually, I received the comment below before:
https://lore.kernel.org/qemu-devel/[email protected]/
At original patch set, I have the case while
HAVE_VIRGL_CONTEXT_INITis set butHAVE_VIRGL_CONTEXT_INITis not defined. But I think we may encounter the case thatvirgl_renderer_context_create_with_flagsis not defined in virglrenderer early version. Should I bring the error message back?Quoted 7 lines
Quoted 2 lines
Thanks,
RayI suggest checking
VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLEDinstead of reporting an error here. Perhaps it may be easier to add #ifdef around:Quoted 2 lines
(quoted diff) +2
-0+ DEFINE_PROP_BIT("context_init", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, false),How about below changes: >
---hw/display/virtio-gpu-virgl.c +9
-2@@ -106,8 +106,15 @@ 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 &&virtio_gpu_context_init_enabled (g->conf)) { +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; + } + +virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, cc.debug_name); } static void virgl_cmd_context_destroy(VirtIOGPU *g,hw/display/virtio-gpu.c +3
-0@@ -1508,6 +1508,10 @@ static Property virtio_gpu_properties[] = {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 ), +#ifdef HAVE_VIRGL_CONTEXT_INIT +DEFINE_PROP_BIT ("context_init" , VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, true),Quoted 8 lines
hw/display/virtio-gpu.c static Property virtio_gpu_properties[] = { · line 1517
Quoted 4 lines
hw/display/virtio-gpu.c +1
-0+#endif DEFINE_PROP_END_OF_LIST(), };It looks better, but not having #ifdef around
virgl_renderer_context_create_with_flags()will result in a link error with old virglrenderer.
Quoted 2 lines
Hmm, right, it seems that we have to have a "#ifdef" around here. Or do you have any better idea?
Having #ifdef is the right direction.
Re: [QEMU PATCH v5 06/13] virtio-gpu: Support context init feature with virglrenderer
Quoted 107 lines · Akihiko Odaki
Quoted 106 lines · Huang Rui
Quoted 104 lines · Akihiko Odaki
Quoted 89 lines · Huang Rui
Quoted 51 lines · Akihiko Odaki
Quoted 50 lines · Huang Rui
Quoted 26 lines · Akihiko Odaki
Quoted 25 lines · Huang Rui
Patch "virtio-gpu:
CONTEXT_INITfeature" has added thecontext_initfeature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags usingcontext_idwhen valid.Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)
hw/display/virtio-gpu-virgl.c| 13 +++++++++++--
hw/display/virtio-gpu.c| 2 ++
2 files changed, 13 insertions(+), 2 deletions(-)hw/display/virtio-gpu-virgl.c +0
-0@@ -106,8 +106,17 @@ static void virgl_cmd_context_create(VirtIOGPU *g,trace_virtio_gpu_cmd_ctx_create (cc.hdr.ctx_id, cc.debug_name);Quoted 13 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_context_create(VirtIOGPU *g, · line 116
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +8
-2-virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, - cc.debug_name); +if (cc.context_init) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif This should deal with the case when
context_initis set whileHAVE_VIRGL_CONTEXT_INITis not defined.Actually, I received the comment below before:
https://lore.kernel.org/qemu-devel/[email protected]/
At original patch set, I have the case while
HAVE_VIRGL_CONTEXT_INITis set butHAVE_VIRGL_CONTEXT_INITis not defined. But I think we may encounter the case thatvirgl_renderer_context_create_with_flagsis not defined in virglrenderer early version. Should I bring the error message back?Quoted 7 lines
Quoted 2 lines
Thanks,
RayI suggest checking
VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLEDinstead of reporting an error here. Perhaps it may be easier to add #ifdef around:Quoted 2 lines
(quoted diff) +2
-0+ DEFINE_PROP_BIT("context_init", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, false),How about below changes: >
---hw/display/virtio-gpu-virgl.c +9
-2@@ -106,8 +106,15 @@ 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 &&virtio_gpu_context_init_enabled (g->conf)) { +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; + } + +virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, cc.debug_name); } static void virgl_cmd_context_destroy(VirtIOGPU *g,hw/display/virtio-gpu.c +0
-0hw/display/virtio-gpu.c static Property virtio_gpu_properties[] = { · line 1517
Quoted 10 lines
hw/display/virtio-gpu.c +4
-0@@ -1508,6 +1508,10 @@ static Property virtio_gpu_properties[] = {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 ), +#ifdef HAVE_VIRGL_CONTEXT_INIT +DEFINE_PROP_BIT ("context_init" , VirtIOGPU, parent_obj.conf.flags, +VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED , true), +#endif DEFINE_PROP_END_OF_LIST(), };It looks better, but not having #ifdef around
virgl_renderer_context_create_with_flags()will result in a link error with old virglrenderer.
Quoted 4 lines
Quoted 2 lines
Hmm, right, it seems that we have to have a "#ifdef" around here. Or do you have any better idea?
Having #ifdef is the right direction.
OK, so we can use cc.context_init and make sure context_init function enabled. Please check below:
---
hw/display/virtio-gpu-virgl.c +11 -2
@@ -106,8 +106,17 @@ 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 &&virtio_gpu_context_init_enabled (g->parent_obj.conf)) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif + } + +virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, cc.debug_name); } static void virgl_cmd_context_destroy(VirtIOGPU *g,
hw/display/virtio-gpu.c +4 -0
@@ -1508,6 +1508,10 @@ static Property virtio_gpu_properties[] = {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 ), +#ifdef HAVE_VIRGL_CONTEXT_INIT +DEFINE_PROP_BIT ("context_init" , VirtIOGPU, parent_obj.conf.flags, +VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED , true), +#endif DEFINE_PROP_END_OF_LIST(), };
Re: [QEMU PATCH v5 06/13] virtio-gpu: Support context init feature with virglrenderer
Quoted 126 lines · Huang Rui
Quoted 107 lines · Akihiko Odaki
Quoted 106 lines · Huang Rui
Quoted 104 lines · Akihiko Odaki
Quoted 89 lines · Huang Rui
Quoted 51 lines · Akihiko Odaki
Quoted 50 lines · Huang Rui
Quoted 26 lines · Akihiko Odaki
Quoted 25 lines · Huang Rui
Patch "virtio-gpu:
CONTEXT_INITfeature" has added thecontext_initfeature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags usingcontext_idwhen valid.Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)
hw/display/virtio-gpu-virgl.c| 13 +++++++++++--
hw/display/virtio-gpu.c| 2 ++
2 files changed, 13 insertions(+), 2 deletions(-)hw/display/virtio-gpu-virgl.c +0
-0@@ -106,8 +106,17 @@ static void virgl_cmd_context_create(VirtIOGPU *g,trace_virtio_gpu_cmd_ctx_create (cc.hdr.ctx_id, cc.debug_name);Quoted 13 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_context_create(VirtIOGPU *g, · line 116
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +8
-2-virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, - cc.debug_name); +if (cc.context_init) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif This should deal with the case when
context_initis set whileHAVE_VIRGL_CONTEXT_INITis not defined.Actually, I received the comment below before:
https://lore.kernel.org/qemu-devel/[email protected]/
At original patch set, I have the case while
HAVE_VIRGL_CONTEXT_INITis set butHAVE_VIRGL_CONTEXT_INITis not defined. But I think we may encounter the case thatvirgl_renderer_context_create_with_flagsis not defined in virglrenderer early version. Should I bring the error message back?Quoted 7 lines
Quoted 2 lines
Thanks,
RayI suggest checking
VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLEDinstead of reporting an error here. Perhaps it may be easier to add #ifdef around:Quoted 2 lines
(quoted diff) +2
-0+ DEFINE_PROP_BIT("context_init", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, false),How about below changes: >
---hw/display/virtio-gpu-virgl.c +9
-2@@ -106,8 +106,15 @@ 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 &&virtio_gpu_context_init_enabled (g->conf)) { +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; + } + +virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, cc.debug_name); } static void virgl_cmd_context_destroy(VirtIOGPU *g,hw/display/virtio-gpu.c +0
-0hw/display/virtio-gpu.c static Property virtio_gpu_properties[] = { · line 1517
Quoted 10 lines
hw/display/virtio-gpu.c +4
-0@@ -1508,6 +1508,10 @@ static Property virtio_gpu_properties[] = {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 ), +#ifdef HAVE_VIRGL_CONTEXT_INIT +DEFINE_PROP_BIT ("context_init" , VirtIOGPU, parent_obj.conf.flags, +VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED , true), +#endif DEFINE_PROP_END_OF_LIST(), };It looks better, but not having #ifdef around
virgl_renderer_context_create_with_flags()will result in a link error with old virglrenderer.Quoted 4 lines
Quoted 2 lines
Hmm, right, it seems that we have to have a "#ifdef" around here. Or do you have any better idea?
Having #ifdef is the right direction.
OK, so we can use cc.context_init and make sure
context_initfunction enabled. Please check below:---
hw/display/virtio-gpu-virgl.c +0
-1@@ -106,8 +106,17 @@ 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,
hw/display/virtio-gpu-virgl.c static void virgl_cmd_context_create(VirtIOGPU *g, · line 117
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +9
-1- cc.debug_name); +if (cc.context_init &&virtio_gpu_context_init_enabled (g->parent_obj.conf)) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif + }
You can put the if-statement into #ifdef. Otherwise it looks good to me.
Re: [QEMU PATCH v5 06/13] virtio-gpu: Support context init feature with virglrenderer
In reply to Huang RuiQuoted 46 lines · Huang Rui
Patch "virtio-gpu:
CONTEXT_INITfeature" has added thecontext_initfeature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags usingcontext_idwhen valid.Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)hw/display/virtio-gpu-virgl.c | 13 +++++++++++-- hw/display/virtio-gpu.c | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-)hw/display/virtio-gpu-virgl.c +11
-2@@ -106,8 +106,17 @@ 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) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif + } + +virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, cc.debug_name); } static void virgl_cmd_context_destroy(VirtIOGPU *g,hw/display/virtio-gpu.c +0
-0
hw/display/virtio-gpu.c static Property virtio_gpu_properties[] = { · line 1513
Quoted 8 lines
hw/display/virtio-gpu.c +2
-0@@ -1506,6 +1506,8 @@ static Property virtio_gpu_properties[] = {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_BIT ("context_init" , VirtIOGPU, parent_obj.conf.flags, +VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED , false), DEFINE_PROP_END_OF_LIST(), };
I think it's more convenient if this feature is enabled by default.
Re: [QEMU PATCH v5 06/13] virtio-gpu: Support context init feature with virglrenderer
Quoted 41 lines · Akihiko Odaki
Quoted 40 lines · Huang Rui
Patch "virtio-gpu:
CONTEXT_INITfeature" has added thecontext_initfeature flags.
We would like to enable the feature with virglrenderer, so add to create virgl renderer context with flags usingcontext_idwhen valid.Originally-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Inverted patch 5 and 6 because we should configureHAVE_VIRGL_CONTEXT_INITfirstly. (Philippe)hw/display/virtio-gpu-virgl.c | 13 +++++++++++-- hw/display/virtio-gpu.c | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-)hw/display/virtio-gpu-virgl.c +11
-2@@ -106,8 +106,17 @@ 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) { +#ifdef HAVE_VIRGL_CONTEXT_INIT +virgl_renderer_context_create_with_flags (cc.hdr.ctx_id, + cc.context_init, + cc.nlen, + cc.debug_name); +return ; +#endif + } + +virgl_renderer_context_create (cc.hdr.ctx_id, cc.nlen, cc.debug_name); }
Quoted 16 lines
Quoted 6 lines
hw/display/virtio-gpu-virgl.c +0
-0static void virgl_cmd_context_destroy(VirtIOGPU *g,hw/display/virtio-gpu.c +0
-0hw/display/virtio-gpu.c static Property virtio_gpu_properties[] = { · line 1513
Quoted 8 lines
hw/display/virtio-gpu.c +2
-0@@ -1506,6 +1506,8 @@ static Property virtio_gpu_properties[] = {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_BIT ("context_init" , VirtIOGPU, parent_obj.conf.flags, +VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED , false), DEFINE_PROP_END_OF_LIST(), };I think it's more convenient if this feature is enabled by default.
Yes, I will update it in next version.
Thanks,
Ray
PATCH v5 7/13 softmmu/memory: enable automatic deallocation of memory regions
In reply to Huang RuiFrom: Xenia Ragiadakou <[email protected]>
When the memory region has a different life-cycle from that of her parent, could be automatically released, once has been unparent and once all of her references have gone away, via the object's free callback.
However, currently, references to the memory region are held by its owner without first incrementing the memory region object's reference count. As a result, the automatic deallocation of the object, not taking into account those references, results in use-after-free memory corruption.
This patch increases the reference count of an owned memory region object on each memory_region_ref() and decreases it on each memory_region_unref().
---
V4 -> V5:
- ref/unref only owned memory regions (Akihiko)
softmmu/memory.c | 5 +++++ 1 file changed, 5 insertions(+)
softmmu/memory.c +5 -0
@@ -1800,6 +1800,9 @@ void memory_region_ref(MemoryRegion *mr)/* MMIO callbacks most likely will access data that belongs * to the owner, hence the need to ref/unref the owner whenever * the memory region is in use. +* Likewise, the owner keeps references to the memory region, +* hence the need to ref/unref the memory region object to prevent +* its automatic deallocation while still referenced by its owner. * * The memory region is a child of its owner. As long as the * owner doesn't call unparent itself on the memory region,
@@ -1808,6 +1811,7 @@ void memory_region_ref(MemoryRegion *mr)* we do not ref/unref them because it slows down DMA sensibly. */ if (mr && mr->owner) { +object_ref (OBJECT (mr));object_ref (mr->owner); } }
@@ -1816,6 +1820,7 @@ void memory_region_unref(MemoryRegion *mr) {if (mr && mr->owner) {object_unref (mr->owner); +object_unref (OBJECT (mr)); } }
Signature · 1 line
2.34.1
Re: [QEMU PATCH v5 07/13] softmmu/memory: enable automatic deallocation of memory regions
Quoted 29 lines · Huang Rui
From: Xenia Ragiadakou <[email protected]>
When the memory region has a different life-cycle from that of her parent, could be automatically released, once has been unparent and once all of her references have gone away, via the object's free callback.
However, currently, references to the memory region are held by its owner without first incrementing the memory region object's reference count. As a result, the automatic deallocation of the object, not taking into account those references, results in use-after-free memory corruption.
This patch increases the reference count of an owned memory region object on each
memory_region_ref()and decreases it on eachmemory_region_unref().Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- ref/unref only owned memory regions (Akihiko)softmmu/memory.c | 5 +++++ 1 file changed, 5 insertions(+)softmmu/memory.c +0
-0
softmmu/memory.c void memory_region_ref(MemoryRegion *mr) · line 1805
Quoted 6 lines
softmmu/memory.c +3
-0@@ -1800,6 +1800,9 @@ void memory_region_ref(MemoryRegion *mr)/* MMIO callbacks most likely will access data that belongs * to the owner, hence the need to ref/unref the owner whenever * the memory region is in use. +* Likewise, the owner keeps references to the memory region, +* hence the need to ref/unref the memory region object to prevent +* its automatic deallocation while still referenced by its owner.
This comment does not make sense. Traditionally no such automatic deallocation happens so the owner has been always required to free the memory region when it gets finalized.
"[QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands" introduces a different kind of memory region, which can be freed anytime before the device gets finalized. Even in this case, the owner removes the reference to the memory owner by doing res->region = NULL;
Regards,
Akihiko Odaki
Re: [QEMU PATCH v5 07/13] softmmu/memory: enable automatic deallocation of memory regions
Quoted 39 lines · Akihiko Odaki
Quoted 29 lines · Huang Rui
From: Xenia Ragiadakou <[email protected]>
When the memory region has a different life-cycle from that of her parent, could be automatically released, once has been unparent and once all of her references have gone away, via the object's free callback.
However, currently, references to the memory region are held by its owner without first incrementing the memory region object's reference count. As a result, the automatic deallocation of the object, not taking into account those references, results in use-after-free memory corruption.
This patch increases the reference count of an owned memory region object on each
memory_region_ref()and decreases it on eachmemory_region_unref().Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- ref/unref only owned memory regions (Akihiko)
softmmu/memory.c| 5 +++++1 file changed, 5 insertions(+)softmmu/memory.c +0
-0softmmu/memory.c void memory_region_ref(MemoryRegion *mr) · line 1805
Quoted 6 lines
softmmu/memory.c +3
-0@@ -1800,6 +1800,9 @@ void memory_region_ref(MemoryRegion *mr) /* MMIO callbacks most likely will access data that belongs* to the owner, hence the need to ref/unref the owner whenever * the memory region is in use. +* Likewise, the owner keeps references to the memory region, +* hence the need to ref/unref the memory region object to prevent +* its automatic deallocation while still referenced by its owner. This comment does not make sense. Traditionally no such automatic deallocation happens so the owner has been always required to free the memory region when it gets finalized.
Quoted 1 line
"[QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands" introduces a different kind of memory region, which can be freed anytime before the device gets finalized. Even in this case, the owner removes the reference to the memory owner by doing
res->region= NULL;
Hi Akihiko,
You are right, the word "owner" is not correct. The issue observed was due to the references kept in flatview ranges and the fact that flatview_destroy() is asynchronous and was called after memory region's destruction.
If I replace the word "owner" with "memory subsystem" in the commit message and drop the comment, would that be ok with you? or do want to suggest something else?
Xenia
Quoted 4 lines
Regards,
Akihiko Odaki
Re: [QEMU PATCH v5 07/13] softmmu/memory: enable automatic deallocation of memory regions
Quoted 41 lines · Xenia Ragiadakou
Quoted 39 lines · Akihiko Odaki
Quoted 29 lines · Huang Rui
From: Xenia Ragiadakou <[email protected]>
When the memory region has a different life-cycle from that of her parent, could be automatically released, once has been unparent and once all of her references have gone away, via the object's free callback.
However, currently, references to the memory region are held by its owner without first incrementing the memory region object's reference count. As a result, the automatic deallocation of the object, not taking into account those references, results in use-after-free memory corruption.
This patch increases the reference count of an owned memory region object on each
memory_region_ref()and decreases it on eachmemory_region_unref().Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- ref/unref only owned memory regions (Akihiko)
softmmu/memory.c| 5 +++++1 file changed, 5 insertions(+)softmmu/memory.c +0
-0softmmu/memory.c void memory_region_ref(MemoryRegion *mr) · line 1805
Quoted 6 lines
softmmu/memory.c +3
-0@@ -1800,6 +1800,9 @@ void memory_region_ref(MemoryRegion *mr) /* MMIO callbacks most likely will access data that belongs* to the owner, hence the need to ref/unref the owner whenever * the memory region is in use. +* Likewise, the owner keeps references to the memory region, +* hence the need to ref/unref the memory region object to prevent +* its automatic deallocation while still referenced by its owner. This comment does not make sense. Traditionally no such automatic deallocation happens so the owner has been always required to free the memory region when it gets finalized.
Quoted 7 lines
Quoted 1 line
"[QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands" introduces a different kind of memory region, which can be freed anytime before the device gets finalized. Even in this case, the owner removes the reference to the memory owner by doing
res->region= NULL;Hi Akihiko,
You are right, the word "owner" is not correct. The issue observed was due to the references kept in flatview ranges and the fact that
flatview_destroy()is asynchronous and was called after memory region's destruction.If I replace the word "owner" with "memory subsystem" in the commit message and drop the comment, would that be ok with you? or do want to suggest something else?
This will extend the lifetime of the memory region, but the underlying memory is still synchronously freed. Can you show that the flatview range will not be used to read the freed memory?
Regards,
Akihiko Odaki
Re: [QEMU PATCH v5 07/13] softmmu/memory: enable automatic deallocation of memory regions
Quoted 46 lines · Akihiko Odaki
Quoted 45 lines · Xenia Ragiadakou
Quoted 42 lines · Akihiko Odaki
Quoted 34 lines · Huang Rui
From: Xenia Ragiadakou <[email protected]>
When the memory region has a different life-cycle from that of her parent, could be automatically released, once has been unparent and once all of her references have gone away, via the object's free callback.
However, currently, references to the memory region are held by its owner without first incrementing the memory region object's reference count. As a result, the automatic deallocation of the object, not taking into account those references, results in use-after-free memory corruption.
This patch increases the reference count of an owned memory region object on each
memory_region_ref()and decreases it on eachmemory_region_unref().Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- ref/unref only owned memory regions (Akihiko)
softmmu/memory.c| 5 +++++1 file changed, 5 insertions(+)softmmu/memory.c +2
-0@@ -1800,6 +1800,9 @@ void memory_region_ref(MemoryRegion *mr) /* MMIO callbacks most likely will access data that belongs* to the owner, hence the need to ref/unref the owner whenever * the memory region is in use. +* Likewise, the owner keeps references to the memory region, +* hence the need to ref/unref the memory region object to Quoted 3 lines
prevent
+ * its automatic deallocation while still referenced by its owner.This comment does not make sense. Traditionally no such automatic deallocation happens so the owner has been always required to free the memory region when it gets finalized.
"[QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands" introduces a different kind of memory region, which can be freed anytime before the device gets finalized. Even in this case, the owner removes the reference to the memory owner by doing
res->region= NULL;
Quoted 7 lines
Quoted 5 lines
Hi Akihiko,
You are right, the word "owner" is not correct. The issue observed was due to the references kept in flatview ranges and the fact that
flatview_destroy()is asynchronous and was called after memory region's destruction.If I replace the word "owner" with "memory subsystem" in the commit message and drop the comment, would that be ok with you? or do want to suggest something else?
This will extend the lifetime of the memory region, but the underlying memory is still synchronously freed. Can you show that the flatview range will not be used to read the freed memory?
Yes, the intention of this patch is to delay the mr object finalization until all memory_region_unref() on this mr have been taken place.
What do you mean by "the underlying memory is still synchronously freed"?
Re: [QEMU PATCH v5 07/13] softmmu/memory: enable automatic deallocation of memory regions
Quoted 52 lines · Xenia Ragiadakou
Quoted 50 lines · Akihiko Odaki
Quoted 49 lines · Xenia Ragiadakou
Quoted 41 lines · Akihiko Odaki
Quoted 34 lines · Huang Rui
From: Xenia Ragiadakou <[email protected]>
When the memory region has a different life-cycle from that of her parent, could be automatically released, once has been unparent and once all of her references have gone away, via the object's free callback.
However, currently, references to the memory region are held by its owner without first incrementing the memory region object's reference count. As a result, the automatic deallocation of the object, not taking into account those references, results in use-after-free memory corruption.
This patch increases the reference count of an owned memory region object on each
memory_region_ref()and decreases it on eachmemory_region_unref().Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- ref/unref only owned memory regions (Akihiko)
softmmu/memory.c| 5 +++++1 file changed, 5 insertions(+)softmmu/memory.c +2
-0@@ -1800,6 +1800,9 @@ void memory_region_ref(MemoryRegion *mr) /* MMIO callbacks most likely will access data that belongs* to the owner, hence the need to ref/unref the owner whenever * the memory region is in use. +* Likewise, the owner keeps references to the memory region, +* hence the need to ref/unref the memory region object to Quoted 3 lines
prevent
+ * its automatic deallocation while still referenced by its owner.This comment does not make sense. Traditionally no such automatic deallocation happens so the owner has been always required to free the memory region when it gets finalized.
Quoted 1 line
"[QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands" introduces a different kind of memory region, which can be freed anytime before the device gets finalized. Even in this case, the owner removes the reference to the memory owner by doing
res->region= NULL;Hi Akihiko,
You are right, the word "owner" is not correct. The issue observed was due to the references kept in flatview ranges and the fact that
flatview_destroy()is asynchronous and was called after memory region's destruction.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
If I replace the word "owner" with "memory subsystem" in the commit message and drop the comment, would that be ok with you? or do want to suggest something else?
This will extend the lifetime of the memory region, but the underlying memory is still synchronously freed. Can you show that the flatview range will not be used to read the freed memory?
Yes, the intention of this patch is to delay the mr object finalization until all
memory_region_unref()on this mr have been taken place.What do you mean by "the underlying memory is still synchronously freed"?
A pointer is passed to memory_region_init_ram_ptr() with the ptr parameter when initializing the memory region and the memory region keeps the pointer.
In virtio_gpu_virgl_resource_unmap(), the memory pointed with the pointer is unmapped with virgl_renderer_resource_unmap() and makes the pointer kept by the memory region dangling though the lifetime of the memory region is extended with this patch. Can you show that the dangling pointer the memory region has will never be referenced?
Re: [QEMU PATCH v5 07/13] softmmu/memory: enable automatic deallocation of memory regions
Quoted 57 lines · Akihiko Odaki
Quoted 56 lines · Xenia Ragiadakou
Quoted 53 lines · Akihiko Odaki
Quoted 43 lines · Xenia Ragiadakou
Quoted 41 lines · Akihiko Odaki
Quoted 34 lines · Huang Rui
From: Xenia Ragiadakou <[email protected]>
When the memory region has a different life-cycle from that of her parent, could be automatically released, once has been unparent and once all of her references have gone away, via the object's free callback.
However, currently, references to the memory region are held by its owner without first incrementing the memory region object's reference count. As a result, the automatic deallocation of the object, not taking into account those references, results in use-after-free memory corruption.
This patch increases the reference count of an owned memory region object on each
memory_region_ref()and decreases it on eachmemory_region_unref().Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- ref/unref only owned memory regions (Akihiko)
softmmu/memory.c| 5 +++++1 file changed, 5 insertions(+)softmmu/memory.c +2
-0@@ -1800,6 +1800,9 @@ void memory_region_ref(MemoryRegion *mr) /* MMIO callbacks most likely will access data that belongs* to the owner, hence the need to ref/unref the owner whenever * the memory region is in use. +* Likewise, the owner keeps references to the memory region, +* hence the need to ref/unref the memory region object to Quoted 3 lines
prevent
+ * its automatic deallocation while still referenced by its owner.This comment does not make sense. Traditionally no such automatic deallocation happens so the owner has been always required to free the memory region when it gets finalized.
Quoted 7 lines
Quoted 1 line
"[QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands" introduces a different kind of memory region, which can be freed anytime before the device gets finalized. Even in this case, the owner removes the reference to the memory owner by doing
res->region= NULL;Hi Akihiko,
You are right, the word "owner" is not correct. The issue observed was due to the references kept in flatview ranges and the fact that
flatview_destroy()is asynchronous and was called after memory region's destruction.If I replace the word "owner" with "memory subsystem" in the commit message and drop the comment, would that be ok with you? or do want to suggest something else?
This will extend the lifetime of the memory region, but the underlying memory is still synchronously freed. Can you show that the flatview range will not be used to read the freed memory?
Quoted 8 lines
Quoted 4 lines
Yes, the intention of this patch is to delay the mr object finalization until all
memory_region_unref()on this mr have been taken place.What do you mean by "the underlying memory is still synchronously freed"?
A pointer is passed to
memory_region_init_ram_ptr()with the ptr parameter when initializing the memory region and the memory region keeps the pointer.In
virtio_gpu_virgl_resource_unmap(), the memory pointed with the pointer is unmapped withvirgl_renderer_resource_unmap()and makes the pointer kept by the memory region dangling though the lifetime of the memory region is extended with this patch. Can you show that the dangling pointer the memory region has will never be referenced?
I see your point but I think it is not directly related to this patch. IMHO, it is related to the implementation of virtio_gpu_virgl_resource_unmap(). Maybe the unmapping should be done in the free callback. However, I would expect the pointer to a disabled memory region to not be used, not sure though.
Re: [QEMU PATCH v5 07/13] softmmu/memory: enable automatic deallocation of memory regions
Quoted 61 lines · Xenia Ragiadakou
Quoted 59 lines · Akihiko Odaki
Quoted 58 lines · Xenia Ragiadakou
Quoted 46 lines · Akihiko Odaki
Quoted 45 lines · Xenia Ragiadakou
Quoted 42 lines · Akihiko Odaki
Quoted 34 lines · Huang Rui
From: Xenia Ragiadakou <[email protected]>
When the memory region has a different life-cycle from that of her parent, could be automatically released, once has been unparent and once all of her references have gone away, via the object's free callback.
However, currently, references to the memory region are held by its owner without first incrementing the memory region object's reference count. As a result, the automatic deallocation of the object, not taking into account those references, results in use-after-free memory corruption.
This patch increases the reference count of an owned memory region object on each
memory_region_ref()and decreases it on eachmemory_region_unref().Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- ref/unref only owned memory regions (Akihiko)
softmmu/memory.c| 5 +++++1 file changed, 5 insertions(+)softmmu/memory.c +2
-0@@ -1800,6 +1800,9 @@ void memory_region_ref(MemoryRegion *mr) /* MMIO callbacks most likely will access data that belongs* to the owner, hence the need to ref/unref the owner whenever * the memory region is in use. +* Likewise, the owner keeps references to the memory region, +* hence the need to ref/unref the memory region object to Quoted 3 lines
prevent
+ * its automatic deallocation while still referenced by its owner.This comment does not make sense. Traditionally no such automatic deallocation happens so the owner has been always required to free the memory region when it gets finalized.
"[QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands" introduces a different kind of memory region, which can be freed anytime before the device gets finalized. Even in this case, the owner removes the reference to the memory owner by doing
res->region= NULL;Quoted 7 lines
Quoted 5 lines
Hi Akihiko,
You are right, the word "owner" is not correct. The issue observed was due to the references kept in flatview ranges and the fact that
flatview_destroy()is asynchronous and was called after memory region's destruction.If I replace the word "owner" with "memory subsystem" in the commit message and drop the comment, would that be ok with you? or do want to suggest something else?
This will extend the lifetime of the memory region, but the underlying memory is still synchronously freed. Can you show that the flatview range will not be used to read the freed memory?
Yes, the intention of this patch is to delay the mr object finalization until all
memory_region_unref()on this mr have been taken place.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
What do you mean by "the underlying memory is still synchronously freed"?
A pointer is passed to
memory_region_init_ram_ptr()with the ptr parameter when initializing the memory region and the memory region keeps the pointer.In
virtio_gpu_virgl_resource_unmap(), the memory pointed with the pointer is unmapped withvirgl_renderer_resource_unmap()and makes the pointer kept by the memory region dangling though the lifetime of the memory region is extended with this patch. Can you show that the dangling pointer the memory region has will never be referenced?I see your point but I think it is not directly related to this patch. IMHO, it is related to the implementation of
virtio_gpu_virgl_resource_unmap(). Maybe the unmapping should be done in the free callback. However, I would expect the pointer to a disabled memory region to not be used, not sure though.
Unmapping in the free callback sounds good.
PATCH v5 8/13 virtio-gpu: Don't require udmabuf when blobs and virgl are enabled
In reply to Huang RuiFrom: Dmitry Osipenko <[email protected]>
The udmabuf usage is mandatory when virgl is disabled and blobs feature enabled in the Qemu machine configuration. If virgl and blobs are enabled, then udmabuf requirement is optional. Since udmabuf isn't widely supported by a popular Linux distros today, let's relax the udmabuf requirement for blobs=on,virgl=on. Now, a full-featured virtio-gpu acceleration is available to Qemu users without a need to have udmabuf available in the system.
--- hw/display/virtio-gpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/display/virtio-gpu.c +2 -1
@@ -1361,7 +1361,8 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)VirtIOGPU *g =VIRTIO_GPU (qdev);if (virtio_gpu_blob_enabled (g->parent_obj.conf)) { -if (!virtio_gpu_have_udmabuf ()) { +if (!virtio_gpu_virgl_enabled (g->parent_obj.conf) && + !virtio_gpu_have_udmabuf ()) {error_setg (errp,"cannot enable blob resources without udmabuf" );return ; }
Signature · 1 line
2.34.1
PATCH v5 9/13 virtio-gpu: Handle resource blob commands
In reply to Huang RuiFrom: Antonio Caggiano <[email protected]>
Support BLOB resources creation, mapping and unmapping by calling the new stable virglrenderer 0.10 interface. Only enabled when available and via the blob config. E.g. -device virtio-vga-gl,blob=true
---
V4 -> V5:
- Use memory_region_init_ram_ptr() instead of memory_region_init_ram_device_ptr() (Akihiko)
hw/display/virtio-gpu-virgl.c | 213 +++++++++++++++++++++++++++++++++ hw/display/virtio-gpu.c | 4 +- include/hw/virtio/virtio-gpu.h | 5 + meson.build | 4 + 4 files changed, 225 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-virgl.c +213 -0
@@ -17,6 +17,7 @@#include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-bswap.h" #include "ui/egl-helpers.h"
@@ -78,9 +79,24 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g,virgl_renderer_resource_create (&args,NULL ,0 ); } +static void virgl_resource_destroy (VirtIOGPU *g, +struct virtio_gpu_simple_resource *res) +{ +if (!res) +return ; + +QTAILQ_REMOVE (&g->reslist, res, next); + +virtio_gpu_cleanup_mapping_iov (g, res->iov, res->iov_cnt); +g_free (res->addrs); + +g_free (res); +} +static void virgl_cmd_resource_unref (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) { +struct virtio_gpu_simple_resource *res;struct virtio_gpu_resource_unref unref;struct iovec *res_iovs =NULL ;int num_iovs =0 ;
@@ -88,13 +104,22 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g,VIRTIO_GPU_FILL_CMD (unref);trace_virtio_gpu_cmd_res_unref (unref.resource_id); + res =virtio_gpu_find_resource (g, unref.resource_id); +virgl_renderer_resource_detach_iov (unref.resource_id, &res_iovs, &num_iovs);if (res_iovs !=NULL && num_iovs !=0 ) {virtio_gpu_cleanup_mapping_iov (g, res_iovs, num_iovs); +if (res) { + res->iov =NULL ; + res->iov_cnt =0 ; + } } +virgl_renderer_resource_unref (unref.resource_id); + +virgl_resource_destroy (g, res); } static void virgl_cmd_context_create(VirtIOGPU *g,
@@ -426,6 +451,183 @@ static void virgl_cmd_get_capset(VirtIOGPU *g,g_free (resp); } +#ifdef HAVE_VIRGL_RESOURCE_BLOB + +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; +struct virgl_renderer_resource_create_blob_args virgl_args = {0 }; +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); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + + res->resource_id = cblob.resource_id; + res->blob_size = cblob.size; + +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) { +g_free (res); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; +return ; + } + } + +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + + virgl_args.res_handle = cblob.resource_id; + virgl_args.ctx_id = cblob.hdr.ctx_id; + virgl_args.blob_mem = cblob.blob_mem; + virgl_args.blob_id = cblob.blob_id; + virgl_args.blob_flags = cblob.blob_flags; + virgl_args.size = cblob.size; + virgl_args.iovecs = res->iov; + virgl_args.num_iovs = res->iov_cnt; + + ret =virgl_renderer_resource_create_blob (&virgl_args); +if (ret) { +virgl_resource_destroy (g, res); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: virgl blob create error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; + } +} + +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; +struct virtio_gpu_resp_map_info resp; +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +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 ; + } +if (res->region) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already mapped %d\n" , + __func__, mblob.resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } + + ret =virgl_renderer_resource_map (res->resource_id, &data, &size); +if (ret) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource map error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } + + res->region =g_new0 (MemoryRegion,1 ); +if (!res->region) { +virgl_renderer_resource_unmap (res->resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } +memory_region_init_ram_ptr (res->region,OBJECT (g),NULL , size, data); +OBJECT (res->region)->free = g_free; +memory_region_add_subregion (&b->hostmem, mblob.offset, res->region); +memory_region_set_enabled (res->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 int virtio_gpu_virgl_resource_unmap (VirtIOGPU *g, +struct virtio_gpu_simple_resource + *res) +{ +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +if (!res) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already unmapped %d\n" , + __func__, res->resource_id); +return VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; + } + +memory_region_set_enabled (res->region, false); +memory_region_del_subregion (&b->hostmem, res->region); +object_unparent (OBJECT (res->region)); + res->region =NULL ; + +return virgl_renderer_resource_unmap (res->resource_id); +} + +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 ; + } + +virtio_gpu_virgl_resource_unmap (g, res); +} + +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ +void virtio_gpu_virgl_process_cmd (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) {
@@ -492,6 +694,17 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,case VIRTIO_GPU_CMD_GET_EDID :virtio_gpu_get_edid (g, cmd);break ; +#ifdef HAVE_VIRGL_RESOURCE_BLOB +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 ; +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ default : cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;break ;
hw/display/virtio-gpu.c +3 -1
@@ -1367,10 +1367,12 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)return ; } +#ifndef HAVE_VIRGL_RESOURCE_BLOB if (virtio_gpu_virgl_enabled (g->parent_obj.conf)) { -error_setg (errp,"blobs and virgl are not compatible (yet)" ); +error_setg (errp,"Linked virglrenderer does not support blob resources" );return ; } +#endif } if (!virtio_gpu_base_device_realize(qdev,
include/hw/virtio/virtio-gpu.h +5 -0
@@ -58,6 +58,11 @@ struct virtio_gpu_simple_resource {int dmabuf_fd;uint8_t *remapped; +#ifdef HAVE_VIRGL_RESOURCE_BLOB +/* only blob resource needs this region to be mapped as guest mmio */ +MemoryRegion *region; +#endif +QTAILQ_ENTRY (virtio_gpu_simple_resource) next; };
meson.build +4 -0
@@ -1072,6 +1072,10 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu cc.has_function('virgl_renderer_context_create_with_flags', prefix: '#include <virglrenderer.h>', dependencies: virgl)) + config_host_data.set('HAVE_VIRGL_RESOURCE_BLOB', + cc.has_function('virgl_renderer_resource_create_blob', + prefix: '#include <virglrenderer.h>', + dependencies: virgl)) endif blkio = not_found if not get_option('blkio').auto() or have_block
Signature · 1 line
2.34.1
Re: [QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands
Quoted 215 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Support BLOB resources creation, mapping and unmapping by calling the new stable virglrenderer 0.10 interface. Only enabled when available and via the blob config. E.g. -device virtio-vga-gl,blob=true
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Usememory_region_init_ram_ptr()instead ofmemory_region_init_ram_device_ptr()(Akihiko)hw/display/virtio-gpu-virgl.c | 213 +++++++++++++++++++++++++++++++++ hw/display/virtio-gpu.c | 4 +- include/hw/virtio/virtio-gpu.h | 5 + meson.build | 4 + 4 files changed, 225 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +154
-0@@ -17,6 +17,7 @@#include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-bswap.h" #include "ui/egl-helpers.h" @@ -78,9 +79,24 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g,virgl_renderer_resource_create (&args,NULL ,0 ); } +static void virgl_resource_destroy (VirtIOGPU *g, +struct virtio_gpu_simple_resource *res) +{ +if (!res) +return ; + +QTAILQ_REMOVE (&g->reslist, res, next); + +virtio_gpu_cleanup_mapping_iov (g, res->iov, res->iov_cnt); +g_free (res->addrs); + +g_free (res); +} +static void virgl_cmd_resource_unref (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) { +struct virtio_gpu_simple_resource *res;struct virtio_gpu_resource_unref unref;struct iovec *res_iovs =NULL ;int num_iovs =0 ;@@ -88,13 +104,22 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g,VIRTIO_GPU_FILL_CMD (unref);trace_virtio_gpu_cmd_res_unref (unref.resource_id); + res =virtio_gpu_find_resource (g, unref.resource_id); +virgl_renderer_resource_detach_iov (unref.resource_id, &res_iovs, &num_iovs);if (res_iovs !=NULL && num_iovs !=0 ) {virtio_gpu_cleanup_mapping_iov (g, res_iovs, num_iovs); +if (res) { + res->iov =NULL ; + res->iov_cnt =0 ; + } } +virgl_renderer_resource_unref (unref.resource_id); + +virgl_resource_destroy (g, res); } static void virgl_cmd_context_create(VirtIOGPU *g,@@ -426,6 +451,183 @@ static void virgl_cmd_get_capset(VirtIOGPU *g,g_free (resp); } +#ifdef HAVE_VIRGL_RESOURCE_BLOB + +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; +struct virgl_renderer_resource_create_blob_args virgl_args = {0 }; +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); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + + res->resource_id = cblob.resource_id; + res->blob_size = cblob.size; + +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) { +g_free (res); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; +return ; + } + } + +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + + virgl_args.res_handle = cblob.resource_id; + virgl_args.ctx_id = cblob.hdr.ctx_id; + virgl_args.blob_mem = cblob.blob_mem; + virgl_args.blob_id = cblob.blob_id; + virgl_args.blob_flags = cblob.blob_flags; + virgl_args.size = cblob.size; + virgl_args.iovecs = res->iov; + virgl_args.num_iovs = res->iov_cnt; + + ret =virgl_renderer_resource_create_blob (&virgl_args); +if (ret) { +virgl_resource_destroy (g, res); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: virgl blob create error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; + } +} + +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; +struct virtio_gpu_resp_map_info resp; +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +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 ; + } +if (res->region) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already mapped %d\n" , + __func__, mblob.resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } + + ret =virgl_renderer_resource_map (res->resource_id, &data, &size); +if (ret) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource map error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } + + res->region =g_new0 (MemoryRegion,1 ); +if (!res->region) { +virgl_renderer_resource_unmap (res->resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } +memory_region_init_ram_ptr (res->region,OBJECT (g),NULL , size, data); +OBJECT (res->region)->free = g_free; +memory_region_add_subregion (&b->hostmem, mblob.offset, res->region); +memory_region_set_enabled (res->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)); +} +
hw/display/virtio-gpu-virgl.c static void virgl_cmd_get_capset(VirtIOGPU *g, · line 592
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +10
-0+static int virtio_gpu_virgl_resource_unmap (VirtIOGPU *g, +struct virtio_gpu_simple_resource + *res) +{ +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +if (!res) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already unmapped %d\n" , + __func__, res->resource_id); +return VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ;
This returns enum virtio_gpu_ctrl_type while virgl_renderer_resource_unmap() returns -errno and the returned error code is ignored.
I think you can just inline this function into virgl_cmd_resource_unmap_blob(). It will be more concise and consistent with virgl_cmd_resource_map_blob().
Quoted 82 lines
hw/display/virtio-gpu-virgl.c +49
-0+ } + +memory_region_set_enabled (res->region, false); +memory_region_del_subregion (&b->hostmem, res->region); +object_unparent (OBJECT (res->region)); + res->region =NULL ; + +return virgl_renderer_resource_unmap (res->resource_id); +} + +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 ; + } + +virtio_gpu_virgl_resource_unmap (g, res); +} + +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ +void virtio_gpu_virgl_process_cmd (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) {@@ -492,6 +694,17 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,case VIRTIO_GPU_CMD_GET_EDID :virtio_gpu_get_edid (g, cmd);break ; +#ifdef HAVE_VIRGL_RESOURCE_BLOB +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 ; +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ default : cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;break ;hw/display/virtio-gpu.c +3
-1@@ -1367,10 +1367,12 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)return ; } +#ifndef HAVE_VIRGL_RESOURCE_BLOB if (virtio_gpu_virgl_enabled (g->parent_obj.conf)) { -error_setg (errp,"blobs and virgl are not compatible (yet)" ); +error_setg (errp,"Linked virglrenderer does not support blob resources" );return ; } +#endif } if (!virtio_gpu_base_device_realize(qdev,include/hw/virtio/virtio-gpu.h +0
-0
include/hw/virtio/virtio-gpu.h struct virtio_gpu_simple_resource { · line 65
Quoted 8 lines
include/hw/virtio/virtio-gpu.h +5
-0@@ -58,6 +58,11 @@ struct virtio_gpu_simple_resource {int dmabuf_fd;uint8_t *remapped; +#ifdef HAVE_VIRGL_RESOURCE_BLOB +/* only blob resource needs this region to be mapped as guest mmio */ +MemoryRegion *region; +#endif +
Since this is specific to virgl, let's create a struct that embeds virtio_gpu_simple_resource and use it to avoid modifying virtio-gpu common code.
Re: [QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands
Quoted 69 lines · Akihiko Odaki
Quoted 68 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Support BLOB resources creation, mapping and unmapping by calling the new stable virglrenderer 0.10 interface. Only enabled when available and via the blob config. E.g. -device virtio-vga-gl,blob=true
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Usememory_region_init_ram_ptr()instead ofmemory_region_init_ram_device_ptr()(Akihiko)hw/display/virtio-gpu-virgl.c | 213 +++++++++++++++++++++++++++++++++ hw/display/virtio-gpu.c | 4 +-
include/hw/virtio/virtio-gpu.h| 5 +
meson.build | 4 +4 files changed, 225 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +19
-0@@ -17,6 +17,7 @@ #include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-bswap.h" #include "ui/egl-helpers.h"@@ -78,9 +79,24 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, virgl_renderer_resource_create(&args, NULL, 0); } +static void virgl_resource_destroy (VirtIOGPU *g, + struct virtio_gpu_simple_resource *res) +{ + if (!res) + return; + + QTAILQ_REMOVE(&g->reslist, res, next); + + virtio_gpu_cleanup_mapping_iov(g, res->iov, res->iov_cnt); + g_free(res->addrs); + + g_free(res); +} + static void virgl_cmd_resource_unref(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { + struct virtio_gpu_simple_resource *res; struct virtio_gpu_resource_unref unref; struct iovec *res_iovs = NULL; int num_iovs = 0;@@ -88,13 +104,22 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g, VIRTIO_GPU_FILL_CMD(unref); trace_virtio_gpu_cmd_res_unref(unref.resource_id); + res = virtio_gpu_find_resource(g, unref.resource_id); + virgl_renderer_resource_detach_iov(unref.resource_id, &res_iovs, &num_iovs); if (res_iovs != NULL && num_iovs != 0) { virtio_gpu_cleanup_mapping_iov(g, res_iovs, num_iovs); + if (res) {
Quoted 8 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_resource_unref(VirtIOGPU *g, · line 122
Quoted 8 lines
hw/display/virtio-gpu-virgl.c +6
-0+ res->iov = NULL; + res->iov_cnt = 0; + } } + virgl_renderer_resource_unref(unref.resource_id); + + virgl_resource_destroy(g, res);
This may leak memory region.
Re: [QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands
Quoted 74 lines · Akihiko Odaki
Quoted 73 lines · Akihiko Odaki
Quoted 72 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Support BLOB resources creation, mapping and unmapping by calling the new stable virglrenderer 0.10 interface. Only enabled when available and via the blob config. E.g. -device virtio-vga-gl,blob=true
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Usememory_region_init_ram_ptr()instead ofmemory_region_init_ram_device_ptr()(Akihiko)hw/display/virtio-gpu-virgl.c | 213 +++++++++++++++++++++++++++++++++ hw/display/virtio-gpu.c | 4 +-
include/hw/virtio/virtio-gpu.h| 5 +
meson.build | 4 +4 files changed, 225 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +15
-0@@ -17,6 +17,7 @@ #include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-bswap.h" #include "ui/egl-helpers.h"@@ -78,9 +79,24 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, virgl_renderer_resource_create(&args, NULL, 0); } +static void virgl_resource_destroy (VirtIOGPU *g, + struct virtio_gpu_simple_resource *res) +{ + if (!res) + return; + + QTAILQ_REMOVE(&g->reslist, res, next); + + virtio_gpu_cleanup_mapping_iov(g, res->iov, res->iov_cnt); + g_free(res->addrs); + + g_free(res); +} + static void virgl_cmd_resource_unref(VirtIOGPU *g,struct
virtio_gpu_ctrl_command*cmd)
{
+ structvirtio_gpu_simple_resource*res;
structvirtio_gpu_resource_unrefunref;
struct iovec*res_iovs= NULL;
intnum_iovs= 0;hw/display/virtio-gpu-virgl.c +5
-0@@ -88,13 +104,22 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g, VIRTIO_GPU_FILL_CMD(unref); trace_virtio_gpu_cmd_res_unref(unref.resource_id); + res = virtio_gpu_find_resource(g, unref.resource_id); + virgl_renderer_resource_detach_iov(unref.resource_id, &res_iovs, &num_iovs); if (res_iovs != NULL && num_iovs != 0) { virtio_gpu_cleanup_mapping_iov(g, res_iovs, num_iovs); + if (res) { + res->iov = NULL; + res->iov_cnt = 0;
Quoted 8 lines
Quoted 6 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_resource_unref(VirtIOGPU *g, · line 122
Quoted 6 lines
hw/display/virtio-gpu-virgl.c +4
-0+ } } + virgl_renderer_resource_unref(unref.resource_id); + + virgl_resource_destroy(g, res);This may leak memory region.
The memory region should be freed under virgl_cmd_resource_unmap_blob() which is calling memory_region_del_subregion(&b->hostmem, res->region). Because this region is created by map_blob(). Do we have the case to call virgl_cmd_resource_unref() without calling virgl_cmd_resource_unmap_blob() for blob memory?
Thanks,
Ray
Re: [QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands
Quoted 84 lines · Huang Rui
Quoted 74 lines · Akihiko Odaki
Quoted 73 lines · Akihiko Odaki
Quoted 72 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Support BLOB resources creation, mapping and unmapping by calling the new stable virglrenderer 0.10 interface. Only enabled when available and via the blob config. E.g. -device virtio-vga-gl,blob=true
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Usememory_region_init_ram_ptr()instead ofmemory_region_init_ram_device_ptr()(Akihiko)hw/display/virtio-gpu-virgl.c | 213 +++++++++++++++++++++++++++++++++ hw/display/virtio-gpu.c | 4 +- include/hw/virtio/virtio-gpu.h | 5 + meson.build | 4 + 4 files changed, 225 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +16
-0@@ -17,6 +17,7 @@ #include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-bswap.h" #include "ui/egl-helpers.h"@@ -78,9 +79,24 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, virgl_renderer_resource_create(&args, NULL, 0); } +static void virgl_resource_destroy (VirtIOGPU *g, + struct virtio_gpu_simple_resource *res) +{ + if (!res) + return; + + QTAILQ_REMOVE(&g->reslist, res, next); + + virtio_gpu_cleanup_mapping_iov(g, res->iov, res->iov_cnt); + g_free(res->addrs); + + g_free(res); +} + static void virgl_cmd_resource_unref(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { + struct virtio_gpu_simple_resource *res; struct virtio_gpu_resource_unref unref; struct iovec *res_iovs = NULL;int
num_iovs= 0;hw/display/virtio-gpu-virgl.c +5
-0@@ -88,13 +104,22 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g, VIRTIO_GPU_FILL_CMD(unref); trace_virtio_gpu_cmd_res_unref(unref.resource_id); + res = virtio_gpu_find_resource(g, unref.resource_id); + virgl_renderer_resource_detach_iov(unref.resource_id, &res_iovs, &num_iovs); if (res_iovs != NULL && num_iovs != 0) { virtio_gpu_cleanup_mapping_iov(g, res_iovs, num_iovs); + if (res) { + res->iov = NULL; + res->iov_cnt = 0;Quoted 8 lines
Quoted 6 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_resource_unref(VirtIOGPU *g, · line 122
Quoted 6 lines
hw/display/virtio-gpu-virgl.c +4
-0+ } } + virgl_renderer_resource_unref(unref.resource_id); + + virgl_resource_destroy(g, res);This may leak memory region.
Quoted 5 lines
The memory region should be freed under
virgl_cmd_resource_unmap_blob()which is callingmemory_region_del_subregion(&b->hostmem, res->region). Because this region is created bymap_blob(). Do we have the case to callvirgl_cmd_resource_unref()without callingvirgl_cmd_resource_unmap_blob()for blob memory?
Calling virgl_cmd_resource_unmap_blob() and virgl_cmd_resource_unref() in order is a guest's responsibility, and we are required to prepare for broken guests.
Re: [QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands
Quoted 91 lines · Akihiko Odaki
Quoted 84 lines · Huang Rui
Quoted 74 lines · Akihiko Odaki
Quoted 73 lines · Akihiko Odaki
Quoted 72 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Support BLOB resources creation, mapping and unmapping by calling the new stable virglrenderer 0.10 interface. Only enabled when available and via the blob config. E.g. -device virtio-vga-gl,blob=true
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Usememory_region_init_ram_ptr()instead ofmemory_region_init_ram_device_ptr()(Akihiko)hw/display/virtio-gpu-virgl.c | 213 +++++++++++++++++++++++++++++++++ hw/display/virtio-gpu.c | 4 +- include/hw/virtio/virtio-gpu.h | 5 + meson.build | 4 + 4 files changed, 225 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +16
-0@@ -17,6 +17,7 @@ #include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-bswap.h" #include "ui/egl-helpers.h"@@ -78,9 +79,24 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, virgl_renderer_resource_create(&args, NULL, 0); } +static void virgl_resource_destroy (VirtIOGPU *g, + struct virtio_gpu_simple_resource *res) +{ + if (!res) + return; + + QTAILQ_REMOVE(&g->reslist, res, next); + + virtio_gpu_cleanup_mapping_iov(g, res->iov, res->iov_cnt); + g_free(res->addrs); + + g_free(res); +} + static void virgl_cmd_resource_unref(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { + struct virtio_gpu_simple_resource *res; struct virtio_gpu_resource_unref unref; struct iovec *res_iovs = NULL;int
num_iovs= 0;hw/display/virtio-gpu-virgl.c +5
-0@@ -88,13 +104,22 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g, VIRTIO_GPU_FILL_CMD(unref); trace_virtio_gpu_cmd_res_unref(unref.resource_id); + res = virtio_gpu_find_resource(g, unref.resource_id); + virgl_renderer_resource_detach_iov(unref.resource_id, &res_iovs, &num_iovs); if (res_iovs != NULL && num_iovs != 0) { virtio_gpu_cleanup_mapping_iov(g, res_iovs, num_iovs); + if (res) { + res->iov = NULL; + res->iov_cnt = 0;Quoted 8 lines
Quoted 6 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_resource_unref(VirtIOGPU *g, · line 122
Quoted 6 lines
hw/display/virtio-gpu-virgl.c +4
-0+ } } + virgl_renderer_resource_unref(unref.resource_id); + + virgl_resource_destroy(g, res);This may leak memory region.
Quoted 5 lines
The memory region should be freed under
virgl_cmd_resource_unmap_blob()which is callingmemory_region_del_subregion(&b->hostmem, res->region). Because this region is created bymap_blob(). Do we have the case to callvirgl_cmd_resource_unref()without callingvirgl_cmd_resource_unmap_blob()for blob memory?
Quoted 3 lines
Calling
virgl_cmd_resource_unmap_blob()andvirgl_cmd_resource_unref()in order is a guest's responsibility, and we are required to prepare for broken guests.
OK, no problem. I will update this in V6.
Thanks,
Ray
Re: [QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands
In reply to Akihiko OdakiQuoted 231 lines · Akihiko Odaki
Quoted 215 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Support BLOB resources creation, mapping and unmapping by calling the new stable virglrenderer 0.10 interface. Only enabled when available and via the blob config. E.g. -device virtio-vga-gl,blob=true
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Usememory_region_init_ram_ptr()instead ofmemory_region_init_ram_device_ptr()(Akihiko)hw/display/virtio-gpu-virgl.c | 213 +++++++++++++++++++++++++++++++++ hw/display/virtio-gpu.c | 4 +- include/hw/virtio/virtio-gpu.h | 5 + meson.build | 4 + 4 files changed, 225 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +154
-0@@ -17,6 +17,7 @@#include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-bswap.h" #include "ui/egl-helpers.h" @@ -78,9 +79,24 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g,virgl_renderer_resource_create (&args,NULL ,0 ); } +static void virgl_resource_destroy (VirtIOGPU *g, +struct virtio_gpu_simple_resource *res) +{ +if (!res) +return ; + +QTAILQ_REMOVE (&g->reslist, res, next); + +virtio_gpu_cleanup_mapping_iov (g, res->iov, res->iov_cnt); +g_free (res->addrs); + +g_free (res); +} +static void virgl_cmd_resource_unref (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) { +struct virtio_gpu_simple_resource *res;struct virtio_gpu_resource_unref unref;struct iovec *res_iovs =NULL ;int num_iovs =0 ;@@ -88,13 +104,22 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g,VIRTIO_GPU_FILL_CMD (unref);trace_virtio_gpu_cmd_res_unref (unref.resource_id); + res =virtio_gpu_find_resource (g, unref.resource_id); +virgl_renderer_resource_detach_iov (unref.resource_id, &res_iovs, &num_iovs);if (res_iovs !=NULL && num_iovs !=0 ) {virtio_gpu_cleanup_mapping_iov (g, res_iovs, num_iovs); +if (res) { + res->iov =NULL ; + res->iov_cnt =0 ; + } } +virgl_renderer_resource_unref (unref.resource_id); + +virgl_resource_destroy (g, res); } static void virgl_cmd_context_create(VirtIOGPU *g,@@ -426,6 +451,183 @@ static void virgl_cmd_get_capset(VirtIOGPU *g,g_free (resp); } +#ifdef HAVE_VIRGL_RESOURCE_BLOB + +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; +struct virgl_renderer_resource_create_blob_args virgl_args = {0 }; +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); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + + res->resource_id = cblob.resource_id; + res->blob_size = cblob.size; + +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) { +g_free (res); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; +return ; + } + } + +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + + virgl_args.res_handle = cblob.resource_id; + virgl_args.ctx_id = cblob.hdr.ctx_id; + virgl_args.blob_mem = cblob.blob_mem; + virgl_args.blob_id = cblob.blob_id; + virgl_args.blob_flags = cblob.blob_flags; + virgl_args.size = cblob.size; + virgl_args.iovecs = res->iov; + virgl_args.num_iovs = res->iov_cnt; + + ret =virgl_renderer_resource_create_blob (&virgl_args); +if (ret) { +virgl_resource_destroy (g, res); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: virgl blob create error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; + } +} + +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; +struct virtio_gpu_resp_map_info resp; +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +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 ; + } +if (res->region) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already mapped %d\n" , + __func__, mblob.resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } + + ret =virgl_renderer_resource_map (res->resource_id, &data, &size); +if (ret) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource map error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } + + res->region =g_new0 (MemoryRegion,1 ); +if (!res->region) { +virgl_renderer_resource_unmap (res->resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } +memory_region_init_ram_ptr (res->region,OBJECT (g),NULL , size, data); +OBJECT (res->region)->free = g_free; +memory_region_add_subregion (&b->hostmem, mblob.offset, res->region); +memory_region_set_enabled (res->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)); +} +hw/display/virtio-gpu-virgl.c static void virgl_cmd_get_capset(VirtIOGPU *g, · line 592
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +10
-0+static int virtio_gpu_virgl_resource_unmap (VirtIOGPU *g, +struct virtio_gpu_simple_resource + *res) +{ +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +if (!res) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already unmapped %d\n" , + __func__, res->resource_id); +return VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ;This returns enum
virtio_gpu_ctrl_typewhilevirgl_renderer_resource_unmap()returns -errno and the returned error code is ignored.
Quoted 3 lines
I think you can just inline this function into
virgl_cmd_resource_unmap_blob(). It will be more concise and consistent withvirgl_cmd_resource_map_blob().
OK, will update in V2.
Quoted 86 lines
Quoted 86 lines
hw/display/virtio-gpu-virgl.c +49
-0+ } + +memory_region_set_enabled (res->region, false); +memory_region_del_subregion (&b->hostmem, res->region); +object_unparent (OBJECT (res->region)); + res->region =NULL ; + +return virgl_renderer_resource_unmap (res->resource_id); +} + +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 ; + } + +virtio_gpu_virgl_resource_unmap (g, res); +} + +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ +void virtio_gpu_virgl_process_cmd (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) {@@ -492,6 +694,17 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,case VIRTIO_GPU_CMD_GET_EDID :virtio_gpu_get_edid (g, cmd);break ; +#ifdef HAVE_VIRGL_RESOURCE_BLOB +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 ; +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ default : cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;break ;hw/display/virtio-gpu.c +3
-1@@ -1367,10 +1367,12 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)return ; } +#ifndef HAVE_VIRGL_RESOURCE_BLOB if (virtio_gpu_virgl_enabled (g->parent_obj.conf)) { -error_setg (errp,"blobs and virgl are not compatible (yet)" ); +error_setg (errp,"Linked virglrenderer does not support blob resources" );return ; } +#endif } if (!virtio_gpu_base_device_realize(qdev,include/hw/virtio/virtio-gpu.h +0
-0@@ -58,6 +58,11 @@ struct virtio_gpu_simple_resource {int dmabuf_fd;uint8_t *remapped;
Quoted 9 lines
include/hw/virtio/virtio-gpu.h struct virtio_gpu_simple_resource { · line 65
Quoted 5 lines
include/hw/virtio/virtio-gpu.h +5
-0+#ifdef HAVE_VIRGL_RESOURCE_BLOB +/* only blob resource needs this region to be mapped as guest mmio */ +MemoryRegion *region; +#endif +Since this is specific to virgl, let's create a struct that embeds
virtio_gpu_simple_resourceand use it to avoid modifying virtio-gpu common code.
I am thinking should I modify the whole virtio-gpu-virgl.c to use the new struct like virgl_gpu_resource which has virtio_gpu_simple_resource embedded? Then in virgl, we can use this structure to indicate the resource for virglrenderer.
Thanks,
Ray
Re: [QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands
Quoted 334 lines · Huang Rui
Quoted 231 lines · Akihiko Odaki
Quoted 215 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Support BLOB resources creation, mapping and unmapping by calling the new stable virglrenderer 0.10 interface. Only enabled when available and via the blob config. E.g. -device virtio-vga-gl,blob=true
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Usememory_region_init_ram_ptr()instead ofmemory_region_init_ram_device_ptr()(Akihiko)hw/display/virtio-gpu-virgl.c | 213 +++++++++++++++++++++++++++++++++ hw/display/virtio-gpu.c | 4 +- include/hw/virtio/virtio-gpu.h | 5 + meson.build | 4 + 4 files changed, 225 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +154
-0@@ -17,6 +17,7 @@#include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-bswap.h" #include "ui/egl-helpers.h" @@ -78,9 +79,24 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g,virgl_renderer_resource_create (&args,NULL ,0 ); } +static void virgl_resource_destroy (VirtIOGPU *g, +struct virtio_gpu_simple_resource *res) +{ +if (!res) +return ; + +QTAILQ_REMOVE (&g->reslist, res, next); + +virtio_gpu_cleanup_mapping_iov (g, res->iov, res->iov_cnt); +g_free (res->addrs); + +g_free (res); +} +static void virgl_cmd_resource_unref (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) { +struct virtio_gpu_simple_resource *res;struct virtio_gpu_resource_unref unref;struct iovec *res_iovs =NULL ;int num_iovs =0 ;@@ -88,13 +104,22 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g,VIRTIO_GPU_FILL_CMD (unref);trace_virtio_gpu_cmd_res_unref (unref.resource_id); + res =virtio_gpu_find_resource (g, unref.resource_id); +virgl_renderer_resource_detach_iov (unref.resource_id, &res_iovs, &num_iovs);if (res_iovs !=NULL && num_iovs !=0 ) {virtio_gpu_cleanup_mapping_iov (g, res_iovs, num_iovs); +if (res) { + res->iov =NULL ; + res->iov_cnt =0 ; + } } +virgl_renderer_resource_unref (unref.resource_id); + +virgl_resource_destroy (g, res); } static void virgl_cmd_context_create(VirtIOGPU *g,@@ -426,6 +451,183 @@ static void virgl_cmd_get_capset(VirtIOGPU *g,g_free (resp); } +#ifdef HAVE_VIRGL_RESOURCE_BLOB + +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; +struct virgl_renderer_resource_create_blob_args virgl_args = {0 }; +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); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + + res->resource_id = cblob.resource_id; + res->blob_size = cblob.size; + +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) { +g_free (res); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; +return ; + } + } + +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + + virgl_args.res_handle = cblob.resource_id; + virgl_args.ctx_id = cblob.hdr.ctx_id; + virgl_args.blob_mem = cblob.blob_mem; + virgl_args.blob_id = cblob.blob_id; + virgl_args.blob_flags = cblob.blob_flags; + virgl_args.size = cblob.size; + virgl_args.iovecs = res->iov; + virgl_args.num_iovs = res->iov_cnt; + + ret =virgl_renderer_resource_create_blob (&virgl_args); +if (ret) { +virgl_resource_destroy (g, res); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: virgl blob create error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; + } +} + +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; +struct virtio_gpu_resp_map_info resp; +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +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 ; + } +if (res->region) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already mapped %d\n" , + __func__, mblob.resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } + + ret =virgl_renderer_resource_map (res->resource_id, &data, &size); +if (ret) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource map error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } + + res->region =g_new0 (MemoryRegion,1 ); +if (!res->region) { +virgl_renderer_resource_unmap (res->resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } +memory_region_init_ram_ptr (res->region,OBJECT (g),NULL , size, data); +OBJECT (res->region)->free = g_free; +memory_region_add_subregion (&b->hostmem, mblob.offset, res->region); +memory_region_set_enabled (res->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)); +} +hw/display/virtio-gpu-virgl.c static void virgl_cmd_get_capset(VirtIOGPU *g, · line 592
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +10
-0+static int virtio_gpu_virgl_resource_unmap (VirtIOGPU *g, +struct virtio_gpu_simple_resource + *res) +{ +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +if (!res) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already unmapped %d\n" , + __func__, res->resource_id); +return VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ;This returns enum
virtio_gpu_ctrl_typewhilevirgl_renderer_resource_unmap()returns -errno and the returned error code is ignored.Quoted 3 lines
I think you can just inline this function into
virgl_cmd_resource_unmap_blob(). It will be more concise and consistent withvirgl_cmd_resource_map_blob().OK, will update in V2.
Quoted 86 lines
Quoted 86 lines
hw/display/virtio-gpu-virgl.c +49
-0+ } + +memory_region_set_enabled (res->region, false); +memory_region_del_subregion (&b->hostmem, res->region); +object_unparent (OBJECT (res->region)); + res->region =NULL ; + +return virgl_renderer_resource_unmap (res->resource_id); +} + +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 ; + } + +virtio_gpu_virgl_resource_unmap (g, res); +} + +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ +void virtio_gpu_virgl_process_cmd (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) {@@ -492,6 +694,17 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,case VIRTIO_GPU_CMD_GET_EDID :virtio_gpu_get_edid (g, cmd);break ; +#ifdef HAVE_VIRGL_RESOURCE_BLOB +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 ; +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ default : cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;break ;hw/display/virtio-gpu.c +3
-1@@ -1367,10 +1367,12 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)return ; } +#ifndef HAVE_VIRGL_RESOURCE_BLOB if (virtio_gpu_virgl_enabled (g->parent_obj.conf)) { -error_setg (errp,"blobs and virgl are not compatible (yet)" ); +error_setg (errp,"Linked virglrenderer does not support blob resources" );return ; } +#endif } if (!virtio_gpu_base_device_realize(qdev,include/hw/virtio/virtio-gpu.h +0
-0@@ -58,6 +58,11 @@ struct virtio_gpu_simple_resource {int dmabuf_fd;uint8_t *remapped;Quoted 9 lines
include/hw/virtio/virtio-gpu.h struct virtio_gpu_simple_resource { · line 65
Quoted 5 lines
include/hw/virtio/virtio-gpu.h +5
-0+#ifdef HAVE_VIRGL_RESOURCE_BLOB +/* only blob resource needs this region to be mapped as guest mmio */ +MemoryRegion *region; +#endif +Since this is specific to virgl, let's create a struct that embeds
virtio_gpu_simple_resourceand use it to avoid modifying virtio-gpu common code.
Quoted 4 lines
I am thinking should I modify the whole
virtio-gpu-virgl.cto use the new struct likevirgl_gpu_resourcewhich hasvirtio_gpu_simple_resourceembedded? Then in virgl, we can use this structure to indicate the resource for virglrenderer.
Yes, that's what I suggest.
Re: [QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands
In reply to Huang RuiHi
Quoted 36 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Support BLOB resources creation, mapping and unmapping by calling the new stable virglrenderer 0.10 interface. Only enabled when available and via the blob config. E.g. -device virtio-vga-gl,blob=true
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Usememory_region_init_ram_ptr()instead ofmemory_region_init_ram_device_ptr()(Akihiko)hw/display/virtio-gpu-virgl.c | 213 +++++++++++++++++++++++++++++++++ hw/display/virtio-gpu.c | 4 +- include/hw/virtio/virtio-gpu.h | 5 + meson.build | 4 + 4 files changed, 225 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +1
-0@@ -17,6 +17,7 @@#include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-bswap.h" #include "ui/egl-helpers.h"
hw/display/virtio-gpu-virgl.c static void virgl_cmd_create_resource_3d(VirtIOGPU *g, · line 87
Quoted 9 lines
hw/display/virtio-gpu-virgl.c +6
-0@@ -78,9 +79,24 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g,virgl_renderer_resource_create (&args,NULL ,0 ); } +static void virgl_resource_destroy (VirtIOGPU *g, +struct virtio_gpu_simple_resource *res) +{ +if (!res) +return ; +
QEMU coding style imposes braces
hw/display/virtio-gpu-virgl.c static void virgl_cmd_create_resource_3d(VirtIOGPU *g, · line 93
Quoted 6 lines
hw/display/virtio-gpu-virgl.c +6
-0+QTAILQ_REMOVE (&g->reslist, res, next); + +virtio_gpu_cleanup_mapping_iov (g, res->iov, res->iov_cnt); +g_free (res->addrs); + +g_free (res);
If you embed virtio_gpu_simple_resource in a new struct, we should instead call the existing virtio_gpu_resource_destroy() I guess.
Quoted 59 lines
hw/display/virtio-gpu-virgl.c +35
-0+} +static void virgl_cmd_resource_unref (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) { +struct virtio_gpu_simple_resource *res;struct virtio_gpu_resource_unref unref;struct iovec *res_iovs =NULL ;int num_iovs =0 ;@@ -88,13 +104,22 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g,VIRTIO_GPU_FILL_CMD (unref);trace_virtio_gpu_cmd_res_unref (unref.resource_id); + res =virtio_gpu_find_resource (g, unref.resource_id); +virgl_renderer_resource_detach_iov (unref.resource_id, &res_iovs, &num_iovs);if (res_iovs !=NULL && num_iovs !=0 ) {virtio_gpu_cleanup_mapping_iov (g, res_iovs, num_iovs); +if (res) { + res->iov =NULL ; + res->iov_cnt =0 ; + } } +virgl_renderer_resource_unref (unref.resource_id); + +virgl_resource_destroy (g, res); } static void virgl_cmd_context_create(VirtIOGPU *g,@@ -426,6 +451,183 @@ static void virgl_cmd_get_capset(VirtIOGPU *g,g_free (resp); } +#ifdef HAVE_VIRGL_RESOURCE_BLOB + +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; +struct virgl_renderer_resource_create_blob_args virgl_args = {0 }; +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) {
hw/display/virtio-gpu-virgl.c static void virgl_cmd_get_capset(VirtIOGPU *g, · line 486
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +10
-0+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); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ;
needless error handling, glib will abort() on OOM.
Quoted 71 lines
hw/display/virtio-gpu-virgl.c +71
-0+ } + + res->resource_id = cblob.resource_id; + res->blob_size = cblob.size; + +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) { +g_free (res); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; +return ; + } + } + +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + + virgl_args.res_handle = cblob.resource_id; + virgl_args.ctx_id = cblob.hdr.ctx_id; + virgl_args.blob_mem = cblob.blob_mem; + virgl_args.blob_id = cblob.blob_id; + virgl_args.blob_flags = cblob.blob_flags; + virgl_args.size = cblob.size; + virgl_args.iovecs = res->iov; + virgl_args.num_iovs = res->iov_cnt; + + ret =virgl_renderer_resource_create_blob (&virgl_args); +if (ret) { +virgl_resource_destroy (g, res); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: virgl blob create error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; + } +} + +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; +struct virtio_gpu_resp_map_info resp; +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +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 ; + } +if (res->region) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already mapped %d\n" , + __func__, mblob.resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } +
hw/display/virtio-gpu-virgl.c static void virgl_cmd_get_capset(VirtIOGPU *g, · line 567
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +10
-0+ ret =virgl_renderer_resource_map (res->resource_id, &data, &size); +if (ret) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource map error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } + + res->region =g_new0 (MemoryRegion,1 ); +if (!res->region) {
no need for OOM handling here too
Quoted 123 lines
hw/display/virtio-gpu-virgl.c +74
-0+virgl_renderer_resource_unmap (res->resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; + return; + } +memory_region_init_ram_ptr (res->region,OBJECT (g),NULL , size, data); +OBJECT (res->region)->free = g_free; +memory_region_add_subregion (&b->hostmem, mblob.offset, res->region); +memory_region_set_enabled (res->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 int virtio_gpu_virgl_resource_unmap (VirtIOGPU *g, +struct virtio_gpu_simple_resource + *res) +{ +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +if (!res) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already unmapped %d\n" , + __func__, res->resource_id); +return VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; + } + +memory_region_set_enabled (res->region, false); +memory_region_del_subregion (&b->hostmem, res->region); +object_unparent (OBJECT (res->region)); + res->region =NULL ; + +return virgl_renderer_resource_unmap (res->resource_id); +} + +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 ; + } + +virtio_gpu_virgl_resource_unmap (g, res); +} + +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ +void virtio_gpu_virgl_process_cmd (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) {@@ -492,6 +694,17 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,case VIRTIO_GPU_CMD_GET_EDID :virtio_gpu_get_edid (g, cmd);break ; +#ifdef HAVE_VIRGL_RESOURCE_BLOB +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 ; +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ default : cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;break ;hw/display/virtio-gpu.c +3
-1@@ -1367,10 +1367,12 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)return ; } +#ifndef HAVE_VIRGL_RESOURCE_BLOB if (virtio_gpu_virgl_enabled (g->parent_obj.conf)) { -error_setg (errp,"blobs and virgl are not compatible (yet)" ); +error_setg (errp,"Linked virglrenderer does not support blob resources" );return ; } +#endif } if (!virtio_gpu_base_device_realize(qdev,include/hw/virtio/virtio-gpu.h +5
-0@@ -58,6 +58,11 @@ struct virtio_gpu_simple_resource {int dmabuf_fd;uint8_t *remapped; +#ifdef HAVE_VIRGL_RESOURCE_BLOB +/* only blob resource needs this region to be mapped as guest mmio */ +MemoryRegion *region; +#endif +QTAILQ_ENTRY (virtio_gpu_simple_resource) next; };meson.build +0
-0
meson.build if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu · line 1078
Quoted 7 lines
meson.build +4
-0@@ -1072,6 +1072,10 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu cc.has_function('virgl_renderer_context_create_with_flags', prefix: '#include <virglrenderer.h>', dependencies: virgl)) + config_host_data.set('HAVE_VIRGL_RESOURCE_BLOB', + cc.has_function('virgl_renderer_resource_create_blob', + prefix: '#include <virglrenderer.h>', + dependencies: virgl))
better moved under the if virgl.found() block
Quoted 7 lines
meson.build +0
-1endif blkio = not_found if not get_option('blkio').auto() or have_block --2.34.1
Signature · 1 line
Marc-André Lureau
Re: [QEMU PATCH v5 09/13] virtio-gpu: Handle resource blob commands
Quoted 42 lines · Marc-André Lureau
Hi
Quoted 39 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Support BLOB resources creation, mapping and unmapping by calling the new stable virglrenderer 0.10 interface. Only enabled when available and via the blob config. E.g. -device virtio-vga-gl,blob=true
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Dmitry Osipenko <[email protected]>Signed-off-by Xenia Ragiadakou <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Usememory_region_init_ram_ptr()instead ofmemory_region_init_ram_device_ptr()(Akihiko)hw/display/virtio-gpu-virgl.c | 213 +++++++++++++++++++++++++++++++++ hw/display/virtio-gpu.c | 4 +- include/hw/virtio/virtio-gpu.h | 5 + meson.build | 4 + 4 files changed, 225 insertions(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +1
-0@@ -17,6 +17,7 @@#include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-bswap.h" #include "ui/egl-helpers.h" @@ -78,9 +79,24 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g,virgl_renderer_resource_create (&args,NULL ,0 ); }
Quoted 9 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_create_resource_3d(VirtIOGPU *g, · line 87
Quoted 6 lines
hw/display/virtio-gpu-virgl.c +6
-0+static void virgl_resource_destroy (VirtIOGPU *g, +struct virtio_gpu_simple_resource *res) +{ +if (!res) +return ; +QEMU coding style imposes braces
Thanks for reminder.
Quoted 9 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_create_resource_3d(VirtIOGPU *g, · line 93
Quoted 6 lines
hw/display/virtio-gpu-virgl.c +6
-0+QTAILQ_REMOVE (&g->reslist, res, next); + +virtio_gpu_cleanup_mapping_iov (g, res->iov, res->iov_cnt); +g_free (res->addrs); + +g_free (res);If you embed
virtio_gpu_simple_resourcein a new struct, we should instead call the existingvirtio_gpu_resource_destroy()I guess.
Yes, but I didn't call virtio_gpu_resource_destroy() here, I am using the virgl_resource_destroy() and the input should be the virgl resource in next version. May I know whether I miss understood your point?
Quoted 64 lines
Quoted 64 lines
hw/display/virtio-gpu-virgl.c +39
-0+} +static void virgl_cmd_resource_unref (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) { +struct virtio_gpu_simple_resource *res;struct virtio_gpu_resource_unref unref;struct iovec *res_iovs =NULL ;int num_iovs =0 ;@@ -88,13 +104,22 @@ static void virgl_cmd_resource_unref(VirtIOGPU *g,VIRTIO_GPU_FILL_CMD (unref);trace_virtio_gpu_cmd_res_unref (unref.resource_id); + res =virtio_gpu_find_resource (g, unref.resource_id); +virgl_renderer_resource_detach_iov (unref.resource_id, &res_iovs, &num_iovs);if (res_iovs !=NULL && num_iovs !=0 ) {virtio_gpu_cleanup_mapping_iov (g, res_iovs, num_iovs); +if (res) { + res->iov =NULL ; + res->iov_cnt =0 ; + } } +virgl_renderer_resource_unref (unref.resource_id); + +virgl_resource_destroy (g, res); } static void virgl_cmd_context_create(VirtIOGPU *g,@@ -426,6 +451,183 @@ static void virgl_cmd_get_capset(VirtIOGPU *g,g_free (resp); } +#ifdef HAVE_VIRGL_RESOURCE_BLOB + +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; +struct virgl_renderer_resource_create_blob_args virgl_args = {0 }; +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 ;
Quoted 8 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_get_capset(VirtIOGPU *g, · line 486
Quoted 6 lines
hw/display/virtio-gpu-virgl.c +6
-0+ } + + res = g_new0(struct virtio_gpu_simple_resource, 1); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ;needless error handling, glib will
abort()on OOM.
OK, I will remove all simliar error handling in next version.
Quoted 203 lines
Quoted 72 lines
hw/display/virtio-gpu-virgl.c +71
-0+ } + + res->resource_id = cblob.resource_id; + res->blob_size = cblob.size; + +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) { +g_free (res); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; +return ; + } + } + +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + + virgl_args.res_handle = cblob.resource_id; + virgl_args.ctx_id = cblob.hdr.ctx_id; + virgl_args.blob_mem = cblob.blob_mem; + virgl_args.blob_id = cblob.blob_id; + virgl_args.blob_flags = cblob.blob_flags; + virgl_args.size = cblob.size; + virgl_args.iovecs = res->iov; + virgl_args.num_iovs = res->iov_cnt; + + ret =virgl_renderer_resource_create_blob (&virgl_args); +if (ret) { +virgl_resource_destroy (g, res); +qemu_log_mask (LOG_GUEST_ERROR ,"%s: virgl blob create error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; + } +} + +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; +struct virtio_gpu_resp_map_info resp; +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +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 ; + } +if (res->region) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already mapped %d\n" , + __func__, mblob.resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } +hw/display/virtio-gpu-virgl.c static void virgl_cmd_get_capset(VirtIOGPU *g, · line 567
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +10
-0+ ret =virgl_renderer_resource_map (res->resource_id, &data, &size); +if (ret) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource map error: %s\n" , + __func__,strerror (-ret)); + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; +return ; + } + + res->region =g_new0 (MemoryRegion,1 ); +if (!res->region) {no need for OOM handling here too
Quoted 118 lines
hw/display/virtio-gpu-virgl.c +74
-0+virgl_renderer_resource_unmap (res->resource_id); + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; + return; + } +memory_region_init_ram_ptr (res->region,OBJECT (g),NULL , size, data); +OBJECT (res->region)->free = g_free; +memory_region_add_subregion (&b->hostmem, mblob.offset, res->region); +memory_region_set_enabled (res->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 int virtio_gpu_virgl_resource_unmap (VirtIOGPU *g, +struct virtio_gpu_simple_resource + *res) +{ +VirtIOGPUBase *b =VIRTIO_GPU_BASE (g); + +if (!res) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: resource already unmapped %d\n" , + __func__, res->resource_id); +return VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; + } + +memory_region_set_enabled (res->region, false); +memory_region_del_subregion (&b->hostmem, res->region); +object_unparent (OBJECT (res->region)); + res->region =NULL ; + +return virgl_renderer_resource_unmap (res->resource_id); +} + +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 ; + } + +virtio_gpu_virgl_resource_unmap (g, res); +} + +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ +void virtio_gpu_virgl_process_cmd (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) {@@ -492,6 +694,17 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,case VIRTIO_GPU_CMD_GET_EDID :virtio_gpu_get_edid (g, cmd);break ; +#ifdef HAVE_VIRGL_RESOURCE_BLOB +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 ; +#endif /* HAVE_VIRGL_RESOURCE_BLOB */ default : cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;break ;hw/display/virtio-gpu.c +3
-1@@ -1367,10 +1367,12 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)return ; } +#ifndef HAVE_VIRGL_RESOURCE_BLOB if (virtio_gpu_virgl_enabled (g->parent_obj.conf)) { -error_setg (errp,"blobs and virgl are not compatible (yet)" ); +error_setg (errp,"Linked virglrenderer does not support blob resources" );return ; } +#endif } if (!virtio_gpu_base_device_realize(qdev,include/hw/virtio/virtio-gpu.h +5
-0@@ -58,6 +58,11 @@ struct virtio_gpu_simple_resource {int dmabuf_fd;uint8_t *remapped; +#ifdef HAVE_VIRGL_RESOURCE_BLOB +/* only blob resource needs this region to be mapped as guest mmio */ +MemoryRegion *region; +#endif +QTAILQ_ENTRY (virtio_gpu_simple_resource) next; };
Quoted 14 lines
meson.build if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu · line 1078
Quoted 12 lines
meson.build +4
-0@@ -1072,6 +1072,10 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu cc.has_function('virgl_renderer_context_create_with_flags', prefix: '#include <virglrenderer.h>', dependencies: virgl)) + config_host_data.set('HAVE_VIRGL_RESOURCE_BLOB', + cc.has_function('virgl_renderer_resource_create_blob', + prefix: '#include <virglrenderer.h>', + dependencies: virgl))better moved under the if
virgl.found()block
Yes, will update.
Quoted 12 lines
Quoted 8 lines
meson.build +0
-1endif blkio = not_found if not get_option('blkio').auto() or have_block --2.34.1
Signature · 1 line
Marc-André Lureau
PATCH v5 10/13 virtio-gpu: Resource UUID
In reply to Huang RuiFrom: Antonio Caggiano <[email protected]>
Enable resource UUID feature and implement command resource assign UUID. This is done by introducing a hash table to map resource IDs to their UUIDs.
---
V4 -> V5:
- Add virtio migration handling for uuid (Akihiko)
- Adjust sequence to allocate gpu resource before virglrender resource creation (Akihiko)
- Clean up (Akihiko)
hw/display/trace-events | 1 + hw/display/virtio-gpu-base.c | 2 ++ hw/display/virtio-gpu-virgl.c | 21 ++++++++++++ hw/display/virtio-gpu.c | 58 ++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-gpu.h | 6 ++++ 5 files changed, 88 insertions(+)
hw/display/trace-events +1 -0
@@ -41,6 +41,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
@@ -236,6 +236,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features, features |= (1 <<VIRTIO_GPU_F_CONTEXT_INIT ); } + features |= (1 <<VIRTIO_GPU_F_RESOURCE_UUID ); +return features; }
hw/display/virtio-gpu-virgl.c +21 -0
@@ -36,11 +36,20 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g, {struct virtio_gpu_resource_create_2d c2d;struct virgl_renderer_resource_create_args args; +struct virtio_gpu_simple_resource *res;VIRTIO_GPU_FILL_CMD (c2d);trace_virtio_gpu_cmd_res_create_2d (c2d.resource_id, c2d.format, c2d.width, c2d.height); + res = g_new0(struct virtio_gpu_simple_resource, 1); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + res->resource_id = c2d.resource_id; +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + args.handle = c2d.resource_id; args.target =2 ; args.format = c2d.format;
@@ -60,11 +69,20 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, {struct virtio_gpu_resource_create_3d c3d;struct virgl_renderer_resource_create_args args; +struct virtio_gpu_simple_resource *res;VIRTIO_GPU_FILL_CMD (c3d);trace_virtio_gpu_cmd_res_create_3d (c3d.resource_id, c3d.format, c3d.width, c3d.height, c3d.depth); + res = g_new0(struct virtio_gpu_simple_resource, 1); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + res->resource_id = c3d.resource_id; +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + args.handle = c3d.resource_id; args.target = c3d.target; args.format = c3d.format;
@@ -682,6 +700,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 +58 -0
118 lines not on this page · raw message
include/hw/virtio/virtio-gpu.h +6 -0
@@ -63,6 +63,8 @@ struct virtio_gpu_simple_resource {MemoryRegion *region;#endif +bool has_uuid; +QTAILQ_ENTRY (virtio_gpu_simple_resource) next; };
@@ -208,6 +210,8 @@ struct VirtIOGPU { QTAILQ_HEAD(, VGPUDMABuf) bufs;VGPUDMABuf *primary[VIRTIO_GPU_MAX_SCANOUTS ]; } dmabuf; + +GHashTable *resource_uuids; };struct VirtIOGPUClass {
@@ -285,6 +289,8 @@ void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g, struct iovec *iov, uint32_t count);void virtio_gpu_cleanup_mapping (VirtIOGPU *g,struct virtio_gpu_simple_resource *res); +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.34.1
Re: [QEMU PATCH v5 10/13] virtio-gpu: Resource UUID
Quoted 60 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Enable resource UUID feature and implement command resource assign UUID. This is done by introducing a hash table to map resource IDs to their UUIDs.
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Add virtio migration handling for uuid (Akihiko)
- Adjust sequence to allocate gpu resource before virglrender resource creation (Akihiko)
- Clean up (Akihiko)hw/display/trace-events | 1 + hw/display/virtio-gpu-base.c | 2 ++ hw/display/virtio-gpu-virgl.c | 21 ++++++++++++ hw/display/virtio-gpu.c | 58 ++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-gpu.h | 6 ++++ 5 files changed, 88 insertions(+)hw/display/trace-events +1
-0@@ -41,6 +41,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@@ -236,6 +236,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features, features |= (1 <<VIRTIO_GPU_F_CONTEXT_INIT ); } + features |= (1 <<VIRTIO_GPU_F_RESOURCE_UUID ); +return features; }hw/display/virtio-gpu-virgl.c +1
-0@@ -36,11 +36,20 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g, {struct virtio_gpu_resource_create_2d c2d;struct virgl_renderer_resource_create_args args; +struct virtio_gpu_simple_resource *res;VIRTIO_GPU_FILL_CMD (c2d); trace_virtio_gpu_cmd_res_create_2d(c2d.resource_id, c2d.format,
hw/display/virtio-gpu-virgl.c static void virgl_cmd_create_resource_2d(VirtIOGPU *g, · line 52
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +8
-0c2d.width, c2d.height); + res = g_new0(struct virtio_gpu_simple_resource, 1); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + res->resource_id = c2d.resource_id; +QTAILQ_INSERT_HEAD (&g->reslist, res, next); +
The struct virtio_gpu_simple_resource for a resource created with virgl_cmd_create_resource_2d() and virgl_resource_attach_backing() will not have iov and iov_cnt set, which is inconsistent with virgl_cmd_resource_create_blob().
Quoted 59 lines
hw/display/virtio-gpu-virgl.c +12
-0args.handle = c2d.resource_id; args.target =2 ; args.format = c2d.format;@@ -60,11 +69,20 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, {struct virtio_gpu_resource_create_3d c3d;struct virgl_renderer_resource_create_args args; +struct virtio_gpu_simple_resource *res;VIRTIO_GPU_FILL_CMD (c3d);trace_virtio_gpu_cmd_res_create_3d (c3d.resource_id, c3d.format, c3d.width, c3d.height, c3d.depth); + res = g_new0(struct virtio_gpu_simple_resource, 1); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + res->resource_id = c3d.resource_id; +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + args.handle = c3d.resource_id; args.target = c3d.target; args.format = c3d.format;@@ -682,6 +700,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 +17
-0@@ -966,6 +966,38 @@ 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; +QemuUUID *uuid; + +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 ; + } +
hw/display/virtio-gpu.c virtio_gpu_resource_detach_backing(VirtIOGPU *g, · line 995
Quoted 10 lines
hw/display/virtio-gpu.c +10
-0+memset (&resp,0 ,sizeof (resp)); + resp.hdr.type =VIRTIO_GPU_RESP_OK_RESOURCE_UUID ; + + uuid =g_hash_table_lookup (g->resource_uuids,GUINT_TO_POINTER (assign.resource_id)); +if (!uuid) { + uuid =g_new (QemuUUID,1 ); +qemu_uuid_generate (uuid); +g_hash_table_insert (g->resource_uuids,GUINT_TO_POINTER (assign.resource_id), uuid); + res->has_uuid = true; + }
What about embedding uuid into struct virtio_gpu_simple_resource? You will not need to maintain another table in this way.
Re: [QEMU PATCH v5 10/13] virtio-gpu: Resource UUID
Quoted 63 lines · Akihiko Odaki
Quoted 62 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Enable resource UUID feature and implement command resource assign UUID. This is done by introducing a hash table to map resource IDs to their UUIDs.
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Add virtio migration handling for uuid (Akihiko)
- Adjust sequence to allocate gpu resource before virglrender resource creation (Akihiko)
- Clean up (Akihiko)hw/display/trace-events | 1 + hw/display/virtio-gpu-base.c | 2 ++ hw/display/virtio-gpu-virgl.c | 21 ++++++++++++ hw/display/virtio-gpu.c | 58 ++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-gpu.h | 6 ++++ 5 files changed, 88 insertions(+)hw/display/trace-events +1
-0@@ -41,6 +41,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@@ -236,6 +236,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features, features |= (1 <<VIRTIO_GPU_F_CONTEXT_INIT ); } + features |= (1 <<VIRTIO_GPU_F_RESOURCE_UUID ); +return features; }hw/display/virtio-gpu-virgl.c +1
-0@@ -36,11 +36,20 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g, {struct virtio_gpu_resource_create_2d c2d;struct virgl_renderer_resource_create_args args; +struct virtio_gpu_simple_resource *res;VIRTIO_GPU_FILL_CMD (c2d);trace_virtio_gpu_cmd_res_create_2d (c2d.resource_id, c2d.format, c2d.width, c2d.height);
Quoted 14 lines
hw/display/virtio-gpu-virgl.c static void virgl_cmd_create_resource_2d(VirtIOGPU *g, · line 52
Quoted 8 lines
hw/display/virtio-gpu-virgl.c +8
-0+ res = g_new0(struct virtio_gpu_simple_resource, 1); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + res->resource_id = c2d.resource_id; +QTAILQ_INSERT_HEAD (&g->reslist, res, next); +The struct
virtio_gpu_simple_resourcefor a resource created withvirgl_cmd_create_resource_2d()andvirgl_resource_attach_backing()will not have iov andiov_cntset, which is inconsistent withvirgl_cmd_resource_create_blob().
OK, so we should find out the resource in virgl_resource_attach_backing(), and set the related iov and iov_cnt for this resource to align with blob memory.
Quoted 64 lines
Quoted 64 lines
hw/display/virtio-gpu-virgl.c +12
-0args.handle = c2d.resource_id; args.target =2 ; args.format = c2d.format;@@ -60,11 +69,20 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, {struct virtio_gpu_resource_create_3d c3d;struct virgl_renderer_resource_create_args args; +struct virtio_gpu_simple_resource *res;VIRTIO_GPU_FILL_CMD (c3d);trace_virtio_gpu_cmd_res_create_3d (c3d.resource_id, c3d.format, c3d.width, c3d.height, c3d.depth); + res = g_new0(struct virtio_gpu_simple_resource, 1); +if (!res) { + cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + res->resource_id = c3d.resource_id; +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + args.handle = c3d.resource_id; args.target = c3d.target; args.format = c3d.format;@@ -682,6 +700,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 +22
-0@@ -966,6 +966,38 @@ 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; +QemuUUID *uuid; + +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 ; + + uuid =g_hash_table_lookup (g->resource_uuids,GUINT_TO_POINTER (assign.resource_id)); +if (!uuid) {
Quoted 8 lines
hw/display/virtio-gpu.c virtio_gpu_resource_detach_backing(VirtIOGPU *g, · line 995
Quoted 5 lines
hw/display/virtio-gpu.c +5
-0+ uuid =g_new (QemuUUID,1 ); +qemu_uuid_generate (uuid); +g_hash_table_insert (g->resource_uuids,GUINT_TO_POINTER (assign.resource_id), uuid); + res->has_uuid = true; + }What about embedding uuid into struct
virtio_gpu_simple_resource? You will not need to maintain another table in this way.
Yes, agree. Will update it in V6.
Thanks,
Ray
Re: [QEMU PATCH v5 10/13] virtio-gpu: Resource UUID
In reply to Huang RuiHi
Quoted 41 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Enable resource UUID feature and implement command resource assign UUID. This is done by introducing a hash table to map resource IDs to their UUIDs.
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Add virtio migration handling for uuid (Akihiko)
- Adjust sequence to allocate gpu resource before virglrender resource creation (Akihiko)
- Clean up (Akihiko)hw/display/trace-events | 1 + hw/display/virtio-gpu-base.c | 2 ++ hw/display/virtio-gpu-virgl.c | 21 ++++++++++++ hw/display/virtio-gpu.c | 58 ++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-gpu.h | 6 ++++ 5 files changed, 88 insertions(+)hw/display/trace-events +1
-0@@ -41,6 +41,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 +0
-0
hw/display/virtio-gpu-base.c virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features, · line 239
Quoted 4 lines
hw/display/virtio-gpu-base.c +1
-0@@ -236,6 +236,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features, features |= (1 <<VIRTIO_GPU_F_CONTEXT_INIT ); } + features |= (1 <<VIRTIO_GPU_F_RESOURCE_UUID );
This changes what is exposed to the guest. We should have an option for it, and set it to false on older machine types (similar to what is done for edid).
Quoted 10 lines
hw/display/virtio-gpu-base.c +1
-0+return features; }hw/display/virtio-gpu-virgl.c +0
-0@@ -36,11 +36,20 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g, {
hw/display/virtio-gpu-virgl.c static void virgl_cmd_create_resource_2d(VirtIOGPU *g, · line 46
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +3
-0struct virtio_gpu_resource_create_2d c2d;struct virgl_renderer_resource_create_args args; +struct virtio_gpu_simple_resource *res;VIRTIO_GPU_FILL_CMD (c2d);trace_virtio_gpu_cmd_res_create_2d (c2d.resource_id, c2d.format, c2d.width, c2d.height); + res = g_new0(struct virtio_gpu_simple_resource, 1); +if (!res) {
needless OOM here too
Quoted 11 lines
hw/display/virtio-gpu-virgl.c +6
-0+ cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + res->resource_id = c2d.resource_id; +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + args.handle = c2d.resource_id; args.target =2 ; args.format = c2d.format;@@ -60,11 +69,20 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, {
hw/display/virtio-gpu-virgl.c static void virgl_cmd_create_resource_3d(VirtIOGPU *g, · line 79
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +3
-0struct virtio_gpu_resource_create_3d c3d;struct virgl_renderer_resource_create_args args; +struct virtio_gpu_simple_resource *res;VIRTIO_GPU_FILL_CMD (c3d);trace_virtio_gpu_cmd_res_create_3d (c3d.resource_id, c3d.format, c3d.width, c3d.height, c3d.depth); + res = g_new0(struct virtio_gpu_simple_resource, 1); +if (!res) {
same
Quoted 81 lines
hw/display/virtio-gpu-virgl.c +9
-0+ cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + res->resource_id = c3d.resource_id; +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + args.handle = c3d.resource_id; args.target = c3d.target; args.format = c3d.format;@@ -682,6 +700,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 +36
-0@@ -966,6 +966,38 @@ 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; +QemuUUID *uuid; + +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 ; + + uuid =g_hash_table_lookup (g->resource_uuids,GUINT_TO_POINTER (assign.resource_id)); +if (!uuid) { + uuid =g_new (QemuUUID,1 ); +qemu_uuid_generate (uuid); +g_hash_table_insert (g->resource_uuids,GUINT_TO_POINTER (assign.resource_id), uuid); + res->has_uuid = true; + } + +memcpy (resp.uuid, uuid,sizeof (QemuUUID)); +virtio_gpu_ctrl_response (g, cmd, &resp.hdr,sizeof (resp)); +} +void virtio_gpu_simple_process_cmd (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) {@@ -1014,6 +1046,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 ;@@ -1208,6 +1243,7 @@ static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size,VirtIOGPU *g = opaque;struct virtio_gpu_simple_resource *res;int i; +QemuUUID *uuid;/* in 2d mode we should never find unprocessed commands here */ assert (QTAILQ_EMPTY (&g->cmdq));
hw/display/virtio-gpu.c static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size, · line 1268
Quoted 9 lines
hw/display/virtio-gpu.c +6
-0@@ -1224,9 +1260,17 @@ static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size, }qemu_put_buffer (f, (void *)pixman_image_get_data (res->image),pixman_image_get_stride (res->image) * res->height); + +qemu_put_byte (f, res->has_uuid); +if (res->has_uuid) { + uuid =g_hash_table_lookup (g->resource_uuids,GUINT_TO_POINTER (res->resource_id)); +qemu_put_buffer (f, (void *)uuid,sizeof (QemuUUID)); + }
This is breaking the migration format. It will need to be handled with an optional subsection instead.
Quoted 9 lines
hw/display/virtio-gpu.c +2
-0}qemu_put_be32 (f,0 );/* end of list */ +g_hash_table_destroy (g->resource_uuids); +return vmstate_save_state (f, &vmstate_virtio_gpu_scanouts, g,NULL ); }
hw/display/virtio-gpu.c static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size, · line 1290
Quoted 8 lines
hw/display/virtio-gpu.c +2
-0@@ -1239,9 +1283,12 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,uint32_t resource_id, pformat;void *bits =NULL ;int i; +QemuUUID *uuid =NULL ; g->hostmem =0 ; + g->resource_uuids =g_hash_table_new_full (NULL ,NULL ,NULL , g_free);
Since it maps int -> uuid, it should probably use g_int_hash() / g_int_qual() instead of the default (g_direct_hash()).
Quoted 77 lines
hw/display/virtio-gpu.c +12
-0+ resource_id =qemu_get_be32 (f);while (resource_id !=0 ) { res =virtio_gpu_find_resource (g, resource_id);@@ -1292,6 +1339,12 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,qemu_get_buffer (f, (void *)pixman_image_get_data (res->image),pixman_image_get_stride (res->image) * res->height); + res->has_uuid =qemu_get_byte (f); +if (res->has_uuid) { +qemu_get_buffer (f, (void *)uuid,sizeof (QemuUUID)); +g_hash_table_insert (g->resource_uuids,GUINT_TO_POINTER (res->resource_id), uuid); + } +/* restore mapping */ for (i =0 ; i < res->iov_cnt; i++) {hwaddr len = res->iov[i].iov_len;@@ -1393,12 +1446,15 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)QTAILQ_INIT (&g->reslist);QTAILQ_INIT (&g->cmdq);QTAILQ_INIT (&g->fenceq); + + g->resource_uuids =g_hash_table_new_full (NULL ,NULL ,NULL , g_free); }static void virtio_gpu_device_unrealize (DeviceState *qdev) {VirtIOGPU *g =VIRTIO_GPU (qdev); +g_hash_table_destroy (g->resource_uuids);g_clear_pointer (&g->ctrl_bh, qemu_bh_delete);g_clear_pointer (&g->cursor_bh, qemu_bh_delete);g_clear_pointer (&g->reset_bh, qemu_bh_delete);@@ -1452,6 +1508,8 @@ void virtio_gpu_reset(VirtIODevice *vdev)g_free (cmd); } +g_hash_table_remove_all (g->resource_uuids); +virtio_gpu_base_reset (VIRTIO_GPU_BASE (vdev)); }include/hw/virtio/virtio-gpu.h +6
-1@@ -63,6 +63,8 @@ struct virtio_gpu_simple_resource {MemoryRegion *region;#endif +bool has_uuid; +QTAILQ_ENTRY (virtio_gpu_simple_resource) next; };@@ -208,6 +210,8 @@ struct VirtIOGPU { QTAILQ_HEAD(, VGPUDMABuf) bufs;VGPUDMABuf *primary[VIRTIO_GPU_MAX_SCANOUTS ]; } dmabuf; + +GHashTable *resource_uuids; };struct VirtIOGPUClass {@@ -285,6 +289,8 @@ void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g, struct iovec *iov, uint32_t count);void virtio_gpu_cleanup_mapping (VirtIOGPU *g,struct virtio_gpu_simple_resource *res); +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); --2.34.1
Signature · 1 line
Marc-André Lureau
Re: [QEMU PATCH v5 10/13] virtio-gpu: Resource UUID
Quoted 47 lines · Marc-André Lureau
Hi
Quoted 44 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Enable resource UUID feature and implement command resource assign UUID. This is done by introducing a hash table to map resource IDs to their UUIDs.
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Add virtio migration handling for uuid (Akihiko)
- Adjust sequence to allocate gpu resource before virglrender resource creation (Akihiko)
- Clean up (Akihiko)hw/display/trace-events | 1 + hw/display/virtio-gpu-base.c | 2 ++ hw/display/virtio-gpu-virgl.c | 21 ++++++++++++ hw/display/virtio-gpu.c | 58 ++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-gpu.h | 6 ++++ 5 files changed, 88 insertions(+)hw/display/trace-events +1
-0@@ -41,6 +41,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 +0
-0@@ -236,6 +236,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features, features |= (1 <<VIRTIO_GPU_F_CONTEXT_INIT ); }
Quoted 6 lines
hw/display/virtio-gpu-base.c virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features, · line 239
Quoted 1 line
hw/display/virtio-gpu-base.c +1
-0+ features |= (1 <<VIRTIO_GPU_F_RESOURCE_UUID );This changes what is exposed to the guest. We should have an option for it, and set it to false on older machine types (similar to what is done for edid).
Did you mean we can add "resource_uuid" in virtio_gpu_properties[] like below, user can set it to false on older types with the param?
DEFINE_PROP_BIT("resource_uuid", VirtIOGPU, parent_obj.conf.flags,
VIRTIO_GPU_FLAG_RESOURCE_UUID, true);
Quoted 125 lines
Quoted 10 lines
hw/display/virtio-gpu-base.c +1
-0+return features; }hw/display/virtio-gpu-virgl.c +0
-0@@ -36,11 +36,20 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g, {hw/display/virtio-gpu-virgl.c static void virgl_cmd_create_resource_2d(VirtIOGPU *g, · line 46
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +3
-0struct virtio_gpu_resource_create_2d c2d;struct virgl_renderer_resource_create_args args; +struct virtio_gpu_simple_resource *res;VIRTIO_GPU_FILL_CMD (c2d);trace_virtio_gpu_cmd_res_create_2d (c2d.resource_id, c2d.format, c2d.width, c2d.height); + res = g_new0(struct virtio_gpu_simple_resource, 1); +if (!res) {needless OOM here too
Quoted 11 lines
hw/display/virtio-gpu-virgl.c +6
-0+ cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + res->resource_id = c2d.resource_id; +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + args.handle = c2d.resource_id; args.target =2 ; args.format = c2d.format;@@ -60,11 +69,20 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, {hw/display/virtio-gpu-virgl.c static void virgl_cmd_create_resource_3d(VirtIOGPU *g, · line 79
Quoted 10 lines
hw/display/virtio-gpu-virgl.c +3
-0struct virtio_gpu_resource_create_3d c3d;struct virgl_renderer_resource_create_args args; +struct virtio_gpu_simple_resource *res;VIRTIO_GPU_FILL_CMD (c3d);trace_virtio_gpu_cmd_res_create_3d (c3d.resource_id, c3d.format, c3d.width, c3d.height, c3d.depth); + res = g_new0(struct virtio_gpu_simple_resource, 1); +if (!res) {same
Quoted 78 lines
hw/display/virtio-gpu-virgl.c +9
-0+ cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ; +return ; + } + res->resource_id = c3d.resource_id; +QTAILQ_INSERT_HEAD (&g->reslist, res, next); + args.handle = c3d.resource_id; args.target = c3d.target; args.format = c3d.format;@@ -682,6 +700,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 +36
-0@@ -966,6 +966,38 @@ 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; +QemuUUID *uuid; + +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 ; + + uuid =g_hash_table_lookup (g->resource_uuids,GUINT_TO_POINTER (assign.resource_id)); +if (!uuid) { + uuid =g_new (QemuUUID,1 ); +qemu_uuid_generate (uuid); +g_hash_table_insert (g->resource_uuids,GUINT_TO_POINTER (assign.resource_id), uuid); + res->has_uuid = true; + } + +memcpy (resp.uuid, uuid,sizeof (QemuUUID)); +virtio_gpu_ctrl_response (g, cmd, &resp.hdr,sizeof (resp)); +} +void virtio_gpu_simple_process_cmd (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd) {@@ -1014,6 +1046,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 ;@@ -1208,6 +1243,7 @@ static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size,VirtIOGPU *g = opaque;struct virtio_gpu_simple_resource *res;int i; +QemuUUID *uuid;
Quoted 15 lines
hw/display/virtio-gpu.c static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size, · line 1268
Quoted 12 lines
hw/display/virtio-gpu.c +6
-0/* in 2d mode we should never find unprocessed commands here */ assert (QTAILQ_EMPTY (&g->cmdq));@@ -1224,9 +1260,17 @@ static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size, }qemu_put_buffer (f, (void *)pixman_image_get_data (res->image),pixman_image_get_stride (res->image) * res->height); + +qemu_put_byte (f, res->has_uuid); +if (res->has_uuid) { + uuid =g_hash_table_lookup (g->resource_uuids,GUINT_TO_POINTER (res->resource_id)); +qemu_put_buffer (f, (void *)uuid,sizeof (QemuUUID)); + }This is breaking the migration format. It will need to be handled with an optional subsection instead.
I am using one byte to store res->has_uuid after pixman data, if check this field is true, then have UUID data.
Would you mind to elaborate the optional subsection?
Quoted 15 lines
Quoted 15 lines
hw/display/virtio-gpu.c +3
-0}qemu_put_be32 (f,0 );/* end of list */ +g_hash_table_destroy (g->resource_uuids); +return vmstate_save_state (f, &vmstate_virtio_gpu_scanouts, g,NULL ); }@@ -1239,9 +1283,12 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,uint32_t resource_id, pformat;void *bits =NULL ;int i; +QemuUUID *uuid =NULL ;
Quoted 7 lines
hw/display/virtio-gpu.c static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size, · line 1290
Quoted 3 lines
hw/display/virtio-gpu.c +1
-0g->hostmem =0 ; + g->resource_uuids =g_hash_table_new_full (NULL ,NULL ,NULL , g_free);Since it maps int -> uuid, it should probably use
g_int_hash()/g_int_qual()instead of the default (g_direct_hash()).
Thanks to reminder, will update it in V6.
Quoted 81 lines
Quoted 77 lines
hw/display/virtio-gpu.c +12
-0+ resource_id =qemu_get_be32 (f);while (resource_id !=0 ) { res =virtio_gpu_find_resource (g, resource_id);@@ -1292,6 +1339,12 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,qemu_get_buffer (f, (void *)pixman_image_get_data (res->image),pixman_image_get_stride (res->image) * res->height); + res->has_uuid =qemu_get_byte (f); +if (res->has_uuid) { +qemu_get_buffer (f, (void *)uuid,sizeof (QemuUUID)); +g_hash_table_insert (g->resource_uuids,GUINT_TO_POINTER (res->resource_id), uuid); + } +/* restore mapping */ for (i =0 ; i < res->iov_cnt; i++) {hwaddr len = res->iov[i].iov_len;@@ -1393,12 +1446,15 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)QTAILQ_INIT (&g->reslist);QTAILQ_INIT (&g->cmdq);QTAILQ_INIT (&g->fenceq); + + g->resource_uuids =g_hash_table_new_full (NULL ,NULL ,NULL , g_free); }static void virtio_gpu_device_unrealize (DeviceState *qdev) {VirtIOGPU *g =VIRTIO_GPU (qdev); +g_hash_table_destroy (g->resource_uuids);g_clear_pointer (&g->ctrl_bh, qemu_bh_delete);g_clear_pointer (&g->cursor_bh, qemu_bh_delete);g_clear_pointer (&g->reset_bh, qemu_bh_delete);@@ -1452,6 +1508,8 @@ void virtio_gpu_reset(VirtIODevice *vdev)g_free (cmd); } +g_hash_table_remove_all (g->resource_uuids); +virtio_gpu_base_reset (VIRTIO_GPU_BASE (vdev)); }include/hw/virtio/virtio-gpu.h +6
-1@@ -63,6 +63,8 @@ struct virtio_gpu_simple_resource {MemoryRegion *region;#endif +bool has_uuid; +QTAILQ_ENTRY (virtio_gpu_simple_resource) next; };@@ -208,6 +210,8 @@ struct VirtIOGPU { QTAILQ_HEAD(, VGPUDMABuf) bufs;VGPUDMABuf *primary[VIRTIO_GPU_MAX_SCANOUTS ]; } dmabuf; + +GHashTable *resource_uuids; };struct VirtIOGPUClass {@@ -285,6 +289,8 @@ void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g, struct iovec *iov, uint32_t count);void virtio_gpu_cleanup_mapping (VirtIOGPU *g,struct virtio_gpu_simple_resource *res); +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); --2.34.1
Signature · 1 line
Marc-André Lureau
PATCH v5 11/13 virtio-gpu: Support Venus capset
In reply to Huang RuiFrom: Antonio Caggiano <[email protected]>
Add support for the Venus capset, which enables Vulkan support through the Venus Vulkan driver for virtio-gpu.
---
V4 -> V5:
- Send kernel patch to define VIRTIO_GPU_CAPSET_VENUS and will use another patch to sync up linux headers. (Akihiko)
- https://lore.kernel.org/lkml/[email protected]/
hw/display/virtio-gpu-virgl.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
hw/display/virtio-gpu-virgl.c +17 -4
@@ -437,6 +437,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 ;
@@ -901,10 +906,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; }
Signature · 1 line
2.34.1
Re: [QEMU PATCH v5 11/13] virtio-gpu: Support Venus capset
Hi
Quoted 6 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Add support for the Venus capset, which enables Vulkan support through the Venus Vulkan driver for virtio-gpu.
Quoted 8 lines
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
V4 -> V5:
- Send kernel patch to defineVIRTIO_GPU_CAPSET_VENUSand will use another patch to sync up linux headers. (Akihiko)
- https://lore.kernel.org/lkml/[email protected]/
Ok but in the meantime, you should have that header update patch in the series too, otherwise we can't compile it :)
thanks
Quoted 47 lines
hw/display/virtio-gpu-virgl.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)hw/display/virtio-gpu-virgl.c +17
-5@@ -437,6 +437,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 ;@@ -901,10 +906,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; } --2.34.1
Signature · 1 line
Marc-André Lureau
Re: [QEMU PATCH v5 11/13] virtio-gpu: Support Venus capset
Quoted 13 lines · Marc-André Lureau
Hi
Quoted 10 lines · Huang Rui
From: Antonio Caggiano <[email protected]>
Add support for the Venus capset, which enables Vulkan support through the Venus Vulkan driver for virtio-gpu.
Signed-off-by Antonio Caggiano <[email protected]>Signed-off-by Huang Rui <[email protected]>---
Quoted 8 lines
Quoted 4 lines
V4 -> V5:
- Send kernel patch to defineVIRTIO_GPU_CAPSET_VENUSand will use another patch to sync up linux headers. (Akihiko)
- https://lore.kernel.org/lkml/[email protected]/Ok but in the meantime, you should have that header update patch in the series too, otherwise we can't compile it :)
In fact, it's in my repo. :-)
I am waiting for it to be merged into kernel mainline and then update the commit id.
https://gitlab.freedesktop.org/rui/qemu-xen/-/commit/4ae9d078f9242890769c98162caf32f95df42529
I will include it in next series.
Thanks,
Ray
Quoted 53 lines
thanks
Quoted 47 lines
hw/display/virtio-gpu-virgl.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)hw/display/virtio-gpu-virgl.c +17
-5@@ -437,6 +437,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 ;@@ -901,10 +906,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; } --2.34.1
Signature · 1 line
Marc-André Lureau
PATCH v5 12/13 virtio-gpu: Initialize Venus
In reply to Huang RuiFrom: Antonio Caggiano <[email protected]>
Request Venus when initializing VirGL.
---
V4 -> V5:
- Add meson check to make sure unstable APIs defined from 0.9.0. (Antonio)
hw/display/virtio-gpu-virgl.c | 4 ++++ meson.build | 5 +++++ 2 files changed, 9 insertions(+)
hw/display/virtio-gpu-virgl.c +4 -0
@@ -887,6 +887,10 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) }#endif +#ifdef VIRGL_RENDERER_VENUS + flags |=VIRGL_RENDERER_VENUS ; +#endif + ret =virgl_renderer_init (g, flags, &virtio_gpu_3d_cbs);if (ret !=0 ) {error_report ("virgl could not be initialized: %d" , ret);
meson.build +5 -0
@@ -1076,6 +1076,11 @@ if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu cc.has_function('virgl_renderer_resource_create_blob', prefix: '#include <virglrenderer.h>', dependencies: virgl)) + if virgl.version().version_compare('>= 0.9.0') and virgl.version().version_compare('< 1.0.0') + message('Enabling virglrenderer unstable APIs') + virgl = declare_dependency(compile_args: '-DVIRGL_RENDERER_UNSTABLE_APIS', + dependencies: virgl) + endif endif blkio = not_found if not get_option('blkio').auto() or have_block
Signature · 1 line
2.34.1
Re: [QEMU PATCH v5 12/13] virtio-gpu: Initialize Venus
meson.build if not get_option('virglrenderer').auto() or have_system or have_vhost_user_gpu · line 1083
Quoted 5 lines · Huang Rui
meson.build +5
-0+ if virgl.version().version_compare('>= 0.9.0') and virgl.version().version_compare('< 1.0.0') + message('Enabling virglrenderer unstable APIs') + virgl = declare_dependency(compile_args: '-DVIRGL_RENDERER_UNSTABLE_APIS', + dependencies: virgl) + endif
All the required APIs has been stabilized in virglrenderer 1.0, we shouldn't use the VIRGL_RENDERER_UNSTABLE_APIS anymore. The unstable APIs were used for development purposes and shouldn't present in the final version.
Please remove the VIRGL_RENDERER_UNSTABLE_APIS in v6.
Signature · 2 lines
Best regards, Dmitry
PATCH v5 13/13 virtio-gpu: Enable virglrenderer render server flag for venus
In reply to Huang RuiVenus in virglrenderer has required render server support.
--- hw/display/virtio-gpu-virgl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/virtio-gpu-virgl.c +1 -1
@@ -888,7 +888,7 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)#endif #ifdef VIRGL_RENDERER_VENUS - flags |=VIRGL_RENDERER_VENUS ; + flags |=VIRGL_RENDERER_VENUS |VIRGL_RENDERER_RENDER_SERVER ;#endif ret =virgl_renderer_init (g, flags, &virtio_gpu_3d_cbs);
Signature · 1 line
2.34.1
Re: [QEMU PATCH v5 13/13] virtio-gpu: Enable virglrenderer render server flag for venus
Quoted 12 lines · Huang Rui
Venus in virglrenderer has required render server support.
Signed-off-by Huang Rui <[email protected]>--- hw/display/virtio-gpu-virgl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/display/virtio-gpu-virgl.c +0
-0
hw/display/virtio-gpu-virgl.c int virtio_gpu_virgl_init(VirtIOGPU *g) · line 894
Quoted 8 lines
hw/display/virtio-gpu-virgl.c +1
-1@@ -888,7 +888,7 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)#endif #ifdef VIRGL_RENDERER_VENUS - flags |=VIRGL_RENDERER_VENUS ; + flags |=VIRGL_RENDERER_VENUS |VIRGL_RENDERER_RENDER_SERVER ;#endif ret =virgl_renderer_init (g, flags, &virtio_gpu_3d_cbs);
This change should be squashed into the previous "Initialize Venus" patch.
Signature · 2 lines
Best regards, Dmitry
Quoted 18 lines · Huang Rui
Hi all,
Antonio Caggiano made the venus with QEMU on KVM platform last September[1]. This series are inherited from his original work to support the features of context init, hostmem, resource uuid, and blob resources for venus.
At March of this year, we sent out the V1 version[2] for the review. But those series are included both xen and virtio gpu. Right now, we would like to divide into two parts, one is to continue the Antonio's work to upstream virtio-gpu support for blob memory and venus, and another is to upstream xen specific patches. This series is focusing on virtio-gpu, so we are marking as V4 version here to continue Antonio's patches[1]. And we will send xen specific patches separately, because they are hypervisor specific. Besides of QEMU, these supports also included virglrenderer[3][4] and mesa[5][6] as well. Right now, virglrenderer and mesa parts are all accepted by upstream. In this qemu version, we try to address the concerns around not proper cleanup during blob resource unmap and unref. Appreciate it if you have any commments.
Venus uses blob buffers. In order to display Venus/VK application using GL display server, the VIRTIO_GPU_CMD_SET_SCANOUT_BLOB must be supported. Otherwise Venus itself isn't practically useful because you can't run VK application with a usual Linux DE because Venus will error out due to the unsupported command.
The VIRTIO_GPU_CMD_SET_SCANOUT_BLOB support needs to be a part of this series, IMO. Can we add it to the next patchset version?
Signature · 2 lines
Best regards, Dmitry