linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] mm: ensure consistency of memory map poisoning
@ 2021-07-14 12:37 Mike Rapoport
  2021-07-14 12:37 ` [PATCH 1/4] mm/page_alloc: always initialize memory map for the holes Mike Rapoport
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Mike Rapoport @ 2021-07-14 12:37 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Michal Simek, Mike Rapoport, Mike Rapoport, linux-kernel, linux-mm

From: Mike Rapoport <rppt@linux.ibm.com>

Hi,

Currently memory map allocation for FLATMEM case does not poison the struct
pages regardless of CONFIG_PAGE_POISON setting.

This happens because allocation of the memory map for FLATMEM and SPARSMEM
use different memblock functions and those that are used for SPARSMEM case
(namely memblock_alloc_try_nid_raw() and memblock_alloc_exact_nid_raw())
implicitly poison the allocated memory.

Another side effect of this implicit poisoning is that early setup code
that uses the same functions to allocate memory burns cycles for the memory
poisoning even if it was not intended.

These patches introduce memmap_alloc() wrapper that ensure that the memory
map allocation is consistent for different memory models.

Mike Rapoport (4):
  mm/page_alloc: always initialize memory map for the holes
  microblaze: simplify pte_alloc_one_kernel()
  mm: introduce memmap_alloc() to unify memory map allocation
  memblock: stop poisoning raw allocations

 arch/microblaze/include/asm/pgtable.h |  2 --
 arch/microblaze/mm/init.c             | 12 ----------
 arch/microblaze/mm/pgtable.c          | 17 +++++++-------
 mm/internal.h                         |  4 ++++
 mm/memblock.c                         | 20 ++++-------------
 mm/page_alloc.c                       | 32 ++++++++++++++++++---------
 mm/sparse.c                           |  6 ++---
 7 files changed, 40 insertions(+), 53 deletions(-)


base-commit: e73f0f0ee7541171d89f2e2491130c7771ba58d3
-- 
2.28.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/4] mm/page_alloc: always initialize memory map for the holes
  2021-07-14 12:37 [PATCH 0/4] mm: ensure consistency of memory map poisoning Mike Rapoport
@ 2021-07-14 12:37 ` Mike Rapoport
  2021-07-31 16:56   ` Guenter Roeck
  2021-08-25 12:11   ` David Hildenbrand
  2021-07-14 12:37 ` [PATCH 2/4] microblaze: simplify pte_alloc_one_kernel() Mike Rapoport
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 16+ messages in thread
From: Mike Rapoport @ 2021-07-14 12:37 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Michal Simek, Mike Rapoport, Mike Rapoport, linux-kernel, linux-mm

From: Mike Rapoport <rppt@linux.ibm.com>

Currently memory map for the holes is initialized only when SPARSEMEM
memory model is used. Yet, even with FLATMEM there could be holes in the
physical memory layout that have memory map entries.

For instance, the memory reserved using e820 API on i386 or
"reserved-memory" nodes in device tree would not appear in memblock.memory
and hence the struct pages for such holes will be skipped during memory map
initialization.

These struct pages will be zeroed because the memory map for FLATMEM
systems is allocated with memblock_alloc_node() that clears the allocated
memory. While zeroed struct pages do not cause immediate problems, the
correct behaviour is to initialize every page using __init_single_page().
Besides, enabling page poison for FLATMEM case will trigger
PF_POISONED_CHECK() unless the memory map is properly initialized.

Make sure init_unavailable_range() is called for both SPARSEMEM and FLATMEM
so that struct pages representing memory holes would appear as PG_Reserved
with any memory layout.

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
---
 mm/page_alloc.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 3b97e17806be..878d7af4403d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6624,7 +6624,6 @@ static void __meminit zone_init_free_lists(struct zone *zone)
 	}
 }
 
-#if !defined(CONFIG_FLATMEM)
 /*
  * Only struct pages that correspond to ranges defined by memblock.memory
  * are zeroed and initialized by going through __init_single_page() during
@@ -6669,13 +6668,6 @@ static void __init init_unavailable_range(unsigned long spfn,
 		pr_info("On node %d, zone %s: %lld pages in unavailable ranges",
 			node, zone_names[zone], pgcnt);
 }
-#else
-static inline void init_unavailable_range(unsigned long spfn,
-					  unsigned long epfn,
-					  int zone, int node)
-{
-}
-#endif
 
 static void __init memmap_init_zone_range(struct zone *zone,
 					  unsigned long start_pfn,
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/4] microblaze: simplify pte_alloc_one_kernel()
  2021-07-14 12:37 [PATCH 0/4] mm: ensure consistency of memory map poisoning Mike Rapoport
  2021-07-14 12:37 ` [PATCH 1/4] mm/page_alloc: always initialize memory map for the holes Mike Rapoport
@ 2021-07-14 12:37 ` Mike Rapoport
  2021-08-25 10:09   ` Michal Simek
  2021-08-25 12:13   ` David Hildenbrand
  2021-07-14 12:37 ` [PATCH 3/4] mm: introduce memmap_alloc() to unify memory map allocation Mike Rapoport
  2021-07-14 12:37 ` [PATCH 4/4] memblock: stop poisoning raw allocations Mike Rapoport
  3 siblings, 2 replies; 16+ messages in thread
From: Mike Rapoport @ 2021-07-14 12:37 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Michal Simek, Mike Rapoport, Mike Rapoport, linux-kernel, linux-mm

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)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/4] mm: introduce memmap_alloc() to unify memory map allocation
  2021-07-14 12:37 [PATCH 0/4] mm: ensure consistency of memory map poisoning Mike Rapoport
  2021-07-14 12:37 ` [PATCH 1/4] mm/page_alloc: always initialize memory map for the holes Mike Rapoport
  2021-07-14 12:37 ` [PATCH 2/4] microblaze: simplify pte_alloc_one_kernel() Mike Rapoport
@ 2021-07-14 12:37 ` Mike Rapoport
  2021-07-14 22:32   ` Andrew Morton
  2021-07-14 12:37 ` [PATCH 4/4] memblock: stop poisoning raw allocations Mike Rapoport
  3 siblings, 1 reply; 16+ messages in thread
From: Mike Rapoport @ 2021-07-14 12:37 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Michal Simek, Mike Rapoport, Mike Rapoport, linux-kernel, linux-mm

From: Mike Rapoport <rppt@linux.ibm.com>

There are several places that allocate memory for the memory map:
alloc_node_mem_map() for FLATMEM, sparse_buffer_init() and
__populate_section_memmap() for SPARSEMEM.

The memory allocated in the FLATMEM case is zeroed and it is never
poisoned, regardless of CONFIG_PAGE_POISON setting.

The memory allocated in the SPARSEMEM cases is not zeroed and it is
implicitly poisoned inside memblock if CONFIG_PAGE_POISON is set.

Introduce memmap_alloc() wrapper for memblock allocators that will be used
for both FLATMEM and SPARSEMEM cases and will makei memory map zeroing and
poisoning consistent for different memory models.

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
---
 mm/internal.h   |  4 ++++
 mm/page_alloc.c | 24 ++++++++++++++++++++++--
 mm/sparse.c     |  6 ++----
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/mm/internal.h b/mm/internal.h
index 31ff935b2547..57e28261a3b1 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -211,6 +211,10 @@ extern void zone_pcp_reset(struct zone *zone);
 extern void zone_pcp_disable(struct zone *zone);
 extern void zone_pcp_enable(struct zone *zone);
 
