Skip to contentSkip to conversation

riscv: fix the global name pfn_base confliction error

PATCH Superseded Kenneth Lee 4 participants 8 messages Jul 28, 2021 1 message not in the archive RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: fix the global name pfn_base confliction error

From: Kenneth Lee <[email protected]>

RISCV use a global variable pfn_base for page/pfn translation. But this is a common name and will be used elsewhere. In those case, the page-pfn macro which refer this name will refer to the local/input variable of those function (such as in vfio_pin_pages_remote). This make everything wrong.

This patch change the name from pfn_base to riscv_global_pfn_base to fix this problem

---
 arch/riscv/include/asm/page.h | 4 ++--
 arch/riscv/mm/init.c          | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/include/asm/page.h +2 -2
index cca8764aed83..8711e415f37c 100644
@@ -79,8 +79,8 @@ typedef struct page *pgtable_t;
 #endif
 
 #ifdef CONFIG_MMU
-extern unsigned long pfn_base;
-#define ARCH_PFN_OFFSET		(pfn_base)
+extern unsigned long riscv_global_pfn_base;
+#define ARCH_PFN_OFFSET		(riscv_global_pfn_base)
 #else
 #define ARCH_PFN_OFFSET		(PAGE_OFFSET >> PAGE_SHIFT)
 #endif /* CONFIG_MMU */
arch/riscv/mm/init.c +3 -3
index a14bf3910eec..2ce4e9a46ca0 100644
@@ -228,8 +228,8 @@ static struct pt_alloc_ops _pt_ops __initdata;
 #define pt_ops _pt_ops
 #endif
 
-unsigned long pfn_base __ro_after_init;
-EXPORT_SYMBOL(pfn_base);
+unsigned long riscv_global_pfn_base __ro_after_init;
+EXPORT_SYMBOL(riscv_global_pfn_base);
 
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
 pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
@@ -572,7 +572,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
 	kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr;
 #endif
 
-	pfn_base = PFN_DOWN(kernel_map.phys_addr);
+	riscv_global_pfn_base = PFN_DOWN(kernel_map.phys_addr);
 
 	/*
 	 * Enforce boot alignment requirements of RV32 and
Signature · 1 line
2.25.1
#1 lore raw
Quoted 9 lines · Kenneth Lee

From: Kenneth Lee <[email protected]>

RISCV use a global variable pfn_base for page/pfn translation. But this is a common name and will be used elsewhere. In those case, the page-pfn macro which refer this name will refer to the local/input variable of those function (such as in vfio_pin_pages_remote). This make everything wrong.

This patch change the name from pfn_base to riscv_global_pfn_base to fix

I think global is excessive, just riscv_pfn_base should be ok for proper namespacing.

Quoted 50 lines

this problem

---
 arch/riscv/include/asm/page.h | 4 ++--
 arch/riscv/mm/init.c          | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/include/asm/page.h +2 -2
index cca8764aed83..8711e415f37c 100644
@@ -79,8 +79,8 @@ typedef struct page *pgtable_t;
 #endif
 
 #ifdef CONFIG_MMU
-extern unsigned long pfn_base;
-#define ARCH_PFN_OFFSET		(pfn_base)
+extern unsigned long riscv_global_pfn_base;
+#define ARCH_PFN_OFFSET		(riscv_global_pfn_base)
 #else
 #define ARCH_PFN_OFFSET		(PAGE_OFFSET >> PAGE_SHIFT)
 #endif /* CONFIG_MMU */
arch/riscv/mm/init.c +3 -3
index a14bf3910eec..2ce4e9a46ca0 100644
@@ -228,8 +228,8 @@ static struct pt_alloc_ops _pt_ops __initdata;
 #define pt_ops _pt_ops
 #endif
 
-unsigned long pfn_base __ro_after_init;
-EXPORT_SYMBOL(pfn_base);
+unsigned long riscv_global_pfn_base __ro_after_init;
+EXPORT_SYMBOL(riscv_global_pfn_base);
 
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
 pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
@@ -572,7 +572,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
 	kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr;
 #endif
 
