[RFC 0/6] vfio: Implement VFIO_DEVICE_FEATURE_DMA_BUF and use it in virtio-gpu

Vivek Kasireddy posted 6 patches 4 days, 9 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250903054438.1179384-1-vivek.kasireddy@intel.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
hw/display/virtio-gpu-udmabuf.c | 60 ++++++++++++++++++++++++++++-----
hw/display/virtio-gpu.c         | 58 +++++++++++++++++++++++++------
hw/vfio/region.c                | 49 +++++++++++++++++++++++++++
include/hw/vfio/vfio-device.h   |  3 ++
linux-headers/linux/vfio.h      | 25 ++++++++++++++
5 files changed, 176 insertions(+), 19 deletions(-)
[RFC 0/6] vfio: Implement VFIO_DEVICE_FEATURE_DMA_BUF and use it in virtio-gpu
Posted by Vivek Kasireddy 4 days, 9 hours ago
The virtio-gpu driver running in the Guest VM can create Guest blob
resources (by importing dmabufs) that are backed by System RAM. This
is made possible by making use of memfd memory backend and udmabuf
driver on the Host side. However, in order to create Guest blobs
that are backed by vfio-pci device regions, we have to implement
VFIO_DEVICE_FEATURE_DMA_BUF and leverage it in virtio-gpu.

So, while creating the blobs we use memory_region_is_ram_device() to
figure out if the blob is backed by memfd or a vfio-pci device. If
it is determined that the blob is backed by vfio-pci device region,
instead of calling into udmabuf driver to create dmabuf we would
now call into vfio-pci driver to have a dmabuf created on the Host.

Tested with an SRIOV enabled Intel dGPU by running Gnome Wayland
(in the VM) and Qemu with the following (relevant) parameters:
-device vfio-pci,host=0000:03:00.1
-device virtio-vga,max_outputs=1,xres=1920,yres=1080,blob=true
-display gtk,gl=on

Associated vfio-pci kernel driver series:
https://lore.kernel.org/dri-devel/cover.1754311439.git.leon@kernel.org/
Associated virtio-gpu kernel driver series (merged):
https://lore.kernel.org/dri-devel/20241126031643.3490496-1-vivek.kasireddy@intel.com/

---
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Cédric Le Goater <clg@redhat.com>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Leon Romanovsky <leonro@nvidia.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Dongwon Kim <dongwon.kim@intel.com>

Vivek Kasireddy (6):
  linux-headers: Update vfio.h to include VFIO_DEVICE_FEATURE_DMA_BUF
  vfio: Add support for VFIO_DEVICE_FEATURE_DMA_BUF
  virtio-gpu-udmabuf: Create dmabuf for blobs associated with VFIO
    devices
  virtio-gpu: Don't rely on res->blob to identify blob resources
  virtio-gpu: Recreate the resource's dmabuf if new backing is attached
  virtio-gpu: Find the host addr given gpa associated with a ram device

 hw/display/virtio-gpu-udmabuf.c | 60 ++++++++++++++++++++++++++++-----
 hw/display/virtio-gpu.c         | 58 +++++++++++++++++++++++++------
 hw/vfio/region.c                | 49 +++++++++++++++++++++++++++
 include/hw/vfio/vfio-device.h   |  3 ++
 linux-headers/linux/vfio.h      | 25 ++++++++++++++
 5 files changed, 176 insertions(+), 19 deletions(-)

-- 
2.50.1