Re: [PATCH v2 09/13] arch, mm: set max_mapnr when allocating memory map for FLATMEM

2025-03-14 Thread Christophe Leroy



Le 13/03/2025 à 14:49, Mike Rapoport a écrit :

From: "Mike Rapoport (Microsoft)" 

max_mapnr is essentially the size of the memory map for systems that use
FLATMEM. There is no reason to calculate it in each and every architecture
when it's anyway calculated in alloc_node_mem_map().

Drop setting of max_mapnr from architecture code and set it once in
alloc_node_mem_map().


As far as I can see alloc_node_mem_map() is called quite late.

I fear that it will regress commit daa9ada2093e ("powerpc/mm: Fix boot 
crash with FLATMEM")


Can you check ?

Christophe



While on it, move definition of mem_map and max_mapnr to mm/mm_init.c so
there won't be two copies for MMU and !MMU variants.

Acked-by: Dave Hansen# x86
Signed-off-by: Mike Rapoport (Microsoft) 
---
  arch/alpha/mm/init.c   |  1 -
  arch/arc/mm/init.c |  5 -
  arch/arm/mm/init.c |  2 --
  arch/csky/mm/init.c|  4 
  arch/loongarch/mm/init.c   |  1 -
  arch/microblaze/mm/init.c  |  4 
  arch/mips/mm/init.c|  8 
  arch/nios2/kernel/setup.c  |  1 -
  arch/nios2/mm/init.c   |  2 +-
  arch/openrisc/mm/init.c|  1 -
  arch/parisc/mm/init.c  |  1 -
  arch/powerpc/kernel/setup-common.c |  2 --
  arch/riscv/mm/init.c   |  1 -
  arch/s390/mm/init.c|  1 -
  arch/sh/mm/init.c  |  1 -
  arch/sparc/mm/init_32.c|  1 -
  arch/um/include/shared/mem_user.h  |  1 -
  arch/um/kernel/physmem.c   | 12 
  arch/um/kernel/um_arch.c   |  1 -
  arch/x86/mm/init_32.c  |  3 ---
  arch/xtensa/mm/init.c  |  1 -
  include/asm-generic/memory_model.h |  5 +++--
  include/linux/mm.h | 11 ---
  mm/memory.c|  8 
  mm/mm_init.c   | 25 +
  mm/nommu.c |  4 
  26 files changed, 21 insertions(+), 86 deletions(-)

diff --git a/arch/alpha/mm/init.c b/arch/alpha/mm/init.c
index 61c2198b1359..ec0eeae9c653 100644
--- a/arch/alpha/mm/init.c
+++ b/arch/alpha/mm/init.c
@@ -276,7 +276,6 @@ srm_paging_stop (void)
  void __init
  mem_init(void)
  {
-   set_max_mapnr(max_low_pfn);
high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
memblock_free_all();
  }
diff --git a/arch/arc/mm/init.c b/arch/arc/mm/init.c
index 6a71b23f1383..7ef883d58dc1 100644
--- a/arch/arc/mm/init.c
+++ b/arch/arc/mm/init.c
@@ -154,11 +154,6 @@ void __init setup_arch_memory(void)
  
  	arch_pfn_offset = min(min_low_pfn, min_high_pfn);

kmap_init();
-
-#else /* CONFIG_HIGHMEM */
-   /* pfn_valid() uses this when FLATMEM=y and HIGHMEM=n */
-   max_mapnr = max_low_pfn - min_low_pfn;
-
  #endif /* CONFIG_HIGHMEM */
  
  	free_area_init(max_zone_pfn);

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 9aec1cb2386f..d4bcc745a044 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -275,8 +275,6 @@ void __init mem_init(void)
swiotlb_init(max_pfn > arm_dma_pfn_limit, SWIOTLB_VERBOSE);
  #endif
  
-	set_max_mapnr(pfn_to_page(max_pfn) - mem_map);

-
  #ifdef CONFIG_SA
/* now that our DMA memory is actually so designated, we can free it */
memblock_phys_free(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
diff --git a/arch/csky/mm/init.c b/arch/csky/mm/init.c
index ab51acbc19b2..ba6694d6170a 100644
--- a/arch/csky/mm/init.c
+++ b/arch/csky/mm/init.c
@@ -46,10 +46,6 @@ void __init mem_init(void)
  {
  #ifdef CONFIG_HIGHMEM
unsigned long tmp;
-
-   set_max_mapnr(highend_pfn - ARCH_PFN_OFFSET);
-#else
-   set_max_mapnr(max_low_pfn - ARCH_PFN_OFFSET);
  #endif
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
  
diff --git a/arch/loongarch/mm/init.c b/arch/loongarch/mm/init.c

index ca5aa5f46a9f..00449df50db1 100644
--- a/arch/loongarch/mm/init.c
+++ b/arch/loongarch/mm/init.c
@@ -78,7 +78,6 @@ void __init paging_init(void)
  
  void __init mem_init(void)

  {
-   max_mapnr = max_low_pfn;
high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
  
  	memblock_free_all();

diff --git a/arch/microblaze/mm/init.c b/arch/microblaze/mm/init.c
index 4520c5741579..857cd2b44bcf 100644
--- a/arch/microblaze/mm/init.c
+++ b/arch/microblaze/mm/init.c
@@ -104,17 +104,13 @@ void __init setup_memory(void)
 *
 * min_low_pfn - the first page (mm/bootmem.c - node_boot_start)
 * max_low_pfn
-* max_mapnr - the first unused page (mm/bootmem.c - node_low_pfn)
 */
  
  	/* memory start is from the kernel end (aligned) to higher addr */

min_low_pfn = memory_start >> PAGE_SHIFT; /* minimum for allocation */
-   /* RAM is assumed contiguous */
-   max_mapnr = memory_size >> PAGE_SHIFT;
max_low_pfn = ((u64)memory_start + (u64)lowmem_size) >> PAGE_SHIFT;
max_pfn = ((u64)memory_start

[PATCH 05/41] arc: Replace __ASSEMBLY__ with __ASSEMBLER__ in the non-uapi headers

2025-03-14 Thread Thomas Huth
While the GCC and Clang compilers already define __ASSEMBLER__
automatically when compiling assembly code, __ASSEMBLY__ is a
macro that only gets defined by the Makefiles in the kernel.
This can be very confusing when switching between userspace
and kernelspace coding, or when dealing with uapi headers that
rather should use __ASSEMBLER__ instead. So let's standardize on
the __ASSEMBLER__ macro that is provided by the compilers now.

This is a completely mechanical patch (done with a simple "sed -i"
statement).

Cc: Vineet Gupta 
Cc: linux-snps-arc@lists.infradead.org
Signed-off-by: Thomas Huth 
---
 arch/arc/include/asm/arcregs.h| 2 +-
 arch/arc/include/asm/atomic.h | 4 ++--
 arch/arc/include/asm/bitops.h | 4 ++--
 arch/arc/include/asm/bug.h| 4 ++--
 arch/arc/include/asm/cache.h  | 4 ++--
 arch/arc/include/asm/current.h| 4 ++--
 arch/arc/include/asm/dsp-impl.h   | 2 +-
 arch/arc/include/asm/dsp.h| 4 ++--
 arch/arc/include/asm/dwarf.h  | 4 ++--
 arch/arc/include/asm/entry.h  | 4 ++--
 arch/arc/include/asm/irqflags-arcv2.h | 4 ++--
 arch/arc/include/asm/irqflags-compact.h   | 4 ++--
 arch/arc/include/asm/jump_label.h | 4 ++--
 arch/arc/include/asm/linkage.h| 6 +++---
 arch/arc/include/asm/mmu-arcv2.h  | 4 ++--
 arch/arc/include/asm/mmu.h| 2 +-
 arch/arc/include/asm/page.h   | 4 ++--
 arch/arc/include/asm/pgtable-bits-arcv2.h | 4 ++--
 arch/arc/include/asm/pgtable-levels.h | 4 ++--
 arch/arc/include/asm/pgtable.h| 4 ++--
 arch/arc/include/asm/processor.h  | 4 ++--
 arch/arc/include/asm/ptrace.h | 4 ++--
 arch/arc/include/asm/switch_to.h  | 2 +-
 arch/arc/include/asm/thread_info.h| 4 ++--
 24 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/arch/arc/include/asm/arcregs.h b/arch/arc/include/asm/arcregs.h
index 005d9e4d187a0..a31bbf5c8bbc8 100644
--- a/arch/arc/include/asm/arcregs.h
+++ b/arch/arc/include/asm/arcregs.h
@@ -144,7 +144,7 @@
 #define ARC_AUX_AGU_MOD2   0x5E2
 #define ARC_AUX_AGU_MOD3   0x5E3
 
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 
 #include 
 
diff --git a/arch/arc/include/asm/atomic.h b/arch/arc/include/asm/atomic.h
index 592d7fffc223c..e615c42b93bab 100644
--- a/arch/arc/include/asm/atomic.h
+++ b/arch/arc/include/asm/atomic.h
@@ -6,7 +6,7 @@
 #ifndef _ASM_ARC_ATOMIC_H
 #define _ASM_ARC_ATOMIC_H
 
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 
 #include 
 #include 
@@ -31,6 +31,6 @@
 #include 
 #endif
 
-#endif /* !__ASSEMBLY__ */
+#endif /* !__ASSEMBLER__ */
 
 #endif
diff --git a/arch/arc/include/asm/bitops.h b/arch/arc/include/asm/bitops.h
index f5a936496f060..5340c28713927 100644
--- a/arch/arc/include/asm/bitops.h
+++ b/arch/arc/include/asm/bitops.h
@@ -10,7 +10,7 @@
 #error only  can be included directly
 #endif
 
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 
 #include 
 #include 
@@ -192,6 +192,6 @@ static inline __attribute__ ((const)) unsigned long 
__ffs(unsigned long x)
 #include 
 #include 
 
-#endif /* !__ASSEMBLY__ */
+#endif /* !__ASSEMBLER__ */
 
 #endif
diff --git a/arch/arc/include/asm/bug.h b/arch/arc/include/asm/bug.h
index 4c453ba96c519..171c16021f709 100644
--- a/arch/arc/include/asm/bug.h
+++ b/arch/arc/include/asm/bug.h
@@ -6,7 +6,7 @@
 #ifndef _ASM_ARC_BUG_H
 #define _ASM_ARC_BUG_H
 
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 
 #include 
 
@@ -29,6 +29,6 @@ void die(const char *str, struct pt_regs *regs, unsigned long 
address);
 
 #include 
 
-#endif /* !__ASSEMBLY__ */
+#endif /* !__ASSEMBLER__ */
 
 #endif
diff --git a/arch/arc/include/asm/cache.h b/arch/arc/include/asm/cache.h
index f0f1fc5d62b66..040a97f4dd829 100644
--- a/arch/arc/include/asm/cache.h
+++ b/arch/arc/include/asm/cache.h
@@ -23,7 +23,7 @@
  */
 #define ARC_UNCACHED_ADDR_SPACE0xc000
 
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 
 #include 
 
@@ -65,7 +65,7 @@
 extern int ioc_enable;
 extern unsigned long perip_base, perip_end;
 
-#endif /* !__ASSEMBLY__ */
+#endif /* !__ASSEMBLER__ */
 
 /* Instruction cache related Auxiliary registers */
 #define ARC_REG_IC_BCR 0x77/* Build Config reg */
diff --git a/arch/arc/include/asm/current.h b/arch/arc/include/asm/current.h
index 06be89f6f2f05..03ffd005f3fa6 100644
--- a/arch/arc/include/asm/current.h
+++ b/arch/arc/include/asm/current.h
@@ -9,7 +9,7 @@
 #ifndef _ASM_ARC_CURRENT_H
 #define _ASM_ARC_CURRENT_H
 
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 
 #ifdef CONFIG_ARC_CURR_IN_REG
 
@@ -20,6 +20,6 @@ register struct task_struct *curr_arc asm("gp");
 #include 
 #endif /* ! CONFIG_ARC_CURR_IN_REG */
 
-#endif /* ! __ASSEMBLY__ */
+#endif /* ! __ASSEMBLER__ */
 
 #endif /* _ASM_ARC_CURRENT_H */
diff --git a/arch/arc/include/asm/dsp-impl.h b/arch/arc/include/asm/dsp-impl.h
index cd5636dfeb6f4..fd5fdaad90c16 100644
--- a/arch/arc/include/asm/dsp-impl.h
+++ b/arch/arc/in

[PATCH 04/41] arc: Replace __ASSEMBLY__ with __ASSEMBLER__ in uapi headers

2025-03-14 Thread Thomas Huth
__ASSEMBLY__ is only defined by the Makefile of the kernel, so
this is not really useful for uapi headers (unless the userspace
Makefile defines it, too). Let's switch to __ASSEMBLER__ which
gets set automatically by the compiler when compiling assembly
code.

Cc: Vineet Gupta 
Cc: linux-snps-arc@lists.infradead.org
Signed-off-by: Thomas Huth 
---
 arch/arc/include/uapi/asm/ptrace.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arc/include/uapi/asm/ptrace.h 
b/arch/arc/include/uapi/asm/ptrace.h
index 2a6eff57f6dd8..3ae832db278cd 100644
--- a/arch/arc/include/uapi/asm/ptrace.h
+++ b/arch/arc/include/uapi/asm/ptrace.h
@@ -14,7 +14,7 @@
 
 #define PTRACE_GET_THREAD_AREA 25
 
-#ifndef __ASSEMBLY__
+#ifndef __ASSEMBLER__
 /*
  * Userspace ABI: Register state needed by
  *  -ptrace (gdbserver)
@@ -53,6 +53,6 @@ struct user_regs_arcv2 {
unsigned long r30, r58, r59;
 };
 
-#endif /* !__ASSEMBLY__ */
+#endif /* !__ASSEMBLER__ */
 
 #endif /* _UAPI__ASM_ARC_PTRACE_H */
-- 
2.48.1


___
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc