On 23/04/2025 08:28, Zhenzhong Duan wrote:
> 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 <c...@redhat.com>
> Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com>

I think this looks right now as it's placed in the auto domains path where mdevs
aren't involved:

        Reviewed-by: Joao Martins <joao.m.mart...@oracle.com>

> ---
>  hw/vfio/iommufd.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> 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;
>      }
>  


Reply via email to