+extern void *memmap_alloc(phys_addr_t size, phys_addr_t align,
+			  phys_addr_t min_addr,
+			  int nid, bool exact_nid);
+
 #if defined CONFIG_COMPACTION || defined CONFIG_CMA
 
 /*
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 878d7af4403d..b82e55006894 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -6730,6 +6730,26 @@ static void __init memmap_init(void)
 		init_unavailable_range(hole_pfn, end_pfn, zone_id, nid);
 }
 
+void __init *memmap_alloc(phys_addr_t size, phys_addr_t align,
+			  phys_addr_t min_addr, int nid, bool exact_nid)
+{
+	void *ptr;
+
+	if (exact_nid)
+		ptr = memblock_alloc_exact_nid_raw(size, align, min_addr,
+						   MEMBLOCK_ALLOC_ACCESSIBLE,
+						   nid);
+	else
+		ptr = memblock_alloc_try_nid_raw(size, align, min_addr,
+						 MEMBLOCK_ALLOC_ACCESSIBLE,
+						 nid);
+
+	if (ptr && size > 0)
+		page_init_poison(ptr, size);
+
+	return ptr;
+}
+
 static int zone_batchsize(struct zone *zone)
 {
 #ifdef CONFIG_MMU
@@ -7501,8 +7521,8 @@ static void __ref alloc_node_mem_map(struct pglist_data *pgdat)
 		end = pgdat_end_pfn(pgdat);
 		end = ALIGN(end, MAX_ORDER_NR_PAGES);
 		size =  (end - start) * sizeof(struct page);
-		map = memblock_alloc_node(size, SMP_CACHE_BYTES,
-					  pgdat->node_id);
+		map = memmap_alloc(size, SMP_CACHE_BYTES, MEMBLOCK_LOW_LIMIT,
+				   pgdat->node_id, false);
 		if (!map)
 			panic("Failed to allocate %ld bytes for node %d memory map\n",
 			      size, pgdat->node_id);
diff --git a/mm/sparse.c b/mm/sparse.c
index 6326cdf36c4f..a5fad244ac5f 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -462,8 +462,7 @@ struct page __init *__populate_section_memmap(unsigned long pfn,
 	if (map)
 		return map;
 
-	map = memblock_alloc_try_nid_raw(size, size, addr,
-					  MEMBLOCK_ALLOC_ACCESSIBLE, nid);
+	map = memmap_alloc(size, size, addr, nid, false);
 	if (!map)
 		panic("%s: Failed to allocate %lu bytes align=0x%lx nid=%d from=%pa\n",
 		      __func__, size, PAGE_SIZE, nid, &addr);
@@ -490,8 +489,7 @@ static void __init sparse_buffer_init(unsigned long size, int nid)
 	 * and we want it to be properly aligned to the section size - this is
 	 * especially the case for VMEMMAP which maps memmap to PMDs
 	 */
-	sparsemap_buf = memblock_alloc_exact_nid_raw(size, section_map_size(),
-					addr, MEMBLOCK_ALLOC_ACCESSIBLE, nid);
+	sparsemap_buf = memmap_alloc(size, section_map_size(), addr, nid, true);
 	sparsemap_buf_end = sparsemap_buf + size;
 }
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/4] memblock: stop poisoning raw allocations
  2021-07-14 12:37 [PATCH 0/4] mm: ensure consistency of memory map poisoning Mike Rapoport
                   ` (2 preceding siblings ...)
  2021-07-14 12:37 ` [PATCH 3/4] mm: introduce memmap_alloc() to unify memory map allocation Mike Rapoport
@ 2021-07-14 12:37 ` Mike Rapoport
  2021-07-31 17:13   ` Joe Perches
  3 siblings, 1 reply; 16+ messages in thread
From: Mike Rapoport @ 2021-07-14 12:37 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Michal Simek, Mike Rapoport, Mike Rapoport, linux-kernel, linux-mm

From: Mike Rapoport <rppt@linux.ibm.com>

Functions memblock_alloc_exact_nid_raw() and memblock_alloc_try_nid_raw()
are intended for early memory allocation without overhead of zeroing the
allocated memory. Since these functions were used to allocate the memory
map, they have ended up with addition of a call to page_init_poison() that
poisoned the allocated memory when CONFIG_PAGE_POISON was set.

Since the memory map is allocated using a dedicated memmep_alloc() function
that takes care of the poisoning, remove page poisoning from the
memblock_alloc_*_raw() functions.

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
---
 mm/memblock.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index 0041ff62c584..9748d0689f81 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1490,18 +1490,12 @@ void * __init memblock_alloc_exact_nid_raw(
 			phys_addr_t min_addr, phys_addr_t max_addr,
 			int nid)
 {
-	void *ptr;
-
 	memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=%pa max_addr=%pa %pS\n",
 		     __func__, (u64)size, (u64)align, nid, &min_addr,
 		     &max_addr, (void *)_RET_IP_);
 
