Convert powerpc to GENERIC_PTDUMP
Subsystems (4)
v2 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.
v2:
- Reworked the pagewalk modification to add locking and check ops->pte_entry
- Modified powerpc early IO mapping to have gaps between mappings
- Removed the logic that checked for contiguous physical memory
- Removed the articial level calculation in ptdump_pte_entry(), level 4 is ok for all.
- Removed page_size argument to note_page()
Christophe Leroy (4):
mm: pagewalk: Fix walk for hugepage tables powerpc/mm: Leave a gap between early allocated IO areas powerpc/mm: Properly coalesce pages in ptdump powerpc/mm: Convert powerpc to GENERIC_PTDUMP
arch/powerpc/Kconfig | 2 + arch/powerpc/Kconfig.debug | 30 ----- arch/powerpc/mm/Makefile | 2 +- arch/powerpc/mm/ioremap_32.c | 4 +- arch/powerpc/mm/ioremap_64.c | 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 | 187 ++++++++---------------------- arch/powerpc/mm/ptdump/shared.c | 6 +- mm/pagewalk.c | 58 ++++++++- 12 files changed, 127 insertions(+), 187 deletions(-)
Signature · 1 line
2.25.0
PATCH v2 1/4 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.
---
v2:
- Add a guard for NULL ops->pte_entry
- Take mm->page_table_lock when walking hugepage table, as suggested by follow_huge_pd()
--- mm/pagewalk.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-)
mm/pagewalk.c +53 -5
@@ -58,6 +58,45 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,return err; } +#ifdef CONFIG_ARCH_HAS_HUGEPD +static int walk_hugepd_range (hugepd_t *phpd,unsigned long addr, +unsigned long end,struct mm_walk *walk,int pdshift) +{ +int err =0 ; +const struct mm_walk_ops *ops = walk->ops; +int shift =hugepd_shift (*phpd); +int page_size =1 << shift; + +if (!ops->pte_entry) +return 0 ; + +if (addr & (page_size -1 )) +return 0 ; + +for (;;) { +pte_t *pte; + +spin_lock (&walk->mm->page_table_lock); + pte =hugepte_offset (*phpd, addr, pdshift); + err = ops->pte_entry (pte, addr, addr + page_size, walk); +spin_unlock (&walk->mm->page_table_lock); + +if (err) +break ; +if (addr >= end - page_size) +break ; + addr += page_size; + } +return err; +} +#else +static int walk_hugepd_range (hugepd_t *phpd,unsigned long addr, +unsigned long end,struct mm_walk *walk,int pdshift) +{ +return 0 ; +} +#endif +static int walk_pmd_range (pud_t *pud,unsigned long addr,unsigned long end,struct mm_walk *walk) {
@@ -108,7 +147,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 +199,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,7 +234,9 @@ 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) +if (is_hugepd (__hugepd (p4d_val (*p4d)))) + err =walk_hugepd_range ((hugepd_t *)p4d, addr, next, walk,P4D_SHIFT ); +else if (ops->pud_entry || ops->pmd_entry || ops->pte_entry) err =walk_pud_range (p4d, addr, next, walk);if (err)break ;
@@ -224,8 +271,9 @@ static int walk_pgd_range(unsigned long addr, unsigned long end,if (err)break ; } -if (ops->p4d_entry || ops->pud_entry || ops->pmd_entry || - ops->pte_entry) +if (is_hugepd (__hugepd (pgd_val (*pgd)))) + err =walk_hugepd_range ((hugepd_t *)pgd, addr, next, walk,PGDIR_SHIFT ); +else if (ops->p4d_entry || ops->pud_entry || ops->pmd_entry || ops->pte_entry) err =walk_p4d_range (pgd, addr, next, walk);if (err)break ;
Signature · 1 line
2.25.0
Re: [PATCH v2 1/4] mm: pagewalk: Fix walk for hugepage tables
Quoted 6 lines · Christophe Leroy
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]>
Looks correct to me, sadly I don't have a suitable system to test it.
Quoted 106 lines
---
v2:
- Add a guard for NULLops->pte_entry
- Takemm->page_table_lockwhen walking hugepage table, as suggested byfollow_huge_pd()--- mm/pagewalk.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-)mm/pagewalk.c +53
-5@@ -58,6 +58,45 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,return err; } +#ifdef CONFIG_ARCH_HAS_HUGEPD +static int walk_hugepd_range (hugepd_t *phpd,unsigned long addr, +unsigned long end,struct mm_walk *walk,int pdshift) +{ +int err =0 ; +const struct mm_walk_ops *ops = walk->ops; +int shift =hugepd_shift (*phpd); +int page_size =1 << shift; + +if (!ops->pte_entry) +return 0 ; + +if (addr & (page_size -1 )) +return 0 ; + +for (;;) { +pte_t *pte; + +spin_lock (&walk->mm->page_table_lock); + pte =hugepte_offset (*phpd, addr, pdshift); + err = ops->pte_entry (pte, addr, addr + page_size, walk); +spin_unlock (&walk->mm->page_table_lock); + +if (err) +break ; +if (addr >= end - page_size) +break ; + addr += page_size; + } +return err; +} +#else +static int walk_hugepd_range (hugepd_t *phpd,unsigned long addr, +unsigned long end,struct mm_walk *walk,int pdshift) +{ +return 0 ; +} +#endif +static int walk_pmd_range (pud_t *pud,unsigned long addr,unsigned long end,struct mm_walk *walk) {@@ -108,7 +147,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 +199,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,7 +234,9 @@ 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) +if (is_hugepd (__hugepd (p4d_val (*p4d)))) + err =walk_hugepd_range ((hugepd_t *)p4d, addr, next, walk,P4D_SHIFT ); +else if (ops->pud_entry || ops->pmd_entry || ops->pte_entry) err =walk_pud_range (p4d, addr, next, walk);if (err)break ;@@ -224,8 +271,9 @@ static int walk_pgd_range(unsigned long addr, unsigned long end,if (err)break ; } -if (ops->p4d_entry || ops->pud_entry || ops->pmd_entry || - ops->pte_entry) +if (is_hugepd (__hugepd (pgd_val (*pgd)))) + err =walk_hugepd_range ((hugepd_t *)pgd, addr, next, walk,PGDIR_SHIFT ); +else if (ops->p4d_entry || ops->pud_entry || ops->pmd_entry || ops->pte_entry) err =walk_p4d_range (pgd, addr, next, walk);if (err)break ;
Re: [PATCH v2 1/4] mm: pagewalk: Fix walk for hugepage tables
In reply to Christophe LeroyHi Michael,
Le 19/04/2021 à 12:47, Christophe Leroy a écrit :
Quoted 4 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.
I see you took patch 2 and 3 of the series.
Do you expect Andrew to take patch 1 via mm tree, and then you'll take patch 4 once mm tree is merged ?
Christophe
Quoted 108 lines
Signed-off-by Christophe Leroy <[email protected]>---
v2:
- Add a guard for NULLops->pte_entry
- Takemm->page_table_lockwhen walking hugepage table, as suggested byfollow_huge_pd()--- mm/pagewalk.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-)mm/pagewalk.c +53
-5@@ -58,6 +58,45 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,return err; } +#ifdef CONFIG_ARCH_HAS_HUGEPD +static int walk_hugepd_range (hugepd_t *phpd,unsigned long addr, +unsigned long end,struct mm_walk *walk,int pdshift) +{ +int err =0 ; +const struct mm_walk_ops *ops = walk->ops; +int shift =hugepd_shift (*phpd); +int page_size =1 << shift; + +if (!ops->pte_entry) +return 0 ; + +if (addr & (page_size -1 )) +return 0 ; + +for (;;) { +pte_t *pte; + +spin_lock (&walk->mm->page_table_lock); + pte =hugepte_offset (*phpd, addr, pdshift); + err = ops->pte_entry (pte, addr, addr + page_size, walk); +spin_unlock (&walk->mm->page_table_lock); + +if (err) +break ; +if (addr >= end - page_size) +break ; + addr += page_size; + } +return err; +} +#else +static int walk_hugepd_range (hugepd_t *phpd,unsigned long addr, +unsigned long end,struct mm_walk *walk,int pdshift) +{ +return 0 ; +} +#endif +static int walk_pmd_range (pud_t *pud,unsigned long addr,unsigned long end,struct mm_walk *walk) {@@ -108,7 +147,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 +199,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,7 +234,9 @@ 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) +if (is_hugepd (__hugepd (p4d_val (*p4d)))) + err =walk_hugepd_range ((hugepd_t *)p4d, addr, next, walk,P4D_SHIFT ); +else if (ops->pud_entry || ops->pmd_entry || ops->pte_entry) err =walk_pud_range (p4d, addr, next, walk);if (err)break ;@@ -224,8 +271,9 @@ static int walk_pgd_range(unsigned long addr, unsigned long end,if (err)break ; } -if (ops->p4d_entry || ops->pud_entry || ops->pmd_entry || - ops->pte_entry) +if (is_hugepd (__hugepd (pgd_val (*pgd)))) + err =walk_hugepd_range ((hugepd_t *)pgd, addr, next, walk,PGDIR_SHIFT ); +else if (ops->p4d_entry || ops->pud_entry || ops->pmd_entry || ops->pte_entry) err =walk_p4d_range (pgd, addr, next, walk);if (err)break ;
Michael Ellerman
reviewerRe: [PATCH v2 1/4] mm: pagewalk: Fix walk for hugepage tables
Quoted 9 lines · Christophe Leroy
Hi Michael,
Le 19/04/2021 à 12:47, Christophe Leroy a écrit :
Quoted 4 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.I see you took patch 2 and 3 of the series.
Yeah I decided those were bug fixes so could be taken separately.
Quoted 2 lines
Do you expect Andrew to take patch 1 via mm tree, and then you'll take patch 4 once mm tree is merged ?
I didn't feel I could take patch 1 via the powerpc tree without risking conflicts.
Andrew could take patch 1 and 4 via mm, though he might not want to pick them up this late.
I guess step one would be to repost 1 and 4 as a new series. Either they can go via mm, or for 5.15 I could probably take them both as long as I pick them up early enough.
cheers
Re: [PATCH v2 1/4] mm: pagewalk: Fix walk for hugepage tables
Le 25/06/2021 à 06:45, Michael Ellerman a écrit :
Quoted 13 lines
Quoted 9 lines · Christophe Leroy
Hi Michael,
Le 19/04/2021 à 12:47, Christophe Leroy a écrit :
Quoted 4 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.I see you took patch 2 and 3 of the series.
Yeah I decided those were bug fixes so could be taken separately.
Quoted 8 lines
Quoted 2 lines
Do you expect Andrew to take patch 1 via mm tree, and then you'll take patch 4 once mm tree is merged ?
I didn't feel I could take patch 1 via the powerpc tree without risking conflicts.
Andrew could take patch 1 and 4 via mm, though he might not want to pick them up this late.
Patch 4 needs patches 2 and 3 and doesn't apply without them so it is not that easy.
Maybe Andrew you can take patch 1 now and then Michael you can take patch 4 at anytime during 5.15 preparation without any conflict risk ?
Quoted 5 lines
I guess step one would be to repost 1 and 4 as a new series. Either they can go via mm, or for 5.15 I could probably take them both as long as I pick them up early enough.
I'll first repost patch 1 as standalone and see what happens.
Christophe
Michael Ellerman
reviewerRe: [PATCH v2 1/4] mm: pagewalk: Fix walk for hugepage tables
Quoted 17 lines · Christophe Leroy
Le 25/06/2021 à 06:45, Michael Ellerman a écrit :
Quoted 16 lines
Quoted 9 lines · Christophe Leroy
Hi Michael,
Le 19/04/2021 à 12:47, Christophe Leroy a écrit :
Quoted 4 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.I see you took patch 2 and 3 of the series.
Yeah I decided those were bug fixes so could be taken separately.
Quoted 2 lines
Do you expect Andrew to take patch 1 via mm tree, and then you'll take patch 4 once mm tree is merged ?
Quoted 7 lines
Quoted 5 lines
I didn't feel I could take patch 1 via the powerpc tree without risking conflicts.
Andrew could take patch 1 and 4 via mm, though he might not want to pick them up this late.
Patch 4 needs patches 2 and 3 and doesn't apply without them so it is not that easy.
Ah duh, sorry.
Quoted 2 lines
Maybe Andrew you can take patch 1 now and then Michael you can take patch 4 at anytime during 5.15 preparation without any conflict risk ?
Yeah that would work.
Quoted 6 lines
Quoted 4 lines
I guess step one would be to repost 1 and 4 as a new series. Either they can go via mm, or for 5.15 I could probably take them both as long as I pick them up early enough.
I'll first repost patch 1 as standalone and see what happens.
Thanks.
cheers
PATCH v2 2/4 powerpc/mm: Leave a gap between early allocated IO areas
In reply to Christophe LeroyVmalloc system leaves a gap between allocated areas. It helps catching overflows.
Do the same for IO areas which are allocated with early_ioremap_range() until slab_is_available().
--- arch/powerpc/mm/ioremap_32.c | 4 ++-- arch/powerpc/mm/ioremap_64.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/mm/ioremap_32.c +2 -2
@@ -70,10 +70,10 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, pgprot_t prot, void *call*/ pr_warn ("ioremap() called early from %pS. Use early_ioremap() instead\n" , caller); - err =early_ioremap_range (ioremap_bot - size, p, size, prot); + err =early_ioremap_range (ioremap_bot - size -PAGE_SIZE , p, size, prot);if (err)return NULL ; - ioremap_bot -= size; + ioremap_bot -= size +PAGE_SIZE ;return (void __iomem *)ioremap_bot + offset; }
arch/powerpc/mm/ioremap_64.c +1 -1
@@ -38,7 +38,7 @@ void __iomem *__ioremap_caller(phys_addr_t addr, unsigned long size,return NULL ; ret = (void __iomem *)ioremap_bot + offset; - ioremap_bot += size; + ioremap_bot += size +PAGE_SIZE ;return ret; }
Signature · 1 line
2.25.0
PATCH v2 3/4 powerpc/mm: Properly coalesce pages in ptdump
In reply to Christophe LeroyCommit aaa229529244 ("powerpc/mm: Add physical address to Linux page table dump") changed range coalescing to only combine ranges that are both virtually and physically contiguous, in order to avoid erroneous combination of unrelated mappings in IOREMAP space.
But in the VMALLOC space, mappings almost never have contiguous physical pages, so the commit mentionned above leads to dumping one line per page for vmalloc mappings.
Taking into account the vmalloc always leave a gap between two areas, we never have two mappings dumped as a single combination even if they have the exact same flags. The only space that may have encountered such an issue was the early IOREMAP which is not using vmalloc engine. But previous commits added gaps between early IO mappings, so it is not an issue anymore.
That commit created some difficulties with KASAN mappings, see commit cabe8138b23c ("powerpc: dump as a single line areas mapping a single physical page.") and with huge page, see
commit b00ff6d8c1c3 ("powerpc/ptdump: Properly handle non standard page size").
So, almost revert commit aaa229529244 to properly coalesce pages mapped with the same flags as before, only keep the display of the first physical address of the range, as it can be usefull especially for IO mappings.
It brings back powerpc at the same level as other architectures and simplifies the conversion to GENERIC PTDUMP.
With the patch:
---[ kasan shadow mem start ]---
0xf8000000-0xf8ffffff 0x07000000 16M huge rw present dirty accessed 0xf9000000-0xf91fffff 0x01434000 2M r present accessed 0xf9200000-0xf95affff 0x02104000 3776K rw present dirty accessed 0xfef5c000-0xfeffffff 0x01434000 656K r present accessed
---[ kasan shadow mem end ]---
Before:
---[ kasan shadow mem start ]---
0xf8000000-0xf8ffffff 0x07000000 16M huge rw present dirty accessed 0xf9000000-0xf91fffff 0x01434000 16K r present accessed 0xf9200000-0xf9203fff 0x02104000 16K rw present dirty accessed 0xf9204000-0xf9207fff 0x0213c000 16K rw present dirty accessed 0xf9208000-0xf920bfff 0x02174000 16K rw present dirty accessed 0xf920c000-0xf920ffff 0x02188000 16K rw present dirty accessed 0xf9210000-0xf9213fff 0x021dc000 16K rw present dirty accessed 0xf9214000-0xf9217fff 0x02220000 16K rw present dirty accessed 0xf9218000-0xf921bfff 0x023c0000 16K rw present dirty accessed 0xf921c000-0xf921ffff 0x023d4000 16K rw present dirty accessed 0xf9220000-0xf9227fff 0x023ec000 32K rw present dirty accessed ... 0xf93b8000-0xf93e3fff 0x02614000 176K rw present dirty accessed 0xf93e4000-0xf94c3fff 0x027c0000 896K rw present dirty accessed 0xf94c4000-0xf94c7fff 0x0236c000 16K rw present dirty accessed 0xf94c8000-0xf94cbfff 0x041f0000 16K rw present dirty accessed 0xf94cc000-0xf94cffff 0x029c0000 16K rw present dirty accessed 0xf94d0000-0xf94d3fff 0x041ec000 16K rw present dirty accessed 0xf94d4000-0xf94d7fff 0x0407c000 16K rw present dirty accessed 0xf94d8000-0xf94f7fff 0x041c0000 128K rw present dirty accessed ... 0xf95ac000-0xf95affff 0x042b0000 16K rw present dirty accessed 0xfef5c000-0xfeffffff 0x01434000 16K r present accessed
---[ kasan shadow mem end ]---
--- arch/powerpc/mm/ptdump/ptdump.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)
arch/powerpc/mm/ptdump/ptdump.c +3 -19
@@ -58,8 +58,6 @@ struct pg_state {const struct addr_marker *marker;unsigned long start_address;unsigned long start_pa; -unsigned long last_pa; -unsigned long page_size;unsigned int level;u64 current_flags;bool check_wx;
@@ -163,8 +161,6 @@ static void dump_flag_info(struct pg_state *st, const struct flag_infostatic void dump_addr (struct pg_state *st,unsigned long addr) { -unsigned long delta; -#ifdef CONFIG_PPC64 #define REG "0x%016lx"#else
@@ -172,14 +168,8 @@ static void dump_addr(struct pg_state *st, unsigned long addr)#endif pt_dump_seq_printf (st->seq,REG "-" REG " " , st->start_address, addr -1 ); -if (st->start_pa == st->last_pa && st->start_address + st->page_size != addr) { -pt_dump_seq_printf (st->seq,"[" REG "]" , st->start_pa); - delta = st->page_size >>10 ; - }else { -pt_dump_seq_printf (st->seq," " REG " " , st->start_pa); - delta = (addr - st->start_address) >>10 ; - } -pt_dump_size (st->seq, delta); +pt_dump_seq_printf (st->seq," " REG " " , st->start_pa); +pt_dump_size (st->seq, (addr - st->start_address) >>10 ); }static void note_prot_wx (struct pg_state *st,unsigned long addr)
@@ -208,7 +198,6 @@ static void note_page_update_state(struct pg_state *st, unsigned long addr, st->current_flags = flag; st->start_address = addr; st->start_pa = pa; - st->page_size = page_size;while (addr >= st->marker[1 ].start_address) { st->marker++;
@@ -220,7 +209,6 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned int level, u64 val, unsigned long page_size) { u64 flag = val & pg_level[level].mask; -u64 pa = val &PTE_RPN_MASK ;/* At first no level is set */ if (!st->level) {
@@ -232,12 +220,9 @@ static void note_page(struct pg_state *st, unsigned long addr,* - we change levels in the tree. * - the address is in a different section of memory and is thus * used for a different purpose, regardless of the flags. -* - the pa of this page is not adjacent to the last inspected page */ }else if (flag != st->current_flags || level != st->level || - addr >= st->marker[1 ].start_address || - (pa != st->last_pa + st->page_size && - (pa != st->start_pa || st->start_pa != st->last_pa))) { + addr >= st->marker[1 ].start_address) {/* Check the PTE flags */ if (st->current_flags) {
@@ -259,7 +244,6 @@ static void note_page(struct pg_state *st, unsigned long addr,*/ note_page_update_state (st, addr, level, val, page_size); } - st->last_pa = pa; }static void walk_pte (struct pg_state *st,pmd_t *pmd,unsigned long start)
Signature · 1 line
2.25.0
PATCH v2 4/4 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 | 165 ++++++++---------------------- arch/powerpc/mm/ptdump/shared.c | 6 +- 9 files changed, 68 insertions(+), 160 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 -120
243 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
Quoted 5 lines · Christophe Leroy
This series converts powerpc to generic PTDUMP.
For that, we first need to add missing hugepd support to pagewalk and ptdump.
Quoted 8 lines
v2:
- Reworked the pagewalk modification to add locking and checkops->pte_entry
- Modified powerpc early IO mapping to have gaps between mappings
- Removed the logic that checked for contiguous physical memory
- Removed the articial level calculation inptdump_pte_entry(), level 4 is ok for all.
- Removedpage_sizeargument tonote_page()[...]
Patches 2 and 4 pplied to powerpc/next.
[2/4] powerpc/mm: Leave a gap between early allocated IO areas
https://git.kernel.org/powerpc/c/57307f1b6edd781fba2bf9f7ec5f4d17a881ea54 [3/4] powerpc/mm: Properly coalesce pages in ptdump https://git.kernel.org/powerpc/c/6ca6512c716afd6e37281372c4c35aa6afd71d10
cheers