From: Manos Pitsidianakis <manos.pitsidiana...@linaro.org> Change the 3 part async cleanup of a blob memory mapping to check if the unmapping has finished already after deleting the subregion; this condition allows us to skip suspending the command and responding to the guest right away.
Signed-off-by: Manos Pitsidianakis <manos.pitsidiana...@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <phi...@linaro.org> Message-Id: <20250410122643.1747913-4-manos.pitsidiana...@linaro.org> Cc: qemu-sta...@nongnu.org --- hw/display/virtio-gpu-virgl.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 8fbe4e70cc..32a32879f7 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -155,7 +155,32 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g, * asynchronously by virtio_gpu_virgl_hostmem_region_free(). * 3. Finish the unmapping with final virgl_renderer_resource_unmap(). */ + + /* 1. Check if we should start unmapping now */ + if (!vmr->finish_unmapping) { + /* begin async unmapping. render will be unblocked once MR is freed */ + b->renderer_blocked++; + + memory_region_set_enabled(mr, false); + memory_region_del_subregion(&b->hostmem, mr); + object_unparent(OBJECT(mr)); + /* + * The unmapping might have already finished at this point if no one + * else held a reference to the MR; if yes, we can skip suspending the + * command and unmap the resource right away. + */ + *cmd_suspended = !vmr->finish_unmapping; + } + + /* + * 2. if virtio_gpu_virgl_hostmem_region_free hasn't been executed yet, we + * have marked the command to be re-processed later by setting + * cmd_suspended to true. The freeing callback will be called from RCU + * context later. + */ + if (vmr->finish_unmapping) { + /* 3. MemoryRegion has been freed, so finish unmapping */ res->mr = NULL; g_free(vmr); @@ -166,16 +191,6 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g, __func__, strerror(-ret)); return ret; } - } else { - *cmd_suspended = true; - - /* render will be unblocked once MR is freed */ - b->renderer_blocked++; - - /* memory region owns self res->mr object and frees it by itself */ - memory_region_set_enabled(mr, false); - memory_region_del_subregion(&b->hostmem, mr); - object_unparent(OBJECT(mr)); } return 0; -- 2.39.5