-	ptr = memblock_alloc_internal(size, align,
-					   min_addr, max_addr, nid, true);
-	if (ptr && size > 0)
-		page_init_poison(ptr, size);
-
-	return ptr;
+	return memblock_alloc_internal(size, align, min_addr, max_addr, nid,
+				       true);
 }
 
 /**
@@ -1528,18 +1522,12 @@ void * __init memblock_alloc_try_nid_raw(
 			phys_addr_t min_addr, phys_addr_t max_addr,
 			int nid)
 {
-	void *ptr;
-
 	memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=%pa max_addr=%pa %pS\n",
 		     __func__, (u64)size, (u64)align, nid, &min_addr,
 		     &max_addr, (void *)_RET_IP_);
 
-	ptr = memblock_alloc_internal(size, align,
-					   min_addr, max_addr, nid, false);
-	if (ptr && size > 0)
-		page_init_poison(ptr, size);
-
-	return ptr;
+	return memblock_alloc_internal(size, align, min_addr, max_addr, nid,
+				       false);
 }
 
 /**
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] mm: introduce memmap_alloc() to unify memory map allocation
  2021-07-14 12:37 ` [PATCH 3/4] mm: introduce memmap_alloc() to unify memory map allocation Mike Rapoport
@ 2021-07-14 22:32   ` Andrew Morton
  2021-07-15  6:10     ` Mike Rapoport
  0 siblings, 1 reply; 16+ messages in thread
From: Andrew Morton @ 2021-07-14 22:32 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: Michal Simek, Mike Rapoport, linux-kernel, linux-mm

On Wed, 14 Jul 2021 15:37:38 +0300 Mike Rapoport <rppt@kernel.org> wrote:

> From: Mike Rapoport <rppt@linux.ibm.com>
> 
> There are several places that allocate memory for the memory map:
> alloc_node_mem_map() for FLATMEM, sparse_buffer_init() and
> __populate_section_memmap() for SPARSEMEM.
> 
> The memory allocated in the FLATMEM case is zeroed and it is never
> poisoned, regardless of CONFIG_PAGE_POISON setting.
> 
> The memory allocated in the SPARSEMEM cases is not zeroed and it is
> implicitly poisoned inside memblock if CONFIG_PAGE_POISON is set.
> 
> Introduce memmap_alloc() wrapper for memblock allocators that will be used
> for both FLATMEM and SPARSEMEM cases and will makei memory map zeroing and
> poisoning consistent for different memory models.
> 
> ...
>
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -6730,6 +6730,26 @@ static void __init memmap_init(void)
>  		init_unavailable_range(hole_pfn, end_pfn, zone_id, nid);
>  }
>  
> +void __init *memmap_alloc(phys_addr_t size, phys_addr_t align,
> +			  phys_addr_t min_addr, int nid, bool exact_nid)
> +{
> +	void *ptr;
> +
> +	if (exact_nid)
> +		ptr = memblock_alloc_exact_nid_raw(size, align, min_addr,
> +						   MEMBLOCK_ALLOC_ACCESSIBLE,
> +						   nid);
> +	else
> +		ptr = memblock_alloc_try_nid_raw(size, align, min_addr,
> +						 MEMBLOCK_ALLOC_ACCESSIBLE,
> +						 nid);
> +
> +	if (ptr && size > 0)
> +		page_init_poison(ptr, size);
> +
> +	return ptr;
> +}
> +
>  static int zone_batchsize(struct zone *zone)
>  {
>  #ifdef CONFIG_MMU
> @@ -7501,8 +7521,8 @@ static void __ref alloc_node_mem_map(struct pglist_data *pgdat)
>  		end = pgdat_end_pfn(pgdat);
>  		end = ALIGN(end, MAX_ORDER_NR_PAGES);
>  		size =  (end - start) * sizeof(struct page);
> -		map = memblock_alloc_node(size, SMP_CACHE_BYTES,
> -					  pgdat->node_id);
> +		map = memmap_alloc(size, SMP_CACHE_BYTES, MEMBLOCK_LOW_LIMIT,
> +				   pgdat->node_id, false);

Mostly offtopic, but...  Why is alloc_node_mem_map() marked __ref? 
afaict it can be __init?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/4] mm: introduce memmap_alloc() to unify memory map allocation
  2021-07-14 22:32   ` Andrew Morton
@ 2021-07-15  6:10     ` Mike Rapoport
  0 siblings, 0 replies; 16+ messages in thread
From: Mike Rapoport @ 2021-07-15  6:10 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Michal Simek, Mike Rapoport, linux-kernel, linux-mm

On Wed, Jul 14, 2021 at 03:32:08PM -0700, Andrew Morton wrote:
> On Wed, 14 Jul 2021 15:37:38 +0300 Mike Rapoport <rppt@kernel.org> wrote:
> 
> > From: Mike Rapoport <rppt@linux.ibm.com>
> > 
> > There are several places that allocate memory for the memory map:
> > alloc_node_mem_map() for FLATMEM, sparse_buffer_init() and
> > __populate_section_memmap() for SPARSEMEM.
> > 
> > The memory allocated in the FLATMEM case is zeroed and it is never
> > poisoned, regardless of CONFIG_PAGE_POISON setting.
> > 
> > The memory allocated in the SPARSEMEM cases is not zeroed and it is
> > implicitly poisoned inside memblock if CONFIG_PAGE_POISON is set.
> > 
> > Introduce memmap_alloc() wrapper for memblock allocators that will be used
> > for both FLATMEM and SPARSEMEM cases and will makei memory map zeroing and
> > poisoning consistent for different memory models.
> > 
> > ...
> >
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -6730,6 +6730,26 @@ static void __init memmap_init(void)
> >  		init_unavailable_range(hole_pfn, end_pfn, zone_id, nid);
> >  }
> >  
> > +void __init *memmap_alloc(phys_addr_t size, phys_addr_t align,
> > +			  phys_addr_t min_addr, int nid, bool exact_nid)
> > +{
> > +	void *ptr;
> > +
> > +	if (exact_nid)
> > +		ptr = memblock_alloc_exact_nid_raw(size, align, min_addr,
> > +						   MEMBLOCK_ALLOC_ACCESSIBLE,
> > +						   nid);
> > +	else
> > +		ptr = memblock_alloc_try_nid_raw(size, align, min_addr,
> > +						 MEMBLOCK_ALLOC_ACCESSIBLE,
> > +						 nid);
> > +
> > +	if (ptr && size > 0)
> > +		page_init_poison(ptr, size);
> > +
> > +	return ptr;
> > +}
> > +
> >  static int zone_batchsize(struct zone *zone)
> >  {
> >  #ifdef CONFIG_MMU
> > @@ -7501,8 +7521,8 @@ static void __ref alloc_node_mem_map(struct pglist_data *pgdat)
> >  		end = pgdat_end_pfn(pgdat);
> >  		end = ALIGN(end, MAX_ORDER_NR_PAGES);
> >  		size =  (end - start) * sizeof(struct page);
> > -		map = memblock_alloc_node(size, SMP_CACHE_BYTES,
> > -					  pgdat->node_id);
> > +		map = memmap_alloc(size, SMP_CACHE_BYTES, MEMBLOCK_LOW_LIMIT,
> > +				   pgdat->node_id, false);
> 
> Mostly offtopic, but...  Why is alloc_node_mem_map() marked __ref? 

Once free_area_init_node() was __meminit, I stopped digging at that point.

> afaict it can be __init?

Yes.

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/4] mm/page_alloc: always initialize memory map for the holes
  2021-07-14 12:37 ` [PATCH 1/4] mm/page_alloc: always initialize memory map for the holes Mike Rapoport
@ 2021-07-31 16:56   ` Guenter Roeck
  2021-07-31 18:30     ` Mike Rapoport
  2021-08-25 12:11   ` David Hildenbrand
  1 sibling, 1 reply; 16+ messages in thread
From: Guenter Roeck @ 2021-07-31 16:56 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Andrew Morton, Michal Simek, Mike Rapoport, linux-kernel, linux-mm

Hi,

On Wed, Jul 14, 2021 at 03:37:36PM +0300, Mike Rapoport wrote:
> From: Mike Rapoport <rppt@linux.ibm.com>
> 
> Currently memory map for the holes is initialized only when SPARSEMEM
> memory model is used. Yet, even with FLATMEM there could be holes in the
> physical memory layout that have memory map entries.
> 
> For instance, the memory reserved using e820 API on i386 or
> "reserved-memory" nodes in device tree would not appear in memblock.memory
> and hence the struct pages for such holes will be skipped during memory map
> initialization.
> 
> These struct pages will be zeroed because the memory map for FLATMEM
> systems is allocated with memblock_alloc_node() that clears the allocated
> memory. While zeroed struct pages do not cause immediate problems, the
> correct behaviour is to initialize every page using __init_single_page().
> Besides, enabling page poison for FLATMEM case will trigger
> PF_POISONED_CHECK() unless the memory map is properly initialized.
> 
> Make sure init_unavailable_range() is called for both SPARSEMEM and FLATMEM
> so that struct pages representing memory holes would appear as PG_Reserved
> with any memory layout.
> 
> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>

This patch causes microblaze petalogix-ml605 qemu emulations to fail
silently (no console output). Reverting it fixes the problem.

Guenter

---
Bisect log:

# bad: [8d4b477da1a807199ca60e0829357ce7aa6758d5] Add linux-next specific files for 20210730
# good: [ff1176468d368232b684f75e82563369208bc371] Linux 5.14-rc3
git bisect start 'HEAD' 'v5.14-rc3'
# good: [8f3eb1f5c702ef868d89799b03c21d122f2fe197] Merge remote-tracking branch 'bpf-next/for-next'
git bisect good 8f3eb1f5c702ef868d89799b03c21d122f2fe197
# good: [32286c7080c56c835f25302c38eebccf41b7b576] Merge remote-tracking branch 'tip/auto-latest'
git bisect good 32286c7080c56c835f25302c38eebccf41b7b576
# good: [70c40604c7d393f95171f49717a27bf8e05b5439] Merge remote-tracking branch 'dmaengine/next'
git bisect good 70c40604c7d393f95171f49717a27bf8e05b5439
# good: [b038834891b35ec410693028a500f769db132a81] Merge remote-tracking branch 'rust/rust-next'
git bisect good b038834891b35ec410693028a500f769db132a81
# bad: [d8f4e506a9ba375110945d75573b3304491e6350] memory-hotplug.rst: complete admin-guide overhaul
git bisect bad d8f4e506a9ba375110945d75573b3304491e6350
# good: [bef692dcfb7cdb5c960abfc31e2386a0ff41af54] lazy tlb: shoot lazies, a non-refcounting lazy tlb option
git bisect good bef692dcfb7cdb5c960abfc31e2386a0ff41af54
# bad: [5fcd957e2f0dc4cb25a6ee60ebfb1200de09c9d1] mm-migrate-demote-pages-during-reclaim-v11
git bisect bad 5fcd957e2f0dc4cb25a6ee60ebfb1200de09c9d1
# good: [8c2a82ab20eb09d217446989ae209f5ff19a64ac] mm/vmalloc: use batched page requests in bulk-allocator
git bisect good 8c2a82ab20eb09d217446989ae209f5ff19a64ac
# bad: [c36a5446e29f1461780b06785769b9402522f847] mm/page_alloc.c: fix 'zone_id' may be used uninitialized in this function warning
git bisect bad c36a5446e29f1461780b06785769b9402522f847
# good: [05e358c552628e26be3985933bea88e7512414c0] mm/kasan: move kasan.fault to mm/kasan/report.c
git bisect good 05e358c552628e26be3985933bea88e7512414c0
# bad: [b467ff7f560908e60ca181658b7ee48e5da94da1] microblaze: simplify pte_alloc_one_kernel()
git bisect bad b467ff7f560908e60ca181658b7ee48e5da94da1
# bad: [d2a572bf593a57246827bd79c91fe2ee6b7af1f0] mm/page_alloc: always initialize memory map for the holes
git bisect bad d2a572bf593a57246827bd79c91fe2ee6b7af1f0
# first bad commit: [d2a572bf593a57246827bd79c91fe2ee6b7af1f0] mm/page_alloc: always initialize memory map for the holes

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/4] memblock: stop poisoning raw allocations
  2021-07-14 12:37 ` [PATCH 4/4] memblock: stop poisoning raw allocations Mike Rapoport
@ 2021-07-31 17:13   ` Joe Perches
  2021-08-03  7:58     ` Mike Rapoport
  0 siblings, 1 reply; 16+ messages in thread
From: Joe Perches @ 2021-07-31 17:13 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton
  Cc: Michal Simek, Mike Rapoport, linux-kernel, linux-mm

On Wed, 2021-07-14 at 15:37 +0300, Mike Rapoport wrote:
> From: Mike Rapoport <rppt@linux.ibm.com>
> 
> Functions memblock_alloc_exact_nid_raw() and memblock_alloc_try_nid_raw()
> are intended for early memory allocation without overhead of zeroing the
> allocated memory. Since these functions were used to allocate the memory
> map, they have ended up with addition of a call to page_init_poison() that
> poisoned the allocated memory when CONFIG_PAGE_POISON was set.
> 
> Since the memory map is allocated using a dedicated memmep_alloc() function
> that takes care of the poisoning, remove page poisoning from the
> memblock_alloc_*_raw() functions.
[]
> diff --git a/mm/memblock.c b/mm/memblock.c
[]
> @@ -1490,18 +1490,12 @@ void * __init memblock_alloc_exact_nid_raw(
>  			phys_addr_t min_addr, phys_addr_t max_addr,
>  			int nid)
>  {
> -	void *ptr;
> -
>  	memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=%pa max_addr=%pa %pS\n",
>  		     __func__, (u64)size, (u64)align, nid, &min_addr,
>  		     &max_addr, (void *)_RET_IP_);

unassociated trivia:

casting _RET_IP_ back to void * seems odd as the define is
include/linux/kernel.h:#define _RET_IP_         (unsigned long)__builtin_return_address(0)

It's probably easier to understand as just __builtin_return_address(0)

> @@ -1528,18 +1522,12 @@ void * __init memblock_alloc_try_nid_raw(
>  			phys_addr_t min_addr, phys_addr_t max_addr,
>  			int nid)
>  {
> -	void *ptr;
> -
>  	memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=%pa max_addr=%pa %pS\n",
>  		     __func__, (u64)size, (u64)align, nid, &min_addr,
>  		     &max_addr, (void *)_RET_IP_);

here too


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/4] mm/page_alloc: always initialize memory map for the holes
  2021-07-31 16:56   ` Guenter Roeck
@ 2021-07-31 18:30     ` Mike Rapoport
  2021-07-31 19:11       ` Guenter Roeck
  0 siblings, 1 reply; 16+ messages in thread
From: Mike Rapoport @ 2021-07-31 18:30 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Andrew Morton, Michal Simek, Mike Rapoport, linux-kernel, linux-mm

On Sat, Jul 31, 2021 at 09:56:01AM -0700, Guenter Roeck wrote:
> Hi,
> 
> On Wed, Jul 14, 2021 at 03:37:36PM +0300, Mike Rapoport wrote:
> > From: Mike Rapoport <rppt@linux.ibm.com>
> > 
> > Currently memory map for the holes is initialized only when SPARSEMEM
> > memory model is used. Yet, even with FLATMEM there could be holes in the
> > physical memory layout that have memory map entries.
> > 
> > For instance, the memory reserved using e820 API on i386 or
> > "reserved-memory" nodes in device tree would not appear in memblock.memory
> > and hence the struct pages for such holes will be skipped during memory map
> > initialization.
> > 
> > These struct pages will be zeroed because the memory map for FLATMEM
> > systems is allocated with memblock_alloc_node() that clears the allocated
> > memory. While zeroed struct pages do not cause immediate problems, the
> > correct behaviour is to initialize every page using __init_single_page().
> > Besides, enabling page poison for FLATMEM case will trigger
> > PF_POISONED_CHECK() unless the memory map is properly initialized.
> > 
> > Make sure init_unavailable_range() is called for both SPARSEMEM and FLATMEM
> > so that struct pages representing memory holes would appear as PG_Reserved
> > with any memory layout.
> > 
> > Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
> 
> This patch causes microblaze petalogix-ml605 qemu emulations to fail
> silently (no console output). Reverting it fixes the problem.

It appears that petalogix-ml605 memory starts at 0x50000, but microblaze's
pfn_valid does not reject pfns < ARCH_PFN_OFFSET.

This should fix the issue:

diff --git a/arch/microblaze/include/asm/page.h b/arch/microblaze/include/asm/page.h
index ce550978f4fc..4b8b2fa78fc5 100644
--- a/arch/microblaze/include/asm/page.h
+++ b/arch/microblaze/include/asm/page.h
@@ -112,8 +112,7 @@ extern int page_is_ram(unsigned long pfn);
 #  define page_to_phys(page)     (page_to_pfn(page) << PAGE_SHIFT)
 
 #  define ARCH_PFN_OFFSET	(memory_start >> PAGE_SHIFT)
-#  define pfn_valid(pfn)	((pfn) < (max_mapnr + ARCH_PFN_OFFSET))
-
+#  define pfn_valid(pfn)	((pfn) >= ARCH_PFN_OFFSET && (pfn) < (max_mapnr + ARCH_PFN_OFFSET))
 # endif /* __ASSEMBLY__ */
 
 #define	virt_addr_valid(vaddr)	(pfn_valid(virt_to_pfn(vaddr)))