-	pfn_base = PFN_DOWN(kernel_map.phys_addr);
+	riscv_global_pfn_base = PFN_DOWN(kernel_map.phys_addr);
 
 	/*
 	 * Enforce boot alignment requirements of RV32 and
Signature · 1 line
2.25.1
Signature · 2 lines
Sincerely yours,
Mike.
author
#2 lore raw

indeed. I'll send a new one.

Quoted 69 lines · Mike Rapoport
Quoted 9 lines · Kenneth Lee

From: Kenneth Lee <[email protected]>

RISCV use a global variable pfn_base for page/pfn translation. But this is a common name and will be used elsewhere. In those case, the page-pfn macro which refer this name will refer to the local/input variable of those function (such as in vfio_pin_pages_remote). This make everything wrong.

This patch change the name from pfn_base to riscv_global_pfn_base to fix

I think global is excessive, just riscv_pfn_base should be ok for proper namespacing.

Quoted 48 lines

this problem

---
 arch/riscv/include/asm/page.h | 4 ++--
 arch/riscv/mm/init.c          | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/include/asm/page.h +2 -2
index cca8764aed83..8711e415f37c 100644
@@ -79,8 +79,8 @@ typedef struct page *pgtable_t;
 #endif
 
 #ifdef CONFIG_MMU
-extern unsigned long pfn_base;
-#define ARCH_PFN_OFFSET              (pfn_base)
+extern unsigned long riscv_global_pfn_base;
+#define ARCH_PFN_OFFSET              (riscv_global_pfn_base)
 #else
 #define ARCH_PFN_OFFSET              (PAGE_OFFSET >> PAGE_SHIFT)
 #endif /* CONFIG_MMU */
arch/riscv/mm/init.c +3 -4
index a14bf3910eec..2ce4e9a46ca0 100644
@@ -228,8 +228,8 @@ static struct pt_alloc_ops _pt_ops __initdata;
 #define pt_ops _pt_ops
 #endif
 
-unsigned long pfn_base __ro_after_init;
-EXPORT_SYMBOL(pfn_base);
+unsigned long riscv_global_pfn_base __ro_after_init;
+EXPORT_SYMBOL(riscv_global_pfn_base);
 
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
 pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
@@ -572,7 +572,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
      kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr;
 #endif
 
-     pfn_base = PFN_DOWN(kernel_map.phys_addr);
+     riscv_global_pfn_base = PFN_DOWN(kernel_map.phys_addr);
 
      /*
       * Enforce boot alignment requirements of RV32 and
--
Quoted 2 lines

2.25.1

--
Sincerely yours,
Mike.

#3 lore raw
In reply to Kenneth Lee
Quoted 37 lines · Kenneth Lee

From: Kenneth Lee <[email protected]>

RISCV use a global variable pfn_base for page/pfn translation. But this is a common name and will be used elsewhere. In those case, the page-pfn macro which refer this name will refer to the local/input variable of those function (such as in vfio_pin_pages_remote). This make everything wrong.

This patch change the name from pfn_base to riscv_global_pfn_base to fix this problem

---
  arch/riscv/include/asm/page.h | 4 ++--
  arch/riscv/mm/init.c          | 6 +++---
  2 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/include/asm/page.h +2 -2
index cca8764aed83..8711e415f37c 100644
@@ -79,8 +79,8 @@ typedef struct page *pgtable_t;
  #endif
 
  #ifdef CONFIG_MMU
-extern unsigned long pfn_base;
-#define ARCH_PFN_OFFSET		(pfn_base)
+extern unsigned long riscv_global_pfn_base;
+#define ARCH_PFN_OFFSET		(riscv_global_pfn_base)
  #else
  #define ARCH_PFN_OFFSET		(PAGE_OFFSET >> PAGE_SHIFT)
  #endif /* CONFIG_MMU */
arch/riscv/mm/init.c +0 -0
index a14bf3910eec..2ce4e9a46ca0 100644

arch/riscv/mm/init.c static struct pt_alloc_ops _pt_ops __initdata; · line 232

Quoted 7 lines
arch/riscv/mm/init.c +2 -2
@@ -228,8 +228,8 @@ static struct pt_alloc_ops _pt_ops __initdata;
  #define pt_ops _pt_ops
  #endif
 
