Skip to contentSkip to conversation

vfio: Add DMABUF support for PCI BAR regions

PATCH Superseded Shameer Kolothum 5 participants 15 messages Jan 13 – Feb 3 RISC-V

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#3 lore raw

PATCH v2 2/4 hw/net/virtio-net: Adapt hash handling to updated UAPI

In reply to Shameer Kolothum

The virtio_net_hdr_v1_hash layout changed in the Linux UAPI, replacing the 32-bit hash_value field with two 16-bit fields, hash_value_lo and hash_value_hi.

Update hash handling to populate the new fields correctly and adjust offset and size calculations accordingly.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
---
 hw/net/virtio-net.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
hw/net/virtio-net.c +7 -4
index 317f1ad23b..512a7c02c9 100644
@@ -1879,7 +1879,8 @@ static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf,
                                              n->rss_data.runtime_hash_types);
     if (net_hash_type > NetPktRssIpV6UdpEx) {
         if (n->rss_data.populate_hash) {
-            hdr->hash_value = VIRTIO_NET_HASH_REPORT_NONE;
+            hdr->hash_value_lo = VIRTIO_NET_HASH_REPORT_NONE;
+            hdr->hash_value_hi = VIRTIO_NET_HASH_REPORT_NONE;
             hdr->hash_report = 0;
         }
         return n->rss_data.redirect ? n->rss_data.default_queue : -1;
@@ -1888,7 +1889,8 @@ static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf,
     hash = net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key);
 
     if (n->rss_data.populate_hash) {
-        hdr->hash_value = hash;
+        hdr->hash_value_lo = cpu_to_le16(hash & 0xffff);
+        hdr->hash_value_hi = cpu_to_le16((hash >> 16) & 0xffff);
         hdr->hash_report = reports[net_hash_type];
     }
 
@@ -1990,10 +1992,11 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
 
             receive_header(n, sg, elem->in_num, buf, size);
             if (n->rss_data.populate_hash) {
-                offset = offsetof(typeof(extra_hdr), hash_value);
+                offset = offsetof(typeof(extra_hdr), hash_value_lo);
                 iov_from_buf(sg, elem->in_num, offset,
                              (char *)&extra_hdr + offset,
-                             sizeof(extra_hdr.hash_value) +
+                             sizeof(extra_hdr.hash_value_lo) +
+                             sizeof(extra_hdr.hash_value_hi) +
                              sizeof(extra_hdr.hash_report));
             }
             offset = n->host_hdr_len;
Signature · 1 line
2.43.0
#0 lore raw

v2 cover vfio: Add DMABUF support for PCI BAR regions

Hi,

Linux now provides a VFIO dmabuf exporter to expose PCI BAR memory for P2P use cases. This adds support for vfio devices to create a dmabuf for each mapped BAR region.

Changes from v1:
https://lore.kernel.org/qemu-devel/[email protected]/

- Addressed feedback on v1. Thanks!.
- Added a helper function to retreive device feature(patch #3)
- This has dependnecy on patches sent by Cédric[0][1]

The dmabuf support was sanity tested on an NVIDIA grace paltform.

Please take a look and let me know.

Thanks,
Shameer
[0] https://lore.kernel.org/qemu-devel/[email protected]/
[1] https://lore.kernel.org/qemu-devel/[email protected]/

Nicolin Chen (1):
hw/vfio/region: Create dmabuf for PCI BAR per region

Shameer Kolothum (3):
linux-headers: Update to Linux v6.19-rc1 hw/net/virtio-net: Adapt hash handling to updated UAPI hw/vfio: Add helper to retrieve device feature

 hw/net/virtio-net.c                           |  11 +-
 hw/vfio/container.c                           |   2 +-
 hw/vfio/device.c                              |  10 +
 hw/vfio/listener.c                            |   4 +-
 hw/vfio/region.c                              |  69 ++-
 hw/vfio/trace-events                          |   1 +
 include/hw/vfio/vfio-device.h                 |   3 +
 include/standard-headers/drm/drm_fourcc.h     |  25 +-
 include/standard-headers/linux/ethtool.h      |   5 +
 .../linux/input-event-codes.h                 |  14 +-
 include/standard-headers/linux/pci_regs.h     |  89 ++++
 include/standard-headers/linux/virtio_net.h   |   3 +-
 include/standard-headers/linux/virtio_pci.h   |   2 +-
 linux-headers/asm-arm64/kvm.h                 |   2 +-
 linux-headers/asm-arm64/unistd_64.h           |   1 +
 linux-headers/asm-generic/unistd.h            |   4 +-
 linux-headers/asm-loongarch/kvm.h             |   1 +
 linux-headers/asm-loongarch/unistd.h          |   6 +
 linux-headers/asm-loongarch/unistd_64.h       |   1 +
 linux-headers/asm-mips/unistd_n32.h           |   1 +
 linux-headers/asm-mips/unistd_n64.h           |   1 +
 linux-headers/asm-mips/unistd_o32.h           |   1 +
 linux-headers/asm-powerpc/unistd_32.h         |   1 +
 linux-headers/asm-powerpc/unistd_64.h         |   1 +
 linux-headers/asm-riscv/kvm.h                 |   3 +
 linux-headers/asm-riscv/unistd_32.h           |   1 +
 linux-headers/asm-riscv/unistd_64.h           |   1 +
 linux-headers/asm-s390/bitsperlong.h          |   4 -
 linux-headers/asm-s390/unistd.h               |   4 -
 linux-headers/asm-s390/unistd_32.h            | 446 ------------------
 linux-headers/asm-s390/unistd_64.h            |   9 +-
 linux-headers/asm-x86/kvm.h                   |   1 +
 linux-headers/asm-x86/unistd_32.h             |   1 +
 linux-headers/asm-x86/unistd_64.h             |   1 +
 linux-headers/asm-x86/unistd_x32.h            |   1 +
 linux-headers/linux/iommufd.h                 |  10 +
 linux-headers/linux/kvm.h                     |  11 +
 linux-headers/linux/mshv.h                    | 116 ++++-
 linux-headers/linux/psp-sev.h                 |  66 ++-
 linux-headers/linux/vfio.h                    |  28 ++
 40 files changed, 455 insertions(+), 506 deletions(-)
 delete mode 100644 linux-headers/asm-s390/unistd_32.h
Signature · 1 line
2.43.0
#10 lore raw

PATCH v2 4/4 hw/vfio/region: Create dmabuf for PCI BAR per region

From: Nicolin Chen <[email protected]>

Linux now provides a VFIO dmabuf exporter to expose PCI BAR memory for P2P use cases. Create a dmabuf for each mapped BAR region after the mmap is set up, and store the returned fd in the region’s RAMBlock. This allows QEMU to pass the fd to dma_map_file(), enabling iommufd to import the dmabuf and map the BAR correctly in the host IOMMU page table.

If the kernel lacks support or dmabuf setup fails, QEMU skips the setup and continues with normal mmap handling.

---
 hw/vfio/region.c     | 69 +++++++++++++++++++++++++++++++++++++++++++-
 hw/vfio/trace-events |  1 +
 2 files changed, 69 insertions(+), 1 deletion(-)
hw/vfio/region.c +68 -1
index ca75ab1be4..8476a54dda 100644
@@ -29,6 +29,7 @@
 #include "qemu/error-report.h"
 #include "qemu/units.h"
 #include "monitor/monitor.h"
+#include "system/ramblock.h"
 #include "vfio-helpers.h"
 
 /*
@@ -238,13 +239,53 @@ static void vfio_subregion_unmap(VFIORegion *region, int index)
     region->mmaps[index].mmap = NULL;
 }
 
+static int vfio_region_create_dma_buf(VFIORegion *region)
+{
+    g_autofree struct vfio_device_feature *feature = NULL;
+    VFIODevice *vbasedev = region->vbasedev;
+    struct vfio_device_feature_dma_buf *dma_buf;
+    size_t total_size;
+    int i, ret;
+
+    g_assert(region->nr_mmaps);
+
+    total_size = sizeof(*feature) + sizeof(*dma_buf) +
+                 sizeof(struct vfio_region_dma_range) * region->nr_mmaps;
+    feature = g_malloc0(total_size);
+    *feature = (struct vfio_device_feature) {
+        .argsz = total_size,
+        .flags = VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_DMA_BUF,
+    };
+
+    dma_buf = (void *)feature->data;
+    *dma_buf = (struct vfio_device_feature_dma_buf) {
+        .region_index = region->nr,
+        .open_flags = O_RDWR,
+        .nr_ranges = region->nr_mmaps,
+    };
+
+    for (i = 0; i < region->nr_mmaps; i++) {
+        dma_buf->dma_ranges[i].offset = region->mmaps[i].offset;
+        dma_buf->dma_ranges[i].length = region->mmaps[i].size;
+    }
+
+    ret = vfio_device_get_feature(vbasedev, feature);
+    for (i = 0; i < region->nr_mmaps; i++) {
+        trace_vfio_region_dmabuf(region->vbasedev->name, ret, region->nr,
+                                 memory_region_name(region->mem),
+                                 region->mmaps[i].offset,
+                                 region->mmaps[i].size);
+    }
+    return ret;
+}
+
 int vfio_region_mmap(VFIORegion *region)
 {
     int i, ret, prot = 0;
     char *name;
     int fd;
 
-    if (!region->mem) {
+    if (!region->mem || !region->nr_mmaps) {
         return 0;
     }
 
@@ -305,6 +346,32 @@ int vfio_region_mmap(VFIORegion *region)
                                region->mmaps[i].size - 1);
     }
 
+    ret = vfio_region_create_dma_buf(region);
+    if (ret < 0) {
+        if (ret == -ENOTTY) {
+            warn_report_once("VFIO dma-buf not supported in kernel: "
+                             "PCI BAR IOMMU mappings may fail");
+        } else {
+            error_report("%s: failed to create dma-buf (%s): "
+                         "PCI BAR IOMMU mappings may fail",
+                         memory_region_name(region->mem), strerror(errno));
+        }
+        /*
+         * Return success as VFIO region mmap succeeded and dmabuf is optional.
+         * P2P DMA or exposing device memory use cases will not be supported.
+         */
+        return 0;
+    }
+
+    /* Assign the dmabuf fd to associated RAMBlock */
+    for (i = 0; i < region->nr_mmaps; i++) {
+        MemoryRegion *mr = &region->mmaps[i].mem;
+        RAMBlock *ram_block = mr->ram_block;
+
+        ram_block->fd = ret;
+        ram_block->fd_offset = region->mmaps[i].offset;
+    }
+
     return 0;
 
 no_mmap:
hw/vfio/trace-events +1 -0
index 1e895448cd..592a0349d4 100644
@@ -117,6 +117,7 @@ vfio_device_put(int fd) "close vdev->fd=%d"
 vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)"
 vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint64_t data) " (%s:region%d+0x%"PRIx64", %d) = 0x%"PRIx64
 vfio_region_setup(const char *dev, int index, const char *name, unsigned long flags, unsigned long offset, unsigned long size) "Device %s, region %d \"%s\", flags: 0x%lx, offset: 0x%lx, size: 0x%lx"
+vfio_region_dmabuf(const char *dev, int fd, int index,  const char *name, unsigned long offset, unsigned long size) "Device %s, dmabuf fd %d region %d \"%s\", offset: 0x%lx, size: 0x%lx"
 vfio_region_mmap_fault(const char *name, int index, unsigned long offset, unsigned long size, int fault) "Region %s mmaps[%d], [0x%lx - 0x%lx], fault: %d"
 vfio_region_mmap(const char *name, unsigned long offset, unsigned long end) "Region %s [0x%lx - 0x%lx]"
 vfio_region_exit(const char *name, int index) "Device %s, region %d"
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/4 linux-headers: Update to Linux v6.19-rc1

In reply to Shameer Kolothum

Mainly for adding support for VFIO DMABUF. While at it, update all headers.

---
 include/standard-headers/drm/drm_fourcc.h     |  25 +-
 include/standard-headers/linux/ethtool.h      |   5 +
 .../linux/input-event-codes.h                 |  14 +-
 include/standard-headers/linux/pci_regs.h     |  89 ++++
 include/standard-headers/linux/virtio_net.h   |   3 +-
 include/standard-headers/linux/virtio_pci.h   |   2 +-
 linux-headers/asm-arm64/kvm.h                 |   2 +-
 linux-headers/asm-arm64/unistd_64.h           |   1 +
 linux-headers/asm-generic/unistd.h            |   4 +-
 linux-headers/asm-loongarch/kvm.h             |   1 +
 linux-headers/asm-loongarch/unistd.h          |   6 +
 linux-headers/asm-loongarch/unistd_64.h       |   1 +
 linux-headers/asm-mips/unistd_n32.h           |   1 +
 linux-headers/asm-mips/unistd_n64.h           |   1 +
 linux-headers/asm-mips/unistd_o32.h           |   1 +
 linux-headers/asm-powerpc/unistd_32.h         |   1 +
 linux-headers/asm-powerpc/unistd_64.h         |   1 +
 linux-headers/asm-riscv/kvm.h                 |   3 +
 linux-headers/asm-riscv/unistd_32.h           |   1 +
 linux-headers/asm-riscv/unistd_64.h           |   1 +
 linux-headers/asm-s390/bitsperlong.h          |   4 -
 linux-headers/asm-s390/unistd.h               |   4 -
 linux-headers/asm-s390/unistd_32.h            | 446 ------------------
 linux-headers/asm-s390/unistd_64.h            |   9 +-
 linux-headers/asm-x86/kvm.h                   |   1 +
 linux-headers/asm-x86/unistd_32.h             |   1 +
 linux-headers/asm-x86/unistd_64.h             |   1 +
 linux-headers/asm-x86/unistd_x32.h            |   1 +
 linux-headers/linux/iommufd.h                 |  10 +
 linux-headers/linux/kvm.h                     |  11 +
 linux-headers/linux/mshv.h                    | 116 ++++-
 linux-headers/linux/psp-sev.h                 |  66 ++-
 linux-headers/linux/vfio.h                    |  28 ++
 33 files changed, 363 insertions(+), 498 deletions(-)
 delete mode 100644 linux-headers/asm-s390/unistd_32.h
include/standard-headers/drm/drm_fourcc.h +16 -9
index cef077dfb3..b39e197cc7 100644
@@ -978,14 +978,20 @@ extern "C" {
  *               2 = Gob Height 8, Turing+ Page Kind mapping
  *               3 = Reserved for future use.
  *
- * 22:22 s     Sector layout.  On Tegra GPUs prior to Xavier, there is a further
- *             bit remapping step that occurs at an even lower level than the
- *             page kind and block linear swizzles.  This causes the layout of
- *             surfaces mapped in those SOC's GPUs to be incompatible with the
- *             equivalent mapping on other GPUs in the same system.
- *
- *               0 = Tegra K1 - Tegra Parker/TX2 Layout.
- *               1 = Desktop GPU and Tegra Xavier+ Layout
+ * 22:22 s     Sector layout.  There is a further bit remapping step that occurs
+ * 26:27       at an even lower level than the page kind and block linear
+ *             swizzles.  This causes the bit arrangement of surfaces in memory
+ *             to differ subtly, and prevents direct sharing of surfaces between
+ *             GPUs with different layouts.
+ *
+ *               0 = Tegra K1 - Tegra Parker/TX2 Layout
+ *               1 = Pre-GB20x, GB20x 32+ bpp, GB10, Tegra Xavier-Orin Layout
+ *               2 = GB20x(Blackwell 2)+ 8 bpp surface layout
+ *               3 = GB20x(Blackwell 2)+ 16 bpp surface layout
+ *               4 = Reserved for future use.
+ *               5 = Reserved for future use.
+ *               6 = Reserved for future use.
+ *               7 = Reserved for future use.
  *
  * 25:23 c     Lossless Framebuffer Compression type.
  *
@@ -1000,7 +1006,7 @@ extern "C" {
  *               6 = Reserved for future use
  *               7 = Reserved for future use
  *
- * 55:25 -     Reserved for future use.  Must be zero.
+ * 55:28 -     Reserved for future use.  Must be zero.
  */
 #define DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(c, s, g, k, h) \
 	fourcc_mod_code(NVIDIA, (0x10 | \
@@ -1008,6 +1014,7 @@ extern "C" {
 				 (((k) & 0xff) << 12) | \
 				 (((g) & 0x3) << 20) | \
 				 (((s) & 0x1) << 22) | \
+				 (((s) & 0x6) << 25) | \
 				 (((c) & 0x7) << 23)))
 
 /* To grandfather in prior block linear format modifiers to the above layout,
include/standard-headers/linux/ethtool.h +5 -0
index dc24512d28..d0f7a63f10 100644
@@ -2077,6 +2077,10 @@ enum ethtool_link_mode_bit_indices {
 	ETHTOOL_LINK_MODE_800000baseDR4_2_Full_BIT	 = 118,
 	ETHTOOL_LINK_MODE_800000baseSR4_Full_BIT	 = 119,
 	ETHTOOL_LINK_MODE_800000baseVR4_Full_BIT	 = 120,
+	ETHTOOL_LINK_MODE_1600000baseCR8_Full_BIT	 = 121,
+	ETHTOOL_LINK_MODE_1600000baseKR8_Full_BIT	 = 122,
+	ETHTOOL_LINK_MODE_1600000baseDR8_Full_BIT	 = 123,
+	ETHTOOL_LINK_MODE_1600000baseDR8_2_Full_BIT	 = 124,
 
 	/* must be last entry */
 	__ETHTOOL_LINK_MODE_MASK_NBITS
@@ -2190,6 +2194,7 @@ enum ethtool_link_mode_bit_indices {
 #define SPEED_200000		200000
 #define SPEED_400000		400000
 #define SPEED_800000		800000
+#define SPEED_1600000		1600000
 
 #define SPEED_UNKNOWN		-1
 
include/standard-headers/linux/input-event-codes.h +13 -1
index c914ccd723..ede79c6ae4 100644
@@ -27,7 +27,7 @@
 #define INPUT_PROP_TOPBUTTONPAD		0x04	/* softbuttons at top of pad */
 #define INPUT_PROP_POINTING_STICK	0x05	/* is a pointing stick */
 #define INPUT_PROP_ACCELEROMETER	0x06	/* has accelerometer */
-#define INPUT_PROP_HAPTIC_TOUCHPAD	0x07	/* is a haptic touchpad */
+#define INPUT_PROP_PRESSUREPAD		0x07	/* pressure triggers clicks */
 
 #define INPUT_PROP_MAX			0x1f
 #define INPUT_PROP_CNT			(INPUT_PROP_MAX + 1)
@@ -631,6 +631,18 @@
 #define KEY_BRIGHTNESS_MIN		0x250	/* Set Brightness to Minimum */
 #define KEY_BRIGHTNESS_MAX		0x251	/* Set Brightness to Maximum */
 
+/*
+ * Keycodes for hotkeys toggling the electronic privacy screen found on some
+ * laptops on/off. Note when the embedded-controller turns on/off the eprivacy
+ * screen itself then the state should be reported through drm connecter props:
+ * https://www.kernel.org/doc/html/latest/gpu/drm-kms.html#standard-connector-properties
+ * Except when implementing the drm connecter properties API is not possible
+ * because e.g. the firmware does not allow querying the presence and/or status
+ * of the eprivacy screen at boot.
+ */
+#define KEY_EPRIVACY_SCREEN_ON		0x252
+#define KEY_EPRIVACY_SCREEN_OFF		0x253
+
 #define KEY_KBDINPUTASSIST_PREV		0x260
 #define KEY_KBDINPUTASSIST_NEXT		0x261
 #define KEY_KBDINPUTASSIST_PREVGROUP		0x262
include/standard-headers/linux/pci_regs.h +89 -0

110 lines not on this page · raw message

include/standard-headers/linux/virtio_net.h +2 -1
index 93abaae0b9..17a0174d6c 100644
@@ -193,7 +193,8 @@ struct virtio_net_hdr_v1 {
 
 struct virtio_net_hdr_v1_hash {
 	struct virtio_net_hdr_v1 hdr;
-	uint32_t hash_value;
+	uint16_t hash_value_lo;
+	uint16_t hash_value_hi;
 #define VIRTIO_NET_HASH_REPORT_NONE            0
 #define VIRTIO_NET_HASH_REPORT_IPv4            1
 #define VIRTIO_NET_HASH_REPORT_TCPv4           2
include/standard-headers/linux/virtio_pci.h +1 -1
index 09e964e6ee..4c82513df2 100644
@@ -40,7 +40,7 @@
 #define _LINUX_VIRTIO_PCI_H
 
 #include "standard-headers/linux/types.h"
-#include "standard-headers/linux/kernel.h"
+#include "standard-headers/linux/const.h"
 
 #ifndef VIRTIO_PCI_NO_LEGACY
 
linux-headers/asm-arm64/kvm.h +1 -1
index f4d9baafa1..46ffbddab5 100644
@@ -31,7 +31,7 @@
 #define KVM_SPSR_FIQ	4
 #define KVM_NR_SPSR	5
 
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 #include <linux/psci.h>
 #include <linux/types.h>
 #include <asm/ptrace.h>
linux-headers/asm-arm64/unistd_64.h +1 -0
index 4ae25c2b91..1ef9c40813 100644
@@ -326,6 +326,7 @@
 #define __NR_open_tree_attr 467
 #define __NR_file_getattr 468
 #define __NR_file_setattr 469
+#define __NR_listns 470
 
 
 #endif /* _ASM_UNISTD_64_H */
linux-headers/asm-generic/unistd.h +3 -1
index 04e0077fb4..942370b3f5 100644
@@ -857,9 +857,11 @@ __SYSCALL(__NR_open_tree_attr, sys_open_tree_attr)
 __SYSCALL(__NR_file_getattr, sys_file_getattr)
 #define __NR_file_setattr 469
 __SYSCALL(__NR_file_setattr, sys_file_setattr)
+#define __NR_listns 470
+__SYSCALL(__NR_listns, sys_listns)
 
 #undef __NR_syscalls
-#define __NR_syscalls 470
+#define __NR_syscalls 471
 
 /*
  * 32 bit systems traditionally used different
linux-headers/asm-loongarch/kvm.h +1 -0
index 57ba1a563b..de6c3f18e4 100644
@@ -104,6 +104,7 @@ struct kvm_fpu {
 #define  KVM_LOONGARCH_VM_FEAT_PV_IPI		6
 #define  KVM_LOONGARCH_VM_FEAT_PV_STEALTIME	7
 #define  KVM_LOONGARCH_VM_FEAT_PTW		8
+#define  KVM_LOONGARCH_VM_FEAT_MSGINT		9
 
 /* Device Control API on vcpu fd */
 #define KVM_LOONGARCH_VCPU_CPUCFG	0
linux-headers/asm-loongarch/unistd.h +6 -0
index 1f01980f9c..e19c7f2f9f 100644
@@ -1,3 +1,9 @@
 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
 
+#include <asm/bitsperlong.h>
+
+#if __BITS_PER_LONG == 32
+#include <asm/unistd_32.h>
+#else
 #include <asm/unistd_64.h>
+#endif
linux-headers/asm-loongarch/unistd_64.h +1 -0
index 5033fc8f2f..aa5daac4ef 100644
@@ -322,6 +322,7 @@
 #define __NR_open_tree_attr 467
 #define __NR_file_getattr 468
 #define __NR_file_setattr 469
+#define __NR_listns 470
 
 
 #endif /* _ASM_UNISTD_64_H */
linux-headers/asm-mips/unistd_n32.h +1 -0
index c99c10e5bf..a33d106dca 100644
@@ -398,5 +398,6 @@
 #define __NR_open_tree_attr (__NR_Linux + 467)
 #define __NR_file_getattr (__NR_Linux + 468)
 #define __NR_file_setattr (__NR_Linux + 469)
+#define __NR_listns (__NR_Linux + 470)
 
 #endif /* _ASM_UNISTD_N32_H */
linux-headers/asm-mips/unistd_n64.h +1 -0
index 0d975bb185..1bc251e450 100644
@@ -374,5 +374,6 @@
 #define __NR_open_tree_attr (__NR_Linux + 467)
 #define __NR_file_getattr (__NR_Linux + 468)
 #define __NR_file_setattr (__NR_Linux + 469)
+#define __NR_listns (__NR_Linux + 470)
 
 #endif /* _ASM_UNISTD_N64_H */
linux-headers/asm-mips/unistd_o32.h +1 -0
index 86ac0ac84b..c57175d496 100644
@@ -444,5 +444,6 @@
 #define __NR_open_tree_attr (__NR_Linux + 467)
 #define __NR_file_getattr (__NR_Linux + 468)
 #define __NR_file_setattr (__NR_Linux + 469)
+#define __NR_listns (__NR_Linux + 470)
 
 #endif /* _ASM_UNISTD_O32_H */
linux-headers/asm-powerpc/unistd_32.h +1 -0
index d7a32c5e06..a3f4aa2fe2 100644
@@ -451,6 +451,7 @@
 #define __NR_open_tree_attr 467
 #define __NR_file_getattr 468
 #define __NR_file_setattr 469
+#define __NR_listns 470
 
 
 #endif /* _ASM_UNISTD_32_H */
linux-headers/asm-powerpc/unistd_64.h +1 -0
index ff35c51fc6..d4444557f1 100644
@@ -423,6 +423,7 @@
 #define __NR_open_tree_attr 467
 #define __NR_file_getattr 468
 #define __NR_file_setattr 469
+#define __NR_listns 470
 
 
 #endif /* _ASM_UNISTD_64_H */
linux-headers/asm-riscv/kvm.h +3 -0
index 759a4852c0..54f3ad7ed2 100644
@@ -23,6 +23,8 @@
 #define KVM_INTERRUPT_SET	-1U
 #define KVM_INTERRUPT_UNSET	-2U
 
+#define KVM_EXIT_FAIL_ENTRY_NO_VSFILE	(1ULL << 0)
+
 /* for KVM_GET_REGS and KVM_SET_REGS */
 struct kvm_regs {
 };
@@ -211,6 +213,7 @@ enum KVM_RISCV_SBI_EXT_ID {
 	KVM_RISCV_SBI_EXT_STA,
 	KVM_RISCV_SBI_EXT_SUSP,
 	KVM_RISCV_SBI_EXT_FWFT,
+	KVM_RISCV_SBI_EXT_MPXY,
 	KVM_RISCV_SBI_EXT_MAX,
 };
 
linux-headers/asm-riscv/unistd_32.h +1 -0
index 6083373e88..9f33956246 100644
@@ -317,6 +317,7 @@
 #define __NR_open_tree_attr 467
 #define __NR_file_getattr 468
 #define __NR_file_setattr 469
+#define __NR_listns 470
 
 
 #endif /* _ASM_UNISTD_32_H */
linux-headers/asm-riscv/unistd_64.h +1 -0
index f0c7585c60..c2e7258916 100644
@@ -327,6 +327,7 @@
 #define __NR_open_tree_attr 467
 #define __NR_file_getattr 468
 #define __NR_file_setattr 469
+#define __NR_listns 470
 
 
 #endif /* _ASM_UNISTD_64_H */
linux-headers/asm-s390/bitsperlong.h +0 -4
index cceaf47b02..7af27a985f 100644
@@ -2,11 +2,7 @@
 #ifndef __ASM_S390_BITSPERLONG_H
 #define __ASM_S390_BITSPERLONG_H
 
-#ifndef __s390x__
-#define __BITS_PER_LONG 32
-#else
 #define __BITS_PER_LONG 64
-#endif
 
 #include <asm-generic/bitsperlong.h>
 
linux-headers/asm-s390/unistd.h +0 -4
index 27b8b211c8..1484618877 100644
@@ -8,10 +8,6 @@
 #ifndef _ASM_S390_UNISTD_H_
 #define _ASM_S390_UNISTD_H_
 
-#ifdef __s390x__
 #include <asm/unistd_64.h>
-#else
-#include <asm/unistd_32.h>
-#endif
 
 #endif /* _ASM_S390_UNISTD_H_ */
linux-headers/asm-s390/unistd_32.h deleted +0 -446

446 lines not on this page · raw message

linux-headers/asm-s390/unistd_64.h +5 -4
index 0652ba6331..8d9e579ef5 100644
@@ -1,6 +1,5 @@
-/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
-#ifndef _ASM_S390_UNISTD_64_H
-#define _ASM_S390_UNISTD_64_H
+#ifndef _ASM_UNISTD_64_H
+#define _ASM_UNISTD_64_H
 
 #define __NR_exit 1
 #define __NR_fork 2
@@ -390,5 +389,7 @@
 #define __NR_open_tree_attr 467
 #define __NR_file_getattr 468
 #define __NR_file_setattr 469
+#define __NR_listns 470
 
-#endif /* _ASM_S390_UNISTD_64_H */
+
+#endif /* _ASM_UNISTD_64_H */
linux-headers/asm-x86/kvm.h +1 -0
index 3bb38f6c3a..b804fd25a2 100644
@@ -500,6 +500,7 @@ struct kvm_sync_regs {
 /* vendor-specific groups and attributes for system fd */
 #define KVM_X86_GRP_SEV			1
 #  define KVM_X86_SEV_VMSA_FEATURES	0
+#  define KVM_X86_SNP_POLICY_BITS	1
 
 struct kvm_vmx_nested_state_data {
 	__u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
linux-headers/asm-x86/unistd_32.h +1 -0
index 8f784a5634..34255aac64 100644
@@ -460,6 +460,7 @@
 #define __NR_open_tree_attr 467
 #define __NR_file_getattr 468
 #define __NR_file_setattr 469
+#define __NR_listns 470
 
 
 #endif /* _ASM_UNISTD_32_H */
linux-headers/asm-x86/unistd_64.h +1 -0
index 26c258d1a6..07f242a5fa 100644
@@ -384,6 +384,7 @@
 #define __NR_open_tree_attr 467
 #define __NR_file_getattr 468
 #define __NR_file_setattr 469
+#define __NR_listns 470
 
 
 #endif /* _ASM_UNISTD_64_H */
linux-headers/asm-x86/unistd_x32.h +1 -0
index 65c2aed946..08fc9da2fa 100644
@@ -337,6 +337,7 @@
 #define __NR_open_tree_attr (__X32_SYSCALL_BIT + 467)
 #define __NR_file_getattr (__X32_SYSCALL_BIT + 468)
 #define __NR_file_setattr (__X32_SYSCALL_BIT + 469)
+#define __NR_listns (__X32_SYSCALL_BIT + 470)
 #define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
 #define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
 #define __NR_ioctl (__X32_SYSCALL_BIT + 514)
linux-headers/linux/iommufd.h +10 -0
index 2105a03955..384183a403 100644
@@ -450,6 +450,16 @@ struct iommu_hwpt_vtd_s1 {
  * nested domain will translate the same as the nesting parent. The S1 will
  * install a Context Descriptor Table pointing at userspace memory translated
  * by the nesting parent.
+ *
+ * It's suggested to allocate a vDEVICE object carrying vSID and then re-attach
+ * the nested domain, as soon as the vSID is available in the VMM level:
+ *
+ * - when Cfg=translate, a vDEVICE must be allocated prior to attaching to the
+ *   allocated nested domain, as CD/ATS invalidations and vevents need a vSID.
+ * - when Cfg=bypass/abort, a vDEVICE is not enforced during the nested domain
+ *   attachment, to support a GBPA case where VM sets CR0.SMMUEN=0. However, if
+ *   VM sets CR0.SMMUEN=1 while missing a vDEVICE object, kernel would fail to
+ *   report events to the VM. E.g. F_TRANSLATION when guest STE.Cfg=abort.
  */
 struct iommu_hwpt_arm_smmuv3 {
 	__aligned_le64 ste[2];
linux-headers/linux/kvm.h +11 -0
index 4ea28ef7ca..a4ab42dcba 100644
@@ -179,6 +179,7 @@ struct kvm_xen_exit {
 #define KVM_EXIT_LOONGARCH_IOCSR  38
 #define KVM_EXIT_MEMORY_FAULT     39
 #define KVM_EXIT_TDX              40
+#define KVM_EXIT_ARM_SEA          41
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 /* Emulate instruction failed. */
@@ -465,6 +466,14 @@ struct kvm_run {
 				} setup_event_notify;
 			};
 		} tdx;
+		/* KVM_EXIT_ARM_SEA */
+		struct {
+#define KVM_EXIT_ARM_SEA_FLAG_GPA_VALID	(1ULL << 0)
+			__u64 flags;
+			__u64 esr;
+			__u64 gva;
+			__u64 gpa;
+		} arm_sea;
 		/* Fix the size of the union. */
 		char padding[256];
 	};
@@ -955,6 +964,8 @@ struct kvm_enable_cap {
 #define KVM_CAP_RISCV_MP_STATE_RESET 242
 #define KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED 243
 #define KVM_CAP_GUEST_MEMFD_FLAGS 244
+#define KVM_CAP_ARM_SEA_TO_USER 245
+#define KVM_CAP_S390_USER_OPEREXEC 246
 
 struct kvm_irq_routing_irqchip {
 	__u32 irqchip;
linux-headers/linux/mshv.h +115 -1

144 lines not on this page · raw message

linux-headers/linux/psp-sev.h +41 -25

79 lines not on this page · raw message

linux-headers/linux/vfio.h +28 -0
index 4d96d1fc12..720edfee7a 100644
@@ -14,6 +14,7 @@
 
 #include <linux/types.h>
 #include <linux/ioctl.h>
+#include <linux/stddef.h>
 
 #define VFIO_API_VERSION	0
 
@@ -1478,6 +1479,33 @@ struct vfio_device_feature_bus_master {
 };
 #define VFIO_DEVICE_FEATURE_BUS_MASTER 10
 
+/**
+ * Upon VFIO_DEVICE_FEATURE_GET create a dma_buf fd for the
+ * regions selected.
+ *
+ * open_flags are the typical flags passed to open(2), eg O_RDWR, O_CLOEXEC,
+ * etc. offset/length specify a slice of the region to create the dmabuf from.
+ * nr_ranges is the total number of (P2P DMA) ranges that comprise the dmabuf.
+ *
+ * flags should be 0.
+ *
+ * Return: The fd number on success, -1 and errno is set on failure.
+ */
+#define VFIO_DEVICE_FEATURE_DMA_BUF 11
+
+struct vfio_region_dma_range {
+	__u64 offset;
+	__u64 length;
+};
+
+struct vfio_device_feature_dma_buf {
+	__u32	region_index;
+	__u32	open_flags;
+	__u32   flags;
+	__u32   nr_ranges;
+	struct vfio_region_dma_range dma_ranges[] __counted_by(nr_ranges);
+};
+
 /* -------- API for Type1 VFIO IOMMU -------- */
 
 /**
Signature · 1 line
2.43.0
#6 lore raw

PATCH v2 3/4 hw/vfio: Add helper to retrieve device feature

In reply to Shameer Kolothum

Add vfio_device_get_feature() as a common helper to retrieve VFIO device features.

No functional change intended.

---
 hw/vfio/container.c           |  2 +-
 hw/vfio/device.c              | 10 ++++++++++
 hw/vfio/listener.c            |  4 ++--
 include/hw/vfio/vfio-device.h |  3 +++
 4 files changed, 16 insertions(+), 3 deletions(-)
hw/vfio/container.c +1 -1
index 5993d90545..b0cbcf0f4a 100644
@@ -208,7 +208,7 @@ static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iova,
     feature->flags = VFIO_DEVICE_FEATURE_GET |
                      VFIO_DEVICE_FEATURE_DMA_LOGGING_REPORT;
 
-    return vbasedev->io_ops->device_feature(vbasedev, feature);
+    return vfio_device_get_feature(vbasedev, feature);
 }
 
 static int vfio_container_iommu_query_dirty_bitmap(
hw/vfio/device.c +10 -0
index 100532f35d..0d9f42a1f0 100644
@@ -516,6 +516,7 @@ void vfio_device_unprepare(VFIODevice *vbasedev)
     vbasedev->bcontainer = NULL;
 }
 
+
 bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev)
 {
     VFIOPCIDevice *vdev = vfio_pci_from_vfio_device(vbasedev);
@@ -527,6 +528,15 @@ bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev)
     return false;
 }
 
+int vfio_device_get_feature(VFIODevice *vbasedev,
+                            struct vfio_device_feature *feature)
+{
+    if (!vbasedev->io_ops || !vbasedev->io_ops->device_feature) {
+        return -EINVAL;
+    }
+    return vbasedev->io_ops->device_feature(vbasedev, feature);
+}
+
 /*
  * Traditional ioctl() based io
  */
hw/vfio/listener.c +2 -2
index 7af0107535..d00fc87f3b 100644
@@ -879,7 +879,7 @@ static void vfio_devices_dma_logging_stop(VFIOContainer *bcontainer)
             continue;
         }
 
-        ret = vbasedev->io_ops->device_feature(vbasedev, feature);
+        ret = vfio_device_get_feature(vbasedev, feature);
 
         if (ret != 0) {
             warn_report("%s: Failed to stop DMA logging, err %d (%s)",
@@ -984,7 +984,7 @@ static bool vfio_devices_dma_logging_start(VFIOContainer *bcontainer,
             continue;
         }
 
-        ret = vbasedev->io_ops->device_feature(vbasedev, feature);
+        ret = vfio_device_get_feature(vbasedev, feature);
         if (ret) {
             error_setg_errno(errp, -ret, "%s: Failed to start DMA logging",
                              vbasedev->name);
include/hw/vfio/vfio-device.h +3 -0
index 0bc877ff62..315dbb742a 100644
@@ -259,6 +259,9 @@ void vfio_device_unprepare(VFIODevice *vbasedev);
 
 bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev);
 
+int vfio_device_get_feature(VFIODevice *vbasedev,
+                            struct vfio_device_feature *feature);
+
 int vfio_device_get_region_info(VFIODevice *vbasedev, int index,
                                 struct vfio_region_info **info);
 int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type,
Signature · 1 line
2.43.0
Reviewed-by on v2 4/4
#11 lore raw

Re: [PATCH v2 4/4] hw/vfio/region: Create dmabuf for PCI BAR per region

In reply to Shameer Kolothum
Quoted 33 lines · Shameer Kolothum

From: Nicolin Chen <[email protected]>

Linux now provides a VFIO dmabuf exporter to expose PCI BAR memory for P2P use cases. Create a dmabuf for each mapped BAR region after the mmap is set up, and store the returned fd in the region’s RAMBlock. This allows QEMU to pass the fd to dma_map_file(), enabling iommufd to import the dmabuf and map the BAR correctly in the host IOMMU page table.

If the kernel lacks support or dmabuf setup fails, QEMU skips the setup and continues with normal mmap handling.

---
  hw/vfio/region.c     | 69 +++++++++++++++++++++++++++++++++++++++++++-
  hw/vfio/trace-events |  1 +
  2 files changed, 69 insertions(+), 1 deletion(-)
hw/vfio/region.c +1 -0
index ca75ab1be4..8476a54dda 100644
@@ -29,6 +29,7 @@
  #include "qemu/error-report.h"
  #include "qemu/units.h"
  #include "monitor/monitor.h"
+#include "system/ramblock.h"
  #include "vfio-helpers.h"
 
  /*
@@ -238,13 +239,53 @@ static void vfio_subregion_unmap(VFIORegion *region, int index)
      region->mmaps[index].mmap = NULL;
  }

hw/vfio/region.c static void vfio_subregion_unmap(VFIORegion *region, int index) · line 250

Quoted 10 lines
hw/vfio/region.c +9 -0
 
+static int vfio_region_create_dma_buf(VFIORegion *region)
+{
+    g_autofree struct vfio_device_feature *feature = NULL;
+    VFIODevice *vbasedev = region->vbasedev;
+    struct vfio_device_feature_dma_buf *dma_buf;
+    size_t total_size;
+    int i, ret;
+
+    g_assert(region->nr_mmaps);

It's redundant as you have the check in vfio_region_mmap(), it's trivial.

Quoted 62 lines
hw/vfio/region.c +48 -1
+
+    total_size = sizeof(*feature) + sizeof(*dma_buf) +
+                 sizeof(struct vfio_region_dma_range) * region->nr_mmaps;
+    feature = g_malloc0(total_size);
+    *feature = (struct vfio_device_feature) {
+        .argsz = total_size,
+        .flags = VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_DMA_BUF,
+    };
+
+    dma_buf = (void *)feature->data;
+    *dma_buf = (struct vfio_device_feature_dma_buf) {
+        .region_index = region->nr,
+        .open_flags = O_RDWR,
+        .nr_ranges = region->nr_mmaps,
+    };
+
+    for (i = 0; i < region->nr_mmaps; i++) {
+        dma_buf->dma_ranges[i].offset = region->mmaps[i].offset;
+        dma_buf->dma_ranges[i].length = region->mmaps[i].size;
+    }
+
+    ret = vfio_device_get_feature(vbasedev, feature);
+    for (i = 0; i < region->nr_mmaps; i++) {
+        trace_vfio_region_dmabuf(region->vbasedev->name, ret, region->nr,
+                                 memory_region_name(region->mem),
+                                 region->mmaps[i].offset,
+                                 region->mmaps[i].size);
+    }
+    return ret;
+}
+
  int vfio_region_mmap(VFIORegion *region)
  {
      int i, ret, prot = 0;
      char *name;
      int fd;
 
-    if (!region->mem) {
+    if (!region->mem || !region->nr_mmaps) {
          return 0;
      }
 
@@ -305,6 +346,32 @@ int vfio_region_mmap(VFIORegion *region)
                                 region->mmaps[i].size - 1);
      }
 
+    ret = vfio_region_create_dma_buf(region);
+    if (ret < 0) {
+        if (ret == -ENOTTY) {
+            warn_report_once("VFIO dma-buf not supported in kernel: "
+                             "PCI BAR IOMMU mappings may fail");
+        } else {
+            error_report("%s: failed to create dma-buf (%s): "
+                         "PCI BAR IOMMU mappings may fail",
+                         memory_region_name(region->mem), strerror(errno));
+        }
+        /*
+         * Return success as VFIO region mmap succeeded and dmabuf is optional.
+         * P2P DMA or exposing device memory use cases will not be supported.
+         */
+        return 0;
+    }

hw/vfio/region.c int vfio_region_mmap(VFIORegion *region) · line 374

Quoted 10 lines
hw/vfio/region.c +10 -0
+
+    /* Assign the dmabuf fd to associated RAMBlock */
+    for (i = 0; i < region->nr_mmaps; i++) {
+        MemoryRegion *mr = &region->mmaps[i].mem;
+        RAMBlock *ram_block = mr->ram_block;
+
+        ram_block->fd = ret;
+        ram_block->fd_offset = region->mmaps[i].offset;
+    }
+

If you have next respin, maybe cleaner to move above dmabuf related code into

vfio_region_create_dma_buf().Anyway LGTM,

Quoted 15 lines
hw/vfio/region.c +0 -0
      return 0;
 
  no_mmap:
hw/vfio/trace-events +1 -0
index 1e895448cd..592a0349d4 100644
@@ -117,6 +117,7 @@ vfio_device_put(int fd) "close vdev->fd=%d"
  vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)"
  vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint64_t data) " (%s:region%d+0x%"PRIx64", %d) = 0x%"PRIx64
  vfio_region_setup(const char *dev, int index, const char *name, unsigned long flags, unsigned long offset, unsigned long size) "Device %s, region %d \"%s\", flags: 0x%lx, offset: 0x%lx, size: 0x%lx"
+vfio_region_dmabuf(const char *dev, int fd, int index,  const char *name, unsigned long offset, unsigned long size) "Device %s, dmabuf fd %d region %d \"%s\", offset: 0x%lx, size: 0x%lx"
  vfio_region_mmap_fault(const char *name, int index, unsigned long offset, unsigned long size, int fault) "Region %s mmaps[%d], [0x%lx - 0x%lx], fault: %d"
  vfio_region_mmap(const char *name, unsigned long offset, unsigned long end) "Region %s [0x%lx - 0x%lx]"
  vfio_region_exit(const char *name, int index) "Device %s, region %d"
#7 lore raw

Re: [PATCH v2 3/4] hw/vfio: Add helper to retrieve device feature

In reply to Shameer Kolothum
Quoted 6 lines · On Tue, 13 Jan 2026 11:37:53 +0000 Shameer Kolothum <[email protected]>…

Add vfio_device_get_feature() as a common helper to retrieve VFIO device features.

No functional change intended.

Hi Shameer,

Happy new year.

Trivial thing noticed whilst glancing at this.

hw/vfio/device.c void vfio_device_unprepare(VFIODevice *vbasedev) · line 519

Quoted 9 lines
hw/vfio/device.c +1 -0
index 100532f35d..0d9f42a1f0 100644
@@ -516,6 +516,7 @@ void vfio_device_unprepare(VFIODevice *vbasedev)
     vbasedev->bcontainer = NULL;
 }
 
+

Stray change.

Quoted 6 lines
hw/vfio/device.c +0 -0
 bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev)
 {
     VFIOPCIDevice *vdev = vfio_pci_from_vfio_device(vbasedev);
@@ -527,6 +528,15 @@ bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev)
     return false;
 }
#8 lore raw

Re: [PATCH v2 3/4] hw/vfio: Add helper to retrieve device feature

Quoted 23 lines · Jonathan Cameron
Quoted 6 lines · On Tue, 13 Jan 2026 11:37:53 +0000 Shameer Kolothum <[email protected]>…

Add vfio_device_get_feature() as a common helper to retrieve VFIO device features.

No functional change intended.

Hi Shameer,

Happy new year.

Trivial thing noticed whilst glancing at this.

Quoted 8 lines
hw/vfio/device.c +0 -0
index 100532f35d..0d9f42a1f0 100644
@@ -516,6 +516,7 @@ void vfio_device_unprepare(VFIODevice *vbasedev)
      vbasedev->bcontainer = NULL;
  }
 
Quoted 3 lines

hw/vfio/device.c void vfio_device_unprepare(VFIODevice *vbasedev) · line 519

Quoted 1 line
hw/vfio/device.c +1 -0
+

Stray change.

Yeah I can fix that when applying. No need to resend.

Thanks,

C.

Quoted 8 lines
Quoted 7 lines
hw/vfio/device.c +0 -0
  bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev)
  {
      VFIOPCIDevice *vdev = vfio_pci_from_vfio_device(vbasedev);
@@ -527,6 +528,15 @@ bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev)
      return false;
  }
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] linux-headers: Update to Linux v6.19-rc1

In reply to Shameer Kolothum
Quoted 39 lines · Shameer Kolothum

Mainly for adding support for VFIO DMABUF. While at it, update all headers.

---
  include/standard-headers/drm/drm_fourcc.h     |  25 +-
  include/standard-headers/linux/ethtool.h      |   5 +
  .../linux/input-event-codes.h                 |  14 +-
  include/standard-headers/linux/pci_regs.h     |  89 ++++
  include/standard-headers/linux/virtio_net.h   |   3 +-
  include/standard-headers/linux/virtio_pci.h   |   2 +-
  linux-headers/asm-arm64/kvm.h                 |   2 +-
  linux-headers/asm-arm64/unistd_64.h           |   1 +
  linux-headers/asm-generic/unistd.h            |   4 +-
  linux-headers/asm-loongarch/kvm.h             |   1 +
  linux-headers/asm-loongarch/unistd.h          |   6 +
  linux-headers/asm-loongarch/unistd_64.h       |   1 +
  linux-headers/asm-mips/unistd_n32.h           |   1 +
  linux-headers/asm-mips/unistd_n64.h           |   1 +
  linux-headers/asm-mips/unistd_o32.h           |   1 +
  linux-headers/asm-powerpc/unistd_32.h         |   1 +
  linux-headers/asm-powerpc/unistd_64.h         |   1 +
  linux-headers/asm-riscv/kvm.h                 |   3 +
  linux-headers/asm-riscv/unistd_32.h           |   1 +
  linux-headers/asm-riscv/unistd_64.h           |   1 +
  linux-headers/asm-s390/bitsperlong.h          |   4 -
  linux-headers/asm-s390/unistd.h               |   4 -
  linux-headers/asm-s390/unistd_32.h            | 446 ------------------
  linux-headers/asm-s390/unistd_64.h            |   9 +-
  linux-headers/asm-x86/kvm.h                   |   1 +
  linux-headers/asm-x86/unistd_32.h             |   1 +
  linux-headers/asm-x86/unistd_64.h             |   1 +
  linux-headers/asm-x86/unistd_x32.h            |   1 +
  linux-headers/linux/iommufd.h                 |  10 +
  linux-headers/linux/kvm.h                     |  11 +
  linux-headers/linux/mshv.h                    | 116 ++++-
  linux-headers/linux/psp-sev.h                 |  66 ++-
  linux-headers/linux/vfio.h                    |  28 ++
  33 files changed, 363 insertions(+), 498 deletions(-)
Quoted 1 line

delete mode 100644 linux-headers/asm-s390/unistd_32.h

Thanks,

C.

Reviewed-by on v2 2/4
#4 lore raw

Re: [PATCH v2 2/4] hw/net/virtio-net: Adapt hash handling to updated UAPI

In reply to Shameer Kolothum
Quoted 42 lines · Shameer Kolothum

The virtio_net_hdr_v1_hash layout changed in the Linux UAPI, replacing the 32-bit hash_value field with two 16-bit fields, hash_value_lo and hash_value_hi.

Update hash handling to populate the new fields correctly and adjust offset and size calculations accordingly.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>
---
  hw/net/virtio-net.c | 11 +++++++----
  1 file changed, 7 insertions(+), 4 deletions(-)
hw/net/virtio-net.c +4 -2
index 317f1ad23b..512a7c02c9 100644
@@ -1879,7 +1879,8 @@ static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf,
                                               n->rss_data.runtime_hash_types);
      if (net_hash_type > NetPktRssIpV6UdpEx) {
          if (n->rss_data.populate_hash) {
-            hdr->hash_value = VIRTIO_NET_HASH_REPORT_NONE;
+            hdr->hash_value_lo = VIRTIO_NET_HASH_REPORT_NONE;
+            hdr->hash_value_hi = VIRTIO_NET_HASH_REPORT_NONE;
              hdr->hash_report = 0;
          }
          return n->rss_data.redirect ? n->rss_data.default_queue : -1;
@@ -1888,7 +1889,8 @@ static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf,
      hash = net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key);
 
      if (n->rss_data.populate_hash) {
-        hdr->hash_value = hash;
+        hdr->hash_value_lo = cpu_to_le16(hash & 0xffff);
+        hdr->hash_value_hi = cpu_to_le16((hash >> 16) & 0xffff);
          hdr->hash_report = reports[net_hash_type];
      }
 
@@ -1990,10 +1992,11 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
 
              receive_header(n, sg, elem->in_num, buf, size);
              if (n->rss_data.populate_hash) {

hw/net/virtio-net.c static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, · line 2002

Quoted 10 lines
hw/net/virtio-net.c +3 -2
-                offset = offsetof(typeof(extra_hdr), hash_value);
+                offset = offsetof(typeof(extra_hdr), hash_value_lo);
                  iov_from_buf(sg, elem->in_num, offset,
                               (char *)&extra_hdr + offset,
-                             sizeof(extra_hdr.hash_value) +
+                             sizeof(extra_hdr.hash_value_lo) +
+                             sizeof(extra_hdr.hash_value_hi) +
                               sizeof(extra_hdr.hash_report));
              }
              offset = n->host_hdr_len;

Thanks,

C.

Reviewed-by on v2 3/4
#9 lore raw

Re: [PATCH v2 3/4] hw/vfio: Add helper to retrieve device feature

In reply to Shameer Kolothum
Quoted 81 lines · Shameer Kolothum

Add vfio_device_get_feature() as a common helper to retrieve VFIO device features.

No functional change intended.

---
  hw/vfio/container.c           |  2 +-
  hw/vfio/device.c              | 10 ++++++++++
  hw/vfio/listener.c            |  4 ++--
  include/hw/vfio/vfio-device.h |  3 +++
  4 files changed, 16 insertions(+), 3 deletions(-)
hw/vfio/container.c +1 -1
index 5993d90545..b0cbcf0f4a 100644
@@ -208,7 +208,7 @@ static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iova,
      feature->flags = VFIO_DEVICE_FEATURE_GET |
                       VFIO_DEVICE_FEATURE_DMA_LOGGING_REPORT;
 
-    return vbasedev->io_ops->device_feature(vbasedev, feature);
+    return vfio_device_get_feature(vbasedev, feature);
  }
 
  static int vfio_container_iommu_query_dirty_bitmap(
hw/vfio/device.c +10 -0
index 100532f35d..0d9f42a1f0 100644
@@ -516,6 +516,7 @@ void vfio_device_unprepare(VFIODevice *vbasedev)
      vbasedev->bcontainer = NULL;
  }
 
+
  bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev)
  {
      VFIOPCIDevice *vdev = vfio_pci_from_vfio_device(vbasedev);
@@ -527,6 +528,15 @@ bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev)
      return false;
  }
 
+int vfio_device_get_feature(VFIODevice *vbasedev,
+                            struct vfio_device_feature *feature)
+{
+    if (!vbasedev->io_ops || !vbasedev->io_ops->device_feature) {
+        return -EINVAL;
+    }
+    return vbasedev->io_ops->device_feature(vbasedev, feature);
+}
+
  /*
   * Traditional ioctl() based io
   */
