Skip to content

WIP: virgl: Work around VIRGL_BIND_CUSTOM resource creation race

For VIRGL_BIND_CUSTOM resources wait for the host to be done with the resource creation, since it also involves populating the backing store, which may conflict with the guest side also using it in parallel.

The offending scenario is:
guest: create_resource with BIND_CUSTOM, map, write data, unmap
host: create_resource, attach_backing_store (which involves copying from res->ptr to iov, since we are using BIND_CUSTOM), transfer_to_host

If we are unlucky, attach_backing_store may occur after the guest has mapped and written to the memory, in which case data could be overwritten. This fixes buffer memory "magically" changing and causing the glitches I have been seeing in !838 (merged).

Alternatively, we could try to ensure on the host that we don't copy to the attached iov if the resource doesn't contain initialized content.

However, both solutions only deal with attachment just after creation, and I am still concerned about additional races involved if the attachment occurs at other times. TTM, for example, seems to detach/attach when moving resources around, so it could be possible for the same scenario to occur when a resource is moved (but I am not familiar with TTM internals to be sure one way or another). I wonder if some more fundamental synchronization is missing/possible here.

Edited by Alexandros Frantzis

Merge request reports