Skip to contentSkip to conversation

loongarch/pgtable.h: move {dmw,tlb}_virt_to_page() to page.h

PATCH In review Max Kellermann 2 participants 4 messages Mar 8, 2024 – Mar 10, 2024 LoongArch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 loongarch/pgtable.h: move {dmw,tlb}_virt_to_page() to page.h

These functions are implemented in pgtable.c, and they are needed only by the virt_to_pfn() macro in page.h. Having the prototypes in pgtable.h causes a circular dependency between page.h and pgtable.h, because page.h's virt_to_pfn() needs pgtable.h for these two functions, and pgtable.h needs various definitions from page.h (e.g. pte_t and pgt_t).

I suggest avoiding this circular dependency by moving the function prototypes to page.h, even though that is slightly incorrect, because they are not implemented in page.c but pgtable.c, but it's the simplest possible solution to this problem and the functions not used anywhere else.

---
 arch/loongarch/include/asm/page.h    | 3 +++
 arch/loongarch/include/asm/pgtable.h | 3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/loongarch/include/asm/page.h +3 -0
index afb6fa16b826..44027060c54a 100644
@@ -75,6 +75,9 @@ typedef struct { unsigned long pgprot; } pgprot_t;
 #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
 #define sym_to_pfn(x)		__phys_to_pfn(__pa_symbol(x))
 
+struct page *dmw_virt_to_page(unsigned long kaddr);
+struct page *tlb_virt_to_page(unsigned long kaddr);
+
 #define virt_to_pfn(kaddr)	PFN_DOWN(PHYSADDR(kaddr))
 
 #define virt_to_page(kaddr)								\
arch/loongarch/include/asm/pgtable.h +0 -3
index 8b5df1bbf9e9..af3acdf3481a 100644
@@ -363,9 +363,6 @@ static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *pt
 extern pgd_t swapper_pg_dir[];
 extern pgd_t invalid_pg_dir[];
 
-struct page *dmw_virt_to_page(unsigned long kaddr);
-struct page *tlb_virt_to_page(unsigned long kaddr);
-
 /*
  * The following only work if pte_present() is true.
  * Undefined behaviour if not..
Signature · 1 line
2.39.2
maintainer
#1 lore raw

Hi, Max,

Could you please share what kind of configuration will cause a build error?

Huacai

Quoted 52 lines · Max Kellermann

These functions are implemented in pgtable.c, and they are needed only by the virt_to_pfn() macro in page.h. Having the prototypes in pgtable.h causes a circular dependency between page.h and pgtable.h, because page.h's virt_to_pfn() needs pgtable.h for these two functions, and pgtable.h needs various definitions from page.h (e.g. pte_t and pgt_t).

I suggest avoiding this circular dependency by moving the function prototypes to page.h, even though that is slightly incorrect, because they are not implemented in page.c but pgtable.c, but it's the simplest possible solution to this problem and the functions not used anywhere else.

---
 arch/loongarch/include/asm/page.h    | 3 +++
 arch/loongarch/include/asm/pgtable.h | 3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/loongarch/include/asm/page.h +3 -0
index afb6fa16b826..44027060c54a 100644
@@ -75,6 +75,9 @@ typedef struct { unsigned long pgprot; } pgprot_t;
 #define pfn_to_kaddr(pfn)      __va((pfn) << PAGE_SHIFT)
 #define sym_to_pfn(x)          __phys_to_pfn(__pa_symbol(x))
 
+struct page *dmw_virt_to_page(unsigned long kaddr);
+struct page *tlb_virt_to_page(unsigned long kaddr);
+
 #define virt_to_pfn(kaddr)     PFN_DOWN(PHYSADDR(kaddr))
 
 #define virt_to_page(kaddr)                                                            \
arch/loongarch/include/asm/pgtable.h +0 -4
index 8b5df1bbf9e9..af3acdf3481a 100644
@@ -363,9 +363,6 @@ static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *pt
 extern pgd_t swapper_pg_dir[];
 extern pgd_t invalid_pg_dir[];
 
-struct page *dmw_virt_to_page(unsigned long kaddr);
-struct page *tlb_virt_to_page(unsigned long kaddr);
-
 /*
  * The following only work if pte_present() is true.
  * Undefined behaviour if not..
--

2.39.2

#2 lore raw
Quoted 1 line · Huacai Chen

Could you please share what kind of configuration will cause a build error?

With the current kernel, I found none; the problem is masked currently due to the current order of include directives, but it caused problems during my attempts to clean up linux/mm.h - see
https://lore.kernel.org/lkml/[email protected]/
for the most recent submission; a later (not-yet-submitted) version of the series which reproduces the problem can be found here:
https://github.com/MaxKellermann/linux/commits/mm.h/

I saw this problem with "randconfig KCONFIG_SEED=0x5D8A9172" - config attached.

Max

maintainer
#3 lore raw

Hi, Max,

Quoted 11 lines · Max Kellermann
Quoted 1 line · Huacai Chen

Could you please share what kind of configuration will cause a build error?

With the current kernel, I found none; the problem is masked currently due to the current order of include directives, but it caused problems during my attempts to clean up linux/mm.h - see
https://lore.kernel.org/lkml/[email protected]/
for the most recent submission; a later (not-yet-submitted) version of the series which reproduces the problem can be found here:
https://github.com/MaxKellermann/linux/commits/mm.h/

OK, I will apply this patch if no one has objections.

Huacai

Quoted 4 lines

I saw this problem with "randconfig KCONFIG_SEED=0x5D8A9172" - config attached.

Max