hw/vfio/listener.c +2 -2
index 7af0107535..d00fc87f3b 100644
@@ -879,7 +879,7 @@ static void vfio_devices_dma_logging_stop(VFIOContainer *bcontainer)
              continue;
          }
 
-        ret = vbasedev->io_ops->device_feature(vbasedev, feature);
+        ret = vfio_device_get_feature(vbasedev, feature);
 
          if (ret != 0) {
              warn_report("%s: Failed to stop DMA logging, err %d (%s)",
@@ -984,7 +984,7 @@ static bool vfio_devices_dma_logging_start(VFIOContainer *bcontainer,
              continue;
          }
 
-        ret = vbasedev->io_ops->device_feature(vbasedev, feature);
+        ret = vfio_device_get_feature(vbasedev, feature);
          if (ret) {
              error_setg_errno(errp, -ret, "%s: Failed to start DMA logging",
                               vbasedev->name);
include/hw/vfio/vfio-device.h +0 -0
index 0bc877ff62..315dbb742a 100644

include/hw/vfio/vfio-device.h void vfio_device_unprepare(VFIODevice *vbasedev); · line 267

Quoted 9 lines
include/hw/vfio/vfio-device.h +3 -0
@@ -259,6 +259,9 @@ void vfio_device_unprepare(VFIODevice *vbasedev);
 
  bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev);
 
+int vfio_device_get_feature(VFIODevice *vbasedev,
+                            struct vfio_device_feature *feature);
+
  int vfio_device_get_region_info(VFIODevice *vbasedev, int index,
                                  struct vfio_region_info **info);
  int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type,

Thanks,

C.

#12 lore raw

Re: [PATCH v2 4/4] hw/vfio/region: Create dmabuf for PCI BAR per region

In reply to Duan, Zhenzhong
Quoted 118 lines · Zhenzhong
Quoted 31 lines · Shameer Kolothum

From: Nicolin Chen <[email protected]>

Linux now provides a VFIO dmabuf exporter to expose PCI BAR memory for P2P use cases. Create a dmabuf for each mapped BAR region after the mmap is set up, and store the returned fd in the region’s RAMBlock. This allows QEMU to pass the fd to dma_map_file(), enabling iommufd to import the dmabuf and map the BAR correctly in the host IOMMU page table.

If the kernel lacks support or dmabuf setup fails, QEMU skips the setup and continues with normal mmap handling.

---
  hw/vfio/region.c     | 69 +++++++++++++++++++++++++++++++++++++++++++- hw/vfio/trace-events |  1 +

  2 files changed, 69 insertions(+), 1 deletion(-)
hw/vfio/region.c +1 -0
index ca75ab1be4..8476a54dda 100644
@@ -29,6 +29,7 @@
   #include "qemu/error-report.h"
   #include "qemu/units.h"
   #include "monitor/monitor.h"
+#include "system/ramblock.h"
   #include "vfio-helpers.h"
   /*
@@ -238,13 +239,53 @@ static void vfio_subregion_unmap(VFIORegion *region, int index)
       region->mmaps[index].mmap = NULL;

hw/vfio/region.c static void vfio_subregion_unmap(VFIORegion *region, int index) · line 249

Quoted 10 lines
hw/vfio/region.c +9 -0
   }
+static int vfio_region_create_dma_buf(VFIORegion *region)
+{
+    g_autofree struct vfio_device_feature *feature = NULL;
+    VFIODevice *vbasedev = region->vbasedev;
+    struct vfio_device_feature_dma_buf *dma_buf;
+    size_t total_size;
+    int i, ret;
+
+    g_assert(region->nr_mmaps);

It's redundant as you have the check in vfio_region_mmap(), it's trivial.

Quoted 59 lines
hw/vfio/region.c +48 -1
+
+    total_size = sizeof(*feature) + sizeof(*dma_buf) +
+                 sizeof(struct vfio_region_dma_range) * region->nr_mmaps;
+    feature = g_malloc0(total_size);
+    *feature = (struct vfio_device_feature) {
+        .argsz = total_size,
+        .flags = VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_DMA_BUF,
+    };
+
+    dma_buf = (void *)feature->data;
+    *dma_buf = (struct vfio_device_feature_dma_buf) {
+        .region_index = region->nr,
+        .open_flags = O_RDWR,
+        .nr_ranges = region->nr_mmaps,
+    };
+
+    for (i = 0; i < region->nr_mmaps; i++) {
+        dma_buf->dma_ranges[i].offset = region->mmaps[i].offset;
+        dma_buf->dma_ranges[i].length = region->mmaps[i].size;
+    }
+
+    ret = vfio_device_get_feature(vbasedev, feature);
+    for (i = 0; i < region->nr_mmaps; i++) {
+        trace_vfio_region_dmabuf(region->vbasedev->name, ret, region->nr,
+                                 memory_region_name(region->mem),
+                                 region->mmaps[i].offset,
+                                 region->mmaps[i].size);
+    }
+    return ret;
+}
+
   int vfio_region_mmap(VFIORegion *region)
   {
       int i, ret, prot = 0;
       char *name;
       int fd;
-    if (!region->mem) {
+    if (!region->mem || !region->nr_mmaps) {
           return 0;
       }
@@ -305,6 +346,32 @@ int vfio_region_mmap(VFIORegion *region)
                                  region->mmaps[i].size - 1);
       }
+    ret = vfio_region_create_dma_buf(region);
+    if (ret < 0) {
+        if (ret == -ENOTTY) {
+            warn_report_once("VFIO dma-buf not supported in kernel: "
+                             "PCI BAR IOMMU mappings may fail");
+        } else {
+            error_report("%s: failed to create dma-buf (%s): "
+                         "PCI BAR IOMMU mappings may fail",
+                         memory_region_name(region->mem), strerror(errno));
+        }
+        /*
+         * Return success as VFIO region mmap succeeded and dmabuf is optional.
+         * P2P DMA or exposing device memory use cases will not be supported.
+         */
+        return 0;
+    }

hw/vfio/region.c int vfio_region_mmap(VFIORegion *region) · line 373

Quoted 10 lines
hw/vfio/region.c +10 -0
+
+    /* Assign the dmabuf fd to associated RAMBlock */
+    for (i = 0; i < region->nr_mmaps; i++) {
+        MemoryRegion *mr = &region->mmaps[i].mem;
+        RAMBlock *ram_block = mr->ram_block;
+
+        ram_block->fd = ret;
+        ram_block->fd_offset = region->mmaps[i].offset;
+    }
+

If you have next respin, maybe cleaner to move above dmabuf related code into

Quoted 1 line

vfio_region_create_dma_buf().

I agree. Can you please respin a v3 Shameer ?

Thanks,

C.

Quoted 19 lines

Anyway LGTM,

Quoted 14 lines
hw/vfio/region.c +0 -0
       return 0;

  no_mmap:

hw/vfio/trace-events +0 -0
index 1e895448cd..592a0349d4 100644
@@ -117,6 +117,7 @@ vfio_device_put(int fd) "close vdev->fd=%d"

  vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)"
  vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint64_t data) " (%s:region%d+0x%"PRIx64", %d) = 0x%"PRIx64
  vfio_region_setup(const char *dev, int index, const char *name, unsigned long flags, unsigned long offset, unsigned long size) "Device %s, region %d \"%s\", flags: 0x%lx, offset: 0x%lx, size: 0x%lx" +vfio_region_dmabuf(const char *dev, int fd, int index,  const char *name, unsigned long offset, unsigned long size) "Device %s, dmabuf fd %d region %d \"%s\", offset: 0x%lx, size: 0x%lx" vfio_region_mmap_fault(const char *name, int index, unsigned long offset, unsigned long size, int fault) "Region %s mmaps[%d], [0x%lx - 0x%lx], fault: %d" vfio_region_mmap(const char *name, unsigned long offset, unsigned long end) "Region %s [0x%lx - 0x%lx]"
  vfio_region_exit(const char *name, int index) "Device %s, region %d"

#13 lore raw

RE: [PATCH v2 4/4] hw/vfio/region: Create dmabuf for PCI BAR per region

Quoted 15 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 15 January 2026 12:51
To: Duan, Zhenzhong <[email protected]>; Shameer Kolothum <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Nicolin Chen <[email protected]>; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; Jason Gunthorpe <[email protected]>; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v2 4/4] hw/vfio/region: Create dmabuf for PCI BAR per region

[...]

Quoted 6 lines
Quoted 1 line

If you have next respin, maybe cleaner to move above dmabuf related code

into

Quoted 2 lines

vfio_region_create_dma_buf().

I agree. Can you please respin a v3 Shameer ?

Ok. Just to confirm, does below look good:

Thanks,
Shameer

...

hw/vfio/region.c +60 -1
index ca75ab1be4..f927e64365 100644
@@ -29,6 +29,7 @@
 #include "qemu/error-report.h"
 #include "qemu/units.h"
 #include "monitor/monitor.h"
+#include "system/ramblock.h"
 #include "vfio-helpers.h"
 
 /*
@@ -238,13 +239,69 @@ static void vfio_subregion_unmap(VFIORegion *region, int index)
     region->mmaps[index].mmap = NULL;
 }
 
+static void vfio_region_create_dma_buf(VFIORegion *region)
+{
+    g_autofree struct vfio_device_feature *feature = NULL;
+    VFIODevice *vbasedev = region->vbasedev;
+    struct vfio_device_feature_dma_buf *dma_buf;
+    size_t total_size;
+    int i, ret;
+
+    total_size = sizeof(*feature) + sizeof(*dma_buf) +
+                 sizeof(struct vfio_region_dma_range) * region->nr_mmaps;
+    feature = g_malloc0(total_size);
+    *feature = (struct vfio_device_feature) {
+        .argsz = total_size,
+        .flags = VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_DMA_BUF,
+    };
+
+    dma_buf = (void *)feature->data;
+    *dma_buf = (struct vfio_device_feature_dma_buf) {
+        .region_index = region->nr,
+        .open_flags = O_RDWR,
+        .nr_ranges = region->nr_mmaps,
+    };
+
+    for (i = 0; i < region->nr_mmaps; i++) {
+        dma_buf->dma_ranges[i].offset = region->mmaps[i].offset;
+        dma_buf->dma_ranges[i].length = region->mmaps[i].size;
+    }
+
+    ret = vfio_device_get_feature(vbasedev, feature);
+    if (ret < 0) {
+        if (ret == -ENOTTY) {
+            warn_report_once("VFIO dma-buf not supported in kernel: "
+                             "PCI BAR IOMMU mappings may fail");
+        } else {
+            error_report("%s: failed to create dma-buf (%s): "
+                         "PCI BAR IOMMU mappings may fail",
+                         memory_region_name(region->mem), strerror(errno));
+        }
+        /* P2P DMA or exposing device memory use cases are not supported. */
+        return;
+    }
+
+    /* Assign the dmabuf fd to associated RAMBlock */
+    for (i = 0; i < region->nr_mmaps; i++) {
+        MemoryRegion *mr = &region->mmaps[i].mem;
+        RAMBlock *ram_block = mr->ram_block;
+
+        ram_block->fd = ret;
+        ram_block->fd_offset = region->mmaps[i].offset;
+        trace_vfio_region_dmabuf(region->vbasedev->name, ret, region->nr,
+                                 memory_region_name(region->mem),
+                                 region->mmaps[i].offset,
+                                 region->mmaps[i].size);
+    }
+}
+
 int vfio_region_mmap(VFIORegion *region)
 {
     int i, ret, prot = 0;
     char *name;
     int fd;
 
-    if (!region->mem) {
+    if (!region->mem || !region->nr_mmaps) {
         return 0;
     }
 
@@ -305,6 +362,8 @@ int vfio_region_mmap(VFIORegion *region)
                                region->mmaps[i].size - 1);
     }
 
+    vfio_region_create_dma_buf(region);
+
     return 0;
 
 no_mmap:
hw/vfio/trace-events +1 -0
index 180e3d526b..466695507b 100644
@@ -118,6 +118,7 @@ vfio_device_put(int fd) "close vdev->fd=%d"
 vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)"
 vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint64_t data) " (%s:region%d+0x%"PRIx64", %d) = 0x%"PRIx64
 vfio_region_setup(const char *dev, int index, const char *name, unsigned long flags, unsigned long offset, unsigned long size) "Device %s, region %d \"%s\", flags: 0x%lx, offset: 0x%lx, size: 0x%lx"
