iommu / p2m: add a page_order parameter to iommu_map/unmap_page()
PATCH v2 1/1 iommu / p2m: add a page_order parameter to iommu_map/unmap_page()
The P2M code currently contains many loops to deal with the fact that, while it may be require to handle page orders greater than 4k, the IOMMU map and unmap functions do not.
This patch adds a page_order parameter to those functions and implements the necessary loops within. This allows the P2M code to be substantially simplified.
NOTE: This patch does not modify the underlying vendor IOMMU
implementations to deal with page orders of more than 4k.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Jun Nakajima <[email protected]>
Cc: Kevin Tian <[email protected]>
v2:
- Add alignment ASSERTs and tweak code structure to avoid to much nesting.
- Don't bail from an unmap in the case of the hardware domain.
--- xen/arch/x86/mm.c | 4 ++- xen/arch/x86/mm/p2m-ept.c | 30 +++------------------- xen/arch/x86/mm/p2m-pt.c | 47 ++++++++-------------------------- xen/arch/x86/mm/p2m.c | 49 +++++------------------------------ xen/arch/x86/x86_64/mm.c | 4 ++- xen/common/grant_table.c | 7 +++-- xen/drivers/passthrough/iommu.c | 51 +++++++++++++++++++++++++++++-------- xen/drivers/passthrough/x86/iommu.c | 2 +- xen/include/xen/iommu.h | 8 +++--- 9 files changed, 77 insertions(+), 125 deletions(-)
xen/arch/x86/mm.c +3 -1
@@ -2794,9 +2794,11 @@ static int _get_page_type(struct page_info *page, unsigned long type,mfn_t mfn =page_to_mfn (page);if ( (x & PGT_type_mask) == PGT_writable_page ) - iommu_ret =iommu_unmap_page (d,_dfn (mfn_x (mfn))); + iommu_ret =iommu_unmap_page (d,_dfn (mfn_x (mfn)), +PAGE_ORDER_4K );else if ( type == PGT_writable_page ) iommu_ret =iommu_map_page (d,_dfn (mfn_x (mfn)), mfn, +PAGE_ORDER_4K , IOMMUF_readable | IOMMUF_writable); }
xen/arch/x86/mm/p2m-ept.c +3 -27
@@ -880,33 +880,9 @@ out:if (iommu_use_hap_pt (d) ) rc =iommu_pte_flush (d, gfn, &ept_entry->epte, order, vtd_pte_present);else if (need_iommu_pt_sync (d) ) - { -dfn_t dfn =_dfn (gfn); - -if ( iommu_flags ) -for ( i =0 ; i < (1 << order); i++ ) - { - rc =iommu_map_page (d,dfn_add (dfn, i), -mfn_add (mfn, i), iommu_flags); -if (unlikely (rc) ) - { -while ( i-- ) -/* If statement to satisfy __must_check. */ -if (iommu_unmap_page (p2m->domain, -dfn_add (dfn, i)) ) -continue ; - -break ; - } - } -else -for ( i =0 ; i < (1 << order); i++ ) - { - ret =iommu_unmap_page (d,dfn_add (dfn, i)); -if ( !rc ) - rc = ret; - } - } + rc = iommu_flags ? +iommu_map_page (d,_dfn (gfn), mfn, order, iommu_flags) : +iommu_unmap_page (d,_dfn (gfn), order); }unmap_domain_page (table);
xen/arch/x86/mm/p2m-pt.c +10 -37
68 lines not on this page · raw message
xen/arch/x86/mm/p2m.c +7 -42
73 lines not on this page · raw message
xen/arch/x86/x86_64/mm.c +3 -1
@@ -1437,13 +1437,15 @@ int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm) {for ( i = spfn; i < epfn; i++ )if (iommu_map_page (hardware_domain,_dfn (i),_mfn (i), +PAGE_ORDER_4K , IOMMUF_readable | IOMMUF_writable) )break ;if ( i != epfn ) {while (i-- > old_max)/* If statement to satisfy __must_check. */ -if (iommu_unmap_page (hardware_domain,_dfn (i)) ) +if (iommu_unmap_page (hardware_domain,_dfn (i), +PAGE_ORDER_4K ) )continue ; goto destroy_m2p;
xen/common/grant_table.c +5 -2
@@ -1142,12 +1142,14 @@ map_grant_ref( {if ( !(kind &MAPKIND_WRITE ) ) err =iommu_map_page (ld,_dfn (mfn_x (mfn)), mfn, +PAGE_ORDER_4K , IOMMUF_readable | IOMMUF_writable); } else if ( act_pin && !old_pin ) {if ( !kind ) err =iommu_map_page (ld,_dfn (mfn_x (mfn)), mfn, +PAGE_ORDER_4K , IOMMUF_readable); }if ( err )
@@ -1396,10 +1398,11 @@ unmap_common( kind =mapkind (lgt, rd, op->mfn);if ( !kind ) - err =iommu_unmap_page (ld,_dfn (mfn_x (op->mfn))); + err =iommu_unmap_page (ld,_dfn (mfn_x (op->mfn)), +PAGE_ORDER_4K );else if ( !(kind &MAPKIND_WRITE ) ) err =iommu_map_page (ld,_dfn (mfn_x (op->mfn)), op->mfn, - IOMMUF_readable); +PAGE_ORDER_4K , IOMMUF_readable);double_gt_unlock (lgt, rgt);
xen/drivers/passthrough/iommu.c +40 -11
87 lines not on this page · raw message
xen/drivers/passthrough/x86/iommu.c +1 -1
@@ -239,7 +239,7 @@ void __hwdom_init arch_iommu_hwdom_init(struct domain *d)if (paging_mode_translate (d) ) rc =set_identity_p2m_entry (d, pfn, p2m_access_rw,0 );else - rc =iommu_map_page (d,_dfn (pfn),_mfn (pfn), + rc =iommu_map_page (d,_dfn (pfn),_mfn (pfn),PAGE_ORDER_4K , IOMMUF_readable | IOMMUF_writable);if ( rc ) printk(XENLOG_WARNING " d%d: IOMMU mapping failed: %d\n",
xen/include/xen/iommu.h +5 -3
@@ -89,9 +89,11 @@ void iommu_teardown(struct domain *d);#define IOMMUF_readable (1u<<_IOMMUF_readable)#define _IOMMUF_writable 1#define IOMMUF_writable (1u<<_IOMMUF_writable) -int __must_check iommu_map_page (struct domain *d,dfn_t dfn, -mfn_t mfn,unsigned int flags); -int __must_check iommu_unmap_page (struct domain *d,dfn_t dfn); +int __must_check iommu_map_page (struct domain *d,dfn_t dfn,mfn_t mfn, +unsigned int page_order, +unsigned int flags); +int __must_check iommu_unmap_page (struct domain *d,dfn_t dfn, +unsigned int page_order);int __must_check iommu_lookup_page (struct domain *d,dfn_t dfn,mfn_t *mfn,unsigned int *flags);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines · Paul Durrant
The P2M code currently contains many loops to deal with the fact that, while it may be require to handle page orders greater than 4k, the IOMMU map and unmap functions do not.
This patch adds apage_orderparameter to those functions and implements the necessary loops within. This allows the P2M code to be substantially simplified.NOTE: This patch does not modify the underlying vendor IOMMU
implementations to deal with page orders of more than 4k.
I'm wondering if it would make sense to drop the _page suffix from those functions now that they take an order parameter.
Quoted 12 lines
xen/drivers/passthrough/iommu.c +1
-1@@ -305,47 +305,76 @@ void iommu_domain_destroy(struct domain *d) }int iommu_map_page (struct domain *d,dfn_t dfn,mfn_t mfn, -unsigned int flags) +unsigned int page_order,unsigned int flags) {const struct domain_iommu *hd =dom_iommu (d);
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 317
Quoted 10 lines
xen/drivers/passthrough/iommu.c +3
-3-int rc; +unsigned long i;if ( !iommu_enabled || !hd->platform_ops )return 0 ; - rc = hd->platform_ops->map_page (d, dfn, mfn, flags); -if (unlikely (rc) ) +ASSERT (!(dfn_x (dfn) & ((1ul << page_order) -1 ))); +ASSERT (!(mfn_x (mfn) & ((1ul << page_order) -1 )));
I would consider using IS_ALIGNED for clarity.
Quoted 8 lines
xen/drivers/passthrough/iommu.c +7
-0+ +for ( i =0 ; i < (1ul << page_order); i++ ) { +int ignored, err = hd->platform_ops->map_page (d,dfn_add (dfn, i), +mfn_add (mfn, i), + flags); + +if (likely (!err) )
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 334
Quoted 10 lines
xen/drivers/passthrough/iommu.c +6
-1+continue ; +if ( !d->is_shutting_down &&printk_ratelimit () )printk (XENLOG_ERR "d%d: IOMMU mapping dfn %" PRI_dfn" to mfn %" PRI_mfn" failed: %d\n" , - d->domain_id,dfn_x (dfn),mfn_x (mfn), rc); + d->domain_id,dfn_x (dfn_add (dfn, i)), +mfn_x (mfn_add (mfn, i)), err); + +while (i--)
Missing spaces in the condition.
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 336
Quoted 2 lines
xen/drivers/passthrough/iommu.c +2
-0+/* assign to something to avoid compiler warning */ + ignored = hd->platform_ops->unmap_page (d,dfn_add (dfn, i));
You could likely declare ignored here to further limit it's scope?
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 341
Quoted 5 lines
xen/drivers/passthrough/iommu.c +2
-0if ( !is_hardware_domain (d) )domain_crash (d); + +return err;
I might prefer to keep the global rc variable here and just break on error, also keeping the 'return rc' below as it was. But that's just a question of taste IMO.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 22 lines
-----Original Message-----
From: Roger Pau Monne
Sent: 30 October 2018 14:44
To: Paul Durrant <[email protected]>
Cc: [email protected]; Kevin Tian <[email protected]>; Stefano Stabellini <[email protected]>; Wei Liu <[email protected]>; Jun Nakajima <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; George Dunlap <[email protected]>; Tim (Xen.org) <[email protected]>; Julien Grall <[email protected]>; Jan Beulich <[email protected]>
Subject: Re: [Xen-devel] [PATCH v2] iommu / p2m: add apage_orderparameter to iommu_map/unmap_page()Quoted 7 lines · Paul Durrant
The P2M code currently contains many loops to deal with the fact that, while it may be require to handle page orders greater than 4k, the IOMMU map and unmap functions do not.
This patch adds apage_orderparameter to those functions and implements the necessary loops within. This allows the P2M code to be substantially simplified.
Quoted 5 lines
Quoted 2 lines
NOTE: This patch does not modify the underlying vendor IOMMU
implementations to deal with page orders of more than 4k.I'm wondering if it would make sense to drop the
_pagesuffix from those functions now that they take an order parameter.
Yes, that might well be a good idea at this point since I have to hit all the call-sites anyway.
Quoted 20 lines
Review
Quoted 2 lines
(quoted diff) +0
-0
b/xen/drivers/passthrough/iommu.cQuoted 17 lines
index
8b438ae4bc..e02dcb101f100644xen/drivers/passthrough/iommu.c +2
-2@@ -305,47 +305,76 @@ void iommu_domain_destroy(struct domain *d) }int iommu_map_page (struct domain *d,dfn_t dfn,mfn_t mfn, -unsigned int flags) +unsigned int page_order,unsigned int flags) {const struct domain_iommu *hd =dom_iommu (d); -int rc; +unsigned long i;if ( !iommu_enabled || !hd->platform_ops )return 0 ;
Quoted 7 lines
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 317
Quoted 4 lines
xen/drivers/passthrough/iommu.c +2
-2- rc = hd->platform_ops->map_page (d, dfn, mfn, flags); -if (unlikely (rc) ) +ASSERT (!(dfn_x (dfn) & ((1ul << page_order) -1 ))); +ASSERT (!(mfn_x (mfn) & ((1ul << page_order) -1 )));I would consider using
IS_ALIGNEDfor clarity.
Ok.
Quoted 15 lines
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d)
Quoted 4 lines
xen/drivers/passthrough/iommu.c +3
-0+ +for ( i =0 ; i < (1ul << page_order); i++ ) { + int ignored, err = hd->platform_ops->map_page(d, dfn_add(dfn,i),
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d)
Quoted 9 lines
xen/drivers/passthrough/iommu.c +6
-0+ mfn_add(mfn, i), + flags); + +if (likely (!err) ) +continue ; +if ( !d->is_shutting_down &&printk_ratelimit () )printk (XENLOG_ERR "d%d: IOMMU mapping dfn %"PRI_dfn" to mfn %"PRI_mfn"failed: %d\n",
Quoted 8 lines
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 334
Quoted 5 lines
xen/drivers/passthrough/iommu.c +4
-1- d->domain_id, dfn_x(dfn), mfn_x(mfn), rc); + d->domain_id,dfn_x (dfn_add (dfn, i)), + mfn_x(mfn_add(mfn, i)), err); + +while (i--)Missing spaces in the condition.
Yes. Jan mentioned this too and I forgot to fix it.
Quoted 5 lines
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 336
Quoted 2 lines
xen/drivers/passthrough/iommu.c +2
-0+/* assign to something to avoid compiler warning */ + ignored = hd->platform_ops->unmap_page (d,dfn_add (dfn, i));You could likely declare ignored here to further limit it's scope?
I'll re-work as Jan prefers.
Quoted 10 lines
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 341
Quoted 5 lines
xen/drivers/passthrough/iommu.c +2
-0if ( !is_hardware_domain (d) )domain_crash (d); + +return err;I might prefer to keep the global rc variable here and just break on error, also keeping the 'return rc' below as it was. But that's just a question of taste IMO.
Ok. I'll see what that looks like. It might be nicer.
Paul
Quoted 1 line
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 29.10.18 at 14:29, <[email protected]> wrote:
xen/common/grant_table.c +2
-0@@ -1142,12 +1142,14 @@ map_grant_ref( {if ( !(kind &MAPKIND_WRITE ) ) err =iommu_map_page (ld,_dfn (mfn_x (mfn)), mfn, +PAGE_ORDER_4K , IOMMUF_readable | IOMMUF_writable); } else if ( act_pin && !old_pin ) {if ( !kind ) err =iommu_map_page (ld,_dfn (mfn_x (mfn)), mfn, +PAGE_ORDER_4K , IOMMUF_readable); }if ( err )@@ -1396,10 +1398,11 @@ unmap_common( kind =mapkind (lgt, rd, op->mfn);
xen/common/grant_table.c unmap_common( · line 1407
Quoted 10 lines
xen/common/grant_table.c +3
-2if ( !kind ) - err =iommu_unmap_page (ld,_dfn (mfn_x (op->mfn))); + err =iommu_unmap_page (ld,_dfn (mfn_x (op->mfn)), +PAGE_ORDER_4K );else if ( !(kind &MAPKIND_WRITE ) ) err =iommu_map_page (ld,_dfn (mfn_x (op->mfn)), op->mfn, - IOMMUF_readable); +PAGE_ORDER_4K , IOMMUF_readable);double_gt_unlock (lgt, rgt);
I am, btw, uncertain that using PAGE_ORDER_4K is correct here:
Other than in the IOMMU code, grant table code isn't tied to a particular architecture, and hence ought to work fine on a port to an architecture with 8k, 16k, or 32k pages.
Quoted 30 lines
xen/drivers/passthrough/iommu.c +13
-4@@ -305,47 +305,76 @@ void iommu_domain_destroy(struct domain *d) }int iommu_map_page (struct domain *d,dfn_t dfn,mfn_t mfn, -unsigned int flags) +unsigned int page_order,unsigned int flags) {const struct domain_iommu *hd =dom_iommu (d); -int rc; +unsigned long i;if ( !iommu_enabled || !hd->platform_ops )return 0 ; - rc = hd->platform_ops->map_page (d, dfn, mfn, flags); -if (unlikely (rc) ) +ASSERT (!(dfn_x (dfn) & ((1ul << page_order) -1 ))); +ASSERT (!(mfn_x (mfn) & ((1ul << page_order) -1 ))); + +for ( i =0 ; i < (1ul << page_order); i++ ) { +int ignored, err = hd->platform_ops->map_page (d,dfn_add (dfn, i), +mfn_add (mfn, i), + flags); + +if (likely (!err) ) +continue ; +
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 336
Quoted 10 lines
xen/drivers/passthrough/iommu.c +6
-1if ( !d->is_shutting_down &&printk_ratelimit () )printk (XENLOG_ERR "d%d: IOMMU mapping dfn %" PRI_dfn" to mfn %" PRI_mfn" failed: %d\n" , - d->domain_id,dfn_x (dfn),mfn_x (mfn), rc); + d->domain_id,dfn_x (dfn_add (dfn, i)), +mfn_x (mfn_add (mfn, i)), err); + +while (i--) +/* assign to something to avoid compiler warning */ + ignored = hd->platform_ops->unmap_page (d,dfn_add (dfn, i));
Hmm, as said on v1 - please use the original mode (while-if-continue) here. This lets you get away without a local variable that's never read, and which hence future compiler versions may legitimately warn about.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 45 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 30 October 2018 16:08
To: Paul Durrant <[email protected]>
Cc: Julien Grall <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Wei Liu <[email protected]>; Ian Jackson <[email protected]>; Jun Nakajima <[email protected]>; Kevin Tian <[email protected]>; Stefano Stabellini <[email protected]>; xen-devel <xen- [email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Tim (Xen.org) <[email protected]>
Subject: Re: [PATCH v2] iommu / p2m: add apage_orderparameter to iommu_map/unmap_page()xen/common/grant_table.c map_grant_ref( · line 1146
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 29.10.18 at 14:29, <[email protected]> wrote:
xen/common/grant_table.c +1
-0@@ -1142,12 +1142,14 @@ map_grant_ref( {if ( !(kind &MAPKIND_WRITE ) ) err = iommu_map_page(ld, _dfn(mfn_x(mfn)), mfn, + PAGE_ORDER_4K, IOMMUF_readable |
IOMMUF_writable);Quoted 21 lines
xen/common/grant_table.c +4
-2}else if ( act_pin && !old_pin ) {if ( !kind ) err =iommu_map_page (ld,_dfn (mfn_x (mfn)), mfn, +PAGE_ORDER_4K , IOMMUF_readable); }if ( err )@@ -1396,10 +1398,11 @@ unmap_common( kind =mapkind (lgt, rd, op->mfn);if ( !kind ) - err =iommu_unmap_page (ld,_dfn (mfn_x (op->mfn))); + err =iommu_unmap_page (ld,_dfn (mfn_x (op->mfn)), +PAGE_ORDER_4K );else if ( !(kind &MAPKIND_WRITE ) ) err =iommu_map_page (ld,_dfn (mfn_x (op->mfn)), op->mfn, - IOMMUF_readable); +PAGE_ORDER_4K , IOMMUF_readable);
Quoted 6 lines
xen/common/grant_table.c unmap_common( · line 1407
Quoted 1 line
xen/common/grant_table.c +0
-0double_gt_unlock (lgt, rgt);I am, btw, uncertain that using
PAGE_ORDER_4Kis correct here:
Other than in the IOMMU code, grant table code isn't tied to a particular architecture, and hence ought to work fine on a port to an architecture with 8k, 16k, or 32k pages.
Would you suggest I add an arch specific #define for a grant table page order and then use that?
Quoted 44 lines
Quoted 15 lines
xen/drivers/passthrough/iommu.c +2
-2@@ -305,47 +305,76 @@ void iommu_domain_destroy(struct domain *d) }int iommu_map_page (struct domain *d,dfn_t dfn,mfn_t mfn, -unsigned int flags) +unsigned int page_order,unsigned int flags) {const struct domain_iommu *hd =dom_iommu (d); -int rc; +unsigned long i;if ( !iommu_enabled || !hd->platform_ops )xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 321
Quoted 10 lines
xen/drivers/passthrough/iommu.c +5
-2return 0 ; - rc = hd->platform_ops->map_page (d, dfn, mfn, flags); -if (unlikely (rc) ) +ASSERT (!(dfn_x (dfn) & ((1ul << page_order) -1 ))); +ASSERT (!(mfn_x (mfn) & ((1ul << page_order) -1 ))); + +for ( i =0 ; i < (1ul << page_order); i++ ) { + int ignored, err = hd->platform_ops->map_page(d, dfn_add(dfn,i),
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d)
Quoted 9 lines
xen/drivers/passthrough/iommu.c +6
-0+ mfn_add(mfn, i), + flags); + +if (likely (!err) ) +continue ; +if ( !d->is_shutting_down &&printk_ratelimit () )printk (XENLOG_ERR "d%d: IOMMU mapping dfn %"PRI_dfn" to mfn %"PRI_mfn"failed: %d\n",
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 336
Quoted 7 lines
xen/drivers/passthrough/iommu.c +6
-1- d->domain_id, dfn_x(dfn), mfn_x(mfn), rc); + d->domain_id,dfn_x (dfn_add (dfn, i)), + mfn_x(mfn_add(mfn, i)), err); + +while (i--) +/* assign to something to avoid compiler warning */ + ignored = hd->platform_ops->unmap_page (d,dfn_add (dfn, i));
Quoted 5 lines
Hmm, as said on v1 - please use the original mode (while-if-continue) here. This lets you get away without a local variable that's never read, and which hence future compiler versions may legitimately warn about.
Ok, I clearly don't understand what you mean by 'while-if-continue' then. Above I have for-if-continue, which is what I thought you wanted. What code structure are you actually looking for?
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 42 lines
Quoted 35 lines
Quoted 1 line · On 30.10.18 at 17:56, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 30 October 2018 16:08xen/common/grant_table.c map_grant_ref( · line 1146
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 29.10.18 at 14:29, <[email protected]> wrote:
xen/common/grant_table.c +1
-0@@ -1142,12 +1142,14 @@ map_grant_ref( {if ( !(kind &MAPKIND_WRITE ) ) err = iommu_map_page(ld, _dfn(mfn_x(mfn)), mfn, + PAGE_ORDER_4K, IOMMUF_readable |
IOMMUF_writable);Quoted 21 lines
xen/common/grant_table.c +4
-2}else if ( act_pin && !old_pin ) {if ( !kind ) err =iommu_map_page (ld,_dfn (mfn_x (mfn)), mfn, +PAGE_ORDER_4K , IOMMUF_readable); }if ( err )@@ -1396,10 +1398,11 @@ unmap_common( kind =mapkind (lgt, rd, op->mfn);if ( !kind ) - err =iommu_unmap_page (ld,_dfn (mfn_x (op->mfn))); + err =iommu_unmap_page (ld,_dfn (mfn_x (op->mfn)), +PAGE_ORDER_4K );else if ( !(kind &MAPKIND_WRITE ) ) err =iommu_map_page (ld,_dfn (mfn_x (op->mfn)), op->mfn, - IOMMUF_readable); +PAGE_ORDER_4K , IOMMUF_readable);Quoted 6 lines
xen/common/grant_table.c unmap_common( · line 1407
Quoted 1 line
xen/common/grant_table.c +0
-0double_gt_unlock (lgt, rgt);I am, btw, uncertain that using
PAGE_ORDER_4Kis correct here:
Other than in the IOMMU code, grant table code isn't tied to a particular architecture, and hence ought to work fine on a port to an architecture with 8k, 16k, or 32k pages.
Quoted 2 lines
Would you suggest I add an arch specific #define for a grant table page order and then use that?
No, I'd prefer if you used liter 0 zero here.
Quoted 49 lines
Quoted 43 lines
Quoted 14 lines
xen/drivers/passthrough/iommu.c +2
-2@@ -305,47 +305,76 @@ void iommu_domain_destroy(struct domain *d) }int iommu_map_page (struct domain *d,dfn_t dfn,mfn_t mfn, -unsigned int flags) +unsigned int page_order,unsigned int flags) {const struct domain_iommu *hd =dom_iommu (d); -int rc; +unsigned long i;if ( !iommu_enabled || !hd->platform_ops )xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 321
Quoted 10 lines
xen/drivers/passthrough/iommu.c +5
-2return 0 ; - rc = hd->platform_ops->map_page (d, dfn, mfn, flags); -if (unlikely (rc) ) +ASSERT (!(dfn_x (dfn) & ((1ul << page_order) -1 ))); +ASSERT (!(mfn_x (mfn) & ((1ul << page_order) -1 ))); + +for ( i =0 ; i < (1ul << page_order); i++ ) { + int ignored, err = hd->platform_ops->map_page(d, dfn_add(dfn,i),
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d)
Quoted 9 lines
xen/drivers/passthrough/iommu.c +6
-0+ mfn_add(mfn, i), + flags); + +if (likely (!err) ) +continue ; +if ( !d->is_shutting_down &&printk_ratelimit () )printk (XENLOG_ERR "d%d: IOMMU mapping dfn %"PRI_dfn" to mfn %"PRI_mfn"failed: %d\n",
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 336
Quoted 7 lines
xen/drivers/passthrough/iommu.c +6
-1- d->domain_id, dfn_x(dfn), mfn_x(mfn), rc); + d->domain_id,dfn_x (dfn_add (dfn, i)), + mfn_x(mfn_add(mfn, i)), err); + +while (i--) +/* assign to something to avoid compiler warning */ + ignored = hd->platform_ops->unmap_page (d,dfn_add (dfn, i));Quoted 5 lines
Hmm, as said on v1 - please use the original mode (while-if-continue) here. This lets you get away without a local variable that's never read, and which hence future compiler versions may legitimately warn about.
Quoted 3 lines
Ok, I clearly don't understand what you mean by 'while-if-continue' then. Above I have for-if-continue, which is what I thought you wanted. What code structure are you actually looking for?
The one your patch removes elsewhere:
- while ( i-- )
- /* If statement to satisfy __must_check. */
- if ( iommu_unmap_page(p2m->domain,
- dfn_add(dfn, i)) )
- continue;
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 56 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 30 October 2018 17:05
To: Paul Durrant <[email protected]>
Cc: Julien Grall <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Jun Nakajima <[email protected]>; Kevin Tian <[email protected]>; Stefano Stabellini <[email protected]>; xen-devel <xen- [email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Tim (Xen.org) <[email protected]>
Subject: RE: [PATCH v2] iommu / p2m: add apage_orderparameter to iommu_map/unmap_page()Quoted 42 lines
Quoted 41 lines
Quoted 1 line · On 30.10.18 at 17:56, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Sent: 30 October 2018 16:08xen/common/grant_table.c map_grant_ref( · line 1146
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 29.10.18 at 14:29, <[email protected]> wrote:
xen/common/grant_table.c +1
-0@@ -1142,12 +1142,14 @@ map_grant_ref( {if ( !(kind &MAPKIND_WRITE ) ) err = iommu_map_page(ld, _dfn(mfn_x(mfn)), mfn, + PAGE_ORDER_4K, IOMMUF_readable |
IOMMUF_writable);Quoted 12 lines
xen/common/grant_table.c +1
-0}else if ( act_pin && !old_pin ) {if ( !kind ) err =iommu_map_page (ld,_dfn (mfn_x (mfn)), mfn, +PAGE_ORDER_4K , IOMMUF_readable); }if ( err )@@ -1396,10 +1398,11 @@ unmap_common( kind =mapkind (lgt, rd, op->mfn);xen/common/grant_table.c unmap_common( · line 1407
Quoted 10 lines
xen/common/grant_table.c +3
-2if ( !kind ) - err =iommu_unmap_page (ld,_dfn (mfn_x (op->mfn))); + err =iommu_unmap_page (ld,_dfn (mfn_x (op->mfn)), +PAGE_ORDER_4K );else if ( !(kind &MAPKIND_WRITE ) ) err =iommu_map_page (ld,_dfn (mfn_x (op->mfn)), op->mfn, - IOMMUF_readable); +PAGE_ORDER_4K , IOMMUF_readable);double_gt_unlock (lgt, rgt);I am, btw, uncertain that using
PAGE_ORDER_4Kis correct here:
Other than in the IOMMU code, grant table code isn't tied to a particular architecture, and hence ought to work fine on a port to an architecture with 8k, 16k, or 32k pages.
Quoted 5 lines
Quoted 2 lines
Would you suggest I add an arch specific #define for a grant table page order and then use that?
No, I'd prefer if you used liter 0 zero here.
Ok.
Quoted 61 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
xen/drivers/passthrough/iommu.c +2
-2@@ -305,47 +305,76 @@ void iommu_domain_destroy(struct domain *d) }int iommu_map_page (struct domain *d,dfn_t dfn,mfn_t mfn, -unsigned int flags) +unsigned int page_order,unsigned int flags) {const struct domain_iommu *hd =dom_iommu (d); -int rc; +unsigned long i;if ( !iommu_enabled || !hd->platform_ops )return 0 ;Quoted 8 lines
Quoted 8 lines
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d)
Quoted 8 lines
xen/drivers/passthrough/iommu.c +5
-2- rc = hd->platform_ops->map_page (d, dfn, mfn, flags); -if (unlikely (rc) ) +ASSERT (!(dfn_x (dfn) & ((1ul << page_order) -1 ))); +ASSERT (!(mfn_x (mfn) & ((1ul << page_order) -1 ))); + +for ( i =0 ; i < (1ul << page_order); i++ ) { + int ignored, err = hd->platform_ops->map_page(d,dfn_add(dfn,
Quoted 2 lines
Quoted 2 lines
i),
Quoted 1 line
xen/drivers/passthrough/iommu.c +1
-0+ mfn_add(mfn,i),
Quoted 8 lines
Quoted 8 lines
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d)
Quoted 8 lines
xen/drivers/passthrough/iommu.c +5
-0+ flags); + +if (likely (!err) ) +continue ; +if ( !d->is_shutting_down &&printk_ratelimit () )printk (XENLOG_ERR "d%d: IOMMU mapping dfn %"PRI_dfn" to mfn%"PRI_mfn"
Quoted 8 lines
Quoted 8 lines
failed: %d\n",
Quoted 7 lines
xen/drivers/passthrough/iommu.c +6
-1- d->domain_id, dfn_x(dfn), mfn_x(mfn), rc); + d->domain_id,dfn_x (dfn_add (dfn, i)), + mfn_x(mfn_add(mfn, i)), err); + +while (i--) +/* assign to something to avoid compiler warning */ + ignored = hd->platform_ops->unmap_page(d, dfn_add(dfn,i));
Quoted 8 lines
Quoted 6 lines
Hmm, as said on v1 - please use the original mode (while-if-continue) here. This lets you get away without a local variable that's never read, and which hence future compiler versions may legitimately warn about.
Ok, I clearly don't understand what you mean by 'while-if-continue'
then.
Quoted 1 line
Above I have for-if-continue, which is what I thought you wanted. What
code
Quoted 1 line
structure are you actually looking for?
The one your patch removes elsewhere:
xen/arch/x86/mm/p2m-ept.c out: · line 897
Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +0
-5-while ( i-- ) -/* If statement to satisfy __must_check. */ -if (iommu_unmap_page (p2m->domain, -dfn_add (dfn, i)) ) -continue ;
Oh, ok. Thanks. I'll change it.
Paul
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel