[PATCH v1 04/13] intel_iommu: Create the nested hwpt with IOMMU_HWPT_ALLOC_PASID flag

Zhenzhong Duan posted 13 patches 1 month ago
Maintainers: Yi Liu <yi.l.liu@intel.com>, Eric Auger <eric.auger@redhat.com>, Zhenzhong Duan <zhenzhong.duan@intel.com>, Peter Maydell <peter.maydell@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>, "Clément Mathieu--Drif" <clement.mathieu--drif@eviden.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>
There is a newer version of this series
[PATCH v1 04/13] intel_iommu: Create the nested hwpt with IOMMU_HWPT_ALLOC_PASID flag
Posted by Zhenzhong Duan 1 month ago
When pasid is enabled, any hwpt attached to non-PASID or PASID should be
IOMMU_HWPT_ALLOC_PASID flagged, or else attachment fails.

Change vtd_destroy_old_fs_hwpt() to pass in 'VTDHostIOMMUDevice *' for
naming consistency.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 hw/i386/intel_iommu_accel.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c
index 45c08c8f6f..c2757f3bcd 100644
--- a/hw/i386/intel_iommu_accel.c
+++ b/hw/i386/intel_iommu_accel.c
@@ -69,11 +69,13 @@ VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as)
     return NULL;
 }
 
-static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev,
+static bool vtd_create_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod,
                                VTDPASIDEntry *pe, uint32_t *fs_hwpt_id,
                                Error **errp)
 {
+    HostIOMMUDeviceIOMMUFD *idev = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);
     struct iommu_hwpt_vtd_s1 vtd = {};
+    uint32_t flags = vtd_hiod->iommu_state->pasid ? IOMMU_HWPT_ALLOC_PASID : 0;
 
     vtd.flags = (VTD_SM_PASID_ENTRY_SRE(pe) ? IOMMU_VTD_S1_SRE : 0) |
                 (VTD_SM_PASID_ENTRY_WPE(pe) ? IOMMU_VTD_S1_WPE : 0) |
@@ -82,13 +84,15 @@ static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev,
     vtd.pgtbl_addr = (uint64_t)vtd_pe_get_fspt_base(pe);
 
     return iommufd_backend_alloc_hwpt(idev->iommufd, idev->devid, idev->hwpt_id,
-                                      0, IOMMU_HWPT_DATA_VTD_S1, sizeof(vtd),
-                                      &vtd, fs_hwpt_id, errp);
+                                      flags, IOMMU_HWPT_DATA_VTD_S1,
+                                      sizeof(vtd), &vtd, fs_hwpt_id, errp);
 }
 
-static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev,
+static void vtd_destroy_old_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod,
                                     VTDAddressSpace *vtd_as)
 {
+    HostIOMMUDeviceIOMMUFD *idev = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);
+
     if (!vtd_as->fs_hwpt_id) {
         return;
     }
@@ -116,7 +120,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
     }
 
     if (vtd_pe_pgtt_is_fst(pe)) {
-        if (!vtd_create_fs_hwpt(idev, pe, &hwpt_id, errp)) {
+        if (!vtd_create_fs_hwpt(vtd_hiod, pe, &hwpt_id, errp)) {
             return false;
         }
     }
@@ -126,7 +130,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
     trace_vtd_device_attach_hwpt(idev->devid, vtd_as->pasid, hwpt_id, ret);
     if (ret) {
         /* Destroy old fs_hwpt if it's a replacement */
-        vtd_destroy_old_fs_hwpt(idev, vtd_as);
+        vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as);
         if (vtd_pe_pgtt_is_fst(pe)) {
             vtd_as->fs_hwpt_id = hwpt_id;
         }
@@ -161,7 +165,7 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
     }
 
     if (ret) {
-        vtd_destroy_old_fs_hwpt(idev, vtd_as);
+        vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as);
     }
 
     return ret;
