2024-03-08 07:46:35

by Max Kellermann

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Max Kellermann <[email protected]>
---
arch/loongarch/include/asm/page.h | 3 +++
arch/loongarch/include/asm/pgtable.h | 3 ---
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/loongarch/include/asm/page.h b/arch/loongarch/include/asm/page.h
index afb6fa16b826..44027060c54a 100644
--- a/arch/loongarch/include/asm/page.h
+++ b/arch/loongarch/include/asm/page.h
@@ -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) \
diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h
index 8b5df1bbf9e9..af3acdf3481a 100644
--- a/arch/loongarch/include/asm/pgtable.h
+++ b/arch/loongarch/include/asm/pgtable.h
@@ -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



2024-03-10 01:14:51

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH] loongarch/pgtable.h: move {dmw,tlb}_virt_to_page() to page.h

Hi, Max,

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

Huacai

On Fri, Mar 8, 2024 at 3:46 PM Max Kellermann <max.kellermann@ionoscom> wrote:
>
> 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.
>
> Signed-off-by: Max Kellermann <[email protected]>
> ---
> arch/loongarch/include/asm/page.h | 3 +++
> arch/loongarch/include/asm/pgtable.h | 3 ---
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/loongarch/include/asm/page.h b/arch/loongarch/include/asm/page.h
> index afb6fa16b826..44027060c54a 100644
> --- a/arch/loongarch/include/asm/page.h
> +++ b/arch/loongarch/include/asm/page.h
> @@ -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) \
> diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h
> index 8b5df1bbf9e9..af3acdf3481a 100644
> --- a/arch/loongarch/include/asm/pgtable.h
> +++ b/arch/loongarch/include/asm/pgtable.h
> @@ -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
>
>

2024-03-10 10:22:40

by Max Kellermann

[permalink] [raw]
Subject: Re: [PATCH] loongarch/pgtable.h: move {dmw,tlb}_virt_to_page() to page.h

On Sun, Mar 10, 2024 at 2:14 AM Huacai Chen <[email protected]> wrote:
> 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


Attachments:
.config (143.97 kB)

2024-03-10 14:03:54

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH] loongarch/pgtable.h: move {dmw,tlb}_virt_to_page() to page.h

Hi, Max,

On Sun, Mar 10, 2024 at 6:22 PM Max Kellermann <[email protected]> wrote:
>
> On Sun, Mar 10, 2024 at 2:14 AM Huacai Chen <[email protected]> wrote:
> > 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

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