[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 16/23] virtio-gpu: Refactor virtio_gpu_create_mapping_iov
From: |
Gerd Hoffmann |
Subject: |
[PULL 16/23] virtio-gpu: Refactor virtio_gpu_create_mapping_iov |
Date: |
Thu, 27 May 2021 16:23:33 +0200 |
From: Vivek Kasireddy <vivek.kasireddy@intel.com>
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.
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
Message-Id: <20210526231429.1045476-8-vivek.kasireddy@intel.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
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(-)
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index b83a91a67f3a..dad9a1d221f9 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -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);
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 72c14d91324b..092c6dc380d9 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -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;
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index fdcedfc61e54..7a0db3a8602e 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -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;
--
2.31.1
- [PULL 06/23] vhost-user-gpu: fix memory leak in 'virgl_resource_attach_backing' (CVE-2021-3544), (continued)
- [PULL 06/23] vhost-user-gpu: fix memory leak in 'virgl_resource_attach_backing' (CVE-2021-3544), Gerd Hoffmann, 2021/05/27
- [PULL 05/23] vhost-user-gpu: fix memory leak in 'virgl_cmd_resource_unref' (CVE-2021-3544), Gerd Hoffmann, 2021/05/27
- [PULL 08/23] vhost-user-gpu: abstract vg_cleanup_mapping_iov, Gerd Hoffmann, 2021/05/27
- [PULL 07/23] vhost-user-gpu: fix OOB write in 'virgl_cmd_get_capset' (CVE-2021-3546), Gerd Hoffmann, 2021/05/27
- [PULL 11/23] headers: Add udmabuf.h, Gerd Hoffmann, 2021/05/27
- [PULL 10/23] ui: Get the fd associated with udmabuf driver, Gerd Hoffmann, 2021/05/27
- [PULL 12/23] virtio-gpu: Add udmabuf helpers, Gerd Hoffmann, 2021/05/27
- [PULL 09/23] hw/display/qxl: Set pci rom address aligned with page size, Gerd Hoffmann, 2021/05/27
- [PULL 13/23] stubs: Add stubs for udmabuf helpers, Gerd Hoffmann, 2021/05/27
- [PULL 14/23] virtio-gpu: Add virtio_gpu_find_check_resource, Gerd Hoffmann, 2021/05/27
- [PULL 16/23] virtio-gpu: Refactor virtio_gpu_create_mapping_iov,
Gerd Hoffmann <=
- [PULL 15/23] virtio-gpu: Refactor virtio_gpu_set_scanout, Gerd Hoffmann, 2021/05/27
- [PULL 17/23] virtio-gpu: Add initial definitions for blob resources, Gerd Hoffmann, 2021/05/27
- [PULL 18/23] virtio-gpu: Add virtio_gpu_resource_create_blob, Gerd Hoffmann, 2021/05/27
- [PULL 19/23] ui/pixman: Add qemu_pixman_to_drm_format(), Gerd Hoffmann, 2021/05/27
- [PULL 21/23] virtio-gpu: Factor out update scanout, Gerd Hoffmann, 2021/05/27
- [PULL 23/23] virtio-gpu: Update cursor data using blob, Gerd Hoffmann, 2021/05/27
- [PULL 20/23] virtio-gpu: Add helpers to create and destroy dmabuf objects, Gerd Hoffmann, 2021/05/27
- [PULL 22/23] virtio-gpu: Add virtio_gpu_set_scanout_blob, Gerd Hoffmann, 2021/05/27
- Re: [PULL 00/23] Vga 20210527 patches, Peter Maydell, 2021/05/30