x86/iommu: fixes to hwdom_iommu_map
cover x86/iommu: fixes to hwdom_iommu_map
Hello,
The following series contains two small fixes to hwdom_iommu_map in order to expand the forbidden ranges to cover the full Interrupt Address Range and the APIC Configuration Space.
Thanks, Roger.
Roger Pau Monne (2):
x86/iommu: avoid mapping the interrupt address range for hwdom x86/iommu: avoid mapping the APIC configuration space for hwdom
xen/drivers/passthrough/x86/iommu.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-)
Signature · 7 lines
2.20.1 (Apple Git-117) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/2 x86/iommu: avoid mapping the interrupt address range for hwdom
Current code only prevent mapping the lapic page into the guest physical memory map. Expand the range to be 0xFEEx_xxxx as described in the Intel VTd specification section 3.13 "Handling Requests to Interrupt Address Range".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.4 "MSI Interrupt Handling and MSI to HT Interrupt Conversion".
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
--- xen/drivers/passthrough/x86/iommu.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
xen/drivers/passthrough/x86/iommu.c +3 -13
@@ -226,19 +226,9 @@ static bool __hwdom_init hwdom_iommu_map(const struct domain *d,return false; } -/* -* Check that it doesn't overlap with the LAPIC -* TODO: if the guest relocates the MMIO area of the LAPIC Xen should make -* sure there's nothing in the new address that would prevent trapping. -*/ -if (has_vlapic (d) ) - { -const struct vcpu *v; - -for_each_vcpu (d, v) -if ( pfn ==PFN_DOWN (vlapic_base_address (vcpu_vlapic (v))) ) -return false; - } +/* Check that it doesn't overlap with the Interrupt Address Range. */ +if ( pfn >=0xfee00 && pfn <=0xfeeff ) +return false;/* ... or the IO-APIC */ for ( i =0 ;has_vioapic (d) && i < d->arch.hvm.nr_vioapics; i++ )if ( pfn ==PFN_DOWN (domain_vioapic (d, i)->base_address) )
Signature · 7 lines
2.20.1 (Apple Git-117) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/2] x86/iommu: avoid mapping the interrupt address range for hwdom
Quoted 4 lines · Roger Pau Monne
Current code only prevent mapping the lapic page into the guest physical memory map. Expand the range to be 0xFEEx_xxxx as described in the Intel VTd specification section 3.13 "Handling Requests to Interrupt Address Range".
Right, and it being device side accesses that are of interest here, the LAPIC address range (visible to the CPU only) shouldn't even matter. Hence after some back and forth with myself I agree that you remove the entire comment there.
Quoted 2 lines
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.4 "MSI Interrupt Handling and MSI to HT Interrupt Conversion".
Which raises the question about yet another patch to also exclude the HT range.
Quoted 2 lines
Requested-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/2] x86/iommu: avoid mapping the interrupt address range for hwdom
In reply to Roger Pau MonneQuoted 10 lines · Roger Pau Monne
Current code only prevent mapping the lapic page into the guest physical memory map. Expand the range to be 0xFEEx_xxxx as described in the Intel VTd specification section 3.13 "Handling Requests to Interrupt Address Range".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.4 "MSI Interrupt Handling and MSI to HT Interrupt Conversion".
Requested-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>
I've committed this on the basis that it shouldn't hurt, but having thought about this some more I'm not really sure I see the point:
The IOMMU special cases accesses into this range anyway, to redirect lookup to the interrupt remapping table instead of the DMA remapping one. Hence any mappings inserted into this range are simply useless, but shouldn't otherwise hurt.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/2] x86/iommu: avoid mapping the interrupt address range for hwdom
Quoted 12 lines · Jan Beulich
Quoted 10 lines · Roger Pau Monne
Current code only prevent mapping the lapic page into the guest physical memory map. Expand the range to be 0xFEEx_xxxx as described in the Intel VTd specification section 3.13 "Handling Requests to Interrupt Address Range".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.4 "MSI Interrupt Handling and MSI to HT Interrupt Conversion".
Requested-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>
Quoted 6 lines
I've committed this on the basis that it shouldn't hurt, but having thought about this some more I'm not really sure I see the point:
The IOMMU special cases accesses into this range anyway, to redirect lookup to the interrupt remapping table instead of the DMA remapping one. Hence any mappings inserted into this range are simply useless, but shouldn't otherwise hurt.
Intel SDM contains:
"Software must ensure the second-level paging-structure entries are programmed not to remap input addresses to the interrupt address range. Hardware behavior is undefined for memory requests remapped to the interrupt address range."
In section 3.13 (Handling Requests to Interrupt Address Range).
Since arch_iommu_hwdom_init/hwdom_iommu_map adds entries to both the hap and the iommu page tables (or to hap only if shared) Xen should be careful to not map this range because the iommu special cases this range, but I'm not sure what hap does.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/2] x86/iommu: avoid mapping the interrupt address range for hwdom
Quoted 34 lines
-----Original Message-----
From: Xen-devel <[email protected]> On Behalf Of Roger Pau Monné
Sent: 25 July 2019 11:54
To: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>; [email protected]
Subject: Re: [Xen-devel] [PATCH 1/2] x86/iommu: avoid mapping the interrupt address range for hwdomQuoted 12 lines · Jan Beulich
Quoted 10 lines · Roger Pau Monne
Current code only prevent mapping the lapic page into the guest physical memory map. Expand the range to be 0xFEEx_xxxx as described in the Intel VTd specification section 3.13 "Handling Requests to Interrupt Address Range".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.4 "MSI Interrupt Handling and MSI to HT Interrupt Conversion".
Requested-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>Quoted 6 lines
I've committed this on the basis that it shouldn't hurt, but having thought about this some more I'm not really sure I see the point:
The IOMMU special cases accesses into this range anyway, to redirect lookup to the interrupt remapping table instead of the DMA remapping one. Hence any mappings inserted into this range are simply useless, but shouldn't otherwise hurt.Intel SDM contains:
"Software must ensure the second-level paging-structure entries are programmed not to remap input addresses to the interrupt address range. Hardware behavior is undefined for memory requests remapped to the interrupt address range."
Quoted 6 lines
In section 3.13 (Handling Requests to Interrupt Address Range).
Since arch_iommu_hwdom_init/hwdom_iommu_map adds entries to both the hap and the iommu page tables (or to hap only if shared) Xen should be careful to not map this range because the iommu special cases this range, but I'm not sure what hap does.
Presumably such ranges should never end up in the P2M as they'd need to be trapped for emulation?
Paul
Quoted 7 lines
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 1/2] x86/iommu: avoid mapping the interrupt address range for hwdom
In reply to Roger Pau MonnéQuoted 27 lines · Roger Pau Monné
Quoted 12 lines · Jan Beulich
Quoted 10 lines · Roger Pau Monne
Current code only prevent mapping the lapic page into the guest physical memory map. Expand the range to be 0xFEEx_xxxx as described in the Intel VTd specification section 3.13 "Handling Requests to Interrupt Address Range".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.4 "MSI Interrupt Handling and MSI to HT Interrupt Conversion".
Requested-by Andrew Cooper <[email protected]>Signed-off-by Roger Pau Monné <[email protected]>Quoted 6 lines
I've committed this on the basis that it shouldn't hurt, but having thought about this some more I'm not really sure I see the point:
The IOMMU special cases accesses into this range anyway, to redirect lookup to the interrupt remapping table instead of the DMA remapping one. Hence any mappings inserted into this range are simply useless, but shouldn't otherwise hurt.Intel SDM contains:
"Software must ensure the second-level paging-structure entries are programmed not to remap input addresses to the interrupt address range. Hardware behavior is undefined for memory requests remapped to the interrupt address range."
Quoted 6 lines
In section 3.13 (Handling Requests to Interrupt Address Range).
Since arch_iommu_hwdom_init/hwdom_iommu_map adds entries to both the hap and the iommu page tables (or to hap only if shared) Xen should be careful to not map this range because the iommu special cases this range, but I'm not sure what hap does.
Hmm, in the shared-pt case this is indeed desirable in any event. I have to admit that I didn't recall that even in the non-shared case arch_iommu_hwdom_init() would fiddle with the HAP tables as well, rather than just the IOMMU ones. I don't think this should remain this way long term. Or was there a reason for this to be needed?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/2 x86/iommu: avoid mapping the APIC configuration space for hwdom
In reply to Roger Pau MonneCurrent code only prevents mapping the io-apic page into the guest physical memory map. Expand the range to be 0xFECx_xxxx as described in the Intel 3 Series Chipset Datasheet section 3.3.1 "APIC Configuration Space (FEC0_0000h–FECF_FFFFh)".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.2 "Non-SB IOAPIC Support".
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
--- xen/drivers/passthrough/x86/iommu.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
xen/drivers/passthrough/x86/iommu.c +4 -5
@@ -195,7 +195,7 @@ static bool __hwdom_init hwdom_iommu_map(const struct domain *d, unsigned long max_pfn) {mfn_t mfn =_mfn (pfn); -unsigned int i, type; +unsigned int type;/* * Set up 1:1 mapping for dom0. Default to include only conventional RAM
@@ -229,10 +229,9 @@ static bool __hwdom_init hwdom_iommu_map(const struct domain *d,/* Check that it doesn't overlap with the Interrupt Address Range. */ if ( pfn >=0xfee00 && pfn <=0xfeeff )return false; -/* ... or the IO-APIC */ -for ( i =0 ;has_vioapic (d) && i < d->arch.hvm.nr_vioapics; i++ ) -if ( pfn ==PFN_DOWN (domain_vioapic (d, i)->base_address) ) -return false; +/* ... or the APIC Configuration Space. */ +if ( pfn >=0xfec00 && pfn <=0xfecff ) +return false;/* * ... or the PCIe MCFG regions. * TODO: runtime added MMCFG regions are not checked to make sure they
Signature · 7 lines
2.20.1 (Apple Git-117) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/2] x86/iommu: avoid mapping the APIC configuration space for hwdom
Quoted 7 lines · Roger Pau Monne
Current code only prevents mapping the io-apic page into the guest physical memory map. Expand the range to be 0xFECx_xxxx as described in the Intel 3 Series Chipset Datasheet section 3.3.1 "APIC Configuration Space (FEC0_0000h–FECF_FFFFh)".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.2 "Non-SB IOAPIC Support".
But that's chipset specific. I don't think we can blindly assume this range. Just in case one small remark on the change itself as well:
xen/drivers/passthrough/x86/iommu.c static bool __hwdom_init hwdom_iommu_map(const struct domain *d, · line 234
Quoted 11 lines
xen/drivers/passthrough/x86/iommu.c +3
-4@@ -229,10 +229,9 @@ static bool __hwdom_init hwdom_iommu_map(const struct domain *d,/* Check that it doesn't overlap with the Interrupt Address Range. */ if ( pfn >=0xfee00 && pfn <=0xfeeff )return false; -/* ... or the IO-APIC */ -for ( i =0 ;has_vioapic (d) && i < d->arch.hvm.nr_vioapics; i++ ) -if ( pfn ==PFN_DOWN (domain_vioapic (d, i)->base_address) ) -return false; +/* ... or the APIC Configuration Space. */ +if ( pfn >=0xfec00 && pfn <=0xfecff ) +return false;
Despite the chipset documentation calling it just APIC, in our code I think it would be better if a connection to IO-APIC was made, to avoid ambiguity.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/2] x86/iommu: avoid mapping the APIC configuration space for hwdom
Quoted 10 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
Current code only prevents mapping the io-apic page into the guest physical memory map. Expand the range to be 0xFECx_xxxx as described in the Intel 3 Series Chipset Datasheet section 3.3.1 "APIC Configuration Space (FEC0_0000h–FECF_FFFFh)".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.2 "Non-SB IOAPIC Support".
But that's chipset specific. I don't think we can blindly assume this range.
The IO-APIC has always lived in that region since its introduction, and the location isn't even configurable on newer chipsets (If I've read the SAD routing rules in Skylake correctly. All that can be configured is multiple IO-APICs being mapped adjacent to each other.)
While this isn't the inbound MSI range (and definitely fixed in the architecture), it isn't plausibly going to change.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/2] x86/iommu: avoid mapping the APIC configuration space for hwdom
Quoted 9 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
Current code only prevents mapping the io-apic page into the guest physical memory map. Expand the range to be 0xFECx_xxxx as described in the Intel 3 Series Chipset Datasheet section 3.3.1 "APIC Configuration Space (FEC0_0000h–FECF_FFFFh)".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.2 "Non-SB IOAPIC Support".
Quoted 7 lines
Quoted 2 lines
But that's chipset specific. I don't think we can blindly assume this range.
The IO-APIC has always lived in that region since its introduction, and the location isn't even configurable on newer chipsets (If I've read the SAD routing rules in Skylake correctly. All that can be configured is multiple IO-APICs being mapped adjacent to each other.)
I'm pretty sure I've seen IO-APICs outside that range.
I'm not entirely opposed to a change like this, but I think it wants to come with better description (taking into account the chipset- rather than architecture-defined-ness) and either retaining of the loop the patch currently replaces, or an explanation why the loop is strictly unnecessary.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/2] x86/iommu: avoid mapping the APIC configuration space for hwdom
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
Current code only prevents mapping the io-apic page into the guest physical memory map. Expand the range to be 0xFECx_xxxx as described in the Intel 3 Series Chipset Datasheet section 3.3.1 "APIC Configuration Space (FEC0_0000h–FECF_FFFFh)".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.2 "Non-SB IOAPIC Support".
But that's chipset specific. I don't think we can blindly assume this range.
Quoted 6 lines
Quoted 4 lines
The IO-APIC has always lived in that region since its introduction, and the location isn't even configurable on newer chipsets (If I've read the SAD routing rules in Skylake correctly. All that can be configured is multiple IO-APICs being mapped adjacent to each other.)
I'm pretty sure I've seen IO-APICs outside that range.
From my AMD Fam15 system:
<7>ACPI: Local APIC address 0xfee00000
<6>IOAPIC[0]: apic_id 0, version 33, address 0xfec00000, GSI 0-23 <6>IOAPIC[1]: apic_id 1, version 33, address 0xc8000000, GSI 24-55
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/2] x86/iommu: avoid mapping the APIC configuration space for hwdom
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Jan Beulich
Quoted 16 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
Current code only prevents mapping the io-apic page into the guest physical memory map. Expand the range to be 0xFECx_xxxx as described in the Intel 3 Series Chipset Datasheet section 3.3.1 "APIC Configuration Space (FEC0_0000h–FECF_FFFFh)".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.2 "Non-SB IOAPIC Support".
But that's chipset specific. I don't think we can blindly assume this range.
The IO-APIC has always lived in that region since its introduction, and the location isn't even configurable on newer chipsets (If I've read the SAD routing rules in Skylake correctly. All that can be configured is multiple IO-APICs being mapped adjacent to each other.)
Quoted 7 lines
Quoted 1 line
I'm pretty sure I've seen IO-APICs outside that range.
From my AMD Fam15 system:
<7>ACPI: Local APIC address
0xfee00000
<6>IOAPIC[0]:apic_id0, version 33, address0xfec00000, GSI 0-23 <6>IOAPIC[1]:apic_id1, version 33, address0xc8000000, GSI 24-55
Hm, I guess the only option is to then blacklist the proposed range plus any of the pages of the io-apics on the system. I can send a new version without dropping the current io-apic blacklisting, but then I'm not sure there's much value in adding the FEC0_0000h–FECF_FFFFh range.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Xen-devel] [PATCH 2/2] x86/iommu: avoid mapping the APIC configuration space for hwdom
Quoted 28 lines · Roger Pau Monné
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Jan Beulich
Quoted 16 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monne
Current code only prevents mapping the io-apic page into the guest physical memory map. Expand the range to be 0xFECx_xxxx as described in the Intel 3 Series Chipset Datasheet section 3.3.1 "APIC Configuration Space (FEC0_0000h–FECF_FFFFh)".
AMD also lists this address range in the AMD SR5690 Databook, section 2.4.2 "Non-SB IOAPIC Support".
But that's chipset specific. I don't think we can blindly assume this range.
The IO-APIC has always lived in that region since its introduction, and the location isn't even configurable on newer chipsets (If I've read the SAD routing rules in Skylake correctly. All that can be configured is multiple IO-APICs being mapped adjacent to each other.)
Quoted 7 lines
Quoted 1 line
I'm pretty sure I've seen IO-APICs outside that range.
From my AMD Fam15 system:
<7>ACPI: Local APIC address
0xfee00000
<6>IOAPIC[0]:apic_id0, version 33, address0xfec00000, GSI 0-23 <6>IOAPIC[1]:apic_id1, version 33, address0xc8000000, GSI 24-55
Quoted 5 lines
Hm, I guess the only option is to then blacklist the proposed range plus any of the pages of the io-apics on the system. I can send a new version without dropping the current io-apic blacklisting, but then I'm not sure there's much value in adding the FEC0_0000h–FECF_FFFFh range.
Neither am I, hence my initial reaction. I'm surprised you don't see much value in there anymore - after all it's quite a bit larger an area that gets guarded against getting populated, as we're unlikely to see many systems with this space fully (or even just mostly) used by many, many IO-APICs. As said, I'd be fine acking the patch with the loop left in place, and with the description refined.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel