Convert powerpc to GENERIC_PTDUMP
Subsystems (10)
cover Convert powerpc to GENERIC_PTDUMP
This series converts powerpc to generic PTDUMP.
For that, we first need to add missing hugepd support to pagewalk and ptdump.
Christophe Leroy (5):
mm: pagewalk: Fix walk for hugepage tables
mm: ptdump: Fix build failure
mm: ptdump: Provide page size to notepage()
mm: ptdump: Support hugepd table entries
powerpc/mm: Convert powerpc to GENERIC_PTDUMP
arch/arm64/mm/ptdump.c | 2 +- arch/powerpc/Kconfig | 2 + arch/powerpc/Kconfig.debug | 30 ------ arch/powerpc/mm/Makefile | 2 +- arch/powerpc/mm/mmu_decl.h | 2 +- arch/powerpc/mm/ptdump/8xx.c | 6 +- arch/powerpc/mm/ptdump/Makefile | 9 +- arch/powerpc/mm/ptdump/book3s64.c | 6 +- arch/powerpc/mm/ptdump/ptdump.c | 161 +++++++++--------------------- arch/powerpc/mm/ptdump/shared.c | 6 +- arch/riscv/mm/ptdump.c | 2 +- arch/s390/mm/dump_pagetables.c | 3 +- arch/x86/mm/dump_pagetables.c | 2 +- include/linux/ptdump.h | 2 +- mm/pagewalk.c | 54 ++++++++-- mm/ptdump.c | 33 ++++-- 16 files changed, 145 insertions(+), 177 deletions(-)
Signature · 1 line
2.25.0
PATCH 1/5 mm: pagewalk: Fix walk for hugepage tables
Pagewalk ignores hugepd entries and walk down the tables as if it was traditionnal entries, leading to crazy result.
Add walk_hugepd_range() and use it to walk hugepage tables.
--- mm/pagewalk.c | 54 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-)
mm/pagewalk.c +48 -6
@@ -58,6 +58,32 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,return err; } +static int walk_hugepd_range (hugepd_t *phpd,unsigned long addr, +unsigned long end,struct mm_walk *walk,int pdshift) +{ +int err =0 ; +#ifdef CONFIG_ARCH_HAS_HUGEPD +const struct mm_walk_ops *ops = walk->ops; +int shift =hugepd_shift (*phpd); +int page_size =1 << shift; + +if (addr & (page_size -1 )) +return 0 ; + +for (;;) { +pte_t *pte =hugepte_offset (*phpd, addr, pdshift); + + err = ops->pte_entry (pte, addr, addr + page_size, walk); +if (err) +break ; +if (addr >= end - page_size) +break ; + addr += page_size; + } +#endif +return err; +} +static int walk_pmd_range (pud_t *pud,unsigned long addr,unsigned long end,struct mm_walk *walk) {
@@ -108,7 +134,10 @@ static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, goto again; } - err =walk_pte_range (pmd, addr, next, walk); +if (is_hugepd (__hugepd (pmd_val (*pmd)))) + err =walk_hugepd_range ((hugepd_t *)pmd, addr, next, walk,PMD_SHIFT ); +else + err =walk_pte_range (pmd, addr, next, walk);if (err)break ; }while (pmd++, addr = next, addr != end);
@@ -157,7 +186,10 @@ static int walk_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,if (pud_none (*pud)) goto again; - err =walk_pmd_range (pud, addr, next, walk); +if (is_hugepd (__hugepd (pud_val (*pud)))) + err =walk_hugepd_range ((hugepd_t *)pud, addr, next, walk,PUD_SHIFT ); +else + err =walk_pmd_range (pud, addr, next, walk);if (err)break ; }while (pud++, addr = next, addr != end);
@@ -189,8 +221,13 @@ static int walk_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long end,if (err)break ; } -if (ops->pud_entry || ops->pmd_entry || ops->pte_entry) - err =walk_pud_range (p4d, addr, next, walk); +if (ops->pud_entry || ops->pmd_entry || ops->pte_entry) { +if (is_hugepd (__hugepd (p4d_val (*p4d)))) + err =walk_hugepd_range ((hugepd_t *)p4d, addr, next, walk, +P4D_SHIFT ); +else + err =walk_pud_range (p4d, addr, next, walk); + }if (err)break ; }while (p4d++, addr = next, addr != end);
@@ -225,8 +262,13 @@ static int walk_pgd_range(unsigned long addr, unsigned long end,break ; }if (ops->p4d_entry || ops->pud_entry || ops->pmd_entry || - ops->pte_entry) - err =walk_p4d_range (pgd, addr, next, walk); + ops->pte_entry) { +if (is_hugepd (__hugepd (pgd_val (*pgd)))) + err =walk_hugepd_range ((hugepd_t *)pgd, addr, next, walk, +PGDIR_SHIFT ); +else + err =walk_p4d_range (pgd, addr, next, walk); + }if (err)break ; }while (pgd++, addr = next, addr != end);
Signature · 1 line
2.25.0
PATCH 2/5 mm: ptdump: Fix build failure
In reply to Christophe Leroy CC mm/ptdump.o
In file included from <command-line>:
mm/ptdump.c: In function 'ptdump_pte_entry':
././include/linux/compiler_types.h:320:38: error: call to '__compiletime_assert_207' declared with attribute error: Unsupported access size for {READ,WRITE}_ONCE().
320 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
././include/linux/compiler_types.h:301:4: note: in definition of macro '__compiletime_assert'
301 | prefix ## suffix(); \
| ^~~~~~
././include/linux/compiler_types.h:320:2: note: in expansion of macro '_compiletime_assert'
320 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
./include/asm-generic/rwonce.h:36:2: note: in expansion of macro 'compiletime_assert'
36 | compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
| ^~~~~~~~~~~~~~~~~~
./include/asm-generic/rwonce.h:49:2: note: in expansion of macro 'compiletime_assert_rwonce_type'
49 | compiletime_assert_rwonce_type(x); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/ptdump.c:114:14: note: in expansion of macro 'READ_ONCE'
114 | pte_t val = READ_ONCE(*pte);
| ^~~~~~~~~
make[2]: *** [mm/ptdump.o] Error 1READ_ONCE() cannot be used for reading PTEs. Use ptep_get() instead. See commit 481e980a7c19 ("mm: Allow arches to provide ptep_get()") and commit c0e1c8c22beb ("powerpc/8xx: Provide ptep_get() with 16k pages") for details.
--- mm/ptdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/ptdump.c +1 -1
@@ -111,7 +111,7 @@ static int ptdump_pte_entry(pte_t *pte, unsigned long addr, unsigned long next, struct mm_walk *walk) { struct ptdump_state *st = walk->private; -pte_t val =READ_ONCE (*pte); +pte_t val =ptep_get (pte);if (st->effective_prot) st->effective_prot (st,4 ,pte_val (val));
Signature · 1 line
2.25.0
PATCH 3/5 mm: ptdump: Provide page size to notepage()
In reply to Christophe LeroyIn order to support large pages on powerpc, notepage() needs to know the page size of the page.
Add a page_size argument to notepage().
--- arch/arm64/mm/ptdump.c | 2 +- arch/riscv/mm/ptdump.c | 2 +- arch/s390/mm/dump_pagetables.c | 3 ++- arch/x86/mm/dump_pagetables.c | 2 +- include/linux/ptdump.h | 2 +- mm/ptdump.c | 16 ++++++++-------- 6 files changed, 14 insertions(+), 13 deletions(-)
arch/arm64/mm/ptdump.c +1 -1
@@ -257,7 +257,7 @@ static void note_prot_wx(struct pg_state *st, unsigned long addr) }static void note_page (struct ptdump_state *pt_st,unsigned long addr,int level, -u64 val) +u64 val,unsigned long page_size) { struct pg_state *st = container_of(pt_st, struct pg_state, ptdump);static const char units[] ="KMGTPE" ;
arch/riscv/mm/ptdump.c +1 -1
@@ -235,7 +235,7 @@ static void note_prot_wx(struct pg_state *st, unsigned long addr) }static void note_page (struct ptdump_state *pt_st,unsigned long addr, -int level,u64 val) +int level,u64 val,unsigned long page_size) { struct pg_state *st = container_of(pt_st, struct pg_state, ptdump);u64 pa =PFN_PHYS (pte_pfn (__pte (val)));
arch/s390/mm/dump_pagetables.c +2 -1
@@ -116,7 +116,8 @@ static void note_prot_wx(struct pg_state *st, unsigned long addr)#endif /* CONFIG_DEBUG_WX */ } -static void note_page (struct ptdump_state *pt_st,unsigned long addr,int level,u64 val) +static void note_page (struct ptdump_state *pt_st,unsigned long addr,int level, +u64 val,unsigned long page_size) {int width =sizeof (unsigned long ) *2 ;static const char units[] ="KMGTPE" ;
arch/x86/mm/dump_pagetables.c +1 -1
@@ -272,7 +272,7 @@ static void effective_prot(struct ptdump_state *pt_st, int level, u64 val)* print what we collected so far. */ static void note_page (struct ptdump_state *pt_st,unsigned long addr,int level, -u64 val) +u64 val,unsigned long page_size) { struct pg_state *st = container_of(pt_st, struct pg_state, ptdump);pgprotval_t new_prot, new_eff;
include/linux/ptdump.h +1 -1
@@ -13,7 +13,7 @@ struct ptdump_range {struct ptdump_state {/* level is 0:PGD to 4:PTE, or -1 if unknown */ void (*note_page)(struct ptdump_state *st,unsigned long addr, -int level,u64 val); +int level,u64 val,unsigned long page_size);void (*effective_prot)(struct ptdump_state *st,int level,u64 val);const struct ptdump_range *range; };
mm/ptdump.c +8 -8
@@ -17,7 +17,7 @@ static inline int note_kasan_page_table(struct mm_walk *walk, {struct ptdump_state *st = walk->private; - st->note_page (st, addr,4 ,pte_val (kasan_early_shadow_pte[0 ])); + st->note_page (st, addr,4 ,pte_val (kasan_early_shadow_pte[0 ]),PAGE_SIZE ); walk->action =ACTION_CONTINUE ;
@@ -41,7 +41,7 @@ static int ptdump_pgd_entry(pgd_t *pgd, unsigned long addr, st->effective_prot (st,0 ,pgd_val (val));if (pgd_leaf (val)) - st->note_page (st, addr,0 ,pgd_val (val)); + st->note_page (st, addr,0 ,pgd_val (val),PGDIR_SIZE );return 0 ; }
@@ -62,7 +62,7 @@ static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr, st->effective_prot (st,1 ,p4d_val (val));if (p4d_leaf (val)) - st->note_page (st, addr,1 ,p4d_val (val)); + st->note_page (st, addr,1 ,p4d_val (val),P4D_SIZE );return 0 ; }
@@ -83,7 +83,7 @@ static int ptdump_pud_entry(pud_t *pud, unsigned long addr, st->effective_prot (st,2 ,pud_val (val));if (pud_leaf (val)) - st->note_page (st, addr,2 ,pud_val (val)); + st->note_page (st, addr,2 ,pud_val (val),PUD_SIZE );return 0 ; }
@@ -102,7 +102,7 @@ static int ptdump_pmd_entry(pmd_t *pmd, unsigned long addr,if (st->effective_prot) st->effective_prot (st,3 ,pmd_val (val));if (pmd_leaf (val)) - st->note_page (st, addr,3 ,pmd_val (val)); + st->note_page (st, addr,3 ,pmd_val (val),PMD_SIZE );return 0 ; }
@@ -116,7 +116,7 @@ static int ptdump_pte_entry(pte_t *pte, unsigned long addr,if (st->effective_prot) st->effective_prot (st,4 ,pte_val (val)); - st->note_page (st, addr,4 ,pte_val (val)); + st->note_page (st, addr,4 ,pte_val (val),PAGE_SIZE );return 0 ; }
@@ -126,7 +126,7 @@ static int ptdump_hole(unsigned long addr, unsigned long next, {struct ptdump_state *st = walk->private; - st->note_page (st, addr, depth,0 ); + st->note_page (st, addr, depth,0 ,0 );return 0 ; }
@@ -153,5 +153,5 @@ void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd)mmap_read_unlock (mm);/* Flush out the last page */ - st->note_page (st,0 ,-1 ,0 ); + st->note_page (st,0 ,-1 ,0 ,0 ); }
Signature · 1 line
2.25.0
PATCH 4/5 mm: ptdump: Support hugepd table entries
In reply to Christophe LeroyWhich hugepd, page table entries can be at any level and can be of any size.
Add support for them.
--- mm/ptdump.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
mm/ptdump.c +15 -2
@@ -112,11 +112,24 @@ static int ptdump_pte_entry(pte_t *pte, unsigned long addr, {struct ptdump_state *st = walk->private;pte_t val =ptep_get (pte); +unsigned long page_size = next - addr; +int level; + +if (page_size >=PGDIR_SIZE ) + level =0 ; +else if (page_size >=P4D_SIZE ) + level =1 ; +else if (page_size >=PUD_SIZE ) + level =2 ; +else if (page_size >=PMD_SIZE ) + level =3 ; +else + level =4 ;if (st->effective_prot) - st->effective_prot (st,4 ,pte_val (val)); + st->effective_prot (st, level,pte_val (val)); - st->note_page (st, addr,4 ,pte_val (val),PAGE_SIZE ); + st->note_page (st, addr, level,pte_val (val), page_size);return 0 ; }
Signature · 1 line
2.25.0
PATCH 5/5 powerpc/mm: Convert powerpc to GENERIC_PTDUMP
In reply to Christophe LeroyThis patch converts powerpc to the generic PTDUMP implementation.
--- arch/powerpc/Kconfig | 2 + arch/powerpc/Kconfig.debug | 30 ------ arch/powerpc/mm/Makefile | 2 +- arch/powerpc/mm/mmu_decl.h | 2 +- arch/powerpc/mm/ptdump/8xx.c | 6 +- arch/powerpc/mm/ptdump/Makefile | 9 +- arch/powerpc/mm/ptdump/book3s64.c | 6 +- arch/powerpc/mm/ptdump/ptdump.c | 161 +++++++++--------------------- arch/powerpc/mm/ptdump/shared.c | 6 +- 9 files changed, 68 insertions(+), 156 deletions(-)
arch/powerpc/Kconfig +2 -0
@@ -120,6 +120,7 @@ config PPC select ARCH_32BIT_OFF_T if PPC32 select ARCH_HAS_DEBUG_VIRTUAL select ARCH_HAS_DEBUG_VM_PGTABLE + select ARCH_HAS_DEBUG_WX if STRICT_KERNEL_RWX select ARCH_HAS_DEVMEM_IS_ALLOWED select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_FORTIFY_SOURCE
@@ -177,6 +178,7 @@ config PPC select GENERIC_IRQ_SHOW select GENERIC_IRQ_SHOW_LEVEL select GENERIC_PCI_IOMAP if PCI + select GENERIC_PTDUMP select GENERIC_SMP_IDLE_THREAD select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER
arch/powerpc/Kconfig.debug +0 -30
@@ -360,36 +360,6 @@ config FAIL_IOMMU If you are unsure, say N. -config PPC_PTDUMP - bool "Export kernel pagetable layout to userspace via debugfs" - depends on DEBUG_KERNEL && DEBUG_FS - help - This option exports the state of the kernel pagetables to a - debugfs file. This is only useful for kernel developers who are - working in architecture specific areas of the kernel - probably - not a good idea to enable this feature in a production kernel. - - If you are unsure, say N. - -config PPC_DEBUG_WX - bool "Warn on W+X mappings at boot" - depends on PPC_PTDUMP && STRICT_KERNEL_RWX - help - Generate a warning if any W+X mappings are found at boot. - - This is useful for discovering cases where the kernel is leaving - W+X mappings after applying NX, as such mappings are a security risk. - - Note that even if the check fails, your kernel is possibly - still fine, as W+X mappings are not a security hole in - themselves, what they do is that they make the exploitation - of other unfixed kernel bugs easier. - - There is no runtime or memory usage effect of this option - once the kernel has booted up - it's a one time check. - - If in doubt, say "Y". - config PPC_FAST_ENDIAN_SWITCH bool "Deprecated fast endian-switch syscall" depends on DEBUG_KERNEL && PPC_BOOK3S_64
arch/powerpc/mm/Makefile +1 -1
@@ -18,5 +18,5 @@ obj-$(CONFIG_PPC_MM_SLICES) += slice.o obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.o -obj-$(CONFIG_PPC_PTDUMP) += ptdump/ +obj-$(CONFIG_PTDUMP_CORE) += ptdump/ obj-$(CONFIG_KASAN) += kasan/
arch/powerpc/mm/mmu_decl.h +1 -1
@@ -180,7 +180,7 @@ static inline void mmu_mark_rodata_ro(void) { }void __init mmu_mapin_immr (void );#endif -#ifdef CONFIG_PPC_DEBUG_WX +#ifdef CONFIG_DEBUG_WX void ptdump_check_wx (void );#else static inline void ptdump_check_wx (void ) { }
arch/powerpc/mm/ptdump/8xx.c +4 -2
@@ -75,8 +75,10 @@ static const struct flag_info flag_array[] = { };struct pgtable_level pg_level[5 ] = { - { - }, {/* pgd */ + {/* pgd */ + .flag = flag_array, + .num =ARRAY_SIZE (flag_array), + }, {/* p4d */ .flag = flag_array, .num =ARRAY_SIZE (flag_array), }, {/* pud */
arch/powerpc/mm/ptdump/Makefile +7 -2
@@ -5,5 +5,10 @@ obj-y += ptdump.o obj-$(CONFIG_4xx) += shared.o obj-$(CONFIG_PPC_8xx) += 8xx.o obj-$(CONFIG_PPC_BOOK3E_MMU) += shared.o -obj-$(CONFIG_PPC_BOOK3S_32) += shared.o bats.o segment_regs.o -obj-$(CONFIG_PPC_BOOK3S_64) += book3s64.o hashpagetable.o +obj-$(CONFIG_PPC_BOOK3S_32) += shared.o +obj-$(CONFIG_PPC_BOOK3S_64) += book3s64.o + +ifdef CONFIG_PTDUMP_DEBUGFS +obj-$(CONFIG_PPC_BOOK3S_32) += bats.o segment_regs.o +obj-$(CONFIG_PPC_BOOK3S_64) += hashpagetable.o +endif
arch/powerpc/mm/ptdump/book3s64.c +4 -2
@@ -103,8 +103,10 @@ static const struct flag_info flag_array[] = { };struct pgtable_level pg_level[5 ] = { - { - }, {/* pgd */ + {/* pgd */ + .flag = flag_array, + .num =ARRAY_SIZE (flag_array), + }, {/* p4d */ .flag = flag_array, .num =ARRAY_SIZE (flag_array), }, {/* pud */
arch/powerpc/mm/ptdump/ptdump.c +45 -116
234 lines not on this page · raw message
arch/powerpc/mm/ptdump/shared.c +4 -2
@@ -68,8 +68,10 @@ static const struct flag_info flag_array[] = { };struct pgtable_level pg_level[5 ] = { - { - }, {/* pgd */ + {/* pgd */ + .flag = flag_array, + .num =ARRAY_SIZE (flag_array), + }, {/* p4d */ .flag = flag_array, .num =ARRAY_SIZE (flag_array), }, {/* pud */
Signature · 1 line
2.25.0
Re: [PATCH v1 1/5] mm: pagewalk: Fix walk for hugepage tables
In reply to Christophe LeroyHi Christophe,
Quoted 30 lines
Pagewalk ignores hugepd entries and walk down the tables as if it was traditionnal entries, leading to crazy result.
Add
walk_hugepd_range()and use it to walk hugepage tables.Signed-off-by Christophe Leroy <[email protected]>--- mm/pagewalk.c | 54 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-)mm/pagewalk.c +12
-0@@ -58,6 +58,32 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,return err; } +static int walk_hugepd_range (hugepd_t *phpd,unsigned long addr, +unsigned long end,struct mm_walk *walk,int pdshift) +{ +int err =0 ; +#ifdef CONFIG_ARCH_HAS_HUGEPD +const struct mm_walk_ops *ops = walk->ops; +int shift =hugepd_shift (*phpd); +int page_size =1 << shift; + +if (addr & (page_size -1 )) +return 0 ; +
mm/pagewalk.c static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, · line 82
Quoted 10 lines
mm/pagewalk.c +10
-0+for (;;) { +pte_t *pte =hugepte_offset (*phpd, addr, pdshift); + + err = ops->pte_entry (pte, addr, addr + page_size, walk); +if (err) +break ; +if (addr >= end - page_size) +break ; + addr += page_size; + }
Initially I thought this was a somewhat unintuitive way to structure this loop, but I see it parallels the structure of walk_pte_range_inner, so I think the consistency is worth it.
I notice the pte walking code potentially takes some locks: does this code need to do that?
arch/powerpc/mm/hugetlbpage.c says that hugepds are protected by the mm->page_table_lock, but I don't think we're taking it in this code.
Quoted 20 lines
mm/pagewalk.c +8
-1+#endif +return err; +} +static int walk_pmd_range (pud_t *pud,unsigned long addr,unsigned long end,struct mm_walk *walk) {@@ -108,7 +134,10 @@ static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, goto again; } - err =walk_pte_range (pmd, addr, next, walk); +if (is_hugepd (__hugepd (pmd_val (*pmd)))) + err =walk_hugepd_range ((hugepd_t *)pmd, addr, next, walk,PMD_SHIFT ); +else + err =walk_pte_range (pmd, addr, next, walk);if (err)break ; }while (pmd++, addr = next, addr != end);
mm/pagewalk.c static int walk_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end, · line 192
Quoted 8 lines
mm/pagewalk.c +4
-1@@ -157,7 +186,10 @@ static int walk_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,if (pud_none (*pud)) goto again; - err =walk_pmd_range (pud, addr, next, walk); +if (is_hugepd (__hugepd (pud_val (*pud)))) + err =walk_hugepd_range ((hugepd_t *)pud, addr, next, walk,PUD_SHIFT ); +else + err =walk_pmd_range (pud, addr, next, walk);
I'm a bit worried you might end up calling into walk_hugepd_range with ops->pte_entry == NULL, and then jumping to 0.
static int walk_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,
struct mm_walk *walk)
{
...
pud = pud_offset(p4d, addr);
do {
...
if ((!walk->vma && (pud_leaf(*pud) || !pud_present(*pud))) ||
walk->action == ACTION_CONTINUE ||
!(ops->pmd_entry || ops->pte_entry)) <<< THIS CHECK
continue;
...
if (is_hugepd(__hugepd(pud_val(*pud))))
err = walk_hugepd_range((hugepd_t *)pud, addr, next, walk, PUD_SHIFT);
else
err = walk_pmd_range(pud, addr, next, walk);
if (err)
break;
} while (pud++, addr = next, addr != end);walk_pud_range will proceed if there is _either_ an ops->pmd_entry _or_ an ops->pte_entry, but walk_hugepd_range will call ops->pte_entry unconditionally.
The same issue applies to walk_{p4d,pgd}_range...
Kind regards,
Daniel
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
In reply to Christophe LeroyHi Christophe,
Review
Quoted 3 lines
static void note_page(struct
ptdump_state*pt_st, unsigned long addr, int level,(quoted diff) +1
-1- u64 val) + u64 val, unsigned long page_size)
Compilers can warn about unused parameters at -Wextra level. However, reading scripts/Makefile.extrawarn it looks like the warning is explicitly _disabled_ in the kernel at W=1 and not reenabled at W=2 or W=3. So I guess this is fine...
mm/ptdump.c static int ptdump_hole(unsigned long addr, unsigned long next, · line 129
Quoted 6 lines
mm/ptdump.c +1
-1@@ -126,7 +126,7 @@ static int ptdump_hole(unsigned long addr, unsigned long next, {struct ptdump_state *st = walk->private; - st->note_page (st, addr, depth,0 ); + st->note_page (st, addr, depth,0 ,0 );
I know it doesn't matter at this point, but I'm not really thrilled by the idea of passing 0 as the size here. Doesn't the hole have a known page size?
mm/ptdump.c void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd) · line 156
Quoted 9 lines
mm/ptdump.c +1
-1return 0 ; }@@ -153,5 +153,5 @@ void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd)mmap_read_unlock (mm);/* Flush out the last page */ - st->note_page (st,0 ,-1 ,0 ); + st->note_page (st,0 ,-1 ,0 ,0 );
I'm more OK with the idea of passing 0 as the size when the depth is -1 (don't know): if we don't know the depth we conceptually can't know the page size.
Regards,
Daniel
Re: [PATCH v1 4/5] mm: ptdump: Support hugepd table entries
In reply to Christophe LeroyHi Christophe,
Quoted 28 lines
Which hugepd, page table entries can be at any level and can be of any size.
Add support for them.
Signed-off-by Christophe Leroy <[email protected]>--- mm/ptdump.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)mm/ptdump.c +10
-0@@ -112,11 +112,24 @@ static int ptdump_pte_entry(pte_t *pte, unsigned long addr, {struct ptdump_state *st = walk->private;pte_t val =ptep_get (pte); +unsigned long page_size = next - addr; +int level; + +if (page_size >=PGDIR_SIZE ) + level =0 ; +else if (page_size >=P4D_SIZE ) + level =1 ; +else if (page_size >=PUD_SIZE ) + level =2 ; +else if (page_size >=PMD_SIZE )
mm/ptdump.c static int ptdump_pte_entry(pte_t *pte, unsigned long addr, · line 132
Quoted 10 lines
mm/ptdump.c +5
-2+ level =3 ; + else + level =4 ;if (st->effective_prot) - st->effective_prot (st,4 ,pte_val (val)); + st->effective_prot (st, level,pte_val (val)); - st->note_page (st, addr,4 ,pte_val (val),PAGE_SIZE ); + st->note_page (st, addr, level,pte_val (val), page_size);
It seems to me that passing both level and page_size is a bit redundant, but I guess it does reduce the impact on each arch's code?
Kind regards,
Daniel
Quoted 5 lines
mm/ptdump.c +0
-0return 0 ; }Signature · 1 line
2.25.0
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
In reply to Daniel AxtensLe 16/04/2021 à 01:12, Daniel Axtens a écrit :
Quoted 10 lines
Hi Christophe,
Review
Quoted 3 lines
static void note_page(struct
ptdump_state*pt_st, unsigned long addr, int level,(quoted diff) +1
-1- u64 val) + u64 val, unsigned long page_size)Compilers can warn about unused parameters at -Wextra level. However, reading
scripts/Makefile.extrawarnit looks like the warning is explicitly _disabled_ in the kernel at W=1 and not reenabled at W=2 or W=3. So I guess this is fine...
There are a lot lot lot functions having unused parameters in the kernel , especially the ones that are re-implemented by each architecture.
Quoted 11 lines
mm/ptdump.c static int ptdump_hole(unsigned long addr, unsigned long next, · line 129
Quoted 7 lines
mm/ptdump.c +1
-1@@ -126,7 +126,7 @@ static int ptdump_hole(unsigned long addr, unsigned long next, {struct ptdump_state *st = walk->private; - st->note_page (st, addr, depth,0 ); + st->note_page (st, addr, depth,0 ,0 );I know it doesn't matter at this point, but I'm not really thrilled by the idea of passing 0 as the size here. Doesn't the hole have a known page size?
The hole has a size for sure, I don't think we can call it a page size:
On powerpc 8xx, we have 4 page sizes: 8M, 512k, 16k and 4k.
A page table will cover 4M areas and will contain pages of size 512k, 16k and 4k.
A PGD table contains either entries which points to a page table (covering 4M), or two identical consecutive entries pointing to the same hugepd which contains a single PTE for an 8M page.
So, if a PGD entry is empty, the hole is 4M, it corresponds to none of the page sizes the architecture supports.
But looking at what is done with that size, it can make sense to pass it to notepage() anyway. Let's do that.
Quoted 18 lines
mm/ptdump.c void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd) · line 156
Quoted 10 lines
mm/ptdump.c +1
-1return 0 ; }@@ -153,5 +153,5 @@ void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd)mmap_read_unlock (mm);/* Flush out the last page */ - st->note_page (st,0 ,-1 ,0 ); + st->note_page (st,0 ,-1 ,0 ,0 );I'm more OK with the idea of passing 0 as the size when the depth is -1 (don't know): if we don't know the depth we conceptually can't know the page size.
Regards,
Daniel
Re: [PATCH v1 4/5] mm: ptdump: Support hugepd table entries
In reply to Daniel AxtensHi Daniel,
Le 16/04/2021 à 01:29, Daniel Axtens a écrit :
Quoted 38 lines
Hi Christophe,
Quoted 36 lines
Which hugepd, page table entries can be at any level and can be of any size.
Add support for them.
Signed-off-by Christophe Leroy <[email protected]>--- mm/ptdump.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)mm/ptdump.c +14
-1@@ -112,11 +112,24 @@ static int ptdump_pte_entry(pte_t *pte, unsigned long addr, {struct ptdump_state *st = walk->private;pte_t val =ptep_get (pte); +unsigned long page_size = next - addr; +int level; + +if (page_size >=PGDIR_SIZE ) + level =0 ; +else if (page_size >=P4D_SIZE ) + level =1 ; +else if (page_size >=PUD_SIZE ) + level =2 ; +else if (page_size >=PMD_SIZE ) + level =3 ; +else + level =4 ;if (st->effective_prot) - st->effective_prot (st,4 ,pte_val (val)); + st->effective_prot (st, level,pte_val (val));
Quoted 5 lines
mm/ptdump.c static int ptdump_pte_entry(pte_t *pte, unsigned long addr, · line 132
Quoted 2 lines
mm/ptdump.c +1
-1- st->note_page (st, addr,4 ,pte_val (val),PAGE_SIZE ); + st->note_page (st, addr, level,pte_val (val), page_size);It seems to me that passing both level and
page_sizeis a bit redundant, but I guess it does reduce the impact on each arch's code?
Exactly, as shown above, the level can be re-calculated based on the page size, but it would be a unnecessary impact on all architectures and would duplicate the re-calculation of the level whereas in most cases we get it for free from the caller.
Quoted 9 lines
Kind regards,
DanielQuoted 5 lines
mm/ptdump.c +0
-0return 0 ; }Signature · 1 line
2.25.0
Re: [PATCH v1 1/5] mm: pagewalk: Fix walk for hugepage tables
In reply to Daniel AxtensLe 16/04/2021 à 00:43, Daniel Axtens a écrit :
Quoted 47 lines
Hi Christophe,
Quoted 30 lines
Pagewalk ignores hugepd entries and walk down the tables as if it was traditionnal entries, leading to crazy result.
Add
walk_hugepd_range()and use it to walk hugepage tables.Signed-off-by Christophe Leroy <[email protected]>--- mm/pagewalk.c | 54 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-)mm/pagewalk.c +12
-0@@ -58,6 +58,32 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,return err; } +static int walk_hugepd_range (hugepd_t *phpd,unsigned long addr, +unsigned long end,struct mm_walk *walk,int pdshift) +{ +int err =0 ; +#ifdef CONFIG_ARCH_HAS_HUGEPD +const struct mm_walk_ops *ops = walk->ops; +int shift =hugepd_shift (*phpd); +int page_size =1 << shift; + +if (addr & (page_size -1 )) +return 0 ; +mm/pagewalk.c static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, · line 82
Quoted 10 lines
mm/pagewalk.c +10
-0+for (;;) { +pte_t *pte =hugepte_offset (*phpd, addr, pdshift); + + err = ops->pte_entry (pte, addr, addr + page_size, walk); +if (err) +break ; +if (addr >= end - page_size) +break ; + addr += page_size; + }Initially I thought this was a somewhat unintuitive way to structure this loop, but I see it parallels the structure of
walk_pte_range_inner, so I think the consistency is worth it.
Quoted 5 lines
I notice the pte walking code potentially takes some locks: does this code need to do that?
arch/powerpc/mm/hugetlbpage.csays that hugepds are protected by themm->page_table_lock, but I don't think we're taking it in this code.
I'll add it, thanks.
Quoted 24 lines
Quoted 24 lines
mm/pagewalk.c +8
-1+#endif +return err; +} +static int walk_pmd_range (pud_t *pud,unsigned long addr,unsigned long end,struct mm_walk *walk) {@@ -108,7 +134,10 @@ static int walk_pmd_range(pud_t *pud, unsigned long addr, unsigned long end, goto again; } - err =walk_pte_range (pmd, addr, next, walk); +if (is_hugepd (__hugepd (pmd_val (*pmd)))) + err =walk_hugepd_range ((hugepd_t *)pmd, addr, next, walk,PMD_SHIFT ); +else + err =walk_pte_range (pmd, addr, next, walk);if (err)break ; }while (pmd++, addr = next, addr != end);@@ -157,7 +186,10 @@ static int walk_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,if (pud_none (*pud)) goto again;
Quoted 8 lines
mm/pagewalk.c static int walk_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end, · line 192
Quoted 5 lines
mm/pagewalk.c +4
-1- err =walk_pmd_range (pud, addr, next, walk); +if (is_hugepd (__hugepd (pud_val (*pud)))) + err =walk_hugepd_range ((hugepd_t *)pud, addr, next, walk,PUD_SHIFT ); +else + err =walk_pmd_range (pud, addr, next, walk);I'm a bit worried you might end up calling into
walk_hugepd_rangewithops->pte_entry== NULL, and then jumping to 0.
You are right, I missed it.
I'll bail out of walk_hugepd_range() when ops->pte_entry is NULL.
Quoted 21 lines
static int walk_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,
structmm_walk*walk)
{
...pud = pud_offset(p4d, addr); do { ... if ((!walk->vma && (pud_leaf(*pud) || !pud_present(*pud))) || walk->action == ACTION_CONTINUE || !(ops->pmd_entry || ops->pte_entry)) <<< THIS CHECK continue; ... if (is_hugepd(__hugepd(pud_val(*pud)))) err = walk_hugepd_range((hugepd_t *)pud, addr, next, walk, PUD_SHIFT); else err = walk_pmd_range(pud, addr, next, walk); if (err) break; } while (pud++, addr = next, addr != end);
Quoted 9 lines
walk_pud_rangewill proceed if there is _either_ anops->pmd_entry_or_ anops->pte_entry, butwalk_hugepd_rangewill callops->pte_entryunconditionally.The same issue applies to walk_{p4d,pgd}_range...
Kind regards,
Daniel
Thanks
Christophe
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
In reply to Christophe LeroyQuoted 15 lines · Christophe Leroy
In order to support large pages on powerpc,
notepage()needs to know the page size of the page.Add a
page_sizeargument tonotepage().Signed-off-by Christophe Leroy <[email protected]>--- arch/arm64/mm/ptdump.c | 2 +- arch/riscv/mm/ptdump.c | 2 +- arch/s390/mm/dump_pagetables.c | 3 ++- arch/x86/mm/dump_pagetables.c | 2 +- include/linux/ptdump.h | 2 +- mm/ptdump.c | 16 ++++++++-------- 6 files changed, 14 insertions(+), 13 deletions(-)
[...]
mm/ptdump.c static inline int note_kasan_page_table(struct mm_walk *walk, · line 20
Quoted 10 lines
mm/ptdump.c +1
-1@@ -17,7 +17,7 @@ static inline int note_kasan_page_table(struct mm_walk *walk, {struct ptdump_state *st = walk->private; - st->note_page (st, addr,4 ,pte_val (kasan_early_shadow_pte[0 ])); + st->note_page (st, addr,4 ,pte_val (kasan_early_shadow_pte[0 ]),PAGE_SIZE );
I'm not completely sure what the page_size is going to be used for, but note that KASAN presents an interesting case here. We short-cut by detecting it's a KASAN region at a high level (PGD/P4D/PUD/PMD) and instead of walking the tree down just call note_page() *once* but with level==4 because we know KASAN sets up the page table like that.
However the one call actually covers a much larger region - so while PAGE_SIZE matches the level it doesn't match the region covered. AFAICT this will lead to odd results if you enable KASAN on powerpc.
To be honest I don't fully understand why powerpc requires the page_size - it appears to be using it purely to find "holes" in the calls to note_page(), but I haven't worked out why such holes would occur.
Steve
Quoted 65 lines
mm/ptdump.c +7
-7walk->action =ACTION_CONTINUE ;@@ -41,7 +41,7 @@ static int ptdump_pgd_entry(pgd_t *pgd, unsigned long addr, st->effective_prot (st,0 ,pgd_val (val));if (pgd_leaf (val)) - st->note_page (st, addr,0 ,pgd_val (val)); + st->note_page (st, addr,0 ,pgd_val (val),PGDIR_SIZE );return 0 ; }@@ -62,7 +62,7 @@ static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr, st->effective_prot (st,1 ,p4d_val (val));if (p4d_leaf (val)) - st->note_page (st, addr,1 ,p4d_val (val)); + st->note_page (st, addr,1 ,p4d_val (val),P4D_SIZE );return 0 ; }@@ -83,7 +83,7 @@ static int ptdump_pud_entry(pud_t *pud, unsigned long addr, st->effective_prot (st,2 ,pud_val (val));if (pud_leaf (val)) - st->note_page (st, addr,2 ,pud_val (val)); + st->note_page (st, addr,2 ,pud_val (val),PUD_SIZE );return 0 ; }@@ -102,7 +102,7 @@ static int ptdump_pmd_entry(pmd_t *pmd, unsigned long addr,if (st->effective_prot) st->effective_prot (st,3 ,pmd_val (val));if (pmd_leaf (val)) - st->note_page (st, addr,3 ,pmd_val (val)); + st->note_page (st, addr,3 ,pmd_val (val),PMD_SIZE );return 0 ; }@@ -116,7 +116,7 @@ static int ptdump_pte_entry(pte_t *pte, unsigned long addr,if (st->effective_prot) st->effective_prot (st,4 ,pte_val (val)); - st->note_page (st, addr,4 ,pte_val (val)); + st->note_page (st, addr,4 ,pte_val (val),PAGE_SIZE );return 0 ; }@@ -126,7 +126,7 @@ static int ptdump_hole(unsigned long addr, unsigned long next, {struct ptdump_state *st = walk->private; - st->note_page (st, addr, depth,0 ); + st->note_page (st, addr, depth,0 ,0 );return 0 ; }@@ -153,5 +153,5 @@ void ptdump_walk_pgd(struct ptdump_state *st, struct mm_struct *mm, pgd_t *pgd)mmap_read_unlock (mm);/* Flush out the last page */ - st->note_page (st,0 ,-1 ,0 ); + st->note_page (st,0 ,-1 ,0 ,0 ); }
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
Le 16/04/2021 à 11:28, Steven Price a écrit :
Quoted 29 lines · Christophe Leroy
Quoted 15 lines
In order to support large pages on powerpc,
notepage()needs to know the page size of the page.Add a
page_sizeargument tonotepage().Signed-off-by Christophe Leroy <[email protected]>---
arch/arm64/mm/ptdump.c | 2 +- arch/riscv/mm/ptdump.c | 2 +-arch/s390/mm/dump_pagetables.c| 3 ++- arch/x86/mm/dump_pagetables.c | 2 +- include/linux/ptdump.h | 2 +- mm/ptdump.c | 16 ++++++++--------6 files changed, 14 insertions(+), 13 deletions(-)[...]
mm/ptdump.c static inline int note_kasan_page_table(struct mm_walk *walk, · line 19
Quoted 9 lines
mm/ptdump.c +1
-1@@ -17,7 +17,7 @@ static inline int note_kasan_page_table(struct mm_walk *walk, { struct ptdump_state *st = walk->private; - st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0])); + st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0]), PAGE_SIZE);I'm not completely sure what the
page_sizeis going to be used for, but note that KASAN presents an interesting case here. We short-cut by detecting it's a KASAN region at a high level (PGD/P4D/PUD/PMD) and instead of walking the tree down just callnote_page()*once* but with level==4 because we know KASAN sets up the page table like that.
Quoted 1 line
However the one call actually covers a much larger region - so while
PAGE_SIZEmatches the level it doesn't match the region covered. AFAICT this will lead to odd results if you enable KASAN on powerpc.
Hum .... I successfully tested it with KASAN, I now realise that I tested it with CONFIG_KASAN_VMALLOC selected. In this situation, since https://github.com/torvalds/linux/commit/af3d0a686 we don't have any common shadow page table anymore.
I'll test again without CONFIG_KASAN_VMALLOC.
Quoted 2 lines
To be honest I don't fully understand why powerpc requires the
page_size- it appears to be using it purely to find "holes" in the calls tonote_page(), but I haven't worked out why such holes would occur.
I was indeed introduced for KASAN. We have a first commit https://github.com/torvalds/linux/commit/cabe8138 which uses page size to detect whether it is a KASAN like stuff.
Then came https://github.com/torvalds/linux/commit/b00ff6d8c as a fix. I can't remember what the problem was exactly, something around the use of hugepages for kernel memory, came as part of the series https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/
Christophe
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
Quoted 38 lines · Christophe Leroy
Le 16/04/2021 à 11:28, Steven Price a écrit :
Quoted 31 lines · Christophe Leroy
Quoted 15 lines
In order to support large pages on powerpc,
notepage()needs to know the page size of the page.Add a
page_sizeargument tonotepage().Signed-off-by Christophe Leroy <[email protected]>---
arch/arm64/mm/ptdump.c | 2 +- arch/riscv/mm/ptdump.c | 2 +-arch/s390/mm/dump_pagetables.c| 3 ++- arch/x86/mm/dump_pagetables.c | 2 +- include/linux/ptdump.h | 2 +- mm/ptdump.c | 16 ++++++++--------6 files changed, 14 insertions(+), 13 deletions(-)[...]
mm/ptdump.c static inline int note_kasan_page_table(struct · line 21
Quoted 11 lines
mm/ptdump.c +1
-1@@ -17,7 +17,7 @@ static inline int note_kasan_page_table(struct mm_walk *walk, { struct ptdump_state *st = walk->private; - st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0])); + st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0]),PAGE_SIZE );I'm not completely sure what the
page_sizeis going to be used for, but note that KASAN presents an interesting case here. We short-cut by detecting it's a KASAN region at a high level (PGD/P4D/PUD/PMD) and instead of walking the tree down just callnote_page()*once* but with level==4 because we know KASAN sets up the page table like that.Quoted 1 line
However the one call actually covers a much larger region - so while
PAGE_SIZEmatches the level it doesn't match the region covered. AFAICT this will lead to odd results if you enable KASAN on powerpc.Hum .... I successfully tested it with KASAN, I now realise that I tested it with
CONFIG_KASAN_VMALLOCselected. In this situation, since https://github.com/torvalds/linux/commit/af3d0a686 we don't have any common shadow page table anymore.
Quoted 8 lines
I'll test again without
CONFIG_KASAN_VMALLOC.Quoted 2 lines
To be honest I don't fully understand why powerpc requires the
page_size- it appears to be using it purely to find "holes" in the calls tonote_page(), but I haven't worked out why such holes would occur.I was indeed introduced for KASAN. We have a first commit https://github.com/torvalds/linux/commit/cabe8138 which uses page size to detect whether it is a KASAN like stuff.
Then came https://github.com/torvalds/linux/commit/b00ff6d8c as a fix. I can't remember what the problem was exactly, something around the use of hugepages for kernel memory, came as part of the series https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/
Ah, that's useful context. So it looks like powerpc took a different route to reducing the KASAN output to x86.
Given the generic ptdump code has handling for KASAN already it should be possible to drop that from the powerpc arch code, which I think means we don't actually need to provide page size to notepage(). Hopefully that means more code to delete ;)
Steve
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
Le 16/04/2021 à 12:51, Steven Price a écrit :
Quoted 42 lines · Christophe Leroy
Quoted 41 lines
Le 16/04/2021 à 11:28, Steven Price a écrit :
Quoted 29 lines · Christophe Leroy
Quoted 15 lines
In order to support large pages on powerpc,
notepage()needs to know the page size of the page.Add a
page_sizeargument tonotepage().Signed-off-by Christophe Leroy <[email protected]>---
arch/arm64/mm/ptdump.c | 2 +- arch/riscv/mm/ptdump.c | 2 +-arch/s390/mm/dump_pagetables.c| 3 ++- arch/x86/mm/dump_pagetables.c | 2 +- include/linux/ptdump.h | 2 +- mm/ptdump.c | 16 ++++++++--------6 files changed, 14 insertions(+), 13 deletions(-)[...]
mm/ptdump.c static inline int note_kasan_page_table(struct mm_walk *walk, · line 19
Quoted 9 lines
mm/ptdump.c +1
-1@@ -17,7 +17,7 @@ static inline int note_kasan_page_table(struct mm_walk *walk, { struct ptdump_state *st = walk->private; - st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0])); + st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0]), PAGE_SIZE);I'm not completely sure what the
page_sizeis going to be used for, but note that KASAN presents an interesting case here. We short-cut by detecting it's a KASAN region at a high level (PGD/P4D/PUD/PMD) and instead of walking the tree down just callnote_page()*once* but with level==4 because we know KASAN sets up the page table like that.Quoted 1 line
However the one call actually covers a much larger region - so while
PAGE_SIZEmatches the level it doesn't match the region covered. AFAICT this will lead to odd results if you enable KASAN on powerpc.Hum .... I successfully tested it with KASAN, I now realise that I tested it with
CONFIG_KASAN_VMALLOCselected. In this situation, since https://github.com/torvalds/linux/commit/af3d0a686 we don't have any common shadow page table anymore.I'll test again without
CONFIG_KASAN_VMALLOC.Quoted 2 lines
To be honest I don't fully understand why powerpc requires the
page_size- it appears to be using it purely to find "holes" in the calls tonote_page(), but I haven't worked out why such holes would occur.
Quoted 9 lines
Quoted 3 lines
I was indeed introduced for KASAN. We have a first commit https://github.com/torvalds/linux/commit/cabe8138 which uses page size to detect whether it is a KASAN like stuff.
Then came https://github.com/torvalds/linux/commit/b00ff6d8c as a fix. I can't remember what the problem was exactly, something around the use of hugepages for kernel memory, came as part of the series https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/
Ah, that's useful context. So it looks like powerpc took a different route to reducing the KASAN output to x86.
Given the generic ptdump code has handling for KASAN already it should be possible to drop that from the powerpc arch code, which I think means we don't actually need to provide page size to
notepage(). Hopefully that means more code to delete ;)
Yes ... and no.
It looks like the generic ptdump handles the case when several pgdir entries points to the same kasan_early_shadow_pte. But it doesn't take into account the powerpc case where we have regular page tables where several (if not all) PTEs are pointing to the kasan_early_shadow_page .
Christophe
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
Quoted 53 lines · Christophe Leroy
Le 16/04/2021 à 12:51, Steven Price a écrit :
Quoted 50 lines · Christophe Leroy
Quoted 46 lines
Le 16/04/2021 à 11:28, Steven Price a écrit :
Quoted 31 lines · Christophe Leroy
Quoted 15 lines
In order to support large pages on powerpc,
notepage()needs to know the page size of the page.Add a
page_sizeargument tonotepage().Signed-off-by Christophe Leroy <[email protected]>---
arch/arm64/mm/ptdump.c | 2 +- arch/riscv/mm/ptdump.c | 2 +-arch/s390/mm/dump_pagetables.c| 3 ++- arch/x86/mm/dump_pagetables.c | 2 +- include/linux/ptdump.h | 2 +- mm/ptdump.c | 16 ++++++++--------6 files changed, 14 insertions(+), 13 deletions(-)[...]
mm/ptdump.c static inline int note_kasan_page_table(struct · line 21
Quoted 11 lines
mm/ptdump.c +1
-1@@ -17,7 +17,7 @@ static inline int note_kasan_page_table(struct mm_walk *walk, { struct ptdump_state *st = walk->private; - st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0])); + st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0]),PAGE_SIZE );I'm not completely sure what the
page_sizeis going to be used for, but note that KASAN presents an interesting case here. We short-cut by detecting it's a KASAN region at a high level (PGD/P4D/PUD/PMD) and instead of walking the tree down just callnote_page()*once* but with level==4 because we know KASAN sets up the page table like that.Quoted 1 line
However the one call actually covers a much larger region - so while
PAGE_SIZEmatches the level it doesn't match the region covered. AFAICT this will lead to odd results if you enable KASAN on powerpc.Hum .... I successfully tested it with KASAN, I now realise that I tested it with
CONFIG_KASAN_VMALLOCselected. In this situation, since https://github.com/torvalds/linux/commit/af3d0a686 we don't have any common shadow page table anymore.I'll test again without
CONFIG_KASAN_VMALLOC.Quoted 2 lines
To be honest I don't fully understand why powerpc requires the
page_size- it appears to be using it purely to find "holes" in the calls tonote_page(), but I haven't worked out why such holes would occur.I was indeed introduced for KASAN. We have a first commit https://github.com/torvalds/linux/commit/cabe8138 which uses page size to detect whether it is a KASAN like stuff.
Then came https://github.com/torvalds/linux/commit/b00ff6d8c as a fix. I can't remember what the problem was exactly, something around the use of hugepages for kernel memory, came as part of the series https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/
Quoted 8 lines
Quoted 4 lines
Ah, that's useful context. So it looks like powerpc took a different route to reducing the KASAN output to x86.
Given the generic ptdump code has handling for KASAN already it should be possible to drop that from the powerpc arch code, which I think means we don't actually need to provide page size to
notepage(). Hopefully that means more code to delete ;)Yes ... and no.
It looks like the generic ptdump handles the case when several pgdir entries points to the same
kasan_early_shadow_pte. But it doesn't take into account the powerpc case where we have regular page tables where several (if not all) PTEs are pointing to thekasan_early_shadow_page.
I'm not sure I follow quite how powerpc is different here. But could you have a similar check for PTEs against kasan_early_shadow_pte as the other levels already have?
I'm just worried that page_size isn't well defined in this interface and it's going to cause problems in the future.
Steve
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
Le 16/04/2021 à 15:00, Steven Price a écrit :
Quoted 58 lines · Christophe Leroy
Quoted 57 lines
Le 16/04/2021 à 12:51, Steven Price a écrit :
Quoted 53 lines · Christophe Leroy
Quoted 36 lines
Le 16/04/2021 à 11:28, Steven Price a écrit :
Quoted 29 lines · Christophe Leroy
Quoted 15 lines
In order to support large pages on powerpc,
notepage()needs to know the page size of the page.Add a
page_sizeargument tonotepage().Signed-off-by Christophe Leroy <[email protected]>---
arch/arm64/mm/ptdump.c | 2 +- arch/riscv/mm/ptdump.c | 2 +-arch/s390/mm/dump_pagetables.c| 3 ++- arch/x86/mm/dump_pagetables.c | 2 +- include/linux/ptdump.h | 2 +- mm/ptdump.c | 16 ++++++++--------6 files changed, 14 insertions(+), 13 deletions(-)[...]
mm/ptdump.c static inline int note_kasan_page_table(struct mm_walk *walk, · line 19
Quoted 9 lines
mm/ptdump.c +1
-1@@ -17,7 +17,7 @@ static inline int note_kasan_page_table(struct mm_walk *walk, { struct ptdump_state *st = walk->private; - st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0])); + st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0]), PAGE_SIZE);I'm not completely sure what the
page_sizeis going to be used for, but note that KASAN presents an interesting case here. We short-cut by detecting it's a KASAN region at a high level (PGD/P4D/PUD/PMD) and instead of walking the tree down just callnote_page()*once* but with level==4 because we know KASAN sets up the page table like that.Quoted 1 line
However the one call actually covers a much larger region - so while
PAGE_SIZEmatches the level it doesn't match the region covered. AFAICT this will lead to odd results if you enable KASAN on powerpc.Hum .... I successfully tested it with KASAN, I now realise that I tested it with
CONFIG_KASAN_VMALLOCselected. In this situation, since https://github.com/torvalds/linux/commit/af3d0a686 we don't have any common shadow page table anymore.Quoted 8 lines
I'll test again without
CONFIG_KASAN_VMALLOC.Quoted 2 lines
To be honest I don't fully understand why powerpc requires the
page_size- it appears to be using it purely to find "holes" in the calls tonote_page(), but I haven't worked out why such holes would occur.I was indeed introduced for KASAN. We have a first commit https://github.com/torvalds/linux/commit/cabe8138 which uses page size to detect whether it is a KASAN like stuff.
Then came https://github.com/torvalds/linux/commit/b00ff6d8c as a fix. I can't remember what the problem was exactly, something around the use of hugepages for kernel memory, came as part of the series https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/
Ah, that's useful context. So it looks like powerpc took a different route to reducing the KASAN output to x86.
Given the generic ptdump code has handling for KASAN already it should be possible to drop that from the powerpc arch code, which I think means we don't actually need to provide page size to
notepage(). Hopefully that means more code to delete ;)
Quoted 8 lines
Quoted 3 lines
Yes ... and no.
It looks like the generic ptdump handles the case when several pgdir entries points to the same
kasan_early_shadow_pte. But it doesn't take into account the powerpc case where we have regular page tables where several (if not all) PTEs are pointing to thekasan_early_shadow_page.I'm not sure I follow quite how powerpc is different here. But could you have a similar check for PTEs against
kasan_early_shadow_pteas the other levels already have?I'm just worried that
page_sizeisn't well defined in this interface and it's going to cause problems in the future.
I'm trying. I reverted the two commits b00ff6d8c and cabe8138.
At the moment, I don't get exactly what I expect: For linear memory I get one line for each 8M page whereas before reverting the patches I got one 16M line and one 112M line.
And for KASAN shadow area I get two lines for the 2x 8M pages shadowing linear mem then I get one 4M line for each PGDIR entry pointing to kasan_early_shadow_pte.
0xf8000000-0xf87fffff 0x07000000 8M huge rw present 0xf8800000-0xf8ffffff 0x07800000 8M huge rw present 0xf9000000-0xf93fffff 0x01430000 4M r present 0xf9400000-0xf97fffff 0x01430000 4M r present 0xf9800000-0xf9bfffff 0x01430000 4M r present 0xf9c00000-0xf9ffffff 0x01430000 4M r present 0xfa000000-0xfa3fffff 0x01430000 4M r present 0xfa400000-0xfa7fffff 0x01430000 4M r present 0xfa800000-0xfabfffff 0x01430000 4M r present 0xfac00000-0xfaffffff 0x01430000 4M r present 0xfb000000-0xfb3fffff 0x01430000 4M r present 0xfb400000-0xfb7fffff 0x01430000 4M r present 0xfb800000-0xfbbfffff 0x01430000 4M r present 0xfbc00000-0xfbffffff 0x01430000 4M r present 0xfc000000-0xfc3fffff 0x01430000 4M r present 0xfc400000-0xfc7fffff 0x01430000 4M r present 0xfc800000-0xfcbfffff 0x01430000 4M r present 0xfcc00000-0xfcffffff 0x01430000 4M r present 0xfd000000-0xfd3fffff 0x01430000 4M r present 0xfd400000-0xfd7fffff 0x01430000 4M r present 0xfd800000-0xfdbfffff 0x01430000 4M r present 0xfdc00000-0xfdffffff 0x01430000 4M r present 0xfe000000-0xfe3fffff 0x01430000 4M r present 0xfe400000-0xfe7fffff 0x01430000 4M r present 0xfe800000-0xfebfffff 0x01430000 4M r present 0xfec00000-0xfeffffff 0x01430000 4M r present
Any idea ?
Christophe
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
Le 16/04/2021 à 16:40, Christophe Leroy a écrit :
Quoted 44 lines
Le 16/04/2021 à 15:00, Steven Price a écrit :
Quoted 23 lines · Christophe Leroy
Quoted 22 lines
Le 16/04/2021 à 12:51, Steven Price a écrit :
Quoted 18 lines · Christophe Leroy
Quoted 8 lines
Le 16/04/2021 à 11:28, Steven Price a écrit :
Quoted 1 line
To be honest I don't fully understand why powerpc requires the
page_size- it appears to be using it purely to find "holes" in the calls tonote_page(), but I haven't worked out why such holes would occur.I was indeed introduced for KASAN. We have a first commit https://github.com/torvalds/linux/commit/cabe8138 which uses page size to detect whether it is a KASAN like stuff.
Then came https://github.com/torvalds/linux/commit/b00ff6d8c as a fix. I can't remember what the problem was exactly, something around the use of hugepages for kernel memory, came as part of the series https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/
Ah, that's useful context. So it looks like powerpc took a different route to reducing the KASAN output to x86.
Given the generic ptdump code has handling for KASAN already it should be possible to drop that from the powerpc arch code, which I think means we don't actually need to provide page size to
notepage(). Hopefully that means more code to delete ;)Quoted 8 lines
Quoted 3 lines
Yes ... and no.
It looks like the generic ptdump handles the case when several pgdir entries points to the same
kasan_early_shadow_pte. But it doesn't take into account the powerpc case where we have regular page tables where several (if not all) PTEs are pointing to thekasan_early_shadow_page.I'm not sure I follow quite how powerpc is different here. But could you have a similar check for PTEs against
kasan_early_shadow_pteas the other levels already have?I'm just worried that
page_sizeisn't well defined in this interface and it's going to cause problems in the future.I'm trying. I reverted the two commits
b00ff6d8candcabe8138.At the moment, I don't get exactly what I expect: For linear memory I get one line for each 8M page whereas before reverting the patches I got one 16M line and one 112M line.
And for KASAN shadow area I get two lines for the 2x 8M pages shadowing linear mem then I get one 4M line for each PGDIR entry pointing to
kasan_early_shadow_pte.0xf8000000-0xf87fffff 0x07000000 8M huge rw present 0xf8800000-0xf8ffffff 0x07800000 8M huge rw present 0xf9000000-0xf93fffff 0x01430000 4M r present
...
Quoted 4 lines
0xfec00000-0xfeffffff 0x01430000 4M r present
Any idea ?
I think the different with other architectures is here:
} else if (flag != st->current_flags || level != st->level ||
addr >= st->marker[1].start_address ||
pa != st->last_pa + PAGE_SIZE) {In addition to the checks everyone do, powerpc also checks "pa != st->last_pa + PAGE_SIZE". And it is definitely for that test that page_size argument add been added.
I see that other architectures except RISCV don't dump the physical address. But even RISCV doesn't include that check.
That physical address dump was added by commit aaa229529244 ("powerpc/mm: Add physical address to Linux page table dump") [https://github.com/torvalds/linux/commit/aaa2295]
How do other architectures deal with the problem described by the commit log of that patch ?
Christophe
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
Le 16/04/2021 à 17:04, Christophe Leroy a écrit :
Quoted 57 lines
Le 16/04/2021 à 16:40, Christophe Leroy a écrit :
Quoted 45 lines
Le 16/04/2021 à 15:00, Steven Price a écrit :
Quoted 24 lines · Christophe Leroy
Quoted 23 lines
Le 16/04/2021 à 12:51, Steven Price a écrit :
Quoted 19 lines · Christophe Leroy
Quoted 8 lines
Le 16/04/2021 à 11:28, Steven Price a écrit :
Quoted 1 line
To be honest I don't fully understand why powerpc requires the
page_size- it appears to be using it purely to find "holes" in the calls tonote_page(), but I haven't worked out why such holes would occur.I was indeed introduced for KASAN. We have a first commit https://github.com/torvalds/linux/commit/cabe8138 which uses page size to detect whether it is a KASAN like stuff.
Then came https://github.com/torvalds/linux/commit/b00ff6d8c as a fix. I can't remember what the problem was exactly, something around the use of hugepages for kernel memory, came as part of the series https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/
Ah, that's useful context. So it looks like powerpc took a different route to reducing the KASAN output to x86.
Given the generic ptdump code has handling for KASAN already it should be possible to drop that from the powerpc arch code, which I think means we don't actually need to provide page size to
notepage(). Hopefully that means more code to delete ;)Quoted 8 lines
Quoted 3 lines
Yes ... and no.
It looks like the generic ptdump handles the case when several pgdir entries points to the same
kasan_early_shadow_pte. But it doesn't take into account the powerpc case where we have regular page tables where several (if not all) PTEs are pointing to thekasan_early_shadow_page.I'm not sure I follow quite how powerpc is different here. But could you have a similar check for PTEs against
kasan_early_shadow_pteas the other levels already have?I'm just worried that
page_sizeisn't well defined in this interface and it's going to cause problems in the future.I'm trying. I reverted the two commits
b00ff6d8candcabe8138.At the moment, I don't get exactly what I expect: For linear memory I get one line for each 8M page whereas before reverting the patches I got one 16M line and one 112M line.
And for KASAN shadow area I get two lines for the 2x 8M pages shadowing linear mem then I get one 4M line for each PGDIR entry pointing to
kasan_early_shadow_pte.0xf8000000-0xf87fffff 0x07000000 8M huge rw present 0xf8800000-0xf8ffffff 0x07800000 8M huge rw present 0xf9000000-0xf93fffff 0x01430000 4M r present
...
Quoted 4 lines
0xfec00000-0xfeffffff 0x01430000 4M r present
Any idea ?
I think the different with other architectures is here:
Quoted 7 lines
} else if (flag !=
st->current_flags|| level !=st->level|| addr >= st->marker[1].start_address ||
pa !=st->last_pa+PAGE_SIZE) {In addition to the checks everyone do, powerpc also checks "pa !=
st->last_pa+PAGE_SIZE". And it is definitely for that test thatpage_sizeargument add been added.
By replacing that test by (pa - st->start_pa != addr - st->start_address) it works again. So we definitely don't need the real page size.
Quoted 8 lines
I see that other architectures except RISCV don't dump the physical address. But even RISCV doesn't include that check.
That physical address dump was added by commit
aaa229529244("powerpc/mm: Add physical address to Linux page table dump") [https://github.com/torvalds/linux/commit/aaa2295]How do other architectures deal with the problem described by the commit log of that patch ?
Christophe
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
Quoted 66 lines · Christophe Leroy
Le 16/04/2021 à 17:04, Christophe Leroy a écrit :
Quoted 63 lines
Le 16/04/2021 à 16:40, Christophe Leroy a écrit :
Quoted 46 lines
Le 16/04/2021 à 15:00, Steven Price a écrit :
Quoted 25 lines · Christophe Leroy
Quoted 24 lines
Le 16/04/2021 à 12:51, Steven Price a écrit :
Quoted 20 lines · Christophe Leroy
Quoted 8 lines
Le 16/04/2021 à 11:28, Steven Price a écrit :
Quoted 1 line
To be honest I don't fully understand why powerpc requires the
page_size- it appears to be using it purely to find "holes" in the calls tonote_page(), but I haven't worked out why such holes would occur.I was indeed introduced for KASAN. We have a first commit https://github.com/torvalds/linux/commit/cabe8138 which uses page size to detect whether it is a KASAN like stuff.
Then came https://github.com/torvalds/linux/commit/b00ff6d8c as a fix. I can't remember what the problem was exactly, something around the use of hugepages for kernel memory, came as part of the series https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/
Ah, that's useful context. So it looks like powerpc took a different route to reducing the KASAN output to x86.
Given the generic ptdump code has handling for KASAN already it should be possible to drop that from the powerpc arch code, which I think means we don't actually need to provide page size to
notepage(). Hopefully that means more code to delete ;)Quoted 8 lines
Quoted 3 lines
Yes ... and no.
It looks like the generic ptdump handles the case when several pgdir entries points to the same
kasan_early_shadow_pte. But it doesn't take into account the powerpc case where we have regular page tables where several (if not all) PTEs are pointing to thekasan_early_shadow_page.I'm not sure I follow quite how powerpc is different here. But could you have a similar check for PTEs against
kasan_early_shadow_pteas the other levels already have?I'm just worried that
page_sizeisn't well defined in this interface and it's going to cause problems in the future.I'm trying. I reverted the two commits
b00ff6d8candcabe8138.At the moment, I don't get exactly what I expect: For linear memory I get one line for each 8M page whereas before reverting the patches I got one 16M line and one 112M line.
And for KASAN shadow area I get two lines for the 2x 8M pages shadowing linear mem then I get one 4M line for each PGDIR entry pointing to
kasan_early_shadow_pte.0xf8000000-0xf87fffff 0x07000000 8M huge rw present
0xf8800000-0xf8ffffff 0x07800000 8M huge rw present
0xf9000000-0xf93fffff 0x01430000 4M r present...
Quoted 4 lines
0xfec00000-0xfeffffff 0x01430000 4M r present
Any idea ?
I think the different with other architectures is here:
} else if (flag !=
st->current_flags|| level !=st->level|| addr >= st->marker[1].start_address ||
pa !=st->last_pa+PAGE_SIZE) {
Quoted 4 lines
Quoted 2 lines
In addition to the checks everyone do, powerpc also checks "pa !=
st->last_pa+PAGE_SIZE". And it is definitely for that test thatpage_sizeargument add been added.By replacing that test by (pa -
st->start_pa!= addr -st->start_address) it works again. So we definitely don't need the real page size.
Yes that should work. Thanks for figuring it out!
Quoted 3 lines
Quoted 3 lines
I see that other architectures except RISCV don't dump the physical address. But even RISCV doesn't include that check.
Yes not having the physical address certainly simplifies things - although I can see why that can be handy to see. The disadvantage is that user space or vmalloc()'d memory will produce a lot of output because the physical addresses are unlikely to be contiguous. And for most uses you don't need the information.
Quoted 3 lines
Quoted 3 lines
That physical address dump was added by commit
aaa229529244("powerpc/mm: Add physical address to Linux page table dump") [https://github.com/torvalds/linux/commit/aaa2295]How do other architectures deal with the problem described by the commit log of that patch ?
AFAIK other architectures are "broken" in this regard. In practice I don't think it often causes an issue though.
Steve
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
In reply to Steven PriceLe 16/04/2021 à 12:51, Steven Price a écrit :
Quoted 8 lines · Christophe Leroy
Quoted 7 lines
Le 16/04/2021 à 11:28, Steven Price a écrit :
Quoted 3 lines · Christophe Leroy
To be honest I don't fully understand why powerpc requires the
page_size- it appears to be using it purely to find "holes" in the calls tonote_page(), but I haven't worked out why such holes would occur.
Quoted 9 lines
Quoted 3 lines
I was indeed introduced for KASAN. We have a first commit https://github.com/torvalds/linux/commit/cabe8138 which uses page size to detect whether it is a KASAN like stuff.
Then came https://github.com/torvalds/linux/commit/b00ff6d8c as a fix. I can't remember what the problem was exactly, something around the use of hugepages for kernel memory, came as part of the series https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/
Ah, that's useful context. So it looks like powerpc took a different route to reducing the KASAN output to x86.
Given the generic ptdump code has handling for KASAN already it should be possible to drop that from the powerpc arch code, which I think means we don't actually need to provide page size to
notepage(). Hopefully that means more code to delete ;)
Looking at how the generic ptdump code handles KASAN, I'm a bit sceptic.
IIUC, it is checking that kasan_early_shadow_pte is in the same page as the pgtable referred by the PMD entry. But what happens if that PMD entry is referring another pgtable which is inside the same page as kasan_early_shadow_pte ?
Shouldn't the test be
if (pmd_page_vaddr(val) == lm_alias(kasan_early_shadow_pte)) return note_kasan_page_table(walk, addr);
Christophe
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
Quoted 22 lines · Christophe Leroy
Le 16/04/2021 à 12:51, Steven Price a écrit :
Quoted 10 lines · Christophe Leroy
Quoted 9 lines
Le 16/04/2021 à 11:28, Steven Price a écrit :
Quoted 3 lines · Christophe Leroy
To be honest I don't fully understand why powerpc requires the
page_size- it appears to be using it purely to find "holes" in the calls tonote_page(), but I haven't worked out why such holes would occur.I was indeed introduced for KASAN. We have a first commit https://github.com/torvalds/linux/commit/cabe8138 which uses page size to detect whether it is a KASAN like stuff.
Quoted 8 lines
Quoted 1 line
Then came https://github.com/torvalds/linux/commit/b00ff6d8c as a fix. I can't remember what the problem was exactly, something around the use of hugepages for kernel memory, came as part of the series https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/
Ah, that's useful context. So it looks like powerpc took a different route to reducing the KASAN output to x86.
Given the generic ptdump code has handling for KASAN already it should be possible to drop that from the powerpc arch code, which I think means we don't actually need to provide page size to
notepage(). Hopefully that means more code to delete ;)
Quoted 8 lines
Looking at how the generic ptdump code handles KASAN, I'm a bit sceptic.
IIUC, it is checking that
kasan_early_shadow_pteis in the same page as the pgtable referred by the PMD entry. But what happens if that PMD entry is referring another pgtable which is inside the same page askasan_early_shadow_pte?Shouldn't the test be
if (
pmd_page_vaddr(val)==lm_alias(kasan_early_shadow_pte)) returnnote_kasan_page_table(walk, addr);
Now I come to look at this code again, I think you're right. On arm64 this doesn't cause a problem - page tables are page sized and page aligned, so there couldn't be any non-KASAN pgtables sharing the page. Obviously that's not necessarily true of other architectures.
Feel free to add a patch to your series ;)
Steve
Re: [PATCH v1 3/5] mm: ptdump: Provide page size to notepage()
Le 19/04/2021 à 16:00, Steven Price a écrit :
Quoted 28 lines · Christophe Leroy
Quoted 27 lines
Le 16/04/2021 à 12:51, Steven Price a écrit :
Quoted 10 lines · Christophe Leroy
Quoted 9 lines
Le 16/04/2021 à 11:28, Steven Price a écrit :
Quoted 3 lines · Christophe Leroy
To be honest I don't fully understand why powerpc requires the
page_size- it appears to be using it purely to find "holes" in the calls tonote_page(), but I haven't worked out why such holes would occur.I was indeed introduced for KASAN. We have a first commit https://github.com/torvalds/linux/commit/cabe8138 which uses page size to detect whether it is a KASAN like stuff.
Quoted 9 lines
Quoted 1 line
Then came https://github.com/torvalds/linux/commit/b00ff6d8c as a fix. I can't remember what the problem was exactly, something around the use of hugepages for kernel memory, came as part of the series https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/
Ah, that's useful context. So it looks like powerpc took a different route to reducing the KASAN output to x86.
Given the generic ptdump code has handling for KASAN already it should be possible to drop that from the powerpc arch code, which I think means we don't actually need to provide page size to
notepage(). Hopefully that means more code to delete ;)Looking at how the generic ptdump code handles KASAN, I'm a bit sceptic.
IIUC, it is checking that
kasan_early_shadow_pteis in the same page as the pgtable referred by the PMD entry. But what happens if that PMD entry is referring another pgtable which is inside the same page askasan_early_shadow_pte?
Quoted 9 lines
Quoted 4 lines
Shouldn't the test be
if (
pmd_page_vaddr(val)==lm_alias(kasan_early_shadow_pte)) returnnote_kasan_page_table(walk, addr);Now I come to look at this code again, I think you're right. On arm64 this doesn't cause a problem - page tables are page sized and page aligned, so there couldn't be any non-KASAN pgtables sharing the page. Obviously that's not necessarily true of other architectures.
Feel free to add a patch to your series ;)
Ok.
I'll leave that outside of the series, it is not a show stopper because early shadow page directories are all tagged __bss_page_aligned so we can't have two of them in the same page and it is really unlikely that we'll have any other statically defined page directory in the same pages either.
And for the special case of powerpc 8xx which is the only one for which we have both KASAN and HUGEPD at the time being, there are only two levels of page directories so no issue.
Christophe