intel-iommu: add support for 5-level virtual IOMMU.
cover intel-iommu: add support for 5-level virtual IOMMU.
Intel's upcoming processors will extend maximum linear address width to 57 bits, and introduce 5-level paging for CPU. Meanwhile, the platform will also extend the maximum guest address width for IOMMU to 57 bits, thus introducing the 5-level paging for 2nd level translation(See chapter 3 in Intel Virtualization Technology for Directed I/O).
This patch set extends the current logic to support a wider address width. A 5-level paging capable IOMMU(for 2nd level translation) can be rendered with configuration "device intel-iommu,x-aw-bits=57".
Yu Zhang (3):
intel-iommu: differentiate host address width from IOVA address width.
intel-iommu: extend VTD emulation to allow 57-bit IOVA address width.
intel-iommu: search iotlb for levels supported by the address width.
---
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Igor Mammedov <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Xu <[email protected]>
hw/i386/acpi-build.c | 2 +- hw/i386/intel_iommu.c | 101 +++++++++++++++++++++++++++-------------- hw/i386/intel_iommu_internal.h | 13 ++++-- include/hw/i386/intel_iommu.h | 10 ++-- 4 files changed, 83 insertions(+), 43 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/3 intel-iommu: differentiate host address width from IOVA address width.
Currently, vIOMMU is using the value of IOVA address width, instead of the host address width(HAW) to calculate the number of reserved bits in data structures such as root entries, context entries, and entries of DMA paging structures etc.
However values of IOVA address width and of the HAW may not equal. For example, a 48-bit IOVA can only be mapped to host addresses no wider than 46 bits. Using 48, instead of 46 to calculate the reserved bit may result in an invalid IOVA being accepted.
To fix this, a new field - haw_bits is introduced in struct IntelIOMMUState, whose value is initialized based on the maximum physical address set to guest CPU. Also, definitions such as VTD_HOST_AW_39/48BIT etc. are renamed to clarify.
---
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Igor Mammedov <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Xu <[email protected]>
--- hw/i386/acpi-build.c | 2 +- hw/i386/intel_iommu.c | 54 +++++++++++++++++++++++-------------------- include/hw/i386/intel_iommu.h | 9 ++++---- 3 files changed, 35 insertions(+), 30 deletions(-)
hw/i386/acpi-build.c +1 -1
@@ -2431,7 +2431,7 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker) } dmar =acpi_data_push (table_data,sizeof (*dmar)); - dmar->host_address_width = intel_iommu->aw_bits -1 ; + dmar->host_address_width = intel_iommu->haw_bits -1 ; dmar->flags = dmar_flags;/* DMAR Remapping Hardware Unit Definition structure */
hw/i386/intel_iommu.c +29 -25
159 lines not on this page · raw message
include/hw/i386/intel_iommu.h +5 -4
@@ -47,9 +47,9 @@#define VTD_SID_TO_DEVFN (sid) ((sid) & 0xff)#define DMAR_REG_SIZE 0x230 -#define VTD_HOST_AW_39BIT 39 -#define VTD_HOST_AW_48BIT 48 -#define VTD_HOST_ADDRESS_WIDTH VTD_HOST_AW_39BIT +#define VTD_AW_39BIT 39 +#define VTD_AW_48BIT 48 +#define VTD_ADDRESS_WIDTH VTD_AW_39BIT#define VTD_HAW_MASK (aw) ((1ULL << (aw)) - 1)#define DMAR_REPORT_F_INTR (1)
@@ -244,7 +244,8 @@ struct IntelIOMMUState {bool intr_eime;/* Extended interrupt mode enabled */ OnOffAuto intr_eim;/* Toggle for EIM cabability */ bool buggy_eim;/* Force buggy EIM unless eim=off */ -uint8_t aw_bits;/* Host/IOVA address width (in bits) */ +uint8_t aw_bits;/* IOVA address width (in bits) */ +uint8_t haw_bits;/* Hardware address width (in bits) */ /* * Protects IOMMU states in general. Currently it protects the
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH v1 1/3] intel-iommu: differentiate host address width from IOVA address width.
Quoted 10 lines · Yu Zhang
Currently, vIOMMU is using the value of IOVA address width, instead of the host address width(HAW) to calculate the number of reserved bits in data structures such as root entries, context entries, and entries of DMA paging structures etc.
However values of IOVA address width and of the HAW may not equal. For example, a 48-bit IOVA can only be mapped to host addresses no wider than 46 bits. Using 48, instead of 46 to calculate the reserved bit may result in an invalid IOVA being accepted.
Quoted 4 lines
To fix this, a new field -
haw_bitsis introduced in struct IntelIOMMUState, whose value is initialized based on the maximum physical address set to guest CPU. Also, definitions such as VTD_HOST_AW_39/48BIT etc. are renamed to clarify.
IIRC I raised this question some time ago somewhere but no one remembered to follow that up. Thanks for fixing it.
It looks mostly good to me, only one tiny comment below...
[...]
hw/i386/intel_iommu.c static int vtd_page_walk_level(dma_addr_t addr, uint64_t start, · line 890
Quoted 5 lines
hw/i386/intel_iommu.c +1
-0@@ -887,6 +887,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start,uint64_t iova = start;uint64_t iova_next;int ret =0 ; +uint8_t haw = info->as->iommu_state->haw_bits;
For now vtd_page_walk_info->aw_bits caches the GAW information and we use a single vtd_page_walk_info during one page walk, maybe we can also do the same for HAW instead of fetching it every time here from info->as->iommu_state->haw_bits?
Regards,
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [PATCH v1 1/3] intel-iommu: differentiate host address width from IOVA address width.
Quoted 23 lines · Peter Xu
Quoted 10 lines · Yu Zhang
Currently, vIOMMU is using the value of IOVA address width, instead of the host address width(HAW) to calculate the number of reserved bits in data structures such as root entries, context entries, and entries of DMA paging structures etc.
However values of IOVA address width and of the HAW may not equal. For example, a 48-bit IOVA can only be mapped to host addresses no wider than 46 bits. Using 48, instead of 46 to calculate the reserved bit may result in an invalid IOVA being accepted.
Quoted 4 lines
To fix this, a new field -
haw_bitsis introduced in struct IntelIOMMUState, whose value is initialized based on the maximum physical address set to guest CPU. Also, definitions such as VTD_HOST_AW_39/48BIT etc. are renamed to clarify.IIRC I raised this question some time ago somewhere but no one remembered to follow that up. Thanks for fixing it.
It looks mostly good to me, only one tiny comment below...
[...]
Quoted 10 lines
hw/i386/intel_iommu.c static int vtd_page_walk_level(dma_addr_t addr, uint64_t start, · line 890
Quoted 5 lines
hw/i386/intel_iommu.c +1
-0@@ -887,6 +887,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start,uint64_t iova = start;uint64_t iova_next;int ret =0 ; +uint8_t haw = info->as->iommu_state->haw_bits;For now
vtd_page_walk_info->aw_bitscaches the GAW information and we use a singlevtd_page_walk_infoduring one page walk, maybe we can also do the same for HAW instead of fetching it every time here frominfo->as->iommu_state->haw_bits?
Thank you, Peter. And yes, using haw_bits in vtd_page_walk_info is better. :)
Quoted 6 lines
Regards,
Signature · 1 line
Peter Xu
B.R.
Yu
PATCH 2/3 intel-iommu: extend VTD emulation to allow 57-bit IOVA address width.
In reply to Yu ZhangA 5-level paging capable VM may choose to use 57-bit IOVA address width. E.g. guest applications like DPDK prefer to use its VA as IOVA when performing VFIO map/unmap operations, to avoid the burden of managing the IOVA space.
This patch extends the current vIOMMU logic to cover the extended address width. When creating a VM with 5-level paging feature, one can choose to create a virtual VTD with 5-level paging capability, with configurations like "-device intel-iommu,x-aw-bits=57".
---
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Xu <[email protected]>
--- hw/i386/intel_iommu.c | 54 ++++++++++++++++++++++++++++++++---------- hw/i386/intel_iommu_internal.h | 6 +++++ include/hw/i386/intel_iommu.h | 1 + 3 files changed, 49 insertions(+), 12 deletions(-)
hw/i386/intel_iommu.c +42 -12
@@ -664,16 +664,16 @@ static inline bool vtd_iova_range_check(uint64_t iova, VTDContextEntry *ce,/* * Rsvd field masks for spte: -* Index [1] to [4] 4k pages -* Index [5] to [8] large pages +* Index [1] to [5] 4k pages +* Index [6] to [10] large pages */ -static uint64_t vtd_paging_entry_rsvd_field[9 ]; +static uint64_t vtd_paging_entry_rsvd_field[11 ];static bool vtd_slpte_nonzero_rsvd (uint64_t slpte,uint32_t level) {if (slpte &VTD_SL_PT_PAGE_SIZE_MASK ) {/* Maybe large page */ -return slpte & vtd_paging_entry_rsvd_field[level +4 ]; +return slpte & vtd_paging_entry_rsvd_field[level +5 ]; }else {return slpte & vtd_paging_entry_rsvd_field[level]; }
@@ -3125,6 +3125,9 @@ static void vtd_init(IntelIOMMUState *s)if (s->aw_bits ==VTD_AW_48BIT ) { s->cap |= VTD_CAP_SAGAW_48bit; } +else if (s->aw_bits ==VTD_AW_57BIT ) { + s->cap |= VTD_CAP_SAGAW_57bit | VTD_CAP_SAGAW_48bit; + } s->ecap =VTD_ECAP_QI |VTD_ECAP_IRO ; s->haw_bits = cpu->phys_bits;
@@ -3136,10 +3139,12 @@ static void vtd_init(IntelIOMMUState *s) vtd_paging_entry_rsvd_field[2 ] =VTD_SPTE_PAGE_L2_RSVD_MASK (s->haw_bits); vtd_paging_entry_rsvd_field[3 ] =VTD_SPTE_PAGE_L3_RSVD_MASK (s->haw_bits); vtd_paging_entry_rsvd_field[4 ] =VTD_SPTE_PAGE_L4_RSVD_MASK (s->haw_bits); - vtd_paging_entry_rsvd_field[5 ] =VTD_SPTE_LPAGE_L1_RSVD_MASK (s->haw_bits); - vtd_paging_entry_rsvd_field[6 ] =VTD_SPTE_LPAGE_L2_RSVD_MASK (s->haw_bits); - vtd_paging_entry_rsvd_field[7 ] =VTD_SPTE_LPAGE_L3_RSVD_MASK (s->haw_bits); - vtd_paging_entry_rsvd_field[8 ] =VTD_SPTE_LPAGE_L4_RSVD_MASK (s->haw_bits); + vtd_paging_entry_rsvd_field[5 ] =VTD_SPTE_PAGE_L5_RSVD_MASK (s->haw_bits); + vtd_paging_entry_rsvd_field[6 ] =VTD_SPTE_LPAGE_L1_RSVD_MASK (s->haw_bits); + vtd_paging_entry_rsvd_field[7 ] =VTD_SPTE_LPAGE_L2_RSVD_MASK (s->haw_bits); + vtd_paging_entry_rsvd_field[8 ] =VTD_SPTE_LPAGE_L3_RSVD_MASK (s->haw_bits); + vtd_paging_entry_rsvd_field[9 ] =VTD_SPTE_LPAGE_L4_RSVD_MASK (s->haw_bits); + vtd_paging_entry_rsvd_field[10 ] =VTD_SPTE_LPAGE_L5_RSVD_MASK (s->haw_bits);if (x86_iommu->intr_supported) { s->ecap |=VTD_ECAP_IR |VTD_ECAP_MHMV ;
@@ -3238,6 +3243,23 @@ static AddressSpace *vtd_host_dma_iommu(PCIBus *bus, void *opaque, int devfn)return &vtd_as->as; } +static bool host_has_la57 (void ) +{ +uint32_t ecx, unused; + +host_cpuid (7 ,0 , &unused, &unused, &ecx, &unused); +return ecx &CPUID_7_0_ECX_LA57 ; +} + +static bool guest_has_la57 (void ) +{ +CPUState *cs = first_cpu; +X86CPU *cpu =X86_CPU (cs); +CPUX86State *env = &cpu->env; + +return env->features[FEAT_7_0_ECX ] &CPUID_7_0_ECX_LA57 ; +} +static bool vtd_decide_config (IntelIOMMUState *s,Error **errp) {X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (s);
@@ -3264,11 +3286,19 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) } } -/* Currently only address widths supported are 39 and 48 bits */ +/* Currently address widths supported are 39, 48, and 57 bits */ if ((s->aw_bits !=VTD_AW_39BIT ) && - (s->aw_bits !=VTD_AW_48BIT )) { -error_setg (errp,"Supported values for x-aw-bits are: %d, %d" , -VTD_AW_39BIT ,VTD_AW_48BIT ); + (s->aw_bits !=VTD_AW_48BIT ) && + (s->aw_bits !=VTD_AW_57BIT )) { +error_setg (errp,"Supported values for x-aw-bits are: %d, %d, %d" , +VTD_AW_39BIT ,VTD_AW_48BIT ,VTD_AW_57BIT ); +return false; + } + +if ((s->aw_bits ==VTD_AW_57BIT ) && + !(host_has_la57 () &&guest_has_la57 ())) { +error_setg (errp,"Do not support 57-bit DMA address, unless both " +"host and guest are capable of 5-level paging.\n" );return false; }
hw/i386/intel_iommu_internal.h +6 -0
@@ -212,6 +212,8 @@#define VTD_CAP_SAGAW_39bit (0x2ULL << VTD_CAP_SAGAW_SHIFT)/* 48-bit AGAW, 4-level page-table */ #define VTD_CAP_SAGAW_48bit (0x4ULL << VTD_CAP_SAGAW_SHIFT) +/* 57-bit AGAW, 5-level page-table */ +#define VTD_CAP_SAGAW_57bit (0x8ULL << VTD_CAP_SAGAW_SHIFT)/* IQT_REG */ #define VTD_IQT_QT (val) (((val) >> 4) & 0x7fffULL)
@@ -379,6 +381,8 @@ typedef union VTDInvDesc VTDInvDesc; (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM))#define VTD_SPTE_PAGE_L4_RSVD_MASK (aw) \ (0x880ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) +#define VTD_SPTE_PAGE_L5_RSVD_MASK (aw) \ + (0x880ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM))#define VTD_SPTE_LPAGE_L1_RSVD_MASK (aw) \ (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM))#define VTD_SPTE_LPAGE_L2_RSVD_MASK (aw) \
@@ -387,6 +391,8 @@ typedef union VTDInvDesc VTDInvDesc; (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM))#define VTD_SPTE_LPAGE_L4_RSVD_MASK (aw) \ (0x880ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) +#define VTD_SPTE_LPAGE_L5_RSVD_MASK (aw) \ + (0x880ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM))/* Information about page-selective IOTLB invalidate */ struct VTDIOTLBPageInvInfo {
include/hw/i386/intel_iommu.h +1 -0
@@ -49,6 +49,7 @@#define DMAR_REG_SIZE 0x230#define VTD_AW_39BIT 39#define VTD_AW_48BIT 48 +#define VTD_AW_57BIT 57#define VTD_ADDRESS_WIDTH VTD_AW_39BIT#define VTD_HAW_MASK (aw) ((1ULL << (aw)) - 1)
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH v1 2/3] intel-iommu: extend VTD emulation to allow 57-bit IOVA address width.
Quoted 4 lines · Yu Zhang
A 5-level paging capable VM may choose to use 57-bit IOVA address width. E.g. guest applications like DPDK prefer to use its VA as IOVA when performing VFIO map/unmap operations, to avoid the burden of managing the IOVA space.
Since you mentioned about DPDK... I'm just curious that whether have you tested the patchset with the 57bit-enabled machines with DPDK VA mode running in the guest? That would be something nice to mention in the cover letter if you have.
[...]
Quoted 11 lines
hw/i386/intel_iommu.c +2
-4@@ -3264,11 +3286,19 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) } } -/* Currently only address widths supported are 39 and 48 bits */ +/* Currently address widths supported are 39, 48, and 57 bits */ if ((s->aw_bits != VTD_AW_39BIT) && - (s->aw_bits !=VTD_AW_48BIT )) { -error_setg (errp,"Supported values for x-aw-bits are: %d, %d" , -VTD_AW_39BIT ,VTD_AW_48BIT ); + (s->aw_bits != VTD_AW_48BIT) &&
hw/i386/intel_iommu.c static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) · line 3301
Quoted 10 lines
hw/i386/intel_iommu.c +10
-0+ (s->aw_bits != VTD_AW_57BIT)) { +error_setg (errp,"Supported values for x-aw-bits are: %d, %d, %d" , +VTD_AW_39BIT ,VTD_AW_48BIT ,VTD_AW_57BIT ); +return false; + } + +if ((s->aw_bits ==VTD_AW_57BIT ) && + !(host_has_la57 () &&guest_has_la57 ())) { +error_setg (errp,"Do not support 57-bit DMA address, unless both " +"host and guest are capable of 5-level paging.\n" );
Is there any context (or pointer to previous discussions would work too) on explaining why we don't support some scenarios like host_paw=48,guest_paw=48,guest_gaw=57?
Thanks,
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [PATCH v1 2/3] intel-iommu: extend VTD emulation to allow 57-bit IOVA address width.
Quoted 11 lines · Peter Xu
Quoted 4 lines · Yu Zhang
A 5-level paging capable VM may choose to use 57-bit IOVA address width. E.g. guest applications like DPDK prefer to use its VA as IOVA when performing VFIO map/unmap operations, to avoid the burden of managing the IOVA space.
Since you mentioned about DPDK... I'm just curious that whether have you tested the patchset with the 57bit-enabled machines with DPDK VA mode running in the guest? That would be something nice to mention in the cover letter if you have.
Hah. Maybe I shall not mention DPDK here.
The story is that we heard the requirement, saying applications like DPDK would need 5-level paging in IOMMU side. And I was convinced after checked DPDK code, seeing it may use VA as IOVA directly. But I did not test this patch with DPDK.
Instead, I used kvm-unit-test to verify this patch series. And of course, I also did some modification to the test case. Patch for the test also sent out at https://www.spinics.net/lists/kvm/msg177425.html.
Quoted 19 lines
[...]
Quoted 17 lines
hw/i386/intel_iommu.c +8
-4@@ -3264,11 +3286,19 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) } } -/* Currently only address widths supported are 39 and 48 bits */ +/* Currently address widths supported are 39, 48, and 57 bits */ if ((s->aw_bits !=VTD_AW_39BIT ) && - (s->aw_bits !=VTD_AW_48BIT )) { -error_setg (errp,"Supported values for x-aw-bits are: %d, %d" , -VTD_AW_39BIT ,VTD_AW_48BIT ); + (s->aw_bits !=VTD_AW_48BIT ) && + (s->aw_bits !=VTD_AW_57BIT )) { +error_setg (errp,"Supported values for x-aw-bits are: %d, %d, %d" , +VTD_AW_39BIT ,VTD_AW_48BIT ,VTD_AW_57BIT ); +return false; + } +
Quoted 9 lines
hw/i386/intel_iommu.c static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) · line 3301
Quoted 4 lines
hw/i386/intel_iommu.c +4
-0+if ((s->aw_bits ==VTD_AW_57BIT ) && + !(host_has_la57 () &&guest_has_la57 ())) { +error_setg (errp,"Do not support 57-bit DMA address, unless both " +"host and guest are capable of 5-level paging.\n" );Is there any context (or pointer to previous discussions would work too) on explaining why we don't support some scenarios like host_paw=48,guest_paw=48,guest_gaw=57?
Well, above check is only to make sure both the host and the guest can use 57bit linear address, which requires 5-level paging. So I believe we do support scenarios like host_paw=48,guest_paw=48,guest_gaw=57. The guest_has_la57() means the guest can use 57-bit linear address, regardless of its physical address width.
Quoted 5 lines
Thanks,
Signature · 1 line
Peter Xu
B.R.
Yu
Re: [Qemu-devel] [PATCH v1 2/3] intel-iommu: extend VTD emulation to allow 57-bit IOVA address width.
Quoted 15 lines · Yu Zhang
Quoted 11 lines · Peter Xu
Quoted 4 lines · Yu Zhang
A 5-level paging capable VM may choose to use 57-bit IOVA address width. E.g. guest applications like DPDK prefer to use its VA as IOVA when performing VFIO map/unmap operations, to avoid the burden of managing the IOVA space.
Since you mentioned about DPDK... I'm just curious that whether have you tested the patchset with the 57bit-enabled machines with DPDK VA mode running in the guest? That would be something nice to mention in the cover letter if you have.
Hah. Maybe I shall not mention DPDK here.
Quoted 8 lines
The story is that we heard the requirement, saying applications like DPDK would need 5-level paging in IOMMU side. And I was convinced after checked DPDK code, seeing it may use VA as IOVA directly. But I did not test this patch with DPDK.
Instead, I used kvm-unit-test to verify this patch series. And of course, I also did some modification to the test case. Patch for the test also sent out at https://www.spinics.net/lists/kvm/msg177425.html.
Yeah that's perfectly fine for me. So instead maybe you can also mention the kvm-unit-test in the cover letter if you gonna repost.
Quoted 30 lines
Quoted 20 lines
[...]
Quoted 17 lines
hw/i386/intel_iommu.c +8
-4@@ -3264,11 +3286,19 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) } } -/* Currently only address widths supported are 39 and 48 bits */ +/* Currently address widths supported are 39, 48, and 57 bits */ if ((s->aw_bits !=VTD_AW_39BIT ) && - (s->aw_bits !=VTD_AW_48BIT )) { -error_setg (errp,"Supported values for x-aw-bits are: %d, %d" , -VTD_AW_39BIT ,VTD_AW_48BIT ); + (s->aw_bits !=VTD_AW_48BIT ) && + (s->aw_bits !=VTD_AW_57BIT )) { +error_setg (errp,"Supported values for x-aw-bits are: %d, %d, %d" , +VTD_AW_39BIT ,VTD_AW_48BIT ,VTD_AW_57BIT ); +return false; + } +Quoted 9 lines
hw/i386/intel_iommu.c static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) · line 3301
Quoted 4 lines
hw/i386/intel_iommu.c +4
-0+if ((s->aw_bits ==VTD_AW_57BIT ) && + !(host_has_la57 () &&guest_has_la57 ())) { +error_setg (errp,"Do not support 57-bit DMA address, unless both " +"host and guest are capable of 5-level paging.\n" );Is there any context (or pointer to previous discussions would work too) on explaining why we don't support some scenarios like host_paw=48,guest_paw=48,guest_gaw=57?
Quoted 5 lines
Well, above check is only to make sure both the host and the guest can use 57bit linear address, which requires 5-level paging. So I believe we do support scenarios like host_paw=48,guest_paw=48,guest_gaw=57. The
guest_has_la57()means the guest can use 57-bit linear address, regardless of its physical address width.
Sorry for my incorrect wording. I mean when host/guest CPU only support 4-level LA then would/should we allow the guest IOMMU to support 5-level IOVA? Asked since I'm thinking whether I can run the series a bit with my laptop/servers.
Since at it, another thing I thought about is making sure the IOMMU capabilities will match between host and guest IOMMU, which I think this series has ignorred so far. E.g., when we're having assigned devices in the guest and with 5-level IOVA, we should make sure the host IOMMU supports 5-level as well before the guest starts since otherwise the shadow page synchronization could potentially fail when the requested IOVA address goes beyond 4-level. One simple solution is just to disable device assignment for now when we're with 57bits vIOMMU but I'm not sure whether that's what you want, especially you mentioned the DPDK case (who may use assigned devices).
(sorry to have mentioned the dpdk case again :)
Regards,
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [PATCH v1 2/3] intel-iommu: extend VTD emulation to allow 57-bit IOVA address width.
Quoted 68 lines · Peter Xu
Quoted 15 lines · Yu Zhang
Quoted 11 lines · Peter Xu
Quoted 4 lines · Yu Zhang
A 5-level paging capable VM may choose to use 57-bit IOVA address width. E.g. guest applications like DPDK prefer to use its VA as IOVA when performing VFIO map/unmap operations, to avoid the burden of managing the IOVA space.
Since you mentioned about DPDK... I'm just curious that whether have you tested the patchset with the 57bit-enabled machines with DPDK VA mode running in the guest? That would be something nice to mention in the cover letter if you have.
Hah. Maybe I shall not mention DPDK here.
Quoted 8 lines
The story is that we heard the requirement, saying applications like DPDK would need 5-level paging in IOMMU side. And I was convinced after checked DPDK code, seeing it may use VA as IOVA directly. But I did not test this patch with DPDK.
Instead, I used kvm-unit-test to verify this patch series. And of course, I also did some modification to the test case. Patch for the test also sent out at https://www.spinics.net/lists/kvm/msg177425.html.
Yeah that's perfectly fine for me. So instead maybe you can also mention the kvm-unit-test in the cover letter if you gonna repost.
Quoted 30 lines
Quoted 20 lines
[...]
Quoted 17 lines
hw/i386/intel_iommu.c +8
-4@@ -3264,11 +3286,19 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) } } -/* Currently only address widths supported are 39 and 48 bits */ +/* Currently address widths supported are 39, 48, and 57 bits */ if ((s->aw_bits !=VTD_AW_39BIT ) && - (s->aw_bits !=VTD_AW_48BIT )) { -error_setg (errp,"Supported values for x-aw-bits are: %d, %d" , -VTD_AW_39BIT ,VTD_AW_48BIT ); + (s->aw_bits !=VTD_AW_48BIT ) && + (s->aw_bits !=VTD_AW_57BIT )) { +error_setg (errp,"Supported values for x-aw-bits are: %d, %d, %d" , +VTD_AW_39BIT ,VTD_AW_48BIT ,VTD_AW_57BIT ); +return false; + } +Quoted 9 lines
hw/i386/intel_iommu.c static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) · line 3301
Quoted 4 lines
hw/i386/intel_iommu.c +4
-0+if ((s->aw_bits ==VTD_AW_57BIT ) && + !(host_has_la57 () &&guest_has_la57 ())) { +error_setg (errp,"Do not support 57-bit DMA address, unless both " +"host and guest are capable of 5-level paging.\n" );Is there any context (or pointer to previous discussions would work too) on explaining why we don't support some scenarios like host_paw=48,guest_paw=48,guest_gaw=57?
Quoted 5 lines
Well, above check is only to make sure both the host and the guest can use 57bit linear address, which requires 5-level paging. So I believe we do support scenarios like host_paw=48,guest_paw=48,guest_gaw=57. The
guest_has_la57()means the guest can use 57-bit linear address, regardless of its physical address width.Sorry for my incorrect wording. I mean when host/guest CPU only support 4-level LA then would/should we allow the guest IOMMU to support 5-level IOVA? Asked since I'm thinking whether I can run the series a bit with my laptop/servers.
[...]
Quoted 11 lines
Since at it, another thing I thought about is making sure the IOMMU capabilities will match between host and guest IOMMU, which I think this series has ignorred so far. E.g., when we're having assigned devices in the guest and with 5-level IOVA, we should make sure the host IOMMU supports 5-level as well before the guest starts since otherwise the shadow page synchronization could potentially fail when the requested IOVA address goes beyond 4-level. One simple solution is just to disable device assignment for now when we're with 57bits vIOMMU but I'm not sure whether that's what you want, especially you mentioned the DPDK case (who may use assigned devices).
Ok I totally forgot that we don't even support any kind of check like this before... So feel free to skip this comment if you want, or it would be even nicer if you want to fix it as a whole. :)
Regards,
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [PATCH v1 2/3] intel-iommu: extend VTD emulation to allow 57-bit IOVA address width.
Quoted 84 lines · Peter Xu
Quoted 68 lines · Peter Xu
Quoted 15 lines · Yu Zhang
Quoted 11 lines · Peter Xu
Quoted 4 lines · Yu Zhang
A 5-level paging capable VM may choose to use 57-bit IOVA address width. E.g. guest applications like DPDK prefer to use its VA as IOVA when performing VFIO map/unmap operations, to avoid the burden of managing the IOVA space.
Since you mentioned about DPDK... I'm just curious that whether have you tested the patchset with the 57bit-enabled machines with DPDK VA mode running in the guest? That would be something nice to mention in the cover letter if you have.
Hah. Maybe I shall not mention DPDK here.
Quoted 8 lines
The story is that we heard the requirement, saying applications like DPDK would need 5-level paging in IOMMU side. And I was convinced after checked DPDK code, seeing it may use VA as IOVA directly. But I did not test this patch with DPDK.
Instead, I used kvm-unit-test to verify this patch series. And of course, I also did some modification to the test case. Patch for the test also sent out at https://www.spinics.net/lists/kvm/msg177425.html.
Yeah that's perfectly fine for me. So instead maybe you can also mention the kvm-unit-test in the cover letter if you gonna repost.
Quoted 30 lines
Quoted 20 lines
[...]
Quoted 17 lines
hw/i386/intel_iommu.c +8
-4@@ -3264,11 +3286,19 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) } } -/* Currently only address widths supported are 39 and 48 bits */ +/* Currently address widths supported are 39, 48, and 57 bits */ if ((s->aw_bits !=VTD_AW_39BIT ) && - (s->aw_bits !=VTD_AW_48BIT )) { -error_setg (errp,"Supported values for x-aw-bits are: %d, %d" , -VTD_AW_39BIT ,VTD_AW_48BIT ); + (s->aw_bits !=VTD_AW_48BIT ) && + (s->aw_bits !=VTD_AW_57BIT )) { +error_setg (errp,"Supported values for x-aw-bits are: %d, %d, %d" , +VTD_AW_39BIT ,VTD_AW_48BIT ,VTD_AW_57BIT ); +return false; + } +Quoted 9 lines
hw/i386/intel_iommu.c static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) · line 3301
Quoted 4 lines
hw/i386/intel_iommu.c +4
-0+if ((s->aw_bits ==VTD_AW_57BIT ) && + !(host_has_la57 () &&guest_has_la57 ())) { +error_setg (errp,"Do not support 57-bit DMA address, unless both " +"host and guest are capable of 5-level paging.\n" );Is there any context (or pointer to previous discussions would work too) on explaining why we don't support some scenarios like host_paw=48,guest_paw=48,guest_gaw=57?
Quoted 5 lines
Well, above check is only to make sure both the host and the guest can use 57bit linear address, which requires 5-level paging. So I believe we do support scenarios like host_paw=48,guest_paw=48,guest_gaw=57. The
guest_has_la57()means the guest can use 57-bit linear address, regardless of its physical address width.Sorry for my incorrect wording. I mean when host/guest CPU only support 4-level LA then would/should we allow the guest IOMMU to support 5-level IOVA? Asked since I'm thinking whether I can run the series a bit with my laptop/servers.
[...]
Quoted 11 lines
Since at it, another thing I thought about is making sure the IOMMU capabilities will match between host and guest IOMMU, which I think this series has ignorred so far. E.g., when we're having assigned devices in the guest and with 5-level IOVA, we should make sure the host IOMMU supports 5-level as well before the guest starts since otherwise the shadow page synchronization could potentially fail when the requested IOVA address goes beyond 4-level. One simple solution is just to disable device assignment for now when we're with 57bits vIOMMU but I'm not sure whether that's what you want, especially you mentioned the DPDK case (who may use assigned devices).
Quoted 4 lines
Ok I totally forgot that we don't even support any kind of check like this before... So feel free to skip this comment if you want, or it would be even nicer if you want to fix it as a whole. :)
Indeed. We have talked about this before. How about we focus on the 5-level extension for now, and solve the check issue in the future? I still do not have any clean solutions in mind. BTW, any suggestions on this issue? :)
Quoted 5 lines
Regards,
Signature · 1 line
Peter Xu
B.R.
Yu
Re: [Qemu-devel] [PATCH v1 2/3] intel-iommu: extend VTD emulation to allow 57-bit IOVA address width.
On Tue, Nov 13, 2018 at 01:45:44PM +0800, Yu Zhang wrote:
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Since at it, another thing I thought about is making sure the IOMMU capabilities will match between host and guest IOMMU, which I think this series has ignorred so far. E.g., when we're having assigned devices in the guest and with 5-level IOVA, we should make sure the host IOMMU supports 5-level as well before the guest starts since otherwise the shadow page synchronization could potentially fail when the requested IOVA address goes beyond 4-level. One simple solution is just to disable device assignment for now when we're with 57bits vIOMMU but I'm not sure whether that's what you want, especially you mentioned the DPDK case (who may use assigned devices).
Quoted 8 lines
Quoted 4 lines
Ok I totally forgot that we don't even support any kind of check like this before... So feel free to skip this comment if you want, or it would be even nicer if you want to fix it as a whole. :)
Indeed. We have talked about this before. How about we focus on the 5-level extension for now, and solve the check issue in the future? I still do not have any clean solutions in mind. BTW, any suggestions on this issue? :)
I started to remember our discussions, sorry I should remember them earlier... :)
The only thing in my mind (I think I also suggested the same thing during that discussion, but I don't trust my memory any more...) is to use sysfs. Say:
1. Scan /sys/class/iommu/dmarN for all the host IOMMUs, read cap of each IOMMU from /sys/class/iommu/dmar0/intel-iommu/cap,
2. For each host iommu, scan /sys/class/iommu/dmarN/devices for all the devices under each host IOMMU, then we can know which IOMMU owns which device,
3. For each assigned device to the guest, we lookup the previous information to know the mgaw for each host device, raise error and stop QEMU from booting if any of the host device has less level supported than the guest vIOMMU (possibly some more checks in vtd_iommu_notify_flag_changed)
(we still have some issue on vtd_iommu_notify_flag_changed since it's
only run until the first enablement of vIOMMU, so we'll only raise the error during guest Linux boots with vIOMMU on. But that's another issue)
Regards,
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [PATCH v1 2/3] intel-iommu: extend VTD emulation to allow 57-bit IOVA address width.
Quoted 44 lines · Peter Xu
On Tue, Nov 13, 2018 at 01:45:44PM +0800, Yu Zhang wrote:
[...]
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Since at it, another thing I thought about is making sure the IOMMU capabilities will match between host and guest IOMMU, which I think this series has ignorred so far. E.g., when we're having assigned devices in the guest and with 5-level IOVA, we should make sure the host IOMMU supports 5-level as well before the guest starts since otherwise the shadow page synchronization could potentially fail when the requested IOVA address goes beyond 4-level. One simple solution is just to disable device assignment for now when we're with 57bits vIOMMU but I'm not sure whether that's what you want, especially you mentioned the DPDK case (who may use assigned devices).
Quoted 8 lines
Quoted 4 lines
Ok I totally forgot that we don't even support any kind of check like this before... So feel free to skip this comment if you want, or it would be even nicer if you want to fix it as a whole. :)
Indeed. We have talked about this before. How about we focus on the 5-level extension for now, and solve the check issue in the future? I still do not have any clean solutions in mind. BTW, any suggestions on this issue? :)
I started to remember our discussions, sorry I should remember them earlier... :)
The only thing in my mind (I think I also suggested the same thing during that discussion, but I don't trust my memory any more...) is to use sysfs. Say:
1. Scan
/sys/class/iommu/dmarNfor all the host IOMMUs, read cap of each IOMMU from/sys/class/iommu/dmar0/intel-iommu/cap,2. For each host iommu, scan
/sys/class/iommu/dmarN/devicesfor all the devices under each host IOMMU, then we can know which IOMMU owns which device,3. For each assigned device to the guest, we lookup the previous information to know the mgaw for each host device, raise error and stop QEMU from booting if any of the host device has less level supported than the guest vIOMMU (possibly some more checks in
vtd_iommu_notify_flag_changed)
Quoted 4 lines
(we still have some issue on
vtd_iommu_notify_flag_changedsince it's
only run until the first enablement of vIOMMU, so we'll only raise the error during guest Linux boots with vIOMMU on. But that's another issue)
Thanks for the explanation, Peter. You do have a better memory than I am.:)
Quoted 6 lines
Regards,
Signature · 1 line
Peter Xu
B.R.
Yu
Re: [Qemu-devel] [PATCH v1 2/3] intel-iommu: extend VTD emulation to allow 57-bit IOVA address width.
In reply to Peter XuQuoted 21 lines · Peter Xu
Quoted 20 lines · Yu Zhang
Quoted 11 lines · Peter Xu
Quoted 4 lines · Yu Zhang
A 5-level paging capable VM may choose to use 57-bit IOVA address width. E.g. guest applications like DPDK prefer to use its VA as IOVA when performing VFIO map/unmap operations, to avoid the burden of managing the IOVA space.
Since you mentioned about DPDK... I'm just curious that whether have you tested the patchset with the 57bit-enabled machines with DPDK VA mode running in the guest? That would be something nice to mention in the cover letter if you have.
Hah. Maybe I shall not mention DPDK here.
The story is that we heard the requirement, saying applications like DPDK would need 5-level paging in IOMMU side. And I was convinced after checked DPDK code, seeing it may use VA as IOVA directly. But I did not test this patch with DPDK.
Quoted 6 lines
Quoted 3 lines
Instead, I used kvm-unit-test to verify this patch series. And of course, I also did some modification to the test case. Patch for the test also sent out at https://www.spinics.net/lists/kvm/msg177425.html.
Yeah that's perfectly fine for me. So instead maybe you can also mention the kvm-unit-test in the cover letter if you gonna repost.
Got it. Thanks!
Quoted 37 lines
Quoted 31 lines
Quoted 21 lines
[...]
Quoted 17 lines
hw/i386/intel_iommu.c +8
-4@@ -3264,11 +3286,19 @@ static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) } } -/* Currently only address widths supported are 39 and 48 bits */ +/* Currently address widths supported are 39, 48, and 57 bits */ if ((s->aw_bits !=VTD_AW_39BIT ) && - (s->aw_bits !=VTD_AW_48BIT )) { -error_setg (errp,"Supported values for x-aw-bits are: %d, %d" , -VTD_AW_39BIT ,VTD_AW_48BIT ); + (s->aw_bits !=VTD_AW_48BIT ) && + (s->aw_bits !=VTD_AW_57BIT )) { +error_setg (errp,"Supported values for x-aw-bits are: %d, %d, %d" , +VTD_AW_39BIT ,VTD_AW_48BIT ,VTD_AW_57BIT ); +return false; + } +Quoted 9 lines
hw/i386/intel_iommu.c static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) · line 3301
Quoted 4 lines
hw/i386/intel_iommu.c +4
-0+if ((s->aw_bits ==VTD_AW_57BIT ) && + !(host_has_la57 () &&guest_has_la57 ())) { +error_setg (errp,"Do not support 57-bit DMA address, unless both " +"host and guest are capable of 5-level paging.\n" );Is there any context (or pointer to previous discussions would work too) on explaining why we don't support some scenarios like host_paw=48,guest_paw=48,guest_gaw=57?
Quoted 5 lines
Well, above check is only to make sure both the host and the guest can use 57bit linear address, which requires 5-level paging. So I believe we do support scenarios like host_paw=48,guest_paw=48,guest_gaw=57. The
guest_has_la57()means the guest can use 57-bit linear address, regardless of its physical address width.
Quoted 4 lines
Sorry for my incorrect wording. I mean when host/guest CPU only support 4-level LA then would/should we allow the guest IOMMU to support 5-level IOVA? Asked since I'm thinking whether I can run the series a bit with my laptop/servers.
Well, by "only support", I guess you mean the hardware capability, instead of its paging mode. So I do not think hardware will support 5-level IOVA for platforms without 5-level VA. Therefore a 5-level vIOMMU is disallowed here. :)
Quoted 12 lines
Since at it, another thing I thought about is making sure the IOMMU capabilities will match between host and guest IOMMU, which I think this series has ignorred so far. E.g., when we're having assigned devices in the guest and with 5-level IOVA, we should make sure the host IOMMU supports 5-level as well before the guest starts since otherwise the shadow page synchronization could potentially fail when the requested IOVA address goes beyond 4-level. One simple solution is just to disable device assignment for now when we're with 57bits vIOMMU but I'm not sure whether that's what you want, especially you mentioned the DPDK case (who may use assigned devices).
Thanks, Peter. Replied in the following up mail. :)
Quoted 7 lines
(sorry to have mentioned the dpdk case again :)
Regards,
Signature · 1 line
Peter Xu
B.R.
Yu
PATCH 3/3 intel-iommu: search iotlb for levels supported by the address width.
In reply to Yu ZhangThis patch updates vtd_lookup_iotlb() to search cached mappings only for all page levels supported by address width of current vIOMMU. Also, to cover 57-bit width, the shift of source id(VTD_IOTLB_SID_SHIFT) and of page level(VTD_IOTLB_LVL_SHIFT) are enlarged by 9 - the stride of one paging structure level.
---
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Xu <[email protected]>
--- hw/i386/intel_iommu.c | 5 +++-- hw/i386/intel_iommu_internal.h | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-)
hw/i386/intel_iommu.c +3 -2
@@ -254,11 +254,12 @@ static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level)static VTDIOTLBEntry *vtd_lookup_iotlb (IntelIOMMUState *s,uint16_t source_id,hwaddr addr) { -VTDIOTLBEntry *entry; +VTDIOTLBEntry *entry =NULL ;uint64_t key;int level; +int max_level = (s->aw_bits -VTD_PAGE_SHIFT_4K ) /VTD_SL_LEVEL_BITS ; -for (level =VTD_SL_PT_LEVEL ; level <VTD_SL_PML4_LEVEL ; level++) { +for (level =VTD_SL_PT_LEVEL ; level < max_level; level++) { key =vtd_get_iotlb_key (vtd_get_iotlb_gfn (addr, level), source_id, level); entry =g_hash_table_lookup (s->iotlb, &key);
hw/i386/intel_iommu_internal.h +2 -5
@@ -114,8 +114,8 @@ VTD_INTERRUPT_ADDR_FIRST + 1)/* The shift of source_id in the key of IOTLB hash table */ -#define VTD_IOTLB_SID_SHIFT 36 -#define VTD_IOTLB_LVL_SHIFT 52 +#define VTD_IOTLB_SID_SHIFT 45 +#define VTD_IOTLB_LVL_SHIFT 61#define VTD_IOTLB_MAX_SIZE 1024/* Max size of the hash table */ /* IOTLB_REG */
@@ -450,9 +450,6 @@ typedef struct VTDRootEntry VTDRootEntry;#define VTD_SL_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
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH v1 3/3] intel-iommu: search iotlb for levels supported by the address width.
Quoted 25 lines · Yu Zhang
This patch updates
vtd_lookup_iotlb()to search cached mappings only for all page levels supported by address width of current vIOMMU. Also, to cover 57-bit width, the shift of sourceid(VTD_IOTLB_SID_SHIFT)and of pagelevel(VTD_IOTLB_LVL_SHIFT)are enlarged by 9 - the stride of one paging structure level.Signed-off-by Yu Zhang <[email protected]>---
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Xu <[email protected]>--- hw/i386/intel_iommu.c | 5 +++-- hw/i386/intel_iommu_internal.h | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-)hw/i386/intel_iommu.c +0
-0@@ -254,11 +254,12 @@ static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id,
hw/i386/intel_iommu.c static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) · line 262
Quoted 10 lines
hw/i386/intel_iommu.c +3
-2hwaddr addr) { -VTDIOTLBEntry *entry; +VTDIOTLBEntry *entry =NULL ;uint64_t key;int level; +int max_level = (s->aw_bits -VTD_PAGE_SHIFT_4K ) /VTD_SL_LEVEL_BITS ; -for (level =VTD_SL_PT_LEVEL ; level <VTD_SL_PML4_LEVEL ; level++) { +for (level =VTD_SL_PT_LEVEL ; level < max_level; level++) {
My understanding of current IOTLB is that it only caches the last level of mapping, say:
- level 1: 4K page
- level 2: 2M page
- level 3: 1G page
So we don't check against level=4 even if x-aw-bits=48 is specified.
Here does it mean that we're going to have... 512G iommu huge pages?
Quoted 31 lines
hw/i386/intel_iommu.c +0
-0key =vtd_get_iotlb_key (vtd_get_iotlb_gfn (addr, level), source_id, level); entry =g_hash_table_lookup (s->iotlb, &key);hw/i386/intel_iommu_internal.h +2
-5@@ -114,8 +114,8 @@ VTD_INTERRUPT_ADDR_FIRST + 1)/* The shift of source_id in the key of IOTLB hash table */ -#define VTD_IOTLB_SID_SHIFT 36 -#define VTD_IOTLB_LVL_SHIFT 52 +#define VTD_IOTLB_SID_SHIFT 45 +#define VTD_IOTLB_LVL_SHIFT 61#define VTD_IOTLB_MAX_SIZE 1024/* Max size of the hash table */ /* IOTLB_REG */ @@ -450,9 +450,6 @@ typedef struct VTDRootEntry VTDRootEntry;#define VTD_SL_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 512Signature · 1 line
1.9.1
Regards,
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [PATCH v1 3/3] intel-iommu: search iotlb for levels supported by the address width.
Quoted 40 lines · Peter Xu
Quoted 25 lines · Yu Zhang
This patch updates
vtd_lookup_iotlb()to search cached mappings only for all page levels supported by address width of current vIOMMU. Also, to cover 57-bit width, the shift of sourceid(VTD_IOTLB_SID_SHIFT)and of pagelevel(VTD_IOTLB_LVL_SHIFT)are enlarged by 9 - the stride of one paging structure level.Signed-off-by Yu Zhang <[email protected]>---
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Xu <[email protected]>--- hw/i386/intel_iommu.c | 5 +++-- hw/i386/intel_iommu_internal.h | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-)hw/i386/intel_iommu.c +0
-0@@ -254,11 +254,12 @@ static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id,hw/i386/intel_iommu.c static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) · line 262
Quoted 10 lines
hw/i386/intel_iommu.c +3
-2hwaddr addr) { -VTDIOTLBEntry *entry; +VTDIOTLBEntry *entry =NULL ;uint64_t key;int level; +int max_level = (s->aw_bits -VTD_PAGE_SHIFT_4K ) /VTD_SL_LEVEL_BITS ; -for (level =VTD_SL_PT_LEVEL ; level <VTD_SL_PML4_LEVEL ; level++) { +for (level =VTD_SL_PT_LEVEL ; level < max_level; level++) {My understanding of current IOTLB is that it only caches the last level of mapping, say:
Quoted 8 lines
- level 1: 4K page
- level 2: 2M page
- level 3: 1G pageSo we don't check against level=4 even if x-aw-bits=48 is specified.
Here does it mean that we're going to have... 512G iommu huge pages?
No. My bad, I misunderstood this routine. And now I believe we do not need this patch. :-)
Thanks, Peter.
Quoted 28 lines
Quoted 28 lines
hw/i386/intel_iommu.c +0
-0key =vtd_get_iotlb_key (vtd_get_iotlb_gfn (addr, level), source_id, level); entry =g_hash_table_lookup (s->iotlb, &key);hw/i386/intel_iommu_internal.h +2
-5@@ -114,8 +114,8 @@ VTD_INTERRUPT_ADDR_FIRST + 1)/* The shift of source_id in the key of IOTLB hash table */ -#define VTD_IOTLB_SID_SHIFT 36 -#define VTD_IOTLB_LVL_SHIFT 52 +#define VTD_IOTLB_SID_SHIFT 45 +#define VTD_IOTLB_LVL_SHIFT 61#define VTD_IOTLB_MAX_SIZE 1024/* Max size of the hash table */ /* IOTLB_REG */ @@ -450,9 +450,6 @@ typedef struct VTDRootEntry VTDRootEntry;#define VTD_SL_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
Quoted 9 lines
Quoted 3 lines
Signature · 1 line
1.9.1Regards,
Signature · 1 line
Peter Xu
B.R.
Yu
Re: [Qemu-devel] [PATCH v1 3/3] intel-iommu: search iotlb for levels supported by the address width.
Quoted 45 lines · Yu Zhang
Quoted 44 lines · Peter Xu
Quoted 25 lines · Yu Zhang
This patch updates
vtd_lookup_iotlb()to search cached mappings only for all page levels supported by address width of current vIOMMU. Also, to cover 57-bit width, the shift of sourceid(VTD_IOTLB_SID_SHIFT)and of pagelevel(VTD_IOTLB_LVL_SHIFT)are enlarged by 9 - the stride of one paging structure level.Signed-off-by Yu Zhang <[email protected]>---
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Xu <[email protected]>--- hw/i386/intel_iommu.c | 5 +++-- hw/i386/intel_iommu_internal.h | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-)hw/i386/intel_iommu.c +0
-0@@ -254,11 +254,12 @@ static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id,hw/i386/intel_iommu.c static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) · line 262
Quoted 10 lines
hw/i386/intel_iommu.c +3
-2hwaddr addr) { -VTDIOTLBEntry *entry; +VTDIOTLBEntry *entry =NULL ;uint64_t key;int level; +int max_level = (s->aw_bits -VTD_PAGE_SHIFT_4K ) /VTD_SL_LEVEL_BITS ; -for (level =VTD_SL_PT_LEVEL ; level <VTD_SL_PML4_LEVEL ; level++) { +for (level =VTD_SL_PT_LEVEL ; level < max_level; level++) {My understanding of current IOTLB is that it only caches the last level of mapping, say:
- level 1: 4K page
- level 2: 2M page
- level 3: 1G page
Quoted 7 lines
Quoted 4 lines
So we don't check against level=4 even if x-aw-bits=48 is specified.
Here does it mean that we're going to have... 512G iommu huge pages?
No. My bad, I misunderstood this routine. And now I believe we do not need this patch. :-)
Yeah good to confirm that :-)
Regards,
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [PATCH v1 3/3] intel-iommu: search iotlb for levels supported by the address width.
Quoted 48 lines · Peter Xu
Quoted 47 lines · Yu Zhang
Quoted 46 lines · Peter Xu
Quoted 25 lines · Yu Zhang
This patch updates
vtd_lookup_iotlb()to search cached mappings only for all page levels supported by address width of current vIOMMU. Also, to cover 57-bit width, the shift of sourceid(VTD_IOTLB_SID_SHIFT)and of pagelevel(VTD_IOTLB_LVL_SHIFT)are enlarged by 9 - the stride of one paging structure level.Signed-off-by Yu Zhang <[email protected]>---
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Xu <[email protected]>--- hw/i386/intel_iommu.c | 5 +++-- hw/i386/intel_iommu_internal.h | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-)hw/i386/intel_iommu.c +0
-0@@ -254,11 +254,12 @@ static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id,hw/i386/intel_iommu.c static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) · line 262
Quoted 10 lines
hw/i386/intel_iommu.c +3
-2hwaddr addr) { -VTDIOTLBEntry *entry; +VTDIOTLBEntry *entry =NULL ;uint64_t key;int level; +int max_level = (s->aw_bits -VTD_PAGE_SHIFT_4K ) /VTD_SL_LEVEL_BITS ; -for (level =VTD_SL_PT_LEVEL ; level <VTD_SL_PML4_LEVEL ; level++) { +for (level =VTD_SL_PT_LEVEL ; level < max_level; level++) {My understanding of current IOTLB is that it only caches the last level of mapping, say:
- level 1: 4K page
- level 2: 2M page
- level 3: 1G pageSo we don't check against level=4 even if x-aw-bits=48 is specified.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Here does it mean that we're going to have... 512G iommu huge pages?
No. My bad, I misunderstood this routine. And now I believe we do not need this patch. :-)
Yeah good to confirm that :-)
Sorry, Peter. I still have question about this part. I agree we do not need to do the extra loop - therefore no need for the max_level part introduced in this patch.
But as to modification of VTD_IOTLB_SID_SHIFT/VTD_IOTLB_LVL_SHIFT, we may still need to do it due to the enlarged gfn, to search an IOTLB entry for a 4K mapping, the pfn itself could be as large as 45-bit.
Besides, currently vtd_get_iotlb_gfn() is just shifting 12 bits for all different levels, is this necessary? I mean, how about we do the shift based on current level?
static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) {
- return (addr & vtd_slpt_level_page_mask(level)) >> VTD_PAGE_SHIFT_4K; + uint32_t shift = vtd_slpt_level_shift(level); + return (addr & vtd_slpt_level_page_mask(level)) >> shift;
}
Quoted 6 lines
Regards,
Signature · 1 line
Peter Xu
B.R.
Yu
Re: [Qemu-devel] [PATCH v1 3/3] intel-iommu: search iotlb for levels supported by the address width.
Quoted 57 lines · Yu Zhang
Quoted 48 lines · Peter Xu
Quoted 47 lines · Yu Zhang
Quoted 46 lines · Peter Xu
Quoted 25 lines · Yu Zhang
This patch updates
vtd_lookup_iotlb()to search cached mappings only for all page levels supported by address width of current vIOMMU. Also, to cover 57-bit width, the shift of sourceid(VTD_IOTLB_SID_SHIFT)and of pagelevel(VTD_IOTLB_LVL_SHIFT)are enlarged by 9 - the stride of one paging structure level.Signed-off-by Yu Zhang <[email protected]>---
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Xu <[email protected]>--- hw/i386/intel_iommu.c | 5 +++-- hw/i386/intel_iommu_internal.h | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-)hw/i386/intel_iommu.c +0
-0@@ -254,11 +254,12 @@ static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id,hw/i386/intel_iommu.c static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) · line 262
Quoted 10 lines
hw/i386/intel_iommu.c +3
-2hwaddr addr) { -VTDIOTLBEntry *entry; +VTDIOTLBEntry *entry =NULL ;uint64_t key;int level; +int max_level = (s->aw_bits -VTD_PAGE_SHIFT_4K ) /VTD_SL_LEVEL_BITS ; -for (level =VTD_SL_PT_LEVEL ; level <VTD_SL_PML4_LEVEL ; level++) { +for (level =VTD_SL_PT_LEVEL ; level < max_level; level++) {My understanding of current IOTLB is that it only caches the last level of mapping, say:
- level 1: 4K page
- level 2: 2M page
- level 3: 1G pageSo we don't check against level=4 even if x-aw-bits=48 is specified.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Here does it mean that we're going to have... 512G iommu huge pages?
No. My bad, I misunderstood this routine. And now I believe we do not need this patch. :-)
Yeah good to confirm that :-)
Quoted 7 lines
Sorry, Peter. I still have question about this part. I agree we do not need to do the extra loop - therefore no need for the
max_levelpart introduced in this patch.But as to modification of VTD_IOTLB_SID_SHIFT/VTD_IOTLB_LVL_SHIFT, we may still need to do it due to the enlarged gfn, to search an IOTLB entry for a 4K mapping, the pfn itself could be as large as 45-bit.
Agreed.
Review
Quoted 11 lines
Besides, currently
vtd_get_iotlb_gfn()is just shifting 12 bits for all different levels, is this necessary? I mean, how about we do the shift based on current level?static
uint64_tvtd_get_iotlb_gfn(hwaddr addr, uint32_t level){(quoted diff) +2
-1- return (addr & vtd_slpt_level_page_mask(level)) >> VTD_PAGE_SHIFT_4K; + uint32_t shift = vtd_slpt_level_shift(level); + return (addr & vtd_slpt_level_page_mask(level)) >> shift; }
IMHO we can, but I don't see much gain from it.
If we shift, we still need to use the maximum possible bits that a PFN can hold, which is 45bits (when with 4k pages), so we can't gain anything out if it (no saved bits on iotlb key). Instead, we'll need to call more vtd_slpt_level_shift() for each vtd_get_iotlb_gfn() which even seems a bit slower.
Regards,
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [PATCH v1 3/3] intel-iommu: search iotlb for levels supported by the address width.
Quoted 62 lines · Peter Xu
Quoted 61 lines · Yu Zhang
Quoted 48 lines · Peter Xu
Quoted 47 lines · Yu Zhang
Quoted 46 lines · Peter Xu
Quoted 25 lines · Yu Zhang
This patch updates
vtd_lookup_iotlb()to search cached mappings only for all page levels supported by address width of current vIOMMU. Also, to cover 57-bit width, the shift of sourceid(VTD_IOTLB_SID_SHIFT)and of pagelevel(VTD_IOTLB_LVL_SHIFT)are enlarged by 9 - the stride of one paging structure level.Signed-off-by Yu Zhang <[email protected]>---
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Peter Xu <[email protected]>--- hw/i386/intel_iommu.c | 5 +++-- hw/i386/intel_iommu_internal.h | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-)hw/i386/intel_iommu.c +0
-0@@ -254,11 +254,12 @@ static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState *s, uint16_t source_id,hw/i386/intel_iommu.c static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) · line 262
Quoted 10 lines
hw/i386/intel_iommu.c +3
-2hwaddr addr) { -VTDIOTLBEntry *entry; +VTDIOTLBEntry *entry =NULL ;uint64_t key;int level; +int max_level = (s->aw_bits -VTD_PAGE_SHIFT_4K ) /VTD_SL_LEVEL_BITS ; -for (level =VTD_SL_PT_LEVEL ; level <VTD_SL_PML4_LEVEL ; level++) { +for (level =VTD_SL_PT_LEVEL ; level < max_level; level++) {My understanding of current IOTLB is that it only caches the last level of mapping, say:
- level 1: 4K page
- level 2: 2M page
- level 3: 1G pageSo we don't check against level=4 even if x-aw-bits=48 is specified.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Here does it mean that we're going to have... 512G iommu huge pages?
No. My bad, I misunderstood this routine. And now I believe we do not need this patch. :-)
Yeah good to confirm that :-)
Sorry, Peter. I still have question about this part. I agree we do not need to do the extra loop - therefore no need for the
max_levelpart introduced in this patch.
Quoted 5 lines
Quoted 3 lines
But as to modification of VTD_IOTLB_SID_SHIFT/VTD_IOTLB_LVL_SHIFT, we may still need to do it due to the enlarged gfn, to search an IOTLB entry for a 4K mapping, the pfn itself could be as large as 45-bit.
Agreed.
Thanks~
Quoted 13 lines
Review
Quoted 12 lines
Besides, currently
vtd_get_iotlb_gfn()is just shifting 12 bits for all different levels, is this necessary? I mean, how about we do the shift based on current level?static
uint64_tvtd_get_iotlb_gfn(hwaddr addr, uint32_t level){(quoted diff) +2
-1- return (addr & vtd_slpt_level_page_mask(level)) >> VTD_PAGE_SHIFT_4K; + uint32_t shift = vtd_slpt_level_shift(level); + return (addr & vtd_slpt_level_page_mask(level)) >> shift; }
Quoted 7 lines
IMHO we can, but I don't see much gain from it.
If we shift, we still need to use the maximum possible bits that a PFN can hold, which is 45bits (when with 4k pages), so we can't gain anything out if it (no saved bits on iotlb key). Instead, we'll need to call more
vtd_slpt_level_shift()for eachvtd_get_iotlb_gfn()which even seems a bit slower.
Yep, we still need to use 45 bits for 4K mappings. The only benifit I can think of is it's more intuitive - more aligned to the vtd spec of iotlb tags. But just like you said, I do not see any runtime gain in it. So I'm fine to drop this. :)
Quoted 6 lines
Regards,
Signature · 1 line
Peter Xu
B.R.
Yu
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH v1 0/3] intel-iommu: add support for 5-level virtual IOMMU.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'bcc712a4f8 intel-iommu: search iotlb for levels supported by the address width. b21a8d281a intel-iommu: extend VTD emulation to allow 57-bit IOVA address width. 5234b6784d intel-iommu: differentiate host address width from IOVA address width.
=== OUTPUT BEGIN ===
Checking PATCH 1/3: intel-iommu: differentiate host address width from IOVA address width....
WARNING: line over 80 characters
#48: FILE: hw/i386/intel_iommu.c:709:
+ uint64_t *slptep, uint32_t *slpte_level, bool *reads,
total: 0 errors, 1 warnings, 188 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 2/3: intel-iommu: extend VTD emulation to allow 57-bit IOVA address width....
ERROR: else should follow close brace '}'
#49: FILE: hw/i386/intel_iommu.c:3128:
}
+ else if (s->aw_bits == VTD_AW_57BIT) {
ERROR: Error messages should not contain newlines
#116: FILE: hw/i386/intel_iommu.c:3301:
+ "host and guest are capable of 5-level paging.\n");
total: 2 errors, 0 warnings, 122 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 3/3: intel-iommu: search iotlb for levels supported by the address width.... === OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Quoted 9 lines · Yu Zhang
Intel's upcoming processors will extend maximum linear address width to 57 bits, and introduce 5-level paging for CPU. Meanwhile, the platform will also extend the maximum guest address width for IOMMU to 57 bits, thus introducing the 5-level paging for 2nd level translation(See chapter 3 in Intel Virtualization Technology for Directed I/O).
This patch set extends the current logic to support a wider address width. A 5-level paging capable IOMMU(for 2nd level translation) can be rendered with configuration "device intel-iommu,x-aw-bits=57".
Along with this series, I'm not sure whether it'll be good we start to consider removing the "x-" prefix for "x-aw-bits".
Michael?
Regards,
Signature · 1 line
Peter Xu