-unsigned long pfn_base __ro_after_init;
-EXPORT_SYMBOL(pfn_base);
+unsigned long riscv_global_pfn_base __ro_after_init;
+EXPORT_SYMBOL(riscv_global_pfn_base);

Just nit: I didn't see any driver in kernel refers to the riscv_global_pfn_base, can we just remove the EXPORT_SYMBOL()?

Thanks
Hanjun

#4 lore raw
Quoted 38 lines · Hanjun Guo
Quoted 37 lines · Kenneth Lee

From: Kenneth Lee <[email protected]>

RISCV use a global variable pfn_base for page/pfn translation. But this is a common name and will be used elsewhere. In those case, the page-pfn macro which refer this name will refer to the local/input variable of those function (such as in vfio_pin_pages_remote). This make everything wrong.

This patch change the name from pfn_base to riscv_global_pfn_base to fix this problem

---
  arch/riscv/include/asm/page.h | 4 ++--
  arch/riscv/mm/init.c          | 6 +++---

  2 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/include/asm/page.h +2 -2
index cca8764aed83..8711e415f37c 100644
@@ -79,8 +79,8 @@ typedef struct page *pgtable_t;
   #endif
   #ifdef CONFIG_MMU
-extern unsigned long pfn_base;
-#define ARCH_PFN_OFFSET        (pfn_base)
+extern unsigned long riscv_global_pfn_base;
+#define ARCH_PFN_OFFSET        (riscv_global_pfn_base)
   #else
   #define ARCH_PFN_OFFSET        (PAGE_OFFSET >> PAGE_SHIFT)
   #endif /* CONFIG_MMU */
arch/riscv/mm/init.c +0 -0
index a14bf3910eec..2ce4e9a46ca0 100644
@@ -228,8 +228,8 @@ static struct pt_alloc_ops _pt_ops __initdata;
   #define pt_ops _pt_ops
Quoted 8 lines

arch/riscv/mm/init.c static struct pt_alloc_ops _pt_ops __initdata; · line 232

Quoted 5 lines
arch/riscv/mm/init.c +2 -2
   #endif
-unsigned long pfn_base __ro_after_init;
-EXPORT_SYMBOL(pfn_base);
+unsigned long riscv_global_pfn_base __ro_after_init;
+EXPORT_SYMBOL(riscv_global_pfn_base);

Just nit: I didn't see any driver in kernel refers to the riscv_global_pfn_base, can we just remove the EXPORT_SYMBOL()?

Sorry, I'm wrong, will be used by ARCH_PFN_OFFSET...

reviewer
#5 lore raw
In reply to Kenneth Lee

Hi Kenneth,

Le 28/07/2021 à 08:43, Kenneth Lee a écrit :

Quoted 10 lines

From: Kenneth Lee <[email protected]>

RISCV use a global variable pfn_base for page/pfn translation. But this is a common name and will be used elsewhere. In those case, the page-pfn macro which refer this name will refer to the local/input variable of those function (such as in vfio_pin_pages_remote). This make everything wrong.

This patch change the name from pfn_base to riscv_global_pfn_base to fix this problem

What about removing this variable entirely and using PFN_DOWN(kernel_map.phys_addr) directly in ARCH_PFN_OFFSET definition? That would remove code from mm/init.c, which is nice :)

Thanks,

Alex

Quoted 47 lines
---
  arch/riscv/include/asm/page.h | 4 ++--
  arch/riscv/mm/init.c          | 6 +++---
  2 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/include/asm/page.h +2 -2
index cca8764aed83..8711e415f37c 100644
@@ -79,8 +79,8 @@ typedef struct page *pgtable_t;
  #endif
 
  #ifdef CONFIG_MMU
-extern unsigned long pfn_base;
-#define ARCH_PFN_OFFSET		(pfn_base)
+extern unsigned long riscv_global_pfn_base;
+#define ARCH_PFN_OFFSET		(riscv_global_pfn_base)
  #else
  #define ARCH_PFN_OFFSET		(PAGE_OFFSET >> PAGE_SHIFT)
  #endif /* CONFIG_MMU */
