All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Andy Lutomirski <luto@kernel.org>,
	Ard Biesheuvel <ardb@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	Borislav Petkov <bp@alien8.de>,
	"David S. Miller" <davem@davemloft.net>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-mm@kvack.org, x86@kernel.org,
	Naresh Kamboju <naresh.kamboju@linaro.org>,
	lkft-triage@lists.linaro.org,
	Linux Regressions <regressions@lists.linux.dev>
Subject: Re: [PATCH v2 10/13] arch, mm: set high_memory in free_area_init()
Date: Wed, 2 Apr 2025 23:18:55 +0300	[thread overview]
Message-ID: <Z-2br1vk8lf9V40T@kernel.org> (raw)
In-Reply-To: <20250402181842-f25872a1-00f7-4a8f-ae6d-3927899ee3a6@linutronix.de>

On Wed, Apr 02, 2025 at 06:31:02PM +0200, Thomas Weißschuh wrote:
> On Wed, Apr 02, 2025 at 03:07:51PM +0200, Thomas Weißschuh wrote:
> > On Wed, Apr 02, 2025 at 03:46:37PM +0300, Mike Rapoport wrote:
> > > On Wed, Apr 02, 2025 at 02:19:01PM +0200, Thomas Weißschuh wrote:
> > > > (drop all the non-x86 and non-mm recipients)
> > > > 
> > > > On Thu, Mar 13, 2025 at 03:50:00PM +0200, Mike Rapoport wrote:
> > > > > From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> > > > > 
> > > > > high_memory defines upper bound on the directly mapped memory.
> > > > > This bound is defined by the beginning of ZONE_HIGHMEM when a system has
> > > > > high memory and by the end of memory otherwise.
> > > > > 
> > > > > All this is known to generic memory management initialization code that
> > > > > can set high_memory while initializing core mm structures.
> > > > > 
> > > > > Add a generic calculation of high_memory to free_area_init() and remove
> > > > > per-architecture calculation except for the architectures that set and
> > > > > use high_memory earlier than that.
> > > > 
> > > > This change (in mainline as commit e120d1bc12da ("arch, mm: set high_memory in free_area_init()")
> > > > breaks booting i386 on QEMU for me (and others [0]).
> > > > The boot just hangs without output.
> > > > 
> > > > It's easily reproducible with kunit:
> > > > ./tools/testing/kunit/kunit.py run --arch i386
> > > > 
> > > > See below for the specific problematic hunk.
> > > > 
> > > > [0] https://lore.kernel.org/lkml/CA+G9fYtdXHVuirs3v6at3UoKNH5keuq0tpcvpz0tJFT4toLG4g@mail.gmail.com/
> > > > 
> > > > 
> > > > > diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
> > > > > index 6d2f8cb9451e..801b659ead0c 100644
> > > > > --- a/arch/x86/mm/init_32.c
> > > > > +++ b/arch/x86/mm/init_32.c
> > > > > @@ -643,9 +643,6 @@ void __init initmem_init(void)
> > > > >  		highstart_pfn = max_low_pfn;
> > > > >  	printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
> > > > >  		pages_to_mb(highend_pfn - highstart_pfn));
> > > > > -	high_memory = (void *) __va(highstart_pfn * PAGE_SIZE - 1) + 1;
> > > > > -#else
> > > > > -	high_memory = (void *) __va(max_low_pfn * PAGE_SIZE - 1) + 1;
> > > > >  #endif
> > > > 
> > > > Reverting this hunk fixes the issue for me.
> > >  
> > > This is already done by d893aca973c3 ("x86/mm: restore early initialization
> > > of high_memory for 32-bits").
> > 
> > Thanks. Of course I only noticed this shortly after sending my mail.
> > But this usecase is indeed broken on mainline.
> > Some further bisecting lead to the mm merge commit being broken, while both its
> > parents work. That lead the bisection astray.
> > eb0ece16027f ("Merge tag 'mm-stable-2025-03-30-16-52' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm")
> > 
> > As unlikely as it sounds, it's reproducible. I'll investigate a bit.
> 
> The issue is fixed with the following diff:
> 
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 284154445409..8cd95f60015d 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -2165,7 +2165,8 @@ static unsigned long __init __free_memory_core(phys_addr_t start,
>                                  phys_addr_t end)
>  {
>         unsigned long start_pfn = PFN_UP(start);
> -       unsigned long end_pfn = PFN_DOWN(end);
> +       unsigned long end_pfn = min_t(unsigned long,
> +                                     PFN_DOWN(end), max_low_pfn);

This will leave HIGHMEM completely unusable. The proper fix is

diff --git a/mm/memblock.c b/mm/memblock.c
index 64ae678cd1d1..d7ff8dfe5f88 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2166,6 +2166,9 @@ static unsigned long __init __free_memory_core(phys_addr_t start,
 	unsigned long start_pfn = PFN_UP(start);
 	unsigned long end_pfn = PFN_DOWN(end);
 
+	if (!IS_ENABLED(CONFIG_HIGHMEM) && end_pfn > max_low_pfn)
+		end_pfn = max_low_pfn;
+
 	if (start_pfn >= end_pfn)
 		return 0;

I've sent it along with the fix for x86 [1] (commit 7790c9c9265e
("memblock: don't release high memory to page allocator when HIGHMEM is
off") in mm-unstable), but for some reason it didn't make it to the Linus
tree :/

@Andrew, are you going to send it to Linus or you prefer if I take it via
memblock tree? 

[1] https://lore.kernel.org/all/20250325114928.1791109-3-rppt@kernel.org/

>         if (start_pfn >= end_pfn)
>                 return 0;
> 
> 
> Background:
> 
> This reverts part of commit 6faea3422e3b ("arch, mm: streamline HIGHMEM freeing")
> which is the direct child of the partially reverted 
> commit e120d1bc12da ("arch, mm: set high_memory in free_area_init()").
> The assumptions the former commit became invalid with the partial revert the latter.
> 
> This bug only triggers when CONFIG_HIGHMEM=n. When mm was branched from mainline
> the i386 configuration generated by kunit ended up with CONFIG_HIGHMEM=y.
> With some recent changes in mainline the kunit configuration switched to
> CONFIG_HIGHMEM=n, triggering this specific reproducer only when mm got merged
> into mainline again.
> 
> New kunit reproducer:
> ./tools/testing/kunit/kunit.py run --arch i386 example --timeout 10 --kconfig_add CONFIG_HIGHMEM=n
> 
> Does this sound reasonable?  If so I'll send a patch tomorrow.
> 
> @Naresh, could you test this, too?
> 
> 
> Thomas

-- 
Sincerely yours,
Mike.

  parent reply	other threads:[~2025-04-02 20:19 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 13:49 [PATCH v2 00/13] arch, mm: reduce code duplication in mem_init() Mike Rapoport
2025-03-13 13:49 ` Mike Rapoport
2025-03-13 13:49 ` Mike Rapoport
2025-03-13 13:49 ` [PATCH v2 01/13] arm: mem_init: use memblock_phys_free() to free DMA memory on SA1111 Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49 ` [PATCH v2 02/13] csky: move setup_initrd() to setup.c Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49 ` [PATCH v2 03/13] hexagon: move initialization of init_mm.context init to paging_init() Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49 ` [PATCH v2 04/13] MIPS: consolidate mem_init() for NUMA machines Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49 ` [PATCH v2 05/13] MIPS: make setup_zero_pages() use memblock Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49 ` [PATCH v2 06/13] nios2: move pr_debug() about memory start and end to setup_arch() Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-17 12:40   ` Dinh Nguyen
2025-03-17 12:40     ` Dinh Nguyen
2025-03-17 12:40     ` Dinh Nguyen
2025-03-13 13:49 ` [PATCH v2 07/13] s390: make setup_zero_pages() use memblock Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49 ` [PATCH v2 08/13] xtensa: split out printing of virtual memory layout to a function Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 17:14   ` Max Filippov
2025-03-13 17:14     ` Max Filippov
2025-03-13 17:14     ` Max Filippov
2025-03-13 13:49 ` [PATCH v2 09/13] arch, mm: set max_mapnr when allocating memory map for FLATMEM Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-13 13:49   ` Mike Rapoport
2025-03-14  9:25   ` Christophe Leroy
2025-03-14  9:25     ` Christophe Leroy
2025-03-14  9:25     ` Christophe Leroy
2025-04-08  5:48     ` Christophe Leroy
2025-04-08  5:48       ` Christophe Leroy
2025-04-08  5:48       ` Christophe Leroy
2025-03-13 13:50 ` [PATCH v2 10/13] arch, mm: set high_memory in free_area_init() Mike Rapoport
2025-03-13 13:50   ` Mike Rapoport
2025-03-13 13:50   ` Mike Rapoport
2025-04-02 12:19   ` Thomas Weißschuh
2025-04-02 12:46     ` Mike Rapoport
2025-04-02 13:07       ` Thomas Weißschuh
2025-04-02 16:31         ` Thomas Weißschuh
2025-04-02 19:12           ` Naresh Kamboju
2025-04-02 20:18           ` Mike Rapoport [this message]
2025-04-02 22:19             ` Andrew Morton
2025-05-16 15:28   ` Pratyush Yadav
2025-05-16 15:28     ` Pratyush Yadav
2025-05-16 15:28     ` Pratyush Yadav
2025-05-16 17:01     ` Mike Rapoport
2025-05-16 17:01       ` Mike Rapoport
2025-05-16 17:01       ` Mike Rapoport
2025-05-19 15:54       ` Alexandre Ghiti
2025-05-19 15:54         ` Alexandre Ghiti
2025-05-19 15:54         ` Alexandre Ghiti
2025-05-19 17:19         ` Mike Rapoport
2025-05-19 17:19           ` Mike Rapoport
2025-05-19 17:19           ` Mike Rapoport
2025-03-13 13:50 ` [PATCH v2 11/13] arch, mm: streamline HIGHMEM freeing Mike Rapoport
2025-03-13 13:50   ` Mike Rapoport
2025-03-13 13:50   ` Mike Rapoport
2025-03-23 19:06   ` Nathan Chancellor
2025-03-13 13:50 ` [PATCH v2 12/13] arch, mm: introduce arch_mm_preinit Mike Rapoport
2025-03-13 13:50   ` Mike Rapoport
2025-03-13 13:50   ` Mike Rapoport
2025-03-13 13:50 ` [PATCH v2 13/13] arch, mm: make releasing of memory to page allocator more explicit Mike Rapoport
2025-03-13 13:50   ` Mike Rapoport
2025-03-13 13:50   ` Mike Rapoport
2025-03-13 15:19   ` Geert Uytterhoeven
2025-03-13 15:19     ` Geert Uytterhoeven
2025-03-13 15:19     ` Geert Uytterhoeven
2025-03-13 15:34     ` Mike Rapoport
2025-03-13 15:51       ` Geert Uytterhoeven
2025-03-13 15:56         ` Geert Uytterhoeven
2025-03-13 16:39         ` Mike Rapoport
2025-03-13 18:31         ` Michael Schmitz
2025-03-14  8:51           ` Geert Uytterhoeven
2025-03-14  9:06             ` Michael Schmitz
2025-03-14  9:13               ` Geert Uytterhoeven
2025-03-13 16:39 ` [PATCH v2 00/13] arch, mm: reduce code duplication in mem_init() Mark Brown
2025-03-13 16:39   ` Mark Brown
2025-03-13 16:39   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z-2br1vk8lf9V40T@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=geert@linux-m68k.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lkft-triage@lists.linaro.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=naresh.kamboju@linaro.org \
    --cc=peterz@infradead.org \
    --cc=regressions@lists.linux.dev \
    --cc=tglx@linutronix.de \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.