[PATCH v3 24/29] arch, mm: consolidate initialization of SPARSE memory model

Thomas Weißschuh thomas.weissschuh at linutronix.de
Mon Feb 23 05:52:45 PST 2026


Hi everyone,

On Sun, Jan 11, 2026 at 10:20:58AM +0200, Mike Rapoport wrote:
> Every architecture calls sparse_init() during setup_arch() although the
> data structures created by sparse_init() are not used until the
> initialization of the core MM.
> 
> Beside the code duplication, calling sparse_init() from architecture
> specific code causes ordering differences of vmemmap and HVO initialization
> on different architectures.
> 
> Move the call to sparse_init() from architecture specific code to
> free_area_init() to ensure that vmemmap and HVO initialization order is
> always the same.

This broke the boot on RISC-V 32-bit (rv32_defconfig) for me.

Specifically if sparse_init() is *not* called before the following callchain,
the kernel dies at that point.

start_kernel()
  setup_arch()
    apply_boot_alternatives()
      _apply_alternatives()
        riscv_cpufeature_patch_func()
          patch_text_nosync()
          riscv_alternative_fix_offsets()


Simple reproducer, using kunit:

./tools/testing/kunit/kunit.py run --raw_output=all --make_options LLVM=1 --arch riscv32 --kconfig_add CONFIG_SPARSEMEM_MANUAL=y --kconfig_add CONFIG_SPARSEMEM=y

> 
> Signed-off-by: Mike Rapoport (Microsoft) <rppt at kernel.org>
> ---
>  Documentation/mm/memory-model.rst                    |  3 ---
>  Documentation/translations/zh_CN/mm/memory-model.rst |  2 --
>  arch/alpha/kernel/setup.c                            |  1 -
>  arch/arm/mm/init.c                                   |  6 ------
>  arch/arm64/mm/init.c                                 |  6 ------
>  arch/csky/kernel/setup.c                             |  2 --
>  arch/loongarch/kernel/setup.c                        |  8 --------
>  arch/mips/kernel/setup.c                             | 11 -----------
>  arch/parisc/mm/init.c                                |  2 --
>  arch/powerpc/include/asm/setup.h                     |  4 ++++
>  arch/powerpc/mm/mem.c                                |  5 -----
>  arch/powerpc/mm/numa.c                               |  2 --
>  arch/riscv/mm/init.c                                 |  1 -
>  arch/s390/mm/init.c                                  |  1 -
>  arch/sh/mm/init.c                                    |  2 --
>  arch/sparc/mm/init_64.c                              |  2 --
>  arch/x86/mm/init_32.c                                |  1 -
>  arch/x86/mm/init_64.c                                |  2 --
>  include/linux/mmzone.h                               |  2 --
>  mm/internal.h                                        |  6 ++++++
>  mm/mm_init.c                                         |  1 +
>  21 files changed, 11 insertions(+), 59 deletions(-)

(...)



More information about the linux-riscv mailing list