Fix grant map/unmap with auto-translated guests
cover Fix grant map/unmap with auto-translated guests
This series adds proper IOMMU entries when performing grant mapping/unmapping inside of auto-translated guests when the p2m is not shared between HAP and IOMMUs, and disables p2m sharing when running on AMD hardware.
In order for the guest to know if it's safe to use grant mapped pages for IO with hardware devices a new xen feature is introduced in the last patch.
[PATCH 1/3] iommu: set correct IOMMU entries when iommu_hap_pt_share [PATCH 2/3] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs [PATCH 3/3] xen: expose that grant table mappings update the IOMMU
PATCH 1/3 iommu: set correct IOMMU entries when iommu_hap_pt_share == 0
If the memory map is not shared between HAP and IOMMU we fails to set correct IOMMU mappings for memory types different than p2m_ram_rw.
This patchs adds IOMMU support for the following memory types:p2m_grant_map_rw, p2m_map_foreign, p2m_ram_ro and p2m_grant_map_ro.
--- xen/arch/x86/mm/p2m-ept.c | 24 +++++++++++++++++++++--- xen/arch/x86/mm/p2m-pt.c | 23 ++++++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-)
xen/arch/x86/mm/p2m-ept.c +21 -3
@@ -475,18 +475,36 @@ out:iommu_pte_flush (d, gfn, (u64 *)ept_entry, order, vtd_pte_present); else { -if ( p2mt == p2m_ram_rw ) +unsigned int flags; + +switch ( p2mt ) + { +case p2m_ram_rw: +case p2m_grant_map_rw: +case p2m_map_foreign: + flags = IOMMUF_readable | IOMMUF_writable; +break ; +case p2m_ram_ro: +case p2m_grant_map_ro: + flags = IOMMUF_readable; +break ; +default : + flags =0 ; +break ; + } + +if ( flags !=0 ) {if ( order >0 ) {for ( i =0 ; i < (1 << order); i++ )iommu_map_page ( p2m->domain, gfn - offset + i,mfn_x (mfn) - offset + i, - IOMMUF_readable | IOMMUF_writable); + flags); }else if ( !order )iommu_map_page ( - p2m->domain, gfn,mfn_x (mfn), IOMMUF_readable | IOMMUF_writable); + p2m->domain, gfn,mfn_x (mfn), flags); }else {
xen/arch/x86/mm/p2m-pt.c +20 -3
@@ -450,10 +450,27 @@ p2m_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, }else { -if ( p2mt == p2m_ram_rw ) +unsigned int flags; + +switch ( p2mt ) + { +case p2m_ram_rw: +case p2m_grant_map_rw: +case p2m_map_foreign: + flags = IOMMUF_readable | IOMMUF_writable; +break ; +case p2m_ram_ro: +case p2m_grant_map_ro: + flags = IOMMUF_readable; +break ; +default : + flags =0 ; +break ; + } + +if ( flags !=0 )for ( i =0 ; i < (1UL << page_order); i++ ) -iommu_map_page (p2m->domain, gfn+i,mfn_x (mfn)+i, - IOMMUF_readable|IOMMUF_writable); +iommu_map_page (p2m->domain, gfn+i,mfn_x (mfn)+i, flags);else for (int i =0 ; i < (1UL << page_order); i++ )iommu_unmap_page (p2m->domain, gfn+i);
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 1/3] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0
Quoted 1 line · Roger Pau Monne
If the memory map is not shared between HAP and IOMMU we fails to set
we fail
Quoted 1 line
correct IOMMU mappings for memory types different than
p2m_ram_rw.
s/different/other/
Quoted 99 lines
This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw,p2m_map_foreign,p2m_ram_roandp2m_grant_map_ro.Signed-off-by Roger Pau Monné <[email protected]>Cc Tim Deegan <[email protected]>Cc Jan Beulich <[email protected]>--- xen/arch/x86/mm/p2m-ept.c | 24 +++++++++++++++++++++--- xen/arch/x86/mm/p2m-pt.c | 23 ++++++++++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-)xen/arch/x86/mm/p2m-ept.c +21
-3@@ -475,18 +475,36 @@ out:iommu_pte_flush (d, gfn, (u64 *)ept_entry, order, vtd_pte_present); else { -if ( p2mt == p2m_ram_rw ) +unsigned int flags; + +switch ( p2mt ) + { +case p2m_ram_rw: +case p2m_grant_map_rw: +case p2m_map_foreign: + flags = IOMMUF_readable | IOMMUF_writable; +break ; +case p2m_ram_ro: +case p2m_grant_map_ro: + flags = IOMMUF_readable; +break ; +default : + flags =0 ; +break ; + } + +if ( flags !=0 ) {if ( order >0 ) {for ( i =0 ; i < (1 << order); i++ )iommu_map_page ( p2m->domain, gfn - offset + i,mfn_x (mfn) - offset + i, - IOMMUF_readable | IOMMUF_writable); + flags); }else if ( !order )iommu_map_page ( - p2m->domain, gfn,mfn_x (mfn), IOMMUF_readable | IOMMUF_writable); + p2m->domain, gfn,mfn_x (mfn), flags); }else {xen/arch/x86/mm/p2m-pt.c +20
-3@@ -450,10 +450,27 @@ p2m_set_entry(struct p2m_domain *p2m, unsigned long gfn, mfn_t mfn, }else { -if ( p2mt == p2m_ram_rw ) +unsigned int flags; + +switch ( p2mt ) + { +case p2m_ram_rw: +case p2m_grant_map_rw: +case p2m_map_foreign: + flags = IOMMUF_readable | IOMMUF_writable; +break ; +case p2m_ram_ro: +case p2m_grant_map_ro: + flags = IOMMUF_readable; +break ; +default : + flags =0 ; +break ; + } + +if ( flags !=0 )for ( i =0 ; i < (1UL << page_order); i++ ) -iommu_map_page (p2m->domain, gfn+i,mfn_x (mfn)+i, - IOMMUF_readable|IOMMUF_writable); +iommu_map_page (p2m->domain, gfn+i,mfn_x (mfn)+i, flags);else for (int i =0 ; i < (1UL << page_order); i++ )iommu_unmap_page (p2m->domain, gfn+i);Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 1/3] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0
In reply to Roger Pau MonneQuoted 6 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
If the memory map is not shared between HAP and IOMMU we fails to set correct IOMMU mappings for memory types different than
p2m_ram_rw.This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw,p2m_map_foreign,p2m_ram_roandp2m_grant_map_ro.
I'm curious about the justification for p2m_map_foreign; the others I agree with.
I also wonder whether p2m_ram_logdirty shouldn't be treated equally to p2m_ram_rw: It's clearly better to have some video corruption than to kill the guest due to excessive IOMMU faults, should its kernel choose to DMA into the frame buffer. But at the very minimum this needs to be included alongside p2m_ram_ro.
Jan
Re: [PATCH 1/3] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0
Quoted 9 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
If the memory map is not shared between HAP and IOMMU we fails to set correct IOMMU mappings for memory types different than
p2m_ram_rw.This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw,p2m_map_foreign,p2m_ram_roandp2m_grant_map_ro.I'm curious about the justification for
p2m_map_foreign; the others I agree with.
Thanks for the review, I didn't see a reason to not allow DMA transfers to/from foreign pages, although there's no user of foreign pages that use DMA.
Quoted 6 lines
I also wonder whether
p2m_ram_logdirtyshouldn't be treated equally top2m_ram_rw: It's clearly better to have some video corruption than to kill the guest due to excessive IOMMU faults, should its kernel choose to DMA into the frame buffer. But at the very minimum this needs to be included alongsidep2m_ram_ro.
Ack. I wasn't sure about p2m_ram_logdirty, so I just decided to not include it. I will add it to my next revision as a RW zone if that's fine.
Roger.
Re: [PATCH 1/3] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 11:19, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
If the memory map is not shared between HAP and IOMMU we fails to set correct IOMMU mappings for memory types different than
p2m_ram_rw.This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw,p2m_map_foreign,p2m_ram_roandp2m_grant_map_ro.
Quoted 6 lines
Quoted 2 lines
I'm curious about the justification for
p2m_map_foreign; the others I agree with.Thanks for the review, I didn't see a reason to not allow DMA transfers to/from foreign pages, although there's no user of foreign pages that use DMA.
They're rather special (tool stack maps of guest pages), and DMAing into/out of them shouldn't normally be done. I'd clearly suggest leaving them unmapped for now.
Quoted 8 lines
Quoted 5 lines
I also wonder whether
p2m_ram_logdirtyshouldn't be treated equally top2m_ram_rw: It's clearly better to have some video corruption than to kill the guest due to excessive IOMMU faults, should its kernel choose to DMA into the frame buffer. But at the very minimum this needs to be included alongsidep2m_ram_ro.Ack. I wasn't sure about
p2m_ram_logdirty, so I just decided to not include it. I will add it to my next revision as a RW zone if that's fine.
Yes please, subject to Tim saying otherwise.
Jan
Re: [PATCH 1/3] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0
In reply to Jan BeulichQuoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
If the memory map is not shared between HAP and IOMMU we fails to set correct IOMMU mappings for memory types different than
p2m_ram_rw.This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw,p2m_map_foreign,p2m_ram_roandp2m_grant_map_ro.
Quoted 6 lines
I'm curious about the justification for
p2m_map_foreign; the others I agree with.I also wonder whether
p2m_ram_logdirtyshouldn't be treated equally top2m_ram_rw: It's clearly better to have some video corruption than to kill the guest due to excessive IOMMU faults,
Hmmm. In that case it seems better; if we're absolutely sure that we can't end up trying to do log-dirty for _migration_ while a guest has a real device passed through, then yes, we can leave them as r/w to the IOMMU.
Maybe make sure at the same time that full log-dirty mode and needs_iommu are mutually exclusive.
Tim.
Re: [PATCH 1/3] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0
Quoted 15 lines · Tim Deegan
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
If the memory map is not shared between HAP and IOMMU we fails to set correct IOMMU mappings for memory types different than
p2m_ram_rw.This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw,p2m_map_foreign,p2m_ram_roandp2m_grant_map_ro.Quoted 6 lines
I'm curious about the justification for
p2m_map_foreign; the others I agree with.I also wonder whether
p2m_ram_logdirtyshouldn't be treated equally top2m_ram_rw: It's clearly better to have some video corruption than to kill the guest due to excessive IOMMU faults,
Quoted 7 lines
Hmmm. In that case it seems better; if we're absolutely sure that we can't end up trying to do log-dirty for _migration_ while a guest has a real device passed through, then yes, we can leave them as r/w to the IOMMU.
Maybe make sure at the same time that full log-dirty mode and
needs_iommuare mutually exclusive.
Would it suffice to add something like:
case p2m_ram_logdirty:
ASSERT(!paging_mode_log_dirty(p2m->domain));
Or are you referring to a more global check?
Thanks, Roger.
Re: [PATCH 1/3] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 17:15, <[email protected]> wrote:
Quoted 20 lines · Tim Deegan
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
If the memory map is not shared between HAP and IOMMU we fails to set correct IOMMU mappings for memory types different than
p2m_ram_rw.This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw,p2m_map_foreign,p2m_ram_roandp2m_grant_map_ro.Quoted 6 lines
I'm curious about the justification for
p2m_map_foreign; the others I agree with.I also wonder whether
p2m_ram_logdirtyshouldn't be treated equally top2m_ram_rw: It's clearly better to have some video corruption than to kill the guest due to excessive IOMMU faults,Hmmm. In that case it seems better; if we're absolutely sure that we can't end up trying to do log-dirty for _migration_ while a guest has a real device passed through, then yes, we can leave them as r/w to the IOMMU.
Quoted 7 lines
Quoted 2 lines
Maybe make sure at the same time that full log-dirty mode and
needs_iommuare mutually exclusive.Would it suffice to add something like:
case
p2m_ram_logdirty:ASSERT(!paging_mode_log_dirty(p2m->domain));
Iirc that would also catch the VRAM dirty tracking, i.e. not be suitable. I'll defer to Tim though to explain what he had in mind instead.
Jan
Re: [PATCH 1/3] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0
In reply to Roger Pau MonnéQuoted 24 lines · Roger Pau Monné
Quoted 15 lines · Tim Deegan
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
If the memory map is not shared between HAP and IOMMU we fails to set correct IOMMU mappings for memory types different than
p2m_ram_rw.This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw,p2m_map_foreign,p2m_ram_roandp2m_grant_map_ro.Quoted 6 lines
I'm curious about the justification for
p2m_map_foreign; the others I agree with.I also wonder whether
p2m_ram_logdirtyshouldn't be treated equally top2m_ram_rw: It's clearly better to have some video corruption than to kill the guest due to excessive IOMMU faults,Quoted 7 lines
Hmmm. In that case it seems better; if we're absolutely sure that we can't end up trying to do log-dirty for _migration_ while a guest has a real device passed through, then yes, we can leave them as r/w to the IOMMU.
Maybe make sure at the same time that full log-dirty mode and
needs_iommuare mutually exclusive.
Quoted 6 lines
Would it suffice to add something like:
case
p2m_ram_logdirty:ASSERT(!paging_mode_log_dirty(p2m->domain));Or are you referring to a more global check?
I was thinking that the paths that _set_ full log-dirty mode or needs_iommu should explicitly test that the other isn't the case (i.e. a logdirty-enable hypercall or assigning a passthough device should fail).
Tim.
Re: [PATCH 1/3] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0
In reply to Jan BeulichQuoted 9 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
If the memory map is not shared between HAP and IOMMU we fails to set correct IOMMU mappings for memory types different than
p2m_ram_rw.This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw,p2m_map_foreign,p2m_ram_roandp2m_grant_map_ro.I'm curious about the justification for
p2m_map_foreign; the others I agree with.
I've spoken with Stefano about this, because I've seen Qemu use foreign mapped pages as arguments to systems calls like pread/pwrite, and I'm quite sure we need IOMMU entries for foreign mappings. If Qemu opens the disk file with O_DIRECT foreign mappings can end up in DMA requests.
Roger.
Re: [PATCH 1/3] iommu: set correct IOMMU entries when iommu_hap_pt_share == 0
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 16.04.14 at 16:36, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
If the memory map is not shared between HAP and IOMMU we fails to set correct IOMMU mappings for memory types different than
p2m_ram_rw.This patchs adds IOMMU support for the following memory types:
p2m_grant_map_rw,p2m_map_foreign,p2m_ram_roandp2m_grant_map_ro.
Quoted 7 lines
Quoted 2 lines
I'm curious about the justification for
p2m_map_foreign; the others I agree with.I've spoken with Stefano about this, because I've seen Qemu use foreign mapped pages as arguments to systems calls like pread/pwrite, and I'm quite sure we need IOMMU entries for foreign mappings. If Qemu opens the disk file with
O_DIRECTforeign mappings can end up in DMA requests.
That's fine then, and at once puts off the option of using the global bit for something (because now we certainly have more types than we could encode).
One request though on the changes done: Please put the p2m-type- to-IOMMU-flags conversion into an inline function, usable by both callers. And iirc there's a third place (in p2m-pt.c) where you also need to do that conversion (as replacement to just special casing p2m_ram_rw).
Jan
PATCH 2/3 amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs
In reply to Roger Pau MonneAccording to the comment in p2m.h, AMD IOMMUs don't work correctly with page types different than p2m_ram_rw when the p2m is shared between HAP and IOMMU, so disable this sharing when using AMD IOMMUs
---
I have not tested this patch on AMD hardware, so I would like some confirmation that this actually works.
--- xen/drivers/passthrough/amd/iommu_init.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
xen/drivers/passthrough/amd/iommu_init.c +7 -0
@@ -1255,6 +1255,13 @@ int __init amd_iommu_init(void)if (iterate_ivrs_mappings (amd_iommu_setup_device_table) !=0 ) goto error_out; +/* +* Disable sharing HAP page tables with AMD IOMMU, +* since it only supports p2m_ram_rw, and this would +* prevent doing IO to/from mapped grant frames. +*/ + iommu_hap_pt_share =0 ; +/* per iommu initialization */ for_each_amd_iommu ( iommu ) if ( amd_iommu_init_one(iommu) != 0 )
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 2/3] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs
Quoted 3 lines · Roger Pau Monne
According to the comment in
p2m.h, AMD IOMMUs don't work correctly with page types different thanp2m_ram_rwwhen the p2m is shared between HAP and IOMMU, so disable this sharing when using AMD IOMMUs
s/between/amongst/
And you are missing an '.' at the off the sentence.
Quoted 38 lines
Signed-off-by Roger Pau Monné <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>---
I have not tested this patch on AMD hardware, so I would like some confirmation that this actually works.--- xen/drivers/passthrough/amd/iommu_init.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)xen/drivers/passthrough/amd/iommu_init.c +7
-0@@ -1255,6 +1255,13 @@ int __init amd_iommu_init(void)if (iterate_ivrs_mappings (amd_iommu_setup_device_table) !=0 ) goto error_out; +/* +* Disable sharing HAP page tables with AMD IOMMU, +* since it only supports p2m_ram_rw, and this would +* prevent doing IO to/from mapped grant frames. +*/ + iommu_hap_pt_share =0 ; +/* per iommu initialization */ for_each_amd_iommu ( iommu ) if ( amd_iommu_init_one(iommu) != 0 )Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 2/3] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Roger Pau Monne
According to the comment in
p2m.h, AMD IOMMUs don't work correctly with page types different thanp2m_ram_rwwhen the p2m is shared between HAP and IOMMU, so disable this sharing when using AMD IOMMUss/between/amongst/
I would say "between". "Amongst", besides sounding a bit archaic, gives me the idea of something being divided up (the bread was shared amongst them), as opposed to a single thing used by both (the car was shared between them).
-George
Re: [PATCH 2/3] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs
Quoted 7 lines · George Dunlap
Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Roger Pau Monne
According to the comment in
p2m.h, AMD IOMMUs don't work correctly with page types different thanp2m_ram_rwwhen the p2m is shared between HAP and IOMMU, so disable this sharing when using AMD IOMMUs
Quoted 6 lines
Quoted 1 line
s/between/amongst/
I would say "between". "Amongst", besides sounding a bit archaic, gives me the idea of something being divided up (the bread was shared amongst them), as opposed to a single thing used by both (the car was shared between them).
Thanks to both (George and Konrad) for spotting those mistakes, will fix in the next revision.
Roger.
Re: [PATCH 2/3] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs
In reply to Roger Pau MonneQuoted 4 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
xen/drivers/passthrough/amd/iommu_init.c int __init amd_iommu_init(void) · line 1264
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_init.c +7
-0@@ -1255,6 +1255,13 @@ int __init amd_iommu_init(void)if (iterate_ivrs_mappings (amd_iommu_setup_device_table) !=0 ) goto error_out; +/* +* Disable sharing HAP page tables with AMD IOMMU, +* since it only supports p2m_ram_rw, and this would +* prevent doing IO to/from mapped grant frames. +*/ + iommu_hap_pt_share =0 ; +
I guess at the very least when the option was specified on the command line you should issue a warning, or perhaps even stay away from enforcing this.
I also think we ought to consider alternatives before taking a harsh step like this (and that's independent of my earlier indication that we may want to switch away from sharing these tables): It looks like the global bit in the host page tables is unused and ignored, and could therefore be used to indicate grant entries. The IW bit could be used to distinguish p2m_{ram,grant}_{ro,rw} respectively.
Curious what Tim's thoughts here are...
Jan
Re: [PATCH 2/3] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs
Quoted 19 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
xen/drivers/passthrough/amd/iommu_init.c int __init amd_iommu_init(void) · line 1264
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_init.c +7
-0@@ -1255,6 +1255,13 @@ int __init amd_iommu_init(void)if (iterate_ivrs_mappings (amd_iommu_setup_device_table) !=0 ) goto error_out; +/* +* Disable sharing HAP page tables with AMD IOMMU, +* since it only supports p2m_ram_rw, and this would +* prevent doing IO to/from mapped grant frames. +*/ + iommu_hap_pt_share =0 ; +I guess at the very least when the option was specified on the command line you should issue a warning, or perhaps even stay away from enforcing this.
Quoted 8 lines
I also think we ought to consider alternatives before taking a harsh step like this (and that's independent of my earlier indication that we may want to switch away from sharing these tables): It looks like the global bit in the host page tables is unused and ignored, and could therefore be used to indicate grant entries. The IW bit could be used to distinguish p2m_{ram,grant}_{ro,rw} respectively.
Curious what Tim's thoughts here are...
Happy to use the global bit to mark grant entries (though I haven't checked the docs to be sure it's actually safe). OTOH it seems like the hadres IOMMU tables might be going away for other reasons so I'm not sure it's worth putting a lot of effort into being clever around this.
Tim.
Re: [PATCH 2/3] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:16, <[email protected]> wrote:
Quoted 26 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
xen/drivers/passthrough/amd/iommu_init.c int __init amd_iommu_init(void) · line 1264
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_init.c +7
-0@@ -1255,6 +1255,13 @@ int __init amd_iommu_init(void)if (iterate_ivrs_mappings (amd_iommu_setup_device_table) !=0 ) goto error_out; +/* +* Disable sharing HAP page tables with AMD IOMMU, +* since it only supports p2m_ram_rw, and this would +* prevent doing IO to/from mapped grant frames. +*/ + iommu_hap_pt_share =0 ; +I guess at the very least when the option was specified on the command line you should issue a warning, or perhaps even stay away from enforcing this.
I also think we ought to consider alternatives before taking a harsh step like this (and that's independent of my earlier indication that we may want to switch away from sharing these tables): It looks like the global bit in the host page tables is unused and ignored, and could therefore be used to indicate grant entries. The IW bit could be used to distinguish p2m_{ram,grant}_{ro,rw} respectively.
Quoted 7 lines
Quoted 1 line
Curious what Tim's thoughts here are...
Happy to use the global bit to mark grant entries (though I haven't checked the docs to be sure it's actually safe). OTOH it seems like the hadres IOMMU tables might be going away for other reasons so I'm not sure it's worth putting a lot of effort into being clever around this.
Yeah - I simply wanted to make sure we think of alternatives if they make sense; if they don't, and if we're settled to drop shared tables anyway, then the patch is presumably fine as is.
Jan
Re: [PATCH 2/3] amd-iommu: disable iommu_hap_pt_share with AMD IOMMUs
In reply to Jan BeulichQuoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 07.04.14 at 18:02, <[email protected]> wrote:
xen/drivers/passthrough/amd/iommu_init.c +0
-0@@ -1255,6 +1255,13 @@ int __init amd_iommu_init(void)if (iterate_ivrs_mappings (amd_iommu_setup_device_table) !=0 ) goto error_out;
Quoted 11 lines
xen/drivers/passthrough/amd/iommu_init.c int __init amd_iommu_init(void) · line 1264
Quoted 7 lines
xen/drivers/passthrough/amd/iommu_init.c +7
-0+/* +* Disable sharing HAP page tables with AMD IOMMU, +* since it only supports p2m_ram_rw, and this would +* prevent doing IO to/from mapped grant frames. +*/ + iommu_hap_pt_share =0 ; +I guess at the very least when the option was specified on the command line you should issue a warning, or perhaps even stay away from enforcing this.
I think we should enforce it even if the user has specified sharept=true, or else we need to gate the XENFEAT_hvm_gntmap_supports_iommu feature. Printing a Warning in this case (user trying to enforce sharept on AMD IOMMU) seems OK to me.
Roger.
PATCH 3/3 xen: expose that grant table mappings update the IOMMU
In reply to Roger Pau MonneAdd a new XENFEAT_hvm_gntmap_supports_iommu that is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.
--- xen/common/kernel.c | 2 ++ xen/include/public/features.h | 6 ++++++ 2 files changed, 8 insertions(+), 0 deletions(-)
xen/common/kernel.c +2 -0
@@ -316,11 +316,13 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)case guest_type_pvh: fi.submap |= (1U << XENFEAT_hvm_safe_pvclock) | (1U << XENFEAT_supervisor_mode_kernel) | + (1U << XENFEAT_hvm_gntmap_supports_iommu) | (1U << XENFEAT_hvm_callback_vector);break ;case guest_type_hvm: fi.submap |= (1U << XENFEAT_hvm_safe_pvclock) | (1U << XENFEAT_hvm_callback_vector) | + (1U << XENFEAT_hvm_gntmap_supports_iommu) | (1U << XENFEAT_hvm_pirqs);break ; }
xen/include/public/features.h +6 -0
@@ -94,6 +94,12 @@/* operation as Dom0 is supported */ #define XENFEAT_dom0 11 +/* +* If set, GNTTABOP_map_grant_ref sets the proper IOMMU mappings so the +* resulting mapped page can be used for IO with hardware devices. +*/ +#define XENFEAT_hvm_gntmap_supports_iommu 12 +#define XENFEAT_NR_SUBMAPS 1#endif /* __XEN_PUBLIC_FEATURES_H__ */
Signature · 7 lines
1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 3/3] xen: expose that grant table mappings update the IOMMU
Quoted 3 lines · Roger Pau Monne
Add a new
XENFEAT_hvm_gntmap_supports_iommuthat is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.
Is it the case on x86 that all devices are behind the IOMMU?
On ARM with have the issue that only a subset of peripherals are behind the IOMMU, for the rest we need other tricks like 1:1 mappings and swiotlb bouncing (for dom0 only, we just don't support passing these devices thru to domU).
Just want to make sure you aren't going to trip over a similar issue on x86 after this ABI has been set...
Ian.
Re: [PATCH 3/3] xen: expose that grant table mappings update the IOMMU
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 10:34, <[email protected]> wrote:
Quoted 3 lines · Roger Pau Monne
Add a new
XENFEAT_hvm_gntmap_supports_iommuthat is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.Is it the case on x86 that all devices are behind the IOMMU?
All PCI ones are. If someone passes through a device through raw MMIO/PIO/PIRQ ranges, then the IOMMU may or may not be involved. But I don't think we formally consider this model valid/supported/secure for HVM guests (and for PV guests it's insecure anyway, due to not requiring an IOMMU in the first place).
Jan
Re: [PATCH 3/3] xen: expose that grant table mappings update the IOMMU
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 10:34, <[email protected]> wrote:
Quoted 3 lines · Roger Pau Monne
Add a new
XENFEAT_hvm_gntmap_supports_iommuthat is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.Is it the case on x86 that all devices are behind the IOMMU?
I suppose I should have said "all DMA capable devices" or some such.
Quoted 6 lines
All PCI ones are. If someone passes through a device through raw MMIO/PIO/PIRQ ranges, then the IOMMU may or may not be involved. But I don't think we formally consider this model valid/supported/secure for HVM guests (and for PV guests it's insecure anyway, due to not requiring an IOMMU in the first place).
I was thinking of PVH dom0 here, which is the closest analogue to the ARM model.
Sounds like it might suffer from the same shortcomings as ARM has to deal with.
Ian.
Re: [PATCH 3/3] xen: expose that grant table mappings update the IOMMU
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 10:58, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 10:34, <[email protected]> wrote:
Quoted 3 lines · Roger Pau Monne
Add a new
XENFEAT_hvm_gntmap_supports_iommuthat is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.Is it the case on x86 that all devices are behind the IOMMU?
I suppose I should have said "all DMA capable devices" or some such.
Quoted 6 lines
All PCI ones are. If someone passes through a device through raw MMIO/PIO/PIRQ ranges, then the IOMMU may or may not be involved. But I don't think we formally consider this model valid/supported/secure for HVM guests (and for PV guests it's insecure anyway, due to not requiring an IOMMU in the first place).
Quoted 5 lines
I was thinking of PVH dom0 here, which is the closest analogue to the ARM model.
Sounds like it might suffer from the same shortcomings as ARM has to deal with.
Except that on x86 there are hardly many DMA-capable non-PCI devices, and even less one may want to consider passing through to a guest.
Jan
Re: [PATCH 3/3] xen: expose that grant table mappings update the IOMMU
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 10:58, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 10:34, <[email protected]> wrote:
Quoted 3 lines · Roger Pau Monne
Add a new
XENFEAT_hvm_gntmap_supports_iommuthat is used to check whether the hypervisor properly updates the IOMMU on auto-translated guests when doing a grant table map/unmap operation.Is it the case on x86 that all devices are behind the IOMMU?
I suppose I should have said "all DMA capable devices" or some such.
Quoted 6 lines
All PCI ones are. If someone passes through a device through raw MMIO/PIO/PIRQ ranges, then the IOMMU may or may not be involved. But I don't think we formally consider this model valid/supported/secure for HVM guests (and for PV guests it's insecure anyway, due to not requiring an IOMMU in the first place).
Quoted 8 lines
Quoted 5 lines
I was thinking of PVH dom0 here, which is the closest analogue to the ARM model.
Sounds like it might suffer from the same shortcomings as ARM has to deal with.
Except that on x86 there are hardly many DMA-capable non-PCI devices,
Sure.
Quoted 2 lines
and even less one may want to consider passing through to a guest.
Again, PVH dom0 is my concern here. By default you would expect dom0 to get given almost everything in the platform, including things which you might not normally pass through to a guest.
Ian.
Re: [PATCH 3/3] xen: expose that grant table mappings update the IOMMU
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 11:57, <[email protected]> wrote:
Again, PVH dom0 is my concern here. By default you would expect dom0 to get given almost everything in the platform, including things which you might not normally pass through to a guest.
I think all we can do is say such devices (if any exist at all) may not work with PVH Dom0. I don't see us accepting a 1:1 hack for x86 like you put in place for ARM, and I take it that you need this hack only because it's essential devices that may come in this form.
Jan
Re: [PATCH 3/3] xen: expose that grant table mappings update the IOMMU
Quoted 8 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 11:57, <[email protected]> wrote:
Again, PVH dom0 is my concern here. By default you would expect dom0 to get given almost everything in the platform, including things which you might not normally pass through to a guest.
I think all we can do is say such devices (if any exist at all) may not work with PVH Dom0. I don't see us accepting a 1:1 hack for x86 like you put in place for ARM,
That's fair enough for x86 I think.
Quoted 2 lines
and I take it that you need this hack only because it's essential devices that may come in this form.
That's right, sometimes it is NICs etc.
Plus we want dom0 to be able to run on systems with no IOMMU at all. I think PVH is predicated on there being an IOMMU in the system.
Ian.
Re: [PATCH 3/3] xen: expose that grant table mappings update the IOMMU
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 12:26, <[email protected]> wrote:
Plus we want dom0 to be able to run on systems with no IOMMU at all. I think PVH is predicated on there being an IOMMU in the system.
Yes, it is.
Jan