> Guenter
> 
> ---
> Bisect log:
> 
> # bad: [8d4b477da1a807199ca60e0829357ce7aa6758d5] Add linux-next specific files for 20210730
> # good: [ff1176468d368232b684f75e82563369208bc371] Linux 5.14-rc3
> git bisect start 'HEAD' 'v5.14-rc3'
> # good: [8f3eb1f5c702ef868d89799b03c21d122f2fe197] Merge remote-tracking branch 'bpf-next/for-next'
> git bisect good 8f3eb1f5c702ef868d89799b03c21d122f2fe197
> # good: [32286c7080c56c835f25302c38eebccf41b7b576] Merge remote-tracking branch 'tip/auto-latest'
> git bisect good 32286c7080c56c835f25302c38eebccf41b7b576
> # good: [70c40604c7d393f95171f49717a27bf8e05b5439] Merge remote-tracking branch 'dmaengine/next'
> git bisect good 70c40604c7d393f95171f49717a27bf8e05b5439
> # good: [b038834891b35ec410693028a500f769db132a81] Merge remote-tracking branch 'rust/rust-next'
> git bisect good b038834891b35ec410693028a500f769db132a81
> # bad: [d8f4e506a9ba375110945d75573b3304491e6350] memory-hotplug.rst: complete admin-guide overhaul
> git bisect bad d8f4e506a9ba375110945d75573b3304491e6350
> # good: [bef692dcfb7cdb5c960abfc31e2386a0ff41af54] lazy tlb: shoot lazies, a non-refcounting lazy tlb option
> git bisect good bef692dcfb7cdb5c960abfc31e2386a0ff41af54
> # bad: [5fcd957e2f0dc4cb25a6ee60ebfb1200de09c9d1] mm-migrate-demote-pages-during-reclaim-v11
> git bisect bad 5fcd957e2f0dc4cb25a6ee60ebfb1200de09c9d1
> # good: [8c2a82ab20eb09d217446989ae209f5ff19a64ac] mm/vmalloc: use batched page requests in bulk-allocator
> git bisect good 8c2a82ab20eb09d217446989ae209f5ff19a64ac
> # bad: [c36a5446e29f1461780b06785769b9402522f847] mm/page_alloc.c: fix 'zone_id' may be used uninitialized in this function warning
> git bisect bad c36a5446e29f1461780b06785769b9402522f847
> # good: [05e358c552628e26be3985933bea88e7512414c0] mm/kasan: move kasan.fault to mm/kasan/report.c
> git bisect good 05e358c552628e26be3985933bea88e7512414c0
> # bad: [b467ff7f560908e60ca181658b7ee48e5da94da1] microblaze: simplify pte_alloc_one_kernel()
> git bisect bad b467ff7f560908e60ca181658b7ee48e5da94da1
> # bad: [d2a572bf593a57246827bd79c91fe2ee6b7af1f0] mm/page_alloc: always initialize memory map for the holes
> git bisect bad d2a572bf593a57246827bd79c91fe2ee6b7af1f0
> # first bad commit: [d2a572bf593a57246827bd79c91fe2ee6b7af1f0] mm/page_alloc: always initialize memory map for the holes