arch/riscv/mm/init.c +3 -3
index a14bf3910eec..2ce4e9a46ca0 100644
@@ -228,8 +228,8 @@ static struct pt_alloc_ops _pt_ops __initdata;
  #define pt_ops _pt_ops
  #endif
 
-unsigned long pfn_base __ro_after_init;
-EXPORT_SYMBOL(pfn_base);
+unsigned long riscv_global_pfn_base __ro_after_init;
+EXPORT_SYMBOL(riscv_global_pfn_base);
 
  pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
  pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
@@ -572,7 +572,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
  	kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr;
  #endif
 
-	pfn_base = PFN_DOWN(kernel_map.phys_addr);
+	riscv_global_pfn_base = PFN_DOWN(kernel_map.phys_addr);
 
  	/*
  	 * Enforce boot alignment requirements of RV32 and

A message that is not in the archive (sent off-list or not yet received): CA+CqrBQPou5QuYfHUYzbe7j2AUPpmBQs1HQJgjJo5QtF51LmXw@mail.gmail.com

reviewer
#7 lore raw

Le 28/07/2021 à 09:33, Lee Ken a écrit :

Quoted 68 lines · Alex Ghiti
Quoted 67 lines

Hi Kenneth,

Quoted 10 lines · Kenneth Lee

From: Kenneth Lee <[email protected]>

RISCV use a global variable pfn_base for page/pfn translation. But this is a common name and will be used elsewhere. In those case, the page-pfn macro which refer this name will refer to the local/input variable of those function (such as in vfio_pin_pages_remote). This make everything wrong.

This patch change the name from pfn_base to riscv_global_pfn_base to fix this problem

What about removing this variable entirely and using PFN_DOWN(kernel_map.phys_addr) directly in ARCH_PFN_OFFSET definition? That would remove code from mm/init.c, which is nice :)

Thanks,

Alex

Quoted 44 lines
---
   arch/riscv/include/asm/page.h | 4 ++--
   arch/riscv/mm/init.c          | 6 +++---
   2 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/include/asm/page.h +2 -2
index cca8764aed83..8711e415f37c 100644
@@ -79,8 +79,8 @@ typedef struct page *pgtable_t;
   #endif
 
   #ifdef CONFIG_MMU
-extern unsigned long pfn_base;
-#define ARCH_PFN_OFFSET              (pfn_base)
+extern unsigned long riscv_global_pfn_base;
+#define ARCH_PFN_OFFSET              (riscv_global_pfn_base)
   #else
   #define ARCH_PFN_OFFSET             (PAGE_OFFSET >> PAGE_SHIFT)
   #endif /* CONFIG_MMU */
arch/riscv/mm/init.c +3 -3
index a14bf3910eec..2ce4e9a46ca0 100644
@@ -228,8 +228,8 @@ static struct pt_alloc_ops _pt_ops __initdata;
   #define pt_ops _pt_ops
   #endif
 
-unsigned long pfn_base __ro_after_init;
-EXPORT_SYMBOL(pfn_base);
+unsigned long riscv_global_pfn_base __ro_after_init;
+EXPORT_SYMBOL(riscv_global_pfn_base);
 
   pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
   pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
@@ -572,7 +572,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
       kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr;
   #endif
 
-     pfn_base = PFN_DOWN(kernel_map.phys_addr);
+     riscv_global_pfn_base = PFN_DOWN(kernel_map.phys_addr);
 
Quoted 9 lines
Quoted 3 lines

arch/riscv/mm/init.c asmlinkage void __init setup_vm(uintptr_t dtb_pa) · line 578

Quoted 3 lines
arch/riscv/mm/init.c +0 -0
       /*
        * Enforce boot alignment requirements of RV32 and

Yes. It is a choice. But I think it is the choice of the maintainer of the module. He should have a full consideration on how to expose the interface. I'm now just working for VFIO enablement in RISCV. It is not wise to be trapped into this;)

I think there is a misunderstanding, I suggested to do the following to get rid of pfn_base entirely:

arch/riscv/include/asm/page.h +1 -2
index adf5b4671684..8afb3db61eb0 100644
@@ -79,8 +79,7 @@ typedef struct page *pgtable_t;
 #endif
 
 #ifdef CONFIG_MMU
-extern unsigned long pfn_base;
-#define ARCH_PFN_OFFSET                (pfn_base)
+#define ARCH_PFN_OFFSET                (PFN_DOWN(kernel_map.phys_addr))
 #else
 #define ARCH_PFN_OFFSET                (PAGE_OFFSET >> PAGE_SHIFT)
 #endif /* CONFIG_MMU */
