[PATCH v7 32/36] backends/iommufd: Add get_pasid_info() callback

Shameer Kolothum posted 36 patches 4 weeks ago
There is a newer version of this series
[PATCH v7 32/36] backends/iommufd: Add get_pasid_info() callback
Posted by Shameer Kolothum 4 weeks ago
The get_pasid_info callback retrieves PASID capability information
when the HostIOMMUDevice backend supports it. Currently, only the
Linux IOMMUFD backend provides this information.

This will be used by a subsequent patch to synthesize a PASID
capability for vfio-pci devices behind a vIOMMU that supports PASID.

Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
---
 backends/iommufd.c                 | 17 +++++++++++++++++
 include/system/host_iommu_device.h | 15 +++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/backends/iommufd.c b/backends/iommufd.c
index 6381f9664b..f1707eadc6 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -538,11 +538,28 @@ static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp)
     }
 }
 
+static bool hiod_iommufd_get_pasid_info(HostIOMMUDevice *hiod,
+                                        PasidInfo *pasid_info)
+{
+    HostIOMMUDeviceCaps *caps = &hiod->caps;
+
+    if (!caps->max_pasid_log2) {
+        return false;
+    }
+
+    g_assert(pasid_info);
+    pasid_info->exec_perm = (caps->hw_caps & IOMMU_HW_CAP_PCI_PASID_EXEC);
+    pasid_info->priv_mod = (caps->hw_caps & IOMMU_HW_CAP_PCI_PASID_PRIV);
+    pasid_info->max_pasid_log2 = caps->max_pasid_log2;
+    return true;
+}
+
 static void hiod_iommufd_class_init(ObjectClass *oc, const void *data)
 {
     HostIOMMUDeviceClass *hioc = HOST_IOMMU_DEVICE_CLASS(oc);
 
     hioc->get_cap = hiod_iommufd_get_cap;
+    hioc->get_pasid_info = hiod_iommufd_get_pasid_info;
 };
 
 static const TypeInfo types[] = {
diff --git a/include/system/host_iommu_device.h b/include/system/host_iommu_device.h
index bfb2b60478..4fbada638f 100644
--- a/include/system/host_iommu_device.h
+++ b/include/system/host_iommu_device.h
@@ -59,6 +59,12 @@ struct HostIOMMUDevice {
 #endif
 };
 
+typedef struct PasidInfo {
+    bool exec_perm;
+    bool priv_mod;
+    uint8_t max_pasid_log2;
+} PasidInfo;
+
 /**
  * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices.
  *
@@ -116,6 +122,15 @@ struct HostIOMMUDeviceClass {
      * @hiod: handle to the host IOMMU device
      */
     uint64_t (*get_page_size_mask)(HostIOMMUDevice *hiod);
+    /**
+     * @get_pasid_info: Return the PASID information associated with the Host
+     * IOMMU device.
+     *
+     * @pasid_info: If success, returns the PASID related information.
+     *
+     * Returns: true on success, false on failure.
+     */
+    bool (*get_pasid_info)(HostIOMMUDevice *hiod, PasidInfo *pasid_info);
 };
 
 /*
-- 
2.43.0
Re: [PATCH v7 32/36] backends/iommufd: Add get_pasid_info() callback
Posted by Eric Auger 2 weeks, 6 days ago

On 1/11/26 8:53 PM, Shameer Kolothum wrote:
> The get_pasid_info callback retrieves PASID capability information
> when the HostIOMMUDevice backend supports it. Currently, only the
> Linux IOMMUFD backend provides this information.
>
> This will be used by a subsequent patch to synthesize a PASID
> capability for vfio-pci devices behind a vIOMMU that supports PASID.
>
> Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Eric
> ---
>  backends/iommufd.c                 | 17 +++++++++++++++++
>  include/system/host_iommu_device.h | 15 +++++++++++++++
>  2 files changed, 32 insertions(+)
>
> diff --git a/backends/iommufd.c b/backends/iommufd.c
> index 6381f9664b..f1707eadc6 100644
> --- a/backends/iommufd.c
> +++ b/backends/iommufd.c
> @@ -538,11 +538,28 @@ static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp)
>      }
>  }
>  
> +static bool hiod_iommufd_get_pasid_info(HostIOMMUDevice *hiod,
> +                                        PasidInfo *pasid_info)
> +{
> +    HostIOMMUDeviceCaps *caps = &hiod->caps;
> +
> +    if (!caps->max_pasid_log2) {
> +        return false;
> +    }
> +
> +    g_assert(pasid_info);
> +    pasid_info->exec_perm = (caps->hw_caps & IOMMU_HW_CAP_PCI_PASID_EXEC);
> +    pasid_info->priv_mod = (caps->hw_caps & IOMMU_HW_CAP_PCI_PASID_PRIV);
> +    pasid_info->max_pasid_log2 = caps->max_pasid_log2;
> +    return true;
> +}
> +
>  static void hiod_iommufd_class_init(ObjectClass *oc, const void *data)
>  {
>      HostIOMMUDeviceClass *hioc = HOST_IOMMU_DEVICE_CLASS(oc);
>  
>      hioc->get_cap = hiod_iommufd_get_cap;
> +    hioc->get_pasid_info = hiod_iommufd_get_pasid_info;
>  };
>  
>  static const TypeInfo types[] = {
> diff --git a/include/system/host_iommu_device.h b/include/system/host_iommu_device.h
> index bfb2b60478..4fbada638f 100644
> --- a/include/system/host_iommu_device.h
> +++ b/include/system/host_iommu_device.h
> @@ -59,6 +59,12 @@ struct HostIOMMUDevice {
>  #endif
>  };
>  
> +typedef struct PasidInfo {
> +    bool exec_perm;
> +    bool priv_mod;
> +    uint8_t max_pasid_log2;
> +} PasidInfo;
> +
>  /**
>   * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices.
>   *
> @@ -116,6 +122,15 @@ struct HostIOMMUDeviceClass {
>       * @hiod: handle to the host IOMMU device
>       */
>      uint64_t (*get_page_size_mask)(HostIOMMUDevice *hiod);
> +    /**
> +     * @get_pasid_info: Return the PASID information associated with the Host
> +     * IOMMU device.
> +     *
> +     * @pasid_info: If success, returns the PASID related information.
> +     *
> +     * Returns: true on success, false on failure.
> +     */
> +    bool (*get_pasid_info)(HostIOMMUDevice *hiod, PasidInfo *pasid_info);
>  };
>  
>  /*
Re: [PATCH v7 32/36] backends/iommufd: Add get_pasid_info() callback
Posted by Jonathan Cameron via qemu development 3 weeks, 4 days ago
On Sun, 11 Jan 2026 19:53:18 +0000
Shameer Kolothum <skolothumtho@nvidia.com> wrote:

> The get_pasid_info callback retrieves PASID capability information
> when the HostIOMMUDevice backend supports it. Currently, only the
> Linux IOMMUFD backend provides this information.
> 
> This will be used by a subsequent patch to synthesize a PASID
> capability for vfio-pci devices behind a vIOMMU that supports PASID.
> 
> Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
Hi Shameer,

Trivial missing parameter docs comment below.  Assuming you just duplicate
the equivalent docs from just above:

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

J
> diff --git a/include/system/host_iommu_device.h b/include/system/host_iommu_device.h
> index bfb2b60478..4fbada638f 100644
> --- a/include/system/host_iommu_device.h
> +++ b/include/system/host_iommu_device.h
...
>  /**
>   * struct HostIOMMUDeviceClass - The base class for all host IOMMU devices.
>   *
> @@ -116,6 +122,15 @@ struct HostIOMMUDeviceClass {
>       * @hiod: handle to the host IOMMU device
>       */
>      uint64_t (*get_page_size_mask)(HostIOMMUDevice *hiod);
> +    /**
> +     * @get_pasid_info: Return the PASID information associated with the Host
> +     * IOMMU device.
> +     *

Feels like it should be complete and say what hiod is as well (see call above).

> +     * @pasid_info: If success, returns the PASID related information.
> +     *
> +     * Returns: true on success, false on failure.
> +     */
> +    bool (*get_pasid_info)(HostIOMMUDevice *hiod, PasidInfo *pasid_info);
>  };
>  
>  /*