include/hw/vfio/vfio-device.h | 13 +++++++++++++ hw/vfio/device.c | 2 ++ hw/vfio/region.c | 5 +++++ 3 files changed, 20 insertions(+)
Different VFIO I/O backends support different features. For example,
the kernel VFIO backend supports DMA-BUF creation, while vfio-user
does not. Currently, this is handled by attempting the operation and
checking for -ENOTTY, which can lead to misleading warnings when a
feature is simply not supported by a particular backend.
Introduce a capability flags mechanism in VFIODeviceIOOps that allows
backends to explicitly advertise which features they support. Callers
can check these capabilities before attempting operations, avoiding
spurious errors and warnings.
Cc: John Levon <john.levon@nutanix.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
include/hw/vfio/vfio-device.h | 13 +++++++++++++
hw/vfio/device.c | 2 ++
hw/vfio/region.c | 5 +++++
3 files changed, 20 insertions(+)
diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index a95c5bf50302a7394582dcc493d96aef00b47dc8..380a55d6e5ea280c8f44016c7a8a1dcb8f4c00fe 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -172,12 +172,25 @@ typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
extern VFIODeviceList vfio_device_list;
#ifdef CONFIG_LINUX
+/*
+ * VFIO backend I/O operation capabilities
+ */
+#define VFIO_IO_CAP_DMA_BUF (1ULL << 0)
+
/*
* How devices communicate with the server. The default option is through
* ioctl() to the kernel VFIO driver, but vfio-user can use a socket to a remote
* process.
*/
struct VFIODeviceIOOps {
+ /**
+ * @capabilities
+ *
+ * Bitmask of VFIO_IO_CAP_* flags indicating which features this
+ * backend supports.
+ */
+ uint64_t capabilities;
+
/**
* @device_feature
*
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 8f7ae919a55dd9e08bdd072eee33f5b46a91aa2a..3ffd69a579b8ac135ef729d3d836c8545e36786b 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -648,6 +648,8 @@ static int vfio_device_io_region_write(VFIODevice *vbasedev, uint8_t index,
}
static VFIODeviceIOOps vfio_device_io_ops_ioctl = {
+ .capabilities = VFIO_IO_CAP_DMA_BUF,
+
.device_feature = vfio_device_io_device_feature,
.get_region_info = vfio_device_io_get_region_info,
.get_irq_info = vfio_device_io_get_irq_info,
diff --git a/hw/vfio/region.c b/hw/vfio/region.c
index 47fdc2df349b65c6be6c9605b7a38a4e367f0475..0342ca712acd0ad846685115c29432c15aa966a0 100644
--- a/hw/vfio/region.c
+++ b/hw/vfio/region.c
@@ -293,6 +293,11 @@ static bool vfio_region_create_dma_buf(VFIORegion *region, Error **errp)
size_t total_size;
int i, ret;
+ /* Check if backend supports DMA-BUF creation */
+ if (!(vbasedev->io_ops->capabilities & VFIO_IO_CAP_DMA_BUF)) {
+ return true;
+ }
+
total_size = sizeof(*feature) + sizeof(*dma_buf) +
sizeof(struct vfio_region_dma_range) * region->nr_mmaps;
feature = g_malloc0(total_size);
--
2.53.0
On 4/9/26 13:43, Cédric Le Goater wrote:
> Different VFIO I/O backends support different features. For example,
> the kernel VFIO backend supports DMA-BUF creation, while vfio-user
> does not. Currently, this is handled by attempting the operation and
> checking for -ENOTTY, which can lead to misleading warnings when a
> feature is simply not supported by a particular backend.
>
> Introduce a capability flags mechanism in VFIODeviceIOOps that allows
> backends to explicitly advertise which features they support. Callers
> can check these capabilities before attempting operations, avoiding
> spurious errors and warnings.
>
> Cc: John Levon <john.levon@nutanix.com>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
> include/hw/vfio/vfio-device.h | 13 +++++++++++++
> hw/vfio/device.c | 2 ++
> hw/vfio/region.c | 5 +++++
> 3 files changed, 20 insertions(+)
>
> diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
> index a95c5bf50302a7394582dcc493d96aef00b47dc8..380a55d6e5ea280c8f44016c7a8a1dcb8f4c00fe 100644
> --- a/include/hw/vfio/vfio-device.h
> +++ b/include/hw/vfio/vfio-device.h
> @@ -172,12 +172,25 @@ typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList;
> extern VFIODeviceList vfio_device_list;
>
> #ifdef CONFIG_LINUX
> +/*
> + * VFIO backend I/O operation capabilities
> + */
> +#define VFIO_IO_CAP_DMA_BUF (1ULL << 0)
> +
> /*
> * How devices communicate with the server. The default option is through
> * ioctl() to the kernel VFIO driver, but vfio-user can use a socket to a remote
> * process.
> */
> struct VFIODeviceIOOps {
> + /**
> + * @capabilities
> + *
> + * Bitmask of VFIO_IO_CAP_* flags indicating which features this
> + * backend supports.
> + */
> + uint64_t capabilities;
> +
> /**
> * @device_feature
> *
> diff --git a/hw/vfio/device.c b/hw/vfio/device.c
> index 8f7ae919a55dd9e08bdd072eee33f5b46a91aa2a..3ffd69a579b8ac135ef729d3d836c8545e36786b 100644
> --- a/hw/vfio/device.c
> +++ b/hw/vfio/device.c
> @@ -648,6 +648,8 @@ static int vfio_device_io_region_write(VFIODevice *vbasedev, uint8_t index,
> }
>
> static VFIODeviceIOOps vfio_device_io_ops_ioctl = {
> + .capabilities = VFIO_IO_CAP_DMA_BUF,
> +
> .device_feature = vfio_device_io_device_feature,
> .get_region_info = vfio_device_io_get_region_info,
> .get_irq_info = vfio_device_io_get_irq_info,
> diff --git a/hw/vfio/region.c b/hw/vfio/region.c
> index 47fdc2df349b65c6be6c9605b7a38a4e367f0475..0342ca712acd0ad846685115c29432c15aa966a0 100644
> --- a/hw/vfio/region.c
> +++ b/hw/vfio/region.c
> @@ -293,6 +293,11 @@ static bool vfio_region_create_dma_buf(VFIORegion *region, Error **errp)
> size_t total_size;
> int i, ret;
>
> + /* Check if backend supports DMA-BUF creation */
> + if (!(vbasedev->io_ops->capabilities & VFIO_IO_CAP_DMA_BUF)) {
> + return true;
> + }
> +
> total_size = sizeof(*feature) + sizeof(*dma_buf) +
> sizeof(struct vfio_region_dma_range) * region->nr_mmaps;
> feature = g_malloc0(total_size);
Applied to vfio-next.
Thanks,
C.
On Thu, Apr 09, 2026 at 01:43:12PM +0200, Cédric Le Goater wrote: > !-------------------------------------------------------------------| > CAUTION: External Email > > |-------------------------------------------------------------------! > > Different VFIO I/O backends support different features. For example, > the kernel VFIO backend supports DMA-BUF creation, while vfio-user > does not. Currently, this is handled by attempting the operation and > checking for -ENOTTY, which can lead to misleading warnings when a > feature is simply not supported by a particular backend. > > Introduce a capability flags mechanism in VFIODeviceIOOps that allows > backends to explicitly advertise which features they support. Callers > can check these capabilities before attempting operations, avoiding > spurious errors and warnings. > > Cc: John Levon <john.levon@nutanix.com> > Signed-off-by: Cédric Le Goater <clg@redhat.com> Thanks! Reviewed-by: John Levon <john.levon@nutanix.com> regards john
© 2016 - 2026 Red Hat, Inc.