From fe9333f7b5e274b683033443bb008d24822b9d55 Mon Sep 17 00:00:00 2001 From: Jiang Feng Date: Mon, 18 Jul 2022 14:53:26 +0800 Subject: [PATCH] virgl: Set res->maybe_busy to true when creating resources Currently, res->maybe_busy is false by default. If wait immediately after the resource is created, virgl_drm_resource_wait() will return directly without checking the actual state of the kernel, which will cause synchronization problems, such as: On Guest: pipe_buffer_create [mesa] virgl_drm_winsys_resource_create virtio_gpu_resource_create_ioctl [kernel] virtio_gpu_fence_alloc virtio_gpu_object_create virtio_gpu_cmd_resource_create_3d VIRTIO_GPU_CMD_RESOURCE_CREATE_3D virtio_gpu_object_attach virtio_gpu_cmd_resource_attach_backing VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING resource_wait [mesa] virgl_drm_resource_wait /* return directly without fence waiting */ pipe_buffer_map [mesa] virgl_drm_resource_map virtio_gpu_map_ioctl [kernel] os_mmap memcpy /* <== here */ On Host (with QEMU): VIRTIO_GPU_CMD_RESOURCE_CREATE_3D virgl_cmd_create_resource_3d [qemu] virgl_renderer_resource_create [virglrenderer] VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING virgl_resource_attach_backing [qemu] virtio_gpu_create_mapping_iov virgl_renderer_resource_attach_iov [virglrenderer] virgl_resource_attach_iov vrend_pipe_resource_attach_iov vrend_write_to_iovec /* <== here */ virtio_gpu_cleanup_mapping_iov [qemu] In the example above, there is a race condition between memcpy and vrend_write_to_iovec. Signed-off-by: Jiang Feng Reviewed-by: Gert Wollny Reviewed-by: Chia-I Wu Part-of: --- src/gallium/winsys/virgl/drm/virgl_drm_winsys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c index 75bd890..38b0c94 100644 --- a/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c +++ b/src/gallium/winsys/virgl/drm/virgl_drm_winsys.c @@ -455,7 +455,7 @@ alloc: res = virgl_drm_winsys_resource_create(qws, target, format, bind, width, height, depth, array_size, last_level, nr_samples, size, - false); + true); return res; } -- 2.7.4