diff mbox series

[2/4] microblaze: simplify pte_alloc_one_kernel()

Message ID 20210714123739.16493-3-rppt@kernel.org (mailing list archive)
State New
Headers show
Series mm: ensure consistency of memory map poisoning | expand

Commit Message

Mike Rapoport July 14, 2021, 12:37 p.m. UTC
From: Mike Rapoport <rppt@linux.ibm.com>

The microblaze's implementation of pte_alloc_one_kernel() used
memblock_alloc_try_nid_raw() along with clear_page() to allocated a zeroed
page during early setup.

Replace calls of these functions with a call to memblock_alloc_try_nid()
that already returns zeroed page and respects the same allocation limits as
memblock_alloc_try_nid_raw().

While on it drop early_get_page() wrapper that was only used in
pte_alloc_one_kernel().

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
---
 arch/microblaze/include/asm/pgtable.h |  2 --
 arch/microblaze/mm/init.c             | 12 ------------
 arch/microblaze/mm/pgtable.c          | 17 ++++++++---------
 3 files changed, 8 insertions(+), 23 deletions(-)

Comments

Michal Simek Aug. 25, 2021, 10:09 a.m. UTC | #1
On 7/14/21 2:37 PM, Mike Rapoport wrote:
> From: Mike Rapoport <rppt@linux.ibm.com>
> 
> The microblaze's implementation of pte_alloc_one_kernel() used
> memblock_alloc_try_nid_raw() along with clear_page() to allocated a zeroed
> page during early setup.
> 
> Replace calls of these functions with a call to memblock_alloc_try_nid()
> that already returns zeroed page and respects the same allocation limits as
> memblock_alloc_try_nid_raw().
> 
> While on it drop early_get_page() wrapper that was only used in
> pte_alloc_one_kernel().
> 
> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
> ---
>  arch/microblaze/include/asm/pgtable.h |  2 --
>  arch/microblaze/mm/init.c             | 12 ------------
>  arch/microblaze/mm/pgtable.c          | 17 ++++++++---------
>  3 files changed, 8 insertions(+), 23 deletions(-)
> 
> diff --git a/arch/microblaze/include/asm/pgtable.h b/arch/microblaze/include/asm/pgtable.h
> index 71cd547655d9..c136a01e467e 100644
> --- a/arch/microblaze/include/asm/pgtable.h
> +++ b/arch/microblaze/include/asm/pgtable.h
> @@ -443,8 +443,6 @@ extern int mem_init_done;
>  
>  asmlinkage void __init mmu_init(void);
>  
> -void __init *early_get_page(void);
> -
>  #endif /* __ASSEMBLY__ */
>  #endif /* __KERNEL__ */
>  
> diff --git a/arch/microblaze/mm/init.c b/arch/microblaze/mm/init.c
> index ab55c70380a5..952f35b335b2 100644
> --- a/arch/microblaze/mm/init.c
> +++ b/arch/microblaze/mm/init.c
> @@ -265,18 +265,6 @@ asmlinkage void __init mmu_init(void)
>  	dma_contiguous_reserve(memory_start + lowmem_size - 1);
>  }
>  
> -/* This is only called until mem_init is done. */
> -void __init *early_get_page(void)
> -{
> -	/*
> -	 * Mem start + kernel_tlb -> here is limit
> -	 * because of mem mapping from head.S
> -	 */
> -	return memblock_alloc_try_nid_raw(PAGE_SIZE, PAGE_SIZE,
> -				MEMBLOCK_LOW_LIMIT, memory_start + kernel_tlb,
> -				NUMA_NO_NODE);
> -}
> -
>  void * __ref zalloc_maybe_bootmem(size_t size, gfp_t mask)
>  {
>  	void *p;
> diff --git a/arch/microblaze/mm/pgtable.c b/arch/microblaze/mm/pgtable.c
> index 38ccb909bc9d..c1833b159d3b 100644
> --- a/arch/microblaze/mm/pgtable.c
> +++ b/arch/microblaze/mm/pgtable.c
> @@ -33,6 +33,7 @@
>  #include <linux/init.h>
>  #include <linux/mm_types.h>
>  #include <linux/pgtable.h>
> +#include <linux/memblock.h>
>  
>  #include <asm/pgalloc.h>
>  #include <linux/io.h>
> @@ -242,15 +243,13 @@ unsigned long iopa(unsigned long addr)
>  
>  __ref pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
>  {
> -	pte_t *pte;
> -	if (mem_init_done) {
> -		pte = (pte_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
> -	} else {
> -		pte = (pte_t *)early_get_page();
> -		if (pte)
> -			clear_page(pte);
> -	}
> -	return pte;
> +	if (mem_init_done)
> +		return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
> +	else
> +		return memblock_alloc_try_nid(PAGE_SIZE, PAGE_SIZE,
> +					      MEMBLOCK_LOW_LIMIT,
> +					      memory_start + kernel_tlb,
> +					      NUMA_NO_NODE);
>  }
>  
>  void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t flags)
> 

I have tested 1/4 with/without the fix from Guenter
and also 2/4 and I can't see any issue on real HW.

That's why feel free to add my
Tested-by: Michal Simek <michal.simek@xilinx.com>

Thanks,
Michal
David Hildenbrand Aug. 25, 2021, 12:13 p.m. UTC | #2
On 14.07.21 14:37, Mike Rapoport wrote:
> From: Mike Rapoport <rppt@linux.ibm.com>
> 
> The microblaze's implementation of pte_alloc_one_kernel() used
> memblock_alloc_try_nid_raw() along with clear_page() to allocated a zeroed
> page during early setup.
> 
> Replace calls of these functions with a call to memblock_alloc_try_nid()
> that already returns zeroed page and respects the same allocation limits as
> memblock_alloc_try_nid_raw().
> 
> While on it drop early_get_page() wrapper that was only used in
> pte_alloc_one_kernel().
> 
> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
> ---
>   arch/microblaze/include/asm/pgtable.h |  2 --
>   arch/microblaze/mm/init.c             | 12 ------------
>   arch/microblaze/mm/pgtable.c          | 17 ++++++++---------
>   3 files changed, 8 insertions(+), 23 deletions(-)
> 
> diff --git a/arch/microblaze/include/asm/pgtable.h b/arch/microblaze/include/asm/pgtable.h
> index 71cd547655d9..c136a01e467e 100644
> --- a/arch/microblaze/include/asm/pgtable.h
> +++ b/arch/microblaze/include/asm/pgtable.h
> @@ -443,8 +443,6 @@ extern int mem_init_done;
>   
>   asmlinkage void __init mmu_init(void);
>   
> -void __init *early_get_page(void);
> -
>   #endif /* __ASSEMBLY__ */
>   #endif /* __KERNEL__ */
>   
> diff --git a/arch/microblaze/mm/init.c b/arch/microblaze/mm/init.c
> index ab55c70380a5..952f35b335b2 100644
> --- a/arch/microblaze/mm/init.c
> +++ b/arch/microblaze/mm/init.c
> @@ -265,18 +265,6 @@ asmlinkage void __init mmu_init(void)
>   	dma_contiguous_reserve(memory_start + lowmem_size - 1);
>   }
>   
> -/* This is only called until mem_init is done. */
> -void __init *early_get_page(void)
> -{
> -	/*
> -	 * Mem start + kernel_tlb -> here is limit
> -	 * because of mem mapping from head.S
> -	 */
> -	return memblock_alloc_try_nid_raw(PAGE_SIZE, PAGE_SIZE,
> -				MEMBLOCK_LOW_LIMIT, memory_start + kernel_tlb,
> -				NUMA_NO_NODE);
> -}
> -
>   void * __ref zalloc_maybe_bootmem(size_t size, gfp_t mask)
>   {
>   	void *p;
> diff --git a/arch/microblaze/mm/pgtable.c b/arch/microblaze/mm/pgtable.c
> index 38ccb909bc9d..c1833b159d3b 100644
> --- a/arch/microblaze/mm/pgtable.c
> +++ b/arch/microblaze/mm/pgtable.c
> @@ -33,6 +33,7 @@
>   #include <linux/init.h>
>   #include <linux/mm_types.h>
>   #include <linux/pgtable.h>
> +#include <linux/memblock.h>
>   
>   #include <asm/pgalloc.h>
>   #include <linux/io.h>
> @@ -242,15 +243,13 @@ unsigned long iopa(unsigned long addr)
>   
>   __ref pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
>   {
> -	pte_t *pte;
> -	if (mem_init_done) {
> -		pte = (pte_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
> -	} else {
> -		pte = (pte_t *)early_get_page();
> -		if (pte)
> -			clear_page(pte);
> -	}
> -	return pte;
> +	if (mem_init_done)
> +		return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
> +	else
> +		return memblock_alloc_try_nid(PAGE_SIZE, PAGE_SIZE,
> +					      MEMBLOCK_LOW_LIMIT,
> +					      memory_start + kernel_tlb,
> +					      NUMA_NO_NODE);
>   }
>   
>   void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t flags)
> 

Reviewed-by: David Hildenbrand <david@redhat.com>
diff mbox series

Patch

diff --git a/arch/microblaze/include/asm/pgtable.h b/arch/microblaze/include/asm/pgtable.h
index 71cd547655d9..c136a01e467e 100644
--- a/arch/microblaze/include/asm/pgtable.h
+++ b/arch/microblaze/include/asm/pgtable.h
@@ -443,8 +443,6 @@  extern int mem_init_done;
 
 asmlinkage void __init mmu_init(void);
 
-void __init *early_get_page(void);
-
 #endif /* __ASSEMBLY__ */
 #endif /* __KERNEL__ */
 
diff --git a/arch/microblaze/mm/init.c b/arch/microblaze/mm/init.c
index ab55c70380a5..952f35b335b2 100644
--- a/arch/microblaze/mm/init.c
+++ b/arch/microblaze/mm/init.c
@@ -265,18 +265,6 @@  asmlinkage void __init mmu_init(void)
 	dma_contiguous_reserve(memory_start + lowmem_size - 1);
 }
 
-/* This is only called until mem_init is done. */
-void __init *early_get_page(void)
-{
-	/*
-	 * Mem start + kernel_tlb -> here is limit
-	 * because of mem mapping from head.S
-	 */
-	return memblock_alloc_try_nid_raw(PAGE_SIZE, PAGE_SIZE,
-				MEMBLOCK_LOW_LIMIT, memory_start + kernel_tlb,
-				NUMA_NO_NODE);
-}
-
 void * __ref zalloc_maybe_bootmem(size_t size, gfp_t mask)
 {
 	void *p;
diff --git a/arch/microblaze/mm/pgtable.c b/arch/microblaze/mm/pgtable.c
index 38ccb909bc9d..c1833b159d3b 100644
--- a/arch/microblaze/mm/pgtable.c
+++ b/arch/microblaze/mm/pgtable.c
@@ -33,6 +33,7 @@ 
 #include <linux/init.h>
 #include <linux/mm_types.h>
 #include <linux/pgtable.h>
+#include <linux/memblock.h>
 
 #include <asm/pgalloc.h>
 #include <linux/io.h>
@@ -242,15 +243,13 @@  unsigned long iopa(unsigned long addr)
 
 __ref pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
 {
-	pte_t *pte;
-	if (mem_init_done) {
-		pte = (pte_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
-	} else {
-		pte = (pte_t *)early_get_page();
-		if (pte)
-			clear_page(pte);
-	}
-	return pte;
+	if (mem_init_done)
+		return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
+	else
+		return memblock_alloc_try_nid(PAGE_SIZE, PAGE_SIZE,
+					      MEMBLOCK_LOW_LIMIT,
+					      memory_start + kernel_tlb,
+					      NUMA_NO_NODE);
 }
 
 void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t flags)