[PATCH v4 24/27] backends/iommufd: Retrieve PASID width from iommufd_backend_get_device_info()

Shameer Kolothum posted 27 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH v4 24/27] backends/iommufd: Retrieve PASID width from iommufd_backend_get_device_info()
Posted by Shameer Kolothum 1 month, 2 weeks ago
And store it in HostIOMMUDeviceCaps for later use.

Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
---
 backends/iommufd.c                 | 6 +++++-
 hw/arm/smmuv3-accel.c              | 3 ++-
 hw/vfio/iommufd.c                  | 7 +++++--
 include/system/host_iommu_device.h | 2 ++
 include/system/iommufd.h           | 3 ++-
 5 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/backends/iommufd.c b/backends/iommufd.c
index d3029d4658..023e67bc46 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -388,7 +388,8 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be,
 
 bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
                                      uint32_t *type, void *data, uint32_t len,
-                                     uint64_t *caps, Error **errp)
+                                     uint64_t *caps, uint8_t *pasid_log2,
+                                     Error **errp)
 {
     struct iommu_hw_info info = {
         .size = sizeof(info),
@@ -407,6 +408,9 @@ bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
     g_assert(caps);
     *caps = info.out_capabilities;
 
+    if (pasid_log2) {
+        *pasid_log2 = info.out_max_pasid_log2;
+    }
     return true;
 }
 
diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c
index ba37d690ad..283d36e6cd 100644
--- a/hw/arm/smmuv3-accel.c
+++ b/hw/arm/smmuv3-accel.c
@@ -124,7 +124,8 @@ smmuv3_accel_hw_compatible(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *idev,
     uint64_t caps;
 
     if (!iommufd_backend_get_device_info(idev->iommufd, idev->devid, &data_type,
-                                         &info, sizeof(info), &caps, errp)) {
+                                         &info, sizeof(info), &caps, NULL,
+                                         errp)) {
         return false;
     }
 
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 525df30ed1..89aa1b76a8 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -366,7 +366,8 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev,
      * instead.
      */
     if (!iommufd_backend_get_device_info(vbasedev->iommufd, vbasedev->devid,
-                                         &type, NULL, 0, &hw_caps, errp)) {
+                                         &type, NULL, 0, &hw_caps, NULL,
+                                         errp)) {
         return false;
     }
 
@@ -901,19 +902,21 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque,
     HostIOMMUDeviceCaps *caps = &hiod->caps;
     VendorCaps *vendor_caps = &caps->vendor_caps;
     enum iommu_hw_info_type type;
+    uint8_t pasid_log2;
     uint64_t hw_caps;
 
     hiod->agent = opaque;
 
     if (!iommufd_backend_get_device_info(vdev->iommufd, vdev->devid, &type,
                                          vendor_caps, sizeof(*vendor_caps),
-                                         &hw_caps, errp)) {
+                                         &hw_caps, &pasid_log2, errp)) {
         return false;
     }
 
     hiod->name = g_strdup(vdev->name);
     caps->type = type;
     caps->hw_caps = hw_caps;
+    caps->max_pasid_log2 = pasid_log2;
 
     idev = HOST_IOMMU_DEVICE_IOMMUFD(hiod);
     idev->iommufd = vdev->iommufd;
diff --git a/include/system/host_iommu_device.h b/include/system/host_iommu_device.h
index ab849a4a82..c6a2a3899a 100644
--- a/include/system/host_iommu_device.h
+++ b/include/system/host_iommu_device.h
@@ -29,6 +29,7 @@ typedef union VendorCaps {
  *
  * @hw_caps: host platform IOMMU capabilities (e.g. on IOMMUFD this represents
  *           the @out_capabilities value returned from IOMMU_GET_HW_INFO ioctl)
+ * @max_pasid_log2: width of PASIDs supported by host IOMMU device
  *
  * @vendor_caps: host platform IOMMU vendor specific capabilities (e.g. on
  *               IOMMUFD this represents a user-space buffer filled by kernel
@@ -37,6 +38,7 @@ typedef union VendorCaps {
 typedef struct HostIOMMUDeviceCaps {
     uint32_t type;
     uint64_t hw_caps;
+    uint8_t max_pasid_log2;
     VendorCaps vendor_caps;
 } HostIOMMUDeviceCaps;
 #endif
diff --git a/include/system/iommufd.h b/include/system/iommufd.h
index e852193f35..d3efcffc45 100644
--- a/include/system/iommufd.h
+++ b/include/system/iommufd.h
@@ -71,7 +71,8 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id,
                               hwaddr iova, ram_addr_t size);
 bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
                                      uint32_t *type, void *data, uint32_t len,
-                                     uint64_t *caps, Error **errp);
+                                     uint64_t *caps, uint8_t *pasid_log2,
+                                     Error **errp);
 bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id,
                                 uint32_t pt_id, uint32_t flags,
                                 uint32_t data_type, uint32_t data_len,
-- 
2.43.0
Re: [PATCH v4 24/27] backends/iommufd: Retrieve PASID width from iommufd_backend_get_device_info()
Posted by Eric Auger 2 weeks, 4 days ago

On 9/29/25 3:36 PM, Shameer Kolothum wrote:
> And store it in HostIOMMUDeviceCaps for later use.
>
> Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
> ---
>  backends/iommufd.c                 | 6 +++++-
>  hw/arm/smmuv3-accel.c              | 3 ++-
>  hw/vfio/iommufd.c                  | 7 +++++--
>  include/system/host_iommu_device.h | 2 ++
>  include/system/iommufd.h           | 3 ++-
>  5 files changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/backends/iommufd.c b/backends/iommufd.c
> index d3029d4658..023e67bc46 100644
> --- a/backends/iommufd.c
> +++ b/backends/iommufd.c
> @@ -388,7 +388,8 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be,
>  
>  bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
>                                       uint32_t *type, void *data, uint32_t len,
> -                                     uint64_t *caps, Error **errp)
> +                                     uint64_t *caps, uint8_t *pasid_log2,
max_pasid_log2
> +                                     Error **errp)
>  {
>      struct iommu_hw_info info = {
>          .size = sizeof(info),
> @@ -407,6 +408,9 @@ bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
>      g_assert(caps);
>      *caps = info.out_capabilities;
>  
> +    if (pasid_log2) {
> +        *pasid_log2 = info.out_max_pasid_log2;
> +    }
>      return true;
>  }
>  
> diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c
> index ba37d690ad..283d36e6cd 100644
> --- a/hw/arm/smmuv3-accel.c
> +++ b/hw/arm/smmuv3-accel.c
> @@ -124,7 +124,8 @@ smmuv3_accel_hw_compatible(SMMUv3State *s, HostIOMMUDeviceIOMMUFD *idev,
>      uint64_t caps;
>  
>      if (!iommufd_backend_get_device_info(idev->iommufd, idev->devid, &data_type,
> -                                         &info, sizeof(info), &caps, errp)) {
> +                                         &info, sizeof(info), &caps, NULL,
> +                                         errp)) {
>          return false;
>      }
>  
> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
> index 525df30ed1..89aa1b76a8 100644
> --- a/hw/vfio/iommufd.c
> +++ b/hw/vfio/iommufd.c
> @@ -366,7 +366,8 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev,
>       * instead.
>       */
>      if (!iommufd_backend_get_device_info(vbasedev->iommufd, vbasedev->devid,
> -                                         &type, NULL, 0, &hw_caps, errp)) {
> +                                         &type, NULL, 0, &hw_caps, NULL,
> +                                         errp)) {
>          return false;
>      }
>  
> @@ -901,19 +902,21 @@ static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque,
>      HostIOMMUDeviceCaps *caps = &hiod->caps;
>      VendorCaps *vendor_caps = &caps->vendor_caps;
>      enum iommu_hw_info_type type;
> +    uint8_t pasid_log2;
>      uint64_t hw_caps;
>  
>      hiod->agent = opaque;
>  
>      if (!iommufd_backend_get_device_info(vdev->iommufd, vdev->devid, &type,
>                                           vendor_caps, sizeof(*vendor_caps),
> -                                         &hw_caps, errp)) {
> +                                         &hw_caps, &pasid_log2, errp)) {
>          return false;
>      }
>  
>      hiod->name = g_strdup(vdev->name);
>      caps->type = type;
>      caps->hw_caps = hw_caps;
> +    caps->max_pasid_log2 = pasid_log2;
>  
>      idev = HOST_IOMMU_DEVICE_IOMMUFD(hiod);
>      idev->iommufd = vdev->iommufd;
> diff --git a/include/system/host_iommu_device.h b/include/system/host_iommu_device.h
> index ab849a4a82..c6a2a3899a 100644
> --- a/include/system/host_iommu_device.h
> +++ b/include/system/host_iommu_device.h
> @@ -29,6 +29,7 @@ typedef union VendorCaps {
>   *
>   * @hw_caps: host platform IOMMU capabilities (e.g. on IOMMUFD this represents
>   *           the @out_capabilities value returned from IOMMU_GET_HW_INFO ioctl)
> + * @max_pasid_log2: width of PASIDs supported by host IOMMU device
>   *
>   * @vendor_caps: host platform IOMMU vendor specific capabilities (e.g. on
>   *               IOMMUFD this represents a user-space buffer filled by kernel
> @@ -37,6 +38,7 @@ typedef union VendorCaps {
>  typedef struct HostIOMMUDeviceCaps {
>      uint32_t type;
>      uint64_t hw_caps;
> +    uint8_t max_pasid_log2;
>      VendorCaps vendor_caps;
>  } HostIOMMUDeviceCaps;
>  #endif
> diff --git a/include/system/iommufd.h b/include/system/iommufd.h
> index e852193f35..d3efcffc45 100644
> --- a/include/system/iommufd.h
> +++ b/include/system/iommufd.h
> @@ -71,7 +71,8 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id,
>                                hwaddr iova, ram_addr_t size);
>  bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
>                                       uint32_t *type, void *data, uint32_t len,
> -                                     uint64_t *caps, Error **errp);
> +                                     uint64_t *caps, uint8_t *pasid_log2,
max_pasid_log2
> +                                     Error **errp);
>  bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id,
>                                  uint32_t pt_id, uint32_t flags,
>                                  uint32_t data_type, uint32_t data_len,
Besides
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Eric
Re: [PATCH v4 24/27] backends/iommufd: Retrieve PASID width from iommufd_backend_get_device_info()
Posted by Jonathan Cameron via 1 month, 2 weeks ago
On Mon, 29 Sep 2025 14:36:40 +0100
Shameer Kolothum <skolothumtho@nvidia.com> wrote:

