From: Naman Gulati <namangulati@google.com>
To: qemu-devel@nongnu.org
Cc: "John Levon" <john.levon@nutanix.com>,
"Thanos Makatos" <thanos.makatos@nutanix.com>,
"Cédric Le Goater" <clg@redhat.com>,
"Alex Williamson" <alex@shazbot.org>,
"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
"Matt Evans" <matt@ozlabs.org>,
"Naman Gulati" <namangulati@google.com>
Subject: [PATCH v5 3/4] vfio: add setup_sparse_mmaps hook to VFIODeviceIOOps
Date: Wed, 14 Oct 2026 21:10:40 +0000 [thread overview]
Message-ID: <20261014211041.1087331-4-namangulati@google.com> (raw)
In-Reply-To: <20261014211041.1087331-1-namangulati@google.com>
Add a setup_sparse_mmaps callback to VFIODeviceIOOps so transport
backends (such as vfio-user) can parse custom sparse mmap capabilities,
falling back to vfio_default_setup_sparse_mmaps() to process shared
VFIO mmap capabilities.
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Signed-off-by: Naman Gulati <namangulati@google.com>
---
hw/vfio/vfio-region.h | 5 +++++
include/hw/vfio/vfio-device.h | 16 ++++++++++++++++
hw/vfio/device.c | 1 +
hw/vfio/region.c | 19 ++++++++++++++++---
4 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/hw/vfio/vfio-region.h b/hw/vfio/vfio-region.h
index 9f6a5cf7d5..a0c9533f9f 100644
--- a/hw/vfio/vfio-region.h
+++ b/hw/vfio/vfio-region.h
@@ -46,4 +46,9 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled);
void vfio_region_exit(VFIORegion *region);
void vfio_region_finalize(VFIORegion *region);
+struct vfio_region_info;
+int vfio_default_setup_sparse_mmaps(VFIORegion *region,
+ struct vfio_region_info *info,
+ Error **errp);
+
#endif /* HW_VFIO_REGION_H */
diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index 8472420d3f..3136e152f2 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -43,6 +43,7 @@ enum {
typedef struct VFIODeviceOps VFIODeviceOps;
typedef struct VFIODeviceIOOps VFIODeviceIOOps;
+typedef struct VFIORegion VFIORegion;
typedef struct VFIOMigration VFIOMigration;
typedef struct IOMMUFDBackend IOMMUFDBackend;
@@ -218,6 +219,21 @@ struct VFIODeviceIOOps {
int (*get_region_info)(VFIODevice *vdev,
struct vfio_region_info *info, int *fd);
+ /**
+ * @setup_sparse_mmaps
+ *
+ * Parse sparse mmap capabilities for a region and initialize region->mmaps.
+ *
+ * @region: #VFIORegion to set up
+ * @info: region info struct containing capabilities
+ * @errp: pointer to Error*, to store an error if it happens
+ *
+ * Returns 0 on success, -ENODEV if not sparse, or negative error code.
+ */
+ int (*setup_sparse_mmaps)(VFIORegion *region,
+ struct vfio_region_info *info,
+ Error **errp);
+
/**
* @get_irq_info
*
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 4f11959633..94d6e7ce09 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -662,6 +662,7 @@ static VFIODeviceIOOps vfio_device_io_ops_ioctl = {
.device_feature = vfio_device_io_device_feature,
.get_region_info = vfio_device_io_get_region_info,
+ .setup_sparse_mmaps = vfio_default_setup_sparse_mmaps,
.get_irq_info = vfio_device_io_get_irq_info,
.set_irqs = vfio_device_io_set_irqs,
.region_read = vfio_device_io_region_read,
diff --git a/hw/vfio/region.c b/hw/vfio/region.c
index 16efed2fce..94cfb708bf 100644
--- a/hw/vfio/region.c
+++ b/hw/vfio/region.c
@@ -162,9 +162,9 @@ static int vfio_mmap_compare_offset(const void *a, const void *b)
return 0;
}
-static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
- struct vfio_region_info *info,
- Error **errp)
+int vfio_default_setup_sparse_mmaps(VFIORegion *region,
+ struct vfio_region_info *info,
+ Error **errp)
{
struct vfio_info_cap_header *hdr;
struct vfio_region_info_cap_sparse_mmap *sparse;
@@ -198,6 +198,19 @@ static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
region->nr_mmaps = j;
region->mmaps = g_realloc(region->mmaps, j * sizeof(VFIOMmap));
+ return 0;
+}
+
+static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
+ struct vfio_region_info *info,
+ Error **errp)
+{
+ int ret, i;
+
+ ret = region->vbasedev->io_ops->setup_sparse_mmaps(region, info, errp);
+ if (ret) {
+ return ret;
+ }
/*
* Sort sparse mmaps by offset to ensure proper handling of gaps
--
2.56.0.385.gd3acb90ef8-goog
next prev parent reply other threads:[~2026-10-14 21:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 21:10 [PATCH v5 0/4] vfio-user: support multiple FDs backing region mmaps Naman Gulati
2026-10-14 21:10 ` [PATCH v5 1/4] vfio-user: add multi-fd region mmap capability Naman Gulati
2026-10-14 21:10 ` [PATCH v5 2/4] vfio: add 'fd' and 'fd_offset' to VFIOMmap Naman Gulati
2026-10-15 7:39 ` Cédric Le Goater
2026-10-14 21:10 ` Naman Gulati [this message]
2026-10-15 7:39 ` [PATCH v5 3/4] vfio: add setup_sparse_mmaps hook to VFIODeviceIOOps Cédric Le Goater
2026-10-15 7:41 ` Cédric Le Goater
2026-10-14 21:10 ` [PATCH v5 4/4] vfio-user: support multiple FDs for sparse mmap regions Naman Gulati
2026-10-15 7:45 ` Cédric Le Goater
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261014211041.1087331-4-namangulati@google.com \
--to=namangulati@google.com \
--cc=alex@shazbot.org \
--cc=clg@redhat.com \
--cc=john.levon@nutanix.com \
--cc=matt@ozlabs.org \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
--cc=thanos.makatos@nutanix.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.