Hi, Andrew, Please drop this patch temporary because I applied another Bibo's patch which causes conflict in linux-next: https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson.git/commit/?h=loongarch-next&id=15832255e84494853f543b4c70ced50afc403067 That patch is urgent and should be merged in 6.12 as soon as possible, while this refactoring patch is in mm-unstable and target for 6.13. Bibo will update this patch to V2 later. Thanks. Huacai On Tue, Oct 15, 2024 at 11:00 AM maobibo <maobibo@xxxxxxxxxxx> wrote: > > > > On 2024/10/15 上午10:20, Huacai Chen wrote: > > Hi, Andrew, > > > > On Tue, Oct 15, 2024 at 4:12 AM Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote: > >> > >> > >> The patch titled > >> Subject: mm: define general function pXd_init() > >> has been added to the -mm mm-unstable branch. Its filename is > >> mm-define-general-function-pxd_init.patch > >> > >> This patch will shortly appear at > >> https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-define-general-function-pxd_init.patch > >> > >> This patch will later appear in the mm-unstable branch at > >> git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm > >> > >> Before you just go and hit "reply", please: > >> a) Consider who else should be cc'ed > >> b) Prefer to cc a suitable mailing list as well > >> c) Ideally: find the original patch on the mailing list and do a > >> reply-to-all to that, adding suitable additional cc's > >> > >> *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** > >> > >> The -mm tree is included into linux-next via the mm-everything > >> branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm > >> and is updated there every 2-3 working days > >> > >> ------------------------------------------------------ > >> From: Bibo Mao <maobibo@xxxxxxxxxxx> > >> Subject: mm: define general function pXd_init() > >> Date: Fri, 11 Oct 2024 17:33:18 +0800 > >> > >> pmd_init() and pud_init() are duplicated defined in file kasan.c and > >> sparse-vmemmap.c as weak functions. Move them to generic header file > >> pgtable.h, architecture can redefine them. > >> > >> Link: https://lkml.kernel.org/r/20241011093318.519432-1-maobibo@xxxxxxxxxxx > >> Signed-off-by: Bibo Mao <maobibo@xxxxxxxxxxx> > >> Cc: Alexander Potapenko <glider@xxxxxxxxxx> > >> Cc: Andrey Konovalov <andreyknvl@xxxxxxxxx> > >> Cc: Andrey Ryabinin <ryabinin.a.a@xxxxxxxxx> > >> Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx> > >> Cc: Huacai Chen <chenhuacai@xxxxxxxxxx> > >> Cc: Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx> > >> Cc: Vincenzo Frascino <vincenzo.frascino@xxxxxxx> > >> Cc: WANG Xuerui <kernel@xxxxxxxxxx> > >> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> > >> --- > >> > >> arch/loongarch/include/asm/pgtable.h | 2 ++ > >> arch/mips/include/asm/pgtable-64.h | 2 ++ > >> include/linux/mm.h | 2 -- > >> include/linux/pgtable.h | 14 ++++++++++++++ > >> mm/kasan/init.c | 8 -------- > >> mm/sparse-vmemmap.c | 8 -------- > >> 6 files changed, 18 insertions(+), 18 deletions(-) > >> > >> --- a/arch/loongarch/include/asm/pgtable.h~mm-define-general-function-pxd_init > >> +++ a/arch/loongarch/include/asm/pgtable.h > >> @@ -267,7 +267,9 @@ extern void set_pmd_at(struct mm_struct > >> * Initialize a new pgd / pud / pmd table with invalid pointers. > >> */ > >> extern void pgd_init(void *addr); > >> +#define pud_init pud_init > >> extern void pud_init(void *addr); > >> +#define pmd_init pmd_init > >> extern void pmd_init(void *addr); > >> > >> /* > >> --- a/arch/mips/include/asm/pgtable-64.h~mm-define-general-function-pxd_init > >> +++ a/arch/mips/include/asm/pgtable-64.h > >> @@ -316,7 +316,9 @@ static inline pmd_t *pud_pgtable(pud_t p > >> * Initialize a new pgd / pud / pmd table with invalid pointers. > >> */ > >> extern void pgd_init(void *addr); > >> +#define pud_init pud_init > >> extern void pud_init(void *addr); > >> +#define pmd_init pmd_init > >> extern void pmd_init(void *addr); > >> > >> /* > >> --- a/include/linux/mm.h~mm-define-general-function-pxd_init > >> +++ a/include/linux/mm.h > >> @@ -3821,8 +3821,6 @@ void *sparse_buffer_alloc(unsigned long > >> struct page * __populate_section_memmap(unsigned long pfn, > >> unsigned long nr_pages, int nid, struct vmem_altmap *altmap, > >> struct dev_pagemap *pgmap); > >> -void pmd_init(void *addr); > >> -void pud_init(void *addr); > >> pgd_t *vmemmap_pgd_populate(unsigned long addr, int node); > >> p4d_t *vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node); > >> pud_t *vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node); > >> --- a/include/linux/pgtable.h~mm-define-general-function-pxd_init > >> +++ a/include/linux/pgtable.h > >> @@ -90,6 +90,20 @@ static inline unsigned long pud_index(un > >> #define pgd_index(a) (((a) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1)) > >> #endif > >> > >> +#ifndef pmd_init > >> +static inline void pmd_init(void *addr) > >> +{ > >> +} > >> +#define pmd_init pmd_init > >> +#endif > >> + > >> +#ifndef pud_init > >> +static inline void pud_init(void *addr) > >> +{ > >> +} > >> +#define pud_init pud_init > >> +#endif > > For the fallback implementation, from other examples, it seems we > > usually don't need something like "#define pmd_init pmd_init". > However for some examples it is used actually, such as: > > #ifndef pmd_index > static inline unsigned long pmd_index(unsigned long address) > { > return (address >> PMD_SHIFT) & (PTRS_PER_PMD - 1); > } > #define pmd_index pmd_index > #endif > > #ifndef pud_index > static inline unsigned long pud_index(unsigned long address) > { > return (address >> PUD_SHIFT) & (PTRS_PER_PUD - 1); > } > #define pud_index pud_index > #endif > > Regards > Bibo Mao > > > > Huacai > > > >> + > >> #ifndef pte_offset_kernel > >> static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long address) > >> { > >> --- a/mm/kasan/init.c~mm-define-general-function-pxd_init > >> +++ a/mm/kasan/init.c > >> @@ -139,10 +139,6 @@ static int __ref zero_pmd_populate(pud_t > >> return 0; > >> } > >> > >> -void __weak __meminit pmd_init(void *addr) > >> -{ > >> -} > >> - > >> static int __ref zero_pud_populate(p4d_t *p4d, unsigned long addr, > >> unsigned long end) > >> { > >> @@ -181,10 +177,6 @@ static int __ref zero_pud_populate(p4d_t > >> return 0; > >> } > >> > >> -void __weak __meminit pud_init(void *addr) > >> -{ > >> -} > >> - > >> static int __ref zero_p4d_populate(pgd_t *pgd, unsigned long addr, > >> unsigned long end) > >> { > >> --- a/mm/sparse-vmemmap.c~mm-define-general-function-pxd_init > >> +++ a/mm/sparse-vmemmap.c > >> @@ -196,10 +196,6 @@ pmd_t * __meminit vmemmap_pmd_populate(p > >> return pmd; > >> } > >> > >> -void __weak __meminit pmd_init(void *addr) > >> -{ > >> -} > >> - > >> pud_t * __meminit vmemmap_pud_populate(p4d_t *p4d, unsigned long addr, int node) > >> { > >> pud_t *pud = pud_offset(p4d, addr); > >> @@ -213,10 +209,6 @@ pud_t * __meminit vmemmap_pud_populate(p > >> return pud; > >> } > >> > >> -void __weak __meminit pud_init(void *addr) > >> -{ > >> -} > >> - > >> p4d_t * __meminit vmemmap_p4d_populate(pgd_t *pgd, unsigned long addr, int node) > >> { > >> p4d_t *p4d = p4d_offset(pgd, addr); > >> _ > >> > >> Patches currently in -mm which might be from maobibo@xxxxxxxxxxx are > >> > >> mm-define-general-function-pxd_init.patch > >> >