From: Zhenzhong Duan Date: Wed, 23 Apr 2025 07:28:20 +0000 (+0800) Subject: vfio/iommufd: Make a separate call to get IOMMU capabilities X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=436114cc4390ff46535229e67e43056196a971c1;p=thirdparty%2Fqemu.git vfio/iommufd: Make a separate call to get IOMMU capabilities Currently we depend on .realize() calling iommufd_backend_get_device_info() to get IOMMU capabilities and check for dirty page tracking support. By make a extra separate call, this dependency is removed. This happens only during device attach, it's not a hot path. Suggested-by: Cédric Le Goater Signed-off-by: Zhenzhong Duan Reviewed-by: Joao Martins Reviewed-by: Cédric Le Goater Link: https://lore.kernel.org/qemu-devel/20250423072824.3647952-2-zhenzhong.duan@intel.com Signed-off-by: Cédric Le Goater --- diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 48db105422..2253778b3a 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -287,7 +287,8 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev, { ERRP_GUARD(); IOMMUFDBackend *iommufd = vbasedev->iommufd; - uint32_t flags = 0; + uint32_t type, flags = 0; + uint64_t hw_caps; VFIOIOASHwpt *hwpt; uint32_t hwpt_id; int ret; @@ -324,7 +325,12 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev, * vfio_migration_realize() may decide to use VF dirty tracking * instead. */ - if (vbasedev->hiod->caps.hw_caps & IOMMU_HW_CAP_DIRTY_TRACKING) { + if (!iommufd_backend_get_device_info(vbasedev->iommufd, vbasedev->devid, + &type, NULL, 0, &hw_caps, errp)) { + return false; + } + + if (hw_caps & IOMMU_HW_CAP_DIRTY_TRACKING) { flags = IOMMU_HWPT_ALLOC_DIRTY_TRACKING; }