>-----Original Message-----
>From: Liu, Yi L <[email protected]>
>Subject: Re: [PATCH v5 10/15] intel_iommu_accel: Handle PASID entry removal for
>pc_inv_dsc request
>
>On 5/22/26 11:07, Duan, Zhenzhong wrote:
>>
>>
>>> -----Original Message-----
>>> From: Liu, Yi L <[email protected]>
>>> Subject: Re: [PATCH v5 10/15] intel_iommu_accel: Handle PASID entry removal
>for
>>> pc_inv_dsc request
>>>
>>> On 5/9/26 12:08, Zhenzhong Duan wrote:
>>>> When guest deletes PASID entries, QEMU will capture the pasid cache
>>>> invalidation request, walk through pasid_cache_list in each passthrough
>>>> device to find stale VTDAccelPASIDCacheEntry and delete them.
>>>>
>>>> Co-developed-by: Yi Liu <[email protected]>
>>>> Signed-off-by: Yi Liu <[email protected]>
>>>> Signed-off-by: Zhenzhong Duan <[email protected]>
>>>> Tested-by: Xudong Hao <[email protected]>
>>>> ---
>>>>    hw/i386/intel_iommu_accel.c | 80
>>> +++++++++++++++++++++++++++++++++++++
>>>>    1 file changed, 80 insertions(+)
>>>>
>>>> diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c
>>>> index a66d63b4c8..82bfbdf484 100644
>>>> --- a/hw/i386/intel_iommu_accel.c
>>>> +++ b/hw/i386/intel_iommu_accel.c
>>>> @@ -16,6 +16,28 @@
>>>>    #include "hw/pci/pci_bus.h"
>>>>    #include "trace.h"
>>>>
>>>> +static int vtd_hiod_get_pe_from_pasid(VTDAccelPASIDCacheEntry *vtd_pce,
>>>
>>> this helper is tricky. vtd_pce already has a pe cached, then why need
>>> to do this?
>>
>> It's used on pc_inv_dsc handler path, vtd_pce caches old pe, we need to get
>refreshed one in memory.
>>
>>> I think it's better to have a helper receives s, devfn, and
>>> pasid instead of accepting vtd_pce. btw. I think the intel_iommu.c
>>> should have such a helper. is it?
>>
>> In intel_iommu.c, there is a helper for vtd_as:
>>
>> static inline int vtd_dev_get_pe_from_pasid(VTDAddressSpace *vtd_as,
>>                                              VTDPASIDEntry *pe)
>>
>> so in intel_iommu_accel.c, vtd_hiod_get_pe_from_pasid() is added for vtd_pce.
>>
>
>got it. VTDAddressSpace also cached a pe, with a closer read, it's
>tricky as well. Could you refactor a bit? e.g. avoid using the
>VTDAddressSpace as an input.

Added as a preparing patch, let me know if any misunderstandings:

commit 31fc6e409f285a2a93f09f99fd271d4b01d87c53 (HEAD)
Author: Zhenzhong Duan <[email protected]>
Date:   Fri May 22 02:14:30 2026 -0400

    intel_iommu: make vtd_dev_get_pe_from_pasid() more generic

    Refactor vtd_dev_get_pe_from_pasid() to take individual parameters
    (IntelIOMMUState, PCIBus, devfn, pasid) instead of VTDAddressSpace.

    This makes the function more reusable and prepares it for export to be
    used in the acceleration path. Remove inline qualifier as the function
    will be exported in a subsequent patch.

    No functional changes intended.

    Suggested-by: Yi Liu <[email protected]>
    Signed-off-by: Zhenzhong Duan <[email protected]>

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index cf275b496e..aa27187e02 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -3113,10 +3113,10 @@ static bool vtd_process_piotlb_desc(IntelIOMMUState *s,
     return true;
 }

-static inline int vtd_dev_get_pe_from_pasid(VTDAddressSpace *vtd_as,
-                                            VTDPASIDEntry *pe)
+static int vtd_dev_get_pe_from_pasid(IntelIOMMUState *s, PCIBus *bus,
+                                     uint8_t devfn, uint32_t pasid,
+                                     VTDPASIDEntry *pe)
 {
-    IntelIOMMUState *s = vtd_as->iommu_state;
     VTDContextEntry ce;
     int ret;

@@ -3124,13 +3124,12 @@ static inline int 
vtd_dev_get_pe_from_pasid(VTDAddressSpace *vtd_as,
         return -VTD_FR_RTADDR_INV_TTM;
     }

-    ret = vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus), vtd_as->devfn,
-                                   &ce);
+    ret = vtd_dev_to_context_entry(s, pci_bus_num(bus), devfn, &ce);
     if (ret) {
         return ret;
     }

-    return vtd_ce_get_pasid_entry(s, &ce, pe, vtd_as->pasid);
+    return vtd_ce_get_pasid_entry(s, &ce, pe, pasid);
 }

 static int vtd_pasid_entry_compare(VTDPASIDEntry *p1, VTDPASIDEntry *p2)
@@ -3151,7 +3150,8 @@ static void vtd_pasid_cache_sync_locked(gpointer key, 
gpointer value,
     const char *err_prefix = "Attaching to HWPT failed: ";
     Error *local_err = NULL;

-    if (vtd_dev_get_pe_from_pasid(vtd_as, &pe)) {
+    if (vtd_dev_get_pe_from_pasid(vtd_as->iommu_state, vtd_as->bus,
+                                  vtd_as->devfn, vtd_as->pasid, &pe)) {
         if (!pc_entry->valid) {
             return;
         }

Reply via email to