xen:vtd: missing RMRR mapping while share EPT
PATCH v3 1/1 xen:vtd: missing RMRR mapping while share EPT
intel_iommu_map_page() does nothing if VT-d shares EPT page table. So rmrr_identity_mapping() never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.
Here we will create those RMRR mappings even in shared EPT case.
--- xen/drivers/passthrough/vtd/iommu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
v3:
* Use set_mmio_p2m_entry() to replace p2m_set_entry()
* Use ASSERT to check
v2:
* Fix coding style.
* Still need to abide intel_iommu_map_page(), so we should do nothing if dom0 and iommu supports pass thru.
xen/drivers/passthrough/vtd/iommu.c +8 -2
@@ -1867,8 +1867,14 @@ static int rmrr_identity_mapping(struct domain *d,while ( base_pfn < end_pfn ) { -if (intel_iommu_map_page (d, base_pfn, base_pfn, - IOMMUF_readable|IOMMUF_writable) ) +if (iommu_use_hap_pt (d) ) + { +ASSERT (!iommu_passthrough || !is_hardware_domain (d)); +if (set_mmio_p2m_entry (d, base_pfn,_mfn (base_pfn)) ) +return -1 ; + } +else if (intel_iommu_map_page (d, base_pfn, base_pfn, + IOMMUF_readable|IOMMUF_writable) )return -1 ; base_pfn++; }
Signature · 1 line
1.9.1
Quoted 7 lines · Tiejun Chen
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.Here we will create those RMRR mappings even in shared EPT case.
Signed-off-by Tiejun Chen <[email protected]>
For the interaction with p2m code:
though I am still worried about what happens if this overwrites an existing mapping.
Tim.
Quoted 44 lines
--- xen/drivers/passthrough/vtd/iommu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)v3:
* Use
set_mmio_p2m_entry()to replacep2m_set_entry()
* Use ASSERT to checkv2:
* Fix coding style.
* Still need to abideintel_iommu_map_page(), so we should do nothing if dom0 and iommu supports pass thru.xen/drivers/passthrough/vtd/iommu.c +8
-2@@ -1867,8 +1867,14 @@ static int rmrr_identity_mapping(struct domain *d,while ( base_pfn < end_pfn ) { -if (intel_iommu_map_page (d, base_pfn, base_pfn, - IOMMUF_readable|IOMMUF_writable) ) +if (iommu_use_hap_pt (d) ) + { +ASSERT (!iommu_passthrough || !is_hardware_domain (d)); +if (set_mmio_p2m_entry (d, base_pfn,_mfn (base_pfn)) ) +return -1 ; + } +else if (intel_iommu_map_page (d, base_pfn, base_pfn, + IOMMUF_readable|IOMMUF_writable) )return -1 ; base_pfn++; }Signature · 7 lines
1.9.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 5 lines · Tim Deegan
Quoted 4 lines · Tiejun Chen
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.
Quoted 7 lines
Quoted 3 lines
Here we will create those RMRR mappings even in shared EPT case.
Signed-off-by Tiejun Chen <[email protected]>For the interaction with p2m code:
Acked-by Tim Deegn <[email protected]>
Thanks a lot.
Quoted 4 lines
though I am still worried about what happens if this overwrites an existing mapping.
As I understand RMRR should be specific. Its unlikely created for different mapping since this should be fixed in BIOS phase. And this is why that function is named as rmrr_identity_mapping().
Tiejun
Quoted 48 lines
Tim.
Quoted 44 lines
--- xen/drivers/passthrough/vtd/iommu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)v3:
* Use
set_mmio_p2m_entry()to replacep2m_set_entry()
* Use ASSERT to checkv2:
* Fix coding style.
* Still need to abideintel_iommu_map_page(), so we should do nothing if dom0 and iommu supports pass thru.xen/drivers/passthrough/vtd/iommu.c +8
-3@@ -1867,8 +1867,14 @@ static int rmrr_identity_mapping(struct domain *d,while ( base_pfn < end_pfn ) { -if (intel_iommu_map_page (d, base_pfn, base_pfn, - IOMMUF_readable|IOMMUF_writable) ) +if (iommu_use_hap_pt (d) ) + { +ASSERT (!iommu_passthrough || !is_hardware_domain (d)); +if (set_mmio_p2m_entry (d, base_pfn,_mfn (base_pfn)) ) +return -1 ; + } +else if (intel_iommu_map_page (d, base_pfn, base_pfn, + IOMMUF_readable|IOMMUF_writable) )return -1 ; base_pfn++; } --1.9.1
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 17 lines · Tiejun
Quoted 5 lines · Tim Deegan
Quoted 4 lines · Tiejun Chen
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.Quoted 7 lines
Quoted 3 lines
Here we will create those RMRR mappings even in shared EPT case.
Signed-off-by Tiejun Chen <[email protected]>For the interaction with p2m code:
Acked-by Tim Deegn <[email protected]>Thanks a lot.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
though I am still worried about what happens if this overwrites an existing mapping.
As I understand RMRR should be specific. Its unlikely created for different mapping since this should be fixed in BIOS phase. And this is why that function is named as
rmrr_identity_mapping().
But the BIOS only sets up _Xen's_ memory map. The toolstack sets up the _VM's_ memory map, and unless it can avoid the RMRRs of all devices in the system (and add them to guest E820s) it risks a clash here.
If you can hot-plug one of these devices into a running guest, then there's no way to be safe, as the guest might have been booted on another system and migrated.
So I think it would be prudent to at least try to detect a clash here and return an error.
(BTW, I think this patch can go in as-is, and the address-space clash be fixed up separately.)
Tim.
Quoted 22 lines · Tim Deegan
Quoted 21 lines · Tiejun
Quoted 5 lines · Tim Deegan
Quoted 4 lines · Tiejun Chen
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.Quoted 7 lines
Quoted 3 lines
Here we will create those RMRR mappings even in shared EPT case.
Signed-off-by Tiejun Chen <[email protected]>For the interaction with p2m code:
Acked-by Tim Deegn <[email protected]>Thanks a lot.
Quoted 4 lines
though I am still worried about what happens if this overwrites an existing mapping.
Quoted 8 lines
Quoted 3 lines
As I understand RMRR should be specific. Its unlikely created for different mapping since this should be fixed in BIOS phase. And this is why that function is named as
rmrr_identity_mapping().But the BIOS only sets up _Xen's_ memory map. The toolstack sets up the _VM's_ memory map, and unless it can avoid the RMRRs of all devices in the system (and add them to guest E820s) it risks a clash here.
RMRR seems be used barely. Here in my case, just GFX passthrough needs this since some windows GFX drivers may access those stolen memory now.
Quoted 4 lines
If you can hot-plug one of these devices into a running guest, then there's no way to be safe, as the guest might have been booted on another system and migrated.
I guess the original RMRR implementation don't consider live migration so current RMRR shouldn't support live migration, right?
So this should be anther story we need to address.
Quoted 3 lines
So I think it would be prudent to at least try to detect a clash here and return an error.
Or do you already have some better ways to do this? I'd like to code them in another thread.
Tiejun
Quoted 7 lines
(BTW, I think this patch can go in as-is, and the address-space clash be fixed up separately.)
Tim.
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 24.07.14 at 13:35, <[email protected]> wrote:
(BTW, I think this patch can go in as-is, and the address-space clash be fixed up separately.)
Not sure - I agree it shouldn't make things worse except when there is an RMRR but the device doesn't actually access it (i.e. would be fine without this patch). But I'm not sure committing half solutions is really appropriate for not really pressing issues.
Jan
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 24.07.14 at 13:51, <[email protected]> wrote:
Quoted 9 lines · Tim Deegan
Quoted 7 lines · Tiejun
Quoted 2 lines · Tim Deegan
though I am still worried about what happens if this overwrites an existing mapping.
As I understand RMRR should be specific. Its unlikely created for different mapping since this should be fixed in BIOS phase. And this is why that function is named as
rmrr_identity_mapping().
Quoted 7 lines
Quoted 4 lines
But the BIOS only sets up _Xen's_ memory map. The toolstack sets up the _VM's_ memory map, and unless it can avoid the RMRRs of all devices in the system (and add them to guest E820s) it risks a clash here.
RMRR seems be used barely. Here in my case, just GFX passthrough needs this since some windows GFX drivers may access those stolen memory now.
USB legacy emulation is another use case iirc, as seen on at least one of the systems I have here.
Furthermore an RMRR (as pointed out a couple of months ago) may be related to more than one device (at least in theory), and in such case it is insecure to assign these devices to distinct domains.
As said in an earlier reply to Tim - I think this half baked solution isn't worth checking in without the other issues with RMRRs properly taken care of.
Quoted 6 lines
Quoted 3 lines
If you can hot-plug one of these devices into a running guest, then there's no way to be safe, as the guest might have been booted on another system and migrated.
I guess the original RMRR implementation don't consider live migration so current RMRR shouldn't support live migration, right?
You didn't read Tim's reply properly: He was referring to the case where a passed through device gets hotplugged into a guest for the first time _after_ the guest was already live migrated at least once.
Jan
Quoted 6 lines
From: Chen, Tiejun
Sent: Thursday, July 24, 2014 4:00 AM
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.
this is not accurate. as long as RMRR is reported, it's always necessary to have the identity mapping there, not just needed in SOME CASES. :-)
a solution for address overlapping issue like Tim pointed. out.
Thanks
Kevin
Quoted 45 lines
Here we will create those RMRR mappings even in shared EPT case.
Signed-off-by Tiejun Chen <[email protected]>--- xen/drivers/passthrough/vtd/iommu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)v3:
* Use
set_mmio_p2m_entry()to replacep2m_set_entry()
* Use ASSERT to checkv2:
* Fix coding style.
* Still need to abideintel_iommu_map_page(), so we should do nothing if dom0 and iommu supports pass thru.xen/drivers/passthrough/vtd/iommu.c +8
-2@@ -1867,8 +1867,14 @@ static int rmrr_identity_mapping(struct domain *d,while ( base_pfn < end_pfn ) { -if (intel_iommu_map_page (d, base_pfn, base_pfn, - IOMMUF_readable|IOMMUF_writable) ) +if (iommu_use_hap_pt (d) ) + { +ASSERT (!iommu_passthrough || !is_hardware_domain (d)); +if (set_mmio_p2m_entry (d, base_pfn,_mfn (base_pfn)) ) +return -1 ; + } +else if (intel_iommu_map_page (d, base_pfn, base_pfn, + IOMMUF_readable|IOMMUF_writable) )return -1 ;base_pfn++; }--
1.9.1
Jan Beulich wrote on 2014-07-24:
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 24.07.14 at 13:35, <[email protected]> wrote:
(BTW, I think this patch can go in as-is, and the address-space clash be fixed up separately.)
Not sure - I agree it shouldn't make things worse except when there is an RMRR but the device doesn't actually access it (i.e. would be fine without this patch). But I'm not sure committing half solutions is really appropriate for not really pressing issues.
I think we are talking two issues. The address-apace clash has nothing to do with the issue this patch tries to fix. We will work out another patch to fix it as Tim suggested.
Quoted 2 lines
Jan
Best regards,
Yang
Quoted 2 lines
So I think it would be prudent to at least try to detect a clash here and return an error.
Could we check if this pte already present like this?
@@ -1870,6 +1872,16 @@ static int rmrr_identity_mapping(struct domain *d,
if ( iommu_use_hap_pt(d) )
{
ASSERT(!iommu_passthrough || !is_hardware_domain(d));
+ /* get last level pte */
+ pg_maddr = addr_to_dma_page_maddr(d, ((paddr_t)gfn << PAGE_SHIFT_4K), 0);
+ page = (struct dma_pte *)map_vtd_domain_page(pg_maddr);
+ pte = page + address_level_offset(addr, 1);
+ if ( dma_pte_present(*pte) )
+ {+ printk(XENLOG_ERR VTDPREFIX
+ "Overlapping RMRRs at %"PRIx64".\n", (paddr_t)base_gfn);
+ return -1;
+ }
if ( set_mmio_p2m_entry(d, base_pfn, _mfn(base_pfn)) )
return -1;
}Thanks
Tiejun
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 24.07.14 at 13:51, <[email protected]> wrote:
Quoted 13 lines · Tim Deegan
Quoted 7 lines · Tiejun
Quoted 2 lines · Tim Deegan
though I am still worried about what happens if this overwrites an existing mapping.
As I understand RMRR should be specific. Its unlikely created for different mapping since this should be fixed in BIOS phase. And this is why that function is named as
rmrr_identity_mapping().But the BIOS only sets up _Xen's_ memory map. The toolstack sets up the _VM's_ memory map, and unless it can avoid the RMRRs of all devices in the system (and add them to guest E820s) it risks a clash here.
Quoted 7 lines
Quoted 2 lines
RMRR seems be used barely. Here in my case, just GFX passthrough needs this since some windows GFX drivers may access those stolen memory now.
USB legacy emulation is another use case iirc, as seen on at least one of the systems I have here.
Furthermore an RMRR (as pointed out a couple of months ago)
I'm poor in this problem, so could you point where I can get this discussion? I think I should take a look at that to know about more.
Quoted 1 line
may be related to more than one device (at least in theory), and
Are you saying one RMRR corresponds to multiple devfns?
Quoted 2 lines
in such case it is insecure to assign these devices to distinct domains.
But looks we always create one RMRR when an associated devfn is assigned to one given domain, so this mean its always insecure before I introduce this patch, right?
But if I'm wrong please correct me.
Quoted 9 lines
As said in an earlier reply to Tim - I think this half baked solution isn't worth checking in without the other issues with RMRRs properly taken care of.
Quoted 4 lines
Quoted 3 lines
If you can hot-plug one of these devices into a running guest, then there's no way to be safe, as the guest might have been booted on another system and migrated.
Quoted 8 lines
Quoted 2 lines
I guess the original RMRR implementation don't consider live migration so current RMRR shouldn't support live migration, right?
You didn't read Tim's reply properly: He was referring to the case where a passed through device gets hotplugged into a guest for the first time _after_ the guest was already live migrated at least once.
Thanks for you explanation.
Tiejun
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 25.07.14 at 02:56, <[email protected]> wrote:
Jan Beulich wrote on 2014-07-24:
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 24.07.14 at 13:35, <[email protected]> wrote:
(BTW, I think this patch can go in as-is, and the address-space clash be fixed up separately.)
Quoted 8 lines
Quoted 4 lines
Not sure - I agree it shouldn't make things worse except when there is an RMRR but the device doesn't actually access it (i.e. would be fine without this patch). But I'm not sure committing half solutions is really appropriate for not really pressing issues.
I think we are talking two issues. The address-apace clash has nothing to do with the issue this patch tries to fix. We will work out another patch to fix it as Tim suggested.
No, we aren't: This patch _introduces_ the address space clash.
Jan
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 25.07.14 at 08:48, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 24.07.14 at 13:51, <[email protected]> wrote:
RMRR seems be used barely. Here in my case, just GFX passthrough needs this since some windows GFX drivers may access those stolen memory now.
Quoted 7 lines
Quoted 4 lines
USB legacy emulation is another use case iirc, as seen on at least one of the systems I have here.
Furthermore an RMRR (as pointed out a couple of months ago)
I'm poor in this problem, so could you point where I can get this discussion? I think I should take a look at that to know about more.
http://lists.xenproject.org/archives/html/xen-devel/2014-02/msg00824.html
(continued in March; the list server doesn't properly deal with cross-month follow-ups, so you'll need to search for the same subject in
http://lists.xenproject.org/archives/html/xen-devel/2014-03/threads.html)
Quoted 3 lines
Quoted 1 line
may be related to more than one device (at least in theory), and
Are you saying one RMRR corresponds to multiple devfns?
Yes, just look at acpi_parse_one_rmrr() and its helper acpi_parse_dev_scope(): There's nothing there enforcing just a single device per RMRR.
Quoted 6 lines
Quoted 2 lines
in such case it is insecure to assign these devices to distinct domains.
But looks we always create one RMRR when an associated devfn is assigned to one given domain, so this mean its always insecure before I introduce this patch, right?
If you meant "already" instead of "always", then yes. Your patch is just widening the issue.
Jan
Quoted 31 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 25.07.14 at 08:48, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 24.07.14 at 13:51, <[email protected]> wrote:
RMRR seems be used barely. Here in my case, just GFX passthrough needs this since some windows GFX drivers may access those stolen memory now.
Quoted 7 lines
Quoted 4 lines
USB legacy emulation is another use case iirc, as seen on at least one of the systems I have here.
Furthermore an RMRR (as pointed out a couple of months ago)
I'm poor in this problem, so could you point where I can get this discussion? I think I should take a look at that to know about more.
http://lists.xenproject.org/archives/html/xen-devel/2014-02/msg00824.html
(continued in March; the list server doesn't properly deal with cross-month follow-ups, so you'll need to search for the same subject in
http://lists.xenproject.org/archives/html/xen-devel/2014-03/threads.html)Quoted 3 lines
Quoted 1 line
may be related to more than one device (at least in theory), and
Are you saying one RMRR corresponds to multiple devfns?
Yes, just look at
acpi_parse_one_rmrr()and its helperacpi_parse_dev_scope(): There's nothing there enforcing just a single device per RMRR.Quoted 3 lines
Quoted 2 lines
in such case it is insecure to assign these devices to distinct domains.
Quoted 7 lines
Quoted 3 lines
But looks we always create one RMRR when an associated devfn is assigned to one given domain, so this mean its always insecure before I introduce this patch, right?
If you meant "already" instead of "always", then yes. Your patch is just widening the issue.
Jan,
Such this kind of problem just happens in shared EPT case, right? In non-shared EPT case, we don't create these EPT tables to override other EPTs, so its okay?
Tiejun
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 25.07.14 at 09:53, <[email protected]> wrote:
Such this kind of problem just happens in shared EPT case, right? In non-shared EPT case, we don't create these EPT tables to override other EPTs, so its okay?
At least I think/hope it is okay in the non-shared case - there's still the problem of the two translation tables not being consistent with one another, but I can't currently see problems arising from that.
Jan
Quoted 13 lines
Quoted 3 lines
Quoted 1 line · On 25.07.14 at 08:47, <[email protected]> wrote:
So I think it would be prudent to at least try to detect a clash here
and return an error.Could we check if this pte already present like this?
(quoted diff) +3
-0@@ -1870,6 +1872,16 @@ static int rmrr_identity_mapping(struct domain *d, if ( iommu_use_hap_pt(d) ) { ASSERT(!iommu_passthrough || !is_hardware_domain(d)); + /* get last level pte */ + pg_maddr = addr_to_dma_page_maddr(d, ((paddr_t)gfn << PAGE_SHIFT_4K), 0); + page = (struct dma_pte *)map_vtd_domain_page(pg_maddr);
Review static int rmrr_identity_mapping(struct domain *d, · line 1887
Quoted 10 lines
(quoted diff) +7
-0+ pte = page + address_level_offset(addr, 1); + if ( dma_pte_present(*pte) ) + { + printk(XENLOG_ERR VTDPREFIX + "Overlapping RMRRs at %"PRIx64".\n", (paddr_t)base_gfn); + return -1; + } if ( set_mmio_p2m_entry(d, base_pfn, _mfn(base_pfn)) ) return -1; }
I think you'd be better off using P2M functions here, even more so considering that you're in an iommu_use_hap_pt() guarded code section.
Jan
Quoted 10 lines
Quoted 7 lines
Quoted 1 line · On 24.07.14 at 19:12, <[email protected]> wrote:
From: Chen, Tiejun
Sent: Thursday, July 24, 2014 4:00 AM
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.this is not accurate. as long as RMRR is reported, it's always necessary to have the identity mapping there, not just needed in SOME CASES. :-)
Actually (as also said before) I think "in some cases" is quite correct:
There's no guarantee that a device will actually access the region(s) an RMRR may specify for it. A particular example would be the USB case where iiuc these regions are needed only until legacy mode emulation gets turned off.
Jan
Jan Beulich wrote on 2014-07-25:
Quoted 11 lines
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 25.07.14 at 02:56, <[email protected]> wrote:
Jan Beulich wrote on 2014-07-24:
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 24.07.14 at 13:35, <[email protected]> wrote:
(BTW, I think this patch can go in as-is, and the address-space clash be fixed up separately.)
Not sure - I agree it shouldn't make things worse except when there is an RMRR but the device doesn't actually access it (i.e. would be fine without this patch). But I'm not sure committing half solutions is really appropriate for not really pressing issues.
Quoted 5 lines
Quoted 3 lines
I think we are talking two issues. The address-apace clash has nothing to do with the issue this patch tries to fix. We will work out another patch to fix it as Tim suggested.
No, we aren't: This patch _introduces_ the address space clash.
In non-sharept case, do we reserve the RMRR in e820 table? If not, the guest may use it as DMA buffer and it actually the same problem we are talking here.
Quoted 2 lines
Jan
Best regards,
Yang
Jan Beulich wrote on 2014-07-25:
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines · On 24.07.14 at 19:12, <[email protected]> wrote:
From: Chen, Tiejun
Sent: Thursday, July 24, 2014 4:00 AM
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.
Quoted 8 lines
Quoted 3 lines
this is not accurate. as long as RMRR is reported, it's always necessary to have the identity mapping there, not just needed in SOME CASES. :-)
Actually (as also said before) I think "in some cases" is quite correct:
There's no guarantee that a device will actually access the region(s) an RMRR may specify for it. A particular example would be the USB case where iiuc these regions are needed only until legacy mode emulation gets turned off.
Yes, even for Intel GFX, the RMRR is never really accessed. So we never saw any issue even without this patch.
Quoted 2 lines
Jan
Best regards,
Yang
Quoted 13 lines · Yang Z
Jan Beulich wrote on 2014-07-25:
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 2 lines · On 24.07.14 at 19:12, <[email protected]> wrote:
From: Chen, Tiejun
Sent: Thursday, July 24, 2014 4:00 AM
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.this is not accurate. as long as RMRR is reported, it's always necessary to have the identity mapping there, not just needed in SOME CASES. :-)
Quoted 7 lines
Quoted 4 lines
Actually (as also said before) I think "in some cases" is quite correct:
There's no guarantee that a device will actually access the region(s) an RMRR may specify for it. A particular example would be the USB case where iiuc these regions are needed only until legacy mode emulation gets turned off.Yes, even for Intel GFX, the RMRR is never really accessed. So we never saw any issue even without this patch.
Yang,
Windows GFX driver really accesses this range now. Without this patch, the blue screen appears.
Tiejun
Chen, Tiejun wrote on 2014-07-25:
Quoted 21 lines · Yang Z
Quoted 18 lines
Jan Beulich wrote on 2014-07-25:
Quoted 17 lines
Quoted 11 lines
Quoted 7 lines
Quoted 2 lines · On 24.07.14 at 19:12, <[email protected]> wrote:
From: Chen, Tiejun
Sent: Thursday, July 24, 2014 4:00 AM
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.this is not accurate. as long as RMRR is reported, it's always necessary to have the identity mapping there, not just needed in SOME CASES. :-)
Actually (as also said before) I think "in some cases" is quite correct:
There's no guarantee that a device will actually access the region(s) an RMRR may specify for it. A particular example would be the USB case where iiuc these regions are needed only until legacy mode emulationgets turned off.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Yes, even for Intel GFX, the RMRR is never really accessed. So we never saw any issue even without this patch.
Yang,
Windows GFX driver really accesses this range now. Without this patch, the blue screen appears.
Okay, so for Linux guest, it works well even without having RMRR mapping.
Quoted 2 lines
Tiejun
Best regards,
Yang
Quoted 26 lines · Yang Z
Chen, Tiejun wrote on 2014-07-25:
Quoted 25 lines · Yang Z
Quoted 18 lines
Jan Beulich wrote on 2014-07-25:
Quoted 17 lines
Quoted 11 lines
Quoted 7 lines
Quoted 2 lines · On 24.07.14 at 19:12, <[email protected]> wrote:
From: Chen, Tiejun
Sent: Thursday, July 24, 2014 4:00 AM
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.this is not accurate. as long as RMRR is reported, it's always necessary to have the identity mapping there, not just needed in SOME CASES. :-)
Actually (as also said before) I think "in some cases" is quite correct:
There's no guarantee that a device will actually access the region(s) an RMRR may specify for it. A particular example would be the USB case where iiuc these regions are needed only until legacy mode emulationgets turned off.
Quoted 4 lines
Yes, even for Intel GFX, the RMRR is never really accessed. So we never saw any issue even without this patch.
Quoted 7 lines
Quoted 4 lines
Yang,
Windows GFX driver really accesses this range now. Without this patch, the blue screen appears.
Okay, so for Linux guest, it works well even without having RMRR mapping.
Yes.
Tiejun
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 25.07.14 at 10:19, <[email protected]> wrote:
Jan Beulich wrote on 2014-07-25:
Quoted 15 lines
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 25.07.14 at 02:56, <[email protected]> wrote:
Jan Beulich wrote on 2014-07-24:
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 24.07.14 at 13:35, <[email protected]> wrote:
(BTW, I think this patch can go in as-is, and the address-space clash be fixed up separately.)
Not sure - I agree it shouldn't make things worse except when there is an RMRR but the device doesn't actually access it (i.e. would be fine without this patch). But I'm not sure committing half solutions is really appropriate for not really pressing issues.
I think we are talking two issues. The address-apace clash has nothing to do with the issue this patch tries to fix. We will work out another patch to fix it as Tim suggested.
Quoted 5 lines
Quoted 1 line
No, we aren't: This patch _introduces_ the address space clash.
In non-sharept case, do we reserve the RMRR in e820 table? If not, the guest may use it as DMA buffer and it actually the same problem we are talking here.
True, indeed. Yet I still consider the patch is fixing a problem at the price of making that situation worse.
Jan
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 25.07.14 at 10:24, <[email protected]> wrote:
Jan Beulich wrote on 2014-07-25:
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 2 lines · On 24.07.14 at 19:12, <[email protected]> wrote:
From: Chen, Tiejun
Sent: Thursday, July 24, 2014 4:00 AM
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.this is not accurate. as long as RMRR is reported, it's always necessary to have the identity mapping there, not just needed in SOME CASES. :-)
Quoted 8 lines
Quoted 4 lines
Actually (as also said before) I think "in some cases" is quite correct:
There's no guarantee that a device will actually access the region(s) an RMRR may specify for it. A particular example would be the USB case where iiuc these regions are needed only until legacy mode emulation getsturned off.
Yes, even for Intel GFX, the RMRR is never really accessed. So we never saw any issue even without this patch.
So then what's the patch good for? If it's just addressing a theoretical issue, then this supports my intention to commit it only when the other (theoretical only) problem also gets taken care of.
Jan
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 25.07.14 at 10:24, <[email protected]> wrote:
Jan Beulich wrote on 2014-07-25:
Quoted 16 lines
Quoted 11 lines
Quoted 7 lines
Quoted 2 lines · On 24.07.14 at 19:12, <[email protected]> wrote:
From: Chen, Tiejun
Sent: Thursday, July 24, 2014 4:00 AM
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.this is not accurate. as long as RMRR is reported, it's always necessary to have the identity mapping there, not just needed in SOME CASES. :-)
Actually (as also said before) I think "in some cases" is quite correct:
There's no guarantee that a device will actually access the region(s) an RMRR may specify for it. A particular example would be the USB case where iiuc these regions are needed only until legacy mode emulation gets
Quoted 6 lines
Quoted 4 lines
turned off.
Yes, even for Intel GFX, the RMRR is never really accessed. So we never saw any issue even without this patch.
So then what's the patch good for? If it's just addressing a theoretical
No, this is not a theoretical problem.
I already reply to Yang, on BDW windows GFX driver really accesses this range now. Without this patch, the blue screen appears.
Tiejun
Quoted 7 lines
issue, then this supports my intention to commit it only when the other (theoretical only) problem also gets taken care of.
Jan
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 3 lines
Quoted 1 line · On 25.07.14 at 08:47, <[email protected]> wrote:
So I think it would be prudent to at least try to detect a clash here
and return an error.Could we check if this pte already present like this?
(quoted diff) +9
-0@@ -1870,6 +1872,16 @@ static int rmrr_identity_mapping(struct domain *d, if ( iommu_use_hap_pt(d) ) { ASSERT(!iommu_passthrough || !is_hardware_domain(d)); + /* get last level pte */ + pg_maddr = addr_to_dma_page_maddr(d, ((paddr_t)gfn << PAGE_SHIFT_4K), 0); + page = (struct dma_pte *)map_vtd_domain_page(pg_maddr); + pte = page + address_level_offset(addr, 1); + if ( dma_pte_present(*pte) ) + { + printk(XENLOG_ERR VTDPREFIX + "Overlapping RMRRs at %"PRIx64".\n", (paddr_t)base_gfn); + return -1;
Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c static int rmrr_identity_mapping(struct domain *d, · line 1880
Quoted 4 lines
xen/drivers/passthrough/vtd/iommu.c +1
-0+ }if (set_mmio_p2m_entry (d, base_pfn,_mfn (base_pfn)) )return -1 ; }I think you'd be better off using P2M functions here, even more so considering that you're in an
iommu_use_hap_pt()guarded code section.
Are you pointing p2m->get_entry?
Thanks
Tiejun
Quoted 30 lines
Quoted 1 line
Quoted 1 line · On 25.07.14 at 10:45, <[email protected]> wrote:
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 3 lines
Quoted 1 line · On 25.07.14 at 08:47, <[email protected]> wrote:
So I think it would be prudent to at least try to detect a clash here
and return an error.Could we check if this pte already present like this?
(quoted diff) +9
-0@@ -1870,6 +1872,16 @@ static int rmrr_identity_mapping(struct domain *d, if ( iommu_use_hap_pt(d) ) { ASSERT(!iommu_passthrough || !is_hardware_domain(d)); + /* get last level pte */ + pg_maddr = addr_to_dma_page_maddr(d, ((paddr_t)gfn << PAGE_SHIFT_4K), 0); + page = (struct dma_pte *)map_vtd_domain_page(pg_maddr); + pte = page + address_level_offset(addr, 1); + if ( dma_pte_present(*pte) ) + { + printk(XENLOG_ERR VTDPREFIX + "Overlapping RMRRs at %"PRIx64".\n", (paddr_t)base_gfn); + return -1;Quoted 8 lines
Review static int rmrr_identity_mapping(struct domain *d, · line 1887
Quoted 4 lines
(quoted diff) +1
-0+ } if ( set_mmio_p2m_entry(d, base_pfn, _mfn(base_pfn)) ) return -1; }I think you'd be better off using P2M functions here, even more so considering that you're in an
iommu_use_hap_pt()guarded code section.
Quoted 1 line
Are you pointing
p2m->get_entry?
Sort of. For the check to really be meaningful the get and set would need to be done without the respective lock dropped intermediately.
Jan
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 25.07.14 at 09:53, <[email protected]> wrote:
Such this kind of problem just happens in shared EPT case, right? In non-shared EPT case, we don't create these EPT tables to override other EPTs, so its okay?
At least I think/hope it is okay in the non-shared case - there's still the problem of the two translation tables not being consistent with one another, but I can't currently see problems arising from that.
It's _not_ OK in the non-shared case: if a guest has RAM at that address and uses a passed-through device to DMA to it, the DMA will end up in the RMRR area. Add we know that this guest has at least one passed-through device. :P
Tim.
Quoted 11 lines
From: Jan Beulich [mailto:[email protected]]
Sent: Friday, July 25, 2014 1:16 AMQuoted 8 lines
Quoted 7 lines
Quoted 1 line · On 24.07.14 at 19:12, <[email protected]> wrote:
From: Chen, Tiejun
Sent: Thursday, July 24, 2014 4:00 AM
intel_iommu_map_page()does nothing if VT-d shares EPT page table. Sormrr_identity_mapping()never create RMRR mapping but in some cases like some GFX drivers it still need to access RMRR.
Quoted 9 lines
Quoted 2 lines
this is not accurate. as long as RMRR is reported, it's always necessary to have the identity mapping there, not just needed in SOME CASES. :-)
Actually (as also said before) I think "in some cases" is quite correct:
There's no guarantee that a device will actually access the region(s) an RMRR may specify for it. A particular example would be the USB case where iiuc these regions are needed only until legacy mode emulation gets turned off.
the device may or may not access RMRR, but from virtualization p.o.v as long as RMRR presents and you assign a device associated, we should ALWAYS setup RMRR mapping since we don't know how device actually work.
Thanks
Kevin