x86/p2m: fix non-translated handling of iommu mappings
PATCH 1/1 x86/p2m: fix non-translated handling of iommu mappings
The current usage of need_iommu_pt_sync in p2m for non-translated guests is wrong because it doesn't correctly handle a relaxed PV hardware domain, that has need_sync set to false, but still need entries to be added from calls to {set/clear}_identity_p2m_entry.
Adjust the code in guest_physmap_add_page to also check whether the domain has an iommu instead of whether it needs syncing or not in order to take a reference to a page to be mapped.
---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Paul Durrant <[email protected]>
--- xen/arch/x86/mm/p2m.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/mm/p2m.c +3 -3
@@ -836,7 +836,7 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn,*/ for ( i =0 ; i < (1UL << page_order); ++i, ++page ) { -if ( !need_iommu_pt_sync (d) ) +if ( !has_iommu_pt (d) )/* nothing */ ;else if (get_page_and_type (page, d, PGT_writable_page) )put_page_and_type (page);
@@ -1341,7 +1341,7 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn_l,if ( !paging_mode_translate (p2m->domain) ) { -if ( !need_iommu_pt_sync (d) ) +if ( !has_iommu_pt (d) )return 0 ;return iommu_legacy_map (d,_dfn (gfn_l),_mfn (gfn_l),PAGE_ORDER_4K , IOMMUF_readable | IOMMUF_writable);
@@ -1432,7 +1432,7 @@ int clear_identity_p2m_entry(struct domain *d, unsigned long gfn_l)if ( !paging_mode_translate (d) ) { -if ( !need_iommu_pt_sync (d) ) +if ( !has_iommu_pt (d) )return 0 ;return iommu_legacy_unmap (d,_dfn (gfn_l),PAGE_ORDER_4K ); }
Signature · 7 lines
2.20.1 (Apple Git-117) _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 18 lines
-----Original Message-----
From: Roger Pau Monne <[email protected]>
Sent: 22 July 2019 16:32
To: [email protected]
Cc: Roger Pau Monne <[email protected]>; George Dunlap <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Paul Durrant <[email protected]>
Subject: [PATCH] x86/p2m: fix non-translated handling of iommu mappingsThe current usage of
need_iommu_pt_syncin p2m for non-translated guests is wrong because it doesn't correctly handle a relaxed PV hardware domain, that hasneed_syncset to false, but still need entries to be added from calls to {set/clear}_identity_p2m_entry.Adjust the code in
guest_physmap_add_pageto also check whether the domain has an iommu instead of whether it needs syncing or not in order to take a reference to a page to be mapped.
Quoted 7 lines
Signed-off-by Roger Pau Monné <[email protected]>---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Paul Durrant <[email protected]>
Quoted 36 lines
--- xen/arch/x86/mm/p2m.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)xen/arch/x86/mm/p2m.c +3
-4@@ -836,7 +836,7 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn,*/ for ( i =0 ; i < (1UL << page_order); ++i, ++page ) { -if ( !need_iommu_pt_sync (d) ) +if ( !has_iommu_pt (d) )/* nothing */ ;else if (get_page_and_type (page, d, PGT_writable_page) )put_page_and_type (page);@@ -1341,7 +1341,7 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn_l,if ( !paging_mode_translate (p2m->domain) ) { -if ( !need_iommu_pt_sync (d) ) +if ( !has_iommu_pt (d) )return 0 ;return iommu_legacy_map (d,_dfn (gfn_l),_mfn (gfn_l),PAGE_ORDER_4K , IOMMUF_readable | IOMMUF_writable);@@ -1432,7 +1432,7 @@ int clear_identity_p2m_entry(struct domain *d, unsigned long gfn_l)if ( !paging_mode_translate (d) ) { -if ( !need_iommu_pt_sync (d) ) +if ( !has_iommu_pt (d) )return 0 ;return iommu_legacy_unmap (d,_dfn (gfn_l),PAGE_ORDER_4K ); } --
Quoted 1 line
2.20.1 (Apple Git-117)
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 8 lines · Roger Pau Monne
The current usage of
need_iommu_pt_syncin p2m for non-translated guests is wrong because it doesn't correctly handle a relaxed PV hardware domain, that hasneed_syncset to false, but still need entries to be added from calls to {set/clear}_identity_p2m_entry.Adjust the code in
guest_physmap_add_pageto also check whether the domain has an iommu instead of whether it needs syncing or not in order to take a reference to a page to be mapped.
Why this seemingly unrelated change? I ask because ...
xen/arch/x86/mm/p2m.c guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn, · line 842
Quoted 11 lines
xen/arch/x86/mm/p2m.c +1
-1@@ -836,7 +836,7 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn,*/ for ( i =0 ; i < (1UL << page_order); ++i, ++page ) { -if ( !need_iommu_pt_sync (d) ) +if ( !has_iommu_pt (d) )/* nothing */ ;else if (get_page_and_type (page, d, PGT_writable_page) )put_page_and_type (page);
... this parallels the code in iommu_hwdom_init(), which similarly uses need_iommu_pt_sync() (and during the prior discussion you did agree with Paul that it shouldn't be changed). IOW the patch for now can have my R-b only with this change and the respective part of the description dropped.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 21 lines · Jan Beulich
Quoted 8 lines · Roger Pau Monne
The current usage of
need_iommu_pt_syncin p2m for non-translated guests is wrong because it doesn't correctly handle a relaxed PV hardware domain, that hasneed_syncset to false, but still need entries to be added from calls to {set/clear}_identity_p2m_entry.Adjust the code in
guest_physmap_add_pageto also check whether the domain has an iommu instead of whether it needs syncing or not in order to take a reference to a page to be mapped.Why this seemingly unrelated change? I ask because ...
Quoted 9 lines
xen/arch/x86/mm/p2m.c +1
-1@@ -836,7 +836,7 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn,*/ for ( i =0 ; i < (1UL << page_order); ++i, ++page ) { -if ( !need_iommu_pt_sync (d) ) +if ( !has_iommu_pt (d) )/* nothing */ ;
Quoted 8 lines
xen/arch/x86/mm/p2m.c guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn, · line 842
Quoted 2 lines
xen/arch/x86/mm/p2m.c +0
-0else if (get_page_and_type (page, d, PGT_writable_page) )put_page_and_type (page);... this parallels the code in
iommu_hwdom_init(), which similarly usesneed_iommu_pt_sync()(and during the prior discussion you did agree with Paul that it shouldn't be changed). IOW the patch for now can have my R-b only with this change and the respective part of the description dropped.
OK, this is again not needed for a relaxed PV hardware domain because all RAM is already mapped on the iommu page tables.
Let me update the commit and resend.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Roger Pau Monne
The current usage of
need_iommu_pt_syncin p2m for non-translated guests is wrong because it doesn't correctly handle a relaxed PV hardware domain, that hasneed_syncset to false, but still need entries to be added from calls to {set/clear}_identity_p2m_entry.Adjust the code in
guest_physmap_add_pageto also check whether the domain has an iommu instead of whether it needs syncing or not in order to take a reference to a page to be mapped.
Quoted 7 lines
Signed-off-by Roger Pau Monné <[email protected]>---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Paul Durrant <[email protected]>
Quoted 39 lines
--- xen/arch/x86/mm/p2m.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)xen/arch/x86/mm/p2m.c +3
-4@@ -836,7 +836,7 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn,*/ for ( i =0 ; i < (1UL << page_order); ++i, ++page ) { -if ( !need_iommu_pt_sync (d) ) +if ( !has_iommu_pt (d) )/* nothing */ ;else if (get_page_and_type (page, d, PGT_writable_page) )put_page_and_type (page);@@ -1341,7 +1341,7 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn_l,if ( !paging_mode_translate (p2m->domain) ) { -if ( !need_iommu_pt_sync (d) ) +if ( !has_iommu_pt (d) )return 0 ;return iommu_legacy_map (d,_dfn (gfn_l),_mfn (gfn_l),PAGE_ORDER_4K , IOMMUF_readable | IOMMUF_writable);@@ -1432,7 +1432,7 @@ int clear_identity_p2m_entry(struct domain *d, unsigned long gfn_l)if ( !paging_mode_translate (d) ) { -if ( !need_iommu_pt_sync (d) ) +if ( !has_iommu_pt (d) )return 0 ;return iommu_legacy_unmap (d,_dfn (gfn_l),PAGE_ORDER_4K ); } --2.20.1 (Apple Git-117)
Quoted 4 lines
_______________________________________________
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
Quoted 19 lines · Roman Shaposhnik
Quoted 10 lines · Roger Pau Monne
The current usage of
need_iommu_pt_syncin p2m for non-translated guests is wrong because it doesn't correctly handle a relaxed PV hardware domain, that hasneed_syncset to false, but still need entries to be added from calls to {set/clear}_identity_p2m_entry.Adjust the code in
guest_physmap_add_pageto also check whether the domain has an iommu instead of whether it needs syncing or not in order to take a reference to a page to be mapped.Quoted 7 lines
Signed-off-by Roger Pau Monné <[email protected]>---
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Paul Durrant <[email protected]>
Quoted 1 line
Tested-by Roman Shaposhnik <[email protected]>
There's a v2 of the patch, but I guess your TB also applies to it.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel