[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH rfcv1 21/23] intel_iommu: invalidate piotlb when flush pasid
From: |
Zhenzhong Duan |
Subject: |
[PATCH rfcv1 21/23] intel_iommu: invalidate piotlb when flush pasid |
Date: |
Mon, 15 Jan 2024 18:37:33 +0800 |
From: Yi Sun <yi.y.sun@linux.intel.com>
When bind/unbind emulated devices, we should invalidate QEMU
piotlb. Host will flush piotlb for passthrough devices so we
don't handle passthrough devices.
Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
hw/i386/intel_iommu.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 6a6478e865..2f3d3a28b0 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -84,6 +84,8 @@ static VTDPASIDAddressSpace
*vtd_add_find_pasid_as(IntelIOMMUState *s,
uint32_t pasid);
static int vtd_dev_get_rid2pasid(IntelIOMMUState *s, uint8_t bus_num,
uint8_t devfn, uint32_t *rid_pasid);
+static gboolean vtd_hash_remove_by_pasid(gpointer key, gpointer value,
+ gpointer user_data);
static void vtd_panic_require_caching_mode(void)
{
@@ -3667,14 +3669,21 @@ static gboolean vtd_flush_pasid(gpointer key, gpointer
value,
VTDPASIDCacheEntry *pc_entry = &vtd_pasid_as->pasid_cache_entry;
PCIBus *bus = vtd_pasid_as->bus;
VTDPASIDEntry pe;
+ VTDIOMMUFDDevice *vtd_idev;
+ VTDIOTLBPageInvInfo info;
uint16_t did;
uint32_t pasid;
uint16_t devfn;
int ret;
+ struct vtd_as_key as_key = {
+ .bus = vtd_pasid_as->bus,
+ .devfn = vtd_pasid_as->devfn,
+ };
did = vtd_pe_get_domain_id(&pc_entry->pasid_entry);
pasid = vtd_pasid_as->pasid;
devfn = vtd_pasid_as->devfn;
+ vtd_idev = g_hash_table_lookup(s->vtd_iommufd_dev, &as_key);
switch (pc_info->type) {
case VTD_PASID_CACHE_FORCE_RESET:
@@ -3702,6 +3711,13 @@ static gboolean vtd_flush_pasid(gpointer key, gpointer
value,
abort();
}
+ info.domain_id = did;
+ info.pasid = pasid;
+ /* For passthrough device, we don't need invalidate QEMU piotlb */
+ if (s->root_scalable && likely(s->dmar_enabled) && !vtd_idev)
+ g_hash_table_foreach_remove(s->p_iotlb, vtd_hash_remove_by_pasid,
+ &info);
+
/*
* pasid cache invalidation may indicate a present pasid
* entry to present pasid entry modification. To cover such
@@ -3725,18 +3741,9 @@ static gboolean vtd_flush_pasid(gpointer key, gpointer
value,
return true;
}
- /*
- * TODO:
- * - when pasid-base-iotlb(piotlb) infrastructure is ready,
- * should invalidate QEMU piotlb togehter with this change.
- */
return false;
+
remove:
- /*
- * TODO:
- * - when pasid-base-iotlb(piotlb) infrastructure is ready,
- * should invalidate QEMU piotlb togehter with this change.
- */
if (vtd_bind_guest_pasid(vtd_pasid_as,
NULL, VTD_PASID_UNBIND)) {
pasid_cache_info_set_error(pc_info);
--
2.34.1
- [PATCH rfcv1 09/23] vfio/iommufd_device: Add ioas_id in IOMMUFDDevice and pass to vIOMMU, (continued)
- [PATCH rfcv1 09/23] vfio/iommufd_device: Add ioas_id in IOMMUFDDevice and pass to vIOMMU, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 10/23] intel_iommu: bind/unbind guest page table to host, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 11/23] intel_iommu: ERRATA_772415 workaround, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 12/23] intel_iommu: replay pasid binds after context cache invalidation, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 13/23] intel_iommu: process PASID-based iotlb invalidation, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 14/23] intel_iommu: propagate PASID-based iotlb invalidation to host, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 15/23] intel_iommu: process PASID-based Device-TLB invalidation, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 16/23] intel_iommu: rename slpte in iotlb_entry to pte, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 17/23] intel_iommu: implement firt level translation, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 18/23] intel_iommu: fix the fault reason report, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 21/23] intel_iommu: invalidate piotlb when flush pasid,
Zhenzhong Duan <=
- [PATCH rfcv1 20/23] intel_iommu: piotlb invalidation should notify unmap, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 19/23] intel_iommu: introduce pasid iotlb cache, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 22/23] intel_iommu: refresh pasid bind after pasid cache force reset, Zhenzhong Duan, 2024/01/15
- [PATCH rfcv1 23/23] intel_iommu: modify x-scalable-mode to be string option, Zhenzhong Duan, 2024/01/15
- Re: [PATCH rfcv1 00/23] intel_iommu: Enable stage-1 translation, Jason Wang, 2024/01/21