From: Shameer Kolothum Date: Wed, 21 Jan 2026 11:41:10 +0000 (+0000) Subject: hw/vfio: Add helper to retrieve device feature X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de36da106dcfd42ee79779a25713e86500276382;p=thirdparty%2Fqemu.git hw/vfio: Add helper to retrieve device feature Add vfio_device_get_feature() as a common helper to retrieve VFIO device features. No functional change intended. Reviewed-by: Cédric Le Goater Signed-off-by: Shameer Kolothum Reviewed-by: Eric Auger Tested-by: Eric Auger Reviewed-by: Michael S. Tsirkin Link: https://lore.kernel.org/qemu-devel/20260121114111.34045-3-skolothumtho@nvidia.com Signed-off-by: Cédric Le Goater --- diff --git a/hw/vfio/container.c b/hw/vfio/container.c index af16cd14db..4c2816b574 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -205,7 +205,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( diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 086f20f676..973fc35b59 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -547,6 +547,15 @@ bool vfio_device_get_host_iommu_quirk_bypass_ro(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 */ diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c index 8ba1cd255d..1087fdc142 100644 --- a/hw/vfio/listener.c +++ b/hw/vfio/listener.c @@ -909,7 +909,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)", @@ -1014,7 +1014,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); diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index f6f3d0e378..35a5ec6d92 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -272,6 +272,9 @@ bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODevice *vbasedev, uint32_t type, void *caps, uint32_t size); +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,