-- 
Sincerely yours,
Mike.

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/4] mm/page_alloc: always initialize memory map for the holes
  2021-07-31 18:30     ` Mike Rapoport
@ 2021-07-31 19:11       ` Guenter Roeck
  0 siblings, 0 replies; 16+ messages in thread
From: Guenter Roeck @ 2021-07-31 19:11 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Andrew Morton, Michal Simek, Mike Rapoport, linux-kernel, linux-mm

Hi,

On 7/31/21 11:30 AM, Mike Rapoport wrote:
> On Sat, Jul 31, 2021 at 09:56:01AM -0700, Guenter Roeck wrote:
>> Hi,
>>
>> On Wed, Jul 14, 2021 at 03:37:36PM +0300, Mike Rapoport wrote:
>>> From: Mike Rapoport <rppt@linux.ibm.com>
>>>
>>> Currently memory map for the holes is initialized only when SPARSEMEM
>>> memory model is used. Yet, even with FLATMEM there could be holes in the
>>> physical memory layout that have memory map entries.
>>>
>>> For instance, the memory reserved using e820 API on i386 or
>>> "reserved-memory" nodes in device tree would not appear in memblock.memory
>>> and hence the struct pages for such holes will be skipped during memory map
>>> initialization.
>>>
>>> These struct pages will be zeroed because the memory map for FLATMEM
>>> systems is allocated with memblock_alloc_node() that clears the allocated
>>> memory. While zeroed struct pages do not cause immediate problems, the
>>> correct behaviour is to initialize every page using __init_single_page().
>>> Besides, enabling page poison for FLATMEM case will trigger
>>> PF_POISONED_CHECK() unless the memory map is properly initialized.
>>>
>>> Make sure init_unavailable_range() is called for both SPARSEMEM and FLATMEM
>>> so that struct pages representing memory holes would appear as PG_Reserved
>>> with any memory layout.
>>>
>>> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
>>
>> This patch causes microblaze petalogix-ml605 qemu emulations to fail
>> silently (no console output). Reverting it fixes the problem.
> 
> It appears that petalogix-ml605 memory starts at 0x50000, but microblaze's
> pfn_valid does not reject pfns < ARCH_PFN_OFFSET.
> 
> This should fix the issue:
> 
> diff --git a/arch/microblaze/include/asm/page.h b/arch/microblaze/include/asm/page.h
> index ce550978f4fc..4b8b2fa78fc5 100644
> --- a/arch/microblaze/include/asm/page.h
> +++ b/arch/microblaze/include/asm/page.h
> @@ -112,8 +112,7 @@ extern int page_is_ram(unsigned long pfn);
>   #  define page_to_phys(page)     (page_to_pfn(page) << PAGE_SHIFT)
>   
>   #  define ARCH_PFN_OFFSET	(memory_start >> PAGE_SHIFT)
> -#  define pfn_valid(pfn)	((pfn) < (max_mapnr + ARCH_PFN_OFFSET))
> -
> +#  define pfn_valid(pfn)	((pfn) >= ARCH_PFN_OFFSET && (pfn) < (max_mapnr + ARCH_PFN_OFFSET))
>   # endif /* __ASSEMBLY__ */
>   
>   #define	virt_addr_valid(vaddr)	(pfn_valid(virt_to_pfn(vaddr)))

Indeed, that does the trick.

Feel free to add

Tested-by: Guenter Roeck <linux@roeck-us.net>

to the patch.

Thanks,
Guenter

>> Guenter
>>
>> ---
>> Bisect log:
>>
>> # bad: [8d4b477da1a807199ca60e0829357ce7aa6758d5] Add linux-next specific files for 20210730
>> # good: [ff1176468d368232b684f75e82563369208bc371] Linux 5.14-rc3
>> git bisect start 'HEAD' 'v5.14-rc3'
>> # good: [8f3eb1f5c702ef868d89799b03c21d122f2fe197] Merge remote-tracking branch 'bpf-next/for-next'
>> git bisect good 8f3eb1f5c702ef868d89799b03c21d122f2fe197
>> # good: [32286c7080c56c835f25302c38eebccf41b7b576] Merge remote-tracking branch 'tip/auto-latest'
>> git bisect good 32286c7080c56c835f25302c38eebccf41b7b576
>> # good: [70c40604c7d393f95171f49717a27bf8e05b5439] Merge remote-tracking branch 'dmaengine/next'
>> git bisect good 70c40604c7d393f95171f49717a27bf8e05b5439
>> # good: [b038834891b35ec410693028a500f769db132a81] Merge remote-tracking branch 'rust/rust-next'
>> git bisect good b038834891b35ec410693028a500f769db132a81
>> # bad: [d8f4e506a9ba375110945d75573b3304491e6350] memory-hotplug.rst: complete admin-guide overhaul
>> git bisect bad d8f4e506a9ba375110945d75573b3304491e6350
>> # good: [bef692dcfb7cdb5c960abfc31e2386a0ff41af54] lazy tlb: shoot lazies, a non-refcounting lazy tlb option
>> git bisect good bef692dcfb7cdb5c960abfc31e2386a0ff41af54
>> # bad: [5fcd957e2f0dc4cb25a6ee60ebfb1200de09c9d1] mm-migrate-demote-pages-during-reclaim-v11
>> git bisect bad 5fcd957e2f0dc4cb25a6ee60ebfb1200de09c9d1
>> # good: [8c2a82ab20eb09d217446989ae209f5ff19a64ac] mm/vmalloc: use batched page requests in bulk-allocator
>> git bisect good 8c2a82ab20eb09d217446989ae209f5ff19a64ac
>> # bad: [c36a5446e29f1461780b06785769b9402522f847] mm/page_alloc.c: fix 'zone_id' may be used uninitialized in this function warning
>> git bisect bad c36a5446e29f1461780b06785769b9402522f847
>> # good: [05e358c552628e26be3985933bea88e7512414c0] mm/kasan: move kasan.fault to mm/kasan/report.c
>> git bisect good 05e358c552628e26be3985933bea88e7512414c0
>> # bad: [b467ff7f560908e60ca181658b7ee48e5da94da1] microblaze: simplify pte_alloc_one_kernel()
>> git bisect bad b467ff7f560908e60ca181658b7ee48e5da94da1
>> # bad: [d2a572bf593a57246827bd79c91fe2ee6b7af1f0] mm/page_alloc: always initialize memory map for the holes
>> git bisect bad d2a572bf593a57246827bd79c91fe2ee6b7af1f0
>> # first bad commit: [d2a572bf593a57246827bd79c91fe2ee6b7af1f0] mm/page_alloc: always initialize memory map for the holes
> 


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/4] memblock: stop poisoning raw allocations
  2021-07-31 17:13   ` Joe Perches
@ 2021-08-03  7:58     ` Mike Rapoport
  2021-08-03 16:19       ` Joe Perches
  0 siblings, 1 reply; 16+ messages in thread
From: Mike Rapoport @ 2021-08-03  7:58 UTC (permalink / raw)
  To: Joe Perches
  Cc: Andrew Morton, Michal Simek, Mike Rapoport, linux-kernel, linux-mm

On Sat, Jul 31, 2021 at 10:13:04AM -0700, Joe Perches wrote:
> On Wed, 2021-07-14 at 15:37 +0300, Mike Rapoport wrote:
> > From: Mike Rapoport <rppt@linux.ibm.com>
> > 
> > Functions memblock_alloc_exact_nid_raw() and memblock_alloc_try_nid_raw()
> > are intended for early memory allocation without overhead of zeroing the
> > allocated memory. Since these functions were used to allocate the memory
> > map, they have ended up with addition of a call to page_init_poison() that
> > poisoned the allocated memory when CONFIG_PAGE_POISON was set.
> > 
> > Since the memory map is allocated using a dedicated memmep_alloc() function
> > that takes care of the poisoning, remove page poisoning from the
> > memblock_alloc_*_raw() functions.
> []
> > diff --git a/mm/memblock.c b/mm/memblock.c
> []
> > @@ -1490,18 +1490,12 @@ void * __init memblock_alloc_exact_nid_raw(
> >  			phys_addr_t min_addr, phys_addr_t max_addr,
> >  			int nid)
> >  {
> > -	void *ptr;
> > -
> >  	memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=%pa max_addr=%pa %pS\n",
> >  		     __func__, (u64)size, (u64)align, nid, &min_addr,
> >  		     &max_addr, (void *)_RET_IP_);
> 
> unassociated trivia:
> 
> casting _RET_IP_ back to void * seems odd as the define is
> include/linux/kernel.h:#define _RET_IP_         (unsigned long)__builtin_return_address(0)
> 
> It's probably easier to understand as just __builtin_return_address(0)

Maybe, but I'm not sure it's worth the churn.
 
> > @@ -1528,18 +1522,12 @@ void * __init memblock_alloc_try_nid_raw(
> >  			phys_addr_t min_addr, phys_addr_t max_addr,
> >  			int nid)
> >  {
> > -	void *ptr;
> > -
> >  	memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=%pa max_addr=%pa %pS\n",
> >  		     __func__, (u64)size, (u64)align, nid, &min_addr,
> >  		     &max_addr, (void *)_RET_IP_);
> 
> here too
> 

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 4/4] memblock: stop poisoning raw allocations
  2021-08-03  7:58     ` Mike Rapoport
