vfio: Add VFIO I/O backend capability flags for feature support
PATCH 1/1 vfio: Add VFIO I/O backend capability flags for feature support
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.
--- include/hw/vfio/vfio-device.h | 13 +++++++++++++ hw/vfio/device.c | 2 ++ hw/vfio/region.c | 5 +++++ 3 files changed, 20 insertions(+)
include/hw/vfio/vfio-device.h +13 -0
@@ -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 *
hw/vfio/device.c +2 -0
@@ -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,
hw/vfio/region.c +5 -0
@@ -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);
Signature · 1 line
2.53.0
Quoted 11 lines · Cédric Le Goater
!-------------------------------------------------------------------|
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.
Quoted 7 lines
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 <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Thanks!
regards
john
Cédric Le Goater
AppliedQuoted 68 lines · Cédric Le Goater
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 <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- include/hw/vfio/vfio-device.h | 13 +++++++++++++ hw/vfio/device.c | 2 ++ hw/vfio/region.c | 5 +++++ 3 files changed, 20 insertions(+)include/hw/vfio/vfio-device.h +13
-0@@ -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 *hw/vfio/device.c +2
-0@@ -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,hw/vfio/region.c +0
-0@@ -293,6 +293,11 @@ static bool vfio_region_create_dma_buf(VFIORegion *region, Error **errp)size_t total_size;
hw/vfio/region.c static bool vfio_region_create_dma_buf(VFIORegion *region, Error **errp) · line 303
Quoted 10 lines
hw/vfio/region.c +5
-0int 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.