On Mon, Feb 08, 2021 at 08:57:48AM +0100, Gerd Hoffmann
wrote:> Hi,
>
> > > +/* extract pages referenced by sgt */
> > > +static struct page **extr_pgs(struct sg_table *sgt, int *nents,
int *last_len)
> >
> > Nack, this doesn't work on dma-buf. And it'll blow up at
runtime when you
> > enable the very recently merged CONFIG_DMABUF_DEBUG (would be good to
test
> > with that, just to make sure).
>
> > Aside from this, for virtio/kvm use-cases we've already merged the
udmabuf
> > driver. Does this not work for your usecase?
>
> udmabuf can be used on the host side to make a collection of guest pages
> available as host dmabuf. It's part of the puzzle, but not a complete
> solution.
>
> As I understand it the intended workflow is this:
>
> (1) guest gpu driver exports some object as dma-buf
> (2) dma-buf is imported into this new driver.
> (3) driver sends the pages to the host.
> (4) hypervisor uses udmabuf to create a host dma-buf.
> (5) host dma-buf is passed on.
>
> And step (3) is the problematic one as this will not
> work in case the dma-buf doesn't live in guest ram but
> in -- for example -- gpu device memory.
Yup, vram or similar special ram is the reason why an importer can't look
at the pages behind a dma-buf sg table.
> Reversing the driver roles in the guest (virtio driver
> allocates pages and exports the dma-buf to the guest
> gpu driver) should work fine.
Yup, this needs to flow the other way round than in these patches.
> Which btw is something you can do today with virtio-gpu.
> Maybe it makes sense to have the option to run virtio-gpu
> in render-only mode for that use case.
Yeah that sounds like a useful addition.
Also, the same flow should work for real gpus passed through as pci
devices. What we need is some way to surface the dma-buf on the guest
side, which I think doesn't exist yet stand-alone. But this role could be
fulfilled by virtio-gpu in render-only mode I think. And (assuming I've
understood the recent discussions around virtio dma-buf sharing using
virtio ids) this would give you some neat zero-copy tricks for free if you
share multiple devices.
Also if you really want seamless buffer sharing between devices that are
passed to the guest and devices on the host side (like displays I guess?
or maybe video encode if this is for cloug gaming?), then using virtio-gpu
in render mode should also allow you to pass the dma_fence back&forth.
Which we'll need too, not just the dma-buf.
So at a first guess I'd say "render-only virtio-gpu mode" sounds
like
something rather useful. But I might be totally off here.
Cheers, Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch