VT-d: some enhancements on iotlb
v4 cover VT-d: some enhancements on iotlb
v4:
- removed patch 2 (x-iotlb-size patch) and patch 4 (mru list for iotlb) [mst]
- used VTD_PAGE_SIZE_4K for patch 1 [Jason]
v3:
- fix issue reported by patchew on style
v2:
- rebase to master
- removed all "info iommu" patches for now
(is it bad to introduce new HMP commands without QMP? I thought not,
but in case I missed anything, please kindly let me know...)
Patch 1: fixes a very rare PT path issue on iova value. It didn't break anything since it's merely not touched (only if when IOMMU enabled, then set one device to PT), but still better fix it.
Patch 2: introduce "x-iotlb-size" to tune iotlb size, or to turn it off (e.g., when we want to measure how iotlb affects one payload).
Patch 3: some refine on iotlb entry.
Patch 4: implemented MRU list algorithm for iotlb.
Please review. Thanks,
Peter Xu (2):
intel_iommu: fix iova for pt
intel_iommu: use access_flags for iotlb
hw/i386/intel_iommu.c | 19 +++++++++---------- hw/i386/intel_iommu_internal.h | 1 - include/hw/i386/intel_iommu.h | 3 +-- 3 files changed, 10 insertions(+), 13 deletions(-)
Signature · 1 line
2.7.4
PATCH v4 1/2 intel_iommu: fix iova for pt
IOMMUTLBEntry.iova is returned incorrectly on one PT path (though mostly we cannot really trigger this path, even if we do, we are mostly disgarding this value, so it didn't break anything). Fix it by converting the VTD_PAGE_MASK into the correct definition VTD_PAGE_MASK_4K, then remove VTD_PAGE_MASK.
--- hw/i386/intel_iommu.c | 4 ++-- hw/i386/intel_iommu_internal.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-)
hw/i386/intel_iommu.c +2 -2
@@ -1139,9 +1139,9 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus,* Also, let's ignore IOTLB caching as well for PT devices. */ if (vtd_ce_get_type (&ce) ==VTD_CONTEXT_TT_PASS_THROUGH ) { - entry->iova = addr &VTD_PAGE_MASK ; + entry->iova = addr &VTD_PAGE_MASK_4K ; entry->translated_addr = entry->iova; - entry->addr_mask =VTD_PAGE_MASK ; + entry->addr_mask = ~VTD_PAGE_MASK_4K ; entry->perm =IOMMU_RW ;trace_vtd_translate_pt (source_id, entry->iova);
hw/i386/intel_iommu_internal.h +0 -1
@@ -384,7 +384,6 @@ typedef struct VTDIOTLBPageInvInfo VTDIOTLBPageInvInfo;/* Pagesize of VTD paging structures, including root and context tables */ #define VTD_PAGE_SHIFT 12#define VTD_PAGE_SIZE (1ULL << VTD_PAGE_SHIFT) -#define VTD_PAGE_MASK (VTD_PAGE_SIZE - 1)#define VTD_PAGE_SHIFT_4K 12#define VTD_PAGE_MASK_4K (~((1ULL << VTD_PAGE_SHIFT_4K) - 1))
Signature · 1 line
2.7.4
PATCH v4 2/2 intel_iommu: use access_flags for iotlb
In reply to Peter XuIt was cached by read/write separately. Let's merge them.
--- hw/i386/intel_iommu.c | 15 +++++++-------- include/hw/i386/intel_iommu.h | 3 +-- 2 files changed, 8 insertions(+), 10 deletions(-)
hw/i386/intel_iommu.c +7 -8
@@ -237,8 +237,7 @@ out:static void vtd_update_iotlb (IntelIOMMUState *s,uint16_t source_id,uint16_t domain_id,hwaddr addr,uint64_t slpte, -bool read_flags,bool write_flags, -uint32_t level) +uint8_t access_flags,uint32_t level) {VTDIOTLBEntry *entry =g_malloc (sizeof (*entry));uint64_t *key =g_malloc (sizeof (*key));
@@ -253,8 +252,7 @@ static void vtd_update_iotlb(IntelIOMMUState *s, uint16_t source_id, entry->gfn = gfn; entry->domain_id = domain_id; entry->slpte = slpte; - entry->read_flags = read_flags; - entry->write_flags = write_flags; + entry->access_flags = access_flags; entry->mask =vtd_slpt_level_page_mask (level); *key =vtd_get_iotlb_key (gfn, source_id, level);g_hash_table_replace (s->iotlb, key, entry);
@@ -1087,6 +1085,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus,bool is_fpd_set = false;bool reads = true;bool writes = true; +uint8_t access_flags;VTDIOTLBEntry *iotlb_entry;/*
@@ -1101,8 +1100,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus,trace_vtd_iotlb_page_hit (source_id, addr, iotlb_entry->slpte, iotlb_entry->domain_id); slpte = iotlb_entry->slpte; - reads = iotlb_entry->read_flags; - writes = iotlb_entry->write_flags; + access_flags = iotlb_entry->access_flags; page_mask = iotlb_entry->mask; goto out; }
@@ -1172,13 +1170,14 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus, } page_mask =vtd_slpt_level_page_mask (level); + access_flags =IOMMU_ACCESS_FLAG (reads, writes);vtd_update_iotlb (s, source_id,VTD_CONTEXT_ENTRY_DID (ce.hi), addr, slpte, - reads, writes, level); + access_flags, level); out: entry->iova = addr & page_mask; entry->translated_addr =vtd_get_slpte_addr (slpte) & page_mask; entry->addr_mask = ~page_mask; - entry->perm =IOMMU_ACCESS_FLAG (reads, writes); + entry->perm = access_flags;return true; error:
include/hw/i386/intel_iommu.h +1 -2
@@ -103,8 +103,7 @@ struct VTDIOTLBEntry {uint16_t domain_id;uint64_t slpte;uint64_t mask; -bool read_flags; -bool write_flags; +uint8_t access_flags; };/* VT-d Source-ID Qualifier types */
Signature · 1 line
2.7.4