arch/riscv/mm/init.c +0 -3
index c9a6362d8c7f..c51f0da03a62 100644
@@ -211,9 +211,6 @@ static void __init setup_bootmem(void)
 #ifdef CONFIG_MMU
 static struct pt_alloc_ops pt_ops __initdata;
 
-unsigned long pfn_base __ro_after_init;
-EXPORT_SYMBOL(pfn_base);
-
 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
 pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
 extern pte_t fixmap_pte[PTRS_PER_PTE];// __page_aligned_bss;
@@ -608,8 +605,6 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
        kernel_map.va_pa_offset = PAGE_OFFSET - kernel_map.phys_addr;
        kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - 

kernel_map.phys_addr;

- pfn_base = PFN_DOWN(kernel_map.phys_addr);
-

        /* Sanity check alignment and size */
        BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
        BUG_ON((kernel_map.phys_addr % PMD_SIZE) != 0);
#8 lore raw
In reply to Alex Ghiti
Quoted 11 lines · Alex Ghiti

Hi Kenneth,

Le 28/07/2021 à 08:43, Kenneth Lee a écrit :

Quoted 8 lines

From: Kenneth Lee <[email protected]>

RISCV use a global variable pfn_base for page/pfn translation. But this is a common name and will be used elsewhere. In those case, the page-pfn macro which refer this name will refer to the local/input variable of those function (such as in vfio_pin_pages_remote). This make everything wrong.

Quoted 6 lines
Quoted 2 lines

This patch change the name from pfn_base to riscv_global_pfn_base to fix this problem

What about removing this variable entirely and using PFN_DOWN(kernel_map.phys_addr) directly in ARCH_PFN_OFFSET definition? That would remove code from mm/init.c, which is nice :)

That would be nice, but such change would also change the generated code. Probably nothing important, but someone would have to at least check what size and bloat-o-meter say.

Quoted 46 lines

Thanks,

Alex

Quoted 42 lines
---
  arch/riscv/include/asm/page.h | 4 ++--
  arch/riscv/mm/init.c          | 6 +++---
  2 files changed, 5 insertions(+), 5 deletions(-)
arch/riscv/include/asm/page.h +2 -2
index cca8764aed83..8711e415f37c 100644
@@ -79,8 +79,8 @@ typedef struct page *pgtable_t;
  #endif
  #ifdef CONFIG_MMU
-extern unsigned long pfn_base;
-#define ARCH_PFN_OFFSET		(pfn_base)
+extern unsigned long riscv_global_pfn_base;
+#define ARCH_PFN_OFFSET		(riscv_global_pfn_base)
  #else
  #define ARCH_PFN_OFFSET		(PAGE_OFFSET >> PAGE_SHIFT)
  #endif /* CONFIG_MMU */
arch/riscv/mm/init.c +3 -3
index a14bf3910eec..2ce4e9a46ca0 100644
@@ -228,8 +228,8 @@ static struct pt_alloc_ops _pt_ops __initdata;
  #define pt_ops _pt_ops
  #endif
-unsigned long pfn_base __ro_after_init;
-EXPORT_SYMBOL(pfn_base);
+unsigned long riscv_global_pfn_base __ro_after_init;
+EXPORT_SYMBOL(riscv_global_pfn_base);
  pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
  pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
@@ -572,7 +572,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
  	kernel_map.va_kernel_pa_offset = kernel_map.virt_addr - kernel_map.phys_addr;
  #endif
-	pfn_base = PFN_DOWN(kernel_map.phys_addr);
+	riscv_global_pfn_base = PFN_DOWN(kernel_map.phys_addr);
  	/*
  	 * Enforce boot alignment requirements of RV32 and
 
Signature · 2 lines
Sincerely yours,
Mike.