diff mbox series

[Xen-devel,v4,14/16] xen/grant: Switch common/grant_table.c to use typesafe MFN

Message ID 20180221140259.29360-15-julien.grall@arm.com
State New
Headers show
Series xen: Convert page_to_mfn and mfn_to_page to use typesafe MFN | expand

Commit Message

Julien Grall Feb. 21, 2018, 2:02 p.m. UTC
No functional change intended.

Signed-off-by: Julien Grall <julien.grall@arm.com>

---

Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Julien Grall <julien.grall@arm.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Tim Deegan <tim@xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>

    Changes in v4:
        - Patch added
---
 xen/arch/arm/mm.c                 |   2 +-
 xen/common/grant_table.c          | 145 ++++++++++++++++++++------------------
 xen/include/asm-arm/grant_table.h |   2 +-
 xen/include/asm-x86/grant_table.h |   2 +-
 4 files changed, 81 insertions(+), 70 deletions(-)

Comments

Wei Liu Feb. 23, 2018, 5:30 p.m. UTC | #1
On Wed, Feb 21, 2018 at 02:02:57PM +0000, Julien Grall wrote:
> No functional change intended.
> 
> Signed-off-by: Julien Grall <julien.grall@arm.com>

Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Jan Beulich March 2, 2018, 3:54 p.m. UTC | #2
>>> On 21.02.18 at 15:02, <julien.grall@arm.com> wrote:
> @@ -872,7 +879,7 @@ map_grant_ref(
>      struct grant_table *lgt, *rgt;
>      struct vcpu   *led;
>      grant_handle_t handle;
> -    unsigned long  frame = 0;
> +    mfn_t frame = _mfn(0);

If the initializer is needed at all, I think it should again become
INVALID_MFN. Same in a few other places.

> --- a/xen/include/asm-x86/grant_table.h
> +++ b/xen/include/asm-x86/grant_table.h
> @@ -76,7 +76,7 @@ static inline unsigned int gnttab_dom0_max(void)
>  #define gnttab_status_gmfn(d, t, i)                     \
>      (mfn_to_gmfn(d, gnttab_status_mfn(t, i)))
>  
> -#define gnttab_mark_dirty(d, f) paging_mark_dirty((d), _mfn(f))
> +#define gnttab_mark_dirty(d, f) paging_mark_dirty((d), f)

Please take the opportunity and also drop the stray parentheses
around d.

With these taken care of and with Wei's R-b
Acked-by: Jan Beulich <jbeulich@suse.com>

Jan
Julien Grall March 2, 2018, 3:59 p.m. UTC | #3
Hi Jan,

On 02/03/18 15:54, Jan Beulich wrote:
>>>> On 21.02.18 at 15:02, <julien.grall@arm.com> wrote:
>> @@ -872,7 +879,7 @@ map_grant_ref(
>>       struct grant_table *lgt, *rgt;
>>       struct vcpu   *led;
>>       grant_handle_t handle;
>> -    unsigned long  frame = 0;
>> +    mfn_t frame = _mfn(0);
> 
> If the initializer is needed at all, I think it should again become
> INVALID_MFN. Same in a few other places.

I didn't switch to INVALID_MFN because I wasn't sure if some place in 
the code where relying on 0. If you think it is fine, then I am more 
thank happy to switch to INVALID_MFN.

> 
>> --- a/xen/include/asm-x86/grant_table.h
>> +++ b/xen/include/asm-x86/grant_table.h
>> @@ -76,7 +76,7 @@ static inline unsigned int gnttab_dom0_max(void)
>>   #define gnttab_status_gmfn(d, t, i)                     \
>>       (mfn_to_gmfn(d, gnttab_status_mfn(t, i)))
>>   
>> -#define gnttab_mark_dirty(d, f) paging_mark_dirty((d), _mfn(f))
>> +#define gnttab_mark_dirty(d, f) paging_mark_dirty((d), f)
> 
> Please take the opportunity and also drop the stray parentheses
> around d.

Sure.

> 
> With these taken care of and with Wei's R-b
> Acked-by: Jan Beulich <jbeulich@suse.com>

Cheers,
Jan Beulich March 2, 2018, 4:12 p.m. UTC | #4
>>> On 02.03.18 at 16:59, <julien.grall@arm.com> wrote:
> On 02/03/18 15:54, Jan Beulich wrote:
>>>>> On 21.02.18 at 15:02, <julien.grall@arm.com> wrote:
>>> @@ -872,7 +879,7 @@ map_grant_ref(
>>>       struct grant_table *lgt, *rgt;
>>>       struct vcpu   *led;
>>>       grant_handle_t handle;
>>> -    unsigned long  frame = 0;
>>> +    mfn_t frame = _mfn(0);
>> 
>> If the initializer is needed at all, I think it should again become
>> INVALID_MFN. Same in a few other places.
> 
> I didn't switch to INVALID_MFN because I wasn't sure if some place in 
> the code where relying on 0. If you think it is fine, then I am more 
> thank happy to switch to INVALID_MFN.

Well, as said - it looks as if the initializer isn't needed at all, in
which case it's value really is a don't care.

Jan
diff mbox series

Patch

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index 4268dd5c2d..db74466a16 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -1413,7 +1413,7 @@  void gnttab_clear_flag(unsigned long nr, uint16_t *addr)
     } while (cmpxchg(addr, old, old & mask) != old);
 }
 
-void gnttab_mark_dirty(struct domain *d, unsigned long l)
+void gnttab_mark_dirty(struct domain *d, mfn_t mfn)
 {
     /* XXX: mark dirty */
     static int warning;
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index c555c1d451..e9a81b66be 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -40,6 +40,12 @@ 
 #include <xsm/xsm.h>
 #include <asm/flushtlb.h>
 
+/* Override macros from asm/page.h to make them work with mfn_t */
+#undef page_to_mfn
+#define page_to_mfn(pg) _mfn(__page_to_mfn(pg))
+#undef mfn_to_page
+#define mfn_to_page(mfn) __mfn_to_page(mfn_x(mfn))
+
 /* Per-domain grant information. */
 struct grant_table {
     /*
@@ -132,7 +138,7 @@  struct gnttab_unmap_common {
 
     /* Shared state beteen *_unmap and *_unmap_complete */
     uint16_t done;
-    unsigned long frame;
+    mfn_t frame;
     struct domain *rd;
     grant_ref_t ref;
 };
@@ -231,7 +237,7 @@  struct active_grant_entry {
                                 grant.                                */
     grant_ref_t   trans_gref;
     struct domain *trans_domain;
-    unsigned long frame;  /* Frame being granted.                     */
+    mfn_t         frame;  /* Frame being granted.                     */
 #ifndef NDEBUG
     gfn_t         gfn;    /* Guest's idea of the frame being granted. */
 #endif
@@ -336,14 +342,14 @@  static inline unsigned int grant_to_status_frames(unsigned int grant_frames)
    If rc == GNTST_okay, *page contains the page struct with a ref taken.
    Caller must do put_page(*page).
    If any error, *page = NULL, *frame = INVALID_MFN, no ref taken. */
-static int get_paged_frame(unsigned long gfn, unsigned long *frame,
+static int get_paged_frame(unsigned long gfn, mfn_t *frame,
                            struct page_info **page, bool readonly,
                            struct domain *rd)
 {
     int rc = GNTST_okay;
     p2m_type_t p2mt;
 
-    *frame = mfn_x(INVALID_MFN);
+    *frame = INVALID_MFN;
     *page = get_page_from_gfn(rd, gfn, &p2mt,
                               readonly ? P2M_ALLOC : P2M_UNSHARE);
     if ( !*page )
@@ -788,7 +794,7 @@  static int _set_status(unsigned gt_version,
 
 static struct active_grant_entry *grant_map_exists(const struct domain *ld,
                                                    struct grant_table *rgt,
-                                                   unsigned long mfn,
+                                                   mfn_t mfn,
                                                    grant_ref_t *cur_ref)
 {
     grant_ref_t ref, max_iter;
@@ -807,7 +813,8 @@  static struct active_grant_entry *grant_map_exists(const struct domain *ld,
     {
         struct active_grant_entry *act = active_entry_acquire(rgt, ref);
 
-        if ( act->pin && act->domid == ld->domain_id && act->frame == mfn )
+        if ( act->pin && act->domid == ld->domain_id &&
+             mfn_eq(act->frame, mfn) )
             return act;
         active_entry_release(act);
     }
@@ -824,7 +831,7 @@  static struct active_grant_entry *grant_map_exists(const struct domain *ld,
 #define MAPKIND_READ 1
 #define MAPKIND_WRITE 2
 static unsigned int mapkind(
-    struct grant_table *lgt, const struct domain *rd, unsigned long mfn)
+    struct grant_table *lgt, const struct domain *rd, mfn_t mfn)
 {
     struct grant_mapping *map;
     grant_handle_t handle, limit = lgt->maptrack_limit;
@@ -849,7 +856,7 @@  static unsigned int mapkind(
         if ( !(map->flags & (GNTMAP_device_map|GNTMAP_host_map)) ||
              map->domid != rd->domain_id )
             continue;
-        if ( _active_entry(rd->grant_table, map->ref).frame == mfn )
+        if ( mfn_eq(_active_entry(rd->grant_table, map->ref).frame, mfn) )
             kind |= map->flags & GNTMAP_readonly ?
                     MAPKIND_READ : MAPKIND_WRITE;
     }
@@ -872,7 +879,7 @@  map_grant_ref(
     struct grant_table *lgt, *rgt;
     struct vcpu   *led;
     grant_handle_t handle;
-    unsigned long  frame = 0;
+    mfn_t frame = _mfn(0);
     struct page_info *pg = NULL;
     int            rc = GNTST_okay;
     u32            old_pin;
@@ -999,7 +1006,7 @@  map_grant_ref(
     /* pg may be set, with a refcount included, from get_paged_frame(). */
     if ( !pg )
     {
-        pg = mfn_valid(_mfn(frame)) ? mfn_to_page(frame) : NULL;
+        pg = mfn_valid(frame) ? mfn_to_page(frame) : NULL;
         if ( pg )
             owner = page_get_owner_and_reference(pg);
     }
@@ -1025,18 +1032,18 @@  map_grant_ref(
             goto undo_out;
         }
 
-        if ( !iomem_access_permitted(rd, frame, frame) )
+        if ( !iomem_access_permitted(rd, mfn_x(frame), mfn_x(frame)) )
         {
             gdprintk(XENLOG_WARNING,
-                     "Iomem mapping not permitted %lx (domain %d)\n",
-                     frame, rd->domain_id);
+                     "Iomem mapping not permitted %#"PRI_mfn" (domain %d)\n",
+                     mfn_x(frame), rd->domain_id);
             rc = GNTST_general_error;
             goto undo_out;
         }
 
         if ( op->flags & GNTMAP_host_map )
         {
-            rc = create_grant_host_mapping(op->host_addr, _mfn(frame), op->flags,
+            rc = create_grant_host_mapping(op->host_addr, frame, op->flags,
                                            cache_flags);
             if ( rc != GNTST_okay )
                 goto undo_out;
@@ -1076,7 +1083,7 @@  map_grant_ref(
                 typecnt++;
             }
 
-            rc = create_grant_host_mapping(op->host_addr, _mfn(frame), op->flags, 0);
+            rc = create_grant_host_mapping(op->host_addr, frame, op->flags, 0);
             if ( rc != GNTST_okay )
                 goto undo_out;
 
@@ -1087,8 +1094,8 @@  map_grant_ref(
     {
     could_not_pin:
         if ( !rd->is_dying )
-            gdprintk(XENLOG_WARNING, "Could not pin grant frame %lx\n",
-                     frame);
+            gdprintk(XENLOG_WARNING, "Could not pin grant frame %#"PRI_mfn"\n",
+                     mfn_x(frame));
         rc = GNTST_general_error;
         goto undo_out;
     }
@@ -1108,13 +1115,14 @@  map_grant_ref(
              !(old_pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask)) )
         {
             if ( !(kind & MAPKIND_WRITE) )
-                err = iommu_map_page(ld, frame, frame,
+                err = iommu_map_page(ld, mfn_x(frame), mfn_x(frame),
                                      IOMMUF_readable|IOMMUF_writable);
         }
         else if ( act_pin && !old_pin )
         {
             if ( !kind )
-                err = iommu_map_page(ld, frame, frame, IOMMUF_readable);
+                err = iommu_map_page(ld, mfn_x(frame), mfn_x(frame),
+                                     IOMMUF_readable);
         }
         if ( err )
         {
@@ -1143,7 +1151,7 @@  map_grant_ref(
     if ( need_iommu )
         double_gt_unlock(lgt, rgt);
 
-    op->dev_bus_addr = (u64)frame << PAGE_SHIFT;
+    op->dev_bus_addr = mfn_to_maddr(frame);
     op->handle       = handle;
     op->status       = GNTST_okay;
 
@@ -1153,7 +1161,7 @@  map_grant_ref(
  undo_out:
     if ( host_map_created )
     {
-        replace_grant_host_mapping(op->host_addr, _mfn(frame), 0, op->flags);
+        replace_grant_host_mapping(op->host_addr, frame, 0, op->flags);
         gnttab_flush_tlb(ld);
     }
 
@@ -1331,15 +1339,15 @@  unmap_common(
     op->frame = act->frame;
 
     if ( op->dev_bus_addr &&
-         unlikely(op->dev_bus_addr != pfn_to_paddr(act->frame)) )
+         unlikely(op->dev_bus_addr != mfn_to_maddr(act->frame)) )
         PIN_FAIL(act_release_out, GNTST_general_error,
                  "Bus address doesn't match gntref (%"PRIx64" != %"PRIpaddr")\n",
-                 op->dev_bus_addr, pfn_to_paddr(act->frame));
+                 op->dev_bus_addr, mfn_to_maddr(act->frame));
 
     if ( op->host_addr && (flags & GNTMAP_host_map) )
     {
         if ( (rc = replace_grant_host_mapping(op->host_addr,
-                                              _mfn(op->frame), op->new_addr,
+                                              op->frame, op->new_addr,
                                               flags)) < 0 )
             goto act_release_out;
 
@@ -1376,9 +1384,10 @@  unmap_common(
 
         kind = mapkind(lgt, rd, op->frame);
         if ( !kind )
-            err = iommu_unmap_page(ld, op->frame);
+            err = iommu_unmap_page(ld, mfn_x(op->frame));
         else if ( !(kind & MAPKIND_WRITE) )
-            err = iommu_map_page(ld, op->frame, op->frame, IOMMUF_readable);
+            err = iommu_map_page(ld, mfn_x(op->frame),
+                                 mfn_x(op->frame), IOMMUF_readable);
 
         double_gt_unlock(lgt, rgt);
 
@@ -1429,7 +1438,7 @@  unmap_common_complete(struct gnttab_unmap_common *op)
 
     if ( op->done & GNTMAP_device_map )
     {
-        if ( !is_iomem_page(_mfn(act->frame)) )
+        if ( !is_iomem_page(act->frame) )
         {
             if ( op->done & GNTMAP_readonly )
                 put_page(pg);
@@ -1446,7 +1455,7 @@  unmap_common_complete(struct gnttab_unmap_common *op)
 
     if ( op->done & GNTMAP_host_map )
     {
-        if ( !is_iomem_page(_mfn(op->frame)) )
+        if ( !is_iomem_page(op->frame) )
         {
             if ( gnttab_host_mapping_get_page_type(op->done & GNTMAP_readonly,
                                                    ld, rd) )
@@ -1487,7 +1496,7 @@  unmap_grant_ref(
     common->done = 0;
     common->new_addr = 0;
     common->rd = NULL;
-    common->frame = 0;
+    common->frame = _mfn(0);
 
     unmap_common(common);
     op->status = common->status;
@@ -1553,7 +1562,7 @@  unmap_and_replace(
     common->done = 0;
     common->dev_bus_addr = 0;
     common->rd = NULL;
-    common->frame = 0;
+    common->frame = _mfn(0);
 
     unmap_common(common);
     op->status = common->status;
@@ -2011,7 +2020,7 @@  gnttab_transfer(
     struct page_info *page;
     int i;
     struct gnttab_transfer gop;
-    unsigned long mfn;
+    mfn_t mfn;
     unsigned int max_bitsize;
     struct active_grant_entry *act;
 
@@ -2035,16 +2044,16 @@  gnttab_transfer(
         {
             p2m_type_t p2mt;
 
-            mfn = mfn_x(get_gfn_unshare(d, gop.mfn, &p2mt));
+            mfn = get_gfn_unshare(d, gop.mfn, &p2mt);
             if ( p2m_is_shared(p2mt) || !p2m_is_valid(p2mt) )
-                mfn = mfn_x(INVALID_MFN);
+                mfn = INVALID_MFN;
         }
 #else
-        mfn = mfn_x(gfn_to_mfn(d, _gfn(gop.mfn)));
+        mfn = gfn_to_mfn(d, _gfn(gop.mfn));
 #endif
 
         /* Check the passed page frame for basic validity. */
-        if ( unlikely(!mfn_valid(_mfn(mfn))) )
+        if ( unlikely(!mfn_valid(mfn)) )
         {
             put_gfn(d, gop.mfn);
             gdprintk(XENLOG_INFO, "out-of-range %lx\n", (unsigned long)gop.mfn);
@@ -2060,12 +2069,13 @@  gnttab_transfer(
             goto copyback;
         }
 
-        rc = guest_physmap_remove_page(d, _gfn(gop.mfn), _mfn(mfn), 0);
+        rc = guest_physmap_remove_page(d, _gfn(gop.mfn), mfn, 0);
         gnttab_flush_tlb(d);
         if ( rc )
         {
-            gdprintk(XENLOG_INFO, "can't remove GFN %"PRI_xen_pfn" (MFN %lx)\n",
-                     gop.mfn, mfn);
+            gdprintk(XENLOG_INFO,
+                     "can't remove GFN %"PRI_xen_pfn" (MFN %#"PRI_mfn")\n",
+                     gop.mfn, mfn_x(mfn));
             gop.status = GNTST_general_error;
             goto put_gfn_and_copyback;
         }
@@ -2094,7 +2104,7 @@  gnttab_transfer(
             e, e->grant_table->gt_version > 1 || paging_mode_translate(e)
                ? BITS_PER_LONG + PAGE_SHIFT : 32 + PAGE_SHIFT);
         if ( max_bitsize < BITS_PER_LONG + PAGE_SHIFT &&
-             (mfn >> (max_bitsize - PAGE_SHIFT)) )
+             (mfn_x(mfn) >> (max_bitsize - PAGE_SHIFT)) )
         {
             struct page_info *new_page;
 
@@ -2106,7 +2116,7 @@  gnttab_transfer(
                 goto unlock_and_copyback;
             }
 
-            copy_domain_page(_mfn(page_to_mfn(new_page)), _mfn(mfn));
+            copy_domain_page(page_to_mfn(new_page), mfn);
 
             page->count_info &= ~(PGC_count_mask|PGC_allocated);
             free_domheap_page(page);
@@ -2183,18 +2193,17 @@  gnttab_transfer(
         {
             grant_entry_v1_t *sha = &shared_entry_v1(e->grant_table, gop.ref);
 
-            guest_physmap_add_page(e, _gfn(sha->frame), _mfn(mfn), 0);
+            guest_physmap_add_page(e, _gfn(sha->frame), mfn, 0);
             if ( !paging_mode_translate(e) )
-                sha->frame = mfn;
+                sha->frame = mfn_x(mfn);
         }
         else
         {
             grant_entry_v2_t *sha = &shared_entry_v2(e->grant_table, gop.ref);
 
-            guest_physmap_add_page(e, _gfn(sha->full_page.frame),
-                                   _mfn(mfn), 0);
+            guest_physmap_add_page(e, _gfn(sha->full_page.frame), mfn, 0);
             if ( !paging_mode_translate(e) )
-                sha->full_page.frame = mfn;
+                sha->full_page.frame = mfn_x(mfn);
         }
         smp_wmb();
         shared_entry_header(e->grant_table, gop.ref)->flags |=
@@ -2230,7 +2239,7 @@  release_grant_for_copy(
     struct grant_table *rgt = rd->grant_table;
     grant_entry_header_t *sha;
     struct active_grant_entry *act;
-    unsigned long r_frame;
+    mfn_t r_frame;
     uint16_t *status;
     grant_ref_t trans_gref;
     struct domain *td;
@@ -2307,7 +2316,7 @@  static void fixup_status_for_copy_pin(const struct active_grant_entry *act,
 static int
 acquire_grant_for_copy(
     struct domain *rd, grant_ref_t gref, domid_t ldom, bool readonly,
-    unsigned long *frame, struct page_info **page,
+    mfn_t *frame, struct page_info **page,
     uint16_t *page_off, uint16_t *length, bool allow_transitive)
 {
     struct grant_table *rgt = rd->grant_table;
@@ -2319,7 +2328,7 @@  acquire_grant_for_copy(
     domid_t trans_domid;
     grant_ref_t trans_gref;
     struct domain *td;
-    unsigned long grant_frame;
+    mfn_t grant_frame;
     uint16_t trans_page_off;
     uint16_t trans_length;
     bool is_sub_page;
@@ -2420,7 +2429,8 @@  acquire_grant_for_copy(
          */
         if ( rgt->gt_version != 2 ||
              act->pin != old_pin ||
-             (old_pin && (act->domid != ldom || act->frame != grant_frame ||
+             (old_pin && (act->domid != ldom ||
+                          !mfn_eq(act->frame, grant_frame) ||
                           act->start != trans_page_off ||
                           act->length != trans_length ||
                           act->trans_domain != td ||
@@ -2512,7 +2522,7 @@  acquire_grant_for_copy(
     }
     else
     {
-        ASSERT(mfn_valid(_mfn(act->frame)));
+        ASSERT(mfn_valid(act->frame));
         *page = mfn_to_page(act->frame);
         td = page_get_owner_and_reference(*page);
         /*
@@ -2567,7 +2577,7 @@  struct gnttab_copy_buf {
 
     /* Mapped etc. */
     struct domain *domain;
-    unsigned long frame;
+    mfn_t frame;
     struct page_info *page;
     void *virt;
     bool_t read_only;
@@ -2698,15 +2708,16 @@  static int gnttab_copy_claim_buf(const struct gnttab_copy *op,
         if ( !get_page_type(buf->page, PGT_writable_page) )
         {
             if ( !buf->domain->is_dying )
-                gdprintk(XENLOG_WARNING, "Could not get writable frame %lx\n",
-                         buf->frame);
+                gdprintk(XENLOG_WARNING,
+                         "Could not get writable frame %#"PRI_mfn"\n",
+                         mfn_x(buf->frame));
             rc = GNTST_general_error;
             goto out;
         }
         buf->have_type = 1;
     }
 
-    buf->virt = map_domain_page(_mfn(buf->frame));
+    buf->virt = map_domain_page(buf->frame);
     rc = GNTST_okay;
 
  out:
@@ -3204,7 +3215,7 @@  static int cache_flush(const gnttab_cache_flush_t *cflush, grant_ref_t *cur_ref)
 {
     struct domain *d, *owner;
     struct page_info *page;
-    unsigned long mfn;
+    mfn_t mfn;
     struct active_grant_entry *act = NULL;
     void *v;
     int ret;
@@ -3223,9 +3234,9 @@  static int cache_flush(const gnttab_cache_flush_t *cflush, grant_ref_t *cur_ref)
         return -EOPNOTSUPP;
 
     d = rcu_lock_current_domain();
-    mfn = cflush->a.dev_bus_addr >> PAGE_SHIFT;
+    mfn = maddr_to_mfn(cflush->a.dev_bus_addr);
 
-    if ( !mfn_valid(_mfn(mfn)) )
+    if ( !mfn_valid(mfn) )
     {
         rcu_unlock_domain(d);
         return -EINVAL;
@@ -3253,7 +3264,7 @@  static int cache_flush(const gnttab_cache_flush_t *cflush, grant_ref_t *cur_ref)
         }
     }
 
-    v = map_domain_page(_mfn(mfn));
+    v = map_domain_page(mfn);
     v += cflush->offset;
 
     if ( (cflush->op & GNTTAB_CACHE_INVAL) && (cflush->op & GNTTAB_CACHE_CLEAN) )
@@ -3570,7 +3581,7 @@  gnttab_release_mappings(
             {
                 BUG_ON(!(act->pin & GNTPIN_devr_mask));
                 act->pin -= GNTPIN_devr_inc;
-                if ( !is_iomem_page(_mfn(act->frame)) )
+                if ( !is_iomem_page(act->frame) )
                     put_page(pg);
             }
 
@@ -3579,7 +3590,7 @@  gnttab_release_mappings(
                 BUG_ON(!(act->pin & GNTPIN_hstr_mask));
                 act->pin -= GNTPIN_hstr_inc;
                 if ( gnttab_release_host_mappings(d) &&
-                     !is_iomem_page(_mfn(act->frame)) )
+                     !is_iomem_page(act->frame) )
                     put_page(pg);
             }
         }
@@ -3589,7 +3600,7 @@  gnttab_release_mappings(
             {
                 BUG_ON(!(act->pin & GNTPIN_devw_mask));
                 act->pin -= GNTPIN_devw_inc;
-                if ( !is_iomem_page(_mfn(act->frame)) )
+                if ( !is_iomem_page(act->frame) )
                     put_page_and_type(pg);
             }
 
@@ -3598,7 +3609,7 @@  gnttab_release_mappings(
                 BUG_ON(!(act->pin & GNTPIN_hstw_mask));
                 act->pin -= GNTPIN_hstw_inc;
                 if ( gnttab_release_host_mappings(d) &&
-                     !is_iomem_page(_mfn(act->frame)) )
+                     !is_iomem_page(act->frame) )
                 {
                     if ( gnttab_host_mapping_get_page_type((map->flags &
                                                             GNTMAP_readonly),
@@ -3650,12 +3661,12 @@  void grant_table_warn_active_grants(struct domain *d)
 #ifndef NDEBUG
                    "GFN %lx, "
 #endif
-                   "MFN: %lx)\n",
+                   "MFN: %#"PRI_mfn")\n",
                    d->domain_id, ref,
 #ifndef NDEBUG
                    gfn_x(act->gfn),
 #endif
-                   act->frame);
+                   mfn_x(act->frame));
         active_entry_release(act);
     }
 
@@ -3855,9 +3866,9 @@  static void gnttab_usage_print(struct domain *rd)
 
         first = 0;
 
-        /*      [0xXXX]  ddddd 0xXXXXXX 0xXXXXXXXX      ddddd 0xXXXXXX 0xXX */
-        printk("[0x%03x]  %5d 0x%06lx 0x%08x      %5d 0x%06"PRIx64" 0x%02x\n",
-               ref, act->domid, act->frame, act->pin,
+        /*      [0xXXX]  ddddd 0xXXXXX 0xXXXXXXXX      ddddd 0xXXXXXX 0xXX */
+        printk("[0x%03x]  %5d 0x%"PRI_mfn" 0x%08x      %5d 0x%06"PRIx64" 0x%02x\n",
+               ref, act->domid, mfn_x(act->frame), act->pin,
                sha->domid, frame, status);
         active_entry_release(act);
     }
diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_table.h
index ffff18d456..4c87870f48 100644
--- a/xen/include/asm-arm/grant_table.h
+++ b/xen/include/asm-arm/grant_table.h
@@ -18,7 +18,7 @@  int create_grant_host_mapping(unsigned long gpaddr, mfn_t mfn,
 #define gnttab_host_mapping_get_page_type(ro, ld, rd) (0)
 int replace_grant_host_mapping(unsigned long gpaddr, mfn_t mfn,
                                unsigned long new_gpaddr, unsigned int flags);
-void gnttab_mark_dirty(struct domain *d, unsigned long l);
+void gnttab_mark_dirty(struct domain *d, mfn_t mfn);
 #define gnttab_create_status_page(d, t, i) do {} while (0)
 #define gnttab_status_gmfn(d, t, i) (0)
 #define gnttab_release_host_mappings(domain) 1
diff --git a/xen/include/asm-x86/grant_table.h b/xen/include/asm-x86/grant_table.h
index e40ac8e3e7..32079274fe 100644
--- a/xen/include/asm-x86/grant_table.h
+++ b/xen/include/asm-x86/grant_table.h
@@ -76,7 +76,7 @@  static inline unsigned int gnttab_dom0_max(void)
 #define gnttab_status_gmfn(d, t, i)                     \
     (mfn_to_gmfn(d, gnttab_status_mfn(t, i)))
 
-#define gnttab_mark_dirty(d, f) paging_mark_dirty((d), _mfn(f))
+#define gnttab_mark_dirty(d, f) paging_mark_dirty((d), f)
 
 static inline void gnttab_clear_flag(unsigned int nr, uint16_t *st)
 {