Skip to contentSkip to conversation

iommu / p2m: add a page_order parameter to iommu_map/unmap_page()...

PATCH In review Paul Durrant 5 participants 5 messages Oct 31, 2018 – Nov 19, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 iommu / p2m: add a page_order parameter to iommu_map/unmap_page()...

...and re-name them to iommu_map/unmap() since they no longer necessarily operate on a single 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 0, 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.

This patch also adds emacs boilerplate to xen/iommu.h to avoid tabbing problem.

NOTE: This patch does not modify the underlying vendor IOMMU
implementations to deal with more than a single page at once.

---
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.

v3:
- Re-name iommu_unmap/map_page() to iommu_map/unmap().
- Drop 'ignored' and use if-continue as preferred by Jan.
- Use literal 0 for page order in grant table code.

---
 xen/arch/x86/mm.c                   |  9 ++++---
 xen/arch/x86/mm/p2m-ept.c           | 30 +++------------------
 xen/arch/x86/mm/p2m-pt.c            | 46 +++++++-------------------------
 xen/arch/x86/mm/p2m.c               | 51 ++++++------------------------------
 xen/arch/x86/x86_64/mm.c            |  7 ++---
 xen/common/grant_table.c            | 14 +++++-----
 xen/drivers/passthrough/iommu.c     | 52 +++++++++++++++++++++++++++++--------
 xen/drivers/passthrough/x86/iommu.c |  4 +--
 xen/include/xen/iommu.h             | 16 +++++++++---
 9 files changed, 92 insertions(+), 137 deletions(-)
xen/arch/x86/mm.c +5 -4
index 703f3301a5..4c1cfdcbc6 100644
@@ -2813,11 +2813,12 @@ 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(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,
-                                           IOMMUF_readable |
-                                           IOMMUF_writable);
+                iommu_ret = iommu_map(d, _dfn(mfn_x(mfn)), mfn,
+                                      PAGE_ORDER_4K,
+                                      IOMMUF_readable | IOMMUF_writable);
         }
     }
 
xen/arch/x86/mm/p2m-ept.c +3 -27
index 407e299e50..b2190ee7fd 100644
@@ -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(d, _dfn(gfn), mfn, order, iommu_flags) :
+                iommu_unmap(d, _dfn(gfn), order);
     }
 
     unmap_domain_page(table);
xen/arch/x86/mm/p2m-pt.c +9 -37

67 lines not on this page · raw message

xen/arch/x86/mm/p2m.c +8 -43

75 lines not on this page · raw message

