Skip to contentSkip to conversation

xen/arm: Properly disable M2P on Arm.

PATCH Superseded Julien Grall 6 participants 77 messages May 7, 2019 – May 29, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover xen/arm: Properly disable M2P on Arm.

Hi all,

Arm never supported a M2P yet there are some helpers implemented to deal with the common code. However, the implementation of mfn_to_gmfn is completely bogus.

This series aims to properly disable the M2P on Arm. See patch #8 for the rationale regarding the lack of M2P on Arm.

While looking at the code, I also continued to convert some code to use typesafe MFN/GFN.

Cheers,

Julien Grall (14):
xen/arm: Use mfn_to_pdx instead of pfn_to_pdx when possible xen/x86: Constify the parameter "d" in mfn_to_gfn xen/x86: Make mfn_to_gfn typesafe
xen/x86: Use mfn_to_gfn rather than mfn_to_gmfn xen/grant-table: Make arch specific macros typesafe
xen: Convert hotplug page function to use typesafe MFN
xen: Convert is_xen_fixed_mfn to use typesafe MFN
xen: Convert is_xen_heap_mfn to use typesafe MFN
xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call
xen: Remove mfn_to_gmfn macro
xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline
function
xen/x86: pv: Convert update_intpte() to use typesafe MFN xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN xen/mm: Provide dummy M2P-related helpers when !CONFIG_HAVE_M2P

 xen/arch/arm/mm.c                   |   2 +-
 xen/arch/x86/Kconfig                |   1 +
 xen/arch/x86/cpu/mcheck/mcaction.c  |  20 ++++---
 xen/arch/x86/domain.c               |  34 ++++++-----
 xen/arch/x86/mm.c                   | 115 ++++++++++++++++++------------------
 xen/arch/x86/mm/mem_sharing.c       |  19 +++---
 xen/arch/x86/mm/p2m-pod.c           |   4 +-
 xen/arch/x86/mm/p2m-pt.c            |  37 ++++++------
 xen/arch/x86/mm/p2m.c               |  70 +++++++++++-----------
 xen/arch/x86/mm/paging.c            |   4 +-
 xen/arch/x86/mm/shadow/common.c     |  31 ++++++----
 xen/arch/x86/mm/shadow/multi.c      |   6 +-
 xen/arch/x86/pv/dom0_build.c        |   6 +-
 xen/arch/x86/pv/emul-priv-op.c      |   4 +-
 xen/arch/x86/pv/grant_table.c       |   6 +-
 xen/arch/x86/pv/mm.h                |   6 +-
 xen/arch/x86/pv/ro-page-fault.c     |   2 +-
 xen/arch/x86/tboot.c                |   2 +-
 xen/arch/x86/x86_64/traps.c         |  41 ++++++-------
 xen/common/Kconfig                  |   3 +
 xen/common/domctl.c                 |   2 +-
 xen/common/grant_table.c            |   4 +-
 xen/common/memory.c                 |   6 +-
 xen/common/page_alloc.c             |  28 ++++-----
 xen/common/sysctl.c                 |  14 ++---
 xen/drivers/passthrough/iommu.c     |  13 ++--
 xen/drivers/passthrough/x86/iommu.c |  16 ++---
 xen/include/asm-arm/domain.h        |   5 ++
 xen/include/asm-arm/grant_table.h   |  12 ++--
 xen/include/asm-arm/mm.h            |  31 +++-------
 xen/include/asm-x86/grant_table.h   |  19 +++---
 xen/include/asm-x86/mm.h            |  46 +++++++--------
 xen/include/asm-x86/p2m.h           |   6 +-
 xen/include/public/domctl.h         |   4 ++
 xen/include/xen/domain.h            |   8 +++
 xen/include/xen/mm.h                |  20 ++++++-
 36 files changed, 344 insertions(+), 303 deletions(-)
Signature · 7 lines
2.11.0


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

PATCH 1/14 xen/arm: Use mfn_to_pdx instead of pfn_to_pdx when possible

mfn_to_pdx adds more safety than pfn_to_pdx. Replace all but on place in the Arm code to use the former.

No functional changes.

---
There are still one use of pfn_to_pdx in the Arm code (see mfn_valid). Ideally we would want to switch __mfn_valid(...) to be typesafe but it looks like it does not compile on x86. For the details see: <[email protected]>

This is unlikely going to be handled in this series.

---
 xen/arch/arm/mm.c        | 2 +-
 xen/include/asm-arm/mm.h | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
xen/arch/arm/mm.c +1 -1
index 01ae2cccc0..be5338bb4c 100644
@@ -886,7 +886,7 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe)
     int i;
 #endif
 
-    frametable_base_pdx = pfn_to_pdx(ps >> PAGE_SHIFT);
+    frametable_base_pdx = mfn_to_pdx(maddr_to_mfn(ps));
     /* Round up to 2M or 32M boundary, as appropriate. */
     frametable_size = ROUNDUP(frametable_size, mapping_size);
     base_mfn = alloc_boot_pages(frametable_size >> PAGE_SHIFT, 32<<(20-12));
xen/include/asm-arm/mm.h +3 -3
index eafa26f56e..7b6aaf5e3f 100644
@@ -225,7 +225,7 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)
 /* Convert between frame number and address formats.  */
 #define pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT)
 #define paddr_to_pfn(pa)  ((unsigned long)((pa) >> PAGE_SHIFT))
-#define paddr_to_pdx(pa)    pfn_to_pdx(paddr_to_pfn(pa))
+#define paddr_to_pdx(pa)    mfn_to_pdx(maddr_to_mfn(pa))
 #define gfn_to_gaddr(gfn)   pfn_to_paddr(gfn_x(gfn))
 #define gaddr_to_gfn(ga)    _gfn(paddr_to_pfn(ga))
 #define mfn_to_maddr(mfn)   pfn_to_paddr(mfn_x(mfn))
@@ -253,7 +253,7 @@ static inline void *maddr_to_virt(paddr_t ma)
 #else
 static inline void *maddr_to_virt(paddr_t ma)
 {
-    ASSERT(pfn_to_pdx(ma >> PAGE_SHIFT) < (DIRECTMAP_SIZE >> PAGE_SHIFT));
+    ASSERT(mfn_to_pdx(maddr_to_mfn(ma)) < (DIRECTMAP_SIZE >> PAGE_SHIFT));
     return (void *)(XENHEAP_VIRT_START -
                     mfn_to_maddr(xenheap_mfn_start) +
                     ((ma & ma_va_bottom_mask) |
@@ -301,7 +301,7 @@ static inline struct page_info *virt_to_page(const void *v)
     ASSERT(va < xenheap_virt_end);
 
     pdx = (va - XENHEAP_VIRT_START) >> PAGE_SHIFT;
-    pdx += pfn_to_pdx(mfn_x(xenheap_mfn_start));
+    pdx += mfn_to_pdx(xenheap_mfn_start);
     return frame_table + pdx - frametable_base_pdx;
 }
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/14
#2 lore raw

Re: [PATCH 01/14] xen/arm: Use mfn_to_pdx instead of pfn_to_pdx when possible

Quoted 6 lines · Julien Grall

mfn_to_pdx adds more safety than pfn_to_pdx. Replace all but on place in the Arm code to use the former.

No functional changes.

Quoted 59 lines

---
There are still one use of pfn_to_pdx in the Arm code (see mfn_valid). Ideally we would want to switch __mfn_valid(...) to be typesafe but it looks like it does not compile on x86. For the details see: <[email protected]>

This is unlikely going to be handled in this series.

---
 xen/arch/arm/mm.c        | 2 +-
 xen/include/asm-arm/mm.h | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
xen/arch/arm/mm.c +1 -1
index 01ae2cccc0..be5338bb4c 100644
@@ -886,7 +886,7 @@ void __init setup_frametable_mappings(paddr_t ps, paddr_t pe)
     int i;
 #endif
 
-    frametable_base_pdx = pfn_to_pdx(ps >> PAGE_SHIFT);
+    frametable_base_pdx = mfn_to_pdx(maddr_to_mfn(ps));
     /* Round up to 2M or 32M boundary, as appropriate. */
     frametable_size = ROUNDUP(frametable_size, mapping_size);
     base_mfn = alloc_boot_pages(frametable_size >> PAGE_SHIFT, 32<<(20-12));
xen/include/asm-arm/mm.h +3 -3
index eafa26f56e..7b6aaf5e3f 100644
@@ -225,7 +225,7 @@ static inline void __iomem *ioremap_wc(paddr_t start, size_t len)
 /* Convert between frame number and address formats.  */
 #define pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT)
 #define paddr_to_pfn(pa)  ((unsigned long)((pa) >> PAGE_SHIFT))
-#define paddr_to_pdx(pa)    pfn_to_pdx(paddr_to_pfn(pa))
+#define paddr_to_pdx(pa)    mfn_to_pdx(maddr_to_mfn(pa))
 #define gfn_to_gaddr(gfn)   pfn_to_paddr(gfn_x(gfn))
 #define gaddr_to_gfn(ga)    _gfn(paddr_to_pfn(ga))
 #define mfn_to_maddr(mfn)   pfn_to_paddr(mfn_x(mfn))
@@ -253,7 +253,7 @@ static inline void *maddr_to_virt(paddr_t ma)
 #else
 static inline void *maddr_to_virt(paddr_t ma)
 {
-    ASSERT(pfn_to_pdx(ma >> PAGE_SHIFT) < (DIRECTMAP_SIZE >> PAGE_SHIFT));
+    ASSERT(mfn_to_pdx(maddr_to_mfn(ma)) < (DIRECTMAP_SIZE >> PAGE_SHIFT));
     return (void *)(XENHEAP_VIRT_START -
                     mfn_to_maddr(xenheap_mfn_start) +
                     ((ma & ma_va_bottom_mask) |
@@ -301,7 +301,7 @@ static inline struct page_info *virt_to_page(const void *v)
     ASSERT(va < xenheap_virt_end);
 
     pdx = (va - XENHEAP_VIRT_START) >> PAGE_SHIFT;
-    pdx += pfn_to_pdx(mfn_x(xenheap_mfn_start));
+    pdx += mfn_to_pdx(xenheap_mfn_start);
     return frame_table + pdx - frametable_base_pdx;
 }
 
Signature · 1 line
2.11.0

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

#3 lore raw

PATCH 2/14 xen/x86: Constify the parameter "d" in mfn_to_gfn

In reply to Julien Grall

The parameter "d" holds the domain and is not modified by the function. So constify it.

---
Changes in v2:
- Fix function name in the title
- Add Jan's reviewed-by

---
 xen/include/asm-x86/p2m.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/asm-x86/p2m.h +1 -1
index 2801a8ccca..c3bd12020e 100644
@@ -506,7 +506,7 @@ static inline struct page_info *get_page_from_gfn(
 }
 
 /* General conversion function from mfn to gfn */
-static inline unsigned long mfn_to_gfn(struct domain *d, mfn_t mfn)
+static inline unsigned long mfn_to_gfn(const struct domain *d, mfn_t mfn)
 {
     if ( paging_mode_translate(d) )
         return get_gpfn_from_mfn(mfn_x(mfn));
Signature · 7 lines
2.11.0


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

PATCH 3/14 xen/x86: Make mfn_to_gfn typesafe

In reply to Julien Grall

No functional changes intended.

---
Changes in v2:
- Patch added

---
 xen/arch/x86/mm/p2m.c           |  2 +-
 xen/arch/x86/mm/shadow/common.c | 31 ++++++++++++++++++-------------
 xen/arch/x86/mm/shadow/multi.c  |  4 ++--
 xen/include/asm-x86/p2m.h       |  6 +++---
 4 files changed, 24 insertions(+), 19 deletions(-)
xen/arch/x86/mm/p2m.c +1 -1
index 9e81a30cc4..b16117dc56 100644
@@ -935,7 +935,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn,
         }
         if ( page_get_owner(mfn_to_page(mfn_add(mfn, i))) != d )
             continue;
-        ogfn = _gfn(mfn_to_gfn(d, mfn_add(mfn, i)));
+        ogfn = mfn_to_gfn(d, mfn_add(mfn, i));
         if ( !gfn_eq(ogfn, _gfn(INVALID_M2P_ENTRY)) &&
              !gfn_eq(ogfn, gfn_add(gfn, i)) )
         {
xen/arch/x86/mm/shadow/common.c +18 -13
index 2d44855388..480fcc740d 100644
@@ -474,7 +474,8 @@ static inline void trace_resync(int event, mfn_t gmfn)
     if ( tb_init_done )
     {
         /* Convert gmfn to gfn */
-        unsigned long gfn = mfn_to_gfn(current->domain, gmfn);
+        unsigned long gfn = gfn_x(mfn_to_gfn(current->domain, gmfn));
+
         __trace_var(event, 0/*!tsc*/, sizeof(gfn), &gfn);
     }
 }
@@ -986,8 +987,9 @@ static inline void trace_shadow_prealloc_unpin(struct domain *d, mfn_t smfn)
     {
         /* Convert smfn to gfn */
         unsigned long gfn;
+
         ASSERT(mfn_valid(smfn));
-        gfn = mfn_to_gfn(d, backpointer(mfn_to_page(smfn)));
+        gfn = gfn_x(mfn_to_gfn(d, backpointer(mfn_to_page(smfn))));
         __trace_var(TRC_SHADOW_PREALLOC_UNPIN, 0/*!tsc*/, sizeof(gfn), &gfn);
     }
 }
@@ -1861,7 +1863,8 @@ static inline void trace_shadow_wrmap_bf(mfn_t gmfn)
     if ( tb_init_done )
     {
         /* Convert gmfn to gfn */
-        unsigned long gfn = mfn_to_gfn(current->domain, gmfn);
+        unsigned long gfn = gfn_x(mfn_to_gfn(current->domain, gmfn));
+
         __trace_var(TRC_SHADOW_WRMAP_BF, 0/*!tsc*/, sizeof(gfn), &gfn);
     }
 }
@@ -1946,7 +1949,7 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn,
 #if SHADOW_OPTIMIZATIONS & SHOPT_WRITABLE_HEURISTIC
     if ( curr->domain == d )
     {
-        unsigned long gfn;
+        gfn_t gfn;
         /* Heuristic: there is likely to be only one writeable mapping,
          * and that mapping is likely to be in the current pagetable,
          * in the guest's linear map (on non-HIGHPTE linux and windows)*/
@@ -1969,8 +1972,9 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn,
                 GUESS(0xC0000000UL + (fault_addr >> 10), 1);
 
             /* Linux lowmem: first 896MB is mapped 1-to-1 above 0xC0000000 */
-            if ((gfn = mfn_to_gfn(d, gmfn)) < 0x38000 )
-                GUESS(0xC0000000UL + (gfn << PAGE_SHIFT), 4);
+            gfn = mfn_to_gfn(d, gmfn);
+            if ( gfn_x(gfn) < 0x38000 )
+                GUESS(0xC0000000UL + gfn_to_gaddr(gfn), 4);
 
             /* FreeBSD: Linear map at 0xBFC00000 */
             if ( level == 1 )
@@ -1987,8 +1991,9 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn,
             }
 
             /* Linux lowmem: first 896MB is mapped 1-to-1 above 0xC0000000 */
-            if ((gfn = mfn_to_gfn(d, gmfn)) < 0x38000 )
-                GUESS(0xC0000000UL + (gfn << PAGE_SHIFT), 4);
+            gfn = mfn_to_gfn(d, gmfn);
+            if ( gfn_x(gfn) < 0x38000 )
+                GUESS(0xC0000000UL + gfn_to_gaddr(gfn), 4);
 
             /* FreeBSD PAE: Linear map at 0xBF800000 */
             switch ( level )
@@ -2016,15 +2021,15 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn,
              * had it at 0xffff810000000000, and older kernels yet had it
              * at 0x0000010000000000UL */
             gfn = mfn_to_gfn(d, gmfn);
-            GUESS(0xffff880000000000UL + (gfn << PAGE_SHIFT), 4);
-            GUESS(0xffff810000000000UL + (gfn << PAGE_SHIFT), 4);
-            GUESS(0x0000010000000000UL + (gfn << PAGE_SHIFT), 4);
+            GUESS(0xffff880000000000UL + gfn_to_gaddr(gfn), 4);
+            GUESS(0xffff810000000000UL + gfn_to_gaddr(gfn), 4);
+            GUESS(0x0000010000000000UL + gfn_to_gaddr(gfn), 4);
 
             /*
              * 64bit Solaris kernel page map at
              * kpm_vbase; 0xfffffe0000000000UL
              */
-            GUESS(0xfffffe0000000000UL + (gfn << PAGE_SHIFT), 4);
+            GUESS(0xfffffe0000000000UL + gfn_to_gaddr(gfn), 4);
 
              /* FreeBSD 64bit: linear map 0xffff800000000000 */
              switch ( level )
@@ -2037,7 +2042,7 @@ int sh_remove_write_access(struct domain *d, mfn_t gmfn,
                            + ((fault_addr & VADDR_MASK) >> 27), 6); break;
              }
              /* FreeBSD 64bit: direct map at 0xffffff0000000000 */
-             GUESS(0xffffff0000000000 + (gfn << PAGE_SHIFT), 6);
+             GUESS(0xffffff0000000000 + gfn_to_gaddr(gfn), 6);
         }
 
 #undef GUESS
xen/arch/x86/mm/shadow/multi.c +2 -2
index 1d282c928f..8781bdcfe5 100644
@@ -1076,7 +1076,7 @@ static inline void shadow_vram_get_l1e(shadow_l1e_t new_sl1e,
          || !mfn_valid(mfn) )   /* mfn can be invalid in mmio_direct */
         return;
 
-    gfn = mfn_to_gfn(d, mfn);
+    gfn = gfn_x(mfn_to_gfn(d, mfn));
     /* Page sharing not supported on shadow PTs */
     BUG_ON(SHARED_M2P(gfn));
 
@@ -1107,7 +1107,7 @@ static inline void shadow_vram_put_l1e(shadow_l1e_t old_sl1e,
          || !mfn_valid(mfn) )   /* mfn can be invalid in mmio_direct */
         return;
 
-    gfn = mfn_to_gfn(d, mfn);
+    gfn = gfn_x(mfn_to_gfn(d, mfn));
     /* Page sharing not supported on shadow PTs */
     BUG_ON(SHARED_M2P(gfn));
 
xen/include/asm-x86/p2m.h +3 -3
index c3bd12020e..0157568be9 100644
@@ -506,12 +506,12 @@ static inline struct page_info *get_page_from_gfn(
 }
 
 /* General conversion function from mfn to gfn */
-static inline unsigned long mfn_to_gfn(const struct domain *d, mfn_t mfn)
+static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn)
 {
     if ( paging_mode_translate(d) )
-        return get_gpfn_from_mfn(mfn_x(mfn));
+        return _gfn(get_gpfn_from_mfn(mfn_x(mfn)));
     else
-        return mfn_x(mfn);
+        return _gfn(mfn_x(mfn));
 }
 
 /* Deadlock-avoidance scheme when calling get_gfn on different gfn's */
Signature · 7 lines
2.11.0


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

Re: [PATCH 03/14] xen/x86: Make mfn_to_gfn typesafe

xen/arch/x86/mm/shadow/common.c static inline void trace_resync(int event, mfn_t gmfn) · line 480

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/shadow/common.c +2 -1
@@ -474,7 +474,8 @@ static inline void trace_resync(int event, mfn_t gmfn)
     if ( tb_init_done )
     {
         /* Convert gmfn to gfn */
-        unsigned long gfn = mfn_to_gfn(current->domain, gmfn);
+        unsigned long gfn = gfn_x(mfn_to_gfn(current->domain, gmfn));
+
         __trace_var(event, 0/*!tsc*/, sizeof(gfn), &gfn);
     }

Can't you use gfn_t here, and hence avoid the gfn_x()? Same again further down.

Jan

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

#6 lore raw

Re: [PATCH 03/14] xen/x86: Make mfn_to_gfn typesafe

Quoted 15 lines · Jan Beulich

xen/arch/x86/mm/shadow/common.c static inline void trace_resync(int event, mfn_t gmfn) · line 480

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/shadow/common.c +2 -1
@@ -474,7 +474,8 @@ static inline void trace_resync(int event, mfn_t gmfn)
      if ( tb_init_done )
      {
          /* Convert gmfn to gfn */
-        unsigned long gfn = mfn_to_gfn(current->domain, gmfn);
+        unsigned long gfn = gfn_x(mfn_to_gfn(current->domain, gmfn));
+
          __trace_var(event, 0/*!tsc*/, sizeof(gfn), &gfn);
      }

Can't you use gfn_t here, and hence avoid the gfn_x()? Same again further down.

Because __trace_var will export the value to the guest. I wasn't sure whether we can safely consider that gfn_t is exactly the same as unsigned long in debug-build.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 03/14] xen/x86: Make mfn_to_gfn typesafe

Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:02, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich

xen/arch/x86/mm/shadow/common.c static inline void trace_resync(int event, mfn_t gmfn) · line 480

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/shadow/common.c +2 -1
@@ -474,7 +474,8 @@ static inline void trace_resync(int event, mfn_t gmfn)
      if ( tb_init_done )
      {
          /* Convert gmfn to gfn */
-        unsigned long gfn = mfn_to_gfn(current->domain, gmfn);
+        unsigned long gfn = gfn_x(mfn_to_gfn(current->domain, gmfn));
+
          __trace_var(event, 0/*!tsc*/, sizeof(gfn), &gfn);
      }

Can't you use gfn_t here, and hence avoid the gfn_x()? Same again further down.

Quoted 4 lines

Because __trace_var will export the value to the guest. I wasn't sure whether we
can safely consider that gfn_t is exactly the same as unsigned long in debug-build.

Hmm, well - see the definition of gfn_t. George, what do you think?

Jan

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

#8 lore raw

Re: [PATCH 03/14] xen/x86: Make mfn_to_gfn typesafe

Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:02, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich

xen/arch/x86/mm/shadow/common.c static inline void trace_resync(int event, mfn_t gmfn) · line 480

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/shadow/common.c +2 -1
@@ -474,7 +474,8 @@ static inline void trace_resync(int event, mfn_t gmfn)
       if ( tb_init_done )
       {
           /* Convert gmfn to gfn */
-        unsigned long gfn = mfn_to_gfn(current->domain, gmfn);
+        unsigned long gfn = gfn_x(mfn_to_gfn(current->domain, gmfn));
+
           __trace_var(event, 0/*!tsc*/, sizeof(gfn), &gfn);
       }

Can't you use gfn_t here, and hence avoid the gfn_x()? Same again further down.

Quoted 6 lines
Quoted 4 lines

Because __trace_var will export the value to the guest. I wasn't sure whether we
can safely consider that gfn_t is exactly the same as unsigned long in debug-build.

Hmm, well - see the definition of gfn_t. George, what do you think?

I know what's the current definition. My point is we never made that assumption before. In all honesty, sure assumption would definitely help in a few places, but I think we ought to safeguard with BUILD_BUG(...).

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 03/14] xen/x86: Make mfn_to_gfn typesafe

Hi,

Quoted 22 lines · Julien Grall
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:02, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich

xen/arch/x86/mm/shadow/common.c static inline void trace_resync(int event, mfn_t gmfn) · line 480

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/shadow/common.c +2 -1
@@ -474,7 +474,8 @@ static inline void trace_resync(int event, mfn_t gmfn)
        if ( tb_init_done )
        {
            /* Convert gmfn to gfn */
-        unsigned long gfn = mfn_to_gfn(current->domain, gmfn);
+        unsigned long gfn = gfn_x(mfn_to_gfn(current->domain, gmfn));
+
            __trace_var(event, 0/*!tsc*/, sizeof(gfn), &gfn);
        }

Can't you use gfn_t here, and hence avoid the gfn_x()? Same again further down.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Because __trace_var will export the value to the guest. I wasn't sure whether we
can safely consider that gfn_t is exactly the same as unsigned long in debug-build.

Hmm, well - see the definition of gfn_t. George, what do you think?

I know what's the current definition. My point is we never made that assumption before. In all honesty, sure assumption would definitely help in a few places, but I think we ought to safeguard with BUILD_BUG(...).

George, do you have any opinions?

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 03/14] xen/x86: Make mfn_to_gfn typesafe

Quoted 33 lines · Julien Grall

Hi,

Quoted 30 lines · Julien Grall
Quoted 27 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:02, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/shadow/common.c +1 -1
@@ -474,7 +474,8 @@ static inline void trace_resync(int event,
 mfn_t gmfn)
        if ( tb_init_done )
        {
            /* Convert gmfn to gfn */
-        unsigned long gfn = mfn_to_gfn(current->domain, gmfn);
+        unsigned long gfn = gfn_x(mfn_to_gfn(current->domain,
Quoted 8 lines
Quoted 4 lines
xen/arch/x86/mm/shadow/common.c +1 -0
 gmfn));
+
            __trace_var(event, 0/*!tsc*/, sizeof(gfn), &gfn);

       }

Can't you use gfn_t here, and hence avoid the gfn_x()? Same again further
down.

Because __trace_var will export the value to the guest. I wasn't sure whether we
can safely consider that gfn_t is exactly the same as unsigned long in debug-build.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Hmm, well - see the definition of gfn_t. George, what do you think?

I know what's the current definition. My point is we never made that assumption before. In all honesty, sure assumption would definitely help in a few places, but I think we ought to safeguard with BUILD_BUG(...).

George, do you have any opinions?

Sorry, not sure how I missed this question earlier.

The __trace_var() call here is designed to be generic: whatever type or size gfn is, it will copy the whole thing. Tracing is explicitly not meant to be a stable interface -- the toolstack needs to track the hypervisor in terms of what it's going to kick out.

So, having gfn be a gfn_t in this case should be fine; in fact it should be _better_ than unsigned long, since if gfn_t ever does change size, the trace record will change size appropriately. If that happens, xenalyze will need to be modified to understand how to deal with the new size, but that's expected.

All that to say: it looks like Jan's suggestion of having gfn_t here would be better.

-George

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

#11 lore raw

Re: [PATCH 03/14] xen/x86: Make mfn_to_gfn typesafe

Hi George,

Quoted 50 lines · George Dunlap
Quoted 33 lines · Julien Grall

Hi,

Quoted 30 lines · Julien Grall
Quoted 27 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:02, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/shadow/common.c +1 -1
@@ -474,7 +474,8 @@ static inline void trace_resync(int event,
 mfn_t gmfn)
        if ( tb_init_done )
        {
            /* Convert gmfn to gfn */
-        unsigned long gfn = mfn_to_gfn(current->domain, gmfn);
+        unsigned long gfn = gfn_x(mfn_to_gfn(current->domain,
Quoted 8 lines
Quoted 4 lines
xen/arch/x86/mm/shadow/common.c +1 -0
 gmfn));
+
            __trace_var(event, 0/*!tsc*/, sizeof(gfn), &gfn);

       }

Can't you use gfn_t here, and hence avoid the gfn_x()? Same again further
down.

Because __trace_var will export the value to the guest. I wasn't sure whether we
can safely consider that gfn_t is exactly the same as unsigned long in debug-build.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Hmm, well - see the definition of gfn_t. George, what do you think?

I know what's the current definition. My point is we never made that assumption before. In all honesty, sure assumption would definitely help in a few places, but I think we ought to safeguard with BUILD_BUG(...).

George, do you have any opinions?

Sorry, not sure how I missed this question earlier.

The __trace_var() call here is designed to be generic: whatever type or size gfn is, it will copy the whole thing. Tracing is explicitly not meant to be a stable interface -- the toolstack needs to track the hypervisor in terms of what it's going to kick out.

Quoted 8 lines

So, having gfn be a gfn_t in this case should be fine; in fact it should be _better_ than unsigned long, since if gfn_t ever does change size, the trace record will change size appropriately. If that happens, xenalyze will need to be modified to understand how to deal with the new size, but that's expected.

All that to say: it looks like Jan's suggestion of having gfn_t here would be better.

Make sense, thank you for the answer. I will respin the series.

Cheers,

Signature · 6 lines
Julien Grall

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

PATCH 4/14 xen/x86: Use mfn_to_gfn rather than mfn_to_gmfn

In reply to Julien Grall

mfn_to_gfn and mfn_to_gmfn are doing exactly the same except the former is using mfn_t.

Furthermore, the naming of the former is more consistent with the current naming scheme (GFN/MFN). So use replace mfn_to_gmfn with mfn_to_gfn in x86 code.

Take the opportunity to convert some of the callers to use typesafe GFN and format the message correctly.

No functional changes.

--
Changes in v2:
- mfn_to_gfn now returns a gfn_t
- Use %pd and PRI_gfn when possible in the message
- Don't split format string to help grep/ack.

---
 xen/arch/x86/domain.c               | 34 +++++++++++++++++++---------------
 xen/arch/x86/mm.c                   |  9 +++++----
 xen/arch/x86/pv/emul-priv-op.c      |  4 ++--
 xen/drivers/passthrough/x86/iommu.c | 16 +++++++++-------
 4 files changed, 35 insertions(+), 28 deletions(-)
xen/arch/x86/domain.c +19 -15
index 9eaa978ce5..8d29dfeecc 100644
@@ -679,7 +679,7 @@ int arch_domain_soft_reset(struct domain *d)
     int ret = 0;
     struct domain *owner;
     mfn_t mfn;
-    unsigned long gfn;
+    gfn_t gfn;
     p2m_type_t p2mt;
     unsigned int i;
 
@@ -713,19 +713,20 @@ int arch_domain_soft_reset(struct domain *d)
     ASSERT( owner == d );
 
     mfn = page_to_mfn(page);
-    gfn = mfn_to_gmfn(d, mfn_x(mfn));
+    gfn = mfn_to_gfn(d, mfn);
 
     /*
      * gfn == INVALID_GFN indicates that the shared_info page was never mapped
      * to the domain's address space and there is nothing to replace.
      */
-    if ( gfn == gfn_x(INVALID_GFN) )
+    if ( gfn_eq(gfn, INVALID_GFN) )
         goto exit_put_page;
 
-    if ( !mfn_eq(get_gfn_query(d, gfn, &p2mt), mfn) )
+    if ( !mfn_eq(get_gfn_query(d, gfn_x(gfn), &p2mt), mfn) )
     {
-        printk(XENLOG_G_ERR "Failed to get Dom%d's shared_info GFN (%lx)\n",
-               d->domain_id, gfn);
+        printk(XENLOG_G_ERR
+               "Failed to get %pd's shared_info GFN (%"PRI_gfn")\n",
+               d, gfn_x(gfn));
         ret = -EINVAL;
         goto exit_put_gfn;
     }
@@ -733,31 +734,34 @@ int arch_domain_soft_reset(struct domain *d)
     new_page = alloc_domheap_page(d, 0);
     if ( !new_page )
     {
-        printk(XENLOG_G_ERR "Failed to alloc a page to replace"
-               " Dom%d's shared_info frame %lx\n", d->domain_id, gfn);
+        printk(XENLOG_G_ERR
+               "Failed to alloc a page to replace %pd's shared_info frame %"PRI_gfn"\n",
+               d, gfn_x(gfn));
         ret = -ENOMEM;
         goto exit_put_gfn;
     }
 
-    ret = guest_physmap_remove_page(d, _gfn(gfn), mfn, PAGE_ORDER_4K);
+    ret = guest_physmap_remove_page(d, gfn, mfn, PAGE_ORDER_4K);
     if ( ret )
     {
-        printk(XENLOG_G_ERR "Failed to remove Dom%d's shared_info frame %lx\n",
-               d->domain_id, gfn);
+        printk(XENLOG_G_ERR
+               "Failed to remove %pd's shared_info frame %"PRI_gfn"\n",
+               d, gfn_x(gfn));
         free_domheap_page(new_page);
         goto exit_put_gfn;
     }
 
