[Xen-devel,04/27] xen/mm: Move {G, M]FN <-> {G, M}ADDR helpers to common code

Message ID 20170814142418.13267-5-julien.grall@arm.com
State New
Headers show
Series
  • xen/arm: Memory subsystem clean-up
Related show

Commit Message

Julien Grall Aug. 14, 2017, 2:23 p.m.
Helpers to convert {G,M}FN to {G,M}ADDR and vice-versa were recently
introduced on ARM. However, they could be used in common code to
simplify a bit the code when using typesafes.

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

Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Tim Deegan <tim@xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>
---
 xen/include/asm-arm/mm.h | 4 ----
 xen/include/xen/mm.h     | 6 ++++++
 2 files changed, 6 insertions(+), 4 deletions(-)

Comments

Jan Beulich Aug. 22, 2017, 8:23 a.m. | #1
>>> On 14.08.17 at 16:23, <julien.grall@arm.com> wrote:
> --- a/xen/include/xen/mm.h
> +++ b/xen/include/xen/mm.h
> @@ -92,6 +92,9 @@ static inline bool_t mfn_eq(mfn_t x, mfn_t y)
>      return mfn_x(x) == mfn_x(y);
>  }
>  
> +#define maddr_to_mfn(maddr) _mfn(paddr_to_pfn(maddr))
> +#define mfn_to_maddr(mfn)   pfn_to_paddr(mfn_x(mfn))
> +
>  TYPE_SAFE(unsigned long, gfn);
>  #define PRI_gfn          "05lx"
>  #define INVALID_GFN      _gfn(~0UL)
> @@ -130,6 +133,9 @@ static inline bool_t gfn_eq(gfn_t x, gfn_t y)
>      return gfn_x(x) == gfn_x(y);
>  }
>  
> +#define gaddr_to_gfn(gaddr) _gfn(paddr_to_pfn(gaddr))
> +#define gfn_to_gaddr(gfn)   pfn_to_paddr(gfn_x(gfn))
> +
>  TYPE_SAFE(unsigned long, pfn);
>  #define PRI_pfn          "05lx"
>  #define INVALID_PFN      (~0UL)

Hmm, if you want this in common code, I think this needs to be
correct from a more abstract perspective, i.e. not just for ARM
and x86. In general I don't think we can assume machine,
physical, and guest addresses to all be the same width (which
the uses above imply). IOW I think these would better stay
arch-specific, and if you want to use them in common code
you'll need to add x86 variants.

Jan
Julien Grall Aug. 22, 2017, 5:37 p.m. | #2
Hi Jan,

On 22/08/17 09:23, Jan Beulich wrote:
>>>> On 14.08.17 at 16:23, <julien.grall@arm.com> wrote:
>> --- a/xen/include/xen/mm.h
>> +++ b/xen/include/xen/mm.h
>> @@ -92,6 +92,9 @@ static inline bool_t mfn_eq(mfn_t x, mfn_t y)
>>      return mfn_x(x) == mfn_x(y);
>>  }
>>
>> +#define maddr_to_mfn(maddr) _mfn(paddr_to_pfn(maddr))
>> +#define mfn_to_maddr(mfn)   pfn_to_paddr(mfn_x(mfn))
>> +
>>  TYPE_SAFE(unsigned long, gfn);
>>  #define PRI_gfn          "05lx"
>>  #define INVALID_GFN      _gfn(~0UL)
>> @@ -130,6 +133,9 @@ static inline bool_t gfn_eq(gfn_t x, gfn_t y)
>>      return gfn_x(x) == gfn_x(y);
>>  }
>>
>> +#define gaddr_to_gfn(gaddr) _gfn(paddr_to_pfn(gaddr))
>> +#define gfn_to_gaddr(gfn)   pfn_to_paddr(gfn_x(gfn))
>> +
>>  TYPE_SAFE(unsigned long, pfn);
>>  #define PRI_pfn          "05lx"
>>  #define INVALID_PFN      (~0UL)
>
> Hmm, if you want this in common code, I think this needs to be
> correct from a more abstract perspective, i.e. not just for ARM
> and x86. In general I don't think we can assume machine,
> physical, and guest addresses to all be the same width (which
> the uses above imply). IOW I think these would better stay
> arch-specific, and if you want to use them in common code
> you'll need to add x86 variants.

I will do that.

Cheers,

Patch

diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h
index ef84b72474..28bdcc900e 100644
--- a/xen/include/asm-arm/mm.h
+++ b/xen/include/asm-arm/mm.h
@@ -207,10 +207,6 @@  static inline void __iomem *ioremap_wc(paddr_t start, size_t len)
 #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 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))
-#define maddr_to_mfn(ma)    _mfn(paddr_to_pfn(ma))
 #define vmap_to_mfn(va)     paddr_to_pfn(virt_to_maddr((vaddr_t)va))
 #define vmap_to_page(va)    mfn_to_page(vmap_to_mfn(va))
 
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 503b92e4b0..eb0409d832 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -92,6 +92,9 @@  static inline bool_t mfn_eq(mfn_t x, mfn_t y)
     return mfn_x(x) == mfn_x(y);
 }
 
+#define maddr_to_mfn(maddr) _mfn(paddr_to_pfn(maddr))
+#define mfn_to_maddr(mfn)   pfn_to_paddr(mfn_x(mfn))
+
 TYPE_SAFE(unsigned long, gfn);
 #define PRI_gfn          "05lx"
 #define INVALID_GFN      _gfn(~0UL)
@@ -130,6 +133,9 @@  static inline bool_t gfn_eq(gfn_t x, gfn_t y)
     return gfn_x(x) == gfn_x(y);
 }
 
+#define gaddr_to_gfn(gaddr) _gfn(paddr_to_pfn(gaddr))
+#define gfn_to_gaddr(gfn)   pfn_to_paddr(gfn_x(gfn))
+
 TYPE_SAFE(unsigned long, pfn);
 #define PRI_pfn          "05lx"
 #define INVALID_PFN      (~0UL)