[PATCH v2 17/19] intel_iommu: Refresh pasid bind when either SRTP or TE bit is changed

Zhenzhong Duan posted 19 patches 4 months, 4 weeks ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>, Yi Liu <yi.l.liu@intel.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.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>, Eric Auger <eric.auger@redhat.com>, Zhenzhong Duan <zhenzhong.duan@intel.com>
There is a newer version of this series
[PATCH v2 17/19] intel_iommu: Refresh pasid bind when either SRTP or TE bit is changed
Posted by Zhenzhong Duan 4 months, 4 weeks ago
From: Yi Liu <yi.l.liu@intel.com>

When either 'Set Root Table Pointer' or 'Translation Enable' bit is changed,
the pasid bindings on host side become stale and need to be updated.

Introduce a helper function vtd_refresh_pasid_bind() for that purpose.

Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 hw/i386/intel_iommu.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index d1fa395274..0b322078cc 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -90,6 +90,7 @@ struct vtd_iotlb_key {
 
 static void vtd_address_space_refresh_all(IntelIOMMUState *s);
 static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n);
+static void vtd_refresh_pasid_bind(IntelIOMMUState *s);
 
 static void vtd_pasid_cache_reset_locked(IntelIOMMUState *s);
 static void vtd_pasid_cache_sync(IntelIOMMUState *s,
@@ -3066,6 +3067,7 @@ static void vtd_handle_gcmd_srtp(IntelIOMMUState *s)
     vtd_set_clear_mask_long(s, DMAR_GSTS_REG, 0, VTD_GSTS_RTPS);
     vtd_reset_caches(s);
     vtd_address_space_refresh_all(s);
+    vtd_refresh_pasid_bind(s);
 }
 
 /* Set Interrupt Remap Table Pointer */
@@ -3100,6 +3102,7 @@ static void vtd_handle_gcmd_te(IntelIOMMUState *s, bool en)
 
     vtd_reset_caches(s);
     vtd_address_space_refresh_all(s);
+    vtd_refresh_pasid_bind(s);
 }
 
 /* Handle Interrupt Remap Enable/Disable */
@@ -3813,6 +3816,26 @@ static void vtd_replay_guest_pasid_bindings(IntelIOMMUState *s,
     }
 }
 
+static void vtd_refresh_pasid_bind(IntelIOMMUState *s)
+{
+    VTDPASIDCacheInfo pc_info = { .error_happened = false,
+                                  .type = VTD_PASID_CACHE_GLOBAL_INV };
+
+    /*
+     * Only when dmar is enabled, should pasid bindings replayed,
+     * otherwise no need to replay.
+     */
+    if (!s->dmar_enabled) {
+        return;
+    }
+
+    if (!s->flts || !s->root_scalable) {
+        return;
+    }
+
+    vtd_replay_guest_pasid_bindings(s, &pc_info);
+}
+
 /*
  * This function syncs the pasid bindings between guest and host.
  * It includes updating the pasid cache in vIOMMU and updating the
-- 
2.34.1
Re: [PATCH v2 17/19] intel_iommu: Refresh pasid bind when either SRTP or TE bit is changed
Posted by Eric Auger 4 months, 3 weeks ago
Hi Zhenzhong,

On 6/20/25 9:18 AM, Zhenzhong Duan wrote:
> From: Yi Liu <yi.l.liu@intel.com>
>
> When either 'Set Root Table Pointer' or 'Translation Enable' bit is changed,
> the pasid bindings on host side become stale and need to be updated.
>
> Introduce a helper function vtd_refresh_pasid_bind() for that purpose.
nit I would avoid introducing yet another terminology, ie. refresh. If
it is a replay let's keep replay and precisely explain what the replay does.
vtd_replay_pasid_bindings?


>
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
>  hw/i386/intel_iommu.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
> index d1fa395274..0b322078cc 100644
> --- a/hw/i386/intel_iommu.c
> +++ b/hw/i386/intel_iommu.c
> @@ -90,6 +90,7 @@ struct vtd_iotlb_key {
>  
>  static void vtd_address_space_refresh_all(IntelIOMMUState *s);
>  static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n);
> +static void vtd_refresh_pasid_bind(IntelIOMMUState *s);
>  
>  static void vtd_pasid_cache_reset_locked(IntelIOMMUState *s);
>  static void vtd_pasid_cache_sync(IntelIOMMUState *s,
> @@ -3066,6 +3067,7 @@ static void vtd_handle_gcmd_srtp(IntelIOMMUState *s)
>      vtd_set_clear_mask_long(s, DMAR_GSTS_REG, 0, VTD_GSTS_RTPS);
>      vtd_reset_caches(s);
>      vtd_address_space_refresh_all(s);
> +    vtd_refresh_pasid_bind(s);
>  }
>  
>  /* Set Interrupt Remap Table Pointer */
> @@ -3100,6 +3102,7 @@ static void vtd_handle_gcmd_te(IntelIOMMUState *s, bool en)
>  
>      vtd_reset_caches(s);
>      vtd_address_space_refresh_all(s);
> +    vtd_refresh_pasid_bind(s);
>  }
>  
>  /* Handle Interrupt Remap Enable/Disable */
> @@ -3813,6 +3816,26 @@ static void vtd_replay_guest_pasid_bindings(IntelIOMMUState *s,
>      }
>  }
>  
> +static void vtd_refresh_pasid_bind(IntelIOMMUState *s)
> +{
> +    VTDPASIDCacheInfo pc_info = { .error_happened = false,
> +                                  .type = VTD_PASID_CACHE_GLOBAL_INV };
> +
> +    /*
> +     * Only when dmar is enabled, should pasid bindings replayed,
> +     * otherwise no need to replay.
> +     */
I am not sure the above comment is necessary.
> +    if (!s->dmar_enabled) {
> +        return;
> +    }
> +
> +    if (!s->flts || !s->root_scalable) {
> +        return;
> +    }
> +
> +    vtd_replay_guest_pasid_bindings(s, &pc_info);
> +}
> +
>  /*
>   * This function syncs the pasid bindings between guest and host.
>   * It includes updating the pasid cache in vIOMMU and updating the
Thanks

Eric
RE: [PATCH v2 17/19] intel_iommu: Refresh pasid bind when either SRTP or TE bit is changed
Posted by Duan, Zhenzhong 4 months, 3 weeks ago
Hi Eric,

>-----Original Message-----
>From: Eric Auger <eric.auger@redhat.com>
>Subject: Re: [PATCH v2 17/19] intel_iommu: Refresh pasid bind when either
>SRTP or TE bit is changed
>
>Hi Zhenzhong,
>
>On 6/20/25 9:18 AM, Zhenzhong Duan wrote:
>> From: Yi Liu <yi.l.liu@intel.com>
>>
>> When either 'Set Root Table Pointer' or 'Translation Enable' bit is changed,
>> the pasid bindings on host side become stale and need to be updated.
>>
>> Introduce a helper function vtd_refresh_pasid_bind() for that purpose.
>nit I would avoid introducing yet another terminology, ie. refresh. If
>it is a replay let's keep replay and precisely explain what the replay does.
>vtd_replay_pasid_bindings?

Will do

>
>
>>
>> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>> ---
>>  hw/i386/intel_iommu.c | 23 +++++++++++++++++++++++
>>  1 file changed, 23 insertions(+)
>>
>> diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
>> index d1fa395274..0b322078cc 100644
>> --- a/hw/i386/intel_iommu.c
>> +++ b/hw/i386/intel_iommu.c
>> @@ -90,6 +90,7 @@ struct vtd_iotlb_key {
>>
>>  static void vtd_address_space_refresh_all(IntelIOMMUState *s);
>>  static void vtd_address_space_unmap(VTDAddressSpace *as,
>IOMMUNotifier *n);
>> +static void vtd_refresh_pasid_bind(IntelIOMMUState *s);
>>
>>  static void vtd_pasid_cache_reset_locked(IntelIOMMUState *s);
>>  static void vtd_pasid_cache_sync(IntelIOMMUState *s,
>> @@ -3066,6 +3067,7 @@ static void
>vtd_handle_gcmd_srtp(IntelIOMMUState *s)
>>      vtd_set_clear_mask_long(s, DMAR_GSTS_REG, 0, VTD_GSTS_RTPS);
>>      vtd_reset_caches(s);
>>      vtd_address_space_refresh_all(s);
>> +    vtd_refresh_pasid_bind(s);
>>  }
>>
>>  /* Set Interrupt Remap Table Pointer */
>> @@ -3100,6 +3102,7 @@ static void
>vtd_handle_gcmd_te(IntelIOMMUState *s, bool en)
>>
>>      vtd_reset_caches(s);
>>      vtd_address_space_refresh_all(s);
>> +    vtd_refresh_pasid_bind(s);
>>  }
>>
>>  /* Handle Interrupt Remap Enable/Disable */
>> @@ -3813,6 +3816,26 @@ static void
>vtd_replay_guest_pasid_bindings(IntelIOMMUState *s,
>>      }
>>  }
>>
>> +static void vtd_refresh_pasid_bind(IntelIOMMUState *s)
>> +{
>> +    VTDPASIDCacheInfo pc_info = { .error_happened = false,
>> +                                  .type =
>VTD_PASID_CACHE_GLOBAL_INV };
>> +
>> +    /*
>> +     * Only when dmar is enabled, should pasid bindings replayed,
>> +     * otherwise no need to replay.
>> +     */
>I am not sure the above comment is necessary.

Will delete it

Thanks
Zhenzhong