diff mbox series

[v8,26/28] vfio-user: add 'no-direct-dma' option

Message ID 20250219144858.266455-27-john.levon@nutanix.com (mailing list archive)
State New
Headers show
Series vfio-user client | expand

Commit Message

John Levon Feb. 19, 2025, 2:48 p.m. UTC
From: Jagannathan Raman <jag.raman@oracle.com>

Normally, the vfio-user client will share a region's file descriptor
with the server to allow it directly mmap() the region memory. Add an
option to disable this, so the server must use
VFIO_USER_REGION_READ/WRITE instead.

FIXME: doesn't actually stop sending the fd??

Originally-by: John Johnson <john.g.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Signed-off-by: John Levon <john.levon@nutanix.com>
---
 hw/vfio-user/common.h    | 1 +
 hw/vfio-user/container.c | 2 +-
 hw/vfio-user/pci.c       | 5 +++++
 3 files changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/hw/vfio-user/common.h b/hw/vfio-user/common.h
index f8c61f2128..72138220ba 100644
--- a/hw/vfio-user/common.h
+++ b/hw/vfio-user/common.h
@@ -84,6 +84,7 @@  typedef struct VFIOUserProxy {
 
 /* VFIOProxy flags */
 #define VFIO_PROXY_CLIENT        0x1
+#define VFIO_PROXY_NO_MMAP       0x2
 #define VFIO_PROXY_FORCE_QUEUED  0x4
 #define VFIO_PROXY_NO_POST       0x8
 
diff --git a/hw/vfio-user/container.c b/hw/vfio-user/container.c
index 3974bc8a8c..3880316238 100644
--- a/hw/vfio-user/container.c
+++ b/hw/vfio-user/container.c
@@ -102,7 +102,7 @@  static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
      * vaddr enters as a QEMU process address; make it either a file offset
      * for mapped areas or leave as 0.
      */
-    if (fd != -1) {
+    if (fd != -1 && !(container->proxy->flags & VFIO_PROXY_NO_MMAP)) {
         msgp->offset = qemu_ram_block_host_offset(mrp->ram_block, vaddr);
     }
 
diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
index e65c7eaf02..8a05e69a46 100644
--- a/hw/vfio-user/pci.c
+++ b/hw/vfio-user/pci.c
@@ -36,6 +36,7 @@  OBJECT_DECLARE_SIMPLE_TYPE(VFIOUserPCIDevice, VFIO_USER_PCI)
 struct VFIOUserPCIDevice {
     VFIOPCIDevice device;
     char *sock_name;
+    bool no_direct_dma; /* disable shared mem for DMA */
     bool send_queued;   /* all sends are queued */
     bool no_post;       /* all regions write are sync */
 };
@@ -264,6 +265,9 @@  static void vfio_user_pci_realize(PCIDevice *pdev, Error **errp)
     vbasedev->proxy = proxy;
     vfio_user_set_handler(vbasedev, vfio_user_pci_process_req, vdev);
 
+    if (udev->no_direct_dma) {
+        proxy->flags |= VFIO_PROXY_NO_MMAP;
+    }
     if (udev->send_queued) {
         proxy->flags |= VFIO_PROXY_FORCE_QUEUED;
     }
@@ -402,6 +406,7 @@  static void vfio_user_pci_reset(DeviceState *dev)
 
 static const Property vfio_user_pci_dev_properties[] = {
     DEFINE_PROP_STRING("socket", VFIOUserPCIDevice, sock_name),
+    DEFINE_PROP_BOOL("no-direct-dma", VFIOUserPCIDevice, no_direct_dma, false),
     DEFINE_PROP_BOOL("x-send-queued", VFIOUserPCIDevice, send_queued, false),
     DEFINE_PROP_BOOL("x-no-posted-writes", VFIOUserPCIDevice, no_post, false),
 };