Skip to contentSkip to conversation

x86+Arm: drop (rename) __virt_to_maddr() / __maddr_to_virt()

PATCH Superseded Jan Beulich 4 participants 9 messages Mar 5, 2024 – Mar 6, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86+Arm: drop (rename) __virt_to_maddr() / __maddr_to_virt()

There's no use of them anymore except in the definitions of the non- underscore-prefixed aliases. Rename the inline functions, adjust the virt_to_maddr() #define-e, and purge the (x86-only) maddr_to_virt() one, thus eliminating a bogus cast which would have allowed the passing of a pointer type variable into maddr_to_virt() to go silently.

xen/arch/arm/include/asm/mm.h +2 -2
@@ -256,12 +256,12 @@ static inline void __iomem *ioremap_wc(p
 /* Page-align address and convert to frame number format */
 #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
-static inline paddr_t __virt_to_maddr(vaddr_t va)
+static inline paddr_t virt_to_maddr(vaddr_t va)
 {
     uint64_t par = va_to_par(va);
     return (par & PADDR_MASK & PAGE_MASK) | (va & ~PAGE_MASK);
 }
-#define virt_to_maddr(va)   __virt_to_maddr((vaddr_t)(va))
+#define virt_to_maddr(va) virt_to_maddr((vaddr_t)(va))
 
 #ifdef CONFIG_ARM_32
 /**
xen/arch/x86/hvm/nestedhvm.c +1 -1
@@ -125,7 +125,7 @@ static int __init cf_check nestedhvm_set
     /* shadow_io_bitmaps can't be declared static because
      *   they must fulfill hw requirements (page aligned section)
      *   and doing so triggers the ASSERT(va >= XEN_VIRT_START)
-     *   in __virt_to_maddr()
+     *   in virt_to_maddr()
      *
      * So as a compromise pre-allocate them when xen boots.
      * This function must be called from within start_xen() when
xen/arch/x86/include/asm/page.h +0 -2
@@ -269,8 +269,6 @@ void scrub_page_cold(void *);
 #define mfn_valid(mfn)      __mfn_valid(mfn_x(mfn))
 #define virt_to_mfn(va)     __virt_to_mfn(va)
 #define mfn_to_virt(mfn)    __mfn_to_virt(mfn)
-#define virt_to_maddr(va)   __virt_to_maddr((unsigned long)(va))
-#define maddr_to_virt(ma)   __maddr_to_virt((unsigned long)(ma))
 #define maddr_to_page(ma)   __maddr_to_page(ma)
 #define page_to_maddr(pg)   __page_to_maddr(pg)
 #define virt_to_page(va)    __virt_to_page(va)
xen/arch/x86/include/asm/x86_64/page.h +3 -2
@@ -34,7 +34,7 @@ static inline unsigned long canonicalise
 #define pdx_to_virt(pdx) ((void *)(DIRECTMAP_VIRT_START + \
                                    ((unsigned long)(pdx) << PAGE_SHIFT)))
 
-static inline unsigned long __virt_to_maddr(unsigned long va)
+static inline unsigned long virt_to_maddr(unsigned long va)
 {
     ASSERT(va < DIRECTMAP_VIRT_END);
     if ( va >= DIRECTMAP_VIRT_START )
@@ -47,8 +47,9 @@ static inline unsigned long __virt_to_ma
 
     return xen_phys_start + va - XEN_VIRT_START;
 }
+#define virt_to_maddr(va) virt_to_maddr((unsigned long)(va))
 
-static inline void *__maddr_to_virt(unsigned long ma)
+static inline void *maddr_to_virt(unsigned long ma)
 {
     /* Offset in the direct map, accounting for pdx compression */
     unsigned long va_offset = maddr_to_directmapoff(ma);
Reviewed-by on v1 1/1
#1 lore raw

Changes looks good to me.

I'll update the RISC-V part correspondingly.

~ Oleksii

Quoted 73 lines · Jan Beulich

There's no use of them anymore except in the definitions of the non- underscore-prefixed aliases. Rename the inline functions, adjust the virt_to_maddr() #define-e, and purge the (x86-only) maddr_to_virt() one,
thus eliminating a bogus cast which would have allowed the passing of a
pointer type variable into maddr_to_virt() to go silently.

xen/arch/arm/include/asm/mm.h +0 -0
@@ -256,12 +256,12 @@ static inline void __iomem *ioremap_wc(p
  /* Page-align address and convert to frame number format */
  #define paddr_to_pfn_aligned(paddr)   
 paddr_to_pfn(PAGE_ALIGN(paddr))

xen/arch/arm/include/asm/mm.h +1 -1
-static inline paddr_t __virt_to_maddr(vaddr_t va)
+static inline paddr_t virt_to_maddr(vaddr_t va)

 {
     uint64_t par = va_to_par(va);
     return (par & PADDR_MASK & PAGE_MASK) | (va & ~PAGE_MASK); }

xen/arch/arm/include/asm/mm.h +1 -1
-#define virt_to_maddr(va)   __virt_to_maddr((vaddr_t)(va))
+#define virt_to_maddr(va) virt_to_maddr((vaddr_t)(va))


 #ifdef CONFIG_ARM_32
 /**

xen/arch/x86/hvm/nestedhvm.c +1 -1
@@ -125,7 +125,7 @@ static int __init cf_check nestedhvm_set
      /* shadow_io_bitmaps can't be declared static because
       *   they must fulfill hw requirements (page aligned section)
       *   and doing so triggers the ASSERT(va >= XEN_VIRT_START)
-     *   in __virt_to_maddr()
+     *   in virt_to_maddr()
       *
       * So as a compromise pre-allocate them when xen boots.
       * This function must be called from within start_xen() when
xen/arch/x86/include/asm/page.h +0 -2
@@ -269,8 +269,6 @@ void scrub_page_cold(void *);
  #define mfn_valid(mfn)      __mfn_valid(mfn_x(mfn))
  #define virt_to_mfn(va)     __virt_to_mfn(va)
  #define mfn_to_virt(mfn)    __mfn_to_virt(mfn)
-#define virt_to_maddr(va)   __virt_to_maddr((unsigned long)(va))
-#define maddr_to_virt(ma)   __maddr_to_virt((unsigned long)(ma))
  #define maddr_to_page(ma)   __maddr_to_page(ma)
  #define page_to_maddr(pg)   __page_to_maddr(pg)
  #define virt_to_page(va)    __virt_to_page(va)
xen/arch/x86/include/asm/x86_64/page.h +0 -0
@@ -34,7 +34,7 @@ static inline unsigned long canonicalise
  #define pdx_to_virt(pdx) ((void *)(DIRECTMAP_VIRT_START + \

                                    ((unsigned long)(pdx) << PAGE_SHIFT)))

xen/arch/x86/include/asm/x86_64/page.h +1 -1
-static inline unsigned long __virt_to_maddr(unsigned long va)
+static inline unsigned long virt_to_maddr(unsigned long va)

 {
     ASSERT(va < DIRECTMAP_VIRT_END);
     if ( va >= DIRECTMAP_VIRT_START )

xen/arch/x86/include/asm/x86_64/page.h +0 -0
@@ -47,8 +47,9 @@ static inline unsigned long __virt_to_ma


     return xen_phys_start + va - XEN_VIRT_START;
 }
+#define virt_to_maddr(va) virt_to_maddr((unsigned long)(va))

xen/arch/x86/include/asm/x86_64/page.h +1 -1
-static inline void *__maddr_to_virt(unsigned long ma)
+static inline void *maddr_to_virt(unsigned long ma)

 {
     /* Offset in the direct map, accounting for pdx compression */ unsigned long va_offset = maddr_to_directmapoff(ma);

#2 lore raw
In reply to Jan Beulich

Hi Jan,

The title is quite confusing. I would have expected the macro...

Quoted 12 lines · Jan Beulich

There's no use of them anymore except in the definitions of the non- underscore-prefixed aliases. Rename the inline functions, adjust the virt_to_maddr() #define-e, and purge the (x86-only) maddr_to_virt() one, thus eliminating a bogus cast which would have allowed the passing of a pointer type variable into maddr_to_virt() to go silently.

xen/arch/arm/include/asm/mm.h +0 -0
@@ -256,12 +256,12 @@ static inline void __iomem *ioremap_wc(p
  /* Page-align address and convert to frame number format */

xen/arch/arm/include/asm/mm.h static inline void __iomem *ioremap_wc(p · line 264

Quoted 10 lines
xen/arch/arm/include/asm/mm.h +2 -2
  #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
-static inline paddr_t __virt_to_maddr(vaddr_t va)
+static inline paddr_t virt_to_maddr(vaddr_t va)
  {
      uint64_t par = va_to_par(va);
      return (par & PADDR_MASK & PAGE_MASK) | (va & ~PAGE_MASK);
  }
-#define virt_to_maddr(va)   __virt_to_maddr((vaddr_t)(va))
+#define virt_to_maddr(va) virt_to_maddr((vaddr_t)(va))

... to be removed. But you keep it and just overload the name. I know it is not possible to remove the macro because some callers are using pointers (?). So I would rather prefer if we keep the name distinct on Arm.

Let see what the other Arm maintainers think.

Cheers,

Signature · 1 line
Julien Grall
#3 lore raw
Quoted 19 lines · Julien Grall

Hi Jan,

The title is quite confusing. I would have expected the macro...

Quoted 14 lines · Jan Beulich

There's no use of them anymore except in the definitions of the non- underscore-prefixed aliases. Rename the inline functions, adjust the virt_to_maddr() #define-e, and purge the (x86-only) maddr_to_virt() one, thus eliminating a bogus cast which would have allowed the passing of a pointer type variable into maddr_to_virt() to go silently.

xen/arch/arm/include/asm/mm.h +0 -0
@@ -256,12 +256,12 @@ static inline void __iomem *ioremap_wc(p
  /* Page-align address and convert to frame number format */
  #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
Quoted 12 lines

xen/arch/arm/include/asm/mm.h static inline void __iomem *ioremap_wc(p · line 264

Quoted 8 lines
xen/arch/arm/include/asm/mm.h +2 -2
-static inline paddr_t __virt_to_maddr(vaddr_t va)
+static inline paddr_t virt_to_maddr(vaddr_t va)
  {
      uint64_t par = va_to_par(va);
      return (par & PADDR_MASK & PAGE_MASK) | (va & ~PAGE_MASK);
  }
-#define virt_to_maddr(va)   __virt_to_maddr((vaddr_t)(va))
+#define virt_to_maddr(va) virt_to_maddr((vaddr_t)(va))

... to be removed. But you keep it and just overload the name. I know it is not possible to remove the macro because some callers are using pointers (?).

Indeed. I actually tried without, but the build fails miserably.

Quoted 3 lines

So I would rather prefer if we keep the name distinct on Arm.

Let see what the other Arm maintainers think.

Well, okay. I'm a little surprised though; I was under the impression that a goal would be to, eventually, get rid of all the __-prefixed secondary variants of this kind of helpers.

Jan

#4 lore raw

Hi Jan,

Quoted 35 lines · Jan Beulich
Quoted 19 lines · Julien Grall

Hi Jan,

The title is quite confusing. I would have expected the macro...

Quoted 14 lines · Jan Beulich

There's no use of them anymore except in the definitions of the non- underscore-prefixed aliases. Rename the inline functions, adjust the virt_to_maddr() #define-e, and purge the (x86-only) maddr_to_virt() one, thus eliminating a bogus cast which would have allowed the passing of a pointer type variable into maddr_to_virt() to go silently.

xen/arch/arm/include/asm/mm.h +0 -0
@@ -256,12 +256,12 @@ static inline void __iomem *ioremap_wc(p
   /* Page-align address and convert to frame number format */
   #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
Quoted 12 lines

xen/arch/arm/include/asm/mm.h static inline void __iomem *ioremap_wc(p · line 264

Quoted 8 lines
xen/arch/arm/include/asm/mm.h +2 -2
-static inline paddr_t __virt_to_maddr(vaddr_t va)
+static inline paddr_t virt_to_maddr(vaddr_t va)
   {
       uint64_t par = va_to_par(va);
       return (par & PADDR_MASK & PAGE_MASK) | (va & ~PAGE_MASK);
   }
-#define virt_to_maddr(va)   __virt_to_maddr((vaddr_t)(va))
+#define virt_to_maddr(va) virt_to_maddr((vaddr_t)(va))

... to be removed. But you keep it and just overload the name. I know it is not possible to remove the macro because some callers are using pointers (?).

Indeed. I actually tried without, but the build fails miserably.

Quoted 7 lines
Quoted 3 lines

So I would rather prefer if we keep the name distinct on Arm.

Let see what the other Arm maintainers think.

Well, okay. I'm a little surprised though; I was under the impression that a goal would be to, eventually, get rid of all the __-prefixed secondary variants of this kind of helpers.

Because of MISRA? If so, you would be replacing one violation by another one (duplicated name). IIRC we decided to deviate it, yet I don't particular want to use the pattern in Arm headers when there is no need.

If you are trying to solve MISRA, then I think we want to either remove the macro (not possible here) or suffix with the double-underscore the static inline helper.

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw
Quoted 42 lines · Julien Grall
Quoted 33 lines · Jan Beulich
Quoted 17 lines · Julien Grall

The title is quite confusing. I would have expected the macro...

Quoted 14 lines · Jan Beulich

There's no use of them anymore except in the definitions of the non- underscore-prefixed aliases. Rename the inline functions, adjust the virt_to_maddr() #define-e, and purge the (x86-only) maddr_to_virt() one, thus eliminating a bogus cast which would have allowed the passing of a pointer type variable into maddr_to_virt() to go silently.

xen/arch/arm/include/asm/mm.h +0 -0
@@ -256,12 +256,12 @@ static inline void __iomem *ioremap_wc(p
   /* Page-align address and convert to frame number format */
   #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
Quoted 12 lines

xen/arch/arm/include/asm/mm.h static inline void __iomem *ioremap_wc(p · line 264

Quoted 8 lines
xen/arch/arm/include/asm/mm.h +2 -2
-static inline paddr_t __virt_to_maddr(vaddr_t va)
+static inline paddr_t virt_to_maddr(vaddr_t va)
   {
       uint64_t par = va_to_par(va);
       return (par & PADDR_MASK & PAGE_MASK) | (va & ~PAGE_MASK);
   }
-#define virt_to_maddr(va)   __virt_to_maddr((vaddr_t)(va))
+#define virt_to_maddr(va) virt_to_maddr((vaddr_t)(va))

... to be removed. But you keep it and just overload the name. I know it is not possible to remove the macro because some callers are using pointers (?).

Indeed. I actually tried without, but the build fails miserably.

Quoted 7 lines
Quoted 3 lines

So I would rather prefer if we keep the name distinct on Arm.

Let see what the other Arm maintainers think.

Well, okay. I'm a little surprised though; I was under the impression that a goal would be to, eventually, get rid of all the __-prefixed secondary variants of this kind of helpers.

Quoted 7 lines

Because of MISRA? If so, you would be replacing one violation by another one (duplicated name). IIRC we decided to deviate it, yet I don't particular want to use the pattern in Arm headers when there is no need.

If you are trying to solve MISRA, then I think we want to either remove the macro (not possible here) or suffix with the double-underscore the static inline helper.

No, Misra is only secondary here. Many of these helpers come in two flavors such than one can be overridden in individual source files. That's mainly connected to type-safety being generally wanted, but not always easy to achieve without a lot of code churn. We've made quite a bit of progress there, and imo ultimately the need for two flavors of doing the same thing ought to disappear.

Jan

#6 lore raw

Hi Jan,

Quoted 51 lines · Jan Beulich
Quoted 42 lines · Julien Grall
Quoted 33 lines · Jan Beulich
Quoted 17 lines · Julien Grall

The title is quite confusing. I would have expected the macro...

Quoted 14 lines · Jan Beulich

There's no use of them anymore except in the definitions of the non- underscore-prefixed aliases. Rename the inline functions, adjust the virt_to_maddr() #define-e, and purge the (x86-only) maddr_to_virt() one, thus eliminating a bogus cast which would have allowed the passing of a pointer type variable into maddr_to_virt() to go silently.

xen/arch/arm/include/asm/mm.h +0 -0
@@ -256,12 +256,12 @@ static inline void __iomem *ioremap_wc(p
    /* Page-align address and convert to frame number format */
    #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
Quoted 12 lines

xen/arch/arm/include/asm/mm.h static inline void __iomem *ioremap_wc(p · line 264

Quoted 8 lines
xen/arch/arm/include/asm/mm.h +2 -2
-static inline paddr_t __virt_to_maddr(vaddr_t va)
+static inline paddr_t virt_to_maddr(vaddr_t va)
    {
        uint64_t par = va_to_par(va);
        return (par & PADDR_MASK & PAGE_MASK) | (va & ~PAGE_MASK);
    }
-#define virt_to_maddr(va)   __virt_to_maddr((vaddr_t)(va))
+#define virt_to_maddr(va) virt_to_maddr((vaddr_t)(va))

... to be removed. But you keep it and just overload the name. I know it is not possible to remove the macro because some callers are using pointers (?).

Indeed. I actually tried without, but the build fails miserably.

Quoted 7 lines
Quoted 3 lines

So I would rather prefer if we keep the name distinct on Arm.

Let see what the other Arm maintainers think.

Well, okay. I'm a little surprised though; I was under the impression that a goal would be to, eventually, get rid of all the __-prefixed secondary variants of this kind of helpers.

Quoted 7 lines

Because of MISRA? If so, you would be replacing one violation by another one (duplicated name). IIRC we decided to deviate it, yet I don't particular want to use the pattern in Arm headers when there is no need.

If you are trying to solve MISRA, then I think we want to either remove the macro (not possible here) or suffix with the double-underscore the static inline helper.

Quoted 6 lines

No, Misra is only secondary here. Many of these helpers come in two flavors such than one can be overridden in individual source files. That's mainly connected to type-safety being generally wanted, but not always easy to achieve without a lot of code churn. We've made quite a bit of progress there, and imo ultimately the need for two flavors of doing the same thing ought to disappear.

What about converting the static inline to a macro? As we cast 'va', I don't think we have any benefits to keep the static inline helper and provide a thin wrapper with just a cast.

This would address my concern and possibly address your wish to remove the double-underscore version.

Cheers,

Signature · 1 line
Julien Grall
#7 lore raw
Quoted 59 lines · Julien Grall
Quoted 51 lines · Jan Beulich
Quoted 42 lines · Julien Grall
Quoted 33 lines · Jan Beulich
Quoted 17 lines · Julien Grall

The title is quite confusing. I would have expected the macro...

Quoted 14 lines · Jan Beulich

There's no use of them anymore except in the definitions of the non- underscore-prefixed aliases. Rename the inline functions, adjust the virt_to_maddr() #define-e, and purge the (x86-only) maddr_to_virt() one, thus eliminating a bogus cast which would have allowed the passing of a pointer type variable into maddr_to_virt() to go silently.

xen/arch/arm/include/asm/mm.h +0 -0
@@ -256,12 +256,12 @@ static inline void __iomem *ioremap_wc(p
    /* Page-align address and convert to frame number format */
    #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
Quoted 12 lines

xen/arch/arm/include/asm/mm.h static inline void __iomem *ioremap_wc(p · line 264

Quoted 8 lines
xen/arch/arm/include/asm/mm.h +2 -2
-static inline paddr_t __virt_to_maddr(vaddr_t va)
+static inline paddr_t virt_to_maddr(vaddr_t va)
    {
        uint64_t par = va_to_par(va);
        return (par & PADDR_MASK & PAGE_MASK) | (va & ~PAGE_MASK);
    }
-#define virt_to_maddr(va)   __virt_to_maddr((vaddr_t)(va))
+#define virt_to_maddr(va) virt_to_maddr((vaddr_t)(va))

... to be removed. But you keep it and just overload the name. I know it is not possible to remove the macro because some callers are using pointers (?).

Indeed. I actually tried without, but the build fails miserably.

Quoted 7 lines
Quoted 3 lines

So I would rather prefer if we keep the name distinct on Arm.

Let see what the other Arm maintainers think.

Well, okay. I'm a little surprised though; I was under the impression that a goal would be to, eventually, get rid of all the __-prefixed secondary variants of this kind of helpers.

Quoted 7 lines

Because of MISRA? If so, you would be replacing one violation by another one (duplicated name). IIRC we decided to deviate it, yet I don't particular want to use the pattern in Arm headers when there is no need.

If you are trying to solve MISRA, then I think we want to either remove the macro (not possible here) or suffix with the double-underscore the static inline helper.

Quoted 6 lines

No, Misra is only secondary here. Many of these helpers come in two flavors such than one can be overridden in individual source files. That's mainly connected to type-safety being generally wanted, but not always easy to achieve without a lot of code churn. We've made quite a bit of progress there, and imo ultimately the need for two flavors of doing the same thing ought to disappear.

Quoted 6 lines

What about converting the static inline to a macro? As we cast 'va', I don't think we have any benefits to keep the static inline helper and provide a thin wrapper with just a cast.

This would address my concern and possibly address your wish to remove the double-underscore version.

Hmm, I didn't even think in that direction, seeing that generally we aim at moving from macros to inline functions. But yes, if converting to a macro is acceptable, that'll be what I do in v2 then.

Jan

#8 lore raw
In reply to Julien Grall
Quoted 34 lines · Julien Grall

Hi Jan,

The title is quite confusing. I would have expected the macro...

Quoted 12 lines · Jan Beulich

There's no use of them anymore except in the definitions of the non- underscore-prefixed aliases. Rename the inline functions, adjust the virt_to_maddr() #define-e, and purge the (x86-only) maddr_to_virt() one, thus eliminating a bogus cast which would have allowed the passing of a pointer type variable into maddr_to_virt() to go silently.

xen/arch/arm/include/asm/mm.h +0 -0
@@ -256,12 +256,12 @@ static inline void __iomem *ioremap_wc(p
  /* Page-align address and convert to frame number format */

xen/arch/arm/include/asm/mm.h static inline void __iomem *ioremap_wc(p · line 264

Quoted 10 lines
xen/arch/arm/include/asm/mm.h +2 -2
  #define paddr_to_pfn_aligned(paddr)    paddr_to_pfn(PAGE_ALIGN(paddr))
 
-static inline paddr_t __virt_to_maddr(vaddr_t va)
+static inline paddr_t virt_to_maddr(vaddr_t va)
  {
      uint64_t par = va_to_par(va);
      return (par & PADDR_MASK & PAGE_MASK) | (va & ~PAGE_MASK);
  }
-#define virt_to_maddr(va)   __virt_to_maddr((vaddr_t)(va))
+#define virt_to_maddr(va) virt_to_maddr((vaddr_t)(va))

... to be removed. But you keep it and just overload the name. I know it is not possible to remove the macro because some callers are using pointers (?). So I would rather prefer if we keep the name distinct on Arm.

Quoted 1 line

Let see what the other Arm maintainers think.

I share the same opinion. If it's about double underscores that violates MISRA rule, I think we deviated it the same way we deviated unique identifiers (IIRC).

~Michal