Vga 20210527 patches
The following changes since commit 2ab2dad01f6dc3667c0d53d2b1ba46b511031207:
Merge remote-tracking branch 'remotes/kraxel/tags/input-20210526-pull-request' into staging (2021-05-26 15:27:20 +0100)
are available in the Git repository at:
git://git.kraxel.org/qemu tags/vga-20210527-pull-request
for you to fetch changes up to bdd53f739273e97b5e5617b699d1763c42a5ea7e:
virtio-gpu: Update cursor data using blob (2021-05-27 12:07:37 +0200)
----------------------------------------------------------------
virtio-gpu: add blob resource support.
vhost-user-gpu: security fixes.
----------------------------------------------------------------
Li Qiang (8):
vhost-user-gpu: fix memory disclosure in virgl_cmd_get_capset_info
(CVE-2021-3545)
vhost-user-gpu: fix resource leak in 'vg_resource_create_2d'
(CVE-2021-3544)
vhost-user-gpu: fix memory leak in vg_resource_attach_backing
(CVE-2021-3544)
vhost-user-gpu: fix memory leak while calling 'vg_resource_unref'
(CVE-2021-3544)
vhost-user-gpu: fix memory leak in 'virgl_cmd_resource_unref'
(CVE-2021-3544)
vhost-user-gpu: fix memory leak in 'virgl_resource_attach_backing'
(CVE-2021-3544)
vhost-user-gpu: fix OOB write in 'virgl_cmd_get_capset'
(CVE-2021-3546) vhost-user-gpu: abstract vg_cleanup_mapping_iov
Vivek Kasireddy (14):
ui: Get the fd associated with udmabuf driver
headers: Add udmabuf.h
virtio-gpu: Add udmabuf helpers
stubs: Add stubs for udmabuf helpers
virtio-gpu: Add virtio_gpu_find_check_resource
virtio-gpu: Refactor virtio_gpu_set_scanout
virtio-gpu: Refactor virtio_gpu_create_mapping_iov
virtio-gpu: Add initial definitions for blob resources
virtio-gpu: Add virtio_gpu_resource_create_blob ui/pixman: Add qemu_pixman_to_drm_format()
virtio-gpu: Add helpers to create and destroy dmabuf objects
virtio-gpu: Factor out update scanout
virtio-gpu: Add virtio_gpu_set_scanout_blob
virtio-gpu: Update cursor data using blob
maobibo (1):
hw/display/qxl: Set pci rom address aligned with page size
contrib/vhost-user-gpu/vugpu.h | 2 +- include/hw/virtio/virtio-gpu-bswap.h | 16 + include/hw/virtio/virtio-gpu.h | 39 +- include/standard-headers/linux/udmabuf.h | 32 ++ include/ui/console.h | 3 + include/ui/qemu-pixman.h | 1 + contrib/vhost-user-gpu/vhost-user-gpu.c | 29 +- contrib/vhost-user-gpu/virgl.c | 20 +- hw/display/qxl.c | 2 +- hw/display/virtio-gpu-base.c | 3 + hw/display/virtio-gpu-udmabuf.c | 223 ++++++++++++ hw/display/virtio-gpu-virgl.c | 3 +- hw/display/virtio-gpu.c | 441 +++++++++++++++++------ stubs/virtio-gpu-udmabuf.c | 27 ++ ui/qemu-pixman.c | 35 +- ui/udmabuf.c | 40 ++ hw/display/meson.build | 1 + hw/display/trace-events | 2 + meson.build | 2 +- scripts/update-linux-headers.sh | 3 + stubs/meson.build | 1 + ui/meson.build | 1 + 22 files changed, 804 insertions(+), 122 deletions(-) create mode 100644 include/standard-headers/linux/udmabuf.h create mode 100644 hw/display/virtio-gpu-udmabuf.c create mode 100644 stubs/virtio-gpu-udmabuf.c create mode 100644 ui/udmabuf.c
Signature · 1 line
2.31.1
[PULL 03/23] vhost-user-gpu: fix memory leak in vg_resource_attach_backing (CVE-2021-3544)
From: Li Qiang <[email protected]>
Check whether the 'res' has already been attach_backing to avoid memory leak.
virtio-gpu fix: 204f01b309 ("virtio-gpu: fix memory leak in resource attach backing")
Message-Id: <[email protected]>
--- contrib/vhost-user-gpu/vhost-user-gpu.c | 5 +++++ 1 file changed, 5 insertions(+)
contrib/vhost-user-gpu/vhost-user-gpu.c +5 -0
@@ -489,6 +489,11 @@ vg_resource_attach_backing(VuGpu *g,return ; } +if (res->iov) { + cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ; +return ; + } + ret =vg_create_mapping_iov (g, &ab, cmd, &res->iov);if (ret !=0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;
Signature · 1 line
2.31.1
[PULL 04/23] vhost-user-gpu: fix memory leak while calling 'vg_resource_unref' (CVE-2021-3544)
In reply to Gerd HoffmannFrom: Li Qiang <[email protected]>
If the guest trigger following sequences, the attach_backing will be leaked:
vg_resource_create_2d
vg_resource_attach_backing
vg_resource_unref
This patch fix this by freeing 'res->iov' in vg_resource_destroy.
virtio-gpu fix: 5e8e3c4c75 ("virtio-gpu: fix resource leak in virgl_cmd_resource_unref")
Message-Id: <[email protected]>
--- contrib/vhost-user-gpu/vhost-user-gpu.c | 1 + 1 file changed, 1 insertion(+)
contrib/vhost-user-gpu/vhost-user-gpu.c +1 -0
@@ -400,6 +400,7 @@ vg_resource_destroy(VuGpu *g, }vugbm_buffer_destroy (&res->buffer); +g_free (res->iov);pixman_image_unref (res->image);QTAILQ_REMOVE (&g->reslist, res, next);g_free (res);
Signature · 1 line
2.31.1
[PULL 02/23] vhost-user-gpu: fix resource leak in 'vg_resource_create_2d' (CVE-2021-3544)
In reply to Gerd HoffmannFrom: Li Qiang <[email protected]>
Call 'vugbm_buffer_destroy' in error path to avoid resource leak.
Message-Id: <[email protected]>
--- contrib/vhost-user-gpu/vhost-user-gpu.c | 1 + 1 file changed, 1 insertion(+)
contrib/vhost-user-gpu/vhost-user-gpu.c +1 -0
@@ -349,6 +349,7 @@ vg_resource_create_2d(VuGpu *g,g_critical ("%s: resource creation failed %d %d %d" , __func__, c2d.resource_id, c2d.width, c2d.height);g_free (res); +vugbm_buffer_destroy (&res->buffer); cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ;return ; }
Signature · 1 line
2.31.1
Re: [PULL 02/23] vhost-user-gpu: fix resource leak in 'vg_resource_create_2d' (CVE-2021-3544)
Quoted 21 lines · Gerd Hoffmann
From: Li Qiang <[email protected]>
Call '
vugbm_buffer_destroy' in error path to avoid resource leak.Fixes CVE-2021-3544Reported-by Li Qiang <[email protected]>Reviewed-by Prasad J Pandit <[email protected]>Signed-off-by Li Qiang <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>Message-Id: <[email protected]>
Signed-off-by Gerd Hoffmann <[email protected]>--- contrib/vhost-user-gpu/vhost-user-gpu.c | 1 + 1 file changed, 1 insertion(+)contrib/vhost-user-gpu/vhost-user-gpu.c +0
-0
contrib/vhost-user-gpu/vhost-user-gpu.c vg_resource_create_2d(VuGpu *g, · line 355
Quoted 7 lines
contrib/vhost-user-gpu/vhost-user-gpu.c +1
-0@@ -349,6 +349,7 @@ vg_resource_create_2d(VuGpu *g,g_critical ("%s: resource creation failed %d %d %d" , __func__, c2d.resource_id, c2d.width, c2d.height);g_free (res); +vugbm_buffer_destroy (&res->buffer); cmd->error =VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY ;return ; }
Hi; Coverity reports this as a use-after-free: we free 'res' and then on the next line we pass a pointer into this freed memory to vugbm_buffer_destroy(), which dereferences it. Probably the two lines should be in the other order ?
(CID 1453812)
thanks
-- PMM
[PULL 06/23] vhost-user-gpu: fix memory leak in 'virgl_resource_attach_backing' (CVE-2021-3544)
In reply to Gerd HoffmannFrom: Li Qiang <[email protected]>
If 'virgl_renderer_resource_attach_iov' failed, the 'res_iovs' will be leaked.
virtio-gpu fix: 33243031da ("virtio-gpu-3d: fix memory leak in resource attach backing")
Message-Id: <[email protected]>
--- contrib/vhost-user-gpu/virgl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/vhost-user-gpu/virgl.c +4 -1
@@ -287,8 +287,11 @@ virgl_resource_attach_backing(VuGpu *g,return ; } -virgl_renderer_resource_attach_iov (att_rb.resource_id, + ret =virgl_renderer_resource_attach_iov (att_rb.resource_id, res_iovs, att_rb.nr_entries); +if (ret !=0 ) { +g_free (res_iovs); + } } static void
Signature · 1 line
2.31.1
[PULL 13/23] stubs: Add stubs for udmabuf helpers
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
This is needed to ensure that virtio-gpu device works for non-linux builds.
Message-Id: <[email protected]>
[ kraxel: add virtio-gpu-udmabuf.c stubs only when building
system emulation ]
--- stubs/virtio-gpu-udmabuf.c | 18 ++++++++++++++++++ meson.build | 2 +- stubs/meson.build | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 stubs/virtio-gpu-udmabuf.c
stubs/virtio-gpu-udmabuf.c new file +18 -0
@@ -0,0 +1,18 @@ +#include "qemu/osdep.h" +#include "hw/virtio/virtio-gpu.h" + +bool virtio_gpu_have_udmabuf (void ) +{ +/* nothing (stub) */ +return false; +} + +void virtio_gpu_init_udmabuf (struct virtio_gpu_simple_resource *res) +{ +/* nothing (stub) */ +} + +void virtio_gpu_fini_udmabuf (struct virtio_gpu_simple_resource *res) +{ +/* nothing (stub) */ +}
meson.build +1 -1
@@ -1899,7 +1899,7 @@ util_ss.add_all(trace_ss) util_ss = util_ss.apply(config_all, strict: false) libqemuutil = static_library('qemuutil', sources: util_ss.sources() + stub_ss.sources() + genh, - dependencies: [util_ss.dependencies(), m, glib, socket, malloc]) + dependencies: [util_ss.dependencies(), m, glib, socket, malloc, pixman]) qemuutil = declare_dependency(link_with: libqemuutil, sources: genh + version_res)
stubs/meson.build +1 -0
@@ -52,6 +52,7 @@ if have_system stub_ss.add(files('semihost.c')) stub_ss.add(files('usb-dev-stub.c')) stub_ss.add(files('xen-hw-stub.c')) + stub_ss.add(files('virtio-gpu-udmabuf.c')) else stub_ss.add(files('qdev.c')) endif
Signature · 1 line
2.31.1
[PULL 01/23] vhost-user-gpu: fix memory disclosure in virgl_cmd_get_capset_info (CVE-2021-3545)
In reply to Gerd HoffmannFrom: Li Qiang <[email protected]>
Otherwise some of the 'resp' will be leaked to guest.
virtio-gpu fix: 42a8dadc74 ("virtio-gpu: fix information leak in getting capset info dispatch")
Message-Id: <[email protected]>
--- contrib/vhost-user-gpu/virgl.c | 1 + 1 file changed, 1 insertion(+)
contrib/vhost-user-gpu/virgl.c +1 -0
@@ -128,6 +128,7 @@ virgl_cmd_get_capset_info(VuGpu *g,VUGPU_FILL_CMD (info); +memset (&resp,0 ,sizeof (resp));if (info.capset_index ==0 ) { resp.capset_id =VIRTIO_GPU_CAPSET_VIRGL ; virgl_renderer_get_cap_set(resp.capset_id,
Signature · 1 line
2.31.1
[PULL 09/23] hw/display/qxl: Set pci rom address aligned with page size
In reply to Gerd HoffmannFrom: maobibo <[email protected]>
On some MIPS system, page size is 16K, and qxl vga device can be used for VM in kvm mode. Qxl pci rom size is set 8K fixed, smaller than 16K page size on host system, it fails to be added into memslots in kvm mode where memory_size and GPA are required to align with page size.
This patch fixes this issue.
Message-Id: <[email protected]>
--- hw/display/qxl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/qxl.c +1 -1
@@ -321,7 +321,7 @@ static ram_addr_t qxl_rom_size(void)#define QXL_ROM_SZ 8192QEMU_BUILD_BUG_ON (QXL_REQUIRED_SZ >QXL_ROM_SZ ); -return QXL_ROM_SZ ; +return QEMU_ALIGN_UP (QXL_REQUIRED_SZ , qemu_real_host_page_size); }static void init_qxl_rom (PCIQXLDevice *d)
Signature · 1 line
2.31.1
[PULL 05/23] vhost-user-gpu: fix memory leak in 'virgl_cmd_resource_unref' (CVE-2021-3544)
In reply to Gerd HoffmannFrom: Li Qiang <[email protected]>
The 'res->iov' will be leaked if the guest trigger following sequences:
virgl_cmd_create_resource_2d
virgl_resource_attach_backing
virgl_cmd_resource_unref
This patch fixes this.
virtio-gpu fix: 5e8e3c4c75 ("virtio-gpu: fix resource leak in virgl_cmd_resource_unref"
Message-Id: <[email protected]>
--- contrib/vhost-user-gpu/virgl.c | 7 +++++++ 1 file changed, 7 insertions(+)
contrib/vhost-user-gpu/virgl.c +7 -0
@@ -108,9 +108,16 @@ virgl_cmd_resource_unref(VuGpu *g, struct virtio_gpu_ctrl_command *cmd) {struct virtio_gpu_resource_unref unref; +struct iovec *res_iovs =NULL ; +int num_iovs =0 ;VUGPU_FILL_CMD (unref); +virgl_renderer_resource_detach_iov (unref.resource_id, + &res_iovs, + &num_iovs); +g_free (res_iovs); +virgl_renderer_resource_unref (unref.resource_id); }
Signature · 1 line
2.31.1
[PULL 18/23] virtio-gpu: Add virtio_gpu_resource_create_blob
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
This API allows Qemu to register the blob allocated by the Guest as a new resource and map its backing storage.
Message-Id: <[email protected]>
--- include/hw/virtio/virtio-gpu-bswap.h | 9 ++++ hw/display/virtio-gpu.c | 73 ++++++++++++++++++++++++++-- hw/display/trace-events | 1 + 3 files changed, 80 insertions(+), 3 deletions(-)
include/hw/virtio/virtio-gpu-bswap.h +9 -0
@@ -59,4 +59,13 @@ virtio_gpu_t2d_bswap(struct virtio_gpu_transfer_to_host_2d *t2d) le32_to_cpus(&t2d->padding); } +static inline void +virtio_gpu_create_blob_bswap (struct virtio_gpu_resource_create_blob *cblob) +{ +virtio_gpu_ctrl_hdr_bswap (&cblob->hdr); +le32_to_cpus (&cblob->resource_id); +le32_to_cpus (&cblob->blob_flags); +le64_to_cpus (&cblob->size); +} +#endif
hw/display/virtio-gpu.c +70 -3
109 lines not on this page · raw message
hw/display/trace-events +1 -0
@@ -32,6 +32,7 @@ virtio_gpu_cmd_get_edid(uint32_t scanout) "scanout %d" virtio_gpu_cmd_set_scanout(uint32_t id, uint32_t res, uint32_t w, uint32_t h, uint32_t x, uint32_t y) "id %d, res 0x%x, w %d, h %d, x %d, y %d" virtio_gpu_cmd_res_create_2d(uint32_t res, uint32_t fmt, uint32_t w, uint32_t h) "res 0x%x, fmt 0x%x, w %d, h %d" virtio_gpu_cmd_res_create_3d(uint32_t res, uint32_t fmt, uint32_t w, uint32_t h, uint32_t d) "res 0x%x, fmt 0x%x, w %d, h %d, d %d" +virtio_gpu_cmd_res_create_blob(uint32_t res, uint64_t size) "res 0x%x, size %" PRId64 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"
Signature · 1 line
2.31.1
[PULL 07/23] vhost-user-gpu: fix OOB write in 'virgl_cmd_get_capset' (CVE-2021-3546)
In reply to Gerd HoffmannFrom: Li Qiang <[email protected]>
If 'virgl_cmd_get_capset' set 'max_size' to 0,
the 'virgl_renderer_fill_caps' will write the data after the 'resp'. This patch avoid this by checking the returned 'max_size'.
virtio-gpu fix: abd7f08b23 ("display: virtio-gpu-3d: check virgl capabilities max_size")
Message-Id: <[email protected]>
--- contrib/vhost-user-gpu/virgl.c | 4 ++++ 1 file changed, 4 insertions(+)
contrib/vhost-user-gpu/virgl.c +4 -0
@@ -177,6 +177,10 @@ virgl_cmd_get_capset(VuGpu *g,virgl_renderer_get_cap_set (gc.capset_id, &max_ver, &max_size); +if (!max_size) { + cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER ; +return ; + } resp =g_malloc0 (sizeof (*resp) + max_size); resp->hdr.type =VIRTIO_GPU_RESP_OK_CAPSET ;
Signature · 1 line
2.31.1
[PULL 14/23] virtio-gpu: Add virtio_gpu_find_check_resource
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
Move finding the resource and validating its backing storage into one function.
Message-Id: <[email protected]>
--- hw/display/virtio-gpu.c | 66 +++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 19 deletions(-)
hw/display/virtio-gpu.c +47 -19
@@ -35,6 +35,10 @@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);
@@ -46,7 +50,8 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g,struct virtio_gpu_simple_resource *res;uint32_t pixels; - res =virtio_gpu_find_resource (g, resource_id); + res =virtio_gpu_find_check_resource (g, resource_id, false, + __func__,NULL );if (!res) {return ; }
@@ -114,6 +119,37 @@ virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id)return NULL ; } +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) +{ +struct virtio_gpu_simple_resource *res; + + res =virtio_gpu_find_resource (g, resource_id); +if (!res) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid resource specified %d\n" , + caller, resource_id); +if (error) { + *error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; + } +return NULL ; + } + +if (require_backing) { +if (!res->iov || !res->image) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: no backing storage %d\n" , + caller, resource_id); +if (error) { + *error =VIRTIO_GPU_RESP_ERR_UNSPEC ; + } +return NULL ; + } + } + +return res; +} + void virtio_gpu_ctrl_response(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd, struct virtio_gpu_ctrl_hdr *resp,
@@ -352,11 +388,9 @@ static void virtio_gpu_transfer_to_host_2d(VirtIOGPU *g,virtio_gpu_t2d_bswap (&t2d);trace_virtio_gpu_cmd_res_xfer_toh_2d (t2d.resource_id); - res =virtio_gpu_find_resource (g, t2d.resource_id); -if (!res || !res->iov) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: illegal resource specified %d\n" , - __func__, t2d.resource_id); - cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; + res =virtio_gpu_find_check_resource (g, t2d.resource_id, true, + __func__, &cmd->error); +if (!res) {return ; }
@@ -410,11 +444,9 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g,trace_virtio_gpu_cmd_res_flush (rf.resource_id, rf.r.width, rf.r.height, rf.r.x, rf.r.y); - res =virtio_gpu_find_resource (g, rf.resource_id); + res =virtio_gpu_find_check_resource (g, rf.resource_id, false, + __func__, &cmd->error);if (!res) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: illegal resource specified %d\n" , - __func__, rf.resource_id); - cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ;return ; }
@@ -497,11 +529,9 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, }/* create a surface for this scanout */ - res =virtio_gpu_find_resource (g, ss.resource_id); + res =virtio_gpu_find_check_resource (g, ss.resource_id, true, + __func__, &cmd->error);if (!res) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: illegal resource specified %d\n" , - __func__, ss.resource_id); - cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ;return ; }
@@ -709,11 +739,9 @@ virtio_gpu_resource_detach_backing(VirtIOGPU *g,virtio_gpu_bswap_32 (&detach,sizeof (detach));trace_virtio_gpu_cmd_res_back_detach (detach.resource_id); - res =virtio_gpu_find_resource (g, detach.resource_id); -if (!res || !res->iov) { -qemu_log_mask (LOG_GUEST_ERROR ,"%s: illegal resource specified %d\n" , - __func__, detach.resource_id); - cmd->error =VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID ; + res =virtio_gpu_find_check_resource (g, detach.resource_id, true, + __func__, &cmd->error); +if (!res) {return ; }virtio_gpu_cleanup_mapping (g, res);
Signature · 1 line
2.31.1
[PULL 08/23] vhost-user-gpu: abstract vg_cleanup_mapping_iov
In reply to Gerd HoffmannFrom: Li Qiang <[email protected]>
Currently in vhost-user-gpu, we free resource directly in the cleanup case of resource. If we change the cleanup logic we need to change several places, also abstruct a 'vg_create_mapping_iov' can be symmetry with the 'vg_create_mapping_iov'. This is like what virtio-gpu does, no function changed.
Message-Id: <[email protected]>
--- contrib/vhost-user-gpu/vugpu.h | 2 +- contrib/vhost-user-gpu/vhost-user-gpu.c | 24 ++++++++++++++++++++---- contrib/vhost-user-gpu/virgl.c | 9 +++++---- 3 files changed, 26 insertions(+), 9 deletions(-)
contrib/vhost-user-gpu/vugpu.h +1 -1
@@ -169,7 +169,7 @@ int vg_create_mapping_iov(VuGpu *g,struct virtio_gpu_resource_attach_backing *ab, struct virtio_gpu_ctrl_command *cmd, struct iovec **iov); - +void vg_cleanup_mapping_iov (VuGpu *g,struct iovec *iov,uint32_t count);void vg_get_display_info (VuGpu *vg,struct virtio_gpu_ctrl_command *cmd);void vg_wait_ok (VuGpu *g);
contrib/vhost-user-gpu/vhost-user-gpu.c +20 -4
@@ -49,6 +49,8 @@ static char *opt_render_node;static gboolean opt_virgl;static void vg_handle_ctrl (VuDev *dev,int qidx); +static void vg_cleanup_mapping (VuGpu *g, +struct virtio_gpu_simple_resource *res);static const char *vg_cmd_to_string (int cmd)
@@ -400,7 +402,7 @@ vg_resource_destroy(VuGpu *g, }vugbm_buffer_destroy (&res->buffer); -g_free (res->iov); +vg_cleanup_mapping (g, res);pixman_image_unref (res->image);QTAILQ_REMOVE (&g->reslist, res, next);g_free (res);
@@ -504,6 +506,22 @@ vg_resource_attach_backing(VuGpu *g, res->iov_cnt = ab.nr_entries; } +/* Though currently only free iov, maybe later will do more work. */ +void vg_cleanup_mapping_iov (VuGpu *g, +struct iovec *iov,uint32_t count) +{ +g_free (iov); +} + +static void +vg_cleanup_mapping (VuGpu *g, +struct virtio_gpu_simple_resource *res) +{ +vg_cleanup_mapping_iov (g, res->iov, res->iov_cnt); + res->iov =NULL ; + res->iov_cnt =0 ; +} +static void vg_resource_detach_backing (VuGpu *g,struct virtio_gpu_ctrl_command *cmd)
@@ -522,9 +540,7 @@ vg_resource_detach_backing(VuGpu *g,return ; } -g_free (res->iov); - res->iov =NULL ; - res->iov_cnt =0 ; +vg_cleanup_mapping (g, res); } static void
contrib/vhost-user-gpu/virgl.c +5 -4
@@ -116,8 +116,9 @@ virgl_cmd_resource_unref(VuGpu *g,virgl_renderer_resource_detach_iov (unref.resource_id, &res_iovs, &num_iovs); -g_free (res_iovs); - +if (res_iovs !=NULL && num_iovs !=0 ) { +vg_cleanup_mapping_iov (g, res_iovs, num_iovs); + }virgl_renderer_resource_unref (unref.resource_id); }
@@ -294,7 +295,7 @@ virgl_resource_attach_backing(VuGpu *g, ret =virgl_renderer_resource_attach_iov (att_rb.resource_id, res_iovs, att_rb.nr_entries);if (ret !=0 ) { -g_free (res_iovs); +vg_cleanup_mapping_iov (g, res_iovs, att_rb.nr_entries); } }
@@ -314,7 +315,7 @@ virgl_resource_detach_backing(VuGpu *g,if (res_iovs ==NULL || num_iovs ==0 ) {return ; } -g_free (res_iovs); +vg_cleanup_mapping_iov (g, res_iovs, num_iovs); } static void
Signature · 1 line
2.31.1
[PULL 20/23] virtio-gpu: Add helpers to create and destroy dmabuf objects
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
These helpers can be useful for creating dmabuf objects from blobs and submitting them to the UI.
Message-Id: <[email protected]>
--- include/hw/virtio/virtio-gpu.h | 15 ++++++++ hw/display/virtio-gpu-udmabuf.c | 65 +++++++++++++++++++++++++++++++++ stubs/virtio-gpu-udmabuf.c | 9 +++++ 3 files changed, 89 insertions(+)
include/hw/virtio/virtio-gpu.h +15 -0
@@ -150,6 +150,12 @@ struct VirtIOGPUBaseClass {DEFINE_PROP_UINT32 ("xres" , _state, _conf.xres,1024 ), \ DEFINE_PROP_UINT32("yres", _state, _conf.yres, 768) +typedef struct VGPUDMABuf { +QemuDmaBuf buf; +uint32_t scanout_id; +QTAILQ_ENTRY (VGPUDMABuf) next; +}VGPUDMABuf ; +struct VirtIOGPU {VirtIOGPUBase parent_obj;
@@ -178,6 +184,11 @@ struct VirtIOGPU {uint32_t req_3d;uint32_t bytes_3d; } stats; + +struct { + QTAILQ_HEAD(, VGPUDMABuf) bufs; +VGPUDMABuf *primary; + } dmabuf; };struct VirtIOGPUClass {
@@ -259,6 +270,10 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g,bool virtio_gpu_have_udmabuf (void );void virtio_gpu_init_udmabuf (struct virtio_gpu_simple_resource *res);void virtio_gpu_fini_udmabuf (struct virtio_gpu_simple_resource *res); +int virtio_gpu_update_dmabuf (VirtIOGPU *g, +uint32_t scanout_id, +struct virtio_gpu_simple_resource *res, +struct virtio_gpu_framebuffer *fb);/* virtio-gpu-3d.c */ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
hw/display/virtio-gpu-udmabuf.c +65 -0
68 lines not on this page · raw message
stubs/virtio-gpu-udmabuf.c +9 -0
@@ -16,3 +16,12 @@ void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) {/* nothing (stub) */ } + +int virtio_gpu_update_dmabuf (VirtIOGPU *g, +uint32_t scanout_id, +struct virtio_gpu_simple_resource *res, +struct virtio_gpu_framebuffer *fb) +{ +/* nothing (stub) */ +return 0 ; +}
Signature · 1 line
2.31.1
[PULL 11/23] headers: Add udmabuf.h
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
This adds udmabuf header to standard headers so that the relevant udmabuf objects can be accessed in subsequent patches.
Message-Id: <[email protected]>
--- include/standard-headers/linux/udmabuf.h | 32 ++++++++++++++++++++++++ scripts/update-linux-headers.sh | 3 +++ 2 files changed, 35 insertions(+) create mode 100644 include/standard-headers/linux/udmabuf.h
include/standard-headers/linux/udmabuf.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_UDMABUF_H +#define _LINUX_UDMABUF_H + +#include "standard-headers/linux/types.h" + +#define UDMABUF_FLAGS_CLOEXEC 0x01 + +struct udmabuf_create { +uint32_t memfd; +uint32_t flags; +uint64_t offset; +uint64_t size; +}; + +struct udmabuf_create_item { +uint32_t memfd; +uint32_t __pad; +uint64_t offset; +uint64_t size; +}; + +struct udmabuf_create_list { +uint32_t flags; +uint32_t count; +struct udmabuf_create_item list[]; +}; + +#define UDMABUF_CREATE _IOW('u', 0x42, struct udmabuf_create) +#define UDMABUF_CREATE_LIST _IOW('u', 0x43, struct udmabuf_create_list) + +#endif /* _LINUX_UDMABUF_H */
scripts/update-linux-headers.sh +3 -0
@@ -34,6 +34,7 @@ cp_portable() { if grep '#include' "$f" | grep -v -e 'linux/virtio' \ -e 'linux/types' \ + -e 'linux/ioctl' \ -e 'stdint' \ -e 'linux/if_ether' \ -e 'input-event-codes' \
@@ -66,6 +67,7 @@ cp_portable() { -e 's/__BITS_PER_LONG/HOST_LONG_BITS/' \ -e '/\"drm.h\"/d' \ -e '/sys\/ioctl.h/d' \ + -e '/linux\/ioctl.h/d' \ -e 's/SW_MAX/SW_MAX_/' \ -e 's/atomic_t/int/' \ -e 's/__kernel_long_t/long/' \
@@ -190,6 +192,7 @@ for i in "$tmpdir"/include/linux/*virtio*.h \ "$tmpdir/include/linux/fuse.h" \ "$tmpdir/include/linux/input.h" \ "$tmpdir/include/linux/input-event-codes.h" \ + "$tmpdir/include/linux/udmabuf.h" \ "$tmpdir/include/linux/pci_regs.h" \ "$tmpdir/include/linux/ethtool.h" \ "$tmpdir/include/linux/const.h" \
Signature · 1 line
2.31.1
[PULL 16/23] virtio-gpu: Refactor virtio_gpu_create_mapping_iov
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
Instead of passing the attach_backing object to extract nr_entries and offset, explicitly pass these as arguments to this function. This will be helpful when adding create_blob API.
Message-Id: <[email protected]>
--- include/hw/virtio/virtio-gpu.h | 2 +- hw/display/virtio-gpu-virgl.c | 3 ++- hw/display/virtio-gpu.c | 19 +++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-)
include/hw/virtio/virtio-gpu.h +1 -1
@@ -238,7 +238,7 @@ void virtio_gpu_get_display_info(VirtIOGPU *g,void virtio_gpu_get_edid (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd);int virtio_gpu_create_mapping_iov (VirtIOGPU *g, -struct virtio_gpu_resource_attach_backing *ab, +uint32_t nr_entries,uint32_t offset,struct virtio_gpu_ctrl_command *cmd,uint64_t **addr,struct iovec **iov,uint32_t *niov);
hw/display/virtio-gpu-virgl.c +2 -1
@@ -289,7 +289,8 @@ static void virgl_resource_attach_backing(VirtIOGPU *g,VIRTIO_GPU_FILL_CMD (att_rb);trace_virtio_gpu_cmd_res_back_attach (att_rb.resource_id); - ret =virtio_gpu_create_mapping_iov (g, &att_rb, cmd,NULL , &res_iovs, &res_niov); + ret =virtio_gpu_create_mapping_iov (g, att_rb.nr_entries,sizeof (att_rb), + cmd,NULL , &res_iovs, &res_niov);if (ret !=0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ;
hw/display/virtio-gpu.c +9 -10
@@ -615,7 +615,7 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, }int virtio_gpu_create_mapping_iov (VirtIOGPU *g, -struct virtio_gpu_resource_attach_backing *ab, +uint32_t nr_entries,uint32_t offset,struct virtio_gpu_ctrl_command *cmd,uint64_t **addr,struct iovec **iov,uint32_t *niov)
@@ -624,17 +624,17 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g,size_t esize, s;int e, v; -if (ab->nr_entries >16384 ) { +if (nr_entries >16384 ) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: nr_entries is too big (%d > 16384)\n" , - __func__, ab->nr_entries); + __func__, nr_entries);return -1 ; } - esize =sizeof (*ents) * ab->nr_entries; + esize =sizeof (*ents) * nr_entries; ents =g_malloc (esize); s =iov_to_buf (cmd->elem.out_sg, cmd->elem.out_num, -sizeof (*ab), ents, esize); + offset, ents, esize);if (s != esize) { qemu_log_mask(LOG_GUEST_ERROR, "%s: command data size incorrect %zu vs %zu\n",
@@ -647,7 +647,7 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g,if (addr) { *addr =NULL ; } -for (e =0 , v =0 ; e < ab->nr_entries; e++) { +for (e =0 , v =0 ; e < nr_entries; e++) {uint64_t a =le64_to_cpu (ents[e].addr);uint32_t l =le32_to_cpu (ents[e].length);hwaddr len;
@@ -659,8 +659,7 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, a, &len, DMA_DIRECTION_TO_DEVICE);if (!map) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: failed to map MMIO memory for" -" resource %d element %d\n" , - __func__, ab->resource_id, e); +" element %d\n" , __func__, e);virtio_gpu_cleanup_mapping_iov (g, *iov, v);g_free (ents); *iov =NULL ;
@@ -743,8 +742,8 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g,return ; } - ret =virtio_gpu_create_mapping_iov (g, &ab, cmd, &res->addrs, - &res->iov, &res->iov_cnt); + ret =virtio_gpu_create_mapping_iov (g, ab.nr_entries,sizeof (ab), cmd, + &res->addrs, &res->iov, &res->iov_cnt);if (ret !=0 ) { cmd->error =VIRTIO_GPU_RESP_ERR_UNSPEC ;return ;
Signature · 1 line
2.31.1
[PULL 10/23] ui: Get the fd associated with udmabuf driver
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
Try to open the udmabuf dev node for the first time or return the fd if the device was previously opened.
Message-Id: <[email protected]>
[ kraxel: fixup fcntl.h include ]
--- include/ui/console.h | 3 +++ ui/udmabuf.c | 40 ++++++++++++++++++++++++++++++++++++++++ ui/meson.build | 1 + 3 files changed, 44 insertions(+) create mode 100644 ui/udmabuf.c
include/ui/console.h +3 -0
@@ -471,4 +471,7 @@ bool vnc_display_reload_certs(const char *id, Error **errp);/* input.c */ int index_from_key (const char *key,size_t key_length); +/* udmabuf.c */ +int udmabuf_fd (void ); +#endif
ui/udmabuf.c new file +40 -0
@@ -0,0 +1,40 @@ +/* +* udmabuf helper functions. +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "ui/console.h" + +#ifdef CONFIG_LINUX + +#include <fcntl.h> +#include <sys/ioctl.h> + +int udmabuf_fd (void ) +{ +static bool first = true; +static int udmabuf; + +if (!first) { +return udmabuf; + } + first = false; + + udmabuf =open ("/dev/udmabuf" ,O_RDWR ); +if (udmabuf <0 ) { +warn_report ("open /dev/udmabuf: %s" ,strerror (errno)); + } +return udmabuf; +} + +#else + +int udmabuf_fd (void ) +{ +return -1 ; +} + +#endif
ui/meson.build +1 -0
@@ -12,6 +12,7 @@ softmmu_ss.add(files( 'kbd-state.c', 'keymaps.c', 'qemu-pixman.c', + 'udmabuf.c', )) softmmu_ss.add([spice_headers, files('spice-module.c')]) softmmu_ss.add(when: spice_protocol, if_true: files('vdagent.c'))
Signature · 1 line
2.31.1
[PULL 12/23] virtio-gpu: Add udmabuf helpers
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
Add helper functions to create a dmabuf for a resource and mmap it. Also, introduce the fields blob and blob_size so that these helpers can start to use them but the full picture will emerge only after adding create_blob API in patch 8 of this series.
To be able to create a dmabuf using the udmabuf driver, Qemu needs to be lauched with the memfd memory backend like this:
qemu-system-x86_64 -m 8192m -object memory-backend-memfd,id=mem1,size=8192M -machine memory-backend=mem1
Message-Id: <[email protected]>
--- include/hw/virtio/virtio-gpu.h | 11 +++ hw/display/virtio-gpu-udmabuf.c | 158 ++++++++++++++++++++++++++++++++ hw/display/meson.build | 1 + 3 files changed, 170 insertions(+) create mode 100644 hw/display/virtio-gpu-udmabuf.c
include/hw/virtio/virtio-gpu.h +11 -0
@@ -50,6 +50,12 @@ struct virtio_gpu_simple_resource {uint32_t scanout_bitmask;pixman_image_t *image;uint64_t hostmem; + +uint64_t blob_size; +void *blob; +int dmabuf_fd; +uint8_t *remapped; +QTAILQ_ENTRY (virtio_gpu_simple_resource) next; };
@@ -238,6 +244,11 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g,struct virtio_gpu_scanout *s, uint32_t resource_id); +/* virtio-gpu-udmabuf.c */ +bool virtio_gpu_have_udmabuf (void ); +void virtio_gpu_init_udmabuf (struct virtio_gpu_simple_resource *res); +void virtio_gpu_fini_udmabuf (struct virtio_gpu_simple_resource *res); +/* virtio-gpu-3d.c */ void virtio_gpu_virgl_process_cmd (VirtIOGPU *g,struct virtio_gpu_ctrl_command *cmd);
hw/display/virtio-gpu-udmabuf.c new file +158 -0
158 lines not on this page · raw message
hw/display/meson.build +1 -0
@@ -56,6 +56,7 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss = ss.source_set() virtio_gpu_ss.add(when: 'CONFIG_VIRTIO_GPU', if_true: [files('virtio-gpu-base.c', 'virtio-gpu.c'), pixman]) + virtio_gpu_ss.add(when: 'CONFIG_LINUX', if_true: files('virtio-gpu-udmabuf.c')) virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-user-gpu.c')) hw_display_modules += {'virtio-gpu': virtio_gpu_ss}
Signature · 1 line
2.31.1
[PULL 17/23] virtio-gpu: Add initial definitions for blob resources
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
Add the property bit, configuration flag and other relevant macros and definitions associated with this feature.
Message-Id: <[email protected]>
--- include/hw/virtio/virtio-gpu.h | 3 +++ hw/display/virtio-gpu-base.c | 3 +++ hw/display/virtio-gpu.c | 14 ++++++++++++++ 3 files changed, 20 insertions(+)
include/hw/virtio/virtio-gpu.h +3 -0
@@ -89,6 +89,7 @@ enum virtio_gpu_base_conf_flags {VIRTIO_GPU_FLAG_STATS_ENABLED ,VIRTIO_GPU_FLAG_EDID_ENABLED ,VIRTIO_GPU_FLAG_DMABUF_ENABLED , + VIRTIO_GPU_FLAG_BLOB_ENABLED, };#define virtio_gpu_virgl_enabled (_cfg) \
@@ -99,6 +100,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_EDID_ENABLED))#define virtio_gpu_dmabuf_enabled (_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED)) +#define virtio_gpu_blob_enabled (_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED))struct virtio_gpu_base_conf {uint32_t max_outputs;
hw/display/virtio-gpu-base.c +3 -0
@@ -208,6 +208,9 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64_t features,if (virtio_gpu_edid_enabled (g->conf)) { features |= (1 <<VIRTIO_GPU_F_EDID ); } +if (virtio_gpu_blob_enabled (g->conf)) { + features |= (1 <<VIRTIO_GPU_F_RESOURCE_BLOB ); + }return features; }
hw/display/virtio-gpu.c +14 -0
@@ -1108,6 +1108,18 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)VirtIODevice *vdev =VIRTIO_DEVICE (qdev);VirtIOGPU *g =VIRTIO_GPU (qdev); +if (virtio_gpu_blob_enabled (g->parent_obj.conf)) { +if (!virtio_gpu_have_udmabuf ()) { +error_setg (errp,"cannot enable blob resources without udmabuf" ); +return ; + } + +if (virtio_gpu_virgl_enabled (g->parent_obj.conf)) { +error_setg (errp,"blobs and virgl are not compatible (yet)" ); +return ; + } + } + if (!virtio_gpu_base_device_realize(qdev, virtio_gpu_handle_ctrl_cb, virtio_gpu_handle_cursor_cb,
@@ -1201,6 +1213,8 @@ static Property virtio_gpu_properties[] = {VIRTIO_GPU_BASE_PROPERTIES (VirtIOGPU, parent_obj.conf),DEFINE_PROP_SIZE ("max_hostmem" , VirtIOGPU, conf_max_hostmem,256 * MiB), +DEFINE_PROP_BIT ("blob" , VirtIOGPU, parent_obj.conf.flags, +VIRTIO_GPU_FLAG_BLOB_ENABLED , false), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
2.31.1
[PULL 21/23] virtio-gpu: Factor out update scanout
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
Creating a small helper function for updating the scanout will be useful in the next patch where this needs to be done early in do_set_scanout before returning.
Message-Id: <[email protected]>
--- hw/display/virtio-gpu.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)
hw/display/virtio-gpu.c +23 -12
@@ -556,6 +556,28 @@ static void virtio_unref_resource(pixman_image_t *image, void *data)pixman_image_unref (data); } +static void virtio_gpu_update_scanout (VirtIOGPU *g, +uint32_t scanout_id, +struct virtio_gpu_simple_resource *res, +struct virtio_gpu_rect *r) +{ +struct virtio_gpu_simple_resource *ores; +struct virtio_gpu_scanout *scanout; + + scanout = &g->parent_obj.scanout[scanout_id]; + ores =virtio_gpu_find_resource (g, scanout->resource_id); +if (ores) { + ores->scanout_bitmask &= ~(1 << scanout_id); + } + + res->scanout_bitmask |= (1 << scanout_id); + scanout->resource_id = res->resource_id; + scanout->x = r->x; + scanout->y = r->y; + scanout->width = r->width; + scanout->height = r->height; +} + static void virtio_gpu_do_set_scanout(VirtIOGPU *g, uint32_t scanout_id, struct virtio_gpu_framebuffer *fb,
@@ -563,7 +585,6 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g,struct virtio_gpu_rect *r, uint32_t *error) { - struct virtio_gpu_simple_resource *ores; struct virtio_gpu_scanout *scanout;uint8_t *data;
@@ -623,17 +644,7 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g, scanout->ds); } - ores =virtio_gpu_find_resource (g, scanout->resource_id); -if (ores) { - ores->scanout_bitmask &= ~(1 << scanout_id); - } - - res->scanout_bitmask |= (1 << scanout_id); - scanout->resource_id = res->resource_id; - scanout->x = r->x; - scanout->y = r->y; - scanout->width = r->width; - scanout->height = r->height; +virtio_gpu_update_scanout (g, scanout_id, res, r); } static void virtio_gpu_set_scanout(VirtIOGPU *g,
Signature · 1 line
2.31.1
[PULL 15/23] virtio-gpu: Refactor virtio_gpu_set_scanout
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
Store the meta-data associated with a FB in a new object (struct virtio_gpu_framebuffer) and pass the object to set_scanout. Also move code in set_scanout into a do_set_scanout function. This will be helpful when adding set_scanout_blob API.
Message-Id: <[email protected]>
--- include/hw/virtio/virtio-gpu.h | 8 ++ hw/display/virtio-gpu.c | 153 +++++++++++++++++++-------------- 2 files changed, 96 insertions(+), 65 deletions(-)
include/hw/virtio/virtio-gpu.h +8 -0
@@ -59,6 +59,14 @@ struct virtio_gpu_simple_resource {QTAILQ_ENTRY (virtio_gpu_simple_resource) next; }; +struct virtio_gpu_framebuffer { +pixman_format_code_t format; +uint32_t bytes_pp; +uint32_t width, height; +uint32_t stride; +uint32_t offset; +}; +struct virtio_gpu_scanout {QemuConsole *con;DisplaySurface *ds;
hw/display/virtio-gpu.c +88 -65
183 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PULL 15/23] virtio-gpu: Refactor virtio_gpu_set_scanout
Quoted 7 lines · Gerd Hoffmann
From: Vivek Kasireddy <[email protected]>
Store the meta-data associated with a FB in a new object (struct
virtio_gpu_framebuffer) and pass the object toset_scanout. Also move code inset_scanoutinto ado_set_scanoutfunction. This will be helpful when addingset_scanout_blobAPI.
Quoted 6 lines
Based-on-patch-by Gerd Hoffmann <[email protected]>Cc Gerd Hoffmann <[email protected]>Signed-off-by Vivek Kasireddy <[email protected]>Message-Id: <[email protected]>
Signed-off-by Gerd Hoffmann <[email protected]>---
Hi,
Recently OSS-Fuzz found a heap-overflow in virtio_gpu_disable_scanout. I bisected it to this patch:
https://gitlab.com/qemu-project/qemu/-/issues/383
-Alex
[PULL 19/23] ui/pixman: Add qemu_pixman_to_drm_format()
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
This new function to get the drm_format associated with a pixman format will be useful while creating a dmabuf.
Message-Id: <[email protected]>
--- include/ui/qemu-pixman.h | 1 + ui/qemu-pixman.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-)
include/ui/qemu-pixman.h +1 -0
@@ -62,6 +62,7 @@ typedef struct PixelFormat {PixelFormat qemu_pixelformat_from_pixman (pixman_format_code_t format);pixman_format_code_t qemu_default_pixman_format (int bpp,bool native_endian);pixman_format_code_t qemu_drm_format_to_pixman (uint32_t drm_format); +uint32_t qemu_pixman_to_drm_format (pixman_format_code_t pixman);int qemu_pixman_get_type (int rshift,int gshift,int bshift);pixman_format_code_t qemu_pixman_get_format (PixelFormat *pf); bool qemu_pixman_check_format(DisplayChangeListener *dcl,
ui/qemu-pixman.c +24 -11
@@ -89,21 +89,34 @@ pixman_format_code_t qemu_default_pixman_format(int bpp, bool native_endian) }/* Note: drm is little endian, pixman is native endian */ +static const struct { +uint32_t drm_format; +pixman_format_code_t pixman_format; +} drm_format_pixman_map[] = { + {DRM_FORMAT_RGB888 , PIXMAN_LE_r8g8b8 }, + {DRM_FORMAT_ARGB8888 , PIXMAN_LE_a8r8g8b8 }, + {DRM_FORMAT_XRGB8888 , PIXMAN_LE_x8r8g8b8 } +}; +pixman_format_code_t qemu_drm_format_to_pixman (uint32_t drm_format) { -static const struct { -uint32_t drm_format; -pixman_format_code_t pixman; - } map[] = { - {DRM_FORMAT_RGB888 , PIXMAN_LE_r8g8b8 }, - {DRM_FORMAT_ARGB8888 , PIXMAN_LE_a8r8g8b8 }, - {DRM_FORMAT_XRGB8888 , PIXMAN_LE_x8r8g8b8 } - };int i; -for (i =0 ; i <ARRAY_SIZE (map); i++) { -if (drm_format == map[i].drm_format) { -return map[i].pixman; +for (i =0 ; i <ARRAY_SIZE (drm_format_pixman_map); i++) { +if (drm_format == drm_format_pixman_map[i].drm_format) { +return drm_format_pixman_map[i].pixman_format; + } + } +return 0 ; +} + +uint32_t qemu_pixman_to_drm_format (pixman_format_code_t pixman_format) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (drm_format_pixman_map); i++) { +if (pixman_format == drm_format_pixman_map[i].pixman_format) { +return drm_format_pixman_map[i].drm_format; } }return 0 ;
Signature · 1 line
2.31.1
[PULL 22/23] virtio-gpu: Add virtio_gpu_set_scanout_blob
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
This API allows Qemu to set the blob allocated by the Guest as the scanout buffer. If Opengl support is available, then the scanout buffer would be submitted as a dmabuf to the UI; if not, a pixman image is created from the scanout buffer and is submitted to the UI via the display surface.
Message-Id: <[email protected]>
--- include/hw/virtio/virtio-gpu-bswap.h | 7 ++ hw/display/virtio-gpu.c | 102 +++++++++++++++++++++++++-- hw/display/trace-events | 1 + 3 files changed, 103 insertions(+), 7 deletions(-)
include/hw/virtio/virtio-gpu-bswap.h +7 -0
@@ -68,4 +68,11 @@ virtio_gpu_create_blob_bswap(struct virtio_gpu_resource_create_blob *cblob) le64_to_cpus(&cblob->size); } +static inline void +virtio_gpu_scanout_blob_bswap (struct virtio_gpu_set_scanout_blob *ssb) +{ +virtio_gpu_bswap_32 (ssb,sizeof (*ssb) -sizeof (ssb->offsets[3 ])); +le32_to_cpus (&ssb->offsets[3 ]); +} +#endif
hw/display/virtio-gpu.c +95 -7
153 lines not on this page · raw message
hw/display/trace-events +1 -0
@@ -30,6 +30,7 @@ virtio_gpu_features(bool virgl) "virgl %d" virtio_gpu_cmd_get_display_info(void) "" virtio_gpu_cmd_get_edid(uint32_t scanout) "scanout %d" virtio_gpu_cmd_set_scanout(uint32_t id, uint32_t res, uint32_t w, uint32_t h, uint32_t x, uint32_t y) "id %d, res 0x%x, w %d, h %d, x %d, y %d" +virtio_gpu_cmd_set_scanout_blob(uint32_t id, uint32_t res, uint32_t w, uint32_t h, uint32_t x, uint32_t y) "id %d, res 0x%x, w %d, h %d, x %d, y %d" virtio_gpu_cmd_res_create_2d(uint32_t res, uint32_t fmt, uint32_t w, uint32_t h) "res 0x%x, fmt 0x%x, w %d, h %d" virtio_gpu_cmd_res_create_3d(uint32_t res, uint32_t fmt, uint32_t w, uint32_t h, uint32_t d) "res 0x%x, fmt 0x%x, w %d, h %d, d %d" virtio_gpu_cmd_res_create_blob(uint32_t res, uint64_t size) "res 0x%x, size %" PRId64
Signature · 1 line
2.31.1
[PULL 23/23] virtio-gpu: Update cursor data using blob
In reply to Gerd HoffmannFrom: Vivek Kasireddy <[email protected]>
If a blob is available for the cursor, copy the data from the blob.
Message-Id: <[email protected]>
--- hw/display/virtio-gpu.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
hw/display/virtio-gpu.c +14 -5
@@ -49,6 +49,7 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, {struct virtio_gpu_simple_resource *res;uint32_t pixels; +void *data; res =virtio_gpu_find_check_resource (g, resource_id, false, __func__,NULL );
@@ -56,14 +57,22 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g,return ; } -if (pixman_image_get_width (res->image) != s->current_cursor->width || -pixman_image_get_height (res->image) != s->current_cursor->height) { -return ; +if (res->blob_size) { +if (res->blob_size < (s->current_cursor->width * + s->current_cursor->height *4 )) { +return ; + } + data = res->blob; + }else { +if (pixman_image_get_width (res->image) != s->current_cursor->width || +pixman_image_get_height (res->image) != s->current_cursor->height) { +return ; + } + data =pixman_image_get_data (res->image); } pixels = s->current_cursor->width * s->current_cursor->height; -memcpy (s->current_cursor->data, -pixman_image_get_data (res->image), +memcpy (s->current_cursor->data, data, pixels *sizeof (uint32_t )); }
Signature · 1 line
2.31.1
Peter Maydell
AppliedQuoted 11 lines · Gerd Hoffmann
The following changes since commit
2ab2dad01f6dc3667c0d53d2b1ba46b511031207:Merge remote-tracking branch 'remotes/kraxel/tags/input-20210526-pull-request' into staging (2021-05-26 15:27:20 +0100)
are available in the Git repository at:
git://git.kraxel.org/qemutags/vga-20210527-pull-requestfor you to fetch changes up to
bdd53f739273e97b5e5617b699d1763c42a5ea7e:
Quoted 8 lines
virtio-gpu: Update cursor data using blob (2021-05-27 12:07:37 +0200)
----------------------------------------------------------------
virtio-gpu: add blob resource support.
vhost-user-gpu: security fixes.----------------------------------------------------------------
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/6.1
for any user-visible changes.
-- PMM