Bring the bit of the description in the title down here as well.
Depending on what tools people use for browsing git it might
end up in very different places on their screen.

> And store it in HostIOMMUDeviceCaps for later use.
> 
> Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
Trivial comment inline.

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>

> ---
>  backends/iommufd.c                 | 6 +++++-
>  hw/arm/smmuv3-accel.c              | 3 ++-
>  hw/vfio/iommufd.c                  | 7 +++++--
>  include/system/host_iommu_device.h | 2 ++
>  include/system/iommufd.h           | 3 ++-
>  5 files changed, 16 insertions(+), 5 deletions(-)

...

> diff --git a/include/system/host_iommu_device.h b/include/system/host_iommu_device.h
> index ab849a4a82..c6a2a3899a 100644
> --- a/include/system/host_iommu_device.h
> +++ b/include/system/host_iommu_device.h
> @@ -29,6 +29,7 @@ typedef union VendorCaps {
>   *
>   * @hw_caps: host platform IOMMU capabilities (e.g. on IOMMUFD this represents
>   *           the @out_capabilities value returned from IOMMU_GET_HW_INFO ioctl)

Blank line here to match local style. 

> + * @max_pasid_log2: width of PASIDs supported by host IOMMU device
>   *
>   * @vendor_caps: host platform IOMMU vendor specific capabilities (e.g. on
>   *               IOMMUFD this represents a user-space buffer filled by kernel
> @@ -37,6 +38,7 @@ typedef union VendorCaps {
>  typedef struct HostIOMMUDeviceCaps {
>      uint32_t type;
>      uint64_t hw_caps;
> +    uint8_t max_pasid_log2;
>      VendorCaps vendor_caps;
>  } HostIOMMUDeviceCaps;
>  #endif
> diff --git a/include/system/iommufd.h b/include/system/iommufd.h
> index e852193f35..d3efcffc45 100644
> --- a/include/system/iommufd.h
> +++ b/include/system/iommufd.h
> @@ -71,7 +71,8 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id,
>                                hwaddr iova, ram_addr_t size);
>  bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
>                                       uint32_t *type, void *data, uint32_t len,
> -                                     uint64_t *caps, Error **errp);
> +                                     uint64_t *caps, uint8_t *pasid_log2,
> +                                     Error **errp);
>  bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id,
>                                  uint32_t pt_id, uint32_t flags,
>                                  uint32_t data_type, uint32_t data_len,
Re: [PATCH v4 24/27] backends/iommufd: Retrieve PASID width from iommufd_backend_get_device_info()
Posted by Eric Auger 2 weeks, 4 days ago

On 10/1/25 3:50 PM, Jonathan Cameron wrote:
> On Mon, 29 Sep 2025 14:36:40 +0100
> Shameer Kolothum <skolothumtho@nvidia.com> wrote:
>
> Bring the bit of the description in the title down here as well.
> Depending on what tools people use for browsing git it might
> end up in very different places on their screen.
+1

Eric
>
>> And store it in HostIOMMUDeviceCaps for later use.
>>
>> Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
> Trivial comment inline.
>
> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
>
>> ---
>>  backends/iommufd.c                 | 6 +++++-
>>  hw/arm/smmuv3-accel.c              | 3 ++-
>>  hw/vfio/iommufd.c                  | 7 +++++--
>>  include/system/host_iommu_device.h | 2 ++
>>  include/system/iommufd.h           | 3 ++-
>>  5 files changed, 16 insertions(+), 5 deletions(-)
> ...
>
>> diff --git a/include/system/host_iommu_device.h b/include/system/host_iommu_device.h
>> index ab849a4a82..c6a2a3899a 100644
>> --- a/include/system/host_iommu_device.h
>> +++ b/include/system/host_iommu_device.h
>> @@ -29,6 +29,7 @@ typedef union VendorCaps {
>>   *
>>   * @hw_caps: host platform IOMMU capabilities (e.g. on IOMMUFD this represents
>>   *           the @out_capabilities value returned from IOMMU_GET_HW_INFO ioctl)
> Blank line here to match local style. 
>
>> + * @max_pasid_log2: width of PASIDs supported by host IOMMU device
>>   *
>>   * @vendor_caps: host platform IOMMU vendor specific capabilities (e.g. on
>>   *               IOMMUFD this represents a user-space buffer filled by kernel
>> @@ -37,6 +38,7 @@ typedef union VendorCaps {
>>  typedef struct HostIOMMUDeviceCaps {
>>      uint32_t type;
>>      uint64_t hw_caps;
>> +    uint8_t max_pasid_log2;
>>      VendorCaps vendor_caps;
>>  } HostIOMMUDeviceCaps;
>>  #endif
>> diff --git a/include/system/iommufd.h b/include/system/iommufd.h
>> index e852193f35..d3efcffc45 100644
>> --- a/include/system/iommufd.h
>> +++ b/include/system/iommufd.h
>> @@ -71,7 +71,8 @@ int iommufd_backend_unmap_dma(IOMMUFDBackend *be, uint32_t ioas_id,
>>                                hwaddr iova, ram_addr_t size);
>>  bool iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
>>                                       uint32_t *type, void *data, uint32_t len,
>> -                                     uint64_t *caps, Error **errp);
>> +                                     uint64_t *caps, uint8_t *pasid_log2,
>> +                                     Error **errp);
>>  bool iommufd_backend_alloc_hwpt(IOMMUFDBackend *be, uint32_t dev_id,
>>                                  uint32_t pt_id, uint32_t flags,
>>                                  uint32_t data_type, uint32_t data_len,