FLTS for VT-d
cover FLTS for VT-d
This series is the first of a list that add support for SVM in the Intel IOMMU.
Here, we implement support for first-stage translation in VT-d. The PASID-based IOTLB invalidation is also added in this series as it is a requirement of FLTS.
The last patch introduces the 'flts' option to enable the feature from the command line.
Once enabled, several drivers of the Linux kernel use this feature.
This work is based on the VT-d specification version 4.1 (March 2023)
Here is a link to a GitHub repository where you can find the following elements :
- Qemu with all the patches for SVM
- ATS
- PRI
- PASID based IOTLB invalidation
- Device IOTLB invalidations
- First-stage translations
- Requests with already translated addresses
- A demo device
- A simple driver for the demo device
- A userspace program (for testing and demonstration purposes)
https://github.com/BullSequana/Qemu-in-guest-SVM-demo
Clément Mathieu--Drif (7):
intel_iommu: fix FRCD construction macro.
intel_iommu: rename slpte to pte before adding FLTS
intel_iommu: make types match
intel_iommu: add support for first-stage translation
intel_iommu: extract device IOTLB invalidation logic
intel_iommu: add PASID-based IOTLB invalidation
intel_iommu: add a CLI option to enable FLTS
hw/i386/intel_iommu.c | 655 ++++++++++++++++++++++++++------- hw/i386/intel_iommu_internal.h | 114 ++++-- include/hw/i386/intel_iommu.h | 3 +- 3 files changed, 609 insertions(+), 163 deletions(-)
Signature · 1 line
2.44.0
PATCH 1/7 intel_iommu: fix FRCD construction macro.
The constant must be unsigned, otherwise the two's complement overrides the other fields when a PASID is present
--- hw/i386/intel_iommu_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu_internal.h +1 -1
@@ -267,7 +267,7 @@/* For the low 64-bit of 128-bit */ #define VTD_FRCD_FI (val) ((val) & ~0xfffULL)#define VTD_FRCD_PV (val) (((val) & 0xffffULL) << 40) -#define VTD_FRCD_PP (val) (((val) & 0x1) << 31) +#define VTD_FRCD_PP (val) (((val) & 0x1ULL) << 31)#define VTD_FRCD_IR_IDX (val) (((val) & 0xffffULL) << 48)/* DMA Remapping Fault Conditions */
Signature · 1 line
2.44.0
PATCH 2/7 intel_iommu: rename slpte to pte before adding FLTS
In reply to CLEMENT MATHIEU--DRIFSome variables struct fields and functions can be used for both slpte and flpte. We can modify certain identifiers to make them more generic.
- slpte in IOMMUTLBEntry becomes pte and will be used for both FL and SL
- VTD_SL_PT_LEVEL, VTD_SL_PT_PAGE_SIZE_MASK and VTD_SL_LEVEL_BITS can be renamed and considered as a common constants
- vtd_iova_range_check becomes vtd_iova_sl_range_check because the range check depends on the translation type
- vtd_do_iommu_translate now handles both FL and SL so we can rename slpte to pte
- VTD_SL_PT_BASE_ADDR_MASK becomes VTD_PT_BASE_ADDR_MASK because the address offset within a 64bits word of a Scalable-Mode PASID Table Entry is the same for FL and SL. As a consequence, vtd_get_slpte_addr is also renamed to vtd_get_pte_addr.
- vtd_is_last_slpte becomes vtd_is_last_slpte because the same bit is used for FL and SL.
- vtd_slpt_level_page_mask becomes vtd_pt_level_page_mask
- vtd_get_slpte becomes vtd_get_pte
--- hw/i386/intel_iommu.c | 106 ++++++++++++++++----------------- hw/i386/intel_iommu_internal.h | 10 ++-- include/hw/i386/intel_iommu.h | 2 +- 3 files changed, 60 insertions(+), 58 deletions(-)
hw/i386/intel_iommu.c +53 -53
@@ -259,15 +259,15 @@ static gboolean vtd_hash_remove_by_domain(gpointer key, gpointer value, }/* The shift of an addr for a certain level of paging structure */ -static inline uint32_t vtd_slpt_level_shift (uint32_t level) +static inline uint32_t vtd_pt_level_shift (uint32_t level) {assert (level !=0 ); -return VTD_PAGE_SHIFT_4K + (level -1 ) *VTD_SL_LEVEL_BITS ; +return VTD_PAGE_SHIFT_4K + (level -1 ) *VTD_LEVEL_BITS ; } -static inline uint64_t vtd_slpt_level_page_mask (uint32_t level) +static inline uint64_t vtd_pt_level_page_mask (uint32_t level) { -return ~((1ULL <<vtd_slpt_level_shift (level)) -1 ); +return ~((1ULL <<vtd_pt_level_shift (level)) -1 ); } static gboolean vtd_hash_remove_by_page(gpointer key, gpointer value,
@@ -324,7 +324,7 @@ static void vtd_reset_caches(IntelIOMMUState *s)static uint64_t vtd_get_iotlb_gfn (hwaddr addr,uint32_t level) { -return (addr &vtd_slpt_level_page_mask (level)) >>VTD_PAGE_SHIFT_4K ; +return (addr &vtd_pt_level_page_mask (level)) >>VTD_PAGE_SHIFT_4K ; }/* Must be called with IOMMU lock held */
@@ -352,7 +352,7 @@ out:/* Must be with IOMMU lock held */ static void vtd_update_iotlb (IntelIOMMUState *s,uint16_t source_id, -uint16_t domain_id,hwaddr addr,uint64_t slpte, +uint16_t domain_id,hwaddr addr,uint64_t pte,uint8_t access_flags,uint32_t level,uint32_t pasid) {
@@ -360,7 +360,7 @@ static void vtd_update_iotlb(IntelIOMMUState *s, uint16_t source_id,struct vtd_iotlb_key *key =g_malloc (sizeof (*key));uint64_t gfn =vtd_get_iotlb_gfn (addr, level); -trace_vtd_iotlb_page_update (source_id, addr, slpte, domain_id); +trace_vtd_iotlb_page_update (source_id, addr, pte, domain_id);if (g_hash_table_size (s->iotlb) >=VTD_IOTLB_MAX_SIZE ) {trace_vtd_iotlb_reset ("iotlb exceeds size limit" );vtd_reset_iotlb_locked (s);
@@ -368,9 +368,9 @@ static void vtd_update_iotlb(IntelIOMMUState *s, uint16_t source_id, entry->gfn = gfn; entry->domain_id = domain_id; - entry->slpte = slpte; + entry->pte = pte; entry->access_flags = access_flags; - entry->mask =vtd_slpt_level_page_mask (level); + entry->mask =vtd_pt_level_page_mask (level); entry->pasid = pasid; key->gfn = gfn;
@@ -685,32 +685,32 @@ static inline dma_addr_t vtd_ce_get_slpt_base(VTDContextEntry *ce)return ce->lo &VTD_CONTEXT_ENTRY_SLPTPTR ; } -static inline uint64_t vtd_get_slpte_addr (uint64_t slpte,uint8_t aw) +static inline uint64_t vtd_get_pte_addr (uint64_t pte,uint8_t aw) { -return slpte &VTD_SL_PT_BASE_ADDR_MASK (aw); +return pte &VTD_PT_BASE_ADDR_MASK (aw); }/* Whether the pte indicates the address of the page frame */ -static inline bool vtd_is_last_slpte (uint64_t slpte,uint32_t level) +static inline bool vtd_is_last_pte (uint64_t pte,uint32_t level) { -return level ==VTD_SL_PT_LEVEL || (slpte &VTD_SL_PT_PAGE_SIZE_MASK ); +return level ==VTD_COMMON_PT_LEVEL || (pte &VTD_PT_PAGE_SIZE_MASK ); } -/* Get the content of a spte located in @base_addr[@index] */ -static uint64_t vtd_get_slpte (dma_addr_t base_addr,uint32_t index) +/* Get the content of a pte located in @base_addr[@index] */ +static uint64_t vtd_get_pte (dma_addr_t base_addr,uint32_t index) { -uint64_t slpte; +uint64_t pte; -assert (index <VTD_SL_PT_ENTRY_NR ); +assert (index <VTD_PT_ENTRY_NR );if (dma_memory_read (&address_space_memory, - base_addr + index *sizeof (slpte), - &slpte,sizeof (slpte),MEMTXATTRS_UNSPECIFIED )) { - slpte = (uint64_t )-1 ; -return slpte; + base_addr + index *sizeof (pte), + &pte,sizeof (pte),MEMTXATTRS_UNSPECIFIED )) { + pte = (uint64_t )-1 ; +return pte; } - slpte =le64_to_cpu (slpte); -return slpte; + pte =le64_to_cpu (pte); +return pte; }/* Given an iova and the level of paging structure, return the offset
@@ -718,8 +718,8 @@ static uint64_t vtd_get_slpte(dma_addr_t base_addr, uint32_t index)*/ static inline uint32_t vtd_iova_level_offset (uint64_t iova,uint32_t level) { -return (iova >>vtd_slpt_level_shift (level)) & - ((1ULL <<VTD_SL_LEVEL_BITS ) -1 ); +return (iova >>vtd_pt_level_shift (level)) & + ((1ULL <<VTD_LEVEL_BITS ) -1 ); }/* Check Capability Register to see if the @level of page-table is supported */
@@ -1016,7 +1016,7 @@ static inline uint64_t vtd_iova_limit(IntelIOMMUState *s, }/* Return true if IOVA passes range check, otherwise false. */ -static inline bool vtd_iova_range_check (IntelIOMMUState *s, +static inline bool vtd_iova_sl_range_check (IntelIOMMUState *s,uint64_t iova,VTDContextEntry *ce,uint8_t aw,uint32_t pasid) {
@@ -1064,12 +1064,12 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level)assert (level <VTD_SPTE_RSVD_LEN );/* * Zero level doesn't exist. The smallest level is VTD_SL_PT_LEVEL=1 and -* checked by vtd_is_last_slpte(). +* checked by vtd_is_last_pte(). */ assert (level);if ((level ==VTD_SL_PD_LEVEL || level ==VTD_SL_PDP_LEVEL ) && - (slpte &VTD_SL_PT_PAGE_SIZE_MASK )) { + (slpte &VTD_PT_PAGE_SIZE_MASK )) {/* large page */ rsvd_mask = vtd_spte_rsvd_large[level]; }else {
@@ -1095,7 +1095,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce,uint64_t access_right_check;uint64_t xlat, size; -if (!vtd_iova_range_check (s, iova, ce, aw_bits, pasid)) { +if (!vtd_iova_sl_range_check (s, iova, ce, aw_bits, pasid)) {error_report_once ("%s: detected IOVA overflow (iova=0x%" PRIx64"," "pasid=0x%" PRIx32")" , __func__, iova, pasid);return -VTD_FR_ADDR_BEYOND_MGAW ;
@@ -1106,7 +1106,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce,while (true) { offset =vtd_iova_level_offset (iova, level); - slpte =vtd_get_slpte (addr, offset); + slpte =vtd_get_pte (addr, offset);if (slpte == (uint64_t )-1 ) { error_report_once("%s: detected read error on DMAR slpte "
@@ -1137,17 +1137,17 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce,return -VTD_FR_PAGING_ENTRY_RSVD ; } -if (vtd_is_last_slpte (slpte, level)) { +if (vtd_is_last_pte (slpte, level)) { *slptep = slpte; *slpte_level = level;break ; } - addr =vtd_get_slpte_addr (slpte, aw_bits); + addr =vtd_get_pte_addr (slpte, aw_bits); level--; } - xlat =vtd_get_slpte_addr (*slptep, aw_bits); - size = ~vtd_slpt_level_page_mask (level) +1 ; + xlat =vtd_get_pte_addr (*slptep, aw_bits); + size = ~vtd_pt_level_page_mask (level) +1 ;/* * From VT-d spec 3.14: Untranslated requests and translation
@@ -1298,14 +1298,14 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start,trace_vtd_page_walk_level (addr, level, start, end); - subpage_size =1ULL <<vtd_slpt_level_shift (level); - subpage_mask =vtd_slpt_level_page_mask (level); + subpage_size =1ULL <<vtd_pt_level_shift (level); + subpage_mask =vtd_pt_level_page_mask (level);while (iova < end) { iova_next = (iova & subpage_mask) + subpage_size; offset =vtd_iova_level_offset (iova, level); - slpte =vtd_get_slpte (addr, offset); + slpte =vtd_get_pte (addr, offset);if (slpte == (uint64_t )-1 ) {trace_vtd_page_walk_skip_read (iova, iova_next);
@@ -1328,12 +1328,12 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start,*/ entry_valid = read_cur | write_cur; -if (!vtd_is_last_slpte (slpte, level) && entry_valid) { +if (!vtd_is_last_pte (slpte, level) && entry_valid) {/* * This is a valid PDE (or even bigger than PDE). We need * to walk one further level. */ - ret =vtd_page_walk_level (vtd_get_slpte_addr (slpte, info->aw), + ret =vtd_page_walk_level (vtd_get_pte_addr (slpte, info->aw), iova,MIN (iova_next, end), level -1 , read_cur, write_cur, info); }else {
@@ -1350,7 +1350,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start, event.entry.perm =IOMMU_ACCESS_FLAG (read_cur, write_cur); event.entry.addr_mask = ~subpage_mask;/* NOTE: this is only meaningful if entry_valid == true */ - event.entry.translated_addr =vtd_get_slpte_addr (slpte, info->aw); + event.entry.translated_addr =vtd_get_pte_addr (slpte, info->aw); event.type = event.entry.perm ?IOMMU_NOTIFIER_MAP :IOMMU_NOTIFIER_UNMAP ; ret =vtd_page_walk_one (&event, info);
@@ -1384,11 +1384,11 @@ static int vtd_page_walk(IntelIOMMUState *s, VTDContextEntry *ce,dma_addr_t addr =vtd_get_iova_pgtbl_base (s, ce, pasid);uint32_t level =vtd_get_iova_level (s, ce, pasid); -if (!vtd_iova_range_check (s, start, ce, info->aw, pasid)) { +if (!vtd_iova_sl_range_check (s, start, ce, info->aw, pasid)) {return -VTD_FR_ADDR_BEYOND_MGAW ; } -if (!vtd_iova_range_check (s, end, ce, info->aw, pasid)) { +if (!vtd_iova_sl_range_check (s, end, ce, info->aw, pasid)) {/* Fix end so that it reaches the maximum */ end =vtd_iova_limit (s, ce, info->aw, pasid); }
@@ -1869,7 +1869,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus,VTDContextEntry ce;uint8_t bus_num =pci_bus_num (bus);VTDContextCacheEntry *cc_entry; -uint64_t slpte, page_mask; +uint64_t pte, page_mask;uint32_t level, pasid = vtd_as->pasid;uint16_t source_id =PCI_BUILD_BDF (bus_num, devfn);int ret_fr;
@@ -1890,13 +1890,13 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus, cc_entry = &vtd_as->context_cache_entry; -/* Try to fetch slpte form IOTLB, we don't need RID2PASID logic */ +/* Try to fetch pte form IOTLB, we don't need RID2PASID logic */ if (!rid2pasid) { iotlb_entry =vtd_lookup_iotlb (s, source_id, pasid, addr);if (iotlb_entry) { -trace_vtd_iotlb_page_hit (source_id, addr, iotlb_entry->slpte, +trace_vtd_iotlb_page_hit (source_id, addr, iotlb_entry->pte, iotlb_entry->domain_id); - slpte = iotlb_entry->slpte; + pte = iotlb_entry->pte; access_flags = iotlb_entry->access_flags; page_mask = iotlb_entry->mask; goto out;
@@ -1968,20 +1968,20 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus,return true; } -/* Try to fetch slpte form IOTLB for RID2PASID slow path */ +/* Try to fetch pte form IOTLB for RID2PASID slow path */ if (rid2pasid) { iotlb_entry =vtd_lookup_iotlb (s, source_id, pasid, addr);if (iotlb_entry) { -trace_vtd_iotlb_page_hit (source_id, addr, iotlb_entry->slpte, +trace_vtd_iotlb_page_hit (source_id, addr, iotlb_entry->pte, iotlb_entry->domain_id); - slpte = iotlb_entry->slpte; + pte = iotlb_entry->pte; access_flags = iotlb_entry->access_flags; page_mask = iotlb_entry->mask; goto out; } } - ret_fr =vtd_iova_to_slpte (s, &ce, addr, is_write, &slpte, &level, + ret_fr =vtd_iova_to_slpte (s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid);if (ret_fr) { vtd_report_fault(s, -ret_fr, is_fpd_set, source_id,
@@ -1989,14 +1989,14 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus, goto error; } - page_mask =vtd_slpt_level_page_mask (level); + page_mask =vtd_pt_level_page_mask (level); access_flags =IOMMU_ACCESS_FLAG (reads, writes);vtd_update_iotlb (s, source_id,vtd_get_domain_id (s, &ce, pasid), - addr, slpte, access_flags, level, pasid); + addr, pte, access_flags, level, pasid); out:vtd_iommu_unlock (s); entry->iova = addr & page_mask; - entry->translated_addr =vtd_get_slpte_addr (slpte, s->aw_bits) & page_mask; + entry->translated_addr =vtd_get_pte_addr (pte, s->aw_bits) & page_mask; entry->addr_mask = ~page_mask; entry->perm = access_flags;return true;
hw/i386/intel_iommu_internal.h +6 -4
@@ -518,22 +518,24 @@ typedef struct VTDRootEntry VTDRootEntry;#define VTD_SM_PASID_ENTRY_SLPTPTR (~0xfffULL)/* Paging Structure common */ -#define VTD_SL_PT_PAGE_SIZE_MASK (1ULL << 7) +#define VTD_SM_PASID_ENTRY_PTPTR (~0xfffULL) +#define VTD_PT_PAGE_SIZE_MASK (1ULL << 7) +#define VTD_PT_ENTRY_NR 512 +#define VTD_PT_BASE_ADDR_MASK (aw) (~(VTD_PAGE_SIZE - 1) & VTD_HAW_MASK(aw)) +#define VTD_COMMON_PT_LEVEL 1/* Bits to decide the offset for each level */ -#define VTD_SL_LEVEL_BITS 9 +#define VTD_LEVEL_BITS 9/* Second Level Paging Structure */ #define VTD_SL_PML4_LEVEL 4#define VTD_SL_PDP_LEVEL 3#define VTD_SL_PD_LEVEL 2#define VTD_SL_PT_LEVEL 1 -#define VTD_SL_PT_ENTRY_NR 512/* Masks for Second Level Paging Entry */ #define VTD_SL_RW_MASK 3ULL#define VTD_SL_R 1ULL#define VTD_SL_W (1ULL << 1) -#define VTD_SL_PT_BASE_ADDR_MASK (aw) (~(VTD_PAGE_SIZE - 1) & VTD_HAW_MASK(aw))#define VTD_SL_IGN_COM 0xbff0000000000000ULL#define VTD_SL_TM (1ULL << 62)
include/hw/i386/intel_iommu.h +1 -1
@@ -152,7 +152,7 @@ struct VTDIOTLBEntry {uint64_t gfn;uint16_t domain_id;uint32_t pasid; -uint64_t slpte; +uint64_t pte;uint64_t mask;uint8_t access_flags; };
Signature · 1 line
2.44.0
PATCH 3/7 intel_iommu: make types match
In reply to CLEMENT MATHIEU--DRIFThe 'level' field in vtd_iotlb_key is an uint8_t. We don't need to store level as an int in vtd_lookup_iotlb
--- hw/i386/intel_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i386/intel_iommu.c +1 -1
@@ -333,7 +333,7 @@ static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id, {struct vtd_iotlb_key key;VTDIOTLBEntry *entry; -int level; +uint8_t level;for (level =VTD_SL_PT_LEVEL ; level <VTD_SL_PML4_LEVEL ; level++) { key.gfn =vtd_get_iotlb_gfn (addr, level);
Signature · 1 line
2.44.0
Re: [PATCH intel_iommu 3/7] intel_iommu: make types match
Quoted 13 lines · CLEMENT MATHIEU--DRIF
The 'level' field in
vtd_iotlb_keyis anuint8_t. We don't need to store level as an int invtd_lookup_iotlbSigned-off-by Clément Mathieu--Drif <[email protected]>--- hw/i386/intel_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/i386/intel_iommu.c +0
-0
hw/i386/intel_iommu.c static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id, · line 336
Quoted 5 lines
hw/i386/intel_iommu.c +1
-1@@ -333,7 +333,7 @@ static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id, {struct vtd_iotlb_key key;VTDIOTLBEntry *entry; -int level; +uint8_t level;
Or simply 'unsigned' up to vtd_slpt_level_shift()?
Re: [PATCH intel_iommu 3/7] intel_iommu: make types match
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 8 lines · CLEMENT MATHIEU--DRIF
The 'level' field in
vtd_iotlb_keyis anuint8_t. We don't need to store level as an int invtd_lookup_iotlbSigned-off-by Clément Mathieu--Drif <[email protected]>---
hw/i386/intel_iommu.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
hw/i386/intel_iommu.c static VTDIOTLBEntry · line 337
Quoted 11 lines
hw/i386/intel_iommu.c +1
-1@@ -333,7 +333,7 @@ static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id, { struct vtd_iotlb_key key; VTDIOTLBEntry *entry; - int level; + uint8_t level;Or simply 'unsigned' up to
vtd_slpt_level_shift()?
vtd_iotlb_key.level is an uint8_t, just avoiding a warning here
Re: [PATCH intel_iommu 3/7] intel_iommu: make types match
Quoted 24 lines · CLEMENT MATHIEU--DRIF
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 8 lines · CLEMENT MATHIEU--DRIF
The 'level' field in
vtd_iotlb_keyis anuint8_t. We don't need to store level as an int invtd_lookup_iotlbSigned-off-by Clément Mathieu--Drif <[email protected]>--- hw/i386/intel_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 13 lines
hw/i386/intel_iommu.c static VTDIOTLBEntry · line 337
Quoted 11 lines
hw/i386/intel_iommu.c +1
-1@@ -333,7 +333,7 @@ static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id, { struct vtd_iotlb_key key; VTDIOTLBEntry *entry; - int level; + uint8_t level;Or simply 'unsigned' up to
vtd_slpt_level_shift()?
Quoted 1 line
vtd_iotlb_key.level is an
uint8_t, just avoiding a warning here
What warning?
Re: [PATCH intel_iommu 3/7] intel_iommu: make types match
Quoted 27 lines · Philippe Mathieu-Daudé
Quoted 25 lines · CLEMENT MATHIEU--DRIF
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 14 lines · CLEMENT MATHIEU--DRIF
The 'level' field in
vtd_iotlb_keyis anuint8_t. We don't need to store level as an int invtd_lookup_iotlbSigned-off-by: Clément Mathieu--Drif
<[email protected]>
---
hw/i386/intel_iommu.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)hw/i386/intel_iommu.c +0
-0hw/i386/intel_iommu.c static VTDIOTLBEntry · line 337
Quoted 6 lines
hw/i386/intel_iommu.c +1
-1@@ -333,7 +333,7 @@ static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id, { struct vtd_iotlb_key key; VTDIOTLBEntry *entry; - int level; + uint8_t level;Or simply 'unsigned' up to
vtd_slpt_level_shift()?
Quoted 3 lines
Quoted 1 line
vtd_iotlb_key.level is an
uint8_t, just avoiding a warning hereWhat warning?
A linter warning, but it's not a big deal in our case because we know the value is lower than 5
PATCH 4/7 intel_iommu: add support for first-stage translation
In reply to CLEMENT MATHIEU--DRIFThis translation mode will only be made available in scalable mode
--- hw/i386/intel_iommu.c | 364 ++++++++++++++++++++++++++++----- hw/i386/intel_iommu_internal.h | 51 ++++- 2 files changed, 362 insertions(+), 53 deletions(-)
hw/i386/intel_iommu.c +315 -49
@@ -713,6 +713,21 @@ static uint64_t vtd_get_pte(dma_addr_t base_addr, uint32_t index)return pte; } +static MemTxResult vtd_set_flag_in_pte (dma_addr_t base_addr,uint32_t index, +uint64_t pte,uint64_t flag) +{ +assert (index <VTD_PT_ENTRY_NR ); +if (pte & flag) { +return MEMTX_OK ; + } + pte |= flag; + pte =cpu_to_le64 (pte); +return dma_memory_write (&address_space_memory, + base_addr + index *sizeof (pte), + &pte,sizeof (pte), +MEMTXATTRS_UNSPECIFIED ); +} +/* Given an iova and the level of paging structure, return the offset * of current level. */
@@ -730,11 +745,17 @@ static inline bool vtd_is_level_supported(IntelIOMMUState *s, uint32_t level) }/* Return true if check passed, otherwise false */ -static inline bool vtd_pe_type_check (X86IOMMUState *x86_iommu, +static inline bool vtd_pe_type_check (IntelIOMMUState *s,VTDPASIDEntry *pe) { +X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (s); +switch (VTD_PE_GET_TYPE (pe)) {case VTD_SM_PASID_ENTRY_FLT : +if (!(s->ecap &VTD_ECAP_FLTS )) { +return false; + } +break ;case VTD_SM_PASID_ENTRY_SLT :case VTD_SM_PASID_ENTRY_NESTED :break ;
@@ -784,6 +805,11 @@ static inline bool vtd_pe_present(VTDPASIDEntry *pe)return pe->val[0 ] &VTD_PASID_ENTRY_P ; } +static inline bool vtd_fl_pte_present (uint64_t pte) +{ +return pte &VTD_FL_PTE_P ; +} + static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s, uint32_t pasid, dma_addr_t addr,
@@ -791,7 +817,6 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s, {uint32_t index;dma_addr_t entry_size; -X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (s); index =VTD_PASID_TABLE_INDEX (pasid); entry_size =VTD_PASID_ENTRY_SIZE ;
@@ -805,7 +830,7 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s, }/* Do translation type check */ -if (!vtd_pe_type_check (x86_iommu, pe)) { +if (!vtd_pe_type_check (s, pe)) {return -VTD_FR_PASID_TABLE_INV ; }
@@ -1027,6 +1052,34 @@ static inline bool vtd_iova_sl_range_check(IntelIOMMUState *s,return !(iova & ~(vtd_iova_limit (s, ce, aw, pasid) -1 )); } +/* Return true if IOVA is canonical, otherwise false. */ +static bool vtd_iova_fl_check_canonical (IntelIOMMUState *s, +uint64_t iova,VTDContextEntry *ce, +uint8_t aw,uint32_t pasid) +{ +uint64_t iova_limit =vtd_iova_limit (s, ce, aw, pasid); +uint64_t upper_bits_mask = ~(iova_limit -1 ); +uint64_t upper_bits = iova & upper_bits_mask; +bool msb = ((iova & (iova_limit >>1 )) !=0 ); +return !( + (!msb && (upper_bits !=0 )) || + (msb && (upper_bits != upper_bits_mask)) + ); +} + +/* Return the page table base address corresponding to the translation type. */ +static dma_addr_t vtd_pe_get_pgtbl_base (VTDPASIDEntry *pe) +{ +uint16_t pgtt =VTD_PE_GET_TYPE (pe); +if (pgtt ==VTD_SM_PASID_ENTRY_FLT ) { +return pe->val[2 ] &VTD_SM_PASID_ENTRY_PTPTR ; + }else if (pgtt ==VTD_SM_PASID_ENTRY_SLT ) { +return pe->val[0 ] &VTD_SM_PASID_ENTRY_PTPTR ; + } + +return 0 ;/* Not supported */ +} +static dma_addr_t vtd_get_iova_pgtbl_base (IntelIOMMUState *s,VTDContextEntry *ce,uint32_t pasid)
@@ -1035,7 +1088,7 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUState *s,if (s->root_scalable) {vtd_ce_get_rid2pasid_entry (s, ce, &pe, pasid); -return pe.val[0 ] &VTD_SM_PASID_ENTRY_SLPTPTR ; +return vtd_pe_get_pgtbl_base (&pe); }return vtd_ce_get_slpt_base (ce);
@@ -1053,6 +1106,10 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUState *s,static uint64_t vtd_spte_rsvd[VTD_SPTE_RSVD_LEN ];static uint64_t vtd_spte_rsvd_large[VTD_SPTE_RSVD_LEN ]; +#define VTD_FPTE_RSVD_LEN 5 +static uint64_t vtd_fpte_rsvd[VTD_FPTE_RSVD_LEN ]; +static uint64_t vtd_fpte_rsvd_large[VTD_FPTE_RSVD_LEN ]; +static bool vtd_slpte_nonzero_rsvd (uint64_t slpte,uint32_t level) {uint64_t rsvd_mask;
@@ -1079,21 +1136,140 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level)return slpte & rsvd_mask; } -/* Given the @iova, get relevant @slptep. @slpte_level will be the last level -* of the translation, can be used for deciding the size of large page. -*/ -static int vtd_iova_to_slpte (IntelIOMMUState *s,VTDContextEntry *ce, -uint64_t iova,bool is_write, -uint64_t *slptep,uint32_t *slpte_level, -bool *reads,bool *writes,uint8_t aw_bits, -uint32_t pasid) +static bool vtd_flpte_nonzero_rsvd (uint64_t flpte,uint32_t level) +{ +uint64_t rsvd_mask; +assert (level <VTD_FPTE_RSVD_LEN ); +assert (level); + +if ((level ==VTD_FL_PD_LEVEL || level ==VTD_FL_PDP_LEVEL ) && + (flpte &VTD_PT_PAGE_SIZE_MASK )) { +/* large page */ + rsvd_mask = vtd_fpte_rsvd_large[level]; + }else { + rsvd_mask = vtd_fpte_rsvd[level]; + } + +return flpte & rsvd_mask; +} + +static int vtd_iova_to_pte_check_read_error (IntelIOMMUState *s, +VTDContextEntry *ce,uint64_t iova, +uint64_t pte,uint32_t pasid, +uint32_t level,uint16_t pgtt) +{ +if (pte == (uint64_t )-1 ) { +error_report_once ("%s: detected read error on DMAR pte " +"(iova=0x%" PRIx64", pasid=0x%" PRIx32")" , + __func__, iova, pasid); +if (level ==vtd_get_iova_level (s, ce, pasid)) { +/* Invalid programming of context-entry */ +if (s->root_scalable) { +return pgtt ==VTD_SM_PASID_ENTRY_FLT ? + -VTD_FR_FIRST_FSPE_ACCESS : + -VTD_FR_FIRST_SSPE_ACCESS ; + }else { +return -VTD_FR_CONTEXT_ENTRY_INV ; + } + }else { +if (s->root_scalable) { +return pgtt ==VTD_SM_PASID_ENTRY_FLT ? + -VTD_FR_FSPE_ACCESS : + -VTD_FR_SSPE_ACCESS ; + }else { +return -VTD_FR_PAGING_ENTRY_INV ; + } + } + } + +return 0 ; +} + +static inline bool vtd_addr_in_interrup_range (hwaddr addr,uint64_t size) +{ +return !((addr >VTD_INTERRUPT_ADDR_LAST ) || + (addr + size -1 <VTD_INTERRUPT_ADDR_FIRST )); +} + +static int vtd_iova_to_pte_fl (IntelIOMMUState *s,VTDContextEntry *ce, +uint64_t iova,bool is_write,uint64_t *ptep, +uint32_t *pte_level,bool *reads,bool *writes, +uint8_t aw_bits,uint32_t pasid,dma_addr_t addr) +{ +uint32_t offset; +uint64_t pte; +uint64_t access_right_check = is_write ?VTD_FL_W :0 ; +int ret; + +if (!vtd_iova_fl_check_canonical (s, iova, ce, aw_bits, pasid)) { +error_report_once ("%s: detected non canonical IOVA (iova=0x%" PRIx64"," +"pasid=0x%" PRIx32")" , __func__, iova, pasid); +return -VTD_FR_FS_NON_CANONICAL ; + } + +while (true) { + offset =vtd_iova_level_offset (iova, *pte_level); + pte =vtd_get_pte (addr, offset); + + ret =vtd_iova_to_pte_check_read_error (s, ce, iova, pte, + pasid, *pte_level, +VTD_SM_PASID_ENTRY_FLT ); +if (ret !=0 ) { +return ret; + } + +if (!vtd_fl_pte_present (pte)) { +return -VTD_FR_FSPE_NOT_PRESENT ; + } + + *reads = true; + *writes = (*writes) && (pte &VTD_FL_W ); + +if (vtd_set_flag_in_pte (addr, offset, pte,VTD_FL_PTE_A ) !=MEMTX_OK ) { +return -VTD_FR_FS_BIT_UPDATE_FAILED ; + } + +if ((pte & access_right_check) != access_right_check) { +error_report_once ("%s: detected pte permission error " +"(iova=0x%" PRIx64", level=0x%" PRIx32", " +"pte=0x%" PRIx64", write=%d, pasid=0x%" + PRIx32")" , __func__, iova, *pte_level, + pte, is_write, pasid); +return is_write ? -VTD_FR_SM_WRITE : -VTD_FR_SM_READ ; + } +if (vtd_flpte_nonzero_rsvd (pte, *pte_level)) { +error_report_once ("%s: detected flpte reserved non-zero " +"iova=0x%" PRIx64", level=0x%" PRIx32 +"pte=0x%" PRIx64", pasid=0x%" PRIX32 ")" , + __func__, iova, *pte_level, pte, pasid); +return -VTD_FR_PAGING_ENTRY_RSVD ; + } + +if (vtd_is_last_pte (pte, *pte_level)) { + *ptep = pte; +break ; + } + addr =vtd_get_pte_addr (pte, aw_bits); + (*pte_level)--; + } + +if (is_write && + (vtd_set_flag_in_pte (addr, offset, pte,VTD_FL_PTE_D ) !=MEMTX_OK )) { +return -VTD_FR_FS_BIT_UPDATE_FAILED ; + } + +return 0 ; +} + +static int vtd_iova_to_pte_sl (IntelIOMMUState *s,VTDContextEntry *ce, +uint64_t iova,bool is_write,uint64_t *slptep, +uint32_t *pte_level,bool *reads,bool *writes, +uint8_t aw_bits,uint32_t pasid,dma_addr_t addr) { -dma_addr_t addr =vtd_get_iova_pgtbl_base (s, ce, pasid); -uint32_t level =vtd_get_iova_level (s, ce, pasid);uint32_t offset;uint64_t slpte; -uint64_t access_right_check; -uint64_t xlat, size; +uint64_t access_right_check = is_write ?VTD_SL_W :VTD_SL_R ; +int ret;if (!vtd_iova_sl_range_check (s, iova, ce, aw_bits, pasid)) { error_report_once("%s: detected IOVA overflow (iova=0x%" PRIx64 ","
@@ -1101,72 +1277,128 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce,return -VTD_FR_ADDR_BEYOND_MGAW ; } -/* FIXME: what is the Atomics request here? */ - access_right_check = is_write ?VTD_SL_W :VTD_SL_R ; -while (true) { - offset =vtd_iova_level_offset (iova, level); + offset =vtd_iova_level_offset (iova, *pte_level); slpte =vtd_get_pte (addr, offset); -if (slpte == (uint64_t )-1 ) { -error_report_once ("%s: detected read error on DMAR slpte " -"(iova=0x%" PRIx64", pasid=0x%" PRIx32")" , - __func__, iova, pasid); -if (level ==vtd_get_iova_level (s, ce, pasid)) { -/* Invalid programming of context-entry */ -return -VTD_FR_CONTEXT_ENTRY_INV ; - }else { -return -VTD_FR_PAGING_ENTRY_INV ; - } + ret =vtd_iova_to_pte_check_read_error (s, ce, iova, slpte, + pasid, *pte_level, +VTD_SM_PASID_ENTRY_SLT ); +if (ret !=0 ) { +return ret; } *reads = (*reads) && (slpte &VTD_SL_R ); *writes = (*writes) && (slpte &VTD_SL_W ); -if (!(slpte & access_right_check)) { +if ((slpte & access_right_check) != access_right_check) {error_report_once ("%s: detected slpte permission error " "(iova=0x%" PRIx64", level=0x%" PRIx32", " "slpte=0x%" PRIx64", write=%d, pasid=0x%" - PRIx32")" , __func__, iova, level, + PRIx32")" , __func__, iova, *pte_level, slpte, is_write, pasid); -return is_write ? -VTD_FR_WRITE : -VTD_FR_READ ; +if (s->root_scalable) { +return is_write ? -VTD_FR_SM_WRITE : -VTD_FR_SM_READ ; + }else { +return is_write ? -VTD_FR_WRITE : -VTD_FR_READ ; + } } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (slpte, *pte_level)) {error_report_once ("%s: detected splte reserve non-zero " "iova=0x%" PRIx64", level=0x%" PRIx32"slpte=0x%" PRIx64", pasid=0x%" PRIX32 ")" , - __func__, iova, level, slpte, pasid); + __func__, iova, *pte_level, slpte, pasid);return -VTD_FR_PAGING_ENTRY_RSVD ; } -if (vtd_is_last_pte (slpte, level)) { +if (vtd_is_last_pte (slpte, *pte_level)) { *slptep = slpte; - *slpte_level = level;break ; } addr =vtd_get_pte_addr (slpte, aw_bits); - level--; + (*pte_level)--; + } + +return 0 ; +} + +/* +* Given the @iova, get relevant @ptep. @pte_level will be the last level +* of the translation, can be used for deciding the size of large page. +*/ +static int vtd_iova_to_pte (IntelIOMMUState *s,VTDContextEntry *ce, +uint64_t iova,bool is_write, +uint64_t *ptep,uint32_t *pte_level, +bool *reads,bool *writes,uint8_t aw_bits, +uint32_t pasid) +{ +dma_addr_t addr; +uint16_t pgtt; +uint64_t xlat, size; +VTDPASIDEntry pe; +int ret; + +/* FIXME: what is the Atomics request in access rights? */ + +if (s->root_scalable) { +vtd_ce_get_rid2pasid_entry (s, ce, &pe, pasid); + pgtt =VTD_PE_GET_TYPE (&pe); + *pte_level =VTD_PE_GET_LEVEL (&pe); + addr =vtd_pe_get_pgtbl_base (&pe); +switch (pgtt) { +case VTD_SM_PASID_ENTRY_FLT : +if (s->ecap &VTD_ECAP_FLTS ) { + ret =vtd_iova_to_pte_fl (s, ce, iova, is_write, ptep, pte_level, + reads, writes, aw_bits, pasid, addr); + }else { +error_report_once ("First-stage translation not supported : %d" , + pgtt); +return -VTD_FR_INVALID_PGTT ; + } +break ; +case VTD_SM_PASID_ENTRY_SLT : +if (s->ecap &VTD_ECAP_SLTS ) { + ret =vtd_iova_to_pte_sl (s, ce, iova, is_write, ptep, pte_level, + reads, writes, aw_bits, pasid, addr); + }else { +error_report_once ("Second-stage translation not supported : %d" , + pgtt); +return -VTD_FR_INVALID_PGTT ; + } +break ; +default : +error_report_once ("Unsupported PGTT : %d" , pgtt); + ret = -VTD_FR_INVALID_PGTT ; +break ; + } + }else { + *pte_level =vtd_ce_get_level (ce); + addr =vtd_ce_get_slpt_base (ce); + ret =vtd_iova_to_pte_sl (s, ce, iova, is_write, ptep, pte_level, + reads, writes, aw_bits, pasid, addr); } - xlat =vtd_get_pte_addr (*slptep, aw_bits); - size = ~vtd_pt_level_page_mask (level) +1 ; +if (ret !=0 ) { +return ret; + } + + xlat =vtd_get_pte_addr (*ptep, aw_bits); + size = ~vtd_pt_level_page_mask (*pte_level) +1 ;/* * From VT-d spec 3.14: Untranslated requests and translation * requests that result in an address in the interrupt range will be * blocked with condition code LGN.4 or SGN.8. */ -if ((xlat >VTD_INTERRUPT_ADDR_LAST || - xlat + size -1 <VTD_INTERRUPT_ADDR_FIRST )) { +if (!vtd_addr_in_interrup_range (xlat, size)) {return 0 ; }else {error_report_once ("%s: xlat address is in interrupt range " "(iova=0x%" PRIx64", level=0x%" PRIx32", " -"slpte=0x%" PRIx64", write=%d, " +"pte=0x%" PRIx64", write=%d, " "xlat=0x%" PRIx64", size=0x%" PRIx64", " "pasid=0x%" PRIx32")" , - __func__, iova, level, slpte, is_write, + __func__, iova, *pte_level, *ptep, is_write, xlat, size, pasid); -return s->scalable_mode ? -VTD_FR_SM_INTERRUPT_ADDR : - -VTD_FR_INTERRUPT_ADDR ; +return -VTD_INTERRUPT_RANGE_ERROR (s); } }
@@ -1772,6 +2004,16 @@ static const bool vtd_qualified_faults[] = { [VTD_FR_CONTEXT_ENTRY_TT] = true, [VTD_FR_PASID_TABLE_INV] = false, [VTD_FR_SM_INTERRUPT_ADDR] = true, + [VTD_FR_INVALID_PGTT] = true, + [VTD_FR_FSPE_ACCESS] = true, + [VTD_FR_FSPE_NOT_PRESENT] = true, + [VTD_FR_FIRST_FSPE_ACCESS] = true, + [VTD_FR_SSPE_ACCESS] = true, + [VTD_FR_FIRST_SSPE_ACCESS] = true, + [VTD_FR_FS_NON_CANONICAL] = true, + [VTD_FR_SM_WRITE] = true, + [VTD_FR_SM_READ] = true, + [VTD_FR_FS_BIT_UPDATE_FAILED] = true, [VTD_FR_MAX] = false, };
@@ -1870,7 +2112,8 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus,uint8_t bus_num =pci_bus_num (bus);VTDContextCacheEntry *cc_entry;uint64_t pte, page_mask; -uint32_t level, pasid = vtd_as->pasid; +uint32_t level =UINT32_MAX ; +uint32_t pasid = vtd_as->pasid;uint16_t source_id =PCI_BUILD_BDF (bus_num, devfn);int ret_fr;bool is_fpd_set = false;
@@ -1981,7 +2224,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus, } } - ret_fr =vtd_iova_to_slpte (s, &ce, addr, is_write, &pte, &level, + ret_fr =vtd_iova_to_pte (s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid);if (ret_fr) { vtd_report_fault(s, -ret_fr, is_fpd_set, source_id,
@@ -1990,6 +2233,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus, } page_mask =vtd_pt_level_page_mask (level); +/* Exe is always set to 0 in the spec */ access_flags =IOMMU_ACCESS_FLAG (reads, writes);vtd_update_iotlb (s, source_id,vtd_get_domain_id (s, &ce, pasid), addr, pte, access_flags, level, pasid);
@@ -2005,7 +2249,12 @@ error:vtd_iommu_unlock (s); entry->iova =0 ; entry->translated_addr =0 ; - entry->addr_mask =0 ; +/* +* Set the mask for ATS (the range must be present even when the +* translation fails : PCIe rev 5 10.2.3.5) +*/ + entry->addr_mask = (level !=UINT32_MAX ) ? + (~vtd_pt_level_page_mask (level)) : (~VTD_PAGE_MASK_4K ); entry->perm =IOMMU_NONE ;return false; }
@@ -3187,6 +3436,8 @@ static IOMMUTLBEntry vtd_iommu_translate(IOMMUMemoryRegion *iommu, hwaddr addr, };bool success; +/* IOMMUAccessFlags : IOMMU_EXEC and IOMMU_PRIV not supported */ +if (likely (s->dmar_enabled)) { success =vtd_do_iommu_translate (vtd_as, vtd_as->bus, vtd_as->devfn, addr, flag &IOMMU_WO , &iotlb);
@@ -3989,6 +4240,21 @@ static void vtd_init(IntelIOMMUState *s) vtd_spte_rsvd_large[3 ] =VTD_SPTE_LPAGE_L3_RSVD_MASK (s->aw_bits, x86_iommu->dt_supported); +/* +* Rsvd field masks for fpte +*/ + vtd_fpte_rsvd[0 ] = ~0ULL ; + vtd_fpte_rsvd[1 ] =VTD_FPTE_PAGE_L1_RSVD_MASK (s->aw_bits); + vtd_fpte_rsvd[2 ] =VTD_FPTE_PAGE_L2_RSVD_MASK (s->aw_bits); + vtd_fpte_rsvd[3 ] =VTD_FPTE_PAGE_L3_RSVD_MASK (s->aw_bits); + vtd_fpte_rsvd[4 ] =VTD_FPTE_PAGE_L4_RSVD_MASK (s->aw_bits); + + vtd_fpte_rsvd_large[0 ] = ~0ULL ; + vtd_fpte_rsvd_large[1 ] = ~0ULL ; + vtd_fpte_rsvd_large[2 ] =VTD_FPTE_PAGE_L2_FS2MP_RSVD_MASK (s->aw_bits); + vtd_fpte_rsvd_large[3 ] =VTD_FPTE_PAGE_L3_FS1GP_RSVD_MASK (s->aw_bits); + vtd_fpte_rsvd_large[4 ] = ~0ULL ; +if (s->scalable_mode || s->snoop_control) { vtd_spte_rsvd[1 ] &= ~VTD_SPTE_SNP ; vtd_spte_rsvd_large[2 ] &= ~VTD_SPTE_SNP ;
hw/i386/intel_iommu_internal.h +47 -4
99 lines not on this page · raw message
Signature · 1 line
2.44.0
PATCH 5/7 intel_iommu: extract device IOTLB invalidation logic
In reply to CLEMENT MATHIEU--DRIFThis piece of code can be shared by both IOTLB invalidation and PASID-based IOTLB invalidation
--- hw/i386/intel_iommu.c | 57 +++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 24 deletions(-)
hw/i386/intel_iommu.c +33 -24
@@ -2890,13 +2890,42 @@ static bool vtd_process_inv_iec_desc(IntelIOMMUState *s,return true; } +static void do_invalidate_device_tlb (VTDAddressSpace *vtd_dev_as, +bool size,hwaddr addr) +{ +/* +* According to ATS spec table 2.4: +* S = 0, bits 15:12 = xxxx range size: 4K +* S = 1, bits 15:12 = xxx0 range size: 8K +* S = 1, bits 15:12 = xx01 range size: 16K +* S = 1, bits 15:12 = x011 range size: 32K +* S = 1, bits 15:12 = 0111 range size: 64K +* ... +*/ + +IOMMUTLBEvent event; +uint64_t sz; + +if (size) { + sz = (VTD_PAGE_SIZE *2 ) <<cto64 (addr >>VTD_PAGE_SHIFT ); + addr &= ~(sz -1 ); + }else { + sz =VTD_PAGE_SIZE ; + } + + event.type =IOMMU_NOTIFIER_DEVIOTLB_UNMAP ; + event.entry.target_as = &vtd_dev_as->as; + event.entry.addr_mask = sz -1 ; + event.entry.iova = addr; + event.entry.perm =IOMMU_NONE ; + event.entry.translated_addr =0 ; +memory_region_notify_iommu (&vtd_dev_as->iommu,0 , event); +}static bool vtd_process_device_iotlb_desc (IntelIOMMUState *s,VTDInvDesc *inv_desc) {VTDAddressSpace *vtd_dev_as; -IOMMUTLBEvent event;hwaddr addr; -uint64_t sz;uint16_t sid;bool size;
@@ -2912,6 +2941,7 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s,return false; } +/* * Using sid is OK since the guest should have finished the * initialization of both the bus and device.
@@ -2921,28 +2951,7 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s, goto done; } -/* According to ATS spec table 2.4: -* S = 0, bits 15:12 = xxxx range size: 4K -* S = 1, bits 15:12 = xxx0 range size: 8K -* S = 1, bits 15:12 = xx01 range size: 16K -* S = 1, bits 15:12 = x011 range size: 32K -* S = 1, bits 15:12 = 0111 range size: 64K -* ... -*/ -if (size) { - sz = (VTD_PAGE_SIZE *2 ) <<cto64 (addr >>VTD_PAGE_SHIFT ); - addr &= ~(sz -1 ); - }else { - sz =VTD_PAGE_SIZE ; - } - - event.type =IOMMU_NOTIFIER_DEVIOTLB_UNMAP ; - event.entry.target_as = &vtd_dev_as->as; - event.entry.addr_mask = sz -1 ; - event.entry.iova = addr; - event.entry.perm =IOMMU_NONE ; - event.entry.translated_addr =0 ; -memory_region_notify_iommu (&vtd_dev_as->iommu,0 , event); +do_invalidate_device_tlb (vtd_dev_as, size, addr); done:return true;
Signature · 1 line
2.44.0
Re: [PATCH intel_iommu 5/7] intel_iommu: extract device IOTLB invalidation logic
Quoted 20 lines · CLEMENT MATHIEU--DRIF
This piece of code can be shared by both IOTLB invalidation and PASID-based IOTLB invalidation
Signed-off-by Clément Mathieu--Drif <[email protected]>--- hw/i386/intel_iommu.c | 57 +++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 24 deletions(-)static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s,
VTDInvDesc*inv_desc){ VTDAddressSpace *vtd_dev_as;hw/i386/intel_iommu.c +0
-2-IOMMUTLBEvent event;hwaddr addr; -uint64_t sz;uint16_t sid;bool size;
hw/i386/intel_iommu.c static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s, · line 2944
Quoted 4 lines
hw/i386/intel_iommu.c +1
-0@@ -2912,6 +2941,7 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s,return false; } +
Spurious newline ;)
Quoted 1 line
(quoted diff) +0
-0/*
Re: [PATCH intel_iommu 5/7] intel_iommu: extract device IOTLB invalidation logic
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 19 lines · CLEMENT MATHIEU--DRIF
This piece of code can be shared by both IOTLB invalidation and PASID-based IOTLB invalidation
Signed-off-by Clément Mathieu--Drif <[email protected]>---
hw/i386/intel_iommu.c| 57 +++++++++++++++++++++++++------------------1 file changed, 33 insertions(+), 24 deletions(-)static bool
vtd_process_device_iotlb_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc){
VTDAddressSpace*vtd_dev_as;
- IOMMUTLBEvent event;
hwaddr addr;
-uint64_tsz;
uint16_tsid;
bool size;
Quoted 8 lines
hw/i386/intel_iommu.c static bool · line 2945
Quoted 6 lines
hw/i386/intel_iommu.c +1
-0@@ -2912,6 +2941,7 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s, return false; } +Spurious newline ;)
Oups, sorry, it's fixed
Quoted 5 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Quoted 1 line
(quoted diff) +0
-0/*
PATCH 6/7 intel_iommu: add PASID-based IOTLB invalidation
In reply to CLEMENT MATHIEU--DRIF--- hw/i386/intel_iommu.c | 130 ++++++++++++++++++++++++++++++--- hw/i386/intel_iommu_internal.h | 51 +++++++------ 2 files changed, 150 insertions(+), 31 deletions(-)
hw/i386/intel_iommu.c +120 -10
@@ -277,9 +277,22 @@ static gboolean vtd_hash_remove_by_page(gpointer key, gpointer value,VTDIOTLBPageInvInfo *info = (VTDIOTLBPageInvInfo *)user_data;uint64_t gfn = (info->addr >>VTD_PAGE_SHIFT_4K ) & info->mask;uint64_t gfn_tlb = (info->addr & entry->mask) >>VTD_PAGE_SHIFT_4K ; -return (entry->domain_id == info->domain_id) && - (((entry->gfn & info->mask) == gfn) || - (entry->gfn == gfn_tlb)); +return ( + (entry->domain_id == info->domain_id) && + (info->pasid == entry->pasid) + ) && ( + ((entry->gfn & info->mask) == gfn) || + (entry->gfn == gfn_tlb) + ); +} + +static gboolean vtd_hash_remove_by_pasid (gpointer key,gpointer value, +gpointer user_data) +{ +VTDIOTLBEntry *entry = (VTDIOTLBEntry *)value; +VTDIOTLBPasidEntryInvInfo *info = (VTDIOTLBPasidEntryInvInfo *)user_data; +return ((entry->domain_id == info->domain_id) && + (info->pasid == entry->pasid)); }/* Reset all the gen of VTDAddressSpace to zero and set the gen of
@@ -1287,8 +1300,10 @@ static int vtd_iova_to_pte_sl(IntelIOMMUState *s, VTDContextEntry *ce,if (ret !=0 ) {return ret; } + *reads = (*reads) && (slpte &VTD_SL_R ); *writes = (*writes) && (slpte &VTD_SL_W ); +if ((slpte & access_right_check) != access_right_check) {error_report_once ("%s: detected slpte permission error " "(iova=0x%" PRIx64 ", level=0x%" PRIx32 ", "
@@ -2484,23 +2499,61 @@ static void vtd_iotlb_page_invalidate_notify(IntelIOMMUState *s, } } +static VTDIOTLBPageInvInfo vtd_build_tlb_page_inv_info (uint16_t domain_id, +hwaddr addr,uint8_t am, +uint32_t pasid) +{ +assert (am <=VTD_MAMV ); +VTDIOTLBPageInvInfo info = { + .domain_id = domain_id, + .addr = addr, + .mask = ~((1ULL << am) -1 ), + .pasid = pasid + }; +return info; +} +static void vtd_iotlb_page_invalidate (IntelIOMMUState *s,uint16_t domain_id,hwaddr addr,uint8_t am) { -VTDIOTLBPageInvInfo info; +VTDIOTLBPageInvInfo info =vtd_build_tlb_page_inv_info (domain_id, addr, + am,PCI_NO_PASID );trace_vtd_inv_desc_iotlb_pages (domain_id, addr, am); -assert (am <=VTD_MAMV ); - info.domain_id = domain_id; - info.addr = addr; - info.mask = ~((1 << am) -1 );vtd_iommu_lock (s);g_hash_table_foreach_remove (s->iotlb, vtd_hash_remove_by_page, &info);vtd_iommu_unlock (s); +vtd_iotlb_page_invalidate_notify (s, domain_id, addr, am,PCI_NO_PASID ); } +static void vtd_pasid_based_iotlb_page_invalidate (IntelIOMMUState *s, +uint16_t domain_id, +hwaddr addr, +uint8_t am,uint32_t pasid) +{ +VTDIOTLBPageInvInfo info =vtd_build_tlb_page_inv_info (domain_id, addr, + am, pasid); +vtd_iommu_lock (s); +g_hash_table_foreach_remove (s->iotlb, vtd_hash_remove_by_page, &info); +vtd_iommu_unlock (s); +} + +static void vtd_pasid_based_iotlb_invalidate (IntelIOMMUState *s, +uint16_t domain_id, +uint32_t pasid) +{ +assert (pasid !=PCI_NO_PASID ); +VTDIOTLBPasidEntryInvInfo info = { + .domain_id = domain_id, + .pasid = pasid + }; +vtd_iommu_lock (s); +g_hash_table_foreach_remove (s->iotlb, vtd_hash_remove_by_pasid, &info); +vtd_iommu_unlock (s); +} +/* Flush IOTLB * Returns the IOTLB Actual Invalidation Granularity. * @val: the content of the IOTLB_REG
@@ -2759,7 +2812,7 @@ static bool vtd_get_inv_desc(IntelIOMMUState *s,static bool vtd_process_wait_desc (IntelIOMMUState *s,VTDInvDesc *inv_desc) {if ((inv_desc->hi &VTD_INV_DESC_WAIT_RSVD_HI ) || - (inv_desc->lo &VTD_INV_DESC_WAIT_RSVD_LO )) { + (inv_desc->lo &VTD_INV_DESC_WAIT_RSVD_LO (s->ecap))) {error_report_once ("%s: invalid wait desc: hi=%" PRIx64", lo=%" PRIx64" (reserved nonzero)" , __func__, inv_desc->hi, inv_desc->lo);
@@ -2785,6 +2838,11 @@ static bool vtd_process_wait_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) }else if (inv_desc->lo &VTD_INV_DESC_WAIT_IF ) {/* Interrupt flag */ vtd_generate_completion_event (s); + }else if (inv_desc->lo &VTD_INV_DESC_WAIT_FN ) { +/* +* SW = 0, IF = 0, FN = 1 +* Nothing to do as we process the events sequentially +*/ }else { error_report_once("%s: invalid wait desc: hi=%"PRIx64", lo=%"PRIx64 " (unknown type)", __func__, inv_desc->hi,
@@ -2957,6 +3015,54 @@ done:return true; } +static bool vtd_process_piotlb_desc (IntelIOMMUState *s, +VTDInvDesc *inv_desc) +{ +uint32_t pasid; +uint16_t domain_id; +hwaddr addr; +uint8_t am; + +if ((inv_desc->lo &VTD_INV_DESC_IOTLB_PASID_RSVD_LO ) || + (inv_desc->hi &VTD_INV_DESC_IOTLB_PASID_RSVD_HI )) { +error_report_once ("%s: invalid piotlb inv desc: hi=0x%" PRIx64 +", lo=0x%" PRIx64" (reserved bits unzero)" , + __func__, inv_desc->hi, inv_desc->lo); +return false; + } + + domain_id =VTD_INV_DESC_IOTLB_DID (inv_desc->lo); + pasid =VTD_INV_DESC_IOTLB_PASID (inv_desc->lo); + addr =VTD_INV_DESC_IOTLB_ADDR (inv_desc->hi); + am =VTD_INV_DESC_IOTLB_AM (inv_desc->hi); + +switch (inv_desc->lo &VTD_INV_DESC_IOTLB_G ) { +case VTD_INV_DESC_IOTLB_PASID_PASID : +vtd_pasid_based_iotlb_invalidate (s, domain_id, pasid); +break ; + +case VTD_INV_DESC_IOTLB_PASID_PAGE : +if (am >VTD_MAMV ) { +error_report_once ("%s: invalid piotlb inv desc: hi=0x%" PRIx64 +", lo=0x%" PRIx64" (am=%u > VTD_MAMV=%u)" , + __func__, inv_desc->hi, inv_desc->lo, + am, (unsigned )VTD_MAMV ); +return false; + } +vtd_pasid_based_iotlb_page_invalidate (s, domain_id, addr, am, pasid); +break ; + +default : +error_report_once ("%s: invalid piotlb inv desc: hi=0x%" PRIx64 +", lo=0x%" PRIx64" (type mismatch: 0x%llx)" , + __func__, inv_desc->hi, inv_desc->lo, + inv_desc->lo &VTD_INV_DESC_IOTLB_G ); +return false; + } + +return true; +} +static bool vtd_process_inv_desc (IntelIOMMUState *s) {VTDInvDesc inv_desc;
@@ -2988,7 +3094,7 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s)break ;/* -* TODO: the entity of below two cases will be implemented in future series. +* TODO: the entity of below case will be implemented in future series. * To make guest (which integrates scalable mode support patch set in * iommu driver) work, just return true is enough so far. */
@@ -2996,6 +3102,10 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s)break ;case VTD_INV_DESC_PIOTLB : +trace_vtd_inv_desc ("piotlb" , inv_desc.hi, inv_desc.lo); +if (!vtd_process_piotlb_desc (s, &inv_desc)) { +return false; + }break ;case VTD_INV_DESC_WAIT :
hw/i386/intel_iommu_internal.h +30 -21
78 lines not on this page · raw message
Signature · 1 line
2.44.0
PATCH 7/7 intel_iommu: add a CLI option to enable FLTS
In reply to CLEMENT MATHIEU--DRIF--- hw/i386/intel_iommu.c | 6 ++++++ include/hw/i386/intel_iommu.h | 1 + 2 files changed, 7 insertions(+)
hw/i386/intel_iommu.c +6 -0
@@ -3704,6 +3704,7 @@ static Property vtd_properties[] = {DEFINE_PROP_BOOL ("x-scalable-mode" , IntelIOMMUState, scalable_mode, FALSE),DEFINE_PROP_BOOL ("snoop-control" , IntelIOMMUState, snoop_control, false),DEFINE_PROP_BOOL ("x-pasid-mode" , IntelIOMMUState, pasid, false), +DEFINE_PROP_BOOL ("flts" , IntelIOMMUState, flts, false),DEFINE_PROP_BOOL ("dma-drain" , IntelIOMMUState, dma_drain, true),DEFINE_PROP_BOOL ("dma-translation" , IntelIOMMUState, dma_translation, true), DEFINE_PROP_END_OF_LIST(),
@@ -4413,6 +4414,11 @@ static void vtd_init(IntelIOMMUState *s) s->ecap |=VTD_ECAP_PASID ; } +if (s->flts) { + s->ecap |=VTD_ECAP_FLTS ; + s->cap |=VTD_CAP_FS1GP ; + } +vtd_reset_caches (s);/* Define registers with default values and bit semantics */
include/hw/i386/intel_iommu.h +1 -0
@@ -263,6 +263,7 @@ struct IntelIOMMUState {bool caching_mode;/* RO - is cap CM enabled? */ bool scalable_mode;/* RO - is Scalable Mode supported? */ bool snoop_control;/* RO - is SNP filed supported? */ +bool flts;/* RO - is FS translation supported? */ dma_addr_t root;/* Current root table pointer */ bool root_scalable;/* Type of root table (scalable or not) */
Signature · 1 line
2.44.0
Cc'ing few developers who touched the intel_iommu model ;)
Quoted 40 lines · CLEMENT MATHIEU--DRIF
This series is the first of a list that add support for SVM in the Intel IOMMU.
Here, we implement support for first-stage translation in VT-d. The PASID-based IOTLB invalidation is also added in this series as it is a requirement of FLTS.
The last patch introduces the 'flts' option to enable the feature from the command line.
Once enabled, several drivers of the Linux kernel use this feature.This work is based on the VT-d specification version 4.1 (March 2023)
Here is a link to a GitHub repository where you can find the following elements :
- Qemu with all the patches for SVM
- ATS
- PRI
- PASID based IOTLB invalidation
- Device IOTLB invalidations
- First-stage translations
- Requests with already translated addresses
- A demo device
- A simple driver for the demo device
- A userspace program (for testing and demonstration purposes)https://github.com/BullSequana/Qemu-in-guest-SVM-demo
Clément Mathieu--Drif (7):
intel_iommu: fix FRCD construction macro.
intel_iommu: rename slpte to pte before adding FLTS
intel_iommu: make types match
intel_iommu: add support for first-stage translation
intel_iommu: extract device IOTLB invalidation logic
intel_iommu: add PASID-based IOTLB invalidation
intel_iommu: add a CLI option to enable FLTShw/i386/intel_iommu.c | 655 ++++++++++++++++++++++++++------- hw/i386/intel_iommu_internal.h | 114 ++++-- include/hw/i386/intel_iommu.h | 3 +- 3 files changed, 609 insertions(+), 163 deletions(-)
Hello,
Adding a few people in Cc: who are familiar with the Intel IOMMU.
Thanks,
C.
Quoted 40 lines · CLEMENT MATHIEU--DRIF
This series is the first of a list that add support for SVM in the Intel IOMMU.
Here, we implement support for first-stage translation in VT-d. The PASID-based IOTLB invalidation is also added in this series as it is a requirement of FLTS.
The last patch introduces the 'flts' option to enable the feature from the command line.
Once enabled, several drivers of the Linux kernel use this feature.This work is based on the VT-d specification version 4.1 (March 2023)
Here is a link to a GitHub repository where you can find the following elements :
- Qemu with all the patches for SVM
- ATS
- PRI
- PASID based IOTLB invalidation
- Device IOTLB invalidations
- First-stage translations
- Requests with already translated addresses
- A demo device
- A simple driver for the demo device
- A userspace program (for testing and demonstration purposes)https://github.com/BullSequana/Qemu-in-guest-SVM-demo
Clément Mathieu--Drif (7):
intel_iommu: fix FRCD construction macro.
intel_iommu: rename slpte to pte before adding FLTS
intel_iommu: make types match
intel_iommu: add support for first-stage translation
intel_iommu: extract device IOTLB invalidation logic
intel_iommu: add PASID-based IOTLB invalidation
intel_iommu: add a CLI option to enable FLTShw/i386/intel_iommu.c | 655 ++++++++++++++++++++++++++------- hw/i386/intel_iommu_internal.h | 114 ++++-- include/hw/i386/intel_iommu.h | 3 +- 3 files changed, 609 insertions(+), 163 deletions(-)
Ah, this is a duplicate effort on stage-1 translation.
Hi Clement,
We had ever sent a rfcv1 series "intel_iommu: Enable stage-1 translation" for both emulated and passthrough device, link:
https://lists.gnu.org/archive/html/qemu-devel/2024-01/msg02740.html
which now evolves to rfcv2, link:
https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_nesting_rfcv2/
It had addressed recent community comments, also the comments in old history series:
https://patchwork.kernel.org/project/kvm/cover/[email protected]/
Would you mind rebasing your remaining part, i.e., ATS, PRI emulation, etc on to our rfcv2?
Thanks
Zhenzhong
Quoted 58 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHello,
Adding a few people in Cc: who are familiar with the Intel IOMMU.
Thanks,
C.
Quoted 6 lines · CLEMENT MATHIEU--DRIF
This series is the first of a list that add support for SVM in the Intel IOMMU.
Here, we implement support for first-stage translation in VT-d. The PASID-based IOTLB invalidation is also added in this series as it is a requirement of FLTS.
Quoted 7 lines
The last patch introduces the 'flts' option to enable the feature from the command line.
Once enabled, several drivers of the Linux kernel use this feature.This work is based on the VT-d specification version 4.1 (March 2023)
Here is a link to a GitHub repository where you can find the following
elements :
Quoted 22 lines
- Qemu with all the patches for SVM
- ATS
- PRI
- PASID based IOTLB invalidation
- Device IOTLB invalidations
- First-stage translations
- Requests with already translated addresses
- A demo device
- A simple driver for the demo device
- A userspace program (for testing and demonstration purposes)https://github.com/BullSequana/Qemu-in-guest-SVM-demo
Clément Mathieu--Drif (7):
intel_iommu: fix FRCD construction macro.
intel_iommu: rename slpte to pte before adding FLTS
intel_iommu: make types match
intel_iommu: add support for first-stage translation
intel_iommu: extract device IOTLB invalidation logic
intel_iommu: add PASID-based IOTLB invalidation
intel_iommu: add a CLI option to enable FLTSQuoted 1 line
hw/i386/intel_iommu.c | 655 ++++++++++++++++++++++++++-------
Quoted 4 lines
hw/i386/intel_iommu_internal.h | 114 ++++-- include/hw/i386/intel_iommu.h | 3 +- 3 files changed, 609 insertions(+), 163 deletions(-)
Hi Zhenzhong,
I will rebase,
thanks
Quoted 79 lines · Zhenzhong
Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.
Ah, this is a duplicate effort on stage-1 translation.
Hi Clement,
We had ever sent a rfcv1 series "
intel_iommu: Enable stage-1 translation" for both emulated and passthrough device, link:
https://lists.gnu.org/archive/html/qemu-devel/2024-01/msg02740.html
which now evolves to rfcv2, link:
https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_nesting_rfcv2/It had addressed recent community comments, also the comments in old history series:
https://patchwork.kernel.org/project/kvm/cover/[email protected]/Would you mind rebasing your remaining part, i.e., ATS, PRI emulation, etc on to our rfcv2?
Thanks
ZhenzhongQuoted 58 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHello,
Adding a few people in Cc: who are familiar with the Intel IOMMU.
Thanks,
C.
Quoted 6 lines · CLEMENT MATHIEU--DRIF
This series is the first of a list that add support for SVM in the Intel IOMMU.
Here, we implement support for first-stage translation in VT-d. The PASID-based IOTLB invalidation is also added in this series as it is a requirement of FLTS.
Quoted 7 lines
The last patch introduces the 'flts' option to enable the feature from the command line.
Once enabled, several drivers of the Linux kernel use this feature.This work is based on the VT-d specification version 4.1 (March 2023)
Here is a link to a GitHub repository where you can find the following
elements :
Quoted 22 lines
- Qemu with all the patches for SVM
- ATS
- PRI
- PASID based IOTLB invalidation
- Device IOTLB invalidations
- First-stage translations
- Requests with already translated addresses
- A demo device
- A simple driver for the demo device
- A userspace program (for testing and demonstration purposes)https://github.com/BullSequana/Qemu-in-guest-SVM-demo
Clément Mathieu--Drif (7):
intel_iommu: fix FRCD construction macro.
intel_iommu: rename slpte to pte before adding FLTS
intel_iommu: make types match
intel_iommu: add support for first-stage translation
intel_iommu: extract device IOTLB invalidation logic
intel_iommu: add PASID-based IOTLB invalidation
intel_iommu: add a CLI option to enable FLTSQuoted 1 line
hw/i386/intel_iommu.c | 655 ++++++++++++++++++++++++++-------
Quoted 4 lines
hw/i386/intel_iommu_internal.h | 114 ++++-- include/hw/i386/intel_iommu.h | 3 +- 3 files changed, 609 insertions(+), 163 deletions(-)
Hi Clement,
Sorry for late response, just back from vacation. I saw your rebased version and thanks for your work. I'll schedule a timeslot to review them.
Thanks
Zhenzhong
Quoted 99 lines
-----Original Message-----
From: CLEMENT MATHIEU--DRIF <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHi Zhenzhong,
I will rebase,
thanks
Quoted 1 line · Zhenzhong
Caution: External email. Do not open attachments or click links, unless this
email comes from a known sender and you know the content is safe.
Quoted 11 lines
Ah, this is a duplicate effort on stage-1 translation.
Hi Clement,
We had ever sent a rfcv1 series "
intel_iommu: Enable stage-1 translation" for both emulated and passthrough device, link:
https://lists.gnu.org/archive/html/qemu-devel/2024-01/msg02740.html
which now evolves to rfcv2, link:https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_nesting
_rfcv2/Quoted 2 lines
It had addressed recent community comments, also the comments in old
history series:
Quoted 1 line
https://patchwork.kernel.org/project/kvm/cover/20210302203827.437645
[email protected]/Quoted 2 lines
Would you mind rebasing your remaining part, i.e., ATS, PRI emulation, etc
on to our rfcv2?
Quoted 21 lines
Thanks
ZhenzhongQuoted 17 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHello,
Adding a few people in Cc: who are familiar with the Intel IOMMU.
Thanks,
C.
Quoted 1 line · CLEMENT MATHIEU--DRIF
This series is the first of a list that add support for SVM in the Intel
IOMMU.
Quoted 35 lines
Quoted 35 lines
Quoted 5 lines
Here, we implement support for first-stage translation in VT-d. The PASID-based IOTLB invalidation is also added in this series as it is a requirement of FLTS.
Quoted 7 lines
The last patch introduces the 'flts' option to enable the feature from the command line.
Once enabled, several drivers of the Linux kernel use this feature.This work is based on the VT-d specification version 4.1 (March 2023)
Here is a link to a GitHub repository where you can find the following
elements :
Quoted 22 lines
- Qemu with all the patches for SVM
- ATS
- PRI
- PASID based IOTLB invalidation
- Device IOTLB invalidations
- First-stage translations
- Requests with already translated addresses
- A demo device
- A simple driver for the demo device
- A userspace program (for testing and demonstration purposes)https://github.com/BullSequana/Qemu-in-guest-SVM-demo
Clément Mathieu--Drif (7):
intel_iommu: fix FRCD construction macro.
intel_iommu: rename slpte to pte before adding FLTS
intel_iommu: make types match
intel_iommu: add support for first-stage translation
intel_iommu: extract device IOTLB invalidation logic
intel_iommu: add PASID-based IOTLB invalidation
intel_iommu: add a CLI option to enable FLTSQuoted 1 line
Quoted 1 line
Quoted 1 line
hw/i386/intel_iommu.c | 655 ++++++++++++++++++++++++++------
Quoted 5 lines
Quoted 5 lines
-
Quoted 4 lines
hw/i386/intel_iommu_internal.h | 114 ++++-- include/hw/i386/intel_iommu.h | 3 +- 3 files changed, 609 insertions(+), 163 deletions(-)
Hi Zhenzhong
Have you had time to review the ATS series rebased on you FLTS patches?
Thanks
Quoted 1 line
cmd
Quoted 105 lines · Zhenzhong
Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.
Hi Clement,
Sorry for late response, just back from vacation. I saw your rebased version and thanks for your work. I'll schedule a timeslot to review them.
Thanks
ZhenzhongQuoted 93 lines
-----Original Message-----
From: CLEMENT MATHIEU--DRIF <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHi Zhenzhong,
I will rebase,
thanks
Quoted 1 line · Zhenzhong
Caution: External email. Do not open attachments or click links, unless this
email comes from a known sender and you know the content is safe.
Quoted 10 lines
Ah, this is a duplicate effort on stage-1 translation.
Hi Clement,
We had ever sent a rfcv1 series "
intel_iommu: Enable stage-1 translation" for both emulated and passthrough device, link:
https://lists.gnu.org/archive/html/qemu-devel/2024-01/msg02740.html
which now evolves to rfcv2, link:https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_nesting
_rfcv2/Quoted 1 line
It had addressed recent community comments, also the comments in old
history series:
https://patchwork.kernel.org/project/kvm/cover/20210302203827.437645
[email protected]/Quoted 1 line
Would you mind rebasing your remaining part, i.e., ATS, PRI emulation, etc
on to our rfcv2?
Quoted 20 lines
Thanks
ZhenzhongQuoted 17 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHello,
Adding a few people in Cc: who are familiar with the Intel IOMMU.
Thanks,
C.
Quoted 1 line · CLEMENT MATHIEU--DRIF
This series is the first of a list that add support for SVM in the Intel
IOMMU.
Quoted 34 lines
Quoted 34 lines
Quoted 11 lines
Here, we implement support for first-stage translation in VT-d. The PASID-based IOTLB invalidation is also added in this series as it is a requirement of FLTS.
The last patch introduces the 'flts' option to enable the feature from the command line.
Once enabled, several drivers of the Linux kernel use this feature.This work is based on the VT-d specification version 4.1 (March 2023)
Here is a link to a GitHub repository where you can find the following
elements :
Quoted 22 lines
- Qemu with all the patches for SVM
- ATS
- PRI
- PASID based IOTLB invalidation
- Device IOTLB invalidations
- First-stage translations
- Requests with already translated addresses
- A demo device
- A simple driver for the demo device
- A userspace program (for testing and demonstration purposes)https://github.com/BullSequana/Qemu-in-guest-SVM-demo
Clément Mathieu--Drif (7):
intel_iommu: fix FRCD construction macro.
intel_iommu: rename slpte to pte before adding FLTS
intel_iommu: make types match
intel_iommu: add support for first-stage translation
intel_iommu: extract device IOTLB invalidation logic
intel_iommu: add PASID-based IOTLB invalidation
intel_iommu: add a CLI option to enable FLTSQuoted 1 line
Quoted 1 line
Quoted 1 line
hw/i386/intel_iommu.c | 655 ++++++++++++++++++++++++++------
Quoted 5 lines
Quoted 5 lines
-
Quoted 4 lines
hw/i386/intel_iommu_internal.h | 114 ++++-- include/hw/i386/intel_iommu.h | 3 +- 3 files changed, 609 insertions(+), 163 deletions(-)
Hi Clement,
I'll learn and try to give comments this week.
Thanks
Zhenzhong
Quoted 128 lines
-----Original Message-----
From: CLEMENT MATHIEU--DRIF <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHi Zhenzhong
Have you had time to review the ATS series rebased on you FLTS patches?
Thanks
Quoted 1 line
cmd
Quoted 1 line · Zhenzhong
Caution: External email. Do not open attachments or click links, unless this
email comes from a known sender and you know the content is safe.
Quoted 23 lines
Hi Clement,
Sorry for late response, just back from vacation. I saw your rebased version and thanks for your work. I'll schedule a timeslot to review them.
Thanks
ZhenzhongQuoted 12 lines
-----Original Message-----
From: CLEMENT MATHIEU--DRIF <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHi Zhenzhong,
I will rebase,
thanks
Quoted 1 line · Zhenzhong
Caution: External email. Do not open attachments or click links, unless
this
Quoted 7 lines
Quoted 7 lines
email comes from a known sender and you know the content is safe.
Quoted 6 lines
Ah, this is a duplicate effort on stage-1 translation.
Hi Clement,
We had ever sent a rfcv1 series "
intel_iommu: Enable stage-1translation"
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
for both emulated and passthrough device, link:
https://lists.gnu.org/archive/html/qemu-devel/2024-01/msg02740.html
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
which now evolves to rfcv2, link:
https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_nesting
Quoted 2 lines
Quoted 2 lines
_rfcv2/
Quoted 1 line
It had addressed recent community comments, also the comments in
old
Quoted 2 lines
Quoted 2 lines
history series:
https://patchwork.kernel.org/project/kvm/cover/20210302203827.437645
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Would you mind rebasing your remaining part, i.e., ATS, PRI emulation,
etc
Quoted 19 lines
Quoted 19 lines
on to our rfcv2?
Quoted 18 lines
Thanks
ZhenzhongQuoted 15 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHello,
Adding a few people in Cc: who are familiar with the Intel IOMMU.
Thanks,
C.
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines · CLEMENT MATHIEU--DRIF
Quoted 1 line
This series is the first of a list that add support for SVM in the Intel
IOMMU.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Here, we implement support for first-stage translation in VT-d. The PASID-based IOTLB invalidation is also added in this series as it is
a
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 9 lines
requirement of FLTS.
The last patch introduces the 'flts' option to enable the feature from the command line.
Once enabled, several drivers of the Linux kernel use this feature.This work is based on the VT-d specification version 4.1 (March 2023)
Here is a link to a GitHub repository where you can find the following
elements :
Quoted 22 lines
- Qemu with all the patches for SVM
- ATS
- PRI
- PASID based IOTLB invalidation
- Device IOTLB invalidations
- First-stage translations
- Requests with already translated addresses
- A demo device
- A simple driver for the demo device
- A userspace program (for testing and demonstration purposes)https://github.com/BullSequana/Qemu-in-guest-SVM-demo
Clément Mathieu--Drif (7):
intel_iommu: fix FRCD construction macro.
intel_iommu: rename slpte to pte before adding FLTS
intel_iommu: make types match
intel_iommu: add support for first-stage translation
intel_iommu: extract device IOTLB invalidation logic
intel_iommu: add PASID-based IOTLB invalidation
intel_iommu: add a CLI option to enable FLTSQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/i386/intel_iommu.c | 655++++++++++++++++++++++++++-
Quoted 6 lines
Quoted 6 lines
-----
Quoted 5 lines
Quoted 5 lines
-
Quoted 4 lines
hw/i386/intel_iommu_internal.h | 114 ++++-- include/hw/i386/intel_iommu.h | 3 +- 3 files changed, 609 insertions(+), 163 deletions(-)
Thanks ;)
Quoted 1 line
cmd
Quoted 134 lines · Zhenzhong
Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.
Hi Clement,
I'll learn and try to give comments this week.
Thanks
ZhenzhongQuoted 124 lines
-----Original Message-----
From: CLEMENT MATHIEU--DRIF <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHi Zhenzhong
Have you had time to review the ATS series rebased on you FLTS patches?
Thanks
Quoted 1 line
cmd
Quoted 1 line · Zhenzhong
Caution: External email. Do not open attachments or click links, unless this
email comes from a known sender and you know the content is safe.
Quoted 22 lines
Hi Clement,
Sorry for late response, just back from vacation. I saw your rebased version and thanks for your work. I'll schedule a timeslot to review them.
Thanks
ZhenzhongQuoted 12 lines
-----Original Message-----
From: CLEMENT MATHIEU--DRIF <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHi Zhenzhong,
I will rebase,
thanks
Quoted 1 line · Zhenzhong
Caution: External email. Do not open attachments or click links, unless
this
Quoted 6 lines
Quoted 6 lines
email comes from a known sender and you know the content is safe.
Quoted 5 lines
Ah, this is a duplicate effort on stage-1 translation.
Hi Clement,
We had ever sent a rfcv1 series "
intel_iommu: Enable stage-1translation"
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
for both emulated and passthrough device, link:
https://lists.gnu.org/archive/html/qemu-devel/2024-01/msg02740.html
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
which now evolves to rfcv2, link:
https://github.com/yiliu1765/qemu/commits/zhenzhong/iommufd_nesting
Quoted 2 lines
Quoted 2 lines
_rfcv2/
Quoted 1 line
It had addressed recent community comments, also the comments in
old
Quoted 2 lines
Quoted 2 lines
history series:
https://patchwork.kernel.org/project/kvm/cover/20210302203827.437645
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Would you mind rebasing your remaining part, i.e., ATS, PRI emulation,
etc
Quoted 19 lines
Quoted 19 lines
on to our rfcv2?
Quoted 18 lines
Thanks
ZhenzhongQuoted 15 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Subject: Re: [PATCHintel_iommu0/7] FLTS for VT-dHello,
Adding a few people in Cc: who are familiar with the Intel IOMMU.
Thanks,
C.
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines · CLEMENT MATHIEU--DRIF
Quoted 1 line
This series is the first of a list that add support for SVM in the Intel
IOMMU.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Here, we implement support for first-stage translation in VT-d. The PASID-based IOTLB invalidation is also added in this series as it is
a
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 9 lines
requirement of FLTS.
The last patch introduces the 'flts' option to enable the feature from the command line.
Once enabled, several drivers of the Linux kernel use this feature.This work is based on the VT-d specification version 4.1 (March 2023)
Here is a link to a GitHub repository where you can find the following
elements :
Quoted 22 lines
- Qemu with all the patches for SVM
- ATS
- PRI
- PASID based IOTLB invalidation
- Device IOTLB invalidations
- First-stage translations
- Requests with already translated addresses
- A demo device
- A simple driver for the demo device
- A userspace program (for testing and demonstration purposes)https://github.com/BullSequana/Qemu-in-guest-SVM-demo
Clément Mathieu--Drif (7):
intel_iommu: fix FRCD construction macro.
intel_iommu: rename slpte to pte before adding FLTS
intel_iommu: make types match
intel_iommu: add support for first-stage translation
intel_iommu: extract device IOTLB invalidation logic
intel_iommu: add PASID-based IOTLB invalidation
intel_iommu: add a CLI option to enable FLTSQuoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hw/i386/intel_iommu.c | 655++++++++++++++++++++++++++-
Quoted 6 lines
Quoted 6 lines
-----
Quoted 5 lines
Quoted 5 lines
-
Quoted 4 lines
hw/i386/intel_iommu_internal.h | 114 ++++-- include/hw/i386/intel_iommu.h | 3 +- 3 files changed, 609 insertions(+), 163 deletions(-)
Quoted 24 lines · CLEMENT MATHIEU--DRIF
This series is the first of a list that add support for SVM in the Intel IOMMU.
Here, we implement support for first-stage translation in VT-d. The PASID-based IOTLB invalidation is also added in this series as it is a requirement of FLTS.
The last patch introduces the 'flts' option to enable the feature from the command line.
Once enabled, several drivers of the Linux kernel use this feature.This work is based on the VT-d specification version 4.1 (March 2023)
Here is a link to a GitHub repository where you can find the following elements :
- Qemu with all the patches for SVM
- ATS
- PRI
- PASID based IOTLB invalidation
- Device IOTLB invalidations
- First-stage translations
- Requests with already translated addresses
- A demo device
- A simple driver for the demo device
- A userspace program (for testing and demonstration purposes)
Pls post v2 addressing minor comments so far.
Quoted 16 lines
Clément Mathieu--Drif (7):
intel_iommu: fix FRCD construction macro.
intel_iommu: rename slpte to pte before adding FLTS
intel_iommu: make types match
intel_iommu: add support for first-stage translation
intel_iommu: extract device IOTLB invalidation logic
intel_iommu: add PASID-based IOTLB invalidation
intel_iommu: add a CLI option to enable FLTShw/i386/intel_iommu.c | 655 ++++++++++++++++++++++++++------- hw/i386/intel_iommu_internal.h | 114 ++++-- include/hw/i386/intel_iommu.h | 3 +- 3 files changed, 609 insertions(+), 163 deletions(-)Signature · 1 line
2.44.0
Quoted 28 lines · Michael S. Tsirkin
Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.
Quoted 24 lines · CLEMENT MATHIEU--DRIF
This series is the first of a list that add support for SVM in the Intel IOMMU.
Here, we implement support for first-stage translation in VT-d. The PASID-based IOTLB invalidation is also added in this series as it is a requirement of FLTS.
The last patch introduces the 'flts' option to enable the feature from the command line.
Once enabled, several drivers of the Linux kernel use this feature.This work is based on the VT-d specification version 4.1 (March 2023)
Here is a link to a GitHub repository where you can find the following elements :
- Qemu with all the patches for SVM
- ATS
- PRI
- PASID based IOTLB invalidation
- Device IOTLB invalidations
- First-stage translations
- Requests with already translated addresses
- A demo device
- A simple driver for the demo device
- A userspace program (for testing and demonstration purposes)
Quoted 2 lines
Pls post v2 addressing minor comments so far.
Hi Michael,
The comments have been addressed and I rebased my work for SVM support on Zhenzhong's FLTS implementation (who cherry picked patches from this series)
You can see all the changes in my series called 'ATS support for VT-d' (posted on May 21st). I also posted the PRI series on May 30th.
I'm going to post a new version of ATS today to address Philippe's comment on patch called 'make types match'
Tell me if you want me to change something
Quoted 19 lines
cmd
Quoted 16 lines
Clément Mathieu--Drif (7):
intel_iommu: fix FRCD construction macro.
intel_iommu: rename slpte to pte before adding FLTS
intel_iommu: make types match
intel_iommu: add support for first-stage translation
intel_iommu: extract device IOTLB invalidation logic
intel_iommu: add PASID-based IOTLB invalidation
intel_iommu: add a CLI option to enable FLTShw/i386/intel_iommu.c | 655 ++++++++++++++++++++++++++------- hw/i386/intel_iommu_internal.h | 114 ++++-- include/hw/i386/intel_iommu.h | 3 +- 3 files changed, 609 insertions(+), 163 deletions(-)--
2.44.0