@ 2021-08-03 16:19       ` Joe Perches
  0 siblings, 0 replies; 16+ messages in thread
From: Joe Perches @ 2021-08-03 16:19 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Andrew Morton, Michal Simek, Mike Rapoport, linux-kernel, linux-mm

On Tue, 2021-08-03 at 10:58 +0300, Mike Rapoport wrote:
> On Sat, Jul 31, 2021 at 10:13:04AM -0700, Joe Perches wrote:
> > On Wed, 2021-07-14 at 15:37 +0300, Mike Rapoport wrote:
> > > From: Mike Rapoport <rppt@linux.ibm.com>
> > > 
> > > Functions memblock_alloc_exact_nid_raw() and memblock_alloc_try_nid_raw()
> > > are intended for early memory allocation without overhead of zeroing the
> > > allocated memory. Since these functions were used to allocate the memory
> > > map, they have ended up with addition of a call to page_init_poison() that
> > > poisoned the allocated memory when CONFIG_PAGE_POISON was set.
> > > 
> > > Since the memory map is allocated using a dedicated memmep_alloc() function
> > > that takes care of the poisoning, remove page poisoning from the
> > > memblock_alloc_*_raw() functions.
> > []
> > > diff --git a/mm/memblock.c b/mm/memblock.c
> > []
> > > @@ -1490,18 +1490,12 @@ void * __init memblock_alloc_exact_nid_raw(
> > >  			phys_addr_t min_addr, phys_addr_t max_addr,
> > >  			int nid)
> > >  {
> > > -	void *ptr;
> > > -
> > >  	memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=%pa max_addr=%pa %pS\n",
> > >  		     __func__, (u64)size, (u64)align, nid, &min_addr,
> > >  		     &max_addr, (void *)_RET_IP_);
> > 
> > unassociated trivia:
> > 
> > casting _RET_IP_ back to void * seems odd as the define is
> > include/linux/kernel.h:#define _RET_IP_         (unsigned long)__builtin_return_address(0)
> > 
> > It's probably easier to understand as just __builtin_return_address(0)
> 
> Maybe, but I'm not sure it's worth the churn.
>  

I think churn is overused as a blocking mechanism over readability.
I prefer readability.

$ git grep -P --name-only  '\(\s*void\s*\*\s*\)\s*_RET_IP_' | \
  xargs sed -r -i -e 's/\(\s*void\s*\*\s*\)\s*_RET_IP_/__builtin_return_address(0)/'
---
 arch/arm/mm/init.c                    |  2 +-
 arch/powerpc/kernel/irq.c             |  2 +-
 arch/powerpc/kernel/setup_32.c        |  2 +-
 arch/x86/mm/kasan_init_64.c           |  2 +-
 drivers/block/drbd/drbd_actlog.c      |  2 +-
 drivers/char/random.c                 |  2 +-
 drivers/firmware/arm_scmi/driver.c    |  2 +-
 drivers/firmware/ti_sci.c             |  2 +-
 drivers/gpu/drm/i915/gt/intel_reset.c |  2 +-
 drivers/gpu/drm/i915/i915_utils.c     |  2 +-
 drivers/soc/ti/smartreflex.c          | 10 +++++-----
 mm/memblock.c                         | 20 ++++++++++----------
 mm/util.c                             |  2 +-
 13 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 6162a070a4104..a4aa1c94e65d5 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -156,7 +156,7 @@ phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align)
 	phys = memblock_phys_alloc(size, align);
 	if (!phys)
 		panic("Failed to steal %pa bytes at %pS\n",
-		      &size, (void *)_RET_IP_);
+		      &size, __builtin_return_address(0));
 
 	memblock_free(phys, size);
 	memblock_remove(phys, size);
diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
index 91e63eac4e8fa..ff171281a8e0b 100644
--- a/arch/powerpc/kernel/irq.c
+++ b/arch/powerpc/kernel/irq.c
@@ -777,7 +777,7 @@ DEFINE_INTERRUPT_HANDLER_ASYNC(do_IRQ)
 static void *__init alloc_vm_stack(void)
 {
 	return __vmalloc_node(THREAD_SIZE, THREAD_ALIGN, THREADINFO_GFP,
-			      NUMA_NO_NODE, (void *)_RET_IP_);
+			      NUMA_NO_NODE, __builtin_return_address(0));
 }
 
 static void __init vmap_irqstack_init(void)
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index 7ec5c47fce0e3..aec19db5c319d 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -143,7 +143,7 @@ static void *__init alloc_stack(void)
 
 	if (!ptr)
 		panic("cannot allocate %d bytes for stack at %pS\n",
-		      THREAD_SIZE, (void *)_RET_IP_);
+		      THREAD_SIZE, __builtin_return_address(0));
 
 	return ptr;
 }
diff --git a/arch/x86/mm/kasan_init_64.c b/arch/x86/mm/kasan_init_64.c
index 1a50434c8a4da..df887e14ed6cb 100644
--- a/arch/x86/mm/kasan_init_64.c
+++ b/arch/x86/mm/kasan_init_64.c
@@ -30,7 +30,7 @@ static __init void *early_alloc(size_t size, int nid, bool should_panic)
 
 	if (!ptr && should_panic)
 		panic("%pS: Failed to allocate page, nid=%d from=%lx\n",
-		      (void *)_RET_IP_, nid, __pa(MAX_DMA_ADDRESS));
+		      __builtin_return_address(0), nid, __pa(MAX_DMA_ADDRESS));
 
 	return ptr;
 }
diff --git a/drivers/block/drbd/drbd_actlog.c b/drivers/block/drbd/drbd_actlog.c
index 72cf7603d51fc..657e2260c4d1b 100644
--- a/drivers/block/drbd/drbd_actlog.c
+++ b/drivers/block/drbd/drbd_actlog.c
@@ -185,7 +185,7 @@ int drbd_md_sync_page_io(struct drbd_device *device, struct drbd_backing_dev *bd
 	dynamic_drbd_dbg(device, "meta_data io: %s [%d]:%s(,%llus,%s) %pS\n",
 	     current->comm, current->pid, __func__,
 	     (unsigned long long)sector, (op == REQ_OP_WRITE) ? "WRITE" : "READ",
-	     (void*)_RET_IP_ );
+	     __builtin_return_address(0) );
 
 	if (sector < drbd_md_first_sector(bdev) ||
 	    sector + 7 > drbd_md_last_sector(bdev))
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 605969ed0f965..04019eaf807bc 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1487,7 +1487,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
 }
 
 #define warn_unseeded_randomness(previous) \
-	_warn_unseeded_randomness(__func__, (void *) _RET_IP_, (previous))
+	_warn_unseeded_randomness(__func__, __builtin_return_address(0), (previous))
 
 static void _warn_unseeded_randomness(const char *func_name, void *caller,
 				      void **previous)
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 9b2e8d42a9922..34df6472c5672 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -468,7 +468,7 @@ static int do_xfer(const struct scmi_protocol_handle *ph,
 		timeout = msecs_to_jiffies(info->desc->max_rx_timeout_ms);
 		if (!wait_for_completion_timeout(&xfer->done, timeout)) {
 			dev_err(dev, "timed out in resp(caller: %pS)\n",
-				(void *)_RET_IP_);
+				__builtin_return_address(0));
 			ret = -ETIMEDOUT;
 		}
 	}
diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
index 235c7e7869aa7..7a74fec632250 100644
--- a/drivers/firmware/ti_sci.c
+++ b/drivers/firmware/ti_sci.c
@@ -417,7 +417,7 @@ static inline int ti_sci_do_xfer(struct ti_sci_info *info,
 	timeout = msecs_to_jiffies(info->desc->max_rx_timeout_ms);
 	if (!wait_for_completion_timeout(&xfer->done, timeout)) {
 		dev_err(dev, "Mbox timedout in resp(caller: %pS)\n",
-			(void *)_RET_IP_);
+			__builtin_return_address(0));
 		ret = -ETIMEDOUT;
 	}
 	/*
diff --git a/drivers/gpu/drm/i915/gt/intel_reset.c b/drivers/gpu/drm/i915/gt/intel_reset.c
index 72251638d4eab..ff16dc55278c5 100644
--- a/drivers/gpu/drm/i915/gt/intel_reset.c
+++ b/drivers/gpu/drm/i915/gt/intel_reset.c
@@ -925,7 +925,7 @@ void intel_gt_set_wedged(struct intel_gt *gt)
 		struct intel_engine_cs *engine;
 		enum intel_engine_id id;
 
-		drm_printf(&p, "called from %pS\n", (void *)_RET_IP_);
+		drm_printf(&p, "called from %pS\n", __builtin_return_address(0));
 		for_each_engine(engine, gt, id) {
 			if (intel_engine_is_idle(engine))
 				continue;
diff --git a/drivers/gpu/drm/i915/i915_utils.c b/drivers/gpu/drm/i915/i915_utils.c
index f9e780dee9dec..7a2d7a9a3f9c1 100644
--- a/drivers/gpu/drm/i915/i915_utils.c
+++ b/drivers/gpu/drm/i915/i915_utils.c
@@ -52,7 +52,7 @@ __i915_printk(struct drm_i915_private *dev_priv, const char *level,
 void add_taint_for_CI(struct drm_i915_private *i915, unsigned int taint)
 {
 	__i915_printk(i915, KERN_NOTICE, "CI tainted:%#x by %pS\n",
-		      taint, (void *)_RET_IP_);
+		      taint, __builtin_return_address(0));
 
 	/* Failures that occur during fault injection testing are expected */
 	if (!i915_error_injected())
diff --git a/drivers/soc/ti/smartreflex.c b/drivers/soc/ti/smartreflex.c
index 06cbee5fd2542..8448a6ea32aeb 100644
--- a/drivers/soc/ti/smartreflex.c
+++ b/drivers/soc/ti/smartreflex.c
@@ -357,7 +357,7 @@ int sr_configure_errgen(struct omap_sr *sr)
 
 	if (!sr) {
 		pr_warn("%s: NULL omap_sr from %pS\n",
-			__func__, (void *)_RET_IP_);
+			__func__, __builtin_return_address(0));
 		return -EINVAL;
 	}
 
@@ -424,7 +424,7 @@ int sr_disable_errgen(struct omap_sr *sr)
 
 	if (!sr) {
 		pr_warn("%s: NULL omap_sr from %pS\n",
-			__func__, (void *)_RET_IP_);
+			__func__, __builtin_return_address(0));
 		return -EINVAL;
 	}
 
@@ -479,7 +479,7 @@ int sr_configure_minmax(struct omap_sr *sr)
 
 	if (!sr) {
 		pr_warn("%s: NULL omap_sr from %pS\n",
-			__func__, (void *)_RET_IP_);
+			__func__, __builtin_return_address(0));
 		return -EINVAL;
 	}
 
@@ -564,7 +564,7 @@ int sr_enable(struct omap_sr *sr, unsigned long volt)
 
 	if (!sr) {
 		pr_warn("%s: NULL omap_sr from %pS\n",
-			__func__, (void *)_RET_IP_);
+			__func__, __builtin_return_address(0));
 		return -EINVAL;
 	}
 
@@ -616,7 +616,7 @@ void sr_disable(struct omap_sr *sr)
 {
 	if (!sr) {
 		pr_warn("%s: NULL omap_sr from %pS\n",
-			__func__, (void *)_RET_IP_);
+			__func__, __builtin_return_address(0));
 		return;
 	}
 
diff --git a/mm/memblock.c b/mm/memblock.c
index a69449bffc8d2..fe620b358b560 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -684,7 +684,7 @@ int __init_memblock memblock_add(phys_addr_t base, phys_addr_t size)
 	phys_addr_t end = base + size - 1;
 
 	memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
-		     &base, &end, (void *)_RET_IP_);
+		     &base, &end, __builtin_return_address(0));
 
 	return memblock_add_range(&memblock.memory, base, size, MAX_NUMNODES, 0);
 }
@@ -785,7 +785,7 @@ int __init_memblock memblock_remove(phys_addr_t base, phys_addr_t size)
 	phys_addr_t end = base + size - 1;
 
 	memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
-		     &base, &end, (void *)_RET_IP_);
+		     &base, &end, __builtin_return_address(0));
 
 	return memblock_remove_range(&memblock.memory, base, size);
 }
@@ -803,7 +803,7 @@ int __init_memblock memblock_free(phys_addr_t base, phys_addr_t size)
 	phys_addr_t end = base + size - 1;
 
 	memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
-		     &base, &end, (void *)_RET_IP_);
+		     &base, &end, __builtin_return_address(0));
 
 	kmemleak_free_part_phys(base, size);
 	return memblock_remove_range(&memblock.reserved, base, size);
@@ -814,7 +814,7 @@ int __init_memblock memblock_reserve(phys_addr_t base, phys_addr_t size)
 	phys_addr_t end = base + size - 1;
 
 	memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
-		     &base, &end, (void *)_RET_IP_);
+		     &base, &end, __builtin_return_address(0));
 
 	return memblock_add_range(&memblock.reserved, base, size, MAX_NUMNODES, 0);
 }
@@ -825,7 +825,7 @@ int __init_memblock memblock_physmem_add(phys_addr_t base, phys_addr_t size)
 	phys_addr_t end = base + size - 1;
 
 	memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
-		     &base, &end, (void *)_RET_IP_);
+		     &base, &end, __builtin_return_address(0));
 
 	return memblock_add_range(&physmem, base, size, MAX_NUMNODES, 0);
 }
@@ -1392,7 +1392,7 @@ phys_addr_t __init memblock_phys_alloc_range(phys_addr_t size,
 {
 	memblock_dbg("%s: %llu bytes align=0x%llx from=%pa max_addr=%pa %pS\n",
 		     __func__, (u64)size, (u64)align, &start, &end,
-		     (void *)_RET_IP_);
+		     __builtin_return_address(0));
 	return memblock_alloc_range_nid(size, align, start, end, NUMA_NO_NODE,
 					false);
 }
@@ -1493,7 +1493,7 @@ void * __init memblock_alloc_exact_nid_raw(
 {
 	memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=%pa max_addr=%pa %pS\n",
 		     __func__, (u64)size, (u64)align, nid, &min_addr,
-		     &max_addr, (void *)_RET_IP_);
+		     &max_addr, __builtin_return_address(0));
 
 	return memblock_alloc_internal(size, align, min_addr, max_addr, nid,
 				       true);
@@ -1525,7 +1525,7 @@ void * __init memblock_alloc_try_nid_raw(
 {
 	memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=%pa max_addr=%pa %pS\n",
 		     __func__, (u64)size, (u64)align, nid, &min_addr,
-		     &max_addr, (void *)_RET_IP_);
+		     &max_addr, __builtin_return_address(0));
 
 	return memblock_alloc_internal(size, align, min_addr, max_addr, nid,
 				       false);
@@ -1557,7 +1557,7 @@ void * __init memblock_alloc_try_nid(
 
 	memblock_dbg("%s: %llu bytes align=0x%llx nid=%d from=%pa max_addr=%pa %pS\n",
 		     __func__, (u64)size, (u64)align, nid, &min_addr,
-		     &max_addr, (void *)_RET_IP_);
+		     &max_addr, __builtin_return_address(0));
 	ptr = memblock_alloc_internal(size, align,
 					   min_addr, max_addr, nid, false);
 	if (ptr)
@@ -1581,7 +1581,7 @@ void __init __memblock_free_late(phys_addr_t base, phys_addr_t size)
 
 	end = base + size - 1;
 	memblock_dbg("%s: [%pa-%pa] %pS\n",
-		     __func__, &base, &end, (void *)_RET_IP_);
+		     __func__, &base, &end, __builtin_return_address(0));
 	kmemleak_free_part_phys(base, size);
 	cursor = PFN_UP(base);
 	end = PFN_DOWN(base + size);
diff --git a/mm/util.c b/mm/util.c
index 821c81717498e..385b232848e47 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -492,7 +492,7 @@ int __account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc,
 	}
 
 	pr_debug("%s: [%d] caller %ps %c%lu %lu/%lu%s\n", __func__, task->pid,
-		 (void *)_RET_IP_, (inc) ? '+' : '-', pages << PAGE_SHIFT,
+		 __builtin_return_address(0), (inc) ? '+' : '-', pages << PAGE_SHIFT,
 		 locked_vm << PAGE_SHIFT, task_rlimit(task, RLIMIT_MEMLOCK),
 		 ret ? " - exceeded" : "");
 


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/4] microblaze: simplify pte_alloc_one_kernel()
  2021-07-14 12:37 ` [PATCH 2/4] microblaze: simplify pte_alloc_one_kernel() Mike Rapoport