-- 
2.47.3
Re: [PATCH v1 04/13] intel_iommu: Create the nested hwpt with IOMMU_HWPT_ALLOC_PASID flag
Posted by Yi Liu 3 weeks, 3 days ago
On 3/6/26 11:43, Zhenzhong Duan wrote:
> When pasid is enabled, any hwpt attached to non-PASID or PASID should be
> IOMMU_HWPT_ALLOC_PASID flagged, or else attachment fails.
> 
> Change vtd_destroy_old_fs_hwpt() to pass in 'VTDHostIOMMUDevice *' for
> naming consistency.

> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
>   hw/i386/intel_iommu_accel.c | 18 +++++++++++-------
>   1 file changed, 11 insertions(+), 7 deletions(-)

Reviewed-by: Yi Liu <yi.l.liu@intel.com>

> diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c
> index 45c08c8f6f..c2757f3bcd 100644
> --- a/hw/i386/intel_iommu_accel.c
> +++ b/hw/i386/intel_iommu_accel.c
> @@ -69,11 +69,13 @@ VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as)
>       return NULL;
>   }
>   
> -static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev,
> +static bool vtd_create_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod,
>                                  VTDPASIDEntry *pe, uint32_t *fs_hwpt_id,
>                                  Error **errp)
>   {
> +    HostIOMMUDeviceIOMMUFD *idev = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);
>       struct iommu_hwpt_vtd_s1 vtd = {};
> +    uint32_t flags = vtd_hiod->iommu_state->pasid ? IOMMU_HWPT_ALLOC_PASID : 0;
>   
>       vtd.flags = (VTD_SM_PASID_ENTRY_SRE(pe) ? IOMMU_VTD_S1_SRE : 0) |
>                   (VTD_SM_PASID_ENTRY_WPE(pe) ? IOMMU_VTD_S1_WPE : 0) |
> @@ -82,13 +84,15 @@ static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev,
>       vtd.pgtbl_addr = (uint64_t)vtd_pe_get_fspt_base(pe);
>   
>       return iommufd_backend_alloc_hwpt(idev->iommufd, idev->devid, idev->hwpt_id,
> -                                      0, IOMMU_HWPT_DATA_VTD_S1, sizeof(vtd),
> -                                      &vtd, fs_hwpt_id, errp);
> +                                      flags, IOMMU_HWPT_DATA_VTD_S1,
> +                                      sizeof(vtd), &vtd, fs_hwpt_id, errp);
>   }
>   
> -static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev,
> +static void vtd_destroy_old_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod,
>                                       VTDAddressSpace *vtd_as)
>   {
> +    HostIOMMUDeviceIOMMUFD *idev = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);
> +
>       if (!vtd_as->fs_hwpt_id) {
>           return;
>       }
> @@ -116,7 +120,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
>       }
>   
>       if (vtd_pe_pgtt_is_fst(pe)) {
> -        if (!vtd_create_fs_hwpt(idev, pe, &hwpt_id, errp)) {
> +        if (!vtd_create_fs_hwpt(vtd_hiod, pe, &hwpt_id, errp)) {
>               return false;
>           }
>       }
> @@ -126,7 +130,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
>       trace_vtd_device_attach_hwpt(idev->devid, vtd_as->pasid, hwpt_id, ret);
>       if (ret) {
>           /* Destroy old fs_hwpt if it's a replacement */
> -        vtd_destroy_old_fs_hwpt(idev, vtd_as);
> +        vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as);
>           if (vtd_pe_pgtt_is_fst(pe)) {
>               vtd_as->fs_hwpt_id = hwpt_id;
>           }
> @@ -161,7 +165,7 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod,
>       }
>   
>       if (ret) {
> -        vtd_destroy_old_fs_hwpt(idev, vtd_as);
> +        vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as);
>       }
>   
>       return ret;
Re: [PATCH v1 04/13] intel_iommu: Create the nested hwpt with IOMMU_HWPT_ALLOC_PASID flag
Posted by CLEMENT MATHIEU--DRIF 1 month ago
Hi Zhenzhong

Reviewed-by: Clement Mathieu--Drif <clement.mathieu--drif@bull.com>

On Thu, 2026-03-05 at 22:43 -0500, Zhenzhong Duan wrote:
> When pasid is enabled, any hwpt attached to non-PASID or PASID should be  
> IOMMU_HWPT_ALLOC_PASID flagged, or else attachment fails.
> 
> Change vtd_destroy_old_fs_hwpt() to pass in 'VTDHostIOMMUDevice *' for  
> naming consistency.
> 
> Signed-off-by: Zhenzhong Duan <[zhenzhong.duan@intel.com](mailto:zhenzhong.duan@intel.com)>  
> ---  
>  hw/i386/intel_iommu_accel.c | 18 +++++++++++-------  
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c  
> index 45c08c8f6f..c2757f3bcd 100644  
> --- a/hw/i386/intel_iommu_accel.c  
> +++ b/hw/i386/intel_iommu_accel.c  
> @@ -69,11 +69,13 @@ VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as)  
>      return NULL;  
>  }  
>    
> -static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev,  
> +static bool vtd_create_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod,  
>                                 VTDPASIDEntry *pe, uint32_t *fs_hwpt_id,  
>                                 Error **errp)  
>  {  
> +    HostIOMMUDeviceIOMMUFD *idev = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);  
>      struct iommu_hwpt_vtd_s1 vtd = {};  
> +    uint32_t flags = vtd_hiod->iommu_state->pasid ? IOMMU_HWPT_ALLOC_PASID : 0;  
>    
>      vtd.flags = (VTD_SM_PASID_ENTRY_SRE(pe) ? IOMMU_VTD_S1_SRE : 0) |  
>                  (VTD_SM_PASID_ENTRY_WPE(pe) ? IOMMU_VTD_S1_WPE : 0) |  
> @@ -82,13 +84,15 @@ static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev,  
>      vtd.pgtbl_addr = (uint64_t)vtd_pe_get_fspt_base(pe);  
>    
>      return iommufd_backend_alloc_hwpt(idev->iommufd, idev->devid, idev->hwpt_id,  
> -                                      0, IOMMU_HWPT_DATA_VTD_S1, sizeof(vtd),  
> -                                      &vtd, fs_hwpt_id, errp);  
> +                                      flags, IOMMU_HWPT_DATA_VTD_S1,  
> +                                      sizeof(vtd), &vtd, fs_hwpt_id, errp);  
>  }  
>    
> -static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev,  
> +static void vtd_destroy_old_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod,  
>                                      VTDAddressSpace *vtd_as)  
>  {  
> +    HostIOMMUDeviceIOMMUFD *idev = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);  
> +  
>      if (!vtd_as->fs_hwpt_id) {  
>          return;  
>      }  
> @@ -116,7 +120,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,  
>      }  
>    
>      if (vtd_pe_pgtt_is_fst(pe)) {  
> -        if (!vtd_create_fs_hwpt(idev, pe, &hwpt_id, errp)) {  
> +        if (!vtd_create_fs_hwpt(vtd_hiod, pe, &hwpt_id, errp)) {  
>              return false;  
>          }  
>      }  
> @@ -126,7 +130,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,  
>      trace_vtd_device_attach_hwpt(idev->devid, vtd_as->pasid, hwpt_id, ret);  
>      if (ret) {  
>          /* Destroy old fs_hwpt if it's a replacement */  
> -        vtd_destroy_old_fs_hwpt(idev, vtd_as);  
> +        vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as);  
>          if (vtd_pe_pgtt_is_fst(pe)) {  
>              vtd_as->fs_hwpt_id = hwpt_id;  
>          }  
> @@ -161,7 +165,7 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod,  
>      }  
>    
>      if (ret) {  
> -        vtd_destroy_old_fs_hwpt(idev, vtd_as);  
> +        vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as);  
>      }  
>    
>      return ret;