mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge remote-tracking branch 'remotes/kraxel/tags/vga-20210527-pull-request' into staging
virtio-gpu: add blob resource support. vhost-user-gpu: security fixes. # gpg: Signature made Thu 27 May 2021 15:23:25 BST # gpg: using RSA key A0328CFFB93A17A79901FE7D4CB6D8EED3E87138 # gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>" [full] # gpg: aka "Gerd Hoffmann <gerd@kraxel.org>" [full] # gpg: aka "Gerd Hoffmann (private) <kraxel@gmail.com>" [full] # Primary key fingerprint: A032 8CFF B93A 17A7 9901 FE7D 4CB6 D8EE D3E8 7138 * remotes/kraxel/tags/vga-20210527-pull-request: (23 commits) virtio-gpu: Update cursor data using blob virtio-gpu: Add virtio_gpu_set_scanout_blob virtio-gpu: Factor out update scanout virtio-gpu: Add helpers to create and destroy dmabuf objects ui/pixman: Add qemu_pixman_to_drm_format() virtio-gpu: Add virtio_gpu_resource_create_blob virtio-gpu: Add initial definitions for blob resources virtio-gpu: Refactor virtio_gpu_create_mapping_iov virtio-gpu: Refactor virtio_gpu_set_scanout virtio-gpu: Add virtio_gpu_find_check_resource stubs: Add stubs for udmabuf helpers virtio-gpu: Add udmabuf helpers headers: Add udmabuf.h ui: Get the fd associated with udmabuf driver hw/display/qxl: Set pci rom address aligned with page size vhost-user-gpu: abstract vg_cleanup_mapping_iov vhost-user-gpu: fix OOB write in 'virgl_cmd_get_capset' (CVE-2021-3546) vhost-user-gpu: fix memory leak in 'virgl_resource_attach_backing' (CVE-2021-3544) vhost-user-gpu: fix memory leak in 'virgl_cmd_resource_unref' (CVE-2021-3544) vhost-user-gpu: fix memory leak while calling 'vg_resource_unref' (CVE-2021-3544) ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
@@ -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)
|
||||
@@ -349,6 +351,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;
|
||||
}
|
||||
@@ -399,6 +402,7 @@ vg_resource_destroy(VuGpu *g,
|
||||
}
|
||||
|
||||
vugbm_buffer_destroy(&res->buffer);
|
||||
vg_cleanup_mapping(g, res);
|
||||
pixman_image_unref(res->image);
|
||||
QTAILQ_REMOVE(&g->reslist, res, next);
|
||||
g_free(res);
|
||||
@@ -488,6 +492,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;
|
||||
@@ -497,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)
|
||||
@@ -515,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
|
||||
|
||||
@@ -108,9 +108,17 @@ 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);
|
||||
if (res_iovs != NULL && num_iovs != 0) {
|
||||
vg_cleanup_mapping_iov(g, res_iovs, num_iovs);
|
||||
}
|
||||
virgl_renderer_resource_unref(unref.resource_id);
|
||||
}
|
||||
|
||||
@@ -128,6 +136,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,
|
||||
@@ -169,6 +178,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;
|
||||
@@ -279,8 +292,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) {
|
||||
vg_cleanup_mapping_iov(g, res_iovs, att_rb.nr_entries);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -299,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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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}
|
||||
|
||||
|
||||
+1
-1
@@ -321,7 +321,7 @@ static ram_addr_t qxl_rom_size(void)
|
||||
#define QXL_ROM_SZ 8192
|
||||
|
||||
QEMU_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)
|
||||
|
||||
@@ -30,8 +30,10 @@ 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
|
||||
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"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Virtio GPU Device
|
||||
*
|
||||
* Copyright Red Hat, Inc. 2013-2014
|
||||
*
|
||||
* Authors:
|
||||
* Dave Airlie <airlied@redhat.com>
|
||||
* Gerd Hoffmann <kraxel@redhat.com>
|
||||
*
|
||||
* 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 "qemu/units.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/iov.h"
|
||||
#include "ui/console.h"
|
||||
#include "hw/virtio/virtio-gpu.h"
|
||||
#include "hw/virtio/virtio-gpu-pixman.h"
|
||||
#include "trace.h"
|
||||
#include "exec/ramblock.h"
|
||||
#include "sysemu/hostmem.h"
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/memfd.h>
|
||||
#include "qemu/memfd.h"
|
||||
#include "standard-headers/linux/udmabuf.h"
|
||||
|
||||
static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *res)
|
||||
{
|
||||
struct udmabuf_create_list *list;
|
||||
RAMBlock *rb;
|
||||
ram_addr_t offset;
|
||||
int udmabuf, i;
|
||||
|
||||
udmabuf = udmabuf_fd();
|
||||
if (udmabuf < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
list = g_malloc0(sizeof(struct udmabuf_create_list) +
|
||||
sizeof(struct udmabuf_create_item) * res->iov_cnt);
|
||||
|
||||
for (i = 0; i < res->iov_cnt; i++) {
|
||||
rcu_read_lock();
|
||||
rb = qemu_ram_block_from_host(res->iov[i].iov_base, false, &offset);
|
||||
rcu_read_unlock();
|
||||
|
||||
if (!rb || rb->fd < 0) {
|
||||
g_free(list);
|
||||
return;
|
||||
}
|
||||
|
||||
list->list[i].memfd = rb->fd;
|
||||
list->list[i].offset = offset;
|
||||
list->list[i].size = res->iov[i].iov_len;
|
||||
}
|
||||
|
||||
list->count = res->iov_cnt;
|
||||
list->flags = UDMABUF_FLAGS_CLOEXEC;
|
||||
|
||||
res->dmabuf_fd = ioctl(udmabuf, UDMABUF_CREATE_LIST, list);
|
||||
if (res->dmabuf_fd < 0) {
|
||||
warn_report("%s: UDMABUF_CREATE_LIST: %s", __func__,
|
||||
strerror(errno));
|
||||
}
|
||||
g_free(list);
|
||||
}
|
||||
|
||||
static void virtio_gpu_remap_udmabuf(struct virtio_gpu_simple_resource *res)
|
||||
{
|
||||
res->remapped = mmap(NULL, res->blob_size, PROT_READ,
|
||||
MAP_SHARED, res->dmabuf_fd, 0);
|
||||
if (res->remapped == MAP_FAILED) {
|
||||
warn_report("%s: dmabuf mmap failed: %s", __func__,
|
||||
strerror(errno));
|
||||
res->remapped = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void virtio_gpu_destroy_udmabuf(struct virtio_gpu_simple_resource *res)
|
||||
{
|
||||
if (res->remapped) {
|
||||
munmap(res->remapped, res->blob_size);
|
||||
res->remapped = NULL;
|
||||
}
|
||||
if (res->dmabuf_fd >= 0) {
|
||||
close(res->dmabuf_fd);
|
||||
res->dmabuf_fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int find_memory_backend_type(Object *obj, void *opaque)
|
||||
{
|
||||
bool *memfd_backend = opaque;
|
||||
int ret;
|
||||
|
||||
if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
|
||||
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
||||
RAMBlock *rb = backend->mr.ram_block;
|
||||
|
||||
if (rb && rb->fd > 0) {
|
||||
ret = fcntl(rb->fd, F_GET_SEALS);
|
||||
if (ret > 0) {
|
||||
*memfd_backend = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool virtio_gpu_have_udmabuf(void)
|
||||
{
|
||||
Object *memdev_root;
|
||||
int udmabuf;
|
||||
bool memfd_backend = false;
|
||||
|
||||
udmabuf = udmabuf_fd();
|
||||
if (udmabuf < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memdev_root = object_resolve_path("/objects", NULL);
|
||||
object_child_foreach(memdev_root, find_memory_backend_type, &memfd_backend);
|
||||
|
||||
return memfd_backend;
|
||||
}
|
||||
|
||||
void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res)
|
||||
{
|
||||
void *pdata = NULL;
|
||||
|
||||
res->dmabuf_fd = -1;
|
||||
if (res->iov_cnt == 1) {
|
||||
pdata = res->iov[0].iov_base;
|
||||
} else {
|
||||
virtio_gpu_create_udmabuf(res);
|
||||
if (res->dmabuf_fd < 0) {
|
||||
return;
|
||||
}
|
||||
virtio_gpu_remap_udmabuf(res);
|
||||
if (!res->remapped) {
|
||||
return;
|
||||
}
|
||||
pdata = res->remapped;
|
||||
}
|
||||
|
||||
res->blob = pdata;
|
||||
}
|
||||
|
||||
void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res)
|
||||
{
|
||||
if (res->remapped) {
|
||||
virtio_gpu_destroy_udmabuf(res);
|
||||
}
|
||||
}
|
||||
|
||||
static void virtio_gpu_free_dmabuf(VirtIOGPU *g, VGPUDMABuf *dmabuf)
|
||||
{
|
||||
struct virtio_gpu_scanout *scanout;
|
||||
|
||||
scanout = &g->parent_obj.scanout[dmabuf->scanout_id];
|
||||
dpy_gl_release_dmabuf(scanout->con, &dmabuf->buf);
|
||||
QTAILQ_REMOVE(&g->dmabuf.bufs, dmabuf, next);
|
||||
g_free(dmabuf);
|
||||
}
|
||||
|
||||
static VGPUDMABuf
|
||||
*virtio_gpu_create_dmabuf(VirtIOGPU *g,
|
||||
uint32_t scanout_id,
|
||||
struct virtio_gpu_simple_resource *res,
|
||||
struct virtio_gpu_framebuffer *fb)
|
||||
{
|
||||
VGPUDMABuf *dmabuf;
|
||||
|
||||
if (res->dmabuf_fd < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dmabuf = g_new0(VGPUDMABuf, 1);
|
||||
dmabuf->buf.width = fb->width;
|
||||
dmabuf->buf.height = fb->height;
|
||||
dmabuf->buf.stride = fb->stride;
|
||||
dmabuf->buf.fourcc = qemu_pixman_to_drm_format(fb->format);
|
||||
dmabuf->buf.fd = res->dmabuf_fd;
|
||||
|
||||
dmabuf->scanout_id = scanout_id;
|
||||
QTAILQ_INSERT_HEAD(&g->dmabuf.bufs, dmabuf, next);
|
||||
|
||||
return dmabuf;
|
||||
}
|
||||
|
||||
int virtio_gpu_update_dmabuf(VirtIOGPU *g,
|
||||
uint32_t scanout_id,
|
||||
struct virtio_gpu_simple_resource *res,
|
||||
struct virtio_gpu_framebuffer *fb)
|
||||
{
|
||||
struct virtio_gpu_scanout *scanout = &g->parent_obj.scanout[scanout_id];
|
||||
VGPUDMABuf *new_primary, *old_primary = NULL;
|
||||
|
||||
new_primary = virtio_gpu_create_dmabuf(g, scanout_id, res, fb);
|
||||
if (!new_primary) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (g->dmabuf.primary) {
|
||||
old_primary = g->dmabuf.primary;
|
||||
}
|
||||
|
||||
g->dmabuf.primary = new_primary;
|
||||
qemu_console_resize(scanout->con,
|
||||
new_primary->buf.width,
|
||||
new_primary->buf.height);
|
||||
dpy_gl_scanout_dmabuf(scanout->con, &new_primary->buf);
|
||||
|
||||
if (old_primary) {
|
||||
virtio_gpu_free_dmabuf(g, old_primary);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
+338
-99
File diff suppressed because it is too large
Load Diff
@@ -59,4 +59,20 @@ 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);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -50,9 +50,23 @@ 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;
|
||||
};
|
||||
|
||||
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;
|
||||
@@ -75,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) \
|
||||
@@ -85,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;
|
||||
@@ -133,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;
|
||||
|
||||
@@ -161,6 +184,11 @@ struct VirtIOGPU {
|
||||
uint32_t req_3d;
|
||||
uint32_t bytes_3d;
|
||||
} stats;
|
||||
|
||||
struct {
|
||||
QTAILQ_HEAD(, VGPUDMABuf) bufs;
|
||||
VGPUDMABuf *primary;
|
||||
} dmabuf;
|
||||
};
|
||||
|
||||
struct VirtIOGPUClass {
|
||||
@@ -224,7 +252,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);
|
||||
@@ -238,6 +266,15 @@ 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);
|
||||
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,
|
||||
struct virtio_gpu_ctrl_command *cmd);
|
||||
|
||||
@@ -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 */
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
+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)
|
||||
|
||||
|
||||
@@ -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" \
|
||||
|
||||
@@ -53,6 +53,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
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#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) */
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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'))
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user