@ 2021-08-25 10:09   ` Michal Simek
  2021-08-25 12:13   ` David Hildenbrand
  1 sibling, 0 replies; 16+ messages in thread
From: Michal Simek @ 2021-08-25 10:09 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton; +Cc: Mike Rapoport, linux-kernel, linux-mm



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

-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/4] mm/page_alloc: always initialize memory map for the holes
  2021-07-14 12:37 ` [PATCH 1/4] mm/page_alloc: always initialize memory map for the holes Mike Rapoport
  2021-07-31 16:56   ` Guenter Roeck
@ 2021-08-25 12:11   ` David Hildenbrand
  1 sibling, 0 replies; 16+ messages in thread
From: David Hildenbrand @ 2021-08-25 12:11 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton
  Cc: Michal Simek, Mike Rapoport, linux-kernel, linux-mm

On 14.07.21 14:37, Mike Rapoport wrote:
> From: Mike Rapoport <rppt@linux.ibm.com>
> 
> Currently memory map for the holes is initialized only when SPARSEMEM
> memory model is used. Yet, even with FLATMEM there could be holes in the
> physical memory layout that have memory map entries.
> 
> For instance, the memory reserved using e820 API on i386 or
> "reserved-memory" nodes in device tree would not appear in memblock.memory
> and hence the struct pages for such holes will be skipped during memory map
> initialization.
> 
> These struct pages will be zeroed because the memory map for FLATMEM
> systems is allocated with memblock_alloc_node() that clears the allocated
> memory. While zeroed struct pages do not cause immediate problems, the
> correct behaviour is to initialize every page using __init_single_page().
> Besides, enabling page poison for FLATMEM case will trigger
> PF_POISONED_CHECK() unless the memory map is properly initialized.
> 
> Make sure init_unavailable_range() is called for both SPARSEMEM and FLATMEM
> so that struct pages representing memory holes would appear as PG_Reserved
> with any memory layout.
> 
> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
> ---
>   mm/page_alloc.c | 8 --------
>   1 file changed, 8 deletions(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 3b97e17806be..878d7af4403d 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -6624,7 +6624,6 @@ static void __meminit zone_init_free_lists(struct zone *zone)
>   	}
>   }
>   
> -#if !defined(CONFIG_FLATMEM)
>   /*
>    * Only struct pages that correspond to ranges defined by memblock.memory
>    * are zeroed and initialized by going through __init_single_page() during
> @@ -6669,13 +6668,6 @@ static void __init init_unavailable_range(unsigned long spfn,
>   		pr_info("On node %d, zone %s: %lld pages in unavailable ranges",
>   			node, zone_names[zone], pgcnt);
>   }
> -#else
> -static inline void init_unavailable_range(unsigned long spfn,
> -					  unsigned long epfn,
> -					  int zone, int node)
> -{
> -}
> -#endif
>   
>   static void __init memmap_init_zone_range(struct zone *zone,
>   					  unsigned long start_pfn,
> 

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/4] microblaze: simplify pte_alloc_one_kernel()
  2021-07-14 12:37 ` [PATCH 2/4] microblaze: simplify pte_alloc_one_kernel() Mike Rapoport
  2021-08-25 10:09   ` Michal Simek
@ 2021-08-25 12:13   ` David Hildenbrand
  1 sibling, 0 replies; 16+ messages in thread