xen/arch/x86/x86_64/mm.c +4 -3
index 543ea030e3..11977f2671 100644
@@ -1436,14 +1436,15 @@ int memory_add(unsigned long spfn, unsigned long epfn, unsigned int pxm)
          !need_iommu_pt_sync(hardware_domain) )
     {
         for ( i = spfn; i < epfn; i++ )
-            if ( iommu_map_page(hardware_domain, _dfn(i), _mfn(i),
-                                IOMMUF_readable | IOMMUF_writable) )
+            if ( iommu_map(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(hardware_domain, _dfn(i), PAGE_ORDER_4K) )
                     continue;
 
             goto destroy_m2p;
xen/common/grant_table.c +7 -7
index 878e668bf5..f9bb76d922 100644
@@ -1141,14 +1141,14 @@ map_grant_ref(
              !(old_pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) )
         {
             if ( !(kind & MAPKIND_WRITE) )
-                err = iommu_map_page(ld, _dfn(mfn_x(mfn)), mfn,
-                                     IOMMUF_readable | IOMMUF_writable);
+                err = iommu_map(ld, _dfn(mfn_x(mfn)), mfn, 0,
+                                IOMMUF_readable | IOMMUF_writable);
         }
         else if ( act_pin && !old_pin )
         {
             if ( !kind )
-                err = iommu_map_page(ld, _dfn(mfn_x(mfn)), mfn,
-                                     IOMMUF_readable);
+                err = iommu_map(ld, _dfn(mfn_x(mfn)), mfn, 0,
+                                IOMMUF_readable);
         }
         if ( err )
         {
@@ -1396,10 +1396,10 @@ unmap_common(
 
         kind = mapkind(lgt, rd, op->mfn);
         if ( !kind )
-            err = iommu_unmap_page(ld, _dfn(mfn_x(op->mfn)));
+            err = iommu_unmap(ld, _dfn(mfn_x(op->mfn)), 0);
         else if ( !(kind & MAPKIND_WRITE) )
-            err = iommu_map_page(ld, _dfn(mfn_x(op->mfn)), op->mfn,
-                                 IOMMUF_readable);
+            err = iommu_map(ld, _dfn(mfn_x(op->mfn)), op->mfn, 0,
+                            IOMMUF_readable);
 
         double_gt_unlock(lgt, rgt);
 
xen/drivers/passthrough/iommu.c +41 -11

89 lines not on this page · raw message

xen/drivers/passthrough/x86/iommu.c +2 -2
index b20bad17de..f00c38f533 100644
@@ -239,8 +239,8 @@ 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),
-                                IOMMUF_readable | IOMMUF_writable);
+            rc = iommu_map(d, _dfn(pfn), _mfn(pfn), PAGE_ORDER_4K,
+                           IOMMUF_readable | IOMMUF_writable);
         if ( rc )
             printk(XENLOG_WARNING " d%d: IOMMU mapping failed: %d\n",
                    d->domain_id, rc);
xen/include/xen/iommu.h +13 -3
index c75333c077..f250b950e2 100644
@@ -89,9 +89,10 @@ 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(struct domain *d, dfn_t dfn, mfn_t mfn,
+                           unsigned int page_order, unsigned int flags);
+int __must_check iommu_unmap(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);
 
@@ -267,3 +268,12 @@ extern struct spinlock iommu_pt_cleanup_lock;
 extern struct page_list_head iommu_pt_cleanup_list;
 
 #endif /* _IOMMU_H_ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v3 1/1
#1 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 31.10.18 at 16:21, <[email protected]> wrote:

...and re-name them to iommu_map/unmap() since they no longer necessarily operate on a single 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 0, 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.

Quoted 7 lines

This patch also adds emacs boilerplate to xen/iommu.h to avoid tabbing problem.

NOTE: This patch does not modify the underlying vendor IOMMU
implementations to deal with more than a single page at once.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v3 1/1
#2 lore raw
In reply to Paul Durrant
Quoted 15 lines

From: Paul Durrant [mailto:[email protected]]
Sent: Wednesday, October 31, 2018 11:22 PM

...and re-name them to iommu_map/unmap() since they no longer necessarily
operate on a single 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 0, 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.

Quoted 7 lines

This patch also adds emacs boilerplate to xen/iommu.h to avoid tabbing problem.

NOTE: This patch does not modify the underlying vendor IOMMU
implementations to deal with more than a single page at once.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v3 1/1
#3 lore raw
In reply to Paul Durrant
Quoted 5 lines · Paul Durrant

...and re-name them to iommu_map/unmap() since they no longer necessarily operate on a single 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 0, the

                         ^d
Quoted 5 lines

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.

Quoted 7 lines

This patch also adds emacs boilerplate to xen/iommu.h to avoid tabbing problem.

NOTE: This patch does not modify the underlying vendor IOMMU
implementations to deal with more than a single page at once.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v3 1/1
#4 lore raw
In reply to Paul Durrant
Quoted 10 lines · Paul Durrant

...and re-name them to iommu_map/unmap() since they no longer necessarily operate on a single 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 0, 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.

Quoted 7 lines

This patch also adds emacs boilerplate to xen/iommu.h to avoid tabbing problem.

NOTE: This patch does not modify the underlying vendor IOMMU
implementations to deal with more than a single page at once.

Good stuff:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel