powerpc/mm: enable memory hotplug on radix
v5 cover powerpc/mm: enable memory hotplug on radix
Do the plumbing needed for memory hotplug on systems using radix pagetables, borrowing from existing vmemmap and x86 code.
This passes basic verification of plugging and removing memory, but this stuff is tricky and I'd appreciate extra scrutiny of the series for correctness--in particular, the adaptation of remove_pagetable() from x86.
Former patch 1 is now a separate fix. This set still depends on it:
https://lkml.kernel.org/r/[email protected]
/* changelog */
v5:
* Retain pr_info() of the size used to map each address range.
* flush_tlb_kernel_range() -> radix__flush_tlb_kernel_range()
v4:
* https://lkml.kernel.org/r/[email protected]
* Sent patch 1 as a standalone fix.
* Extract a common function that can be used by both radix_init_pgtable() and radix__create_section_mapping().
* Reduce tlb flushing to one flush_tlb_kernel_range() per section, and do less granular locking of init_mm->page_table_lock.
v3:
* https://lkml.kernel.org/r/[email protected]
* Port remove_pagetable() et al. from x86 for unmapping.
* [RFC] -> [PATCH]
v2:
* https://lkml.kernel.org/r/[email protected]
* Do not simply fall through to vmemmap_{create,remove}_mapping(). As Aneesh and Michael pointed out, they are tied to CONFIG_SPARSEMEM_VMEMMAP and only did what I needed by luck anyway.
v1:
* https://lkml.kernel.org/r/[email protected]
Reza Arbab (4):
powerpc/mm: refactor radix physical page mapping powerpc/mm: add radix__create_section_mapping() powerpc/mm: add radix__remove_section_mapping() powerpc/mm: unstub radix__vmemmap_remove_mapping()
arch/powerpc/include/asm/book3s/64/radix.h | 5 + arch/powerpc/mm/pgtable-book3s64.c | 4 +- arch/powerpc/mm/pgtable-radix.c | 257 ++++++++++++++++++++++++----- 3 files changed, 225 insertions(+), 41 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v5 1/4 powerpc/mm: refactor radix physical page mapping
Move the page mapping code in radix_init_pgtable() into a separate function that will also be used for memory hotplug.
The current goto loop progressively decreases its mapping size as it covers the tail of a range whose end is unaligned. Change this to a for loop which can do the same for both ends of the range.
--- arch/powerpc/mm/pgtable-radix.c | 88 +++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 38 deletions(-)
arch/powerpc/mm/pgtable-radix.c +50 -38
@@ -107,54 +107,66 @@ int radix__map_kernel_page(unsigned long ea, unsigned long pa,return 0 ; } +static inline void __meminit print_mapping (unsigned long start, +unsigned long end, +unsigned long size) +{ +if (end <= start) +return ; + +pr_info ("Mapped range 0x%lx - 0x%lx with 0x%lx\n" , start, end, size); +} + +static int __meminit create_physical_mapping (unsigned long start, +unsigned long end) +{ +unsigned long addr, mapping_size; + + start =_ALIGN_UP (start,PAGE_SIZE ); +for (addr = start; addr < end; addr += mapping_size) { +unsigned long gap, previous_size; +int rc; + + gap = end - addr; + previous_size = mapping_size; + +if (IS_ALIGNED (addr,PUD_SIZE ) && gap >=PUD_SIZE && + mmu_psize_defs[MMU_PAGE_1G ].shift) + mapping_size =PUD_SIZE ; +else if (IS_ALIGNED (addr,PMD_SIZE ) && gap >=PMD_SIZE && + mmu_psize_defs[MMU_PAGE_2M ].shift) + mapping_size =PMD_SIZE ; +else + mapping_size =PAGE_SIZE ; + +if (mapping_size != previous_size) { +print_mapping (start, addr, previous_size); + start = addr; + } + + rc =radix__map_kernel_page ((unsigned long )__va (addr), addr, +PAGE_KERNEL_X , mapping_size); +if (rc) +return rc; + } + +print_mapping (start, addr, mapping_size); +return 0 ; +} +static void __init radix_init_pgtable (void ) { -int loop_count; -u64 base, end, start_addr;unsigned long rts_field;struct memblock_region *reg; -unsigned long linear_page_size;/* We don't support slb for radix */ mmu_slb_size =0 ;/* * Create the linear mapping, using standard page size for now */ - loop_count =0 ; -for_each_memblock (memory, reg) { - - start_addr = reg->base; - -redo: -if (loop_count <1 && mmu_psize_defs[MMU_PAGE_1G ].shift) - linear_page_size =PUD_SIZE ; -else if (loop_count <2 && mmu_psize_defs[MMU_PAGE_2M ].shift) - linear_page_size =PMD_SIZE ; -else - linear_page_size =PAGE_SIZE ; - - base =_ALIGN_UP (start_addr, linear_page_size); - end =_ALIGN_DOWN (reg->base + reg->size, linear_page_size); - -pr_info ("Mapping range 0x%lx - 0x%lx with 0x%lx\n" , - (unsigned long )base, (unsigned long )end, - linear_page_size); - -while (base < end) { -radix__map_kernel_page ((unsigned long )__va (base), - base,PAGE_KERNEL_X , - linear_page_size); - base += linear_page_size; - } -/* -* map the rest using lower page size -*/ -if (end < reg->base + reg->size) { - start_addr = end; - loop_count++; - goto redo; - } - } +for_each_memblock (memory, reg) +WARN_ON (create_physical_mapping (reg->base, + reg->base + reg->size));/* * Allocate Partition table and process table for the * host.
Signature · 1 line
1.8.3.1
PATCH v5 2/4 powerpc/mm: add radix__create_section_mapping()
In reply to Reza ArbabWire up memory hotplug page mapping for radix. Share the mapping function already used by radix_init_pgtable().
--- arch/powerpc/include/asm/book3s/64/radix.h | 4 ++++ arch/powerpc/mm/pgtable-book3s64.c | 2 +- arch/powerpc/mm/pgtable-radix.c | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/radix.h +4 -0
@@ -291,5 +291,9 @@ static inline unsigned long radix__get_tree_size(void) }return rts_field; } + +#ifdef CONFIG_MEMORY_HOTPLUG +int radix__create_section_mapping (unsigned long start,unsigned long end); +#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* __ASSEMBLY__ */ #endif
arch/powerpc/mm/pgtable-book3s64.c +1 -1
@@ -131,7 +131,7 @@ void mmu_cleanup_all(void)int create_section_mapping (unsigned long start,unsigned long end) {if (radix_enabled ()) -return -ENODEV ; +return radix__create_section_mapping (start, end);return hash__create_section_mapping (start, end); }
arch/powerpc/mm/pgtable-radix.c +7 -0
@@ -475,6 +475,13 @@ void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base,memblock_set_current_limit (first_memblock_base + first_memblock_size); } +#ifdef CONFIG_MEMORY_HOTPLUG +int __ref radix__create_section_mapping (unsigned long start,unsigned long end) +{ +return create_physical_mapping (start, end); +} +#endif /* CONFIG_MEMORY_HOTPLUG */ +#ifdef CONFIG_SPARSEMEM_VMEMMAP int __meminit radix__vmemmap_create_mapping(unsigned long start, unsigned long page_size,
Signature · 1 line
1.8.3.1
PATCH v5 3/4 powerpc/mm: add radix__remove_section_mapping()
In reply to Reza ArbabTear down and free the four-level page tables of physical mappings during memory hotremove.
Borrow the basic structure of remove_pagetable() and friends from the identically-named x86 functions. Reduce the frequency of tlb flushes and page_table_lock spinlocks by only doing them in the outermost function. There was some question as to whether the locking is needed at all. Leave it for now, but we could consider dropping it.
Memory must be offline to be removed, thus not in use. So there shouldn't be the sort of concurrent page walking activity here that might prompt us to use RCU.
--- arch/powerpc/include/asm/book3s/64/radix.h | 1 + arch/powerpc/mm/pgtable-book3s64.c | 2 +- arch/powerpc/mm/pgtable-radix.c | 133 +++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/radix.h +1 -0
@@ -294,6 +294,7 @@ static inline unsigned long radix__get_tree_size(void)#ifdef CONFIG_MEMORY_HOTPLUG int radix__create_section_mapping (unsigned long start,unsigned long end); +int radix__remove_section_mapping (unsigned long start,unsigned long end);#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* __ASSEMBLY__ */ #endif
arch/powerpc/mm/pgtable-book3s64.c +1 -1
@@ -139,7 +139,7 @@ int create_section_mapping(unsigned long start, unsigned long end)int remove_section_mapping (unsigned long start,unsigned long end) {if (radix_enabled ()) -return -ENODEV ; +return radix__remove_section_mapping (start, end);return hash__remove_section_mapping (start, end); }
arch/powerpc/mm/pgtable-radix.c +133 -0
143 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 4/4 powerpc/mm: unstub radix__vmemmap_remove_mapping()
In reply to Reza ArbabUse remove_pagetable() and friends for radix vmemmap removal.
We do not require the special-case handling of vmemmap done in the x86 versions of these functions. This is because vmemmap_free() has already freed the mapped pages, and calls us with an aligned address range.
So, add a few failsafe WARNs, but otherwise the code to remove physical mappings is already sufficient for vmemmap.
--- arch/powerpc/mm/pgtable-radix.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
arch/powerpc/mm/pgtable-radix.c +28 -1
@@ -521,6 +521,15 @@ static void remove_pte_table(pte_t *pte_start, unsigned long addr,if (!pte_present (*pte))continue ; +if (!PAGE_ALIGNED (addr) || !PAGE_ALIGNED (next)) { +/* +* The vmemmap_free() and remove_section_mapping() +* codepaths call us with aligned addresses. +*/ +WARN_ONCE (1 ,"%s: unaligned range\n" , __func__); +continue ; + } +pte_clear (&init_mm, addr, pte); } }
@@ -540,6 +549,12 @@ static void remove_pmd_table(pmd_t *pmd_start, unsigned long addr,continue ;if (pmd_huge (*pmd)) { +if (!IS_ALIGNED (addr,PMD_SIZE ) || + !IS_ALIGNED (next,PMD_SIZE )) { +WARN_ONCE (1 ,"%s: unaligned range\n" , __func__); +continue ; + } +pte_clear (&init_mm, addr, (pte_t *)pmd);continue ; }
@@ -565,6 +580,12 @@ static void remove_pud_table(pud_t *pud_start, unsigned long addr,continue ;if (pud_huge (*pud)) { +if (!IS_ALIGNED (addr,PUD_SIZE ) || + !IS_ALIGNED (next,PUD_SIZE )) { +WARN_ONCE (1 ,"%s: unaligned range\n" , __func__); +continue ; + } +pte_clear (&init_mm, addr, (pte_t *)pud);continue ; }
@@ -591,6 +612,12 @@ static void remove_pagetable(unsigned long start, unsigned long end)continue ;if (pgd_huge (*pgd)) { +if (!IS_ALIGNED (addr,PGDIR_SIZE ) || + !IS_ALIGNED (next,PGDIR_SIZE )) { +WARN_ONCE (1 ,"%s: unaligned range\n" , __func__); +continue ; + } +pte_clear (&init_mm, addr, (pte_t *)pgd);continue ; }
@@ -630,7 +657,7 @@ int __meminit radix__vmemmap_create_mapping(unsigned long start,#ifdef CONFIG_MEMORY_HOTPLUG void radix__vmemmap_remove_mapping (unsigned long start,unsigned long page_size) { -/* FIXME!! intel does more. We should free page tables mapping vmemmap ? */ +remove_pagetable (start, start + page_size); }#endif #endif
Signature · 1 line
1.8.3.1
Re: [PATCH v5 1/4] powerpc/mm: refactor radix physical page mapping
In reply to Reza ArbabQuoted 17 lines · Reza Arbab
Move the page mapping code in
radix_init_pgtable()into a separate function that will also be used for memory hotplug.The current goto loop progressively decreases its mapping size as it covers the tail of a range whose end is unaligned. Change this to a for loop which can do the same for both ends of the range.
Signed-off-by Reza Arbab <[email protected]>--- arch/powerpc/mm/pgtable-radix.c | 88 +++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 38 deletions(-)arch/powerpc/mm/pgtable-radix.c +0
-0
arch/powerpc/mm/pgtable-radix.c int radix__map_kernel_page(unsigned long ea, unsigned long pa, · line 115
Quoted 9 lines
arch/powerpc/mm/pgtable-radix.c +6
-0@@ -107,54 +107,66 @@ int radix__map_kernel_page(unsigned long ea, unsigned long pa,return 0 ; } +static inline void __meminit print_mapping (unsigned long start, +unsigned long end, +unsigned long size) +{ +if (end <= start) +return ;
Should we pr_err for start > end?
Quoted 25 lines
arch/powerpc/mm/pgtable-radix.c +25
-0+ +pr_info ("Mapped range 0x%lx - 0x%lx with 0x%lx\n" , start, end, size); +} + +static int __meminit create_physical_mapping (unsigned long start, +unsigned long end) +{ +unsigned long addr, mapping_size; + + start =_ALIGN_UP (start,PAGE_SIZE ); +for (addr = start; addr < end; addr += mapping_size) { +unsigned long gap, previous_size; +int rc; + + gap = end - addr; + previous_size = mapping_size; + +if (IS_ALIGNED (addr,PUD_SIZE ) && gap >=PUD_SIZE && + mmu_psize_defs[MMU_PAGE_1G ].shift) + mapping_size =PUD_SIZE ; +else if (IS_ALIGNED (addr,PMD_SIZE ) && gap >=PMD_SIZE && + mmu_psize_defs[MMU_PAGE_2M ].shift) + mapping_size =PMD_SIZE ; +else + mapping_size =PAGE_SIZE ;
arch/powerpc/mm/pgtable-radix.c int radix__map_kernel_page(unsigned long ea, unsigned long pa, · line 150
Quoted 10 lines
arch/powerpc/mm/pgtable-radix.c +10
-0+ +if (mapping_size != previous_size) { +print_mapping (start, addr, previous_size); + start = addr; + } + + rc =radix__map_kernel_page ((unsigned long )__va (addr), addr, +PAGE_KERNEL_X , mapping_size); +if (rc) +return rc;
Should we try a lower page size if map_kernel_page fails for this mapping_size? I like the cleanup very much, BTW
Balbir Singh.
Re: [PATCH v5 2/4] powerpc/mm: add radix__create_section_mapping()
In reply to Reza ArbabQuoted 5 lines · Reza Arbab
Wire up memory hotplug page mapping for radix. Share the mapping function already used by
radix_init_pgtable().Signed-off-by Reza Arbab <[email protected]>---
Re: [PATCH v5 3/4] powerpc/mm: add radix__remove_section_mapping()
In reply to Reza ArbabQuoted 50 lines · Reza Arbab
Tear down and free the four-level page tables of physical mappings during memory hotremove.
Borrow the basic structure of
remove_pagetable()and friends from the identically-named x86 functions. Reduce the frequency of tlb flushes andpage_table_lockspinlocks by only doing them in the outermost function. There was some question as to whether the locking is needed at all. Leave it for now, but we could consider dropping it.Memory must be offline to be removed, thus not in use. So there shouldn't be the sort of concurrent page walking activity here that might prompt us to use RCU.
Signed-off-by Reza Arbab <[email protected]>--- arch/powerpc/include/asm/book3s/64/radix.h | 1 + arch/powerpc/mm/pgtable-book3s64.c | 2 +- arch/powerpc/mm/pgtable-radix.c | 133 +++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-)arch/powerpc/include/asm/book3s/64/radix.h +1
-0@@ -294,6 +294,7 @@ static inline unsigned long radix__get_tree_size(void)#ifdef CONFIG_MEMORY_HOTPLUG int radix__create_section_mapping (unsigned long start,unsigned long end); +int radix__remove_section_mapping (unsigned long start,unsigned long end);#endif /* CONFIG_MEMORY_HOTPLUG */ #endif /* __ASSEMBLY__ */ #endif arch/powerpc/mm/pgtable-book3s64.c +1
-1@@ -139,7 +139,7 @@ int create_section_mapping(unsigned long start, unsigned long end)int remove_section_mapping (unsigned long start,unsigned long end) {if (radix_enabled ()) -return -ENODEV ; +return radix__remove_section_mapping (start, end);return hash__remove_section_mapping (start, end); }arch/powerpc/mm/pgtable-radix.c +0
-0
arch/powerpc/mm/pgtable-radix.c void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, · line 477
Quoted 2 lines
arch/powerpc/mm/pgtable-radix.c +0
-0@@ -476,10 +476,143 @@ void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, }
Shouldn't most of these functions have __meminit?
arch/powerpc/mm/pgtable-radix.c void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, · line 487
Quoted 10 lines
arch/powerpc/mm/pgtable-radix.c +9
-0#ifdef CONFIG_MEMORY_HOTPLUG +static void free_pte_table (pte_t *pte_start,pmd_t *pmd) +{ +pte_t *pte; +int i; + +for (i =0 ; i <PTRS_PER_PTE ; i++) { + pte = pte_start + i; +if (!pte_none (*pte)) +return ;
If !pte_none() we fail the hotplug? Or silently leave the allocated pte's around. I guess this is the same as x86
Quoted 46 lines
arch/powerpc/mm/pgtable-radix.c +46
-0+ } + +pte_free_kernel (&init_mm, pte_start); +pmd_clear (pmd); +} + +static void free_pmd_table (pmd_t *pmd_start,pud_t *pud) +{ +pmd_t *pmd; +int i; + +for (i =0 ; i <PTRS_PER_PMD ; i++) { + pmd = pmd_start + i; +if (!pmd_none (*pmd)) +return ; + } + +pmd_free (&init_mm, pmd_start); +pud_clear (pud); +} + +static void remove_pte_table (pte_t *pte_start,unsigned long addr, +unsigned long end) +{ +unsigned long next; +pte_t *pte; + + pte = pte_start +pte_index (addr); +for (; addr < end; addr = next, pte++) { + next = (addr +PAGE_SIZE ) &PAGE_MASK ; +if (next > end) + next = end; + +if (!pte_present (*pte)) +continue ; + +pte_clear (&init_mm, addr, pte); + } +} + +static void remove_pmd_table (pmd_t *pmd_start,unsigned long addr, +unsigned long end) +{ +unsigned long next; +pte_t *pte_base; +pmd_t *pmd;
arch/powerpc/mm/pgtable-radix.c void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, · line 543
Quoted 10 lines
arch/powerpc/mm/pgtable-radix.c +10
-0+ + pmd = pmd_start +pmd_index (addr); +for (; addr < end; addr = next, pmd++) { + next =pmd_addr_end (addr, end); + +if (!pmd_present (*pmd)) +continue ; + +if (pmd_huge (*pmd)) { +pte_clear (&init_mm, addr, (pte_t *)pmd);
pmd_clear()?
Quoted 15 lines
arch/powerpc/mm/pgtable-radix.c +15
-0+continue ; + } + + pte_base = (pte_t *)pmd_page_vaddr (*pmd); +remove_pte_table (pte_base, addr, next); +free_pte_table (pte_base, pmd); + } +} + +static void remove_pud_table (pud_t *pud_start,unsigned long addr, +unsigned long end) +{ +unsigned long next; +pmd_t *pmd_base; +pud_t *pud;
arch/powerpc/mm/pgtable-radix.c void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, · line 568
Quoted 10 lines
arch/powerpc/mm/pgtable-radix.c +10
-0+ + pud = pud_start +pud_index (addr); +for (; addr < end; addr = next, pud++) { + next =pud_addr_end (addr, end); + +if (!pud_present (*pud)) +continue ; + +if (pud_huge (*pud)) { +pte_clear (&init_mm, addr, (pte_t *)pud);
pud_clear()?
Quoted 7 lines
arch/powerpc/mm/pgtable-radix.c +7
-0+continue ; + } + + pmd_base = (pmd_t *)pud_page_vaddr (*pud); +remove_pmd_table (pmd_base, addr, next); +free_pmd_table (pmd_base, pud); + }
arch/powerpc/mm/pgtable-radix.c void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, · line 585
Quoted 10 lines
arch/powerpc/mm/pgtable-radix.c +10
-0+} + +static void remove_pagetable (unsigned long start,unsigned long end) +{ +unsigned long addr, next; +pud_t *pud_base; +pgd_t *pgd; + +spin_lock (&init_mm.page_table_lock); +
x86 does more granular lock acquisition only during clearing the relevant entries. I suppose we don't have to worry about it since its not fast path and frequent.
Balbir Singh.
Re: [PATCH v5 4/4] powerpc/mm: unstub radix__vmemmap_remove_mapping()
In reply to Reza ArbabQuoted 8 lines · Reza Arbab
Use
remove_pagetable()and friends for radix vmemmap removal.We do not require the special-case handling of vmemmap done in the x86 versions of these functions. This is because
vmemmap_free()has already freed the mapped pages, and calls us with an aligned address range.So, add a few failsafe WARNs, but otherwise the code to remove physical mappings is already sufficient for vmemmap.
I wonder if we really need them?
Balbir Singh.
Re: [PATCH v5 1/4] powerpc/mm: refactor radix physical page mapping
In reply to Balbir SinghThanks for your review!
Quoted 7 lines · Balbir Singh
Quoted 6 lines · Reza Arbab
arch/powerpc/mm/pgtable-radix.c +0
-0@@ -107,54 +107,66 @@ int radix__map_kernel_page(unsigned long ea, unsigned long pa,return 0 ; }
Quoted 8 lines
arch/powerpc/mm/pgtable-radix.c int radix__map_kernel_page(unsigned long ea, unsigned long pa, · line 115
Quoted 6 lines
arch/powerpc/mm/pgtable-radix.c +6
-0+static inline void __meminit print_mapping (unsigned long start, +unsigned long end, +unsigned long size) +{ +if (end <= start) +return ;Should we
pr_errfor start > end?
I think that would be overkill. The way this little inline is called, start > end is not possible. The real point is not to print anything if start == end. Using <= just seemed better in context.
Quoted 25 lines
Quoted 25 lines
arch/powerpc/mm/pgtable-radix.c +25
-0+static int __meminit create_physical_mapping (unsigned long start, +unsigned long end) +{ +unsigned long addr, mapping_size; + + start =_ALIGN_UP (start,PAGE_SIZE ); +for (addr = start; addr < end; addr += mapping_size) { +unsigned long gap, previous_size; +int rc; + + gap = end - addr; + previous_size = mapping_size; + +if (IS_ALIGNED (addr,PUD_SIZE ) && gap >=PUD_SIZE && + mmu_psize_defs[MMU_PAGE_1G ].shift) + mapping_size =PUD_SIZE ; +else if (IS_ALIGNED (addr,PMD_SIZE ) && gap >=PMD_SIZE && + mmu_psize_defs[MMU_PAGE_2M ].shift) + mapping_size =PMD_SIZE ; +else + mapping_size =PAGE_SIZE ; + +if (mapping_size != previous_size) { +print_mapping (start, addr, previous_size); + start = addr;
Quoted 8 lines
arch/powerpc/mm/pgtable-radix.c int radix__map_kernel_page(unsigned long ea, unsigned long pa, · line 150
Quoted 6 lines
arch/powerpc/mm/pgtable-radix.c +6
-0+ } + + rc =radix__map_kernel_page ((unsigned long )__va (addr), addr, +PAGE_KERNEL_X , mapping_size); +if (rc) +return rc;Should we try a lower page size if
map_kernel_pagefails for thismapping_size?
The only way map_kernel_page can fail is -ENOMEM. If that's the case,
there's no way we're going to be able to map this range at all. Better to fail fast here, I would think.
Signature · 1 line
Reza Arbab
Re: [PATCH v5 3/4] powerpc/mm: add radix__remove_section_mapping()
In reply to Balbir SinghQuoted 1 line · Balbir Singh
Shouldn't most of these functions have
__meminit?
I don't think so. The mapping functions are __meminit, but the unmapping functions are completely within #ifdef CONFIG_MEMORY_HOTPLUG already.
Quoted 7 lines · Reza Arbab
Quoted 6 lines
#ifdef
CONFIG_MEMORY_HOTPLUGarch/powerpc/mm/pgtable-radix.c +5
-0+static void free_pte_table (pte_t *pte_start,pmd_t *pmd) +{ +pte_t *pte; +int i; +
Quoted 8 lines
arch/powerpc/mm/pgtable-radix.c void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, · line 487
Quoted 4 lines
arch/powerpc/mm/pgtable-radix.c +4
-0+for (i =0 ; i <PTRS_PER_PTE ; i++) { + pte = pte_start + i; +if (!pte_none (*pte)) +return ;If !pte_none() we fail the hotplug? Or silently leave the allocated pte's around. I guess this is the same as x86
The latter--it's not a failure. If you provided remove_pagetable() an unaligned address range, there could be a pte left unremoved at either end.
Quoted 10 lines
Quoted 10 lines
arch/powerpc/mm/pgtable-radix.c +10
-0+static void remove_pmd_table (pmd_t *pmd_start,unsigned long addr, +unsigned long end) +{ +unsigned long next; +pte_t *pte_base; +pmd_t *pmd; + + pmd = pmd_start +pmd_index (addr); +for (; addr < end; addr = next, pmd++) { + next =pmd_addr_end (addr, end);
Quoted 8 lines
arch/powerpc/mm/pgtable-radix.c void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, · line 543
Quoted 6 lines
arch/powerpc/mm/pgtable-radix.c +6
-0+ +if (!pmd_present (*pmd)) +continue ; + +if (pmd_huge (*pmd)) { +pte_clear (&init_mm, addr, (pte_t *)pmd);
pmd_clear()?
I used pte_clear() to mirror what happens in radix__map_kernel_page():
if (map_page_size == PMD_SIZE) {
ptep = (pte_t *)pmdp;
goto set_the_pte;
}
[...]
set_the_pte:
set_pte_at(&init_mm, ea, ptep, pfn_pte(pa >> PAGE_SHIFT, flags));Would pmd_clear() be equivalent, since the pointer got set like a pte?
Quoted 4 lines
Quoted 4 lines
arch/powerpc/mm/pgtable-radix.c +4
-0+static void remove_pagetable (unsigned long start,unsigned long end) +{ +unsigned long addr, next; +pud_t *pud_base;
Quoted 8 lines
arch/powerpc/mm/pgtable-radix.c void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, · line 585
Quoted 4 lines
arch/powerpc/mm/pgtable-radix.c +4
-0+pgd_t *pgd; + +spin_lock (&init_mm.page_table_lock); +x86 does more granular lock acquisition only during clearing the relevant entries. I suppose we don't have to worry about it since its not fast path and frequent.
Yep. Ben thought the locking in remove_pte_table() was actually too granular, and Aneesh questioned what was being protected in the first place. So I left one lock/unlock in the outermost function for now.
Signature · 1 line
Reza Arbab
Re: [PATCH v5 4/4] powerpc/mm: unstub radix__vmemmap_remove_mapping()
In reply to Balbir SinghQuoted 11 lines · Balbir Singh
Quoted 8 lines · Reza Arbab
Use
remove_pagetable()and friends for radix vmemmap removal.We do not require the special-case handling of vmemmap done in the x86 versions of these functions. This is because
vmemmap_free()has already freed the mapped pages, and calls us with an aligned address range.So, add a few failsafe WARNs, but otherwise the code to remove physical mappings is already sufficient for vmemmap.
I wonder if we really need them?
Not sure what the guideline is for a "this shouldn't happen" WARN. It could save us some grief, should our vmemmap code ever start calling with an unaligned range, like it does on x86.
Signature · 1 line
Reza Arbab
Re: [PATCH v5 1/4] powerpc/mm: refactor radix physical page mapping
In reply to Reza ArbabQuoted 19 lines · Reza Arbab
Thanks for your review!
Quoted 7 lines · Balbir Singh
Quoted 6 lines · Reza Arbab
arch/powerpc/mm/pgtable-radix.c +0
-0@@ -107,54 +107,66 @@ int radix__map_kernel_page(unsigned long ea, unsigned long pa,return 0 ; }Quoted 8 lines
arch/powerpc/mm/pgtable-radix.c int radix__map_kernel_page(unsigned long ea, unsigned long pa, · line 115
Quoted 6 lines
arch/powerpc/mm/pgtable-radix.c +6
-0+static inline void __meminit print_mapping (unsigned long start, +unsigned long end, +unsigned long size) +{ +if (end <= start) +return ;Should we
pr_errfor start > end?
Quoted 4 lines
I think that would be overkill. The way this little inline is called, start
Quoted 1 line
end is not possible. The real point is not to print anything if start ==
end. Using <= just seemed better in context.
Agreed
<snip>
Quoted 7 lines
Quoted 2 lines
Should we try a lower page size if
map_kernel_pagefails for thismapping_size?The only way
map_kernel_pagecan fail is-ENOMEM. If that's the case, there's no way we're going to be able to map this range at all. Better to fail fast here, I would think.
I think I am OK with this implementation for now.
Balbir Singh.
Re: [PATCH v5 3/4] powerpc/mm: add radix__remove_section_mapping()
In reply to Reza ArbabQuoted 22 lines · Reza Arbab
Quoted 1 line · Balbir Singh
Shouldn't most of these functions have
__meminit?I don't think so. The mapping functions are
__meminit, but the unmapping functions are completely within #ifdefCONFIG_MEMORY_HOTPLUGalready.Quoted 7 lines · Reza Arbab
Quoted 6 lines
#ifdef
CONFIG_MEMORY_HOTPLUGarch/powerpc/mm/pgtable-radix.c +5
-0+static void free_pte_table (pte_t *pte_start,pmd_t *pmd) +{ +pte_t *pte; +int i; +Quoted 8 lines
arch/powerpc/mm/pgtable-radix.c void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, · line 487
Quoted 4 lines
arch/powerpc/mm/pgtable-radix.c +4
-0+for (i =0 ; i <PTRS_PER_PTE ; i++) { + pte = pte_start + i; +if (!pte_none (*pte)) +return ;If !pte_none() we fail the hotplug? Or silently leave the allocated pte's around. I guess this is the same as x86
Quoted 3 lines
The latter--it's not a failure. If you provided
remove_pagetable()an unaligned address range, there could be a pte left unremoved at either end.
OK.
Quoted 31 lines
Quoted 10 lines
Quoted 10 lines
arch/powerpc/mm/pgtable-radix.c +10
-0+static void remove_pmd_table (pmd_t *pmd_start,unsigned long addr, +unsigned long end) +{ +unsigned long next; +pte_t *pte_base; +pmd_t *pmd; + + pmd = pmd_start +pmd_index (addr); +for (; addr < end; addr = next, pmd++) { + next =pmd_addr_end (addr, end);Quoted 8 lines
arch/powerpc/mm/pgtable-radix.c void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, · line 543
Quoted 6 lines
arch/powerpc/mm/pgtable-radix.c +6
-0+ +if (!pmd_present (*pmd)) +continue ; + +if (pmd_huge (*pmd)) { +pte_clear (&init_mm, addr, (pte_t *)pmd);
pmd_clear()?I used
pte_clear()to mirror what happens inradix__map_kernel_page():if (map_page_size == PMD_SIZE) { ptep = (pte_t *)pmdp; goto set_the_pte; } [...] set_the_pte: set_pte_at(&init_mm, ea, ptep, pfn_pte(pa >> PAGE_SHIFT, flags));
Quoted 1 line
Would
pmd_clear()be equivalent, since the pointer got set like a pte?
But we are still setting a pmdp. pmd_clear() will set the pmd to 0, pte_clear() will go through the pte_update() mechanism which is expensive IMHO and we may not need to do it.
Quoted 14 lines
Quoted 13 lines
arch/powerpc/mm/pgtable-radix.c void radix__setup_initial_memory_limit(phys_addr_t first_memblock_base, · line 585
Quoted 9 lines
arch/powerpc/mm/pgtable-radix.c +8
-0+static void remove_pagetable (unsigned long start,unsigned long end) +{ +unsigned long addr, next; +pud_t *pud_base; +pgd_t *pgd; + +spin_lock (&init_mm.page_table_lock); +x86 does more granular lock acquisition only during clearing the relevant entries. I suppose we don't have to worry about it since its not fast path and frequent.
Quoted 4 lines
Yep. Ben thought the locking in
remove_pte_table()was actually too granular, and Aneesh questioned what was being protected in the first place. So I left one lock/unlock in the outermost function for now.
Fair enough
Balbir Singh.
Balbir Singh
Acked-byRe: [PATCH v5 4/4] powerpc/mm: unstub radix__vmemmap_remove_mapping()
In reply to Reza ArbabQuoted 8 lines · Reza Arbab
Quoted 7 lines · Balbir Singh
Quoted 6 lines · Reza Arbab
Use
remove_pagetable()and friends for radix vmemmap removal.We do not require the special-case handling of vmemmap done in the x86 versions of these functions. This is because
vmemmap_free()has already freed the mapped pages, and calls us with an aligned address range.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
So, add a few failsafe WARNs, but otherwise the code to remove physical mappings is already sufficient for vmemmap.
I wonder if we really need them?
Not sure what the guideline is for a "this shouldn't happen" WARN. It could save us some grief, should our vmemmap code ever start calling with an unaligned range, like it does on x86.
Fair enough
Michael Ellerman
reviewerRe: [PATCH v5 1/4] powerpc/mm: refactor radix physical page mapping
In reply to Reza Arbabarch/powerpc/mm/pgtable-ra=
Quoted 1 line · Reza Arbab
arch/powerpc/mm/pgtable-ra= renamed from arch/powerpc/mm/pgtable-radix.c +0
-0
dix.c
arch/powerpc/mm/pgtable-radix.c int radix__map_kernel_page(unsigned long ea, unsign=
Quoted 4 lines
index 623a0dc..2ce1354 100644
arch/powerpc/mm/pgtable-radix.c +0
-0@@ -107,54 +107,66 @@ int radix__map_kernel_page(unsigned long ea, unsign=
ed long pa,
Quoted 37 lines
arch/powerpc/mm/pgtable-radix.c +0
-0return 0 ; }=20=20
arch/powerpc/mm/pgtable-radix.c +34
-0+static inline void __meminit print_mapping (unsigned long start, +unsigned long end, +unsigned long size) +{ + if (end <=3D start) +return ; + +pr_info ("Mapped range 0x%lx - 0x%lx with 0x%lx\n" , start, end, size); +} + +static int __meminit create_physical_mapping (unsigned long start, +unsigned long end) +{ +unsigned long addr, mapping_size; + + start =3D _ALIGN_UP(start, PAGE_SIZE); + for (addr =3D start; addr < end; addr +=3D mapping_size) { +unsigned long gap, previous_size; +int rc; + + gap =3D end - addr; + previous_size =3D mapping_size; + + if (IS_ALIGNED(addr, PUD_SIZE) && gap >=3D PUD_SIZE && + mmu_psize_defs[MMU_PAGE_1G ].shift) + mapping_size =3D PUD_SIZE; + else if (IS_ALIGNED(addr, PMD_SIZE) && gap >=3D PMD_SIZE && + mmu_psize_defs[MMU_PAGE_2M ].shift) + mapping_size =3D PMD_SIZE; +else + mapping_size =3D PAGE_SIZE; + + if (mapping_size !=3D previous_size) { +print_mapping (start, addr, previous_size);
arch/powerpc/mm/pgtable-radix.c int radix__map_kernel_page(unsigned long ea, unsigned long pa, · line 153
Quoted 10 lines
arch/powerpc/mm/pgtable-radix.c +10
-0+ start =3D addr; + } + + rc =3D radix__map_kernel_page((unsigned long)__va(addr), addr, +PAGE_KERNEL_X , mapping_size); +if (rc) +return rc; + } + +print_mapping (start, addr, mapping_size);
Doesn't build.
In file included from ../include/linux/kernel.h:13:0,
from ../include/linux/sched.h:17,
from ../arch/powerpc/mm/pgtable-radix.c:11:../arch/powerpc/mm/pgtable-radix.c: In function =E2=80=98create_physical_ma= pping=E2=80=99:../include/linux/printk.h:299:2: error: =E2=80=98mapping_size=E2=80=99 may = be used uninitialized in this function [-Werror=3Dmaybe-uninitialized]
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
^~~~~~../arch/powerpc/mm/pgtable-radix.c:123:22: note: =E2=80=98mapping_size=E2= =80=99 was declared here
unsigned long addr, mapping_size;
^~~~~~~~~~~~cheers
Re: [PATCH v5 1/4] powerpc/mm: refactor radix physical page mapping
Quoted 11 lines · Michael Ellerman
Doesn't build.
In file included from
../include/linux/kernel.h:13:0,from ../include/linux/sched.h:17, from ../arch/powerpc/mm/pgtable-radix.c:11:
../arch/powerpc/mm/pgtable-radix.c: In function ‘create_physical_mapping’:../include/linux/printk.h:299:2: error: ‘mapping_size’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
^~~~~~../arch/powerpc/mm/pgtable-radix.c:123:22: note: ‘mapping_size’ was declared here
unsigned long addr,mapping_size;
Doh. Could you please do the following for now?
- unsigned long addr, mapping_size;
+ unsigned long addr, mapping_size = 0;
I'd like to delay spinning v6 with this until I see any input you might have on the rest of the set.
And for future reference, how are you ending up with -Werror=maybe-uninitialized? On powerpc/next, with pseries_le_defconfig, I get -Wno-maybe-uninitialized.
Signature · 1 line
Reza Arbab
Michael Ellerman
reviewerRe: [PATCH v5 1/4] powerpc/mm: refactor radix physical page mapping
Quoted 7 lines · Reza Arbab
Quoted 6 lines · Michael Ellerman
Doesn't build.
In file included from
../include/linux/kernel.h:13:0,from ../include/linux/sched.h:17, from ../arch/powerpc/mm/pgtable-radix.c:11:
../arch/powerpc/mm/pgtable-radix.c: In function =E2=80=98create_physical_=
mapping=E2=80=99:
Quoted 1 line
Quoted 1 line
../include/linux/printk.h:299:2: error: =E2=80=98mapping_size=E2=80=99 ma=
y be used uninitialized in this function [-Werror=3Dmaybe-uninitialized]
Quoted 3 lines
Quoted 3 lines
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
^~~~~~../arch/powerpc/mm/pgtable-radix.c:123:22: note: =E2=80=98mapping_size=E2=
=80=99 was declared here
Review
Quoted 6 lines
Quoted 1 line
unsigned long addr,
mapping_size;Doh. Could you please do the following for now?
(quoted diff) +1
-1- unsigned long addr, mapping_size; + unsigned long addr, mapping_size =3D 0;
Thanks.
Quoted 2 lines
I'd like to delay spinning v6 with this until I see any input you might=20 have on the rest of the set.
I don't think I have any at the moment. So I'll just fold the above into v5.
Quoted 2 lines
And for future reference, how are you ending up with=20 -Werror=3Dmaybe-uninitialized? On powerpc/next, with pseries_le_defconfig=
,=20
Quoted 1 line
I get -Wno-maybe-uninitialized.
By default. Probably you're not getting it because your compiler is too old. If I'm reading Makefile correctly it's enabled for GCC 4.9 or later:
KBUILD_CFLAGS +=3D $(call cc-ifversion, -lt, 0409, \ $(call cc-disable-warning,maybe-uninitialized,))
I'm using GCC 6.2.0.
cheers
Re: [v5,1/4] powerpc/mm: refactor radix physical page mapping
In reply to Reza ArbabQuoted 8 lines · Reza Arbab
Move the page mapping code in
radix_init_pgtable()into a separate function that will also be used for memory hotplug.The current goto loop progressively decreases its mapping size as it covers the tail of a range whose end is unaligned. Change this to a for loop which can do the same for both ends of the range.
Signed-off-by Reza Arbab <[email protected]>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/b5200ec9edf038459619fce9988842
cheers