From: David Hildenbrand @ 2021-08-25 12:13 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton
  Cc: Michal Simek, Mike Rapoport, linux-kernel, linux-mm

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>

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-08-25 12:13 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14 12:37 [PATCH 0/4] mm: ensure consistency of memory map poisoning Mike Rapoport
2021-07-14 12:37 ` [PATCH 1/4] mm/page_alloc: always initialize memory map for the holes Mike Rapoport
2021-07-31 16:56   ` Guenter Roeck
2021-07-31 18:30     ` Mike Rapoport
2021-07-31 19:11       ` Guenter Roeck
2021-08-25 12:11   ` David Hildenbrand
2021-07-14 12:37 ` [PATCH 2/4] microblaze: simplify pte_alloc_one_kernel() Mike Rapoport
2021-08-25 10:09   ` Michal Simek
2021-08-25 12:13   ` David Hildenbrand
2021-07-14 12:37 ` [PATCH 3/4] mm: introduce memmap_alloc() to unify memory map allocation Mike Rapoport
2021-07-14 22:32   ` Andrew Morton
2021-07-15  6:10     ` Mike Rapoport
2021-07-14 12:37 ` [PATCH 4/4] memblock: stop poisoning raw allocations Mike Rapoport
2021-07-31 17:13   ` Joe Perches
2021-08-03  7:58     ` Mike Rapoport
2021-08-03 16:19       ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).