+vfio_region_dmabuf(const char *dev, int fd, int index,  const char *name, unsigned long offset, unsigned long size) "Device %s, dmabuf fd %d region %d \"%s\", offset: 0x%lx, size: 0x%lx"
 vfio_region_mmap_fault(const char *name, int index, unsigned long offset, unsigned long size, int fault) "Region %s mmaps[%d], [0x%lx - 0x%lx], fault: %d"
 vfio_region_mmap(const char *name, unsigned long offset, unsigned long end) "Region %s [0x%lx - 0x%lx]"
 vfio_region_exit(const char *name, int index) "Device %s, region %d"
#14 lore raw

Re: [PATCH v2 4/4] hw/vfio/region: Create dmabuf for PCI BAR per region

Quoted 18 lines · Shameer Kolothum
Quoted 15 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 15 January 2026 12:51
To: Duan, Zhenzhong <[email protected]>; Shameer Kolothum <[email protected]>; [email protected]; qemu- [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Nicolin Chen <[email protected]>; Nathan Chen <[email protected]>; Matt Ochs <[email protected]>; Jason Gunthorpe <[email protected]>; Krishnakant Jaju <[email protected]>
Subject: Re: [PATCH v2 4/4] hw/vfio/region: Create dmabuf for PCI BAR per region

[...]

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

If you have next respin, maybe cleaner to move above dmabuf related code

into

Quoted 2 lines

vfio_region_create_dma_buf().

I agree. Can you please respin a v3 Shameer ?

Ok. Just to confirm, does below look good:

it does.

Quoted 18 lines

Thanks,
Shameer

...

hw/vfio/region.c +1 -0
index ca75ab1be4..f927e64365 100644
@@ -29,6 +29,7 @@
  #include "qemu/error-report.h"
  #include "qemu/units.h"
  #include "monitor/monitor.h"
+#include "system/ramblock.h"
  #include "vfio-helpers.h"
 
  /*

hw/vfio/region.c static void vfio_subregion_unmap(VFIORegion *region, int index) · line 243

Quoted 5 lines
hw/vfio/region.c +2 -0
@@ -238,13 +239,69 @@ static void vfio_subregion_unmap(VFIORegion *region, int index)
      region->mmaps[index].mmap = NULL;
  }
 
+static void vfio_region_create_dma_buf(VFIORegion *region)
+{

While at changing things, could you please add an 'Error** errp' parameter to vfio_region_create_dma_buf() and make it return a bool.

Quoted 66 lines
hw/vfio/region.c +55 -1
+    g_autofree struct vfio_device_feature *feature = NULL;
+    VFIODevice *vbasedev = region->vbasedev;
+    struct vfio_device_feature_dma_buf *dma_buf;
+    size_t total_size;
+    int i, ret;
+
+    total_size = sizeof(*feature) + sizeof(*dma_buf) +
+                 sizeof(struct vfio_region_dma_range) * region->nr_mmaps;
+    feature = g_malloc0(total_size);
+    *feature = (struct vfio_device_feature) {
+        .argsz = total_size,
+        .flags = VFIO_DEVICE_FEATURE_GET | VFIO_DEVICE_FEATURE_DMA_BUF,
+    };
+
+    dma_buf = (void *)feature->data;
+    *dma_buf = (struct vfio_device_feature_dma_buf) {
+        .region_index = region->nr,
+        .open_flags = O_RDWR,
+        .nr_ranges = region->nr_mmaps,
+    };
+
+    for (i = 0; i < region->nr_mmaps; i++) {
+        dma_buf->dma_ranges[i].offset = region->mmaps[i].offset;
+        dma_buf->dma_ranges[i].length = region->mmaps[i].size;
+    }
+
+    ret = vfio_device_get_feature(vbasedev, feature);
+    if (ret < 0) {
+        if (ret == -ENOTTY) {
+            warn_report_once("VFIO dma-buf not supported in kernel: "
+                             "PCI BAR IOMMU mappings may fail");
+        } else {
+            error_report("%s: failed to create dma-buf (%s): "
+                         "PCI BAR IOMMU mappings may fail",
+                         memory_region_name(region->mem), strerror(errno));
+        }
+        /* P2P DMA or exposing device memory use cases are not supported. */
+        return;
+    }
+
+    /* Assign the dmabuf fd to associated RAMBlock */
+    for (i = 0; i < region->nr_mmaps; i++) {
+        MemoryRegion *mr = &region->mmaps[i].mem;
+        RAMBlock *ram_block = mr->ram_block;
+
+        ram_block->fd = ret;
+        ram_block->fd_offset = region->mmaps[i].offset;
+        trace_vfio_region_dmabuf(region->vbasedev->name, ret, region->nr,
+                                 memory_region_name(region->mem),
+                                 region->mmaps[i].offset,
+                                 region->mmaps[i].size);
+    }
+}
+
  int vfio_region_mmap(VFIORegion *region)
  {
      int i, ret, prot = 0;
      char *name;
      int fd;
 
-    if (!region->mem) {
+    if (!region->mem || !region->nr_mmaps) {
          return 0;
      }
 

hw/vfio/region.c int vfio_region_mmap(VFIORegion *region) · line 366

Quoted 5 lines
hw/vfio/region.c +2 -0
@@ -305,6 +362,8 @@ int vfio_region_mmap(VFIORegion *region)
                                 region->mmaps[i].size - 1);
      }
 
+    vfio_region_create_dma_buf(region);
+

vfio_region_mmap() would then test the returned value and call error_report_err() on the error.

In follow-ups patches, we could propagate this error to callers of vfio_region_mmap(). Can come later.

Thanks,

C.

Quoted 17 lines
hw/vfio/region.c +0 -0
      return 0;
 
  no_mmap:
hw/vfio/trace-events +1 -0
index 180e3d526b..466695507b 100644
@@ -118,6 +118,7 @@ vfio_device_put(int fd) "close vdev->fd=%d"
  vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)"
  vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint64_t data) " (%s:region%d+0x%"PRIx64", %d) = 0x%"PRIx64
  vfio_region_setup(const char *dev, int index, const char *name, unsigned long flags, unsigned long offset, unsigned long size) "Device %s, region %d \"%s\", flags: 0x%lx, offset: 0x%lx, size: 0x%lx"
+vfio_region_dmabuf(const char *dev, int fd, int index,  const char *name, unsigned long offset, unsigned long size) "Device %s, dmabuf fd %d region %d \"%s\", offset: 0x%lx, size: 0x%lx"
  vfio_region_mmap_fault(const char *name, int index, unsigned long offset, unsigned long size, int fault) "Region %s mmaps[%d], [0x%lx - 0x%lx], fault: %d"
  vfio_region_mmap(const char *name, unsigned long offset, unsigned long end) "Region %s [0x%lx - 0x%lx]"
  vfio_region_exit(const char *name, int index) "Device %s, region %d"
#5 lore raw

Re: [PATCH v2 2/4] hw/net/virtio-net: Adapt hash handling to updated UAPI

In reply to Shameer Kolothum
Quoted 10 lines · Shameer Kolothum

The virtio_net_hdr_v1_hash layout changed in the Linux UAPI, replacing the 32-bit hash_value field with two 16-bit fields, hash_value_lo and hash_value_hi.

Update hash handling to populate the new fields correctly and adjust offset and size calculations accordingly.

Cc Michael S. Tsirkin <[email protected]>
Cc Jason Wang <[email protected]>

Has to be squashed in patch 1 or bisect will be broken.

Quoted 44 lines
---
 hw/net/virtio-net.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
hw/net/virtio-net.c +7 -4
index 317f1ad23b..512a7c02c9 100644
@@ -1879,7 +1879,8 @@ static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf,
                                              n->rss_data.runtime_hash_types);
     if (net_hash_type > NetPktRssIpV6UdpEx) {
         if (n->rss_data.populate_hash) {
-            hdr->hash_value = VIRTIO_NET_HASH_REPORT_NONE;
+            hdr->hash_value_lo = VIRTIO_NET_HASH_REPORT_NONE;
+            hdr->hash_value_hi = VIRTIO_NET_HASH_REPORT_NONE;
             hdr->hash_report = 0;
         }
         return n->rss_data.redirect ? n->rss_data.default_queue : -1;
@@ -1888,7 +1889,8 @@ static int virtio_net_process_rss(NetClientState *nc, const uint8_t *buf,
     hash = net_rx_pkt_calc_rss_hash(pkt, net_hash_type, n->rss_data.key);
 
     if (n->rss_data.populate_hash) {
-        hdr->hash_value = hash;
+        hdr->hash_value_lo = cpu_to_le16(hash & 0xffff);
+        hdr->hash_value_hi = cpu_to_le16((hash >> 16) & 0xffff);
         hdr->hash_report = reports[net_hash_type];
     }
 
@@ -1990,10 +1992,11 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
 
             receive_header(n, sg, elem->in_num, buf, size);
             if (n->rss_data.populate_hash) {
-                offset = offsetof(typeof(extra_hdr), hash_value);
+                offset = offsetof(typeof(extra_hdr), hash_value_lo);
                 iov_from_buf(sg, elem->in_num, offset,
                              (char *)&extra_hdr + offset,
-                             sizeof(extra_hdr.hash_value) +
+                             sizeof(extra_hdr.hash_value_lo) +
+                             sizeof(extra_hdr.hash_value_hi) +
                              sizeof(extra_hdr.hash_report));
             }
             offset = n->host_hdr_len;
Signature · 1 line
2.43.0