On Thu, Aug 28, 2025 at 02:17:32PM +0100, Alex Bennée wrote:
> The virtio-gpu blobs are a special MR which we handle clumsily at the
> moment as they are backed by separate thread (virglrenderer) and we need
> to jump through hoops (c.f. virtio_gpu_virgl_hostmem_region_free) to
> make sure it is done with the memory before we can free the container.

I remember looking at that path when discussing this problem.

Using virtio_gpu_virgl_hostmem_region_free overwrites the object->free is
pretty tricky.  Same on having MR->owner points to itself..

Is it possible to make virtio_gpu_virgl_hostmem_region an object, then make
it as the owner of virtio_gpu_virgl_hostmem_region.mr?

In general, whenever a MR needs serious refcounts on its own besides the
device to be emulated, IMHO the simplest way (which still 100% follow the
current QEMU's MR refcount design), is to create an umbrella object, making
that to be the owner instead.

We recently also have another discussion on how to achieve similar dynamic
MRs in vhost-user's SHMEM_MAP series:

https://lore.kernel.org/all/20250805081123.137064-1-aest...@redhat.com/#r

Ultimately, Albert went on with the VhostUserShmemObject approach, looks
like it works all fine, it's used in his latest post:

https://lore.kernel.org/all/20250818100353.1560655-2-aest...@redhat.com/#t

In that work, TYPE_VHOST_USER_SHMEM_OBJECT still dynamically allocates the
MR, but then it needs an explicit object_unparent() in finalize().  IIUC it
can be an embeded MR inside the owner object then object_unparent() isn't
needed either.

I may not have the full picture of virgl here, but not sure if this can be
solved in the similiar way to avoid the hacks.

-- 
Peter Xu


Reply via email to