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 <jiangfeng@kylinos.cn>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17592>