-    ret = guest_physmap_add_page(d, _gfn(gfn), page_to_mfn(new_page),
+    ret = guest_physmap_add_page(d, gfn, page_to_mfn(new_page),
                                  PAGE_ORDER_4K);
     if ( ret )
     {
-        printk(XENLOG_G_ERR "Failed to add a page to replace"
-               " Dom%d's shared_info frame %lx\n", d->domain_id, gfn);
+        printk(XENLOG_G_ERR
+               "Failed to add a page to replace %pd's shared_info frame %"PRI_gfn"\n",
+               d, gfn_x(gfn));
         free_domheap_page(new_page);
     }
  exit_put_gfn:
-    put_gfn(d, gfn);
+    put_gfn(d, gfn_x(gfn));
  exit_put_page:
     put_page(page);
 
xen/arch/x86/mm.c +5 -4
index 45fadbab61..9878453eb0 100644
@@ -2632,19 +2632,20 @@ int free_page_type(struct page_info *page, unsigned long type,
 {
 #ifdef CONFIG_PV
     struct domain *owner = page_get_owner(page);
-    unsigned long gmfn;
     int rc;
 
     if ( likely(owner != NULL) && unlikely(paging_mode_enabled(owner)) )
     {
+        gfn_t gfn;
+
         /* A page table is dirtied when its type count becomes zero. */
         paging_mark_dirty(owner, page_to_mfn(page));
 
         ASSERT(!shadow_mode_refcounts(owner));
 
-        gmfn = mfn_to_gmfn(owner, mfn_x(page_to_mfn(page)));
-        if ( VALID_M2P(gmfn) )
-            shadow_remove_all_shadows(owner, _mfn(gmfn));
+        gfn = mfn_to_gfn(owner, page_to_mfn(page));
+        if ( VALID_M2P(gfn_x(gfn)) )
+            shadow_remove_all_shadows(owner, _mfn(gfn_x(gfn)));
     }
 
     if ( !(type & PGT_partial) )
xen/arch/x86/pv/emul-priv-op.c +2 -2
index af74f50dc8..e976ff9898 100644
@@ -712,7 +712,7 @@ static int read_cr(unsigned int reg, unsigned long *val,
         if ( !is_pv_32bit_domain(currd) )
         {
             mfn = pagetable_get_mfn(curr->arch.guest_table);
-            *val = xen_pfn_to_cr3(mfn_to_gmfn(currd, mfn_x(mfn)));
+            *val = xen_pfn_to_cr3(gfn_x(mfn_to_gfn(currd, mfn)));
         }
         else
         {
@@ -721,7 +721,7 @@ static int read_cr(unsigned int reg, unsigned long *val,
 
             mfn = l4e_get_mfn(*pl4e);
             unmap_domain_page(pl4e);
-            *val = compat_pfn_to_cr3(mfn_to_gmfn(currd, mfn_x(mfn)));
+            *val = compat_pfn_to_cr3(gfn_x(mfn_to_gfn(currd, mfn)));
         }
         /* PTs should not be shared */
         BUG_ON(page_get_owner(mfn_to_page(mfn)) == dom_cow);
xen/drivers/passthrough/x86/iommu.c +9 -7
index 034ac903dd..7a756ef19e 100644
@@ -92,15 +92,17 @@ int arch_iommu_populate_page_table(struct domain *d)
         if ( is_hvm_domain(d) ||
             (page->u.inuse.type_info & PGT_type_mask) == PGT_writable_page )
         {
-            unsigned long mfn = mfn_x(page_to_mfn(page));
-            unsigned long gfn = mfn_to_gmfn(d, mfn);
+            mfn_t mfn = page_to_mfn(page);
+            gfn_t gfn = mfn_to_gfn(d, mfn);
             unsigned int flush_flags = 0;
 
-            if ( gfn != gfn_x(INVALID_GFN) )
+            if ( !gfn_eq(gfn, INVALID_GFN) )
             {
-                ASSERT(!(gfn >> DEFAULT_DOMAIN_ADDRESS_WIDTH));
-                BUG_ON(SHARED_M2P(gfn));
-                rc = iommu_map(d, _dfn(gfn), _mfn(mfn), PAGE_ORDER_4K,
+                dfn_t dfn = _dfn(gfn_x(gfn));
+
+                ASSERT(!(gfn_x(gfn) >> DEFAULT_DOMAIN_ADDRESS_WIDTH));
+                BUG_ON(SHARED_M2P(gfn_x(gfn)));
+                rc = iommu_map(d, dfn, mfn, PAGE_ORDER_4K,
                                IOMMUF_readable | IOMMUF_writable,
                                &flush_flags);
 
@@ -118,7 +120,7 @@ int arch_iommu_populate_page_table(struct domain *d)
                      ((page->u.inuse.type_info & PGT_type_mask) !=
                       PGT_writable_page) )
                 {
-                    rc = iommu_unmap(d, _dfn(gfn), PAGE_ORDER_4K, &flush_flags);
+                    rc = iommu_unmap(d, dfn, PAGE_ORDER_4K, &flush_flags);
                     /* If the type changed yet again, simply force a retry. */
                     if ( !rc && ((page->u.inuse.type_info & PGT_type_mask) ==
                                  PGT_writable_page) )
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 4/14
#13 lore raw

Re: [PATCH 04/14] xen/x86: Use mfn_to_gfn rather than mfn_to_gmfn

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:

mfn_to_gfn and mfn_to_gmfn are doing exactly the same except the former is using mfn_t.

... and gfn_t (return type) as of patch 3.

Quoted 3 lines

Furthermore, the naming of the former is more consistent with the current naming scheme (GFN/MFN). So use replace mfn_to_gmfn with mfn_to_gfn in x86 code.

Nit: Either "use" or "replace with", but not both.

Quoted 12 lines
xen/arch/x86/domain.c +1 -2
@@ -713,19 +713,20 @@ int arch_domain_soft_reset(struct domain *d)
     ASSERT( owner == d );
 
     mfn = page_to_mfn(page);
-    gfn = mfn_to_gmfn(d, mfn_x(mfn));
+    gfn = mfn_to_gfn(d, mfn);
 
     /*
      * gfn == INVALID_GFN indicates that the shared_info page was never mapped
      * to the domain's address space and there is nothing to replace.
      */
-    if ( gfn == gfn_x(INVALID_GFN) )

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 728

Quoted 10 lines
xen/arch/x86/domain.c +4 -3
+    if ( gfn_eq(gfn, INVALID_GFN) )
         goto exit_put_page;
 
-    if ( !mfn_eq(get_gfn_query(d, gfn, &p2mt), mfn) )
+    if ( !mfn_eq(get_gfn_query(d, gfn_x(gfn), &p2mt), mfn) )
     {
-        printk(XENLOG_G_ERR "Failed to get Dom%d's shared_info GFN (%lx)\n",
-               d->domain_id, gfn);
+        printk(XENLOG_G_ERR
+               "Failed to get %pd's shared_info GFN (%"PRI_gfn")\n",

I'd recommend to drop the parentheses from the format string at the same time.

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 738

Quoted 8 lines
xen/arch/x86/domain.c +2 -2
@@ -733,31 +734,34 @@ int arch_domain_soft_reset(struct domain *d)
     new_page = alloc_domheap_page(d, 0);
     if ( !new_page )
     {
-        printk(XENLOG_G_ERR "Failed to alloc a page to replace"
-               " Dom%d's shared_info frame %lx\n", d->domain_id, gfn);
+        printk(XENLOG_G_ERR
+               "Failed to alloc a page to replace %pd's shared_info frame %"PRI_gfn"\n",

s/frame/GFN/ to better match the earlier one? Same in the further log messages here then.

Quoted 15 lines
xen/arch/x86/mm.c +2 -1
@@ -2632,19 +2632,20 @@ int free_page_type(struct page_info *page, unsigned long type,
 {
 #ifdef CONFIG_PV
     struct domain *owner = page_get_owner(page);
-    unsigned long gmfn;
     int rc;
 
     if ( likely(owner != NULL) && unlikely(paging_mode_enabled(owner)) )
     {
+        gfn_t gfn;
+
         /* A page table is dirtied when its type count becomes zero. */
         paging_mark_dirty(owner, page_to_mfn(page));

xen/arch/x86/mm.c int free_page_type(struct page_info *page, unsigned long type, · line 2649

Quoted 10 lines
xen/arch/x86/mm.c +3 -3
 
         ASSERT(!shadow_mode_refcounts(owner));
 
-        gmfn = mfn_to_gmfn(owner, mfn_x(page_to_mfn(page)));
-        if ( VALID_M2P(gmfn) )
-            shadow_remove_all_shadows(owner, _mfn(gmfn));
+        gfn = mfn_to_gfn(owner, page_to_mfn(page));
+        if ( VALID_M2P(gfn_x(gfn)) )
+            shadow_remove_all_shadows(owner, _mfn(gfn_x(gfn)));
     }

This is a highly suspicious change imo (albeit the code was bogus already before): It certainly isn't GFN here even if we were to assume translated mode could be in use. One other caller of
the function, sh_page_fault() passes a variable named gmfn as well, but typed mfn_t (and this gmfn gets set from get_gfn(), i.e. is _not_ a GFN). The 3rd one, shadow_prepare_page_type_change(), clearly passes an MFN.

I think the best course of action here is to split out the change, just to explain why removing the mfn_to_gmfn() here altogether is appropriate nowadays: PV guests can't be in translated mode anymore, and hence mfn_to_gmfn() doesn't do any translation. At that point the VALID_M2P() check can go away as well, so you'll be able to simply do

        shadow_remove_all_shadows(owner, page_to_mfn(page));

perhaps with another !shadow_mode_translate() assertion added next to the one that's already there. Tim, thoughts?

With this split out and irrespective of whether you decide to follow the format string suggestions further up

Jan

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

#14 lore raw

Re: [PATCH 04/14] xen/x86: Use mfn_to_gfn rather than mfn_to_gmfn

Hi Jan,

Quoted 91 lines · Jan Beulich
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:

mfn_to_gfn and mfn_to_gmfn are doing exactly the same except the former is using mfn_t.

... and gfn_t (return type) as of patch 3.

Quoted 3 lines

Furthermore, the naming of the former is more consistent with the current naming scheme (GFN/MFN). So use replace mfn_to_gmfn with mfn_to_gfn in x86 code.

Nit: Either "use" or "replace with", but not both.

Quoted 12 lines
xen/arch/x86/domain.c +1 -2
@@ -713,19 +713,20 @@ int arch_domain_soft_reset(struct domain *d)
      ASSERT( owner == d );
 
      mfn = page_to_mfn(page);
-    gfn = mfn_to_gmfn(d, mfn_x(mfn));
+    gfn = mfn_to_gfn(d, mfn);
 
      /*
       * gfn == INVALID_GFN indicates that the shared_info page was never mapped
       * to the domain's address space and there is nothing to replace.
       */
-    if ( gfn == gfn_x(INVALID_GFN) )

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 728

Quoted 10 lines
xen/arch/x86/domain.c +4 -3
+    if ( gfn_eq(gfn, INVALID_GFN) )
          goto exit_put_page;
 
-    if ( !mfn_eq(get_gfn_query(d, gfn, &p2mt), mfn) )
+    if ( !mfn_eq(get_gfn_query(d, gfn_x(gfn), &p2mt), mfn) )
      {
-        printk(XENLOG_G_ERR "Failed to get Dom%d's shared_info GFN (%lx)\n",
-               d->domain_id, gfn);
+        printk(XENLOG_G_ERR
+               "Failed to get %pd's shared_info GFN (%"PRI_gfn")\n",

I'd recommend to drop the parentheses from the format string at the same time.

xen/arch/x86/domain.c int arch_domain_soft_reset(struct domain *d) · line 738

Quoted 8 lines
xen/arch/x86/domain.c +2 -2
@@ -733,31 +734,34 @@ int arch_domain_soft_reset(struct domain *d)
      new_page = alloc_domheap_page(d, 0);
      if ( !new_page )
      {
-        printk(XENLOG_G_ERR "Failed to alloc a page to replace"
-               " Dom%d's shared_info frame %lx\n", d->domain_id, gfn);
+        printk(XENLOG_G_ERR
+               "Failed to alloc a page to replace %pd's shared_info frame %"PRI_gfn"\n",

s/frame/GFN/ to better match the earlier one? Same in the further log messages here then.

Quoted 15 lines
xen/arch/x86/mm.c +2 -1
@@ -2632,19 +2632,20 @@ int free_page_type(struct page_info *page, unsigned long type,
  {
  #ifdef CONFIG_PV
      struct domain *owner = page_get_owner(page);
-    unsigned long gmfn;
      int rc;
 
      if ( likely(owner != NULL) && unlikely(paging_mode_enabled(owner)) )
      {
+        gfn_t gfn;
+
          /* A page table is dirtied when its type count becomes zero. */
          paging_mark_dirty(owner, page_to_mfn(page));

xen/arch/x86/mm.c int free_page_type(struct page_info *page, unsigned long type, · line 2649

Quoted 10 lines
xen/arch/x86/mm.c +3 -3
 
          ASSERT(!shadow_mode_refcounts(owner));
 
-        gmfn = mfn_to_gmfn(owner, mfn_x(page_to_mfn(page)));
-        if ( VALID_M2P(gmfn) )
-            shadow_remove_all_shadows(owner, _mfn(gmfn));
+        gfn = mfn_to_gfn(owner, page_to_mfn(page));
+        if ( VALID_M2P(gfn_x(gfn)) )
+            shadow_remove_all_shadows(owner, _mfn(gfn_x(gfn)));
      }

This is a highly suspicious change imo (albeit the code was bogus already before): It certainly isn't GFN here even if we were to assume translated mode could be in use. One other caller of
the function, sh_page_fault() passes a variable named gmfn as well, but typed mfn_t (and this gmfn gets set from get_gfn(), i.e. is _not_ a GFN). The 3rd one, shadow_prepare_page_type_change(), clearly passes an MFN.

I think the best course of action here is to split out the change, just to explain why removing the mfn_to_gmfn() here altogether is appropriate nowadays: PV guests can't be in translated mode anymore, and hence mfn_to_gmfn() doesn't do any translation. At that point the VALID_M2P() check can go away as well, so you'll be able to simply do

Quoted 7 lines
         shadow_remove_all_shadows(owner, page_to_mfn(page));

perhaps with another !shadow_mode_translate() assertion added next to the one that's already there. Tim, thoughts?

With this split out and irrespective of whether you decide to follow the format string suggestions further up

I don't have enough experience with x86 to provide the patch you suggest.

I am happy to rebase on top of any patch you provide. Alternatively I can drop this and keep mfn_to_gmfn on x86 but replaces the one in common code with mfn_to_gfn.

Quoted 1 line

Cheers,

Signature · 6 lines
Julien Grall

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

PATCH 5/14 xen/grant-table: Make arch specific macros typesafe

In reply to Julien Grall

This patch rework all the arch specific macros in grant_table.h to use the typesafe MFN/GFN.

At the same time, some functions are renamed s/gmfn/gfn/ to match the current naming scheme (see include/mm.h).

No functional changes intended.

---
Changes in v2:
- Update commit message to explain the changes made
- Fix indentation
- Adapt the code to match the new prototype of mfn_to_gfn
- Add Jan's acked-by for non-ARM parts

---
 xen/common/grant_table.c          |  4 ++--
 xen/include/asm-arm/grant_table.h | 12 ++++++------
 xen/include/asm-x86/grant_table.h | 19 +++++++------------
 3 files changed, 15 insertions(+), 20 deletions(-)
xen/common/grant_table.c +2 -2
index 80728ea57d..abc966f775 100644
@@ -1935,7 +1935,7 @@ gnttab_setup_table(
     op.status = GNTST_okay;
     for ( i = 0; i < op.nr_frames; i++ )
     {
-        xen_pfn_t gmfn = gnttab_shared_gmfn(d, gt, i);
+        xen_pfn_t gmfn = gfn_x(gnttab_shared_gfn(d, gt, i));
 
         /* Grant tables cannot be shared */
         BUG_ON(SHARED_M2P(gmfn));
@@ -3149,7 +3149,7 @@ gnttab_get_status_frames(XEN_GUEST_HANDLE_PARAM(gnttab_get_status_frames_t) uop,
 
     for ( i = 0; i < op.nr_frames; i++ )
     {
-        gmfn = gnttab_status_gmfn(d, gt, i);
+        gmfn = gfn_x(gnttab_status_gfn(d, gt, i));
         if ( copy_to_guest_offset(op.frame_list, i, &gmfn, 1) )
             op.status = GNTST_bad_virt_addr;
     }
xen/include/asm-arm/grant_table.h +6 -6
index 051db1362b..750536184e 100644
@@ -65,15 +65,15 @@ void gnttab_mark_dirty(struct domain *d, mfn_t mfn);
     } while ( 0 )
 
 #define gnttab_get_frame_gfn(gt, st, idx) ({                             \
-   _gfn((st) ? gnttab_status_gmfn(NULL, gt, idx)                         \
-             : gnttab_shared_gmfn(NULL, gt, idx));                       \
+   (st) ? gnttab_status_gfn(NULL, gt, idx)                               \
+        : gnttab_shared_gfn(NULL, gt, idx);                              \
 })
 
-#define gnttab_shared_gmfn(d, t, i)                                      \
-    gfn_x(((i) >= nr_grant_frames(t)) ? INVALID_GFN : (t)->arch.shared_gfn[i])
+#define gnttab_shared_gfn(d, t, i)                                       \
+    (((i) >= nr_grant_frames(t)) ? INVALID_GFN : (t)->arch.shared_gfn[i])
 
-#define gnttab_status_gmfn(d, t, i)                                      \
-    gfn_x(((i) >= nr_status_frames(t)) ? INVALID_GFN : (t)->arch.status_gfn[i])
+#define gnttab_status_gfn(d, t, i)                                       \
+    (((i) >= nr_status_frames(t)) ? INVALID_GFN : (t)->arch.status_gfn[i])
 
 #define gnttab_need_iommu_mapping(d)                    \
     (is_domain_direct_mapped(d) && need_iommu_pt_sync(d))
xen/include/asm-x86/grant_table.h +7 -12
index 8b604ed51f..661228dd39 100644
@@ -39,24 +39,19 @@ static inline int replace_grant_host_mapping(uint64_t addr, mfn_t frame,
 #define gnttab_destroy_arch(gt) do {} while ( 0 )
 #define gnttab_set_frame_gfn(gt, st, idx, gfn) do {} while ( 0 )
 #define gnttab_get_frame_gfn(gt, st, idx) ({                             \
-    unsigned long mfn_ = (st) ? gnttab_status_mfn(gt, idx)               \
-                              : gnttab_shared_mfn(gt, idx);              \
-    unsigned long gpfn_ = get_gpfn_from_mfn(mfn_);                       \
+    mfn_t mfn_ = (st) ? gnttab_status_mfn(gt, idx)                       \
+                      : gnttab_shared_mfn(gt, idx);                      \
+    unsigned long gpfn_ = get_gpfn_from_mfn(mfn_x(mfn_));                \
     VALID_M2P(gpfn_) ? _gfn(gpfn_) : INVALID_GFN;                        \
 })
 
-#define gnttab_shared_mfn(t, i)                         \
-    ((virt_to_maddr((t)->shared_raw[i]) >> PAGE_SHIFT))
+#define gnttab_shared_mfn(t, i) _mfn(__virt_to_mfn((t)->shared_raw[i]))
 
-#define gnttab_shared_gmfn(d, t, i)                     \
-    (mfn_to_gmfn(d, gnttab_shared_mfn(t, i)))
+#define gnttab_shared_gfn(d, t, i) mfn_to_gfn(d, gnttab_shared_mfn(t, i))
 
+#define gnttab_status_mfn(t, i) _mfn(__virt_to_mfn((t)->status[i]))
 
-#define gnttab_status_mfn(t, i)                         \
-    ((virt_to_maddr((t)->status[i]) >> PAGE_SHIFT))
-
-#define gnttab_status_gmfn(d, t, i)                     \
-    (mfn_to_gmfn(d, gnttab_status_mfn(t, i)))
+#define gnttab_status_gfn(d, t, i) mfn_to_gfn(d, gnttab_status_mfn(t, i))
 
 #define gnttab_mark_dirty(d, f) paging_mark_dirty(d, f)
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 5/14
#16 lore raw

Re: [PATCH 05/14] xen/grant-table: Make arch specific macros typesafe

Quoted 10 lines · Julien Grall

This patch rework all the arch specific macros in grant_table.h to use the typesafe MFN/GFN.

At the same time, some functions are renamed s/gmfn/gfn/ to match the current naming scheme (see include/mm.h).

No functional changes intended.

Quoted 99 lines

---
Changes in v2:
- Update commit message to explain the changes made
- Fix indentation
- Adapt the code to match the new prototype of mfn_to_gfn
- Add Jan's acked-by for non-ARM parts

---
 xen/common/grant_table.c          |  4 ++--
 xen/include/asm-arm/grant_table.h | 12 ++++++------
 xen/include/asm-x86/grant_table.h | 19 +++++++------------
 3 files changed, 15 insertions(+), 20 deletions(-)
xen/common/grant_table.c +2 -2
index 80728ea57d..abc966f775 100644
@@ -1935,7 +1935,7 @@ gnttab_setup_table(
     op.status = GNTST_okay;
     for ( i = 0; i < op.nr_frames; i++ )
     {
-        xen_pfn_t gmfn = gnttab_shared_gmfn(d, gt, i);
+        xen_pfn_t gmfn = gfn_x(gnttab_shared_gfn(d, gt, i));
 
         /* Grant tables cannot be shared */
         BUG_ON(SHARED_M2P(gmfn));
@@ -3149,7 +3149,7 @@ gnttab_get_status_frames(XEN_GUEST_HANDLE_PARAM(gnttab_get_status_frames_t) uop,
 
     for ( i = 0; i < op.nr_frames; i++ )
     {
-        gmfn = gnttab_status_gmfn(d, gt, i);
+        gmfn = gfn_x(gnttab_status_gfn(d, gt, i));
         if ( copy_to_guest_offset(op.frame_list, i, &gmfn, 1) )
             op.status = GNTST_bad_virt_addr;
     }
xen/include/asm-arm/grant_table.h +6 -6
index 051db1362b..750536184e 100644
@@ -65,15 +65,15 @@ void gnttab_mark_dirty(struct domain *d, mfn_t mfn);
     } while ( 0 )
 
 #define gnttab_get_frame_gfn(gt, st, idx) ({                             \
-   _gfn((st) ? gnttab_status_gmfn(NULL, gt, idx)                         \
-             : gnttab_shared_gmfn(NULL, gt, idx));                       \
+   (st) ? gnttab_status_gfn(NULL, gt, idx)                               \
+        : gnttab_shared_gfn(NULL, gt, idx);                              \
 })
 
-#define gnttab_shared_gmfn(d, t, i)                                      \
-    gfn_x(((i) >= nr_grant_frames(t)) ? INVALID_GFN : (t)->arch.shared_gfn[i])
+#define gnttab_shared_gfn(d, t, i)                                       \
+    (((i) >= nr_grant_frames(t)) ? INVALID_GFN : (t)->arch.shared_gfn[i])
 
-#define gnttab_status_gmfn(d, t, i)                                      \
-    gfn_x(((i) >= nr_status_frames(t)) ? INVALID_GFN : (t)->arch.status_gfn[i])
+#define gnttab_status_gfn(d, t, i)                                       \
+    (((i) >= nr_status_frames(t)) ? INVALID_GFN : (t)->arch.status_gfn[i])
 
 #define gnttab_need_iommu_mapping(d)                    \
     (is_domain_direct_mapped(d) && need_iommu_pt_sync(d))
xen/include/asm-x86/grant_table.h +7 -12
index 8b604ed51f..661228dd39 100644
@@ -39,24 +39,19 @@ static inline int replace_grant_host_mapping(uint64_t addr, mfn_t frame,
 #define gnttab_destroy_arch(gt) do {} while ( 0 )
 #define gnttab_set_frame_gfn(gt, st, idx, gfn) do {} while ( 0 )
 #define gnttab_get_frame_gfn(gt, st, idx) ({                             \
-    unsigned long mfn_ = (st) ? gnttab_status_mfn(gt, idx)               \
-                              : gnttab_shared_mfn(gt, idx);              \
-    unsigned long gpfn_ = get_gpfn_from_mfn(mfn_);                       \
+    mfn_t mfn_ = (st) ? gnttab_status_mfn(gt, idx)                       \
+                      : gnttab_shared_mfn(gt, idx);                      \
+    unsigned long gpfn_ = get_gpfn_from_mfn(mfn_x(mfn_));                \
     VALID_M2P(gpfn_) ? _gfn(gpfn_) : INVALID_GFN;                        \
 })
 
-#define gnttab_shared_mfn(t, i)                         \
-    ((virt_to_maddr((t)->shared_raw[i]) >> PAGE_SHIFT))
+#define gnttab_shared_mfn(t, i) _mfn(__virt_to_mfn((t)->shared_raw[i]))
 
-#define gnttab_shared_gmfn(d, t, i)                     \
-    (mfn_to_gmfn(d, gnttab_shared_mfn(t, i)))
+#define gnttab_shared_gfn(d, t, i) mfn_to_gfn(d, gnttab_shared_mfn(t, i))
 
+#define gnttab_status_mfn(t, i) _mfn(__virt_to_mfn((t)->status[i]))
 
-#define gnttab_status_mfn(t, i)                         \
-    ((virt_to_maddr((t)->status[i]) >> PAGE_SHIFT))
-
-#define gnttab_status_gmfn(d, t, i)                     \
-    (mfn_to_gmfn(d, gnttab_status_mfn(t, i)))
+#define gnttab_status_gfn(d, t, i) mfn_to_gfn(d, gnttab_status_mfn(t, i))
 
 #define gnttab_mark_dirty(d, f) paging_mark_dirty(d, f)
 
Signature · 1 line
2.11.0

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

#17 lore raw

PATCH 6/14 xen: Convert hotplug page function to use typesafe MFN

In reply to Julien Grall

Convert online_page, offline_page and query_page_offline to use typesafe MFN.

Note, for clarity, the words have been re-ordered in the error message updated by this patch.

No functional changes.

---
Changes:
- Update error message
- Add Jan's acked-by

---
 xen/arch/x86/cpu/mcheck/mcaction.c | 18 ++++++++++--------
 xen/common/page_alloc.c            | 24 ++++++++++++------------
 xen/common/sysctl.c                | 14 +++++++-------
 xen/include/xen/mm.h               |  6 +++---
 4 files changed, 32 insertions(+), 30 deletions(-)
xen/arch/x86/cpu/mcheck/mcaction.c +10 -8
index e42267414e..69332fb84d 100644
@@ -6,7 +6,7 @@
 
 static struct mcinfo_recovery *
 mci_action_add_pageoffline(int bank, struct mc_info *mi,
-                           uint64_t mfn, uint32_t status)
+                           mfn_t mfn, uint32_t status)
 {
     struct mcinfo_recovery *rec;
 
@@ -22,7 +22,7 @@ mci_action_add_pageoffline(int bank, struct mc_info *mi,
 
     rec->mc_bank = bank;
     rec->action_types = MC_ACTION_PAGE_OFFLINE;
-    rec->action_info.page_retire.mfn = mfn;
+    rec->action_info.page_retire.mfn = mfn_x(mfn);
     rec->action_info.page_retire.status = status;
     return rec;
 }
@@ -42,7 +42,8 @@ mc_memerr_dhandler(struct mca_binfo *binfo,
     struct mcinfo_bank *bank = binfo->mib;
     struct mcinfo_global *global = binfo->mig;
     struct domain *d;
-    unsigned long mfn, gfn;
+    mfn_t mfn;
+    unsigned long gfn;
     uint32_t status;
     int vmce_vcpuid;
     unsigned int mc_vcpuid;
@@ -54,11 +55,12 @@ mc_memerr_dhandler(struct mca_binfo *binfo,
         return;
     }
 
-    mfn = bank->mc_addr >> PAGE_SHIFT;
+    mfn = maddr_to_mfn(bank->mc_addr);
     if ( offline_page(mfn, 1, &status) )
     {
         dprintk(XENLOG_WARNING,
-                "Failed to offline page %lx for MCE error\n", mfn);
+                "Failed to offline page %"PRI_mfn" for MCE error\n",
+                mfn_x(mfn));
         return;
     }
 
@@ -89,10 +91,10 @@ mc_memerr_dhandler(struct mca_binfo *binfo,
                 ASSERT(d);
                 gfn = get_gpfn_from_mfn((bank->mc_addr) >> PAGE_SHIFT);
 
-                if ( unmmap_broken_page(d, _mfn(mfn), gfn) )
+                if ( unmmap_broken_page(d, mfn, gfn) )
                 {
-                    printk("Unmap broken memory %lx for DOM%d failed\n",
-                           mfn, d->domain_id);
+                    printk("Unmap broken memory %"PRI_mfn" for DOM%d failed\n",
+                           mfn_x(mfn), d->domain_id);
                     goto vmce_failed;
                 }
 
xen/common/page_alloc.c +12 -12
index be44158033..f445f7daec 100644
@@ -1568,23 +1568,23 @@ static int reserve_heap_page(struct page_info *pg)
 
 }
 
-int offline_page(unsigned long mfn, int broken, uint32_t *status)
+int offline_page(mfn_t mfn, int broken, uint32_t *status)
 {
     unsigned long old_info = 0;
     struct domain *owner;
     struct page_info *pg;
 
-    if ( !mfn_valid(_mfn(mfn)) )
+    if ( !mfn_valid(mfn) )
     {
         dprintk(XENLOG_WARNING,
-                "try to offline page out of range %lx\n", mfn);
+                "try to offline out of range page %"PRI_mfn"\n", mfn_x(mfn));
         return -EINVAL;
     }
 
     *status = 0;
-    pg = mfn_to_page(_mfn(mfn));
+    pg = mfn_to_page(mfn);
 
-    if ( is_xen_fixed_mfn(mfn) )
+    if ( is_xen_fixed_mfn(mfn_x(mfn)) )
     {
         *status = PG_OFFLINE_XENPAGE | PG_OFFLINE_FAILED |
           (DOMID_XEN << PG_OFFLINE_OWNER_SHIFT);
@@ -1595,7 +1595,7 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status)
      * N.B. xen's txt in x86_64 is marked reserved and handled already.
      * Also kexec range is reserved.
      */
-    if ( !page_is_ram_type(mfn, RAM_TYPE_CONVENTIONAL) )
+    if ( !page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL) )
     {
         *status = PG_OFFLINE_FAILED | PG_OFFLINE_NOT_CONV_RAM;
         return -EINVAL;
@@ -1677,19 +1677,19 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status)
  *   The caller should make sure end_pfn <= max_page,
  *   if not, expand_pages() should be called prior to online_page().
  */
-unsigned int online_page(unsigned long mfn, uint32_t *status)
+unsigned int online_page(mfn_t mfn, uint32_t *status)
 {
     unsigned long x, nx, y;
     struct page_info *pg;
     int ret;
 
-    if ( !mfn_valid(_mfn(mfn)) )
+    if ( !mfn_valid(mfn) )
     {
         dprintk(XENLOG_WARNING, "call expand_pages() first\n");
         return -EINVAL;
     }
 
-    pg = mfn_to_page(_mfn(mfn));
+    pg = mfn_to_page(mfn);
 
     spin_lock(&heap_lock);
 
@@ -1730,11 +1730,11 @@ unsigned int online_page(unsigned long mfn, uint32_t *status)
     return ret;
 }
 
-int query_page_offline(unsigned long mfn, uint32_t *status)
+int query_page_offline(mfn_t mfn, uint32_t *status)
 {
     struct page_info *pg;
 
-    if ( !mfn_valid(_mfn(mfn)) || !page_is_ram_type(mfn, RAM_TYPE_CONVENTIONAL) )
+    if ( !mfn_valid(mfn) || !page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL) )
     {
         dprintk(XENLOG_WARNING, "call expand_pages() first\n");
         return -EINVAL;
@@ -1743,7 +1743,7 @@ int query_page_offline(unsigned long mfn, uint32_t *status)
     *status = 0;
     spin_lock(&heap_lock);
 
-    pg = mfn_to_page(_mfn(mfn));
+    pg = mfn_to_page(mfn);
 
     if ( page_state_is(pg, offlining) )
         *status |= PG_OFFLINE_STATUS_OFFLINE_PENDING;
xen/common/sysctl.c +7 -7
index c0aa6bde4e..ab161793e5 100644
@@ -186,7 +186,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     case XEN_SYSCTL_page_offline_op:
     {
         uint32_t *status, *ptr;
-        unsigned long pfn;
+        mfn_t mfn;
 
         ret = xsm_page_offline(XSM_HOOK, op->u.page_offline.cmd);
         if ( ret )
@@ -205,21 +205,21 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
         memset(status, PG_OFFLINE_INVALID, sizeof(uint32_t) *
                       (op->u.page_offline.end - op->u.page_offline.start + 1));
 
-        for ( pfn = op->u.page_offline.start;
-              pfn <= op->u.page_offline.end;
-              pfn ++ )
+        for ( mfn = _mfn(op->u.page_offline.start);
+              mfn_x(mfn) <= op->u.page_offline.end;
+              mfn = mfn_add(mfn, 1) )
         {
             switch ( op->u.page_offline.cmd )
             {
                 /* Shall revert her if failed, or leave caller do it? */
                 case sysctl_page_offline:
-                    ret = offline_page(pfn, 0, ptr++);
+                    ret = offline_page(mfn, 0, ptr++);
                     break;
                 case sysctl_page_online:
-                    ret = online_page(pfn, ptr++);
+                    ret = online_page(mfn, ptr++);
                     break;
                 case sysctl_query_page_offline:
-                    ret = query_page_offline(pfn, ptr++);
+                    ret = query_page_offline(mfn, ptr++);
                     break;
                 default:
                     ret = -EINVAL;
xen/include/xen/mm.h +3 -3
index e971147234..3ba7168cc9 100644
@@ -206,9 +206,9 @@ unsigned long avail_domheap_pages(void);
 unsigned long avail_node_heap_pages(unsigned int);
 #define alloc_domheap_page(d,f) (alloc_domheap_pages(d,0,f))
 #define free_domheap_page(p)  (free_domheap_pages(p,0))
-unsigned int online_page(unsigned long mfn, uint32_t *status);
-int offline_page(unsigned long mfn, int broken, uint32_t *status);
-int query_page_offline(unsigned long mfn, uint32_t *status);
+unsigned int online_page(mfn_t mfn, uint32_t *status);
+int offline_page(mfn_t mfn, int broken, uint32_t *status);
+int query_page_offline(mfn_t mfn, uint32_t *status);
 unsigned long total_free_pages(void);
 
 void heap_init_late(void);
Signature · 7 lines
2.11.0


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

Re: [PATCH 06/14] xen: Convert hotplug page function to use typesafe MFN

Quoted 2 lines · Julien Grall

Convert online_page, offline_page and query_page_offline to use typesafe MFN.

I would like to have a statement in the commit message mentioning the changes below to mci_action_add_pageoffline and mc_memerr_dhandler.

From an ARM point of view, it is fine.

Quoted 229 lines

Note, for clarity, the words have been re-ordered in the error message updated by this patch.

No functional changes.

---
Changes:
- Update error message
- Add Jan's acked-by

---
 xen/arch/x86/cpu/mcheck/mcaction.c | 18 ++++++++++--------
 xen/common/page_alloc.c            | 24 ++++++++++++------------
 xen/common/sysctl.c                | 14 +++++++-------
 xen/include/xen/mm.h               |  6 +++---
 4 files changed, 32 insertions(+), 30 deletions(-)
xen/arch/x86/cpu/mcheck/mcaction.c +10 -8
index e42267414e..69332fb84d 100644
@@ -6,7 +6,7 @@
 
 static struct mcinfo_recovery *
 mci_action_add_pageoffline(int bank, struct mc_info *mi,
-                           uint64_t mfn, uint32_t status)
+                           mfn_t mfn, uint32_t status)
 {
     struct mcinfo_recovery *rec;
 
@@ -22,7 +22,7 @@ mci_action_add_pageoffline(int bank, struct mc_info *mi,
 
     rec->mc_bank = bank;
     rec->action_types = MC_ACTION_PAGE_OFFLINE;
-    rec->action_info.page_retire.mfn = mfn;
+    rec->action_info.page_retire.mfn = mfn_x(mfn);
     rec->action_info.page_retire.status = status;
     return rec;
 }
@@ -42,7 +42,8 @@ mc_memerr_dhandler(struct mca_binfo *binfo,
     struct mcinfo_bank *bank = binfo->mib;
     struct mcinfo_global *global = binfo->mig;
     struct domain *d;
-    unsigned long mfn, gfn;
+    mfn_t mfn;
+    unsigned long gfn;
     uint32_t status;
     int vmce_vcpuid;
     unsigned int mc_vcpuid;
@@ -54,11 +55,12 @@ mc_memerr_dhandler(struct mca_binfo *binfo,
         return;
     }
 
-    mfn = bank->mc_addr >> PAGE_SHIFT;
+    mfn = maddr_to_mfn(bank->mc_addr);
     if ( offline_page(mfn, 1, &status) )
     {
         dprintk(XENLOG_WARNING,
-                "Failed to offline page %lx for MCE error\n", mfn);
+                "Failed to offline page %"PRI_mfn" for MCE error\n",
+                mfn_x(mfn));
         return;
     }
 
@@ -89,10 +91,10 @@ mc_memerr_dhandler(struct mca_binfo *binfo,
                 ASSERT(d);
                 gfn = get_gpfn_from_mfn((bank->mc_addr) >> PAGE_SHIFT);
 
-                if ( unmmap_broken_page(d, _mfn(mfn), gfn) )
+                if ( unmmap_broken_page(d, mfn, gfn) )
                 {
-                    printk("Unmap broken memory %lx for DOM%d failed\n",
-                           mfn, d->domain_id);
+                    printk("Unmap broken memory %"PRI_mfn" for DOM%d failed\n",
+                           mfn_x(mfn), d->domain_id);
                     goto vmce_failed;
                 }
 
xen/common/page_alloc.c +12 -12
index be44158033..f445f7daec 100644
@@ -1568,23 +1568,23 @@ static int reserve_heap_page(struct page_info *pg)
 
 }
 
-int offline_page(unsigned long mfn, int broken, uint32_t *status)
+int offline_page(mfn_t mfn, int broken, uint32_t *status)
 {
     unsigned long old_info = 0;
     struct domain *owner;
     struct page_info *pg;
 
-    if ( !mfn_valid(_mfn(mfn)) )
+    if ( !mfn_valid(mfn) )
     {
         dprintk(XENLOG_WARNING,
-                "try to offline page out of range %lx\n", mfn);
+                "try to offline out of range page %"PRI_mfn"\n", mfn_x(mfn));
         return -EINVAL;
     }
 
     *status = 0;
-    pg = mfn_to_page(_mfn(mfn));
+    pg = mfn_to_page(mfn);
 
-    if ( is_xen_fixed_mfn(mfn) )
+    if ( is_xen_fixed_mfn(mfn_x(mfn)) )
     {
         *status = PG_OFFLINE_XENPAGE | PG_OFFLINE_FAILED |
           (DOMID_XEN << PG_OFFLINE_OWNER_SHIFT);
@@ -1595,7 +1595,7 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status)
      * N.B. xen's txt in x86_64 is marked reserved and handled already.
      * Also kexec range is reserved.
      */
-    if ( !page_is_ram_type(mfn, RAM_TYPE_CONVENTIONAL) )
+    if ( !page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL) )
     {
         *status = PG_OFFLINE_FAILED | PG_OFFLINE_NOT_CONV_RAM;
         return -EINVAL;
@@ -1677,19 +1677,19 @@ int offline_page(unsigned long mfn, int broken, uint32_t *status)
  *   The caller should make sure end_pfn <= max_page,
  *   if not, expand_pages() should be called prior to online_page().
  */
-unsigned int online_page(unsigned long mfn, uint32_t *status)
+unsigned int online_page(mfn_t mfn, uint32_t *status)
 {
     unsigned long x, nx, y;
     struct page_info *pg;
     int ret;
 
-    if ( !mfn_valid(_mfn(mfn)) )
+    if ( !mfn_valid(mfn) )
     {
         dprintk(XENLOG_WARNING, "call expand_pages() first\n");
         return -EINVAL;
     }
 
-    pg = mfn_to_page(_mfn(mfn));
+    pg = mfn_to_page(mfn);
 
     spin_lock(&heap_lock);
 
@@ -1730,11 +1730,11 @@ unsigned int online_page(unsigned long mfn, uint32_t *status)
     return ret;
 }
 
-int query_page_offline(unsigned long mfn, uint32_t *status)
+int query_page_offline(mfn_t mfn, uint32_t *status)
 {
     struct page_info *pg;
 
-    if ( !mfn_valid(_mfn(mfn)) || !page_is_ram_type(mfn, RAM_TYPE_CONVENTIONAL) )
+    if ( !mfn_valid(mfn) || !page_is_ram_type(mfn_x(mfn), RAM_TYPE_CONVENTIONAL) )
     {
         dprintk(XENLOG_WARNING, "call expand_pages() first\n");
         return -EINVAL;
@@ -1743,7 +1743,7 @@ int query_page_offline(unsigned long mfn, uint32_t *status)
     *status = 0;
     spin_lock(&heap_lock);
 
-    pg = mfn_to_page(_mfn(mfn));
+    pg = mfn_to_page(mfn);
 
     if ( page_state_is(pg, offlining) )
         *status |= PG_OFFLINE_STATUS_OFFLINE_PENDING;
xen/common/sysctl.c +7 -7
index c0aa6bde4e..ab161793e5 100644
@@ -186,7 +186,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
     case XEN_SYSCTL_page_offline_op:
     {
         uint32_t *status, *ptr;
-        unsigned long pfn;
+        mfn_t mfn;
 
         ret = xsm_page_offline(XSM_HOOK, op->u.page_offline.cmd);
         if ( ret )
@@ -205,21 +205,21 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
         memset(status, PG_OFFLINE_INVALID, sizeof(uint32_t) *
                       (op->u.page_offline.end - op->u.page_offline.start + 1));
 
-        for ( pfn = op->u.page_offline.start;
-              pfn <= op->u.page_offline.end;
-              pfn ++ )
+        for ( mfn = _mfn(op->u.page_offline.start);
+              mfn_x(mfn) <= op->u.page_offline.end;
+              mfn = mfn_add(mfn, 1) )
         {
             switch ( op->u.page_offline.cmd )
             {
                 /* Shall revert her if failed, or leave caller do it? */
                 case sysctl_page_offline:
-                    ret = offline_page(pfn, 0, ptr++);
+                    ret = offline_page(mfn, 0, ptr++);
                     break;
                 case sysctl_page_online:
-                    ret = online_page(pfn, ptr++);
+                    ret = online_page(mfn, ptr++);
                     break;
                 case sysctl_query_page_offline:
-                    ret = query_page_offline(pfn, ptr++);
+                    ret = query_page_offline(mfn, ptr++);
                     break;
                 default:
                     ret = -EINVAL;
xen/include/xen/mm.h +3 -3
index e971147234..3ba7168cc9 100644
@@ -206,9 +206,9 @@ unsigned long avail_domheap_pages(void);
 unsigned long avail_node_heap_pages(unsigned int);
 #define alloc_domheap_page(d,f) (alloc_domheap_pages(d,0,f))
 #define free_domheap_page(p)  (free_domheap_pages(p,0))
-unsigned int online_page(unsigned long mfn, uint32_t *status);
-int offline_page(unsigned long mfn, int broken, uint32_t *status);
-int query_page_offline(unsigned long mfn, uint32_t *status);
+unsigned int online_page(mfn_t mfn, uint32_t *status);
+int offline_page(mfn_t mfn, int broken, uint32_t *status);
+int query_page_offline(mfn_t mfn, uint32_t *status);
 unsigned long total_free_pages(void);
 
 void heap_init_late(void);
Signature · 1 line
2.11.0

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

#19 lore raw

Re: [PATCH 06/14] xen: Convert hotplug page function to use typesafe MFN

Hi Stefano,

Quoted 6 lines · Stefano Stabellini
Quoted 2 lines · Julien Grall

Convert online_page, offline_page and query_page_offline to use typesafe MFN.

I would like to have a statement in the commit message mentioning the changes below to mci_action_add_pageoffline and mc_memerr_dhandler.

I would prefer the generic wording:

"At the same time, the typesafe is propagated as far as possible without major modifications."

Quoted 2 lines

From an ARM point of view, it is fine.

Thank you!

Cheers,

Signature · 6 lines
Julien Grall

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

PATCH 7/14 xen: Convert is_xen_fixed_mfn to use typesafe MFN

In reply to Julien Grall

No functional changes.

---
Changes in v2:
- Add Jan's reviewed-by
- Add Stefano's acked-by

---
 xen/arch/x86/tboot.c     | 2 +-
 xen/common/page_alloc.c  | 2 +-
 xen/include/asm-arm/mm.h | 4 ++--
 xen/include/asm-x86/mm.h | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)
xen/arch/x86/tboot.c +1 -1
index f3fdee4d39..30d159cc62 100644
@@ -280,7 +280,7 @@ static void tboot_gen_xenheap_integrity(const uint8_t key[TB_KEY_SIZE],
 
         if ( !mfn_valid(_mfn(mfn)) )
             continue;
-        if ( is_xen_fixed_mfn(mfn) )
+        if ( is_xen_fixed_mfn(_mfn(mfn)) )
             continue; /* skip Xen */
         if ( (mfn >= PFN_DOWN(g_tboot_shared->tboot_base - 3 * PAGE_SIZE))
              && (mfn < PFN_UP(g_tboot_shared->tboot_base
xen/common/page_alloc.c +1 -1
index f445f7daec..b4067ae202 100644
@@ -1584,7 +1584,7 @@ int offline_page(mfn_t mfn, int broken, uint32_t *status)
     *status = 0;
     pg = mfn_to_page(mfn);
 
-    if ( is_xen_fixed_mfn(mfn_x(mfn)) )
+    if ( is_xen_fixed_mfn(mfn) )
     {
         *status = PG_OFFLINE_XENPAGE | PG_OFFLINE_FAILED |
           (DOMID_XEN << PG_OFFLINE_OWNER_SHIFT);
xen/include/asm-arm/mm.h +2 -2
index 7b6aaf5e3f..b56018aace 100644
@@ -151,8 +151,8 @@ extern vaddr_t xenheap_virt_start;
 #endif
 
 #define is_xen_fixed_mfn(mfn)                                   \
-    ((pfn_to_paddr(mfn) >= virt_to_maddr(&_start)) &&       \
-     (pfn_to_paddr(mfn) <= virt_to_maddr(&_end)))
+    ((mfn_to_maddr(mfn) >= virt_to_maddr(&_start)) &&           \
+     (mfn_to_maddr(mfn) <= virt_to_maddr(&_end)))
 
 #define page_get_owner(_p)    (_p)->v.inuse.domain
 #define page_set_owner(_p,_d) ((_p)->v.inuse.domain = (_d))
xen/include/asm-x86/mm.h +2 -2
index 6faa563167..f124f57964 100644
@@ -280,8 +280,8 @@ struct page_info
 #define is_xen_heap_mfn(mfn) \
     (__mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(_mfn(mfn))))
 #define is_xen_fixed_mfn(mfn)                     \
-    ((((mfn) << PAGE_SHIFT) >= __pa(&_stext)) &&  \
-     (((mfn) << PAGE_SHIFT) <= __pa(&__2M_rwdata_end)))
+    (((mfn_to_maddr(mfn)) >= __pa(&_stext)) &&    \
+     ((mfn_to_maddr(mfn)) <= __pa(&__2M_rwdata_end)))
 
 #define PRtype_info "016lx"/* should only be used for printk's */
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 7/14
#21 lore raw

Re: [PATCH 07/14] xen: Convert is_xen_fixed_mfn to use typesafe MFN

Quoted 5 lines · Julien Grall

No functional changes.

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

#22 lore raw

PATCH 8/14 xen: Convert is_xen_heap_mfn to use typesafe MFN

In reply to Julien Grall

No functional changes.

---
Changes in v2:
- Fix coding style
- Merge the declaration for gpfn and old_gpfn
- Don't open-code mfn_valid
- Add Jan's reviewed-by
- Use mfn_add(mfn, -1)
- Add Stefano's acked-by for ARM parts

---
 xen/arch/x86/mm.c              | 10 +++++-----
 xen/arch/x86/mm/p2m.c          |  2 +-
 xen/arch/x86/mm/shadow/multi.c |  2 +-
 xen/common/page_alloc.c        |  4 ++--
 xen/include/asm-arm/mm.h       |  8 ++++----
 xen/include/asm-x86/mm.h       |  2 +-
 6 files changed, 14 insertions(+), 14 deletions(-)
xen/arch/x86/mm.c +5 -5
index 9878453eb0..570e1e0deb 100644
@@ -4462,8 +4462,8 @@ int xenmem_add_to_physmap_one(
     gfn_t gpfn)
 {
     struct page_info *page = NULL;
-    unsigned long gfn = 0; /* gcc ... */
-    unsigned long prev_mfn, old_gpfn;
+    unsigned long gfn = 0 /* gcc ... */, old_gpfn;
+    mfn_t prev_mfn;
     int rc = 0;
     mfn_t mfn = INVALID_MFN;
     p2m_type_t p2mt;
@@ -4512,12 +4512,12 @@ int xenmem_add_to_physmap_one(
     }
 
     /* Remove previously mapped page if it was present. */
-    prev_mfn = mfn_x(get_gfn(d, gfn_x(gpfn), &p2mt));
-    if ( mfn_valid(_mfn(prev_mfn)) )
+    prev_mfn = get_gfn(d, gfn_x(gpfn), &p2mt);
+    if ( mfn_valid(prev_mfn) )
     {
         if ( is_xen_heap_mfn(prev_mfn) )
             /* Xen heap frames are simply unhooked from this phys slot. */
-            rc = guest_physmap_remove_page(d, gpfn, _mfn(prev_mfn), PAGE_ORDER_4K);
+            rc = guest_physmap_remove_page(d, gpfn, prev_mfn, PAGE_ORDER_4K);
         else
             /* Normal domain memory is freed, to avoid leaking memory. */
             rc = guest_remove_page(d, gfn_x(gpfn));
xen/arch/x86/mm/p2m.c +1 -1
index b16117dc56..3c98f72dbb 100644
@@ -2935,7 +2935,7 @@ int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
     prev_mfn = get_gfn(tdom, gpfn, &p2mt_prev);
     if ( mfn_valid(prev_mfn) )
     {
-        if ( is_xen_heap_mfn(mfn_x(prev_mfn)) )
+        if ( is_xen_heap_mfn(prev_mfn) )
             /* Xen heap frames are simply unhooked from this phys slot */
             rc = guest_physmap_remove_page(tdom, _gfn(gpfn), prev_mfn, 0);
         else
xen/arch/x86/mm/shadow/multi.c +1 -1
index 8781bdcfe5..35a7b606d0 100644
@@ -559,7 +559,7 @@ _sh_propagate(struct vcpu *v,
      * caching attributes in the shadows to match what was asked for.
      */
     if ( (level == 1) && is_hvm_domain(d) &&
-         !is_xen_heap_mfn(mfn_x(target_mfn)) )
+         !is_xen_heap_mfn(target_mfn) )
     {
         int type;
 
xen/common/page_alloc.c +2 -2
index b4067ae202..6061cce24f 100644
@@ -2121,9 +2121,9 @@ void init_xenheap_pages(paddr_t ps, paddr_t pe)
      * Yuk! Ensure there is a one-page buffer between Xen and Dom zones, to
      * prevent merging of power-of-two blocks across the zone boundary.
      */
-    if ( ps && !is_xen_heap_mfn(paddr_to_pfn(ps)-1) )
+    if ( ps && !is_xen_heap_mfn(mfn_add(maddr_to_mfn(ps), -1)) )
         ps += PAGE_SIZE;
-    if ( !is_xen_heap_mfn(paddr_to_pfn(pe)) )
+    if ( !is_xen_heap_mfn(maddr_to_mfn(pe)) )
         pe -= PAGE_SIZE;
 
     memguard_guard_range(maddr_to_virt(ps), pe - ps);
xen/include/asm-arm/mm.h +4 -4
index b56018aace..a9c8352b94 100644
@@ -138,16 +138,16 @@ extern vaddr_t xenheap_virt_start;
 #endif
 
 #ifdef CONFIG_ARM_32
-#define is_xen_heap_page(page) is_xen_heap_mfn(mfn_x(page_to_mfn(page)))
+#define is_xen_heap_page(page) is_xen_heap_mfn(page_to_mfn(page))
 #define is_xen_heap_mfn(mfn) ({                                 \
-    unsigned long mfn_ = (mfn);                                 \
+    unsigned long mfn_ = mfn_x(mfn);                            \
     (mfn_ >= mfn_x(xenheap_mfn_start) &&                        \
      mfn_ < mfn_x(xenheap_mfn_end));                            \
 })
 #else
 #define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
 #define is_xen_heap_mfn(mfn) \
-    (mfn_valid(_mfn(mfn)) && is_xen_heap_page(mfn_to_page(_mfn(mfn))))
+    (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn)))
 #endif
 
 #define is_xen_fixed_mfn(mfn)                                   \
@@ -246,7 +246,7 @@ static inline paddr_t __virt_to_maddr(vaddr_t va)
 #ifdef CONFIG_ARM_32
 static inline void *maddr_to_virt(paddr_t ma)
 {
-    ASSERT(is_xen_heap_mfn(ma >> PAGE_SHIFT));
+    ASSERT(is_xen_heap_mfn(maddr_to_mfn(ma)));
     ma -= mfn_to_maddr(xenheap_mfn_start);
     return (void *)(unsigned long) ma + XENHEAP_VIRT_START;
 }
xen/include/asm-x86/mm.h +1 -1
index f124f57964..6f76f004ab 100644
@@ -278,7 +278,7 @@ struct page_info
 
 #define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
 #define is_xen_heap_mfn(mfn) \
-    (__mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(_mfn(mfn))))
+    (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn)))
 #define is_xen_fixed_mfn(mfn)                     \
     (((mfn_to_maddr(mfn)) >= __pa(&_stext)) &&    \
      ((mfn_to_maddr(mfn)) <= __pa(&__2M_rwdata_end)))
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 8/14
#23 lore raw

Re: [PATCH 08/14] xen: Convert is_xen_heap_mfn to use typesafe MFN

Quoted 5 lines · Julien Grall

No functional changes.

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

#24 lore raw

PATCH 9/14 xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

In reply to Julien Grall

While Arm never had a M2P, the implementation of mfn_to_gmfn is pretty bogus as we directly return the MFN passed in parameter.

Thankfully, the use of mfn_to_gmfn is pretty limited on Arm today. There are only 3 callers:
- iommu_hwdom_init: mfn_to_gmfn is used for creating IOMMU page-tables when the P2M is not shared with the IOMMU. No issues so far as Arm does not yet support non-shared P2M case.
- memory_exchange: Arm cannot not use it because steal_page is not implemented.
- getdomaininfo: Toolstack may map the shared page. It looks like this is mostly used for mapping the P2M of PV guest. Therefore the issue might be minor.

Implementing the M2P on Arm is not planned. The M2P would require significant amount of VA address (very tough on 32-bit) that can hardly be justified with the current use of mfn_to_gmfn.
- iommu_hwdom_init: mfn_to_gmfn is used because the creating of the IOMMU page-tables is delayed until the first device is assigned. In the embedded case, we will known in most of the times what devices are assigned during the domain creation. So it is possible to take to enable the IOMMU from start. See [1] for the patch.
- memory_exchange: This does not work and I haven't seen any request for it so far.
- getdomaininfo: The structure on Arm does not seem to contain a lot of useful information on Arm. It is unclear whether we want to allow the toolstack mapping it on Arm.

This patch introduces a config option HAS_M2P to tell whether an architecture implements the M2P.
- iommu_hwdom_init: For now, we require the M2P support when the IOMMU is not sharing the P2M.
- memory_exchange: The hypercall is marked as not supported when the M2P does not exist.
- getdomaininfo: A new helper is introduced to wrap the call to mfn_to_gfn/mfn_to_gmfn. For Arm, it returns an invalid GFN so the mapping will fail.

[1] https://patchwork.kernel.org/patch/9719913/

Signed-off-by Julien Grall <[email protected]>

---

Changes in v2:
- Add a warning in public headers
- Constify local variable in domain_shared_info_gfn
- Invert the naming (_d / d) in domain_shared_info_gfn
- Use -EOPNOTSUPP rather than -ENOSYS
- Rework how the memory_exchange hypercall is removed from Arm

---
 xen/arch/x86/Kconfig            | 1 +
 xen/common/Kconfig              | 3 +++
 xen/common/domctl.c             | 2 +-
 xen/common/memory.c             | 4 ++++
 xen/drivers/passthrough/iommu.c | 6 +++++-
 xen/include/asm-arm/domain.h    | 5 +++++
 xen/include/public/domctl.h     | 4 ++++
 xen/include/xen/domain.h        | 8 ++++++++
 8 files changed, 31 insertions(+), 2 deletions(-)
xen/arch/x86/Kconfig +1 -0
index 4b8b07b549..52922a87e7 100644
@@ -16,6 +16,7 @@ config X86
 	select HAS_IOPORTS
 	select HAS_KEXEC
 	select MEM_ACCESS_ALWAYS_ON
+	select HAS_M2P
 	select HAS_MEM_PAGING
 	select HAS_MEM_SHARING
 	select HAS_NS16550
xen/common/Kconfig +3 -0
index c838506241..df871adc8f 100644
@@ -63,6 +63,9 @@ config HAS_GDBSX
 config HAS_IOPORTS
 	bool
 
+config HAS_M2P
+	bool
+
 config NEEDS_LIBELF
 	bool
 
xen/common/domctl.c +1 -1
index bade9a63b1..29940fdea5 100644
@@ -205,7 +205,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info)
     info->outstanding_pages = d->outstanding_pages;
     info->shr_pages         = atomic_read(&d->shr_pages);
     info->paged_pages       = atomic_read(&d->paged_pages);
-    info->shared_info_frame = mfn_to_gmfn(d, virt_to_mfn(d->shared_info));
+    info->shared_info_frame = gfn_x(domain_shared_info_gfn(d));
     BUG_ON(SHARED_M2P(info->shared_info_frame));
 
     info->cpupool = d->cpupool ? d->cpupool->cpupool_id : CPUPOOLID_NONE;
xen/common/memory.c +4 -0
index 86567e6117..d6a580da31 100644
@@ -512,6 +512,7 @@ static bool propagate_node(unsigned int xmf, unsigned int *memflags)
 
 static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
 {
+#ifdef CONFIG_M2P
     struct xen_memory_exchange exch;
     PAGE_LIST_HEAD(in_chunk_list);
     PAGE_LIST_HEAD(out_chunk_list);
@@ -806,6 +807,9 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
     if ( __copy_field_to_guest(arg, &exch, nr_exchanged) )
         rc = -EFAULT;
     return rc;
+#else /* !CONFIG_M2P */
+    return -EOPNOTSUPP;
+#endif
 }
 
 int xenmem_add_to_physmap(struct domain *d, struct xen_add_to_physmap *xatp,
xen/drivers/passthrough/iommu.c +5 -1
index a6697d58fb..dbb64b13bc 100644
@@ -188,9 +188,10 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
     hd->need_sync = iommu_hwdom_strict && !iommu_use_hap_pt(d);
     if ( need_iommu_pt_sync(d) )
     {
+        int rc = 0;
+#ifdef CONFIG_HAS_M2P
         struct page_info *page;
         unsigned int i = 0, flush_flags = 0;
-        int rc = 0;
 
         page_list_for_each ( page, &d->page_list )
         {
@@ -217,6 +218,9 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
         /* Use while-break to avoid compiler warning */
         while ( iommu_iotlb_flush_all(d, flush_flags) )
             break;
+#else
+        rc = -EOPNOTSUPP;
+#endif
 
         if ( rc )
             printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n",
xen/include/asm-arm/domain.h +5 -0
index 312fec8932..d61b0188da 100644
@@ -267,6 +267,11 @@ static inline void free_vcpu_guest_context(struct vcpu_guest_context *vgc)
 
 static inline void arch_vcpu_block(struct vcpu *v) {}
 
+static inline gfn_t domain_shared_info_gfn(struct domain *d)
+{
+    return INVALID_GFN;
+}
+
 #endif /* __ASM_DOMAIN_H__ */
 
 /*
xen/include/public/domctl.h +4 -0
index 19486d5e32..cac8ffffe9 100644
@@ -118,6 +118,10 @@ struct xen_domctl_getdomaininfo {
     uint64_aligned_t outstanding_pages;
     uint64_aligned_t shr_pages;
     uint64_aligned_t paged_pages;
+    /*
+     * GFN of shared_info struct. Some architectures (e.g Arm) may not
+     * provide a valid GFN.
+     */
     uint64_aligned_t shared_info_frame; /* GMFN of shared_info struct */
     uint64_aligned_t cpu_time;
     uint32_t nr_online_vcpus;    /* Number of VCPUs currently online. */
xen/include/xen/domain.h +8 -0
index d1bfc82f57..f1761fe183 100644
@@ -118,4 +118,12 @@ struct vnuma_info {
 
 void vnuma_destroy(struct vnuma_info *vnuma);
 
+#ifdef CONFIG_HAS_M2P
+#define domain_shared_info_gfn(d) ({                            \
+    const struct domain *d_ = (d);                              \
+                                                                \
+    mfn_to_gfn(d_, _mfn(__virt_to_mfn(d_->shared_info)));       \
+})
+#endif
+
 #endif /* __XEN_DOMAIN_H__ */
Signature · 7 lines
2.11.0


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

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Quoted 187 lines · Julien Grall

While Arm never had a M2P, the implementation of mfn_to_gmfn is pretty bogus as we directly return the MFN passed in parameter.

Thankfully, the use of mfn_to_gmfn is pretty limited on Arm today. There are only 3 callers:
- iommu_hwdom_init: mfn_to_gmfn is used for creating IOMMU page-tables when the P2M is not shared with the IOMMU. No issues so far as Arm does not yet support non-shared P2M case.
- memory_exchange: Arm cannot not use it because steal_page is not implemented.
- getdomaininfo: Toolstack may map the shared page. It looks like this is mostly used for mapping the P2M of PV guest. Therefore the issue might be minor.

Implementing the M2P on Arm is not planned. The M2P would require significant amount of VA address (very tough on 32-bit) that can hardly be justified with the current use of mfn_to_gmfn.
- iommu_hwdom_init: mfn_to_gmfn is used because the creating of the IOMMU page-tables is delayed until the first device is assigned. In the embedded case, we will known in most of the times what devices are assigned during the domain creation. So it is possible to take to enable the IOMMU from start. See [1] for the patch.
- memory_exchange: This does not work and I haven't seen any request for it so far.
- getdomaininfo: The structure on Arm does not seem to contain a lot of useful information on Arm. It is unclear whether we want to allow the toolstack mapping it on Arm.

This patch introduces a config option HAS_M2P to tell whether an architecture implements the M2P.
- iommu_hwdom_init: For now, we require the M2P support when the IOMMU is not sharing the P2M.
- memory_exchange: The hypercall is marked as not supported when the M2P does not exist.
- getdomaininfo: A new helper is introduced to wrap the call to mfn_to_gfn/mfn_to_gmfn. For Arm, it returns an invalid GFN so the mapping will fail.

[1] https://patchwork.kernel.org/patch/9719913/

Signed-off-by Julien Grall <[email protected]>

---

Changes in v2:
- Add a warning in public headers
- Constify local variable in domain_shared_info_gfn
- Invert the naming (_d / d) in domain_shared_info_gfn
- Use -EOPNOTSUPP rather than -ENOSYS
- Rework how the memory_exchange hypercall is removed from Arm

---
 xen/arch/x86/Kconfig            | 1 +
 xen/common/Kconfig              | 3 +++
 xen/common/domctl.c             | 2 +-
 xen/common/memory.c             | 4 ++++
 xen/drivers/passthrough/iommu.c | 6 +++++-
 xen/include/asm-arm/domain.h    | 5 +++++
 xen/include/public/domctl.h     | 4 ++++
 xen/include/xen/domain.h        | 8 ++++++++
 8 files changed, 31 insertions(+), 2 deletions(-)
xen/arch/x86/Kconfig +1 -0
index 4b8b07b549..52922a87e7 100644
@@ -16,6 +16,7 @@ config X86
 	select HAS_IOPORTS
 	select HAS_KEXEC
 	select MEM_ACCESS_ALWAYS_ON
+	select HAS_M2P
 	select HAS_MEM_PAGING
 	select HAS_MEM_SHARING
 	select HAS_NS16550
xen/common/Kconfig +3 -0
index c838506241..df871adc8f 100644
@@ -63,6 +63,9 @@ config HAS_GDBSX
 config HAS_IOPORTS
 	bool
 
+config HAS_M2P
+	bool
+
 config NEEDS_LIBELF
 	bool
 
xen/common/domctl.c +1 -1
index bade9a63b1..29940fdea5 100644
@@ -205,7 +205,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info)
     info->outstanding_pages = d->outstanding_pages;
     info->shr_pages         = atomic_read(&d->shr_pages);
     info->paged_pages       = atomic_read(&d->paged_pages);
-    info->shared_info_frame = mfn_to_gmfn(d, virt_to_mfn(d->shared_info));
+    info->shared_info_frame = gfn_x(domain_shared_info_gfn(d));
     BUG_ON(SHARED_M2P(info->shared_info_frame));
 
     info->cpupool = d->cpupool ? d->cpupool->cpupool_id : CPUPOOLID_NONE;
xen/common/memory.c +4 -0
index 86567e6117..d6a580da31 100644
@@ -512,6 +512,7 @@ static bool propagate_node(unsigned int xmf, unsigned int *memflags)
 
 static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
 {
+#ifdef CONFIG_M2P
     struct xen_memory_exchange exch;
     PAGE_LIST_HEAD(in_chunk_list);
     PAGE_LIST_HEAD(out_chunk_list);
@@ -806,6 +807,9 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
     if ( __copy_field_to_guest(arg, &exch, nr_exchanged) )
         rc = -EFAULT;
     return rc;
+#else /* !CONFIG_M2P */
+    return -EOPNOTSUPP;
+#endif
 }
 
 int xenmem_add_to_physmap(struct domain *d, struct xen_add_to_physmap *xatp,
xen/drivers/passthrough/iommu.c +5 -1
index a6697d58fb..dbb64b13bc 100644
@@ -188,9 +188,10 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
     hd->need_sync = iommu_hwdom_strict && !iommu_use_hap_pt(d);
     if ( need_iommu_pt_sync(d) )
     {
+        int rc = 0;
+#ifdef CONFIG_HAS_M2P
         struct page_info *page;
         unsigned int i = 0, flush_flags = 0;
-        int rc = 0;
 
         page_list_for_each ( page, &d->page_list )
         {
@@ -217,6 +218,9 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
         /* Use while-break to avoid compiler warning */
         while ( iommu_iotlb_flush_all(d, flush_flags) )
             break;
+#else
+        rc = -EOPNOTSUPP;
+#endif
 
         if ( rc )
             printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n",
xen/include/asm-arm/domain.h +5 -0
index 312fec8932..d61b0188da 100644
@@ -267,6 +267,11 @@ static inline void free_vcpu_guest_context(struct vcpu_guest_context *vgc)
 
 static inline void arch_vcpu_block(struct vcpu *v) {}
 
+static inline gfn_t domain_shared_info_gfn(struct domain *d)
+{
+    return INVALID_GFN;
+}
+
 #endif /* __ASM_DOMAIN_H__ */
 
 /*
xen/include/public/domctl.h +4 -0
index 19486d5e32..cac8ffffe9 100644
@@ -118,6 +118,10 @@ struct xen_domctl_getdomaininfo {
     uint64_aligned_t outstanding_pages;
     uint64_aligned_t shr_pages;
     uint64_aligned_t paged_pages;
+    /*
+     * GFN of shared_info struct. Some architectures (e.g Arm) may not
+     * provide a valid GFN.
+     */
     uint64_aligned_t shared_info_frame; /* GMFN of shared_info struct */
     uint64_aligned_t cpu_time;
     uint32_t nr_online_vcpus;    /* Number of VCPUs currently online. */
xen/include/xen/domain.h +0 -0
index d1bfc82f57..f1761fe183 100644

xen/include/xen/domain.h struct vnuma_info { · line 125

Quoted 8 lines
xen/include/xen/domain.h +5 -0
@@ -118,4 +118,12 @@ struct vnuma_info {
 
 void vnuma_destroy(struct vnuma_info *vnuma);
 
+#ifdef CONFIG_HAS_M2P
+#define domain_shared_info_gfn(d) ({                            \
+    const struct domain *d_ = (d);                              \
+                                                                \
+    mfn_to_gfn(d_, _mfn(__virt_to_mfn(d_->shared_info)));       \

Aren't you missing a _gfn here?

  _gfn(mfn_to_gfn(d, _mfn(__virt_to_mfn(d->shared_info))));

xen/include/xen/domain.h struct vnuma_info { · line 129

Quoted 4 lines
xen/include/xen/domain.h +3 -0
+})
+#endif
+
 #endif /* __XEN_DOMAIN_H__ */

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

#26 lore raw

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Hi,

Quoted 17 lines · Stefano Stabellini

xen/include/xen/domain.h struct vnuma_info { · line 125

Quoted 13 lines · Julien Grall
xen/include/xen/domain.h +5 -0
index d1bfc82f57..f1761fe183 100644
@@ -118,4 +118,12 @@ struct vnuma_info {
 
  void vnuma_destroy(struct vnuma_info *vnuma);
 
+#ifdef CONFIG_HAS_M2P
+#define domain_shared_info_gfn(d) ({                            \
+    const struct domain *d_ = (d);                              \
+                                                                \
+    mfn_to_gfn(d_, _mfn(__virt_to_mfn(d_->shared_info)));       \

Aren't you missing a _gfn here?

Quoted 1 line
   _gfn(mfn_to_gfn(d, _mfn(__virt_to_mfn(d->shared_info))));

Patch #3 of this series convert mfn_to_gfn to use typesafe MFN & GFN. So the function now return a gfn_t.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Quoted 18 lines · Julien Grall

Hi,

Quoted 15 lines · Stefano Stabellini

xen/include/xen/domain.h struct vnuma_info { · line 123

Quoted 11 lines · Julien Grall
xen/include/xen/domain.h +4 -0
index d1bfc82f57..f1761fe183 100644
@@ -118,4 +118,12 @@ struct vnuma_info {
    void vnuma_destroy(struct vnuma_info *vnuma);
  +#ifdef CONFIG_HAS_M2P
+#define domain_shared_info_gfn(d) ({                            \
+    const struct domain *d_ = (d);                              \
+                                                                \
+    mfn_to_gfn(d_, _mfn(__virt_to_mfn(d_->shared_info)));       \

Aren't you missing a _gfn here?

Quoted 4 lines
Quoted 1 line
   _gfn(mfn_to_gfn(d, _mfn(__virt_to_mfn(d->shared_info))));

Patch #3 of this series convert mfn_to_gfn to use typesafe MFN & GFN. So the function now return a gfn_t.

Ah! Somehow I am missing patches 2-3-4 in my inbox. I'll try to get them from the archive.

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

#28 lore raw

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Hi Stefano,

Quoted 19 lines · Stefano Stabellini
Quoted 18 lines · Julien Grall

Hi,

Quoted 15 lines · Stefano Stabellini

xen/include/xen/domain.h struct vnuma_info { · line 123

Quoted 11 lines · Julien Grall
xen/include/xen/domain.h +4 -0
index d1bfc82f57..f1761fe183 100644
@@ -118,4 +118,12 @@ struct vnuma_info {
     void vnuma_destroy(struct vnuma_info *vnuma);
   +#ifdef CONFIG_HAS_M2P
+#define domain_shared_info_gfn(d) ({                            \
+    const struct domain *d_ = (d);                              \
+                                                                \
+    mfn_to_gfn(d_, _mfn(__virt_to_mfn(d_->shared_info)));       \

Aren't you missing a _gfn here?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line
    _gfn(mfn_to_gfn(d, _mfn(__virt_to_mfn(d->shared_info))));

Patch #3 of this series convert mfn_to_gfn to use typesafe MFN & GFN. So the function now return a gfn_t.

Ah! Somehow I am missing patches 2-3-4 in my inbox. I'll try to get them from the archive.

Because they are x86 specific :). The rationale of implementing domain_shared_info_gfn() in common code is any arch using M2P should provide a similar helper.

Arm doesn't have an M2P, hence why mfn_to_gfn is not existent.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Quoted 28 lines · Julien Grall

Hi Stefano,

Quoted 25 lines · Stefano Stabellini
Quoted 23 lines · Julien Grall

Hi,

Quoted 15 lines · Stefano Stabellini

xen/include/xen/domain.h struct vnuma_info { · line 123

Quoted 11 lines · Julien Grall
xen/include/xen/domain.h +4 -0
index d1bfc82f57..f1761fe183 100644
@@ -118,4 +118,12 @@ struct vnuma_info {
     void vnuma_destroy(struct vnuma_info *vnuma);
   +#ifdef CONFIG_HAS_M2P
+#define domain_shared_info_gfn(d) ({                            \
+    const struct domain *d_ = (d);                              \
+                                                                \
+    mfn_to_gfn(d_, _mfn(__virt_to_mfn(d_->shared_info)));       \

Aren't you missing a _gfn here?

Quoted 1 line
    _gfn(mfn_to_gfn(d, _mfn(__virt_to_mfn(d->shared_info))));

Patch #3 of this series convert mfn_to_gfn to use typesafe MFN & GFN. So the
function now return a gfn_t.

Quoted 8 lines
Quoted 2 lines

Ah! Somehow I am missing patches 2-3-4 in my inbox. I'll try to get them from the archive.

Because they are x86 specific :). The rationale of implementing domain_shared_info_gfn() in common code is any arch using M2P should provide a similar helper.

Arm doesn't have an M2P, hence why mfn_to_gfn is not existent.

All right. Add my acked-by to this patch.

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

#30 lore raw

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

In reply to Julien Grall
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:

This patch introduces a config option HAS_M2P to tell whether an architecture implements the M2P.
- iommu_hwdom_init: For now, we require the M2P support when the IOMMU is not sharing the P2M.
- memory_exchange: The hypercall is marked as not supported when the M2P does not exist.

Was it you or someone else to suggest it be restricted to non-translated guests in the first place? I'd prefer this over the #ifdef-ary you add.

Quoted 3 lines

- getdomaininfo: A new helper is introduced to wrap the call to mfn_to_gfn/mfn_to_gmfn. For Arm, it returns an invalid GFN so the mapping will fail.

There's no use of mfn_to_gmfn() in either of the wrappers, so why mention this to-be-removed one?

xen/common/domctl.c void getdomaininfo(struct domain *d, struct · line 209

Quoted 9 lines
xen/common/domctl.c +1 -1
@@ -205,7 +205,7 @@ void getdomaininfo(struct domain *d, struct 
 xen_domctl_getdomaininfo *info)
     info->outstanding_pages = d->outstanding_pages;
     info->shr_pages         = atomic_read(&d->shr_pages);
     info->paged_pages       = atomic_read(&d->paged_pages);
-    info->shared_info_frame = mfn_to_gmfn(d, virt_to_mfn(d->shared_info));
+    info->shared_info_frame = gfn_x(domain_shared_info_gfn(d));

What is the intended behavior on 32-bit Arm here? Do you really mean to return a value with 32 bits of ones (instead of 64 bits of them) in this 64-bit field?

Quoted 15 lines
xen/drivers/passthrough/iommu.c +2 -1
@@ -188,9 +188,10 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
     hd->need_sync = iommu_hwdom_strict && !iommu_use_hap_pt(d);
     if ( need_iommu_pt_sync(d) )
     {
+        int rc = 0;
+#ifdef CONFIG_HAS_M2P
         struct page_info *page;
         unsigned int i = 0, flush_flags = 0;
-        int rc = 0;
 
         page_list_for_each ( page, &d->page_list )
         {

xen/drivers/passthrough/iommu.c void __hwdom_init iommu_hwdom_init(struct domain *d) · line 226

Quoted 9 lines
xen/drivers/passthrough/iommu.c +3 -0
@@ -217,6 +218,9 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
         /* Use while-break to avoid compiler warning */
         while ( iommu_iotlb_flush_all(d, flush_flags) )
             break;
+#else
+        rc = -EOPNOTSUPP;
+#endif
 
         if ( rc )
             printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n",

Would you mind extending the scope of the #ifdef beyond this printk()? It seems pretty pointless to me to unconditionally emit a log message here.

xen/include/public/domctl.h struct xen_domctl_getdomaininfo { · line 124

Quoted 10 lines
xen/include/public/domctl.h +4 -0
@@ -118,6 +118,10 @@ struct xen_domctl_getdomaininfo {
     uint64_aligned_t outstanding_pages;
     uint64_aligned_t shr_pages;
     uint64_aligned_t paged_pages;
+    /*
+     * GFN of shared_info struct. Some architectures (e.g Arm) may not
+     * provide a valid GFN.
+     */

Along the lines of what I've said above, I think you want to spell out here what the value is going to be in this case.

xen/include/xen/domain.h struct vnuma_info { · line 127

Quoted 13 lines
xen/include/xen/domain.h +7 -0
@@ -118,4 +118,12 @@ struct vnuma_info {
 
 void vnuma_destroy(struct vnuma_info *vnuma);
 
+#ifdef CONFIG_HAS_M2P
+#define domain_shared_info_gfn(d) ({                            \
+    const struct domain *d_ = (d);                              \
+                                                                \
+    mfn_to_gfn(d_, _mfn(__virt_to_mfn(d_->shared_info)));       \
+})
+#endif

And an inline function doesn't work here?

Jan

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

#31 lore raw

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Hi,

Quoted 10 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:

This patch introduces a config option HAS_M2P to tell whether an architecture implements the M2P.
- iommu_hwdom_init: For now, we require the M2P support when the IOMMU is not sharing the P2M.
- memory_exchange: The hypercall is marked as not supported when the M2P does not exist.

Was it you or someone else to suggest it be restricted to non-translated guests in the first place? I'd prefer this over the #ifdef-ary you add.

I never suggested that as I have no idea who is using it on x86.

But then, we would still need to implement mfn_to_gfn on Arm to make it compile. I really want to avoid such macro on Arm.

Quoted 7 lines
Quoted 4 lines

- getdomaininfo: A new helper is introduced to wrap the call to mfn_to_gfn/mfn_to_gmfn. For Arm, it returns an invalid GFN so the mapping will fail.

There's no use of mfn_to_gmfn() in either of the wrappers, so why mention this to-be-removed one?

Because code has been changed over the revision and I forgot to update the commit message.

Quoted 14 lines

xen/common/domctl.c void getdomaininfo(struct domain *d, struct · line 209

Quoted 10 lines
xen/common/domctl.c +1 -1
@@ -205,7 +205,7 @@ void getdomaininfo(struct domain *d, struct
 xen_domctl_getdomaininfo *info)
      info->outstanding_pages = d->outstanding_pages;
      info->shr_pages         = atomic_read(&d->shr_pages);
      info->paged_pages       = atomic_read(&d->paged_pages);
-    info->shared_info_frame = mfn_to_gmfn(d, virt_to_mfn(d->shared_info));
+    info->shared_info_frame = gfn_x(domain_shared_info_gfn(d));

What is the intended behavior on 32-bit Arm here? Do you really mean to return a value with 32 bits of ones (instead of 64 bits of them) in this 64-bit field?

It does not matter as long as the GFN is invalid so it can't be mapped afterwards. The exact value is not documented in the header to avoid any assumption.

Quoted 23 lines
Quoted 23 lines
xen/drivers/passthrough/iommu.c +5 -1
@@ -188,9 +188,10 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
      hd->need_sync = iommu_hwdom_strict && !iommu_use_hap_pt(d);
      if ( need_iommu_pt_sync(d) )
      {
+        int rc = 0;
+#ifdef CONFIG_HAS_M2P
          struct page_info *page;
          unsigned int i = 0, flush_flags = 0;
-        int rc = 0;
 
          page_list_for_each ( page, &d->page_list )
          {
@@ -217,6 +218,9 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
          /* Use while-break to avoid compiler warning */
          while ( iommu_iotlb_flush_all(d, flush_flags) )
              break;
+#else
+        rc = -EOPNOTSUPP;
+#endif
 
Quoted 6 lines

xen/drivers/passthrough/iommu.c void __hwdom_init iommu_hwdom_init(struct domain *d) · line 226

Quoted 2 lines
xen/drivers/passthrough/iommu.c +0 -0
          if ( rc )
              printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n",

Would you mind extending the scope of the #ifdef beyond this printk()? It seems pretty pointless to me to unconditionally emit a log message here.

Well, it at least tell you the function can't work. So I think it is still makes sense to have it.

Quoted 14 lines

xen/include/public/domctl.h struct xen_domctl_getdomaininfo { · line 124

Quoted 11 lines
xen/include/public/domctl.h +4 -0
@@ -118,6 +118,10 @@ struct xen_domctl_getdomaininfo {
      uint64_aligned_t outstanding_pages;
      uint64_aligned_t shr_pages;
      uint64_aligned_t paged_pages;
+    /*
+     * GFN of shared_info struct. Some architectures (e.g Arm) may not
+     * provide a valid GFN.
+     */

Along the lines of what I've said above, I think you want to spell out here what the value is going to be in this case.

Spelling out the exact value gives us less freedom. What matters here is the GFN return can't be mapped.

Quoted 7 lines
Quoted 7 lines
xen/include/xen/domain.h +0 -0
@@ -118,4 +118,12 @@ struct vnuma_info {
 
  void vnuma_destroy(struct vnuma_info *vnuma);
 
Quoted 9 lines

xen/include/xen/domain.h struct vnuma_info { · line 127

Quoted 7 lines
xen/include/xen/domain.h +7 -0
+#ifdef CONFIG_HAS_M2P
+#define domain_shared_info_gfn(d) ({                            \
+    const struct domain *d_ = (d);                              \
+                                                                \
+    mfn_to_gfn(d_, _mfn(__virt_to_mfn(d_->shared_info)));       \
+})
+#endif

And an inline function doesn't work here?

With enough time to rework the headers maybe. At the moment, no because mfn_to_gfn is implemented in p2m.h which depends on domain.h for the definition of struct domain d:

In file included from /home/julieng/works/xen/xen/include/xen/sched.h:11:0,

                 from x86_64/asm-offsets.c:9:
/home/julieng/works/xen/xen/include/xen/domain.h: In function ‘domain_shared_info_gfn’:
/home/julieng/works/xen/xen/include/xen/domain.h:124:12: error: implicit declaration of function ‘mfn_to_gfn’ [-Werror=implicit-function-declaration]
     return mfn_to_gfn(d, _mfn(__virt_to_mfn(d->shared_info)));
            ^~~~~~~~~~
/home/julieng/works/xen/xen/include/xen/domain.h:124:5: error: nested extern declaration of ‘mfn_to_gfn’ [-Werror=nested-externs]
     return mfn_to_gfn(d, _mfn(__virt_to_mfn(d->shared_info)));
     ^~~~~~
In file included from /home/julieng/works/xen/xen/include/asm/current.h:12:0,
                 from /home/julieng/works/xen/xen/include/asm/smp.h:10,
                 from /home/julieng/works/xen/xen/include/xen/smp.h:4,
                 from /home/julieng/works/xen/xen/include/asm/processor.h:10,
                 from /home/julieng/works/xen/xen/include/asm/system.h:6,
                 from /home/julieng/works/xen/xen/include/xen/spinlock.h:4,
                 from /home/julieng/works/xen/xen/include/xen/sched.h:6,
                 from x86_64/asm-offsets.c:9:
/home/julieng/works/xen/xen/include/xen/domain.h:124:46: error: dereferencing pointer to incomplete type ‘struct domain’
     return mfn_to_gfn(d, _mfn(__virt_to_mfn(d->shared_info)));
                                              ^
/home/julieng/works/xen/xen/include/asm/page.h:265:61: note: in definition of macro ‘virt_to_maddr’
 #define virt_to_maddr(va)   __virt_to_maddr((unsigned long)(va))
                                                             ^~
/home/julieng/works/xen/xen/include/xen/domain.h:124:31: note: in expansion of macro ‘__virt_to_mfn’
     return mfn_to_gfn(d, _mfn(__virt_to_mfn(d->shared_info)));
                               ^~~~~~~~~~~~~

cc1: all warnings being treated as errors
Makefile:217: recipe for target 'asm-offsets.s' failed make[2]: *** [asm-offsets.s] Error 1
make[2]: Leaving directory '/home/julieng/works/xen/xen/arch/x86' Makefile:136: recipe for target '/home/julieng/works/xen/xen/xen' failed make[1]: *** [/home/julieng/works/xen/xen/xen] Error 2 make[1]: Leaving directory '/home/julieng/works/xen/xen' Makefile:45: recipe for target 'build' failed
make: *** [build] Error 2

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:22, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich

xen/common/domctl.c void getdomaininfo(struct domain *d, struct · line 209

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/common/domctl.c +1 -1
@@ -205,7 +205,7 @@ void getdomaininfo(struct domain *d, struct
 xen_domctl_getdomaininfo *info)
      info->outstanding_pages = d->outstanding_pages;
      info->shr_pages         = atomic_read(&d->shr_pages);
      info->paged_pages       = atomic_read(&d->paged_pages);
-    info->shared_info_frame = mfn_to_gmfn(d, virt_to_mfn(d->shared_info));
+    info->shared_info_frame = gfn_x(domain_shared_info_gfn(d));

What is the intended behavior on 32-bit Arm here? Do you really mean to return a value with 32 bits of ones (instead of 64 bits of them) in this 64-bit field?

Quoted 3 lines

It does not matter as long as the GFN is invalid so it can't be mapped afterwards. The exact value is not documented in the header to avoid any assumption.

That's not helpful - how would a consumer know to avoid the mapping attempt in the first place?

Quoted 29 lines
Quoted 22 lines
Quoted 22 lines
xen/drivers/passthrough/iommu.c +5 -1
@@ -188,9 +188,10 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
      hd->need_sync = iommu_hwdom_strict && !iommu_use_hap_pt(d);
      if ( need_iommu_pt_sync(d) )
      {
+        int rc = 0;
+#ifdef CONFIG_HAS_M2P
          struct page_info *page;
          unsigned int i = 0, flush_flags = 0;
-        int rc = 0;
 
          page_list_for_each ( page, &d->page_list )
          {
@@ -217,6 +218,9 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
          /* Use while-break to avoid compiler warning */
          while ( iommu_iotlb_flush_all(d, flush_flags) )
              break;
+#else
+        rc = -EOPNOTSUPP;
+#endif
 
Quoted 6 lines

xen/drivers/passthrough/iommu.c void __hwdom_init iommu_hwdom_init(struct domain *d) · line 226

Quoted 2 lines
xen/drivers/passthrough/iommu.c +0 -0
          if ( rc )
              printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n",

Would you mind extending the scope of the #ifdef beyond this printk()? It seems pretty pointless to me to unconditionally emit a log message here.

Quoted 2 lines

Well, it at least tell you the function can't work. So I think it is still makes sense to have it.

I disagree.

Jan

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

#33 lore raw

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Hi Jan,

Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:22, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich

xen/common/domctl.c void getdomaininfo(struct domain *d, struct · line 209

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/common/domctl.c +1 -1
@@ -205,7 +205,7 @@ void getdomaininfo(struct domain *d, struct
 xen_domctl_getdomaininfo *info)
       info->outstanding_pages = d->outstanding_pages;
       info->shr_pages         = atomic_read(&d->shr_pages);
       info->paged_pages       = atomic_read(&d->paged_pages);
-    info->shared_info_frame = mfn_to_gmfn(d, virt_to_mfn(d->shared_info));
+    info->shared_info_frame = gfn_x(domain_shared_info_gfn(d));

What is the intended behavior on 32-bit Arm here? Do you really mean to return a value with 32 bits of ones (instead of 64 bits of them) in this 64-bit field?

Quoted 6 lines
Quoted 3 lines

It does not matter as long as the GFN is invalid so it can't be mapped afterwards. The exact value is not documented in the header to avoid any assumption.

That's not helpful - how would a consumer know to avoid the mapping attempt in the first place?

I can't see any issue with the consumer to try to map it. Ok, you will waste a couple of cycles, but that should be pretty rare.

The point here, we keep within the hypervisor the idea of what's valid or invalid. This allows us more flexibility on the value here (imagine we decide to change the value of GFN_INVALID in the future...).

Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 16 lines
xen/drivers/passthrough/iommu.c +2 -1
@@ -188,9 +188,10 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
       hd->need_sync = iommu_hwdom_strict && !iommu_use_hap_pt(d);
       if ( need_iommu_pt_sync(d) )
       {
+        int rc = 0;
+#ifdef CONFIG_HAS_M2P
           struct page_info *page;
           unsigned int i = 0, flush_flags = 0;
-        int rc = 0;
 
           page_list_for_each ( page, &d->page_list )
           {

xen/drivers/passthrough/iommu.c void __hwdom_init iommu_hwdom_init(struct domain *d) · line 226

Quoted 9 lines
xen/drivers/passthrough/iommu.c +3 -0
@@ -217,6 +218,9 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
           /* Use while-break to avoid compiler warning */
           while ( iommu_iotlb_flush_all(d, flush_flags) )
               break;
+#else
+        rc = -EOPNOTSUPP;
+#endif
 
           if ( rc )
               printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n",

Would you mind extending the scope of the #ifdef beyond this printk()? It seems pretty pointless to me to unconditionally emit a log message here.

Quoted 4 lines
Quoted 2 lines

Well, it at least tell you the function can't work. So I think it is still makes sense to have it.

I disagree.

You disagree because...?

I hope you are aware, this is unlikely going to be printed as the code should not be called. If it ever happens, it is easier for a user to grep the code for the message rather than having to add some to find out where the -EOPNOTSUPP is coming from.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:41, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:22, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich

xen/common/domctl.c void getdomaininfo(struct domain *d, struct · line 209

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/common/domctl.c +1 -1
@@ -205,7 +205,7 @@ void getdomaininfo(struct domain *d, struct
 xen_domctl_getdomaininfo *info)
       info->outstanding_pages = d->outstanding_pages;
       info->shr_pages         = atomic_read(&d->shr_pages);
       info->paged_pages       = atomic_read(&d->paged_pages);
-    info->shared_info_frame = mfn_to_gmfn(d, virt_to_mfn(d->shared_info));
+    info->shared_info_frame = gfn_x(domain_shared_info_gfn(d));

What is the intended behavior on 32-bit Arm here? Do you really mean to return a value with 32 bits of ones (instead of 64 bits of them) in this 64-bit field?

It does not matter as long as the GFN is invalid so it can't be mapped afterwards. The exact value is not documented in the header to avoid any assumption.

Quoted 5 lines
Quoted 2 lines

That's not helpful - how would a consumer know to avoid the mapping attempt in the first place?

I can't see any issue with the consumer to try to map it. Ok, you will waste a couple of cycles, but that should be pretty rare.

The attempt may result in a log message spit out.

Quoted 3 lines

The point here, we keep within the hypervisor the idea of what's valid or invalid. This allows us more flexibility on the value here (imagine we decide to change the value of GFN_INVALID in the future...).

Exactly, and hence INVALID_GFN should not become visible to the outside. Hence my request to use an all-ones value here.

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 15 lines
xen/drivers/passthrough/iommu.c +2 -1
@@ -188,9 +188,10 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
       hd->need_sync = iommu_hwdom_strict && !iommu_use_hap_pt(d);
       if ( need_iommu_pt_sync(d) )
       {
+        int rc = 0;
+#ifdef CONFIG_HAS_M2P
           struct page_info *page;
           unsigned int i = 0, flush_flags = 0;
-        int rc = 0;
 
           page_list_for_each ( page, &d->page_list )
           {

xen/drivers/passthrough/iommu.c void __hwdom_init iommu_hwdom_init(struct domain *d) · line 226

Quoted 9 lines
xen/drivers/passthrough/iommu.c +3 -0
@@ -217,6 +218,9 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
           /* Use while-break to avoid compiler warning */
           while ( iommu_iotlb_flush_all(d, flush_flags) )
               break;
+#else
+        rc = -EOPNOTSUPP;
+#endif
 
           if ( rc )
               printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n",

Would you mind extending the scope of the #ifdef beyond this printk()? It seems pretty pointless to me to unconditionally emit a log message here.

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

Well, it at least tell you the function can't work. So I think it is still makes sense to have it.

I disagree.

You disagree because...?

Because of what I've said in my initial reply (still quoted above).

Quoted 2 lines

I hope you are aware, this is unlikely going to be printed as the code should not be called.

ASSERT_UNREACHABLE() then?

Jan

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

#35 lore raw

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Hi Jan,

Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:41, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:22, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich

xen/common/domctl.c void getdomaininfo(struct domain *d, struct · line 209

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/common/domctl.c +1 -1
@@ -205,7 +205,7 @@ void getdomaininfo(struct domain *d, struct
 xen_domctl_getdomaininfo *info)
        info->outstanding_pages = d->outstanding_pages;
        info->shr_pages         = atomic_read(&d->shr_pages);
        info->paged_pages       = atomic_read(&d->paged_pages);
-    info->shared_info_frame = mfn_to_gmfn(d, virt_to_mfn(d->shared_info));
+    info->shared_info_frame = gfn_x(domain_shared_info_gfn(d));

What is the intended behavior on 32-bit Arm here? Do you really mean to return a value with 32 bits of ones (instead of 64 bits of them) in this 64-bit field?

It does not matter as long as the GFN is invalid so it can't be mapped afterwards. The exact value is not documented in the header to avoid any assumption.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

That's not helpful - how would a consumer know to avoid the mapping attempt in the first place?

I can't see any issue with the consumer to try to map it. Ok, you will waste a couple of cycles, but that should be pretty rare.

The attempt may result in a log message spit out.

I still can't see the issue here. This is nothing different than the frame were not setup beforehand.

Quoted 7 lines
Quoted 4 lines

The point here, we keep within the hypervisor the idea of what's valid or invalid. This allows us more flexibility on the value here (imagine we decide to change the value of GFN_INVALID in the future...).

Exactly, and hence INVALID_GFN should not become visible to the outside. Hence my request to use an all-ones value here.

It is only visible if you put an exact value in the documentation. Your suggestion is to put a exactly value and I would rather not see that.

Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 15 lines
xen/drivers/passthrough/iommu.c +2 -1
@@ -188,9 +188,10 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
        hd->need_sync = iommu_hwdom_strict && !iommu_use_hap_pt(d);
        if ( need_iommu_pt_sync(d) )
        {
+        int rc = 0;
+#ifdef CONFIG_HAS_M2P
            struct page_info *page;
            unsigned int i = 0, flush_flags = 0;
-        int rc = 0;
 
            page_list_for_each ( page, &d->page_list )
            {

xen/drivers/passthrough/iommu.c void __hwdom_init iommu_hwdom_init(struct domain *d) · line 226

Quoted 9 lines
xen/drivers/passthrough/iommu.c +3 -0
@@ -217,6 +218,9 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
            /* Use while-break to avoid compiler warning */
            while ( iommu_iotlb_flush_all(d, flush_flags) )
                break;
+#else
+        rc = -EOPNOTSUPP;
+#endif
 
            if ( rc )
                printk(XENLOG_WARNING "d%d: IOMMU mapping failed: %d\n",

Would you mind extending the scope of the #ifdef beyond this printk()? It seems pretty pointless to me to unconditionally emit a log message here.

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

Well, it at least tell you the function can't work. So I think it is still makes sense to have it.

I disagree.

You disagree because...?

Because of what I've said in my initial reply (still quoted above).

I still don't see the problem of unconditional log message. It is not really the first place we have that.

Quoted 5 lines
Quoted 3 lines

I hope you are aware, this is unlikely going to be printed as the code should not be called.

ASSERT_UNREACHABLE() then?

And still avoiding the printk?

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 16:04, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:41, <[email protected]> wrote:

The point here, we keep within the hypervisor the idea of what's valid or invalid. This allows us more flexibility on the value here (imagine we decide to change the value of GFN_INVALID in the future...).

Exactly, and hence INVALID_GFN should not become visible to the outside. Hence my request to use an all-ones value here.

It is only visible if you put an exact value in the documentation. Your suggestion is to put a exactly value and I would rather not see that.

I did specifically suggest to _not_ store INVALID_GFN here, but to store 64-bit bits of ones. Note the difference between the two on 32-bit Arm.

Quoted 12 lines
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

Well, it at least tell you the function can't work. So I think it is still makes sense to have it.

I disagree.

You disagree because...?

Because of what I've said in my initial reply (still quoted above).

I still don't see the problem of unconditional log message. It is not really the first place we have that.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

I hope you are aware, this is unlikely going to be printed as the code should not be called.

ASSERT_UNREACHABLE() then?

And still avoiding the printk?

Preferably yes; depends on how exactly you code the assertion. If you follow the if()-ASSERT_UNREACHABLE()-return style we've been using elsewhere, then no matter how you place the #else or #endif the printk() will be compiled out.

Jan

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

#37 lore raw

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Hi Jan,

Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 16:04, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:41, <[email protected]> wrote:

The point here, we keep within the hypervisor the idea of what's valid or invalid. This allows us more flexibility on the value here (imagine we decide to change the value of GFN_INVALID in the future...).

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Exactly, and hence INVALID_GFN should not become visible to the outside. Hence my request to use an all-ones value here.

It is only visible if you put an exact value in the documentation. Your suggestion is to put a exactly value and I would rather not see that.

I did specifically suggest to _not_ store INVALID_GFN here, but to store 64-bit bits of ones. Note the difference between the two on 32-bit Arm.

Your point of having an exact value is only useful if you want to toolstack to silently ignore the missing frame and avoid a call.

The former is pretty much wrong as if you were trying to read the frame then most likely you wanted to access it. So a message makes sense here.

For the latter, avoiding the call is only going to save you a couple of cycles in a likely cold path.

You really don't need to give an exact (including say all ones). You only need to say that the address return may not be mappable. The toolstack will try to map it and fail. That's not a big deal.

Anyway, I will wait and see what's the view from the tools maintainer.

Quoted 5 lines

Preferably yes; depends on how exactly you code the assertion. If you follow the if()-ASSERT_UNREACHABLE()-return style we've been using elsewhere, then no matter how you place the #else or #endif the printk() will be compiled out.

I will have a look.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 09/14] xen: Introduce HAS_M2P config and use to protect mfn_to_gmfn call

Hi,

Answering to myself.

Quoted 18 lines · Julien Grall
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 16:04, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:41, <[email protected]> wrote:

The point here, we keep within the hypervisor the idea of what's valid or invalid. This allows us more flexibility on the value here (imagine we decide to change the value of GFN_INVALID in the future...).

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Exactly, and hence INVALID_GFN should not become visible to the outside. Hence my request to use an all-ones value here.

It is only visible if you put an exact value in the documentation. Your suggestion is to put a exactly value and I would rather not see that.

I did specifically suggest to _not_ store INVALID_GFN here, but to store 64-bit bits of ones. Note the difference between the two on 32-bit Arm.

Your point of having an exact value is only useful if you want to toolstack to silently ignore the missing frame and avoid a call.

Quoted 7 lines

The former is pretty much wrong as if you were trying to read the frame then most likely you wanted to access it. So a message makes sense here.

For the latter, avoiding the call is only going to save you a couple of cycles in a likely cold path.

You really don't need to give an exact (including say all ones). You only need to say that the address return may not be mappable. The toolstack will try to map it and fail. That's not a big deal.

Anyway, I will wait and see what's the view from the tools maintainer.

I had a discussion with Ian on IRC regarding the value here. After some debate we agreed that specifying a single value would be best.

At the moment, Xen only supports 48-bits address that could be covered by 36-bit MFN. Newer Arm revision supports up to 52-bit address, but that's only with 64KB page granularity. Even if we were supporting 64-bit address, it would only cover 48-bit, so all ones should still be invalid. So I am happy with the all ones version.

I will introduce a define so the tools can use it rather than an hardcoded value.

Cheers,

Signature · 6 lines
Julien Grall

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

PATCH 10/14 xen: Remove mfn_to_gmfn macro

In reply to Julien Grall

On x86, mfn_to_gmfn can be replaced with mfn_to_gfn. On Arm, there are no more call to mfn_to_gmfn, so the helper can be dropped.

At the same time rework a comment in Arm code that does not make sense.

---
Changes in v2:
- Add Jan's and Stefano's acked-by

---
 xen/drivers/passthrough/iommu.c | 7 +++----
 xen/include/asm-arm/mm.h        | 4 +---
 xen/include/asm-x86/mm.h        | 5 -----
 3 files changed, 4 insertions(+), 12 deletions(-)
xen/drivers/passthrough/iommu.c +3 -4
index dbb64b13bc..054f71b919 100644
@@ -195,8 +195,8 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
 
         page_list_for_each ( page, &d->page_list )
         {
-            unsigned long mfn = mfn_x(page_to_mfn(page));
-            unsigned long dfn = mfn_to_gmfn(d, mfn);
+            mfn_t mfn = page_to_mfn(page);
+            dfn_t dfn = _dfn(gfn_x(mfn_to_gfn(d, mfn)));
             unsigned int mapping = IOMMUF_readable;
             int ret;
 
@@ -205,8 +205,7 @@ void __hwdom_init iommu_hwdom_init(struct domain *d)
                   == PGT_writable_page) )
                 mapping |= IOMMUF_writable;
 
-            ret = iommu_map(d, _dfn(dfn), _mfn(mfn), 0, mapping,
-                            &flush_flags);
+            ret = iommu_map(d, dfn, mfn, 0, mapping, &flush_flags);
 
             if ( !rc )
                 rc = ret;
xen/include/asm-arm/mm.h +1 -3
index a9c8352b94..a9cb98a6c7 100644
@@ -321,10 +321,8 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
 #define SHARED_M2P_ENTRY         (~0UL - 1UL)
 #define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
 
-/* Xen always owns P2M on ARM */
+/* We don't have a M2P on Arm */
 #define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn); } while (0)
-#define mfn_to_gmfn(_d, mfn)  (mfn)
-
 
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
xen/include/asm-x86/mm.h +0 -5
index 6f76f004ab..717378730b 100644
@@ -506,11 +506,6 @@ extern struct rangeset *mmio_ro_ranges;
 
 #define get_gpfn_from_mfn(mfn)      (machine_to_phys_mapping[(mfn)])
 
-#define mfn_to_gmfn(_d, mfn)                            \
-    ( (paging_mode_translate(_d))                       \
-      ? get_gpfn_from_mfn(mfn)                          \
-      : (mfn) )
-
 #define compat_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
 #define compat_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
 
Signature · 7 lines
2.11.0


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

PATCH 11/14 xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function

In reply to Julien Grall

set_gpfn_from_mfn() is currently implement in a 2 part macros. The second macro is only called within the first macro, so they can be folded together.

Furthermore, this is now converted to a static inline making the code more readable and safer.

As set_gpfn_from_mfn is now a static inline function, the extern variable dom_cow should be defined earlier on. For convenience, the definition of all dom_* variables are moved earlier on.

---
Changes in v2:
- Patch added

---
 xen/include/asm-x86/mm.h | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
xen/include/asm-x86/mm.h +15 -14
index 717378730b..4721725c60 100644
@@ -442,6 +442,8 @@ int check_descriptor(const struct domain *d, seg_desc_t *desc);
 
 extern paddr_t mem_hotplug;
 
+extern struct domain *dom_xen, *dom_io, *dom_cow;	/* for vmcoreinfo */
+
 /******************************************************************************
  * With shadow pagetables, the different kinds of address start
  * to get get confusing.
@@ -483,24 +485,25 @@ extern paddr_t mem_hotplug;
 #define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
 
 #define compat_machine_to_phys_mapping ((unsigned int *)RDWR_COMPAT_MPT_VIRT_START)
-#define _set_gpfn_from_mfn(mfn, pfn) ({                        \
-    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn))); \
-    unsigned long entry = (d && (d == dom_cow)) ?              \
-        SHARED_M2P_ENTRY : (pfn);                              \
-    ((void)((mfn) >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 || \
-            (compat_machine_to_phys_mapping[(mfn)] = (unsigned int)(entry))), \
-     machine_to_phys_mapping[(mfn)] = (entry));                \
-    })
 
 /*
  * Disable some users of set_gpfn_from_mfn() (e.g., free_heap_pages()) until
  * the machine_to_phys_mapping is actually set up.
  */
 extern bool machine_to_phys_mapping_valid;
-#define set_gpfn_from_mfn(mfn, pfn) do {        \
-    if ( machine_to_phys_mapping_valid )        \
-        _set_gpfn_from_mfn(mfn, pfn);           \
-} while (0)
+
+static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+{
+    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;
+
+    if (!machine_to_phys_mapping_valid)
+        return;
+
+    if ( mfn >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )
+        compat_machine_to_phys_mapping[mfn] = entry;
+    machine_to_phys_mapping[mfn] = entry;
+}
 
 extern struct rangeset *mmio_ro_ranges;
 
@@ -592,8 +595,6 @@ unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
 
 unsigned long domain_get_maximum_gpfn(struct domain *d);
 
-extern struct domain *dom_xen, *dom_io, *dom_cow;	/* for vmcoreinfo */
-
 /* Definition of an mm lock: spinlock with extra fields for debugging */
 typedef struct mm_lock {
     spinlock_t         lock;
Signature · 7 lines
2.11.0


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

Re: [PATCH 11/14] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function

xen/include/asm-x86/mm.h extern paddr_t mem_hotplug; · line 498

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/include/asm-x86/mm.h +4 -0
+static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+{
+    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;

The && here looks, ehm, funny, but I guess it's needed for early boot? But that's perhaps a separate thing to clean up. However, looking at this - why is Arm setting up dom_cow in the first place?

Quoted 1 line

+ if (!machine_to_phys_mapping_valid)

Please add the missing blanks.

xen/include/asm-x86/mm.h extern paddr_t mem_hotplug; · line 503

Quoted 3 lines
xen/include/asm-x86/mm.h +3 -0
+        return;
+
+    if ( mfn >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )

You've inverted the original condition (by re-using it verbatim) - I'm pretty sure this is going to crash.

Jan

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

#42 lore raw

Re: [PATCH 11/14] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function

Hi,

Quoted 7 lines · Jan Beulich

xen/include/asm-x86/mm.h extern paddr_t mem_hotplug; · line 498

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/include/asm-x86/mm.h +4 -0
+static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+{
+    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;

The && here looks, ehm, funny, but I guess it's needed for early boot?

I have no idea, this is x86 not Arm...

Quoted 2 lines

But that's perhaps a separate thing to clean up. However, looking at this - why is Arm setting up dom_cow in the first place?

Common code is using dom_cow, so I don't think we want it to be NULL on Arm to avoid weird issues.

Quoted 4 lines
Quoted 2 lines

+ if (!machine_to_phys_mapping_valid)

Please add the missing blanks.

Ok.

Quoted 7 lines

xen/include/asm-x86/mm.h extern paddr_t mem_hotplug; · line 503

Quoted 4 lines
xen/include/asm-x86/mm.h +3 -0
+        return;
+
+    if ( mfn >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )

You've inverted the original condition (by re-using it verbatim) - I'm pretty sure this is going to crash.

Good point, I will update the patch.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 11/14] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:27, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich

xen/include/asm-x86/mm.h extern paddr_t mem_hotplug; · line 498

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/include/asm-x86/mm.h +4 -0
+static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+{
+    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;

The && here looks, ehm, funny, but I guess it's needed for early boot?

Quoted 7 lines

I have no idea, this is x86 not Arm...

Quoted 2 lines

But that's perhaps a separate thing to clean up. However, looking at this - why is Arm setting up dom_cow in the first place?

Common code is using dom_cow, so I don't think we want it to be NULL on Arm to avoid weird issues.

I didn't mean it to remain NULL. Common code doesn't dereference it (and isn't supposed to), so I'd consider initializing it to some known faulting non-NULL address, if there is such on Arm.

Jan

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

#44 lore raw

Re: [PATCH 11/14] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function

Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:27, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich

xen/include/asm-x86/mm.h extern paddr_t mem_hotplug; · line 498

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/include/asm-x86/mm.h +4 -0
+static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+{
+    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;

The && here looks, ehm, funny, but I guess it's needed for early boot?

I have no idea, this is x86 not Arm...

Quoted 2 lines

But that's perhaps a separate thing to clean up. However, looking at this - why is Arm setting up dom_cow in the first place?

Quoted 6 lines
Quoted 2 lines

Common code is using dom_cow, so I don't think we want it to be NULL on Arm to avoid weird issues.

I didn't mean it to remain NULL. Common code doesn't dereference it (and isn't supposed to), so I'd consider initializing it to some known faulting non-NULL address, if there is such on Arm.

Patches are welcomed ;).

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 11/14] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function

Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:41, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:27, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich

xen/include/asm-x86/mm.h extern paddr_t mem_hotplug; · line 498

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/include/asm-x86/mm.h +4 -0
+static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+{
+    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;

The && here looks, ehm, funny, but I guess it's needed for early boot?

I have no idea, this is x86 not Arm...

Quoted 2 lines

But that's perhaps a separate thing to clean up. However, looking at this - why is Arm setting up dom_cow in the first place?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Common code is using dom_cow, so I don't think we want it to be NULL on Arm to avoid weird issues.

I didn't mean it to remain NULL. Common code doesn't dereference it (and isn't supposed to), so I'd consider initializing it to some known faulting non-NULL address, if there is such on Arm.

Patches are welcomed ;).

So is there such an address on Arm?

Jan

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

#46 lore raw

Re: [PATCH 11/14] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function

Hi,

Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:41, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:27, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich

xen/include/asm-x86/mm.h extern paddr_t mem_hotplug; · line 498

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/include/asm-x86/mm.h +4 -0
+static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+{
+    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;

The && here looks, ehm, funny, but I guess it's needed for early boot?

I have no idea, this is x86 not Arm...

Quoted 2 lines

But that's perhaps a separate thing to clean up. However, looking at this - why is Arm setting up dom_cow in the first place?

Common code is using dom_cow, so I don't think we want it to be NULL on Arm to avoid weird issues.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I didn't mean it to remain NULL. Common code doesn't dereference it (and isn't supposed to), so I'd consider initializing it to some known faulting non-NULL address, if there is such on Arm.

Patches are welcomed ;).

So is there such an address on Arm?

0 - 2MB is unmapped so far. I don't know whether this will still be the case (at least for the range 4KB - 2MB) with the rework I am attempting.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 11/14] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 16:05, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:41, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich

I didn't mean it to remain NULL. Common code doesn't dereference it (and isn't supposed to), so I'd consider initializing it to some known faulting non-NULL address, if there is such on Arm.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Patches are welcomed ;).

So is there such an address on Arm?

0 - 2MB is unmapped so far. I don't know whether this will still be the case (at least for the range 4KB - 2MB) with the rework I am attempting.

Hmm, I was hoping for an architecturally faulting address, like the non-canonical ones we have on x86-64.

Jan

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

#48 lore raw

Re: [PATCH 11/14] xen/x86: mm: Re-implement set_gpfn_from_mfn() as a static inline function

Hi,

Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 16:05, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:41, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich

I didn't mean it to remain NULL. Common code doesn't dereference it (and isn't supposed to), so I'd consider initializing it to some known faulting non-NULL address, if there is such on Arm.

Patches are welcomed ;).

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

So is there such an address on Arm?

0 - 2MB is unmapped so far. I don't know whether this will still be the case (at least for the range 4KB - 2MB) with the rework I am attempting.

Hmm, I was hoping for an architecturally faulting address, like the non-canonical ones we have on x86-64.

Nothing we can reliably use across Armv7 and Armv8 (and future extension).

Cheers,

Signature · 6 lines
Julien Grall

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

PATCH 12/14 xen/x86: pv: Convert update_intpte() to use typesafe MFN

In reply to Julien Grall

The third parameter of update_intpte() is a MFN, so it can be switched to use the typesafe.

At the same time, the typesafe is propagated as far as possible without major modifications.

---
Changes in v2:
- Patch added

---
 xen/arch/x86/mm.c               | 84 ++++++++++++++++++++---------------------
 xen/arch/x86/pv/grant_table.c   |  6 +--
 xen/arch/x86/pv/mm.h            |  6 +--
 xen/arch/x86/pv/ro-page-fault.c |  2 +-
 4 files changed, 49 insertions(+), 49 deletions(-)
xen/arch/x86/mm.c +42 -42
index 570e1e0deb..7d887f2699 100644
@@ -2080,7 +2080,7 @@ void page_unlock(struct page_info *page)
 
 /* Update the L1 entry at pl1e to new value nl1e. */
 static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e,
-                        unsigned long gl1mfn, unsigned int cmd,
+                        mfn_t gl1mfn, unsigned int cmd,
                         struct vcpu *pt_vcpu, struct domain *pg_dom)
 {
     bool preserve_ad = (cmd == MMU_PT_UPDATE_PRESERVE_AD);
@@ -2177,8 +2177,8 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e,
     }
     else if ( pv_l1tf_check_l1e(pt_dom, nl1e) )
         return -ERESTART;
-    else if ( unlikely(!UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,
-                                     preserve_ad)) )
+    else if ( unlikely(!UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn,
+                                     pt_vcpu, preserve_ad)) )
     {
         return -EBUSY;
     }
@@ -2188,16 +2188,16 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e,
 }
 
 
-/* Update the L2 entry at pl2e to new value nl2e. pl2e is within frame pfn. */
+/* Update the L2 entry at pl2e to new value nl2e. pl2e is within frame mfn. */
 static int mod_l2_entry(l2_pgentry_t *pl2e,
                         l2_pgentry_t nl2e,
-                        unsigned long pfn,
+                        mfn_t mfn,
                         int preserve_ad,
                         struct vcpu *vcpu)
 {
     l2_pgentry_t ol2e;
     struct domain *d = vcpu->domain;
-    struct page_info *l2pg = mfn_to_page(_mfn(pfn));
+    struct page_info *l2pg = mfn_to_page(mfn);
     unsigned long type = l2pg->u.inuse.type_info;
     int rc = 0;
 
@@ -2224,16 +2224,16 @@ static int mod_l2_entry(l2_pgentry_t *pl2e,
         if ( !l2e_has_changed(ol2e, nl2e, ~FASTPATH_FLAG_WHITELIST) )
         {
             nl2e = adjust_guest_l2e(nl2e, d);
-            if ( UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu, preserve_ad) )
+            if ( UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, mfn, vcpu, preserve_ad) )
                 return 0;
             return -EBUSY;
         }
 
-        if ( unlikely((rc = get_page_from_l2e(nl2e, pfn, d, 0)) < 0) )
+        if ( unlikely((rc = get_page_from_l2e(nl2e, mfn_x(mfn), d, 0)) < 0) )
             return rc;
 
         nl2e = adjust_guest_l2e(nl2e, d);
-        if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu,
+        if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, mfn, vcpu,
                                     preserve_ad)) )
         {
             ol2e = nl2e;
@@ -2242,21 +2242,21 @@ static int mod_l2_entry(l2_pgentry_t *pl2e,
     }
     else if ( pv_l1tf_check_l2e(d, nl2e) )
         return -ERESTART;
-    else if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, pfn, vcpu,
+    else if ( unlikely(!UPDATE_ENTRY(l2, pl2e, ol2e, nl2e, mfn, vcpu,
                                      preserve_ad)) )
     {
         return -EBUSY;
     }
 
-    put_page_from_l2e(ol2e, pfn, 0, true);
+    put_page_from_l2e(ol2e, mfn_x(mfn), 0, true);
 
     return rc;
 }
 
-/* Update the L3 entry at pl3e to new value nl3e. pl3e is within frame pfn. */
+/* Update the L3 entry at pl3e to new value nl3e. pl3e is within frame mfn. */
 static int mod_l3_entry(l3_pgentry_t *pl3e,
                         l3_pgentry_t nl3e,
-                        unsigned long pfn,
+                        mfn_t mfn,
                         int preserve_ad,
                         struct vcpu *vcpu)
 {
@@ -2287,17 +2287,17 @@ static int mod_l3_entry(l3_pgentry_t *pl3e,
         if ( !l3e_has_changed(ol3e, nl3e, ~FASTPATH_FLAG_WHITELIST) )
         {
             nl3e = adjust_guest_l3e(nl3e, d);
-            rc = UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, pfn, vcpu, preserve_ad);
+            rc = UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, mfn, vcpu, preserve_ad);
             return rc ? 0 : -EFAULT;
         }
 
-        rc = get_page_from_l3e(nl3e, pfn, d, 0);
+        rc = get_page_from_l3e(nl3e, mfn_x(mfn), d, 0);
         if ( unlikely(rc < 0) )
             return rc;
         rc = 0;
 
         nl3e = adjust_guest_l3e(nl3e, d);
-        if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, pfn, vcpu,
+        if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, mfn, vcpu,
                                     preserve_ad)) )
         {
             ol3e = nl3e;
@@ -2306,7 +2306,7 @@ static int mod_l3_entry(l3_pgentry_t *pl3e,
     }
     else if ( pv_l1tf_check_l3e(d, nl3e) )
         return -ERESTART;
-    else if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, pfn, vcpu,
+    else if ( unlikely(!UPDATE_ENTRY(l3, pl3e, ol3e, nl3e, mfn, vcpu,
                                      preserve_ad)) )
     {
         return -EFAULT;
@@ -2316,14 +2316,14 @@ static int mod_l3_entry(l3_pgentry_t *pl3e,
         if ( !create_pae_xen_mappings(d, pl3e) )
             BUG();
 
-    put_page_from_l3e(ol3e, pfn, 0, 1);
+    put_page_from_l3e(ol3e, mfn_x(mfn), 0, 1);
     return rc;
 }
 
-/* Update the L4 entry at pl4e to new value nl4e. pl4e is within frame pfn. */
+/* Update the L4 entry at pl4e to new value nl4e. pl4e is within frame mfn. */
 static int mod_l4_entry(l4_pgentry_t *pl4e,
                         l4_pgentry_t nl4e,
-                        unsigned long pfn,
+                        mfn_t mfn,
                         int preserve_ad,
                         struct vcpu *vcpu)
 {
@@ -2354,17 +2354,17 @@ static int mod_l4_entry(l4_pgentry_t *pl4e,
         if ( !l4e_has_changed(ol4e, nl4e, ~FASTPATH_FLAG_WHITELIST) )
         {
             nl4e = adjust_guest_l4e(nl4e, d);
-            rc = UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, pfn, vcpu, preserve_ad);
+            rc = UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, mfn, vcpu, preserve_ad);
             return rc ? 0 : -EFAULT;
         }
 
-        rc = get_page_from_l4e(nl4e, pfn, d, 0);
+        rc = get_page_from_l4e(nl4e, mfn_x(mfn), d, 0);
         if ( unlikely(rc < 0) )
             return rc;
         rc = 0;
 
         nl4e = adjust_guest_l4e(nl4e, d);
-        if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, pfn, vcpu,
+        if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, mfn, vcpu,
                                     preserve_ad)) )
         {
             ol4e = nl4e;
@@ -2373,13 +2373,13 @@ static int mod_l4_entry(l4_pgentry_t *pl4e,
     }
     else if ( pv_l1tf_check_l4e(d, nl4e) )
         return -ERESTART;
-    else if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, pfn, vcpu,
+    else if ( unlikely(!UPDATE_ENTRY(l4, pl4e, ol4e, nl4e, mfn, vcpu,
                                      preserve_ad)) )
     {
         return -EFAULT;
     }
 
-    put_page_from_l4e(ol4e, pfn, 0, 1);
+    put_page_from_l4e(ol4e, mfn_x(mfn), 0, 1);
     return rc;
 }
 #endif /* CONFIG_PV */
@@ -3083,7 +3083,7 @@ int new_guest_cr3(mfn_t mfn)
                           l4e_from_mfn(mfn,
                                        (_PAGE_PRESENT | _PAGE_RW |
                                         _PAGE_USER | _PAGE_ACCESSED)),
-                          mfn_x(gt_mfn), 0, curr);
+                          gt_mfn, 0, curr);
         unmap_domain_page(pl4e);
         switch ( rc )
         {
@@ -3752,12 +3752,12 @@ long do_mmu_update(
 {
     struct mmu_update req;
     void *va = NULL;
-    unsigned long gpfn, gmfn, mfn;
+    unsigned long gpfn, gmfn;
     struct page_info *page;
     unsigned int cmd, i = 0, done = 0, pt_dom;
     struct vcpu *curr = current, *v = curr;
     struct domain *d = v->domain, *pt_owner = d, *pg_owner;
-    mfn_t map_mfn = INVALID_MFN;
+    mfn_t map_mfn = INVALID_MFN, mfn;
     bool sync_guest = false;
     uint32_t xsm_needed = 0;
     uint32_t xsm_checked = 0;
@@ -3883,14 +3883,14 @@ long do_mmu_update(
                 break;
             }
 
-            mfn = mfn_x(page_to_mfn(page));
+            mfn = page_to_mfn(page);
 
-            if ( !mfn_eq(_mfn(mfn), map_mfn) )
+            if ( !mfn_eq(mfn, map_mfn) )
             {
                 if ( va )
                     unmap_domain_page(va);
-                va = map_domain_page(_mfn(mfn));
-                map_mfn = _mfn(mfn);
+                va = map_domain_page(mfn);
+                map_mfn = mfn;
             }
             va = _p(((unsigned long)va & PAGE_MASK) + (req.ptr & ~PAGE_MASK));
 
@@ -3926,7 +3926,8 @@ long do_mmu_update(
                     {
                         bool local_in_use = false;
 
-                        if ( pagetable_get_pfn(curr->arch.guest_table) == mfn )
+                        if ( mfn_eq(pagetable_get_mfn(curr->arch.guest_table),
+                                    mfn) )
                         {
                             local_in_use = true;
                             get_cpu_info()->root_pgt_changed = true;
@@ -3939,15 +3940,15 @@ long do_mmu_update(
                          */
                         if ( (page->u.inuse.type_info & PGT_count_mask) >
                              (1 + !!(page->u.inuse.type_info & PGT_pinned) +
-                              (pagetable_get_pfn(curr->arch.guest_table_user) ==
-                               mfn) + local_in_use) )
+                              (mfn_eq(pagetable_get_mfn(curr->arch.guest_table_user),
+                                      mfn)) + local_in_use) )
                             sync_guest = true;
                     }
                     break;
 
                 case PGT_writable_page:
                     perfc_incr(writable_mmu_updates);
-                    if ( paging_write_guest_entry(v, va, req.val, _mfn(mfn)) )
+                    if ( paging_write_guest_entry(v, va, req.val, mfn) )
                         rc = 0;
                     break;
                 }
@@ -3958,7 +3959,7 @@ long do_mmu_update(
             else if ( get_page_type(page, PGT_writable_page) )
             {
                 perfc_incr(writable_mmu_updates);
-                if ( paging_write_guest_entry(v, va, req.val, _mfn(mfn)) )
+                if ( paging_write_guest_entry(v, va, req.val, mfn) )
                     rc = 0;
                 put_page_type(page);
             }
@@ -3980,7 +3981,7 @@ long do_mmu_update(
                 break;
             }
 
-            mfn = req.ptr >> PAGE_SHIFT;
+            mfn = maddr_to_mfn(req.ptr);
             gpfn = req.val;
 
             xsm_needed |= XSM_MMU_MACHPHYS_UPDATE;
@@ -3992,7 +3993,7 @@ long do_mmu_update(
                 xsm_checked = xsm_needed;
             }
 
-            page = get_page_from_mfn(_mfn(mfn), pg_owner);
+            page = get_page_from_mfn(mfn, pg_owner);
             if ( unlikely(!page) )
             {
                 gdprintk(XENLOG_WARNING,
@@ -4001,7 +4002,7 @@ long do_mmu_update(
                 break;
             }
 
-            set_gpfn_from_mfn(mfn, gpfn);
+            set_gpfn_from_mfn(mfn_x(mfn), gpfn);
             paging_mark_pfn_dirty(pg_owner, _pfn(gpfn));
 
             put_page(page);
@@ -4257,8 +4258,7 @@ static int __do_update_va_mapping(
         goto out;
     }
 
-    rc = mod_l1_entry(pl1e, val, mfn_x(gl1mfn), MMU_NORMAL_PT_UPDATE, v,
-                      pg_owner);
+    rc = mod_l1_entry(pl1e, val, gl1mfn, MMU_NORMAL_PT_UPDATE, v, pg_owner);
 
     page_unlock(gl1pg);
     put_page(gl1pg);
xen/arch/x86/pv/grant_table.c +3 -3
index 5180334f42..0325618c98 100644
@@ -108,7 +108,7 @@ int create_grant_pv_mapping(uint64_t addr, mfn_t frame,
         goto out_unlock;
 
     ol1e = *pl1e;
-    if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn_x(gl1mfn), curr, 0) )
+    if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, curr, 0) )
         rc = GNTST_okay;
 
  out_unlock:
@@ -165,7 +165,7 @@ static bool steal_linear_address(unsigned long linear, l1_pgentry_t *out)
         goto out_unlock;
 
     ol1e = *pl1e;
-    okay = UPDATE_ENTRY(l1, pl1e, ol1e, l1e_empty(), mfn_x(gl1mfn), curr, 0);
+    okay = UPDATE_ENTRY(l1, pl1e, ol1e, l1e_empty(), gl1mfn, curr, 0);
 
     if ( okay )
         *out = ol1e;
@@ -293,7 +293,7 @@ int replace_grant_pv_mapping(uint64_t addr, mfn_t frame,
                  "PTE flags %x for %"PRIx64" don't match grant (%x)\n",
                  l1e_get_flags(ol1e), addr, grant_pte_flags);
 
-    if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn_x(gl1mfn), curr, 0) )
+    if ( UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, curr, 0) )
         rc = GNTST_okay;
 
  out_unlock:
xen/arch/x86/pv/mm.h +3 -3
index 976209ba4c..ef84dbb41c 100644
@@ -37,7 +37,7 @@ static inline l1_pgentry_t guest_get_eff_l1e(unsigned long linear)
  * Returns false for failure (pointer not valid), true for success.
  */
 static inline bool update_intpte(intpte_t *p, intpte_t old, intpte_t new,
-                                 unsigned long mfn, struct vcpu *v,
+                                 mfn_t mfn, struct vcpu *v,
                                  bool preserve_ad)
 {
     bool rv = true;
@@ -45,7 +45,7 @@ static inline bool update_intpte(intpte_t *p, intpte_t old, intpte_t new,
 #ifndef PTE_UPDATE_WITH_CMPXCHG
     if ( !preserve_ad )
     {
-        rv = paging_write_guest_entry(v, p, new, _mfn(mfn));
+        rv = paging_write_guest_entry(v, p, new, mfn);
     }
     else
 #endif
@@ -59,7 +59,7 @@ static inline bool update_intpte(intpte_t *p, intpte_t old, intpte_t new,
             if ( preserve_ad )
                 _new |= old & (_PAGE_ACCESSED | _PAGE_DIRTY);
 
-            rv = paging_cmpxchg_guest_entry(v, p, &t, _new, _mfn(mfn));
+            rv = paging_cmpxchg_guest_entry(v, p, &t, _new, mfn);
             if ( unlikely(rv == 0) )
             {
                 gdprintk(XENLOG_WARNING,
xen/arch/x86/pv/ro-page-fault.c +1 -1
index e7a7179dda..92911076ef 100644
@@ -197,7 +197,7 @@ static int ptwr_emulated_update(unsigned long addr, intpte_t *p_old,
     else
     {
         ol1e = *pl1e;
-        if ( !UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn_x(mfn), v, 0) )
+        if ( !UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, mfn, v, 0) )
             BUG();
     }
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 12/14
#50 lore raw

Re: [PATCH 12/14] xen/x86: pv: Convert update_intpte() to use typesafe MFN

xen/arch/x86/mm.c static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e, · line 2181

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm.c +2 -2
@@ -2177,8 +2177,8 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e,
     }
     else if ( pv_l1tf_check_l1e(pt_dom, nl1e) )
         return -ERESTART;
-    else if ( unlikely(!UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,
-                                     preserve_ad)) )
+    else if ( unlikely(!UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn,
+                                     pt_vcpu, preserve_ad)) )

Stray change?

xen/arch/x86/mm.c long do_mmu_update( · line 3944

Quoted 8 lines
xen/arch/x86/mm.c +2 -2
@@ -3939,15 +3940,15 @@ long do_mmu_update(
                          */
                         if ( (page->u.inuse.type_info & PGT_count_mask) >
                              (1 + !!(page->u.inuse.type_info & PGT_pinned) +
-                              (pagetable_get_pfn(curr->arch.guest_table_user) ==
-                               mfn) + local_in_use) )
+                              (mfn_eq(pagetable_get_mfn(curr->arch.guest_table_user),
+                                      mfn)) + local_in_use) )

There's a stray pair of parentheses now left around a function call.

xen/arch/x86/pv/mm.h static inline l1_pgentry_t guest_get_eff_l1e(unsigned long linear) · line 41

Quoted 9 lines
xen/arch/x86/pv/mm.h +1 -1
@@ -37,7 +37,7 @@ static inline l1_pgentry_t guest_get_eff_l1e(unsigned long linear)
  * Returns false for failure (pointer not valid), true for success.
  */
 static inline bool update_intpte(intpte_t *p, intpte_t old, intpte_t new,
-                                 unsigned long mfn, struct vcpu *v,
+                                 mfn_t mfn, struct vcpu *v,
                                  bool preserve_ad)

Would you mind re-flowing this, as the last parameter declaration now fits on the earlier line?

With at least the former two taken care of

Jan

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

#51 lore raw

Re: [PATCH 12/14] xen/x86: pv: Convert update_intpte() to use typesafe MFN

Quoted 11 lines · Jan Beulich

xen/arch/x86/mm.c static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e, · line 2181

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm.c +2 -2
@@ -2177,8 +2177,8 @@ static int mod_l1_entry(l1_pgentry_t *pl1e, l1_pgentry_t nl1e,
      }
      else if ( pv_l1tf_check_l1e(pt_dom, nl1e) )
          return -ERESTART;
-    else if ( unlikely(!UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn, pt_vcpu,
-                                     preserve_ad)) )
+    else if ( unlikely(!UPDATE_ENTRY(l1, pl1e, ol1e, nl1e, gl1mfn,
+                                     pt_vcpu, preserve_ad)) )

Stray change?

Yes, I will fix it.

Quoted 11 lines

xen/arch/x86/mm.c long do_mmu_update( · line 3944

Quoted 9 lines
xen/arch/x86/mm.c +2 -2
@@ -3939,15 +3940,15 @@ long do_mmu_update(
                           */
                          if ( (page->u.inuse.type_info & PGT_count_mask) >
                               (1 + !!(page->u.inuse.type_info & PGT_pinned) +
-                              (pagetable_get_pfn(curr->arch.guest_table_user) ==
-                               mfn) + local_in_use) )
+                              (mfn_eq(pagetable_get_mfn(curr->arch.guest_table_user),
+                                      mfn)) + local_in_use) )

There's a stray pair of parentheses now left around a function call.

Ok.

Quoted 13 lines

xen/arch/x86/pv/mm.h static inline l1_pgentry_t guest_get_eff_l1e(unsigned long linear) · line 41

Quoted 10 lines
xen/arch/x86/pv/mm.h +1 -1
@@ -37,7 +37,7 @@ static inline l1_pgentry_t guest_get_eff_l1e(unsigned long linear)
   * Returns false for failure (pointer not valid), true for success.
   */
  static inline bool update_intpte(intpte_t *p, intpte_t old, intpte_t new,
-                                 unsigned long mfn, struct vcpu *v,
+                                 mfn_t mfn, struct vcpu *v,
                                   bool preserve_ad)

Would you mind re-flowing this, as the last parameter declaration now fits on the earlier line?

Ok.

Quoted 3 lines

With at least the former two taken care of

Thank you.

Cheers,

Signature · 6 lines
Julien Grall

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

PATCH 13/14 xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

In reply to Julien Grall

The first parameter of {s,g}et_gpfn_from_mfn() is an MFN, so it can be switched to use the typesafe.

At the same time, replace gpfn with pfn in the helpers as they all deal with PFN and also turn the macros to static inline.

Note that the return of the getter and the 2nd parameter of the setter have not been converted to use typesafe PFN because it was requiring more changes than expected.

---
Changes in v2:
- Patch added

---
 xen/arch/x86/cpu/mcheck/mcaction.c |  2 +-
 xen/arch/x86/mm.c                  | 14 ++++----
 xen/arch/x86/mm/mem_sharing.c      | 19 +++++------
 xen/arch/x86/mm/p2m-pod.c          |  4 +--
 xen/arch/x86/mm/p2m-pt.c           | 37 ++++++++++-----------
 xen/arch/x86/mm/p2m.c              | 66 +++++++++++++++++++-------------------
 xen/arch/x86/mm/paging.c           |  4 +--
 xen/arch/x86/pv/dom0_build.c       |  6 ++--
 xen/arch/x86/x86_64/traps.c        | 41 +++++++++++------------
 xen/common/memory.c                |  2 +-
 xen/common/page_alloc.c            |  2 +-
 xen/include/asm-arm/mm.h           |  2 +-
 xen/include/asm-x86/grant_table.h  |  2 +-
 xen/include/asm-x86/mm.h           | 16 +++++----
 xen/include/asm-x86/p2m.h          |  2 +-
 15 files changed, 113 insertions(+), 106 deletions(-)
xen/arch/x86/cpu/mcheck/mcaction.c +1 -1
index 69332fb84d..5e78fb7703 100644
@@ -89,7 +89,7 @@ mc_memerr_dhandler(struct mca_binfo *binfo,
             {
                 d = get_domain_by_id(bank->mc_domid);
                 ASSERT(d);
-                gfn = get_gpfn_from_mfn((bank->mc_addr) >> PAGE_SHIFT);
+                gfn = get_pfn_from_mfn(maddr_to_mfn(bank->mc_addr));
 
                 if ( unmmap_broken_page(d, mfn, gfn) )
                 {
xen/arch/x86/mm.c +7 -7
index 7d887f2699..60c47582be 100644
@@ -502,7 +502,7 @@ void share_xen_page_with_guest(struct page_info *page, struct domain *d,
     if ( page_get_owner(page) == d )
         return;
 
-    set_gpfn_from_mfn(mfn_x(page_to_mfn(page)), INVALID_M2P_ENTRY);
+    set_pfn_from_mfn(page_to_mfn(page), INVALID_M2P_ENTRY);
 
     spin_lock(&d->page_alloc_lock);
 
@@ -1077,7 +1077,7 @@ get_page_from_l1e(
 
             gdprintk(XENLOG_WARNING, "Error updating mappings for mfn %" PRI_mfn
                      " (pfn %" PRI_pfn ", from L1 entry %" PRIpte ") for d%d\n",
-                     mfn, get_gpfn_from_mfn(mfn),
+                     mfn, get_pfn_from_mfn(_mfn(mfn)),
                      l1e_get_intpte(l1e), l1e_owner->domain_id);
             return err;
         }
@@ -1088,7 +1088,7 @@ get_page_from_l1e(
  could_not_pin:
     gdprintk(XENLOG_WARNING, "Error getting mfn %" PRI_mfn " (pfn %" PRI_pfn
              ") from L1 entry %" PRIpte " for l1e_owner d%d, pg_owner d%d\n",
-             mfn, get_gpfn_from_mfn(mfn),
+             mfn, get_pfn_from_mfn(_mfn(mfn)),
              l1e_get_intpte(l1e), l1e_owner->domain_id, pg_owner->domain_id);
     if ( real_pg_owner != NULL )
         put_page(page);
@@ -2604,7 +2604,7 @@ static int alloc_page_type(struct page_info *page, unsigned long type,
                  " (pfn %" PRI_pfn ") for type %" PRtype_info
                  ": caf=%08lx taf=%" PRtype_info "\n",
                  mfn_x(page_to_mfn(page)),
-                 get_gpfn_from_mfn(mfn_x(page_to_mfn(page))),
+                 get_pfn_from_mfn(page_to_mfn(page)),
                  type, page->count_info, page->u.inuse.type_info);
         if ( page != current->arch.old_guest_table )
             page->u.inuse.type_info = 0;
@@ -2890,7 +2890,7 @@ static int _get_page_type(struct page_info *page, unsigned long type,
                      "Bad type (saw %" PRtype_info " != exp %" PRtype_info ") "
                      "for mfn %" PRI_mfn " (pfn %" PRI_pfn ")\n",
                      x, type, mfn_x(page_to_mfn(page)),
-                     get_gpfn_from_mfn(mfn_x(page_to_mfn(page))));
+                     get_pfn_from_mfn(page_to_mfn(page)));
             return -EINVAL;
         }
         else if ( unlikely(!(x & PGT_validated)) )
@@ -4002,7 +4002,7 @@ long do_mmu_update(
                 break;
             }
 
-            set_gpfn_from_mfn(mfn_x(mfn), gpfn);
+            set_pfn_from_mfn(mfn, gpfn);
             paging_mark_pfn_dirty(pg_owner, _pfn(gpfn));
 
             put_page(page);
@@ -4529,7 +4529,7 @@ int xenmem_add_to_physmap_one(
         goto put_both;
 
     /* Unmap from old location, if any. */
-    old_gpfn = get_gpfn_from_mfn(mfn_x(mfn));
+    old_gpfn = get_pfn_from_mfn(mfn);
     ASSERT(!SHARED_M2P(old_gpfn));
     if ( space == XENMAPSPACE_gmfn && old_gpfn != gfn )
     {
xen/arch/x86/mm/mem_sharing.c +10 -9
index 5ac9d8f54c..af903c11e9 100644
@@ -391,11 +391,12 @@ static inline void mem_sharing_gfn_destroy(struct page_info *page,
     xfree(gfn_info);
 }
 
-static struct page_info* mem_sharing_lookup(unsigned long mfn)
+static struct page_info* mem_sharing_lookup(mfn_t mfn)
 {
-    if ( mfn_valid(_mfn(mfn)) )
+    if ( mfn_valid(mfn) )
     {
-        struct page_info* page = mfn_to_page(_mfn(mfn));
+        struct page_info* page = mfn_to_page(mfn);
+
         if ( page_get_owner(page) == dom_cow )
         {
             /* Count has to be at least two, because we're called
@@ -404,7 +405,7 @@ static struct page_info* mem_sharing_lookup(unsigned long mfn)
             unsigned long t = read_atomic(&page->u.inuse.type_info);
             ASSERT((t & PGT_type_mask) == PGT_shared_page);
             ASSERT((t & PGT_count_mask) >= 2);
-            ASSERT(SHARED_M2P(get_gpfn_from_mfn(mfn)));
+            ASSERT(SHARED_M2P(get_pfn_from_mfn(mfn)));
             return page;
         }
     }
@@ -464,10 +465,10 @@ static int audit(void)
         }
 
         /* Check the m2p entry */
-        if ( !SHARED_M2P(get_gpfn_from_mfn(mfn_x(mfn))) )
+        if ( !SHARED_M2P(get_pfn_from_mfn(mfn)) )
         {
            MEM_SHARING_DEBUG("mfn %lx shared, but wrong m2p entry (%lx)!\n",
-                             mfn_x(mfn), get_gpfn_from_mfn(mfn_x(mfn)));
+                             mfn_x(mfn), get_pfn_from_mfn(mfn));
            errors++;
         }
 
@@ -693,7 +694,7 @@ static inline struct page_info *__grab_shared_page(mfn_t mfn)
     if ( !mem_sharing_page_lock(pg) )
         return NULL;
 
-    if ( mem_sharing_lookup(mfn_x(mfn)) == NULL )
+    if ( mem_sharing_lookup(mfn) == NULL )
     {
         mem_sharing_page_unlock(pg);
         return NULL;
@@ -877,7 +878,7 @@ static int nominate_page(struct domain *d, gfn_t gfn,
     atomic_inc(&nr_shared_mfns);
 
     /* Update m2p entry to SHARED_M2P_ENTRY */
-    set_gpfn_from_mfn(mfn_x(mfn), SHARED_M2P_ENTRY);
+    set_pfn_from_mfn(mfn, SHARED_M2P_ENTRY);
 
     *phandle = page->sharing->handle;
     audit_add_list(page);
@@ -1222,7 +1223,7 @@ private_page_found:
     }
 
     /* Update m2p entry */
-    set_gpfn_from_mfn(mfn_x(page_to_mfn(page)), gfn);
+    set_pfn_from_mfn(page_to_mfn(page), gfn);
 
     /* Now that the gfn<->mfn map is properly established,
      * marking dirty is feasible */
xen/arch/x86/mm/p2m-pod.c +2 -2
index 4313863066..9e001738f4 100644
@@ -652,7 +652,7 @@ p2m_pod_decrease_reservation(struct domain *d, gfn_t gfn, unsigned int order)
             }
             p2m_tlb_flush_sync(p2m);
             for ( j = 0; j < n; ++j )
-                set_gpfn_from_mfn(mfn_x(mfn), INVALID_M2P_ENTRY);
+                set_pfn_from_mfn(mfn, INVALID_M2P_ENTRY);
             p2m_pod_cache_add(p2m, page, cur_order);
 
             steal_for_cache =  ( p2m->pod.entry_count > p2m->pod.count );
@@ -1203,7 +1203,7 @@ p2m_pod_demand_populate(struct p2m_domain *p2m, gfn_t gfn,
 
     for( i = 0; i < (1UL << order); i++ )
     {
-        set_gpfn_from_mfn(mfn_x(mfn) + i, gfn_x(gfn_aligned) + i);
+        set_pfn_from_mfn(mfn_add(mfn, i), gfn_x(gfn_aligned) + i);
         paging_mark_pfn_dirty(d, _pfn(gfn_x(gfn_aligned) + i));
     }
 
xen/arch/x86/mm/p2m-pt.c +19 -18
index cafc9f299b..0e85819f9b 100644
@@ -991,7 +991,8 @@ static int p2m_pt_change_entry_type_range(struct p2m_domain *p2m,
 long p2m_pt_audit_p2m(struct p2m_domain *p2m)
 {
     unsigned long entry_count = 0, pmbad = 0;
-    unsigned long mfn, gfn, m2pfn;
+    unsigned long gfn, m2pfn;
+    mfn_t mfn;
 
     ASSERT(p2m_locked_by_me(p2m));
     ASSERT(pod_locked_by_me(p2m));
@@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                 /* check for 1GB super page */
                 if ( l3e_get_flags(l3e[i3]) & _PAGE_PSE )
                 {
-                    mfn = l3e_get_pfn(l3e[i3]);
-                    ASSERT(mfn_valid(_mfn(mfn)));
+                    mfn = l3e_get_mfn(l3e[i3]);
+                    ASSERT(mfn_valid(mfn));
                     /* we have to cover 512x512 4K pages */
                     for ( i2 = 0; 
                           i2 < (L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES);
                           i2++)
                     {
-                        m2pfn = get_gpfn_from_mfn(mfn+i2);
+                        m2pfn = get_pfn_from_mfn(mfn_add(mfn, i2));
                         if ( m2pfn != (gfn + i2) )
                         {
                             pmbad++;
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn+i2, mfn+i2,
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" gfn %#lx\n",
+                                       gfn + i2, mfn_x(mfn_add(mfn, i2)),
                                        m2pfn);
                             BUG();
                         }
@@ -1067,17 +1068,17 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                     /* check for super page */
                     if ( l2e_get_flags(l2e[i2]) & _PAGE_PSE )
                     {
-                        mfn = l2e_get_pfn(l2e[i2]);
-                        ASSERT(mfn_valid(_mfn(mfn)));
+                        mfn = l2e_get_mfn(l2e[i2]);
+                        ASSERT(mfn_valid(mfn));
                         for ( i1 = 0; i1 < L1_PAGETABLE_ENTRIES; i1++)
                         {
-                            m2pfn = get_gpfn_from_mfn(mfn+i1);
+                            m2pfn = get_pfn_from_mfn(mfn_add(mfn, i1));
                             /* Allow shared M2Ps */
                             if ( (m2pfn != (gfn + i1)) && !SHARED_M2P(m2pfn) )
                             {
                                 pmbad++;
-                                P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                           " -> gfn %#lx\n", gfn+i1, mfn+i1,
+                                P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                           gfn + i1, mfn_x(mfn_add(mfn, i1)),
                                            m2pfn);
                                 BUG();
                             }
@@ -1099,19 +1100,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                                 entry_count++;
                             continue;
                         }
-                        mfn = l1e_get_pfn(l1e[i1]);
-                        ASSERT(mfn_valid(_mfn(mfn)));
-                        m2pfn = get_gpfn_from_mfn(mfn);
+                        mfn = l1e_get_mfn(l1e[i1]);
+                        ASSERT(mfn_valid(mfn));
+                        m2pfn = get_pfn_from_mfn(mfn);
                         if ( m2pfn != gfn &&
                              type != p2m_mmio_direct &&
                              !p2m_is_grant(type) &&
                              !p2m_is_shared(type) )
                         {
                             pmbad++;
-                            printk("mismatch: gfn %#lx -> mfn %#lx"
-                                   " -> gfn %#lx\n", gfn, mfn, m2pfn);
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn, mfn, m2pfn);
+                            printk("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                   gfn, mfn_x(mfn), m2pfn);
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                       gfn, mfn_x(mfn), m2pfn);
                             BUG();
                         }
                     }
xen/arch/x86/mm/p2m.c +33 -33

183 lines not on this page · raw message

xen/arch/x86/mm/paging.c +2 -2
index 9b0f268e74..cef2f90186 100644
@@ -344,7 +344,7 @@ void paging_mark_dirty(struct domain *d, mfn_t gmfn)
         return;
 
     /* We /really/ mean PFN here, even for non-translated guests. */
-    pfn = _pfn(get_gpfn_from_mfn(mfn_x(gmfn)));
+    pfn = _pfn(get_pfn_from_mfn(gmfn));
 
     paging_mark_pfn_dirty(d, pfn);
 }
@@ -362,7 +362,7 @@ int paging_mfn_is_dirty(struct domain *d, mfn_t gmfn)
     ASSERT(paging_mode_log_dirty(d));
 
     /* We /really/ mean PFN here, even for non-translated guests. */
-    pfn = _pfn(get_gpfn_from_mfn(mfn_x(gmfn)));
+    pfn = _pfn(get_pfn_from_mfn(gmfn));
     /* Invalid pages can't be dirty. */
     if ( unlikely(!VALID_M2P(pfn_x(pfn))) )
         return 0;
xen/arch/x86/pv/dom0_build.c +3 -3
index cef2d42254..b39ab67092 100644
@@ -39,7 +39,7 @@ void __init dom0_update_physmap(struct domain *d, unsigned long pfn,
     else
         ((unsigned int *)vphysmap_s)[pfn] = mfn;
 
-    set_gpfn_from_mfn(mfn, pfn);
+    set_pfn_from_mfn(_mfn(mfn), pfn);
 }
 
 static __init void mark_pv_pt_pages_rdonly(struct domain *d,
@@ -798,8 +798,8 @@ int __init dom0_construct_pv(struct domain *d,
     page_list_for_each ( page, &d->page_list )
     {
         mfn = mfn_x(page_to_mfn(page));
-        BUG_ON(SHARED_M2P(get_gpfn_from_mfn(mfn)));
-        if ( get_gpfn_from_mfn(mfn) >= count )
+        BUG_ON(SHARED_M2P(get_pfn_from_mfn(_mfn(mfn))));
+        if ( get_pfn_from_mfn(_mfn(mfn)) >= count )
         {
             BUG_ON(is_pv_32bit_domain(d));
             if ( !page->u.inuse.type_info &&
xen/arch/x86/x86_64/traps.c +21 -20

80 lines not on this page · raw message

xen/common/memory.c +1 -1
index d6a580da31..eecc9671ff 100644
@@ -273,7 +273,7 @@ static void populate_physmap(struct memop_args *a)
             if ( !paging_mode_translate(d) )
             {
                 for ( j = 0; j < (1U << a->extent_order); j++ )
-                    set_gpfn_from_mfn(mfn_x(mfn_add(mfn, j)), gpfn + j);
+                    set_pfn_from_mfn(mfn_add(mfn, j), gpfn + j);
 
                 /* Inform the domain of the new page's machine address. */ 
                 if ( unlikely(__copy_mfn_to_guest_offset(a->extent_list, i,
xen/common/page_alloc.c +1 -1
index 6061cce24f..a100e03e2e 100644
@@ -1424,7 +1424,7 @@ static void free_heap_pages(
 
         /* This page is not a guest frame any more. */
         page_set_owner(&pg[i], NULL); /* set_gpfn_from_mfn snoops pg owner */
-        set_gpfn_from_mfn(mfn_x(mfn) + i, INVALID_M2P_ENTRY);
+        set_pfn_from_mfn(mfn_add(mfn, + i), INVALID_M2P_ENTRY);
 
         if ( need_scrub )
         {
xen/include/asm-arm/mm.h +1 -1
index a9cb98a6c7..3c03be3bca 100644
@@ -322,7 +322,7 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
 #define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
 
 /* We don't have a M2P on Arm */
-#define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn); } while (0)
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
 
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
xen/include/asm-x86/grant_table.h +1 -1
index 661228dd39..d731b9e49f 100644
@@ -41,7 +41,7 @@ static inline int replace_grant_host_mapping(uint64_t addr, mfn_t frame,
 #define gnttab_get_frame_gfn(gt, st, idx) ({                             \
     mfn_t mfn_ = (st) ? gnttab_status_mfn(gt, idx)                       \
                       : gnttab_shared_mfn(gt, idx);                      \
-    unsigned long gpfn_ = get_gpfn_from_mfn(mfn_x(mfn_));                \
+    unsigned long gpfn_ = get_pfn_from_mfn(mfn_);                        \
     VALID_M2P(gpfn_) ? _gfn(gpfn_) : INVALID_GFN;                        \
 })
 
xen/include/asm-x86/mm.h +10 -6
index 4721725c60..bce60619c3 100644
@@ -492,22 +492,26 @@ extern struct domain *dom_xen, *dom_io, *dom_cow;	/* for vmcoreinfo */
  */
 extern bool machine_to_phys_mapping_valid;
 
-static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn)
 {
-    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    const unsigned long mfn_ = mfn_x(mfn);
+    struct domain *d = page_get_owner(mfn_to_page(mfn));
     unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;
 
     if (!machine_to_phys_mapping_valid)
         return;
 
-    if ( mfn >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )
-        compat_machine_to_phys_mapping[mfn] = entry;
-    machine_to_phys_mapping[mfn] = entry;
+    if ( mfn_ >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )
+        compat_machine_to_phys_mapping[mfn_] = entry;
+    machine_to_phys_mapping[mfn_] = entry;
 }
 
 extern struct rangeset *mmio_ro_ranges;
 
-#define get_gpfn_from_mfn(mfn)      (machine_to_phys_mapping[(mfn)])
+static inline unsigned long get_pfn_from_mfn(mfn_t mfn)
+{
+    return machine_to_phys_mapping[mfn_x(mfn)];
+}
 
 #define compat_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
 #define compat_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
xen/include/asm-x86/p2m.h +1 -1
index 0157568be9..07b7ec6db0 100644
@@ -509,7 +509,7 @@ static inline struct page_info *get_page_from_gfn(
 static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn)
 {
     if ( paging_mode_translate(d) )
-        return _gfn(get_gpfn_from_mfn(mfn_x(mfn)));
+        return _gfn(get_pfn_from_mfn(mfn));
     else
         return _gfn(mfn_x(mfn));
 }
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 13/14
#53 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

Quoted 4 lines · Julien Grall

The first parameter of {s,g}et_gpfn_from_mfn() is an MFN, so it can be switched to use the typesafe.

Quoted 8 lines

At the same time, replace gpfn with pfn in the helpers as they all deal with PFN and also turn the macros to static inline.

Note that the return of the getter and the 2nd parameter of the setter have not been converted to use typesafe PFN because it was requiring more changes than expected.

For the mem_sharing bits:

Quoted 716 lines

---
Changes in v2:
- Patch added

---
 xen/arch/x86/cpu/mcheck/mcaction.c |  2 +-
 xen/arch/x86/mm.c                  | 14 ++++----
 xen/arch/x86/mm/mem_sharing.c      | 19 +++++------
 xen/arch/x86/mm/p2m-pod.c          |  4 +--
 xen/arch/x86/mm/p2m-pt.c           | 37 ++++++++++-----------
 xen/arch/x86/mm/p2m.c              | 66 +++++++++++++++++++-------------------
 xen/arch/x86/mm/paging.c           |  4 +--
 xen/arch/x86/pv/dom0_build.c       |  6 ++--
 xen/arch/x86/x86_64/traps.c        | 41 +++++++++++------------
 xen/common/memory.c                |  2 +-
 xen/common/page_alloc.c            |  2 +-
 xen/include/asm-arm/mm.h           |  2 +-
 xen/include/asm-x86/grant_table.h  |  2 +-
 xen/include/asm-x86/mm.h           | 16 +++++----
 xen/include/asm-x86/p2m.h          |  2 +-
 15 files changed, 113 insertions(+), 106 deletions(-)
xen/arch/x86/cpu/mcheck/mcaction.c +1 -1
index 69332fb84d..5e78fb7703 100644
@@ -89,7 +89,7 @@ mc_memerr_dhandler(struct mca_binfo *binfo,
             {
                 d = get_domain_by_id(bank->mc_domid);
                 ASSERT(d);
-                gfn = get_gpfn_from_mfn((bank->mc_addr) >> PAGE_SHIFT);
+                gfn = get_pfn_from_mfn(maddr_to_mfn(bank->mc_addr));
 
                 if ( unmmap_broken_page(d, mfn, gfn) )
                 {
xen/arch/x86/mm.c +7 -7
index 7d887f2699..60c47582be 100644
@@ -502,7 +502,7 @@ void share_xen_page_with_guest(struct page_info *page, struct domain *d,
     if ( page_get_owner(page) == d )
         return;
 
-    set_gpfn_from_mfn(mfn_x(page_to_mfn(page)), INVALID_M2P_ENTRY);
+    set_pfn_from_mfn(page_to_mfn(page), INVALID_M2P_ENTRY);
 
     spin_lock(&d->page_alloc_lock);
 
@@ -1077,7 +1077,7 @@ get_page_from_l1e(
 
             gdprintk(XENLOG_WARNING, "Error updating mappings for mfn %" PRI_mfn
                      " (pfn %" PRI_pfn ", from L1 entry %" PRIpte ") for d%d\n",
-                     mfn, get_gpfn_from_mfn(mfn),
+                     mfn, get_pfn_from_mfn(_mfn(mfn)),
                      l1e_get_intpte(l1e), l1e_owner->domain_id);
             return err;
         }
@@ -1088,7 +1088,7 @@ get_page_from_l1e(
  could_not_pin:
     gdprintk(XENLOG_WARNING, "Error getting mfn %" PRI_mfn " (pfn %" PRI_pfn
              ") from L1 entry %" PRIpte " for l1e_owner d%d, pg_owner d%d\n",
-             mfn, get_gpfn_from_mfn(mfn),
+             mfn, get_pfn_from_mfn(_mfn(mfn)),
              l1e_get_intpte(l1e), l1e_owner->domain_id, pg_owner->domain_id);
     if ( real_pg_owner != NULL )
         put_page(page);
@@ -2604,7 +2604,7 @@ static int alloc_page_type(struct page_info *page, unsigned long type,
                  " (pfn %" PRI_pfn ") for type %" PRtype_info
                  ": caf=%08lx taf=%" PRtype_info "\n",
                  mfn_x(page_to_mfn(page)),
-                 get_gpfn_from_mfn(mfn_x(page_to_mfn(page))),
+                 get_pfn_from_mfn(page_to_mfn(page)),
                  type, page->count_info, page->u.inuse.type_info);
         if ( page != current->arch.old_guest_table )
             page->u.inuse.type_info = 0;
@@ -2890,7 +2890,7 @@ static int _get_page_type(struct page_info *page, unsigned long type,
                      "Bad type (saw %" PRtype_info " != exp %" PRtype_info ") "
                      "for mfn %" PRI_mfn " (pfn %" PRI_pfn ")\n",
                      x, type, mfn_x(page_to_mfn(page)),
-                     get_gpfn_from_mfn(mfn_x(page_to_mfn(page))));
+                     get_pfn_from_mfn(page_to_mfn(page)));
             return -EINVAL;
         }
         else if ( unlikely(!(x & PGT_validated)) )
@@ -4002,7 +4002,7 @@ long do_mmu_update(
                 break;
             }
 
-            set_gpfn_from_mfn(mfn_x(mfn), gpfn);
+            set_pfn_from_mfn(mfn, gpfn);
             paging_mark_pfn_dirty(pg_owner, _pfn(gpfn));
 
             put_page(page);
@@ -4529,7 +4529,7 @@ int xenmem_add_to_physmap_one(
         goto put_both;
 
     /* Unmap from old location, if any. */
-    old_gpfn = get_gpfn_from_mfn(mfn_x(mfn));
+    old_gpfn = get_pfn_from_mfn(mfn);
     ASSERT(!SHARED_M2P(old_gpfn));
     if ( space == XENMAPSPACE_gmfn && old_gpfn != gfn )
     {
xen/arch/x86/mm/mem_sharing.c +10 -9
index 5ac9d8f54c..af903c11e9 100644
@@ -391,11 +391,12 @@ static inline void mem_sharing_gfn_destroy(struct page_info *page,
     xfree(gfn_info);
 }
 
-static struct page_info* mem_sharing_lookup(unsigned long mfn)
+static struct page_info* mem_sharing_lookup(mfn_t mfn)
 {
-    if ( mfn_valid(_mfn(mfn)) )
+    if ( mfn_valid(mfn) )
     {
-        struct page_info* page = mfn_to_page(_mfn(mfn));
+        struct page_info* page = mfn_to_page(mfn);
+
         if ( page_get_owner(page) == dom_cow )
         {
             /* Count has to be at least two, because we're called
@@ -404,7 +405,7 @@ static struct page_info* mem_sharing_lookup(unsigned long mfn)
             unsigned long t = read_atomic(&page->u.inuse.type_info);
             ASSERT((t & PGT_type_mask) == PGT_shared_page);
             ASSERT((t & PGT_count_mask) >= 2);
-            ASSERT(SHARED_M2P(get_gpfn_from_mfn(mfn)));
+            ASSERT(SHARED_M2P(get_pfn_from_mfn(mfn)));
             return page;
         }
     }
@@ -464,10 +465,10 @@ static int audit(void)
         }
 
         /* Check the m2p entry */
-        if ( !SHARED_M2P(get_gpfn_from_mfn(mfn_x(mfn))) )
+        if ( !SHARED_M2P(get_pfn_from_mfn(mfn)) )
         {
            MEM_SHARING_DEBUG("mfn %lx shared, but wrong m2p entry (%lx)!\n",
-                             mfn_x(mfn), get_gpfn_from_mfn(mfn_x(mfn)));
+                             mfn_x(mfn), get_pfn_from_mfn(mfn));
            errors++;
         }
 
@@ -693,7 +694,7 @@ static inline struct page_info *__grab_shared_page(mfn_t mfn)
     if ( !mem_sharing_page_lock(pg) )
         return NULL;
 
-    if ( mem_sharing_lookup(mfn_x(mfn)) == NULL )
+    if ( mem_sharing_lookup(mfn) == NULL )
     {
         mem_sharing_page_unlock(pg);
         return NULL;
@@ -877,7 +878,7 @@ static int nominate_page(struct domain *d, gfn_t gfn,
     atomic_inc(&nr_shared_mfns);
 
     /* Update m2p entry to SHARED_M2P_ENTRY */
-    set_gpfn_from_mfn(mfn_x(mfn), SHARED_M2P_ENTRY);
+    set_pfn_from_mfn(mfn, SHARED_M2P_ENTRY);
 
     *phandle = page->sharing->handle;
     audit_add_list(page);
@@ -1222,7 +1223,7 @@ private_page_found:
     }
 
     /* Update m2p entry */
-    set_gpfn_from_mfn(mfn_x(page_to_mfn(page)), gfn);
+    set_pfn_from_mfn(page_to_mfn(page), gfn);
 
     /* Now that the gfn<->mfn map is properly established,
      * marking dirty is feasible */
xen/arch/x86/mm/p2m-pod.c +2 -2
index 4313863066..9e001738f4 100644
@@ -652,7 +652,7 @@ p2m_pod_decrease_reservation(struct domain *d, gfn_t gfn, unsigned int order)
             }
             p2m_tlb_flush_sync(p2m);
             for ( j = 0; j < n; ++j )
-                set_gpfn_from_mfn(mfn_x(mfn), INVALID_M2P_ENTRY);
+                set_pfn_from_mfn(mfn, INVALID_M2P_ENTRY);
             p2m_pod_cache_add(p2m, page, cur_order);
 
             steal_for_cache =  ( p2m->pod.entry_count > p2m->pod.count );
@@ -1203,7 +1203,7 @@ p2m_pod_demand_populate(struct p2m_domain *p2m, gfn_t gfn,
 
     for( i = 0; i < (1UL << order); i++ )
     {
-        set_gpfn_from_mfn(mfn_x(mfn) + i, gfn_x(gfn_aligned) + i);
+        set_pfn_from_mfn(mfn_add(mfn, i), gfn_x(gfn_aligned) + i);
         paging_mark_pfn_dirty(d, _pfn(gfn_x(gfn_aligned) + i));
     }
 
xen/arch/x86/mm/p2m-pt.c +19 -18
index cafc9f299b..0e85819f9b 100644
@@ -991,7 +991,8 @@ static int p2m_pt_change_entry_type_range(struct p2m_domain *p2m,
 long p2m_pt_audit_p2m(struct p2m_domain *p2m)
 {
     unsigned long entry_count = 0, pmbad = 0;
-    unsigned long mfn, gfn, m2pfn;
+    unsigned long gfn, m2pfn;
+    mfn_t mfn;
 
     ASSERT(p2m_locked_by_me(p2m));
     ASSERT(pod_locked_by_me(p2m));
@@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                 /* check for 1GB super page */
                 if ( l3e_get_flags(l3e[i3]) & _PAGE_PSE )
                 {
-                    mfn = l3e_get_pfn(l3e[i3]);
-                    ASSERT(mfn_valid(_mfn(mfn)));
+                    mfn = l3e_get_mfn(l3e[i3]);
+                    ASSERT(mfn_valid(mfn));
                     /* we have to cover 512x512 4K pages */
                     for ( i2 = 0;
                           i2 < (L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES);
                           i2++)
                     {
-                        m2pfn = get_gpfn_from_mfn(mfn+i2);
+                        m2pfn = get_pfn_from_mfn(mfn_add(mfn, i2));
                         if ( m2pfn != (gfn + i2) )
                         {
                             pmbad++;
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn+i2, mfn+i2,
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" gfn %#lx\n",
+                                       gfn + i2, mfn_x(mfn_add(mfn, i2)),
                                        m2pfn);
                             BUG();
                         }
@@ -1067,17 +1068,17 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                     /* check for super page */
                     if ( l2e_get_flags(l2e[i2]) & _PAGE_PSE )
                     {
-                        mfn = l2e_get_pfn(l2e[i2]);
-                        ASSERT(mfn_valid(_mfn(mfn)));
+                        mfn = l2e_get_mfn(l2e[i2]);
+                        ASSERT(mfn_valid(mfn));
                         for ( i1 = 0; i1 < L1_PAGETABLE_ENTRIES; i1++)
                         {
-                            m2pfn = get_gpfn_from_mfn(mfn+i1);
+                            m2pfn = get_pfn_from_mfn(mfn_add(mfn, i1));
                             /* Allow shared M2Ps */
                             if ( (m2pfn != (gfn + i1)) && !SHARED_M2P(m2pfn) )
                             {
                                 pmbad++;
-                                P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                           " -> gfn %#lx\n", gfn+i1, mfn+i1,
+                                P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                           gfn + i1, mfn_x(mfn_add(mfn, i1)),
                                            m2pfn);
                                 BUG();
                             }
@@ -1099,19 +1100,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                                 entry_count++;
                             continue;
                         }
-                        mfn = l1e_get_pfn(l1e[i1]);
-                        ASSERT(mfn_valid(_mfn(mfn)));
-                        m2pfn = get_gpfn_from_mfn(mfn);
+                        mfn = l1e_get_mfn(l1e[i1]);
+                        ASSERT(mfn_valid(mfn));
+                        m2pfn = get_pfn_from_mfn(mfn);
                         if ( m2pfn != gfn &&
                              type != p2m_mmio_direct &&
                              !p2m_is_grant(type) &&
                              !p2m_is_shared(type) )
                         {
                             pmbad++;
-                            printk("mismatch: gfn %#lx -> mfn %#lx"
-                                   " -> gfn %#lx\n", gfn, mfn, m2pfn);
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn, mfn, m2pfn);
+                            printk("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                   gfn, mfn_x(mfn), m2pfn);
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                       gfn, mfn_x(mfn), m2pfn);
                             BUG();
                         }
                     }
xen/arch/x86/mm/p2m.c +33 -33
index 3c98f72dbb..003ed97521 100644
@@ -769,7 +769,7 @@ void p2m_final_teardown(struct domain *d)
 
 
 static int
-p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn_l, unsigned long mfn,
+p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn_l, mfn_t mfn,
                 unsigned int page_order)
 {
     unsigned long i;
@@ -783,17 +783,17 @@ p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn_l, unsigned long mfn,
         return 0;
 
     ASSERT(gfn_locked_by_me(p2m, gfn));
-    P2M_DEBUG("removing gfn=%#lx mfn=%#lx\n", gfn_l, mfn);
+    P2M_DEBUG("removing gfn=%#lx mfn=%"PRI_mfn"\n", gfn_l, mfn_x(mfn));
 
-    if ( mfn_valid(_mfn(mfn)) )
+    if ( mfn_valid(mfn) )
     {
         for ( i = 0; i < (1UL << page_order); i++ )
         {
             mfn_return = p2m->get_entry(p2m, gfn_add(gfn, i), &t, &a, 0,
                                         NULL, NULL);
             if ( !p2m_is_grant(t) && !p2m_is_shared(t) && !p2m_is_foreign(t) )
-                set_gpfn_from_mfn(mfn+i, INVALID_M2P_ENTRY);
-            ASSERT( !p2m_is_valid(t) || mfn + i == mfn_x(mfn_return) );
+                set_pfn_from_mfn(mfn_add(mfn, i), INVALID_M2P_ENTRY);
+            ASSERT( !p2m_is_valid(t) || mfn_eq(mfn_add(mfn, i), mfn_return) );
         }
     }
     return p2m_set_entry(p2m, gfn, INVALID_MFN, page_order, p2m_invalid,
@@ -807,7 +807,7 @@ guest_physmap_remove_page(struct domain *d, gfn_t gfn,
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
     int rc;
     gfn_lock(p2m, gfn, page_order);
-    rc = p2m_remove_page(p2m, gfn_x(gfn), mfn_x(mfn), page_order);
+    rc = p2m_remove_page(p2m, gfn_x(gfn), mfn, page_order);
     gfn_unlock(p2m, gfn, page_order);
     return rc;
 }
@@ -908,7 +908,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn,
         else if ( p2m_is_ram(ot) && !p2m_is_paged(ot) )
         {
             ASSERT(mfn_valid(omfn));
-            set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);
+            set_pfn_from_mfn(omfn, INVALID_M2P_ENTRY);
         }
         else if ( ot == p2m_populate_on_demand )
         {
@@ -951,7 +951,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn,
                 P2M_DEBUG("old gfn=%#lx -> mfn %#lx\n",
                           gfn_x(ogfn) , mfn_x(omfn));
                 if ( mfn_eq(omfn, mfn_add(mfn, i)) )
-                    p2m_remove_page(p2m, gfn_x(ogfn), mfn_x(mfn_add(mfn, i)),
+                    p2m_remove_page(p2m, gfn_x(ogfn), mfn_add(mfn, i),
                                     0);
             }
         }
@@ -968,8 +968,8 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn,
         if ( !p2m_is_grant(t) )
         {
             for ( i = 0; i < (1UL << page_order); i++ )
-                set_gpfn_from_mfn(mfn_x(mfn_add(mfn, i)),
-                                  gfn_x(gfn_add(gfn, i)));
+                set_pfn_from_mfn(mfn_add(mfn, i),
+                                 gfn_x(gfn_add(gfn, i)));
         }
     }
     else
@@ -1272,7 +1272,7 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn_l,
         for ( i = 0; i < (1UL << order); ++i )
         {
             ASSERT(mfn_valid(mfn_add(omfn, i)));
-            set_gpfn_from_mfn(mfn_x(omfn) + i, INVALID_M2P_ENTRY);
+            set_pfn_from_mfn(mfn_add(omfn, i), INVALID_M2P_ENTRY);
         }
     }
 
@@ -1467,7 +1467,7 @@ int set_shared_p2m_entry(struct domain *d, unsigned long gfn_l, mfn_t mfn)
     pg_type = read_atomic(&(mfn_to_page(omfn)->u.inuse.type_info));
     if ( (pg_type & PGT_count_mask) == 0
          || (pg_type & PGT_type_mask) != PGT_shared_page )
-        set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);
+        set_pfn_from_mfn(omfn, INVALID_M2P_ENTRY);
 
     P2M_DEBUG("set shared %lx %lx\n", gfn_l, mfn_x(mfn));
     rc = p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, p2m_ram_shared,
@@ -1821,7 +1821,7 @@ int p2m_mem_paging_prep(struct domain *d, unsigned long gfn_l, uint64_t buffer)
     ret = p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K,
                         paging_mode_log_dirty(d) ? p2m_ram_logdirty
                                                  : p2m_ram_rw, a);
-    set_gpfn_from_mfn(mfn_x(mfn), gfn_l);
+    set_pfn_from_mfn(mfn, gfn_l);
 
     if ( !page_extant )
         atomic_dec(&d->paged_pages);
@@ -1872,7 +1872,7 @@ void p2m_mem_paging_resume(struct domain *d, vm_event_response_t *rsp)
                                    p2m_ram_rw, a);
 
             if ( !rc )
-                set_gpfn_from_mfn(mfn_x(mfn), gfn_x(gfn));
+                set_pfn_from_mfn(mfn, gfn_x(gfn));
         }
         gfn_unlock(p2m, gfn, 0);
     }
@@ -2635,7 +2635,7 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
     if ( gfn_eq(new_gfn, INVALID_GFN) )
     {
         if ( mfn_valid(mfn) )
-            p2m_remove_page(ap2m, gfn_x(old_gfn), mfn_x(mfn), PAGE_ORDER_4K);
+            p2m_remove_page(ap2m, gfn_x(old_gfn), mfn, PAGE_ORDER_4K);
         rc = 0;
         goto out;
     }
@@ -2772,8 +2772,8 @@ void audit_p2m(struct domain *d,
 {
     struct page_info *page;
     struct domain *od;
-    unsigned long mfn, gfn;
-    mfn_t p2mfn;
+    unsigned long gfn;
+    mfn_t p2mfn, mfn;
     unsigned long orphans_count = 0, mpbad = 0, pmbad = 0;
     p2m_access_t p2ma;
     p2m_type_t type;
@@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
     spin_lock(&d->page_alloc_lock);
     page_list_for_each ( page, &d->page_list )
     {
-        mfn = mfn_x(page_to_mfn(page));
+        mfn = page_to_mfn(page);
 
-        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);
+        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n", mfn_x(mfn));
 
         od = page_get_owner(page);
 
         if ( od != d )
         {
-            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
-                       mfn, od, (od?od->domain_id:-1), d, d->domain_id);
+            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) != %p(%u)\n",
+                       mfn_x(mfn), od, (od?od->domain_id:-1), d, d->domain_id);
             continue;
         }
 
-        gfn = get_gpfn_from_mfn(mfn);
+        gfn = get_pfn_from_mfn(mfn);
         if ( gfn == INVALID_M2P_ENTRY )
         {
             orphans_count++;
-            P2M_PRINTK("orphaned guest page: mfn=%#lx has invalid gfn\n",
-                           mfn);
+            P2M_PRINTK("orphaned guest page: mfn=%"PRI_mfn" has invalid gfn\n",
+                       mfn_x(mfn));
             continue;
         }
 
         if ( SHARED_M2P(gfn) )
         {
-            P2M_PRINTK("shared mfn (%lx) on domain page list!\n",
-                    mfn);
+            P2M_PRINTK("shared mfn (%"PRI_mfn") on domain page list!\n",
+                       mfn_x(mfn));
             continue;
         }
 
         p2mfn = get_gfn_type_access(p2m, gfn, &type, &p2ma, 0, NULL);
-        if ( mfn_x(p2mfn) != mfn )
+        if ( !mfn_eq(p2mfn, mfn) )
         {
             mpbad++;
-            P2M_PRINTK("map mismatch mfn %#lx -> gfn %#lx -> mfn %#lx"
+            P2M_PRINTK("map mismatch mfn %"PRI_mfn" -> gfn %#lx -> mfn %"PRI_mfn""
                        " (-> gfn %#lx)\n",
-                       mfn, gfn, mfn_x(p2mfn),
+                       mfn_x(mfn), gfn, mfn_x(p2mfn),
                        (mfn_valid(p2mfn)
-                        ? get_gpfn_from_mfn(mfn_x(p2mfn))
+                        ? get_pfn_from_mfn(p2mfn)
                         : -1u));
             /* This m2p entry is stale: the domain has another frame in
              * this physical slot.  No great disaster, but for neatness,
              * blow away the m2p entry. */
-            set_gpfn_from_mfn(mfn, INVALID_M2P_ENTRY);
+            set_pfn_from_mfn(mfn, INVALID_M2P_ENTRY);
         }
         __put_gfn(p2m, gfn);
 
-        P2M_PRINTK("OK: mfn=%#lx, gfn=%#lx, p2mfn=%#lx\n",
-                       mfn, gfn, mfn_x(p2mfn));
+        P2M_PRINTK("OK: mfn=%"PRI_mfn", gfn=%#lx, p2mfn=%"PRI_mfn"\n",
+                   mfn_x(mfn), gfn, mfn_x(p2mfn));
     }
     spin_unlock(&d->page_alloc_lock);
 
xen/arch/x86/mm/paging.c +2 -2
index 9b0f268e74..cef2f90186 100644
@@ -344,7 +344,7 @@ void paging_mark_dirty(struct domain *d, mfn_t gmfn)
         return;
 
     /* We /really/ mean PFN here, even for non-translated guests. */
-    pfn = _pfn(get_gpfn_from_mfn(mfn_x(gmfn)));
+    pfn = _pfn(get_pfn_from_mfn(gmfn));
 
     paging_mark_pfn_dirty(d, pfn);
 }
@@ -362,7 +362,7 @@ int paging_mfn_is_dirty(struct domain *d, mfn_t gmfn)
     ASSERT(paging_mode_log_dirty(d));
 
     /* We /really/ mean PFN here, even for non-translated guests. */
-    pfn = _pfn(get_gpfn_from_mfn(mfn_x(gmfn)));
+    pfn = _pfn(get_pfn_from_mfn(gmfn));
     /* Invalid pages can't be dirty. */
     if ( unlikely(!VALID_M2P(pfn_x(pfn))) )
         return 0;
xen/arch/x86/pv/dom0_build.c +3 -3
index cef2d42254..b39ab67092 100644
@@ -39,7 +39,7 @@ void __init dom0_update_physmap(struct domain *d, unsigned long pfn,
     else
         ((unsigned int *)vphysmap_s)[pfn] = mfn;
 
-    set_gpfn_from_mfn(mfn, pfn);
+    set_pfn_from_mfn(_mfn(mfn), pfn);
 }
 
 static __init void mark_pv_pt_pages_rdonly(struct domain *d,
@@ -798,8 +798,8 @@ int __init dom0_construct_pv(struct domain *d,
     page_list_for_each ( page, &d->page_list )
     {
         mfn = mfn_x(page_to_mfn(page));
-        BUG_ON(SHARED_M2P(get_gpfn_from_mfn(mfn)));
-        if ( get_gpfn_from_mfn(mfn) >= count )
+        BUG_ON(SHARED_M2P(get_pfn_from_mfn(_mfn(mfn))));
+        if ( get_pfn_from_mfn(_mfn(mfn)) >= count )
         {
             BUG_ON(is_pv_32bit_domain(d));
             if ( !page->u.inuse.type_info &&
xen/arch/x86/x86_64/traps.c +21 -20
index 44af765e3e..f80f2250fe 100644
@@ -184,7 +184,8 @@ void vcpu_show_registers(const struct vcpu *v)
 
 void show_page_walk(unsigned long addr)
 {
-    unsigned long pfn, mfn = read_cr3() >> PAGE_SHIFT;
+    unsigned long pfn;
+    mfn_t mfn = maddr_to_mfn(read_cr3());
     l4_pgentry_t l4e, *l4t;
     l3_pgentry_t l3e, *l3t;
     l2_pgentry_t l2e, *l2t;
@@ -194,52 +195,52 @@ void show_page_walk(unsigned long addr)
     if ( !is_canonical_address(addr) )
         return;
 
-    l4t = map_domain_page(_mfn(mfn));
+    l4t = map_domain_page(mfn);
     l4e = l4t[l4_table_offset(addr)];
     unmap_domain_page(l4t);
-    mfn = l4e_get_pfn(l4e);
-    pfn = mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ?
-          get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
+    mfn = l4e_get_mfn(l4e);
+    pfn = mfn_valid(mfn) && machine_to_phys_mapping_valid ?
+          get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
     printk(" L4[0x%03lx] = %"PRIpte" %016lx\n",
            l4_table_offset(addr), l4e_get_intpte(l4e), pfn);
     if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) ||
-         !mfn_valid(_mfn(mfn)) )
+         !mfn_valid(mfn) )
         return;
 
-    l3t = map_domain_page(_mfn(mfn));
+    l3t = map_domain_page(mfn);
     l3e = l3t[l3_table_offset(addr)];
     unmap_domain_page(l3t);
-    mfn = l3e_get_pfn(l3e);
-    pfn = mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ?
-          get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
+    mfn = l3e_get_mfn(l3e);
+    pfn = mfn_valid(mfn) && machine_to_phys_mapping_valid ?
+          get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
     printk(" L3[0x%03lx] = %"PRIpte" %016lx%s\n",
            l3_table_offset(addr), l3e_get_intpte(l3e), pfn,
            (l3e_get_flags(l3e) & _PAGE_PSE) ? " (PSE)" : "");
     if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) ||
          (l3e_get_flags(l3e) & _PAGE_PSE) ||
-         !mfn_valid(_mfn(mfn)) )
+         !mfn_valid(mfn) )
         return;
 
-    l2t = map_domain_page(_mfn(mfn));
+    l2t = map_domain_page(mfn);
     l2e = l2t[l2_table_offset(addr)];
     unmap_domain_page(l2t);
-    mfn = l2e_get_pfn(l2e);
-    pfn = mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ?
-          get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
+    mfn = l2e_get_mfn(l2e);
+    pfn = mfn_valid(mfn) && machine_to_phys_mapping_valid ?
+          get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
     printk(" L2[0x%03lx] = %"PRIpte" %016lx%s\n",
            l2_table_offset(addr), l2e_get_intpte(l2e), pfn,
            (l2e_get_flags(l2e) & _PAGE_PSE) ? " (PSE)" : "");
     if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT) ||
          (l2e_get_flags(l2e) & _PAGE_PSE) ||
-         !mfn_valid(_mfn(mfn)) )
+         !mfn_valid(mfn) )
         return;
 
-    l1t = map_domain_page(_mfn(mfn));
+    l1t = map_domain_page(mfn);
     l1e = l1t[l1_table_offset(addr)];
     unmap_domain_page(l1t);
-    mfn = l1e_get_pfn(l1e);
-    pfn = mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ?
-          get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
+    mfn = l1e_get_mfn(l1e);
+    pfn = mfn_valid(mfn) && machine_to_phys_mapping_valid ?
+          get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
     printk(" L1[0x%03lx] = %"PRIpte" %016lx\n",
            l1_table_offset(addr), l1e_get_intpte(l1e), pfn);
 }
xen/common/memory.c +1 -1
index d6a580da31..eecc9671ff 100644
@@ -273,7 +273,7 @@ static void populate_physmap(struct memop_args *a)
             if ( !paging_mode_translate(d) )
             {
                 for ( j = 0; j < (1U << a->extent_order); j++ )
-                    set_gpfn_from_mfn(mfn_x(mfn_add(mfn, j)), gpfn + j);
+                    set_pfn_from_mfn(mfn_add(mfn, j), gpfn + j);
 
                 /* Inform the domain of the new page's machine address. */
                 if ( unlikely(__copy_mfn_to_guest_offset(a->extent_list, i,
xen/common/page_alloc.c +1 -1
index 6061cce24f..a100e03e2e 100644
@@ -1424,7 +1424,7 @@ static void free_heap_pages(
 
         /* This page is not a guest frame any more. */
         page_set_owner(&pg[i], NULL); /* set_gpfn_from_mfn snoops pg owner */
-        set_gpfn_from_mfn(mfn_x(mfn) + i, INVALID_M2P_ENTRY);
+        set_pfn_from_mfn(mfn_add(mfn, + i), INVALID_M2P_ENTRY);
 
         if ( need_scrub )
         {
xen/include/asm-arm/mm.h +1 -1
index a9cb98a6c7..3c03be3bca 100644
@@ -322,7 +322,7 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
 #define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
 
 /* We don't have a M2P on Arm */
-#define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn); } while (0)
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
 
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
xen/include/asm-x86/grant_table.h +1 -1
index 661228dd39..d731b9e49f 100644
@@ -41,7 +41,7 @@ static inline int replace_grant_host_mapping(uint64_t addr, mfn_t frame,
 #define gnttab_get_frame_gfn(gt, st, idx) ({                             \
     mfn_t mfn_ = (st) ? gnttab_status_mfn(gt, idx)                       \
                       : gnttab_shared_mfn(gt, idx);                      \
-    unsigned long gpfn_ = get_gpfn_from_mfn(mfn_x(mfn_));                \
+    unsigned long gpfn_ = get_pfn_from_mfn(mfn_);                        \
     VALID_M2P(gpfn_) ? _gfn(gpfn_) : INVALID_GFN;                        \
 })
 
xen/include/asm-x86/mm.h +10 -6
index 4721725c60..bce60619c3 100644
@@ -492,22 +492,26 @@ extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */
  */
 extern bool machine_to_phys_mapping_valid;
 
-static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn)
 {
-    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    const unsigned long mfn_ = mfn_x(mfn);
+    struct domain *d = page_get_owner(mfn_to_page(mfn));
     unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;
 
     if (!machine_to_phys_mapping_valid)
         return;
 
-    if ( mfn >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )
-        compat_machine_to_phys_mapping[mfn] = entry;
-    machine_to_phys_mapping[mfn] = entry;
+    if ( mfn_ >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )
+        compat_machine_to_phys_mapping[mfn_] = entry;
+    machine_to_phys_mapping[mfn_] = entry;
 }
 
 extern struct rangeset *mmio_ro_ranges;
 
-#define get_gpfn_from_mfn(mfn)      (machine_to_phys_mapping[(mfn)])
+static inline unsigned long get_pfn_from_mfn(mfn_t mfn)
+{
+    return machine_to_phys_mapping[mfn_x(mfn)];
+}
 
 #define compat_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
 #define compat_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
xen/include/asm-x86/p2m.h +1 -2
index 0157568be9..07b7ec6db0 100644
@@ -509,7 +509,7 @@ static inline struct page_info *get_page_from_gfn(
 static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn)
 {
     if ( paging_mode_translate(d) )
-        return _gfn(get_gpfn_from_mfn(mfn_x(mfn)));
+        return _gfn(get_pfn_from_mfn(mfn));
     else
         return _gfn(mfn_x(mfn));
 }
--
Quoted 1 line

2.11.0

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

Acked-by on v1 13/14
#54 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

In reply to Julien Grall
Quoted 11 lines · Julien Grall

The first parameter of {s,g}et_gpfn_from_mfn() is an MFN, so it can be switched to use the typesafe.

At the same time, replace gpfn with pfn in the helpers as they all deal with PFN and also turn the macros to static inline.

Note that the return of the getter and the 2nd parameter of the setter have not been converted to use typesafe PFN because it was requiring more changes than expected.

I only skimmed through the x86 bits.

Quoted 718 lines

---
Changes in v2:
- Patch added

---
 xen/arch/x86/cpu/mcheck/mcaction.c |  2 +-
 xen/arch/x86/mm.c                  | 14 ++++----
 xen/arch/x86/mm/mem_sharing.c      | 19 +++++------
 xen/arch/x86/mm/p2m-pod.c          |  4 +--
 xen/arch/x86/mm/p2m-pt.c           | 37 ++++++++++-----------
 xen/arch/x86/mm/p2m.c              | 66 +++++++++++++++++++-------------------
 xen/arch/x86/mm/paging.c           |  4 +--
 xen/arch/x86/pv/dom0_build.c       |  6 ++--
 xen/arch/x86/x86_64/traps.c        | 41 +++++++++++------------
 xen/common/memory.c                |  2 +-
 xen/common/page_alloc.c            |  2 +-
 xen/include/asm-arm/mm.h           |  2 +-
 xen/include/asm-x86/grant_table.h  |  2 +-
 xen/include/asm-x86/mm.h           | 16 +++++----
 xen/include/asm-x86/p2m.h          |  2 +-
 15 files changed, 113 insertions(+), 106 deletions(-)
xen/arch/x86/cpu/mcheck/mcaction.c +1 -1
index 69332fb84d..5e78fb7703 100644
@@ -89,7 +89,7 @@ mc_memerr_dhandler(struct mca_binfo *binfo,
             {
                 d = get_domain_by_id(bank->mc_domid);
                 ASSERT(d);
-                gfn = get_gpfn_from_mfn((bank->mc_addr) >> PAGE_SHIFT);
+                gfn = get_pfn_from_mfn(maddr_to_mfn(bank->mc_addr));
 
                 if ( unmmap_broken_page(d, mfn, gfn) )
                 {
xen/arch/x86/mm.c +7 -7
index 7d887f2699..60c47582be 100644
@@ -502,7 +502,7 @@ void share_xen_page_with_guest(struct page_info *page, struct domain *d,
     if ( page_get_owner(page) == d )
         return;
 
-    set_gpfn_from_mfn(mfn_x(page_to_mfn(page)), INVALID_M2P_ENTRY);
+    set_pfn_from_mfn(page_to_mfn(page), INVALID_M2P_ENTRY);
 
     spin_lock(&d->page_alloc_lock);
 
@@ -1077,7 +1077,7 @@ get_page_from_l1e(
 
             gdprintk(XENLOG_WARNING, "Error updating mappings for mfn %" PRI_mfn
                      " (pfn %" PRI_pfn ", from L1 entry %" PRIpte ") for d%d\n",
-                     mfn, get_gpfn_from_mfn(mfn),
+                     mfn, get_pfn_from_mfn(_mfn(mfn)),
                      l1e_get_intpte(l1e), l1e_owner->domain_id);
             return err;
         }
@@ -1088,7 +1088,7 @@ get_page_from_l1e(
  could_not_pin:
     gdprintk(XENLOG_WARNING, "Error getting mfn %" PRI_mfn " (pfn %" PRI_pfn
              ") from L1 entry %" PRIpte " for l1e_owner d%d, pg_owner d%d\n",
-             mfn, get_gpfn_from_mfn(mfn),
+             mfn, get_pfn_from_mfn(_mfn(mfn)),
              l1e_get_intpte(l1e), l1e_owner->domain_id, pg_owner->domain_id);
     if ( real_pg_owner != NULL )
         put_page(page);
@@ -2604,7 +2604,7 @@ static int alloc_page_type(struct page_info *page, unsigned long type,
                  " (pfn %" PRI_pfn ") for type %" PRtype_info
                  ": caf=%08lx taf=%" PRtype_info "\n",
                  mfn_x(page_to_mfn(page)),
-                 get_gpfn_from_mfn(mfn_x(page_to_mfn(page))),
+                 get_pfn_from_mfn(page_to_mfn(page)),
                  type, page->count_info, page->u.inuse.type_info);
         if ( page != current->arch.old_guest_table )
             page->u.inuse.type_info = 0;
@@ -2890,7 +2890,7 @@ static int _get_page_type(struct page_info *page, unsigned long type,
                      "Bad type (saw %" PRtype_info " != exp %" PRtype_info ") "
                      "for mfn %" PRI_mfn " (pfn %" PRI_pfn ")\n",
                      x, type, mfn_x(page_to_mfn(page)),
-                     get_gpfn_from_mfn(mfn_x(page_to_mfn(page))));
+                     get_pfn_from_mfn(page_to_mfn(page)));
             return -EINVAL;
         }
         else if ( unlikely(!(x & PGT_validated)) )
@@ -4002,7 +4002,7 @@ long do_mmu_update(
                 break;
             }
 
-            set_gpfn_from_mfn(mfn_x(mfn), gpfn);
+            set_pfn_from_mfn(mfn, gpfn);
             paging_mark_pfn_dirty(pg_owner, _pfn(gpfn));
 
             put_page(page);
@@ -4529,7 +4529,7 @@ int xenmem_add_to_physmap_one(
         goto put_both;
 
     /* Unmap from old location, if any. */
-    old_gpfn = get_gpfn_from_mfn(mfn_x(mfn));
+    old_gpfn = get_pfn_from_mfn(mfn);
     ASSERT(!SHARED_M2P(old_gpfn));
     if ( space == XENMAPSPACE_gmfn && old_gpfn != gfn )
     {
xen/arch/x86/mm/mem_sharing.c +10 -9
index 5ac9d8f54c..af903c11e9 100644
@@ -391,11 +391,12 @@ static inline void mem_sharing_gfn_destroy(struct page_info *page,
     xfree(gfn_info);
 }
 
-static struct page_info* mem_sharing_lookup(unsigned long mfn)
+static struct page_info* mem_sharing_lookup(mfn_t mfn)
 {
-    if ( mfn_valid(_mfn(mfn)) )
+    if ( mfn_valid(mfn) )
     {
-        struct page_info* page = mfn_to_page(_mfn(mfn));
+        struct page_info* page = mfn_to_page(mfn);
+
         if ( page_get_owner(page) == dom_cow )
         {
             /* Count has to be at least two, because we're called
@@ -404,7 +405,7 @@ static struct page_info* mem_sharing_lookup(unsigned long mfn)
             unsigned long t = read_atomic(&page->u.inuse.type_info);
             ASSERT((t & PGT_type_mask) == PGT_shared_page);
             ASSERT((t & PGT_count_mask) >= 2);
-            ASSERT(SHARED_M2P(get_gpfn_from_mfn(mfn)));
+            ASSERT(SHARED_M2P(get_pfn_from_mfn(mfn)));
             return page;
         }
     }
@@ -464,10 +465,10 @@ static int audit(void)
         }
 
         /* Check the m2p entry */
-        if ( !SHARED_M2P(get_gpfn_from_mfn(mfn_x(mfn))) )
+        if ( !SHARED_M2P(get_pfn_from_mfn(mfn)) )
         {
            MEM_SHARING_DEBUG("mfn %lx shared, but wrong m2p entry (%lx)!\n",
-                             mfn_x(mfn), get_gpfn_from_mfn(mfn_x(mfn)));
+                             mfn_x(mfn), get_pfn_from_mfn(mfn));
            errors++;
         }
 
@@ -693,7 +694,7 @@ static inline struct page_info *__grab_shared_page(mfn_t mfn)
     if ( !mem_sharing_page_lock(pg) )
         return NULL;
 
-    if ( mem_sharing_lookup(mfn_x(mfn)) == NULL )
+    if ( mem_sharing_lookup(mfn) == NULL )
     {
         mem_sharing_page_unlock(pg);
         return NULL;
@@ -877,7 +878,7 @@ static int nominate_page(struct domain *d, gfn_t gfn,
     atomic_inc(&nr_shared_mfns);
 
     /* Update m2p entry to SHARED_M2P_ENTRY */
-    set_gpfn_from_mfn(mfn_x(mfn), SHARED_M2P_ENTRY);
+    set_pfn_from_mfn(mfn, SHARED_M2P_ENTRY);
 
     *phandle = page->sharing->handle;
     audit_add_list(page);
@@ -1222,7 +1223,7 @@ private_page_found:
     }
 
     /* Update m2p entry */
-    set_gpfn_from_mfn(mfn_x(page_to_mfn(page)), gfn);
+    set_pfn_from_mfn(page_to_mfn(page), gfn);
 
     /* Now that the gfn<->mfn map is properly established,
      * marking dirty is feasible */
xen/arch/x86/mm/p2m-pod.c +2 -2
index 4313863066..9e001738f4 100644
@@ -652,7 +652,7 @@ p2m_pod_decrease_reservation(struct domain *d, gfn_t gfn, unsigned int order)
             }
             p2m_tlb_flush_sync(p2m);
             for ( j = 0; j < n; ++j )
-                set_gpfn_from_mfn(mfn_x(mfn), INVALID_M2P_ENTRY);
+                set_pfn_from_mfn(mfn, INVALID_M2P_ENTRY);
             p2m_pod_cache_add(p2m, page, cur_order);
 
             steal_for_cache =  ( p2m->pod.entry_count > p2m->pod.count );
@@ -1203,7 +1203,7 @@ p2m_pod_demand_populate(struct p2m_domain *p2m, gfn_t gfn,
 
     for( i = 0; i < (1UL << order); i++ )
     {
-        set_gpfn_from_mfn(mfn_x(mfn) + i, gfn_x(gfn_aligned) + i);
+        set_pfn_from_mfn(mfn_add(mfn, i), gfn_x(gfn_aligned) + i);
         paging_mark_pfn_dirty(d, _pfn(gfn_x(gfn_aligned) + i));
     }
 
xen/arch/x86/mm/p2m-pt.c +19 -18
index cafc9f299b..0e85819f9b 100644
@@ -991,7 +991,8 @@ static int p2m_pt_change_entry_type_range(struct p2m_domain *p2m,
 long p2m_pt_audit_p2m(struct p2m_domain *p2m)
 {
     unsigned long entry_count = 0, pmbad = 0;
-    unsigned long mfn, gfn, m2pfn;
+    unsigned long gfn, m2pfn;
+    mfn_t mfn;
 
     ASSERT(p2m_locked_by_me(p2m));
     ASSERT(pod_locked_by_me(p2m));
@@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                 /* check for 1GB super page */
                 if ( l3e_get_flags(l3e[i3]) & _PAGE_PSE )
                 {
-                    mfn = l3e_get_pfn(l3e[i3]);
-                    ASSERT(mfn_valid(_mfn(mfn)));
+                    mfn = l3e_get_mfn(l3e[i3]);
+                    ASSERT(mfn_valid(mfn));
                     /* we have to cover 512x512 4K pages */
                     for ( i2 = 0; 
                           i2 < (L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES);
                           i2++)
                     {
-                        m2pfn = get_gpfn_from_mfn(mfn+i2);
+                        m2pfn = get_pfn_from_mfn(mfn_add(mfn, i2));
                         if ( m2pfn != (gfn + i2) )
                         {
                             pmbad++;
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn+i2, mfn+i2,
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" gfn %#lx\n",
+                                       gfn + i2, mfn_x(mfn_add(mfn, i2)),
                                        m2pfn);
                             BUG();
                         }
@@ -1067,17 +1068,17 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                     /* check for super page */
                     if ( l2e_get_flags(l2e[i2]) & _PAGE_PSE )
                     {
-                        mfn = l2e_get_pfn(l2e[i2]);
-                        ASSERT(mfn_valid(_mfn(mfn)));
+                        mfn = l2e_get_mfn(l2e[i2]);
+                        ASSERT(mfn_valid(mfn));
                         for ( i1 = 0; i1 < L1_PAGETABLE_ENTRIES; i1++)
                         {
-                            m2pfn = get_gpfn_from_mfn(mfn+i1);
+                            m2pfn = get_pfn_from_mfn(mfn_add(mfn, i1));
                             /* Allow shared M2Ps */
                             if ( (m2pfn != (gfn + i1)) && !SHARED_M2P(m2pfn) )
                             {
                                 pmbad++;
-                                P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                           " -> gfn %#lx\n", gfn+i1, mfn+i1,
+                                P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                           gfn + i1, mfn_x(mfn_add(mfn, i1)),
                                            m2pfn);
                                 BUG();
                             }
@@ -1099,19 +1100,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                                 entry_count++;
                             continue;
                         }
-                        mfn = l1e_get_pfn(l1e[i1]);
-                        ASSERT(mfn_valid(_mfn(mfn)));
-                        m2pfn = get_gpfn_from_mfn(mfn);
+                        mfn = l1e_get_mfn(l1e[i1]);
+                        ASSERT(mfn_valid(mfn));
+                        m2pfn = get_pfn_from_mfn(mfn);
                         if ( m2pfn != gfn &&
                              type != p2m_mmio_direct &&
                              !p2m_is_grant(type) &&
                              !p2m_is_shared(type) )
                         {
                             pmbad++;
-                            printk("mismatch: gfn %#lx -> mfn %#lx"
-                                   " -> gfn %#lx\n", gfn, mfn, m2pfn);
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn, mfn, m2pfn);
+                            printk("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                   gfn, mfn_x(mfn), m2pfn);
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                       gfn, mfn_x(mfn), m2pfn);
                             BUG();
                         }
                     }
xen/arch/x86/mm/p2m.c +33 -33
index 3c98f72dbb..003ed97521 100644
@@ -769,7 +769,7 @@ void p2m_final_teardown(struct domain *d)
 
 
 static int
-p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn_l, unsigned long mfn,
+p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn_l, mfn_t mfn,
                 unsigned int page_order)
 {
     unsigned long i;
@@ -783,17 +783,17 @@ p2m_remove_page(struct p2m_domain *p2m, unsigned long gfn_l, unsigned long mfn,
         return 0;
 
     ASSERT(gfn_locked_by_me(p2m, gfn));
-    P2M_DEBUG("removing gfn=%#lx mfn=%#lx\n", gfn_l, mfn);
+    P2M_DEBUG("removing gfn=%#lx mfn=%"PRI_mfn"\n", gfn_l, mfn_x(mfn));
 
-    if ( mfn_valid(_mfn(mfn)) )
+    if ( mfn_valid(mfn) )
     {
         for ( i = 0; i < (1UL << page_order); i++ )
         {
             mfn_return = p2m->get_entry(p2m, gfn_add(gfn, i), &t, &a, 0,
                                         NULL, NULL);
             if ( !p2m_is_grant(t) && !p2m_is_shared(t) && !p2m_is_foreign(t) )
-                set_gpfn_from_mfn(mfn+i, INVALID_M2P_ENTRY);
-            ASSERT( !p2m_is_valid(t) || mfn + i == mfn_x(mfn_return) );
+                set_pfn_from_mfn(mfn_add(mfn, i), INVALID_M2P_ENTRY);
+            ASSERT( !p2m_is_valid(t) || mfn_eq(mfn_add(mfn, i), mfn_return) );
         }
     }
     return p2m_set_entry(p2m, gfn, INVALID_MFN, page_order, p2m_invalid,
@@ -807,7 +807,7 @@ guest_physmap_remove_page(struct domain *d, gfn_t gfn,
     struct p2m_domain *p2m = p2m_get_hostp2m(d);
     int rc;
     gfn_lock(p2m, gfn, page_order);
-    rc = p2m_remove_page(p2m, gfn_x(gfn), mfn_x(mfn), page_order);
+    rc = p2m_remove_page(p2m, gfn_x(gfn), mfn, page_order);
     gfn_unlock(p2m, gfn, page_order);
     return rc;
 }
@@ -908,7 +908,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn,
         else if ( p2m_is_ram(ot) && !p2m_is_paged(ot) )
         {
             ASSERT(mfn_valid(omfn));
-            set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);
+            set_pfn_from_mfn(omfn, INVALID_M2P_ENTRY);
         }
         else if ( ot == p2m_populate_on_demand )
         {
@@ -951,7 +951,7 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn,
                 P2M_DEBUG("old gfn=%#lx -> mfn %#lx\n",
                           gfn_x(ogfn) , mfn_x(omfn));
                 if ( mfn_eq(omfn, mfn_add(mfn, i)) )
-                    p2m_remove_page(p2m, gfn_x(ogfn), mfn_x(mfn_add(mfn, i)),
+                    p2m_remove_page(p2m, gfn_x(ogfn), mfn_add(mfn, i),
                                     0);
             }
         }
@@ -968,8 +968,8 @@ guest_physmap_add_entry(struct domain *d, gfn_t gfn, mfn_t mfn,
         if ( !p2m_is_grant(t) )
         {
             for ( i = 0; i < (1UL << page_order); i++ )
-                set_gpfn_from_mfn(mfn_x(mfn_add(mfn, i)),
-                                  gfn_x(gfn_add(gfn, i)));
+                set_pfn_from_mfn(mfn_add(mfn, i),
+                                 gfn_x(gfn_add(gfn, i)));
         }
     }
     else
@@ -1272,7 +1272,7 @@ static int set_typed_p2m_entry(struct domain *d, unsigned long gfn_l,
         for ( i = 0; i < (1UL << order); ++i )
         {
             ASSERT(mfn_valid(mfn_add(omfn, i)));
-            set_gpfn_from_mfn(mfn_x(omfn) + i, INVALID_M2P_ENTRY);
+            set_pfn_from_mfn(mfn_add(omfn, i), INVALID_M2P_ENTRY);
         }
     }
 
@@ -1467,7 +1467,7 @@ int set_shared_p2m_entry(struct domain *d, unsigned long gfn_l, mfn_t mfn)
     pg_type = read_atomic(&(mfn_to_page(omfn)->u.inuse.type_info));
     if ( (pg_type & PGT_count_mask) == 0
          || (pg_type & PGT_type_mask) != PGT_shared_page )
-        set_gpfn_from_mfn(mfn_x(omfn), INVALID_M2P_ENTRY);
+        set_pfn_from_mfn(omfn, INVALID_M2P_ENTRY);
 
     P2M_DEBUG("set shared %lx %lx\n", gfn_l, mfn_x(mfn));
     rc = p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K, p2m_ram_shared,
@@ -1821,7 +1821,7 @@ int p2m_mem_paging_prep(struct domain *d, unsigned long gfn_l, uint64_t buffer)
     ret = p2m_set_entry(p2m, gfn, mfn, PAGE_ORDER_4K,
                         paging_mode_log_dirty(d) ? p2m_ram_logdirty
                                                  : p2m_ram_rw, a);
-    set_gpfn_from_mfn(mfn_x(mfn), gfn_l);
+    set_pfn_from_mfn(mfn, gfn_l);
 
     if ( !page_extant )
         atomic_dec(&d->paged_pages);
@@ -1872,7 +1872,7 @@ void p2m_mem_paging_resume(struct domain *d, vm_event_response_t *rsp)
                                    p2m_ram_rw, a);
 
             if ( !rc )
-                set_gpfn_from_mfn(mfn_x(mfn), gfn_x(gfn));
+                set_pfn_from_mfn(mfn, gfn_x(gfn));
         }
         gfn_unlock(p2m, gfn, 0);
     }
@@ -2635,7 +2635,7 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx,
     if ( gfn_eq(new_gfn, INVALID_GFN) )
     {
         if ( mfn_valid(mfn) )
-            p2m_remove_page(ap2m, gfn_x(old_gfn), mfn_x(mfn), PAGE_ORDER_4K);
+            p2m_remove_page(ap2m, gfn_x(old_gfn), mfn, PAGE_ORDER_4K);
         rc = 0;
         goto out;
     }
@@ -2772,8 +2772,8 @@ void audit_p2m(struct domain *d,
 {
     struct page_info *page;
     struct domain *od;
-    unsigned long mfn, gfn;
-    mfn_t p2mfn;
+    unsigned long gfn;
+    mfn_t p2mfn, mfn;
     unsigned long orphans_count = 0, mpbad = 0, pmbad = 0;
     p2m_access_t p2ma;
     p2m_type_t type;
@@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
     spin_lock(&d->page_alloc_lock);
     page_list_for_each ( page, &d->page_list )
     {
-        mfn = mfn_x(page_to_mfn(page));
+        mfn = page_to_mfn(page);
 
-        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);
+        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n", mfn_x(mfn));
 
         od = page_get_owner(page);
 
         if ( od != d )
         {
-            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
-                       mfn, od, (od?od->domain_id:-1), d, d->domain_id);
+            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) != %p(%u)\n",
+                       mfn_x(mfn), od, (od?od->domain_id:-1), d, d->domain_id);
             continue;
         }
 
-        gfn = get_gpfn_from_mfn(mfn);
+        gfn = get_pfn_from_mfn(mfn);
         if ( gfn == INVALID_M2P_ENTRY )
         {
             orphans_count++;
-            P2M_PRINTK("orphaned guest page: mfn=%#lx has invalid gfn\n",
-                           mfn);
+            P2M_PRINTK("orphaned guest page: mfn=%"PRI_mfn" has invalid gfn\n",
+                       mfn_x(mfn));
             continue;
         }
 
         if ( SHARED_M2P(gfn) )
         {
-            P2M_PRINTK("shared mfn (%lx) on domain page list!\n",
-                    mfn);
+            P2M_PRINTK("shared mfn (%"PRI_mfn") on domain page list!\n",
+                       mfn_x(mfn));
             continue;
         }
 
         p2mfn = get_gfn_type_access(p2m, gfn, &type, &p2ma, 0, NULL);
-        if ( mfn_x(p2mfn) != mfn )
+        if ( !mfn_eq(p2mfn, mfn) )
         {
             mpbad++;
-            P2M_PRINTK("map mismatch mfn %#lx -> gfn %#lx -> mfn %#lx"
+            P2M_PRINTK("map mismatch mfn %"PRI_mfn" -> gfn %#lx -> mfn %"PRI_mfn""
                        " (-> gfn %#lx)\n",
-                       mfn, gfn, mfn_x(p2mfn),
+                       mfn_x(mfn), gfn, mfn_x(p2mfn),
                        (mfn_valid(p2mfn)
-                        ? get_gpfn_from_mfn(mfn_x(p2mfn))
+                        ? get_pfn_from_mfn(p2mfn)
                         : -1u));
             /* This m2p entry is stale: the domain has another frame in
              * this physical slot.  No great disaster, but for neatness,
              * blow away the m2p entry. */
-            set_gpfn_from_mfn(mfn, INVALID_M2P_ENTRY);
+            set_pfn_from_mfn(mfn, INVALID_M2P_ENTRY);
         }
         __put_gfn(p2m, gfn);
 
-        P2M_PRINTK("OK: mfn=%#lx, gfn=%#lx, p2mfn=%#lx\n",
-                       mfn, gfn, mfn_x(p2mfn));
+        P2M_PRINTK("OK: mfn=%"PRI_mfn", gfn=%#lx, p2mfn=%"PRI_mfn"\n",
+                   mfn_x(mfn), gfn, mfn_x(p2mfn));
     }
     spin_unlock(&d->page_alloc_lock);
 
xen/arch/x86/mm/paging.c +2 -2
index 9b0f268e74..cef2f90186 100644
@@ -344,7 +344,7 @@ void paging_mark_dirty(struct domain *d, mfn_t gmfn)
         return;
 
     /* We /really/ mean PFN here, even for non-translated guests. */
-    pfn = _pfn(get_gpfn_from_mfn(mfn_x(gmfn)));
+    pfn = _pfn(get_pfn_from_mfn(gmfn));
 
     paging_mark_pfn_dirty(d, pfn);
 }
@@ -362,7 +362,7 @@ int paging_mfn_is_dirty(struct domain *d, mfn_t gmfn)
     ASSERT(paging_mode_log_dirty(d));
 
     /* We /really/ mean PFN here, even for non-translated guests. */
-    pfn = _pfn(get_gpfn_from_mfn(mfn_x(gmfn)));
+    pfn = _pfn(get_pfn_from_mfn(gmfn));
     /* Invalid pages can't be dirty. */
     if ( unlikely(!VALID_M2P(pfn_x(pfn))) )
         return 0;
xen/arch/x86/pv/dom0_build.c +3 -3
index cef2d42254..b39ab67092 100644
@@ -39,7 +39,7 @@ void __init dom0_update_physmap(struct domain *d, unsigned long pfn,
     else
         ((unsigned int *)vphysmap_s)[pfn] = mfn;
 
-    set_gpfn_from_mfn(mfn, pfn);
+    set_pfn_from_mfn(_mfn(mfn), pfn);
 }
 
 static __init void mark_pv_pt_pages_rdonly(struct domain *d,
@@ -798,8 +798,8 @@ int __init dom0_construct_pv(struct domain *d,
     page_list_for_each ( page, &d->page_list )
     {
         mfn = mfn_x(page_to_mfn(page));
-        BUG_ON(SHARED_M2P(get_gpfn_from_mfn(mfn)));
-        if ( get_gpfn_from_mfn(mfn) >= count )
+        BUG_ON(SHARED_M2P(get_pfn_from_mfn(_mfn(mfn))));
+        if ( get_pfn_from_mfn(_mfn(mfn)) >= count )
         {
             BUG_ON(is_pv_32bit_domain(d));
             if ( !page->u.inuse.type_info &&
xen/arch/x86/x86_64/traps.c +21 -20
index 44af765e3e..f80f2250fe 100644
@@ -184,7 +184,8 @@ void vcpu_show_registers(const struct vcpu *v)
 
 void show_page_walk(unsigned long addr)
 {
-    unsigned long pfn, mfn = read_cr3() >> PAGE_SHIFT;
+    unsigned long pfn;
+    mfn_t mfn = maddr_to_mfn(read_cr3());
     l4_pgentry_t l4e, *l4t;
     l3_pgentry_t l3e, *l3t;
     l2_pgentry_t l2e, *l2t;
@@ -194,52 +195,52 @@ void show_page_walk(unsigned long addr)
     if ( !is_canonical_address(addr) )
         return;
 
-    l4t = map_domain_page(_mfn(mfn));
+    l4t = map_domain_page(mfn);
     l4e = l4t[l4_table_offset(addr)];
     unmap_domain_page(l4t);
-    mfn = l4e_get_pfn(l4e);
-    pfn = mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ?
-          get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
+    mfn = l4e_get_mfn(l4e);
+    pfn = mfn_valid(mfn) && machine_to_phys_mapping_valid ?
+          get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
     printk(" L4[0x%03lx] = %"PRIpte" %016lx\n",
            l4_table_offset(addr), l4e_get_intpte(l4e), pfn);
     if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) ||
-         !mfn_valid(_mfn(mfn)) )
+         !mfn_valid(mfn) )
         return;
 
-    l3t = map_domain_page(_mfn(mfn));
+    l3t = map_domain_page(mfn);
     l3e = l3t[l3_table_offset(addr)];
     unmap_domain_page(l3t);
-    mfn = l3e_get_pfn(l3e);
-    pfn = mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ?
-          get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
+    mfn = l3e_get_mfn(l3e);
+    pfn = mfn_valid(mfn) && machine_to_phys_mapping_valid ?
+          get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
     printk(" L3[0x%03lx] = %"PRIpte" %016lx%s\n",
            l3_table_offset(addr), l3e_get_intpte(l3e), pfn,
            (l3e_get_flags(l3e) & _PAGE_PSE) ? " (PSE)" : "");
     if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) ||
          (l3e_get_flags(l3e) & _PAGE_PSE) ||
-         !mfn_valid(_mfn(mfn)) )
+         !mfn_valid(mfn) )
         return;
 
-    l2t = map_domain_page(_mfn(mfn));
+    l2t = map_domain_page(mfn);
     l2e = l2t[l2_table_offset(addr)];
     unmap_domain_page(l2t);
-    mfn = l2e_get_pfn(l2e);
-    pfn = mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ?
-          get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
+    mfn = l2e_get_mfn(l2e);
+    pfn = mfn_valid(mfn) && machine_to_phys_mapping_valid ?
+          get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
     printk(" L2[0x%03lx] = %"PRIpte" %016lx%s\n",
            l2_table_offset(addr), l2e_get_intpte(l2e), pfn,
            (l2e_get_flags(l2e) & _PAGE_PSE) ? " (PSE)" : "");
     if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT) ||
          (l2e_get_flags(l2e) & _PAGE_PSE) ||
-         !mfn_valid(_mfn(mfn)) )
+         !mfn_valid(mfn) )
         return;
 
-    l1t = map_domain_page(_mfn(mfn));
+    l1t = map_domain_page(mfn);
     l1e = l1t[l1_table_offset(addr)];
     unmap_domain_page(l1t);
-    mfn = l1e_get_pfn(l1e);
-    pfn = mfn_valid(_mfn(mfn)) && machine_to_phys_mapping_valid ?
-          get_gpfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
+    mfn = l1e_get_mfn(l1e);
+    pfn = mfn_valid(mfn) && machine_to_phys_mapping_valid ?
+          get_pfn_from_mfn(mfn) : INVALID_M2P_ENTRY;
     printk(" L1[0x%03lx] = %"PRIpte" %016lx\n",
            l1_table_offset(addr), l1e_get_intpte(l1e), pfn);
 }
xen/common/memory.c +1 -1
index d6a580da31..eecc9671ff 100644
@@ -273,7 +273,7 @@ static void populate_physmap(struct memop_args *a)
             if ( !paging_mode_translate(d) )
             {
                 for ( j = 0; j < (1U << a->extent_order); j++ )
-                    set_gpfn_from_mfn(mfn_x(mfn_add(mfn, j)), gpfn + j);
+                    set_pfn_from_mfn(mfn_add(mfn, j), gpfn + j);
 
                 /* Inform the domain of the new page's machine address. */ 
                 if ( unlikely(__copy_mfn_to_guest_offset(a->extent_list, i,
xen/common/page_alloc.c +1 -1
index 6061cce24f..a100e03e2e 100644
@@ -1424,7 +1424,7 @@ static void free_heap_pages(
 
         /* This page is not a guest frame any more. */
         page_set_owner(&pg[i], NULL); /* set_gpfn_from_mfn snoops pg owner */
-        set_gpfn_from_mfn(mfn_x(mfn) + i, INVALID_M2P_ENTRY);
+        set_pfn_from_mfn(mfn_add(mfn, + i), INVALID_M2P_ENTRY);
 
         if ( need_scrub )
         {
xen/include/asm-arm/mm.h +1 -1
index a9cb98a6c7..3c03be3bca 100644
@@ -322,7 +322,7 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
 #define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
 
 /* We don't have a M2P on Arm */
-#define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn); } while (0)
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
 
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
xen/include/asm-x86/grant_table.h +1 -1
index 661228dd39..d731b9e49f 100644
@@ -41,7 +41,7 @@ static inline int replace_grant_host_mapping(uint64_t addr, mfn_t frame,
 #define gnttab_get_frame_gfn(gt, st, idx) ({                             \
     mfn_t mfn_ = (st) ? gnttab_status_mfn(gt, idx)                       \
                       : gnttab_shared_mfn(gt, idx);                      \
-    unsigned long gpfn_ = get_gpfn_from_mfn(mfn_x(mfn_));                \
+    unsigned long gpfn_ = get_pfn_from_mfn(mfn_);                        \
     VALID_M2P(gpfn_) ? _gfn(gpfn_) : INVALID_GFN;                        \
 })
 
xen/include/asm-x86/mm.h +10 -6
index 4721725c60..bce60619c3 100644
@@ -492,22 +492,26 @@ extern struct domain *dom_xen, *dom_io, *dom_cow;	/* for vmcoreinfo */
  */
 extern bool machine_to_phys_mapping_valid;
 
-static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn)
 {
-    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    const unsigned long mfn_ = mfn_x(mfn);
+    struct domain *d = page_get_owner(mfn_to_page(mfn));
     unsigned long entry = (d && (d == dom_cow)) ? SHARED_M2P_ENTRY : pfn;
 
     if (!machine_to_phys_mapping_valid)
         return;
 
-    if ( mfn >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )
-        compat_machine_to_phys_mapping[mfn] = entry;
-    machine_to_phys_mapping[mfn] = entry;
+    if ( mfn_ >= (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) / 4 )
+        compat_machine_to_phys_mapping[mfn_] = entry;
+    machine_to_phys_mapping[mfn_] = entry;
 }
 
 extern struct rangeset *mmio_ro_ranges;
 
-#define get_gpfn_from_mfn(mfn)      (machine_to_phys_mapping[(mfn)])
+static inline unsigned long get_pfn_from_mfn(mfn_t mfn)
+{
+    return machine_to_phys_mapping[mfn_x(mfn)];
+}
 
 #define compat_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
 #define compat_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
xen/include/asm-x86/p2m.h +1 -1
index 0157568be9..07b7ec6db0 100644
@@ -509,7 +509,7 @@ static inline struct page_info *get_page_from_gfn(
 static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn)
 {
     if ( paging_mode_translate(d) )
-        return _gfn(get_gpfn_from_mfn(mfn_x(mfn)));
+        return _gfn(get_pfn_from_mfn(mfn));
     else
         return _gfn(mfn_x(mfn));
 }
Signature · 1 line
2.11.0

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

#55 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

In reply to Julien Grall

xen/arch/x86/mm/mem_sharing.c static inline void mem_sharing_gfn_destroy(struct page_info *page, · line 394

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/mem_sharing.c +1 -1
@@ -391,11 +391,12 @@ static inline void mem_sharing_gfn_destroy(struct page_info *page,
     xfree(gfn_info);
 }
 
-static struct page_info* mem_sharing_lookup(unsigned long mfn)
+static struct page_info* mem_sharing_lookup(mfn_t mfn)

Could you fix the style issue (swapped * and blank) here at the same time?

Quoted 12 lines
xen/arch/x86/mm/mem_sharing.c +2 -2
@@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                 /* check for 1GB super page */
                 if ( l3e_get_flags(l3e[i3]) & _PAGE_PSE )
                 {
-                    mfn = l3e_get_pfn(l3e[i3]);
-                    ASSERT(mfn_valid(_mfn(mfn)));
+                    mfn = l3e_get_mfn(l3e[i3]);
+                    ASSERT(mfn_valid(mfn));
                     /* we have to cover 512x512 4K pages */
                     for ( i2 = 0; 
                           i2 < (L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES);
                           i2++)

xen/arch/x86/mm/mem_sharing.c long p2m_pt_audit_p2m(struct p2m_domain *p2m) · line 1046

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +3 -3
                     {
-                        m2pfn = get_gpfn_from_mfn(mfn+i2);
+                        m2pfn = get_pfn_from_mfn(mfn_add(mfn, i2));
                         if ( m2pfn != (gfn + i2) )
                         {
                             pmbad++;
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn+i2, mfn+i2,
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" gfn %#lx\n",
+                                       gfn + i2, mfn_x(mfn_add(mfn, i2)),

I think the shorter mfn_x(mfn) + i2 would be preferable here (and similarly below).

Quoted 14 lines
xen/arch/x86/mm/mem_sharing.c +3 -3
@@ -1099,19 +1100,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                                 entry_count++;
                             continue;
                         }
-                        mfn = l1e_get_pfn(l1e[i1]);
-                        ASSERT(mfn_valid(_mfn(mfn)));
-                        m2pfn = get_gpfn_from_mfn(mfn);
+                        mfn = l1e_get_mfn(l1e[i1]);
+                        ASSERT(mfn_valid(mfn));
+                        m2pfn = get_pfn_from_mfn(mfn);
                         if ( m2pfn != gfn &&
                              type != p2m_mmio_direct &&
                              !p2m_is_grant(type) &&
                              !p2m_is_shared(type) )

xen/arch/x86/mm/mem_sharing.c long p2m_pt_audit_p2m(struct p2m_domain *p2m) · line 1115

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +4 -4
                         {
                             pmbad++;
-                            printk("mismatch: gfn %#lx -> mfn %#lx"
-                                   " -> gfn %#lx\n", gfn, mfn, m2pfn);
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn, mfn, m2pfn);
+                            printk("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                   gfn, mfn_x(mfn), m2pfn);
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                       gfn, mfn_x(mfn), m2pfn);

George, do we really mean to have printk() and P2M_PRINTK() here?

Quoted 8 lines
xen/arch/x86/mm/mem_sharing.c +1 -2
@@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
     spin_lock(&d->page_alloc_lock);
     page_list_for_each ( page, &d->page_list )
     {
-        mfn = mfn_x(page_to_mfn(page));
+        mfn = page_to_mfn(page);
 
-        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);

xen/arch/x86/mm/mem_sharing.c void audit_p2m(struct domain *d, · line 2807

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +3 -2
+        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n", mfn_x(mfn));
 
         od = page_get_owner(page);
 
         if ( od != d )
         {
-            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
-                       mfn, od, (od?od->domain_id:-1), d, d->domain_id);
+            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) != %p(%u)\n",
+                       mfn_x(mfn), od, (od?od->domain_id:-1), d, d->domain_id);

Please be careful not to drop 0x prefixes from the resulting output (which are an effect of the # flag that you delete), at least when log messages contain a mix of hex and dec numbers. (I am, btw, not convinced that switching to PRI_mfn here is helpful.)

Also would you mind fixing the formatting (missing blanks) here?

xen/arch/x86/x86_64/traps.c void vcpu_show_registers(const struct vcpu *v) · line 188

Quoted 9 lines
xen/arch/x86/x86_64/traps.c +2 -1
@@ -184,7 +184,8 @@ void vcpu_show_registers(const struct vcpu *v)
 
 void show_page_walk(unsigned long addr)
 {
-    unsigned long pfn, mfn = read_cr3() >> PAGE_SHIFT;
+    unsigned long pfn;
+    mfn_t mfn = maddr_to_mfn(read_cr3());

I realize you simply take what has been there and transform it, but maddr_to_mfn() (other than shifting by PAGE_SHIFT) is not truly applicable here: What the CR3 register holds is not a physical address, both the low twelve bits as well as the high twelve ones have different meaning. The shift is correct currently because the high ones are (right now) zero on reads. Please consider AND-ing with X86_CR3_ADDR_MASK (or keeping the shift).

xen/common/page_alloc.c static void free_heap_pages( · line 1427

Quoted 8 lines
xen/common/page_alloc.c +1 -1
@@ -1424,7 +1424,7 @@ static void free_heap_pages(
 
         /* This page is not a guest frame any more. */
         page_set_owner(&pg[i], NULL); /* set_gpfn_from_mfn snoops pg owner */
-        set_gpfn_from_mfn(mfn_x(mfn) + i, INVALID_M2P_ENTRY);
+        set_pfn_from_mfn(mfn_add(mfn, + i), INVALID_M2P_ENTRY);

Stray leftover + ?

xen/include/asm-x86/mm.h extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */ · line 497

Quoted 11 lines
xen/include/asm-x86/mm.h +2 -2
@@ -492,22 +492,26 @@ extern struct domain *dom_xen, *dom_io, *dom_cow;	/* for vmcoreinfo */
  */
 extern bool machine_to_phys_mapping_valid;
 
-static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn)
 {
-    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    const unsigned long mfn_ = mfn_x(mfn);

I'm not overly happy to see a trailing underscore used outside a macro definition, but other than perhaps "frame" this may indeed be the best thing to do here.

Jan

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

#56 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

Quoted 24 lines · Jan Beulich
Quoted 9 lines
xen/arch/x86/mm/p2m.c +1 -2
@@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
     spin_lock(&d->page_alloc_lock);
     page_list_for_each ( page, &d->page_list )
     {
-        mfn = mfn_x(page_to_mfn(page));
+        mfn = page_to_mfn(page);
 
-        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);

xen/arch/x86/mm/p2m.c void audit_p2m(struct domain *d, · line 2807

Quoted 10 lines
xen/arch/x86/mm/p2m.c +3 -2
+        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n", mfn_x(mfn));
 
         od = page_get_owner(page);
 
         if ( od != d )
         {
-            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
-                       mfn, od, (od?od->domain_id:-1), d, d->domain_id);
+            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) != %p(%u)\n",
+                       mfn_x(mfn), od, (od?od->domain_id:-1), d, d->domain_id);

Please be careful not to drop 0x prefixes from the resulting output (which are an effect of the # flag that you delete), at least when log messages contain a mix of hex and dec numbers. (I am, btw, not convinced that switching to PRI_mfn here is helpful.)

Quoted 1 line

Also would you mind fixing the formatting (missing blanks) here?

Please also fix the od? conditional while making this change.  %pd was specifically designed to cope with a NULL pointer to avoid gymnastics like this in debugging code.

I'd rewrite it entirely to something like "mfn %"PRI_mfn" owner %pd != %pd\n"

~Andrew

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

#57 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

In reply to Jan Beulich
Quoted 11 lines · Jan Beulich

xen/arch/x86/mm/mem_sharing.c static inline void mem_sharing_gfn_destroy(struct page_info *page, · line 394

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/mem_sharing.c +1 -1
@@ -391,11 +391,12 @@ static inline void mem_sharing_gfn_destroy(struct page_info *page,
      xfree(gfn_info);
  }
 
-static struct page_info* mem_sharing_lookup(unsigned long mfn)
+static struct page_info* mem_sharing_lookup(mfn_t mfn)

Could you fix the style issue (swapped * and blank) here at the same time?

Ok.

Quoted 18 lines
Quoted 18 lines
xen/arch/x86/mm/mem_sharing.c +3 -3
@@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                  /* check for 1GB super page */
                  if ( l3e_get_flags(l3e[i3]) & _PAGE_PSE )
                  {
-                    mfn = l3e_get_pfn(l3e[i3]);
-                    ASSERT(mfn_valid(_mfn(mfn)));
+                    mfn = l3e_get_mfn(l3e[i3]);
+                    ASSERT(mfn_valid(mfn));
                      /* we have to cover 512x512 4K pages */
                      for ( i2 = 0;
                            i2 < (L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES);
                            i2++)
                      {
-                        m2pfn = get_gpfn_from_mfn(mfn+i2);
+                        m2pfn = get_pfn_from_mfn(mfn_add(mfn, i2));
                          if ( m2pfn != (gfn + i2) )
                          {
Quoted 8 lines

xen/arch/x86/mm/mem_sharing.c long p2m_pt_audit_p2m(struct p2m_domain *p2m) · line 1046

Quoted 5 lines
xen/arch/x86/mm/mem_sharing.c +2 -2
                              pmbad++;
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn+i2, mfn+i2,
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" gfn %#lx\n",
+                                       gfn + i2, mfn_x(mfn_add(mfn, i2)),

I think the shorter mfn_x(mfn) + i2 would be preferable here (and similarly below).

I thought about it, but I wanted to keep the typesafe as far as possible. Anyway, that's x86 code so that's your call.

Quoted 40 lines
Quoted 15 lines
xen/arch/x86/mm/mem_sharing.c +3 -3
@@ -1099,19 +1100,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                                  entry_count++;
                              continue;
                          }
-                        mfn = l1e_get_pfn(l1e[i1]);
-                        ASSERT(mfn_valid(_mfn(mfn)));
-                        m2pfn = get_gpfn_from_mfn(mfn);
+                        mfn = l1e_get_mfn(l1e[i1]);
+                        ASSERT(mfn_valid(mfn));
+                        m2pfn = get_pfn_from_mfn(mfn);
                          if ( m2pfn != gfn &&
                               type != p2m_mmio_direct &&
                               !p2m_is_grant(type) &&
                               !p2m_is_shared(type) )

xen/arch/x86/mm/mem_sharing.c long p2m_pt_audit_p2m(struct p2m_domain *p2m) · line 1115

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +4 -4
                          {
                              pmbad++;
-                            printk("mismatch: gfn %#lx -> mfn %#lx"
-                                   " -> gfn %#lx\n", gfn, mfn, m2pfn);
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn, mfn, m2pfn);
+                            printk("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                   gfn, mfn_x(mfn), m2pfn);
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                       gfn, mfn_x(mfn), m2pfn);

George, do we really mean to have printk() and P2M_PRINTK() here?

Quoted 12 lines
xen/arch/x86/mm/mem_sharing.c +2 -2
@@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
      spin_lock(&d->page_alloc_lock);
      page_list_for_each ( page, &d->page_list )
      {
-        mfn = mfn_x(page_to_mfn(page));
+        mfn = page_to_mfn(page);
 
-        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);
+        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n", mfn_x(mfn));
 
          od = page_get_owner(page);
 
Quoted 11 lines

xen/arch/x86/mm/mem_sharing.c void audit_p2m(struct domain *d, · line 2807

Quoted 6 lines
xen/arch/x86/mm/mem_sharing.c +2 -2
          if ( od != d )
          {
-            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
-                       mfn, od, (od?od->domain_id:-1), d, d->domain_id);
+            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) != %p(%u)\n",
+                       mfn_x(mfn), od, (od?od->domain_id:-1), d, d->domain_id);

Please be careful not to drop 0x prefixes from the resulting output (which are an effect of the # flag that you delete), at least when log messages contain a mix of hex and dec numbers. (I am, btw, not convinced that switching to PRI_mfn here is helpful.)

Last time I keeped %# for MFN, I have been asked to remove the #. I prefer having 0x for all the hex, and I am happy to be keep as is. But I would like a bit of consistency on the way we print MFN...

Quoted 2 lines

Also would you mind fixing the formatting (missing blanks) here?

Ok.

Quoted 5 lines
Quoted 5 lines
xen/arch/x86/x86_64/traps.c +0 -0
@@ -184,7 +184,8 @@ void vcpu_show_registers(const struct vcpu *v)
 
Quoted 13 lines

xen/arch/x86/x86_64/traps.c void vcpu_show_registers(const struct vcpu *v) · line 188

Quoted 5 lines
xen/arch/x86/x86_64/traps.c +2 -1
  void show_page_walk(unsigned long addr)
  {
-    unsigned long pfn, mfn = read_cr3() >> PAGE_SHIFT;
+    unsigned long pfn;
+    mfn_t mfn = maddr_to_mfn(read_cr3());

I realize you simply take what has been there and transform it, but maddr_to_mfn() (other than shifting by PAGE_SHIFT) is not truly applicable here: What the CR3 register holds is not a physical address, both the low twelve bits as well as the high twelve ones have different meaning. The shift is correct currently because the high ones are (right now) zero on reads. Please consider AND-ing with X86_CR3_ADDR_MASK (or keeping the shift).

I will keep the shift and move to _mfn(...).

Quoted 11 lines

xen/common/page_alloc.c static void free_heap_pages( · line 1427

Quoted 9 lines
xen/common/page_alloc.c +1 -1
@@ -1424,7 +1424,7 @@ static void free_heap_pages(
 
          /* This page is not a guest frame any more. */
          page_set_owner(&pg[i], NULL); /* set_gpfn_from_mfn snoops pg owner */
-        set_gpfn_from_mfn(mfn_x(mfn) + i, INVALID_M2P_ENTRY);
+        set_pfn_from_mfn(mfn_add(mfn, + i), INVALID_M2P_ENTRY);

Stray leftover + ?

Yes.

Quoted 7 lines
Quoted 7 lines
xen/include/asm-x86/mm.h +0 -0
@@ -492,22 +492,26 @@ extern struct domain *dom_xen, *dom_io, *dom_cow;	/* for vmcoreinfo */
   */
  extern bool machine_to_phys_mapping_valid;
 
Quoted 9 lines

xen/include/asm-x86/mm.h extern struct domain *dom_xen, *dom_io, *dom_cow; /* for vmcoreinfo */ · line 497

Quoted 5 lines
xen/include/asm-x86/mm.h +2 -2
-static inline void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn)
  {
-    struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
+    const unsigned long mfn_ = mfn_x(mfn);

I'm not overly happy to see a trailing underscore used outside a macro definition, but other than perhaps "frame" this may indeed be the best thing to do here.

That's x86 so your call.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:34, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/p2m-pt.c +3 -3
@@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                  /* check for 1GB super page */
                  if ( l3e_get_flags(l3e[i3]) & _PAGE_PSE )
                  {
-                    mfn = l3e_get_pfn(l3e[i3]);
-                    ASSERT(mfn_valid(_mfn(mfn)));
+                    mfn = l3e_get_mfn(l3e[i3]);
+                    ASSERT(mfn_valid(mfn));
                      /* we have to cover 512x512 4K pages */
                      for ( i2 = 0;
                            i2 < (L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES);
                            i2++)
                      {
-                        m2pfn = get_gpfn_from_mfn(mfn+i2);
+                        m2pfn = get_pfn_from_mfn(mfn_add(mfn, i2));
                          if ( m2pfn != (gfn + i2) )
                          {
Quoted 8 lines

xen/arch/x86/mm/p2m-pt.c long p2m_pt_audit_p2m(struct p2m_domain *p2m) · line 1046

Quoted 5 lines
xen/arch/x86/mm/p2m-pt.c +2 -2
                              pmbad++;
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn+i2, mfn+i2,
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" gfn %#lx\n",
+                                       gfn + i2, mfn_x(mfn_add(mfn, i2)),

I think the shorter mfn_x(mfn) + i2 would be preferable here (and similarly below).

Quoted 2 lines

I thought about it, but I wanted to keep the typesafe as far as possible. Anyway, that's x86 code so that's your call.

George's in this case.

Quoted 24 lines
Quoted 12 lines
Quoted 12 lines
xen/arch/x86/mm/p2m.c +2 -2
@@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
      spin_lock(&d->page_alloc_lock);
      page_list_for_each ( page, &d->page_list )
      {
-        mfn = mfn_x(page_to_mfn(page));
+        mfn = page_to_mfn(page);
 
-        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);
+        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n", mfn_x(mfn));
 
          od = page_get_owner(page);
 
Quoted 11 lines

xen/arch/x86/mm/p2m.c void audit_p2m(struct domain *d, · line 2807

Quoted 6 lines
xen/arch/x86/mm/p2m.c +2 -2
          if ( od != d )
          {
-            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
-                       mfn, od, (od?od->domain_id:-1), d, d->domain_id);
+            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) != %p(%u)\n",
+                       mfn_x(mfn), od, (od?od->domain_id:-1), d, d->domain_id);

Please be careful not to drop 0x prefixes from the resulting output (which are an effect of the # flag that you delete), at least when log messages contain a mix of hex and dec numbers. (I am, btw, not convinced that switching to PRI_mfn here is helpful.)

Quoted 3 lines

Last time I keeped %# for MFN, I have been asked to remove the #. I prefer having 0x for all the hex, and I am happy to be keep as is. But I would like a bit of consistency on the way we print MFN...

Well, "%#"PRI_mfn is bogus (because of the combination with the minimum width specification), so it ought to be "%#lx" or "0x%"PRI_mfn. Have you really been asked for something else? If so, and if it was me, then I apologize.

Jan

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

#59 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

Quoted 28 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:34, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +1 -2
@@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
@@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
       spin_lock(&d->page_alloc_lock);
       page_list_for_each ( page, &d->page_list )
       {
-        mfn = mfn_x(page_to_mfn(page));
+        mfn = page_to_mfn(page);
 
-        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);

xen/arch/x86/mm/p2m.c void audit_p2m(struct domain *d, · line 2807

Quoted 10 lines
xen/arch/x86/mm/p2m.c +3 -2
+        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n", mfn_x(mfn));
 
           od = page_get_owner(page);
 
           if ( od != d )
           {
-            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
-                       mfn, od, (od?od->domain_id:-1), d, d->domain_id);
+            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) != %p(%u)\n",
+                       mfn_x(mfn), od, (od?od->domain_id:-1), d, d->domain_id);

Please be careful not to drop 0x prefixes from the resulting output (which are an effect of the # flag that you delete), at least when log messages contain a mix of hex and dec numbers. (I am, btw, not convinced that switching to PRI_mfn here is helpful.)

Quoted 8 lines
Quoted 3 lines

Last time I keeped %# for MFN, I have been asked to remove the #. I prefer having 0x for all the hex, and I am happy to be keep as is. But I would like a bit of consistency on the way we print MFN...

Well, "%#"PRI_mfn is bogus (because of the combination with the minimum width specification), so it ought to be "%#lx" or "0x%"PRI_mfn. Have you really been asked for something else? If so, and if it was me, then I apologize.

I am not sure why this is bogus. The thing is using different format for the MFN makes it difficult to read a message without looking format string.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

Quoted 34 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:46, <[email protected]> wrote:
Quoted 32 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:34, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +2 -2
@@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
@@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
       spin_lock(&d->page_alloc_lock);
       page_list_for_each ( page, &d->page_list )
       {
-        mfn = mfn_x(page_to_mfn(page));
+        mfn = page_to_mfn(page);
 
-        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);
+        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n", mfn_x(mfn));
 
           od = page_get_owner(page);
 
Quoted 11 lines

xen/arch/x86/mm/p2m.c void audit_p2m(struct domain *d, · line 2807

Quoted 6 lines
xen/arch/x86/mm/p2m.c +2 -2
           if ( od != d )
           {
-            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
-                       mfn, od, (od?od->domain_id:-1), d, d->domain_id);
+            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) != %p(%u)\n",
+                       mfn_x(mfn), od, (od?od->domain_id:-1), d, d->domain_id);

Please be careful not to drop 0x prefixes from the resulting output (which are an effect of the # flag that you delete), at least when log messages contain a mix of hex and dec numbers. (I am, btw, not convinced that switching to PRI_mfn here is helpful.)

Last time I keeped %# for MFN, I have been asked to remove the #. I prefer having 0x for all the hex, and I am happy to be keep as is. But I would like a bit of consistency on the way we print MFN...

Quoted 7 lines
Quoted 4 lines

Well, "%#"PRI_mfn is bogus (because of the combination with the minimum width specification), so it ought to be "%#lx" or "0x%"PRI_mfn. Have you really been asked for something else? If so, and if it was me, then I apologize.

I am not sure why this is bogus. The thing is using different format for the MFN makes it difficult to read a message without looking format string.

We look to be in agreement that there should be a 0x prefix here. What I'm asking for is to avoid the value logged to de-generate into a 3-digit one (0x???) when a five digit one is meant (see PRI_mfn). Not to speak of the further inconsistent string that would be logged for MFN 0.

Jan

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

#61 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

Quoted 35 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:46, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:34, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/arch/x86/mm/p2m.c +2 -2
@@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
@@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
       spin_lock(&d->page_alloc_lock);
       page_list_for_each ( page, &d->page_list )
       {
-        mfn = mfn_x(page_to_mfn(page));
+        mfn = page_to_mfn(page);
 
-        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);
+        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n", mfn_x(mfn));
 
           od = page_get_owner(page);
 
Quoted 10 lines

xen/arch/x86/mm/p2m.c void audit_p2m(struct domain *d, · line 2807

Quoted 6 lines
xen/arch/x86/mm/p2m.c +2 -2
           if ( od != d )
           {
-            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
-                       mfn, od, (od?od->domain_id:-1), d, d->domain_id);
+            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) != %p(%u)\n",
+                       mfn_x(mfn), od, (od?od->domain_id:-1), d, d->domain_id);

Please be careful not to drop 0x prefixes from the resulting output (which are an effect of the # flag that you delete), at least when log messages contain a mix of hex and dec numbers. (I am, btw, not convinced that switching to PRI_mfn here is helpful.)

Quoted 3 lines

Last time I keeped %# for MFN, I have been asked to remove the #. I prefer having 0x for all the hex, and I am happy to be keep as is. But I would like a bit of consistency on the way we print MFN...

Well, "%#"PRI_mfn is bogus (because of the combination with the minimum width specification), so it ought to be "%#lx" or "0x%"PRI_mfn. Have you really been asked for something else? If so, and if it was me, then I apologize.

Quoted 7 lines
Quoted 2 lines

I am not sure why this is bogus. The thing is using different format for the MFN makes it difficult to read a message without looking format string.

We look to be in agreement that there should be a 0x prefix here. What I'm asking for is to avoid the value logged to de-generate into a 3-digit one (0x???) when a five digit one is meant (see PRI_mfn). Not to speak of the further inconsistent string that would be logged for MFN 0.

The overwhelming majority way of printing mfns is via:

mfn %"PRI_mfn"

which is almost fully consistent across the x86 code.

Various bits of common code, and most of ARM code use variations of %#"PRI_mfn", and this ought to be fixed.

~Andrew

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

#62 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

Quoted 44 lines · Andrew Cooper
Quoted 35 lines · Jan Beulich
Quoted 35 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:46, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 26 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:34, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
(quoted diff) +2 -2
@@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
@@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
        spin_lock(&d->page_alloc_lock);
        page_list_for_each ( page, &d->page_list )
        {
-        mfn = mfn_x(page_to_mfn(page));
+        mfn = page_to_mfn(page);
 
-        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);
+        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n", mfn_x(mfn));
 
            od = page_get_owner(page);
 
Quoted 10 lines

Review void audit_p2m(struct domain *d, · line 2807

Quoted 6 lines
(quoted diff) +2 -2
            if ( od != d )
            {
-            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
-                       mfn, od, (od?od->domain_id:-1), d, d->domain_id);
+            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) != %p(%u)\n",
+                       mfn_x(mfn), od, (od?od->domain_id:-1), d, d->domain_id);

Please be careful not to drop 0x prefixes from the resulting output (which are an effect of the # flag that you delete), at least when log messages contain a mix of hex and dec numbers. (I am, btw, not convinced that switching to PRI_mfn here is helpful.)

Quoted 3 lines

Last time I keeped %# for MFN, I have been asked to remove the #. I prefer having 0x for all the hex, and I am happy to be keep as is. But I would like a bit of consistency on the way we print MFN...

Well, "%#"PRI_mfn is bogus (because of the combination with the minimum width specification), so it ought to be "%#lx" or "0x%"PRI_mfn. Have you really been asked for something else? If so, and if it was me, then I apologize.

Quoted 7 lines
Quoted 2 lines

I am not sure why this is bogus. The thing is using different format for the MFN makes it difficult to read a message without looking format string.

We look to be in agreement that there should be a 0x prefix here. What I'm asking for is to avoid the value logged to de-generate into a 3-digit one (0x???) when a five digit one is meant (see PRI_mfn). Not to speak of the further inconsistent string that would be logged for MFN 0.

Quoted 5 lines

The overwhelming majority way of printing mfns is via:

mfn %"PRI_mfn"

which is almost fully consistent across the x86 code.

If I got it right, the format here would be "wrong owner mfn %"PRI_mfn". Am I correct?

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

Quoted 54 lines · Julien Grall
Quoted 51 lines · Andrew Cooper
Quoted 49 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:46, <[email protected]> wrote:
Quoted 33 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:34, <[email protected]> wrote:
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
(quoted diff) +2 -3
@@ -1030,19 +1031,19 @@ long p2m_pt_audit_p2m(struct p2m_domain
 *p2m)
@@ -2795,54 +2795,54 @@ void audit_p2m(struct domain *d,
         spin_lock(&d->page_alloc_lock);
         page_list_for_each ( page, &d->page_list )
         {
-        mfn = mfn_x(page_to_mfn(page));
+        mfn = page_to_mfn(page);
     -        P2M_PRINTK("auditing guest page, mfn=%#lx\n", mfn);
+        P2M_PRINTK("auditing guest page, mfn=%"PRI_mfn"\n",
 mfn_x(mfn));
                 od = page_get_owner(page);
                 if ( od != d )
             {
-            P2M_PRINTK("wrong owner %#lx -> %p(%u) != %p(%u)\n",
-                       mfn, od, (od?od->domain_id:-1), d,
 d->domain_id);
Quoted 8 lines

Review void audit_p2m(struct domain *d, · line 2809

Quoted 4 lines
(quoted diff) +2 -0
+            P2M_PRINTK("wrong owner %"PRI_mfn" -> %p(%u) !=
 %p(%u)\n",
+                       mfn_x(mfn), od, (od?od->domain_id:-1),
 d, d->domain_id);

Please be careful not to drop 0x prefixes from the resulting output (which are an effect of the # flag that you delete), at least when log messages contain a mix of hex and dec numbers. (I am, btw, not convinced that switching to PRI_mfn here is helpful.)

Quoted 5 lines

Last time I keeped %# for MFN, I have been asked to remove the #. I prefer
having 0x for all the hex, and I am happy to be keep as is. But I would like a
bit of consistency on the way we print MFN...

Quoted 6 lines

Well, "%#"PRI_mfn is bogus (because of the combination with the minimum width specification), so it ought to be "%#lx" or "0x%"PRI_mfn.
Have you really been asked for something else? If so, and if it was me,
then I apologize.

Quoted 3 lines

I am not sure why this is bogus. The thing is using different format for the MFN
makes it difficult to read a message without looking format string.

We look to be in agreement that there should be a 0x prefix here. What I'm asking for is to avoid the value logged to de-generate into a 3-digit one (0x???) when a five digit one is meant (see PRI_mfn). Not to speak of the further inconsistent string that would be logged for MFN 0.

Quoted 8 lines
Quoted 5 lines

The overwhelming majority way of printing mfns is via:

mfn %"PRI_mfn"

which is almost fully consistent across the x86 code.

If I got it right, the format here would be "wrong owner mfn %"PRI_mfn". Am I correct?

IMO, yes, but see my specific email for an even better alternative.

~Andrew

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

#64 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

In reply to Andrew Cooper
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 16:05, <[email protected]> wrote:

The overwhelming majority way of printing mfns is via:

mfn %"PRI_mfn"

which is almost fully consistent across the x86 code.

Various bits of common code, and most of ARM code use variations of %#"PRI_mfn", and this ought to be fixed.

Oh, so you're fine with omitting the 0x here? That's fine with me. I've suggested its addition merely because commonly you ask for the prefix.

Jan

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

#65 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

Quoted 11 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 16:05, <[email protected]> wrote:

The overwhelming majority way of printing mfns is via:

mfn %"PRI_mfn"

which is almost fully consistent across the x86 code.

Various bits of common code, and most of ARM code use variations of %#"PRI_mfn", and this ought to be fixed.

Oh, so you're fine with omitting the 0x here? That's fine with me. I've suggested its addition merely because commonly you ask for the prefix.

This falls into the category of "what is commonly done" vs "what is ideal".

Personally, I'd prefer to have no ambiguity between dec and hex, and would in principle prefer to start printing mfns with a leading 0x.

However, we a) don't have the current expectations documented, and b) I consider it rude and obstructive to make an undocumented change to expectations as part of reviewing an unrelated change.  (I certainly find it obstructive when others do it to me in review.)

So long as the number is clearly identified as an mfn (which it wasn't previously), the prevailing format used in Xen is %05lx, and this what should be used.

When point a) above is addressed, there can be a proposed change to expectations by patching the docs and adjusting the existing users.

~Andrew

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

#66 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

In reply to Jan Beulich
Quoted 18 lines · Jan Beulich
Quoted 18 lines
xen/arch/x86/mm/p2m-pt.c +3 -5
@@ -1099,19 +1100,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                                 entry_count++;
                             continue;
                         }
-                        mfn = l1e_get_pfn(l1e[i1]);
-                        ASSERT(mfn_valid(_mfn(mfn)));
-                        m2pfn = get_gpfn_from_mfn(mfn);
+                        mfn = l1e_get_mfn(l1e[i1]);
+                        ASSERT(mfn_valid(mfn));
+                        m2pfn = get_pfn_from_mfn(mfn);
                         if ( m2pfn != gfn &&
                              type != p2m_mmio_direct &&
                              !p2m_is_grant(type) &&
                              !p2m_is_shared(type) )
                         {
                             pmbad++;
-                            printk("mismatch: gfn %#lx -> mfn %#lx"
-                                   " -> gfn %#lx\n", gfn, mfn, m2pfn);
Quoted 8 lines

xen/arch/x86/mm/p2m-pt.c long p2m_pt_audit_p2m(struct p2m_domain *p2m) · line 1115

Quoted 6 lines
xen/arch/x86/mm/p2m-pt.c +4 -2
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn, mfn, m2pfn);
+                            printk("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                   gfn, mfn_x(mfn), m2pfn);
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                       gfn, mfn_x(mfn), m2pfn);

George, do we really mean to have printk() and P2M_PRINTK() here?

Looks like this was introduced (by me!) in a589ff6c179; my best guess is that it was due to a bad rebase merge.

I'll leave it to Julien to decide if he wants to clean this up or leave it be.

-George

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

#67 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

Hi George,

Quoted 28 lines · George Dunlap
Quoted 18 lines · Jan Beulich
Quoted 18 lines
xen/arch/x86/mm/p2m-pt.c +3 -5
@@ -1099,19 +1100,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                                  entry_count++;
                              continue;
                          }
-                        mfn = l1e_get_pfn(l1e[i1]);
-                        ASSERT(mfn_valid(_mfn(mfn)));
-                        m2pfn = get_gpfn_from_mfn(mfn);
+                        mfn = l1e_get_mfn(l1e[i1]);
+                        ASSERT(mfn_valid(mfn));
+                        m2pfn = get_pfn_from_mfn(mfn);
                          if ( m2pfn != gfn &&
                               type != p2m_mmio_direct &&
                               !p2m_is_grant(type) &&
                               !p2m_is_shared(type) )
                          {
                              pmbad++;
-                            printk("mismatch: gfn %#lx -> mfn %#lx"
-                                   " -> gfn %#lx\n", gfn, mfn, m2pfn);
Quoted 8 lines

xen/arch/x86/mm/p2m-pt.c long p2m_pt_audit_p2m(struct p2m_domain *p2m) · line 1115

Quoted 6 lines
xen/arch/x86/mm/p2m-pt.c +4 -2
-                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"
-                                       " -> gfn %#lx\n", gfn, mfn, m2pfn);
+                            printk("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                   gfn, mfn_x(mfn), m2pfn);
+                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                       gfn, mfn_x(mfn), m2pfn);

George, do we really mean to have printk() and P2M_PRINTK() here?

Quoted 2 lines

Looks like this was introduced (by me!) in a589ff6c179; my best guess is that it was due to a bad rebase merge.

Only the P2M_PRINTK version should be kept, am I right?

Quoted 3 lines

I'll leave it to Julien to decide if he wants to clean this up or leave it be.

I am happy to write a patch to remove the duplicated message.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

Quoted 35 lines · Julien Grall

Hi George,

Quoted 32 lines · George Dunlap
Quoted 30 lines · Jan Beulich
Quoted 20 lines
xen/arch/x86/mm/p2m-pt.c +3 -3
@@ -1099,19 +1100,19 @@ long p2m_pt_audit_p2m(struct p2m_domain *p2m)
                                   entry_count++;
                               continue;
                           }
-                        mfn = l1e_get_pfn(l1e[i1]);
-                        ASSERT(mfn_valid(_mfn(mfn)));
-                        m2pfn = get_gpfn_from_mfn(mfn);
+                        mfn = l1e_get_mfn(l1e[i1]);
+                        ASSERT(mfn_valid(mfn));
+                        m2pfn = get_pfn_from_mfn(mfn);

                          if ( m2pfn != gfn &&
                               type != p2m_mmio_direct && !p2m_is_grant(type) && !p2m_is_shared(type) )
                          {
                              pmbad++;
-                            printk("mismatch: gfn %#lx -> mfn %#lx" -                                   " -> gfn %#lx\n", gfn, mfn, m2pfn); -                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %#lx"

Quoted 8 lines

-                                       " -> gfn %#lx\n", gfn, mfn, m2pfn);
+                            printk("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                   gfn, mfn_x(mfn), m2pfn); +                            P2M_PRINTK("mismatch: gfn %#lx -> mfn %"PRI_mfn" -> gfn %#lx\n",
+                                       gfn, mfn_x(mfn), m2pfn);

George, do we really mean to have printk() and P2M_PRINTK() here?

Quoted 4 lines
Quoted 2 lines

Looks like this was introduced (by me!) in a589ff6c179; my best guess is that it was due to a bad rebase merge.

Only the P2M_PRINTK version should be kept, am I right?

Yes, that's right.

Quoted 4 lines
Quoted 2 lines

I'll leave it to Julien to decide if he wants to clean this up or leave it be.

I am happy to write a patch to remove the duplicated message.

Great, thanks.

-George

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

Acked-by on v1 13/14
#69 lore raw

Re: [PATCH 13/14] xen/mm: Convert {s, g}et_gpfn_from_mfn() to use typesafe MFN

In reply to Julien Grall
Quoted 11 lines · Julien Grall

The first parameter of {s,g}et_gpfn_from_mfn() is an MFN, so it can be switched to use the typesafe.

At the same time, replace gpfn with pfn in the helpers as they all deal with PFN and also turn the macros to static inline.

Note that the return of the getter and the 2nd parameter of the setter have not been converted to use typesafe PFN because it was requiring more changes than expected.

For the mm bits, I'm happy for this to be checked in as-is, or with any of the changes proposed in this sub-thread:

Sorry for taking so long to get to this, and thanks for taking on this fairly monumental task.

-George

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

#70 lore raw

PATCH 14/14 xen/mm: Provide dummy M2P-related helpers when !CONFIG_HAVE_M2P

In reply to Julien Grall

At the moment, Arm is providing a dummy implementation for the M2P helpers used in common code. However, they are quite isolated and could be used by other architecture in the future. So move all the helpers in xen/mm.h.

---
Changes in v2:
- Patch added

---
 xen/include/asm-arm/mm.h | 11 -----------
 xen/include/xen/mm.h     | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 11 deletions(-)
xen/include/asm-arm/mm.h +0 -11
index 3c03be3bca..d68d1794e5 100644
@@ -313,17 +313,6 @@ static inline void *page_to_virt(const struct page_info *pg)
 struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
                                     unsigned long flags);
 
-/*
- * Arm does not have an M2P, but common code expects a handful of
- * M2P-related defines and functions. Provide dummy versions of these.
- */
-#define INVALID_M2P_ENTRY        (~0UL)
-#define SHARED_M2P_ENTRY         (~0UL - 1UL)
-#define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
-
-/* We don't have a M2P on Arm */
-static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
-
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 
xen/include/xen/mm.h +14 -0
index 3ba7168cc9..07d2d44491 100644
@@ -658,4 +658,18 @@ static inline void share_xen_page_with_privileged_guests(
     share_xen_page_with_guest(page, dom_xen, flags);
 }
 
+/*
+ * Dummy implementation of M2P-related helpers for common code when
+ * the architecture doesn't have an M2P.
+ */
+#ifndef CONFIG_HAS_M2P
+
+#define INVALID_M2P_ENTRY        (~0UL)
+#define SHARED_M2P_ENTRY         (~0UL - 1UL)
+#define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
+
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
+
+#endif
+
 #endif /* __XEN_MM_H__ */
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 14/14
#71 lore raw

Re: [PATCH 14/14] xen/mm: Provide dummy M2P-related helpers when !CONFIG_HAVE_M2P

Quoted 6 lines · Julien Grall

At the moment, Arm is providing a dummy implementation for the M2P helpers used in common code. However, they are quite isolated and could be used by other architecture in the future. So move all the helpers in xen/mm.h.

Quoted 56 lines

---
Changes in v2:
- Patch added

---
 xen/include/asm-arm/mm.h | 11 -----------
 xen/include/xen/mm.h     | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 11 deletions(-)
xen/include/asm-arm/mm.h +0 -11
index 3c03be3bca..d68d1794e5 100644
@@ -313,17 +313,6 @@ static inline void *page_to_virt(const struct page_info *pg)
 struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
                                     unsigned long flags);
 
-/*
- * Arm does not have an M2P, but common code expects a handful of
- * M2P-related defines and functions. Provide dummy versions of these.
- */
-#define INVALID_M2P_ENTRY        (~0UL)
-#define SHARED_M2P_ENTRY         (~0UL - 1UL)
-#define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
-
-/* We don't have a M2P on Arm */
-static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
-
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 
xen/include/xen/mm.h +14 -0
index 3ba7168cc9..07d2d44491 100644
@@ -658,4 +658,18 @@ static inline void share_xen_page_with_privileged_guests(
     share_xen_page_with_guest(page, dom_xen, flags);
 }
 
+/*
+ * Dummy implementation of M2P-related helpers for common code when
+ * the architecture doesn't have an M2P.
+ */
+#ifndef CONFIG_HAS_M2P
+
+#define INVALID_M2P_ENTRY        (~0UL)
+#define SHARED_M2P_ENTRY         (~0UL - 1UL)
+#define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
+
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
+
+#endif
+
 #endif /* __XEN_MM_H__ */
Signature · 1 line
2.11.0

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

#72 lore raw

Re: [PATCH 14/14] xen/mm: Provide dummy M2P-related helpers when !CONFIG_HAVE_M2P

In reply to Julien Grall
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/include/xen/mm.h +3 -0
@@ -658,4 +658,18 @@ static inline void share_xen_page_with_privileged_guests(
     share_xen_page_with_guest(page, dom_xen, flags);
 }
 
+/*
+ * Dummy implementation of M2P-related helpers for common code when
+ * the architecture doesn't have an M2P.

xen/include/xen/mm.h static inline void share_xen_page_with_privileged_guests( · line 673

Quoted 10 lines
xen/include/xen/mm.h +10 -0
+ */
+#ifndef CONFIG_HAS_M2P
+
+#define INVALID_M2P_ENTRY        (~0UL)
+#define SHARED_M2P_ENTRY         (~0UL - 1UL)
+#define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
+
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
+
+#endif

In order for things to not be scattered around, could domain_shared_info_gfn() (see patch 9) move here? It doesn't look as if this would cause a build issue.

Jan

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

#73 lore raw

Re: [PATCH 14/14] xen/mm: Provide dummy M2P-related helpers when !CONFIG_HAVE_M2P

Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/include/xen/mm.h +9 -0
@@ -658,4 +658,18 @@ static inline void share_xen_page_with_privileged_guests(
      share_xen_page_with_guest(page, dom_xen, flags);
  }
 
+/*
+ * Dummy implementation of M2P-related helpers for common code when
+ * the architecture doesn't have an M2P.
+ */
+#ifndef CONFIG_HAS_M2P
+
+#define INVALID_M2P_ENTRY        (~0UL)
+#define SHARED_M2P_ENTRY         (~0UL - 1UL)
+#define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
Quoted 8 lines

xen/include/xen/mm.h static inline void share_xen_page_with_privileged_guests( · line 673

Quoted 4 lines
xen/include/xen/mm.h +4 -0
+
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
+
+#endif

In order for things to not be scattered around, could domain_shared_info_gfn() (see patch 9) move here? It doesn't look as if this would cause a build issue.

The two are different, one deal with memory, the other with a domain. So the current split makes sense.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [PATCH 14/14] xen/mm: Provide dummy M2P-related helpers when !CONFIG_HAVE_M2P

Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:29, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/include/xen/mm.h +9 -0
@@ -658,4 +658,18 @@ static inline void share_xen_page_with_privileged_guests(
      share_xen_page_with_guest(page, dom_xen, flags);
  }
 
+/*
+ * Dummy implementation of M2P-related helpers for common code when
+ * the architecture doesn't have an M2P.
+ */
+#ifndef CONFIG_HAS_M2P
+
+#define INVALID_M2P_ENTRY        (~0UL)
+#define SHARED_M2P_ENTRY         (~0UL - 1UL)
+#define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
Quoted 8 lines

xen/include/xen/mm.h static inline void share_xen_page_with_privileged_guests( · line 673

Quoted 4 lines
xen/include/xen/mm.h +4 -0
+
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
+
+#endif

In order for things to not be scattered around, could domain_shared_info_gfn() (see patch 9) move here? It doesn't look as if this would cause a build issue.

Quoted 2 lines

The two are different, one deal with memory, the other with a domain. So the current split makes sense.

Well, that's one perspective to take. The other is that it's mm to obtain a specific other form of a given address.

Jan

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

#75 lore raw

Re: [PATCH 14/14] xen/mm: Provide dummy M2P-related helpers when !CONFIG_HAVE_M2P

Quoted 27 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 10.05.19 at 15:29, <[email protected]> wrote:
Quoted 24 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 07.05.19 at 17:14, <[email protected]> wrote:
xen/include/xen/mm.h +3 -0
@@ -658,4 +658,18 @@ static inline void share_xen_page_with_privileged_guests(
       share_xen_page_with_guest(page, dom_xen, flags);
   }
 
+/*
+ * Dummy implementation of M2P-related helpers for common code when
+ * the architecture doesn't have an M2P.

xen/include/xen/mm.h static inline void share_xen_page_with_privileged_guests( · line 673

Quoted 10 lines
xen/include/xen/mm.h +10 -0
+ */
+#ifndef CONFIG_HAS_M2P
+
+#define INVALID_M2P_ENTRY        (~0UL)
+#define SHARED_M2P_ENTRY         (~0UL - 1UL)
+#define SHARED_M2P(_e)           ((_e) == SHARED_M2P_ENTRY)
+
+static inline void set_pfn_from_mfn(mfn_t mfn, unsigned long pfn) {}
+
+#endif

In order for things to not be scattered around, could domain_shared_info_gfn() (see patch 9) move here? It doesn't look as if this would cause a build issue.

Quoted 5 lines
Quoted 2 lines

The two are different, one deal with memory, the other with a domain. So the current split makes sense.

Well, that's one perspective to take. The other is that it's mm to obtain a specific other form of a given address.

It is just an implementation detail. If I follow your view, we would have a single header for everything under the same #ifdef...

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 14/14
#76 lore raw

Re: [PATCH 14/14] xen/mm: Provide dummy M2P-related helpers when !CONFIG_HAVE_M2P

In reply to Julien Grall
Quoted 6 lines · Julien Grall

At the moment, Arm is providing a dummy implementation for the M2P helpers used in common code. However, they are quite isolated and could be used by other architecture in the future. So move all the helpers in xen/mm.h.

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