Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: sashiko-reviews@lists.linux.dev,
	"Arnd Bergmann" <arnd@kernel.org>,
	linux-mm@kvack.org
Cc: "Andreas Larsson" <andreas@gaisler.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Christophe Leroy" <chleroy@kernel.org>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"David Hildenbrand (Red Hat)" <david@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Jason Gunthorpe" <jgg@nvidia.com>,
	"Linus Walleij" <linusw@kernel.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Lucas Stach" <l.stach@pengutronix.de>,
	"Madhavan Srinivasan" <maddy@linux.ibm.com>,
	"Malin Jonsson" <malin.jonsson@est.tech>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Michal Simek" <monstr@monstr.eu>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Nishanth Menon" <nm@ti.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Russell King" <linux@armlinux.org.uk>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	x86@kernel.org, "Borislav Petkov" <bp@alien8.de>,
	"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	"Vlastimil Babka" <vbabka@suse.cz>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Michal Hocko" <mhocko@suse.com>
Subject: Re: [PATCH v3 06/10] arch/*: increase lowmem size to avoid highmem use
Date: Wed, 18 Nov 2026 10:35:39 +0100	[thread overview]
Message-ID: <0829a44d-fab9-439a-b80e-4791fc72ba0b@app.fastmail.com> (raw)
In-Reply-To: <sashiko-outbox-218801@kernel.org>

On Tue, Nov 17, 2026, at 13:49, sashiko-bot@kernel.org wrote:

>> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
>> index c3b6cd6556069..1eef831faf3a7 100644
>> --- a/arch/powerpc/Kconfig
>> +++ b/arch/powerpc/Kconfig
>
> [ ... ]
>
>> @@ -1207,10 +1211,10 @@ config LOWMEM_CAM_NUM_BOOL
>>  config LOWMEM_CAM_NUM
>>  	depends on PPC_85xx
>>  	int "Number of CAMs to use to map low memory" if LOWMEM_CAM_NUM_BOOL
>> -	default 3 if !STRICT_KERNEL_RWX
>> -	default 9 if DATA_SHIFT >= 24
>> -	default 12 if DATA_SHIFT >= 22
>> -	default 15
>> +	default 8 if !STRICT_KERNEL_RWX
>> +	default 14 if DATA_SHIFT >= 24
>> +	default 17 if DATA_SHIFT >= 22
>> +	default 20
>
> [Severity: Medium]
> Can the new default values of 17 and 20 for LOWMEM_CAM_NUM exceed the 16
> hardware TLB1 entries on e500v1 and e500v2 cores (CONFIG_PPC_85xx=y with
> CONFIG_PPC_E500MC=n)?
>
> During boot in adjust_total_lowmem() and secondary CPU bringup in
> __secondary_start, switch_to_as1() uses the last hardware TLB1 slot (entry
> 15 on 16-entry e500v1/v2) for its temporary AS=1 mapping while
> map_mem_in_cams_addr() populates up to CONFIG_LOWMEM_CAM_NUM slots starting
> from 0 without clamping against SPRN_TLB1CFG:
>
> arch/powerpc/mm/nohash/e500.c:map_mem_in_cams_addr() {
> 	...
> 	for (i = 0; boundary && i < max_cam_idx; i++) {
> 	...
> 	}
> 	for (ram -= amount_mapped; ram && i < max_cam_idx; i++) {
> 	...
> 	}
> 	if (init) {
> 		loadcam_multi(0, i, max_cam_idx);
> 		tlbcam_index = i;
> 	}
> 	...
> }
>
> Because PAGE_OFFSET is now 0xb0000000 or 0x70000000 (an odd multiple of
> 256MiB), calc_cam_sz() caps each CAM at 256MiB even on e500v2.  When
> CONFIG_STRICT_KERNEL_RWX=y and CONFIG_DATA_SHIFT is set below 24, mapping
> 1GiB or 2GiB of RAM reaches index 15 and overwrites the active AS=1 entry in
> TLB1[15] (and wraps the 4-bit MAS0[ESEL] field at index 16 onto TLB1[0]),
> crashing during boot.

Ah, this would explain why Richard was able to boot using my patch
with 1.75GiB but not 2GiB, at least if he was using DATA_SHIFT=22.
Hopefully this should still work as expected if we force DATA_SHIFT=24
for larger lowmem sizes like.

--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -897,7 +897,8 @@ config DATA_SHIFT
        default 24 if STRICT_KERNEL_RWX && PPC64
        range 17 28 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_BOOK3S_32
        range 14 23 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_8xx
-       range 20 24 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_85xx
+       range 20 24 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_85xx && LOWMEM_SIZE<=0x30000000  
+       range 22 24 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_85xx && LOWMEM_SIZE<=0x40000000
+       range 24 24 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_85xx
        default 22 if STRICT_KERNEL_RWX && PPC_BOOK3S_32
        default 18 if (DEBUG_PAGEALLOC || KFENCE) && PPC_BOOK3S_32
        default 23 if (STRICT_KERNEL_RWX || DEBUG_PAGEALLOC || KFENCE) && PPC_8xx && \

> Also, increasing all defaults by 5 unconditionally
> reserves CAMs for 2GiB of lowmem even when CONFIG_HIGHMEM=n caps
> LOWMEM_SIZE at 1GiB.

This feels like Kconfig is not the ideal tool for calculating these ;-)
I've tried to fit this into a concise form that doesn't overshoot too much,
and list the calculation in the help text for reference:

config LOWMEM_CAM_NUM
        depends on PPC_85xx
        int "Number of CAMs to use to map low memory" if LOWMEM_CAM_NUM_BOOL
        default 8 if !STRICT_KERNEL_RWX && LOWMEM_SIZE >  0x40000000
        default 4 if !STRICT_KERNEL_RWX && LOWMEM_SIZE <= 0x40000000
        default 14 if LOWMEM_SIZE > 0x40000000 # requires DATA_SHIFT=24
        default 10 if DATA_SHIFT >= 24
        default 13 if DATA_SHIFT >= 22
        default 15 # 768MiB lowmem, DATA_SHIFT=20
        help
          Without STRICT_KERNEL_RWX, 1 CAM is used per 256MiB of lowmem,
          with STRICT_KERNEL_RWX, extra entries are usually needed for
          smaller sections depending on DATA_SHIFT. On 2GiB lowmem systems
          with 16 CAMs, only DATA_SHIFT=24 (16MiB alignment) can work.

          The default values are optimized for LOWMEM_SIZE of 1GiB or 2GiB
          and could be adjusted for smaller systems:

          2GiB lowmem, 256MiB aligned: 8*256
          1GiB lowmem, 256MiB aligned: 4*256
          2GiB lowmem,  16MiB aligned: 4*16, 3*64, 7*256
          1GiB lowmem,  16MiB aligned: 4*16, 3*64, 3*256
          1GiB lowmem,   4MiB aligned: 4*4, 3*16, 3*64, 3*256
          768MiB lowmem, 1MiB aligned: 4*1, 3*4, 3*16, 3*64, 2*256

>> @@ -1242,7 +1246,8 @@ config PAGE_OFFSET_BOOL
>>  
>>  config PAGE_OFFSET
>>  	hex "Virtual address of memory base" if PAGE_OFFSET_BOOL
>> -	default "0xc0000000"
>> +	default "0x70000000" if HIGHMEM && !44x
>> +	default "0xb0000000"
>
> [Severity: High]
> With PAGE_OFFSET lowered to 0xb0000000 or 0x70000000 on 32-bit Book3S, does
> LOAD_HOST_SEGMENTS on KVM guest exit leave the upper host kernel segment
> registers holding guest values?

That should be addressed by my update in reply to Christophe pointing
out the same mistake.

      Arnd


  reply	other threads:[~2026-11-18  9:36 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 12:48 [PATCH v3 00/10] mm: highmem cleanups Arnd Bergmann
2026-11-16 12:48 ` [PATCH v3 01/10] ARM: remove support for highmem on VIVT Arnd Bergmann
2026-11-17 12:49   ` sashiko-bot
2026-11-18  9:47     ` Arnd Bergmann
2026-11-16 12:48 ` [PATCH v3 02/10] ARM: drop CONFIG_HIGHPTE support Arnd Bergmann
2026-11-16 12:48 ` [PATCH v3 03/10] ARM: pxa: support arbitrary PAGE_OFFSET Arnd Bergmann
2026-11-16 12:48 ` [PATCH v3 04/10] powerpc: kvm: allow flexible PAGE_OFFSET Arnd Bergmann
2026-11-16 13:38   ` Christophe Leroy (CS GROUP)
2026-11-16 22:54     ` Arnd Bergmann
2026-11-17 15:11       ` Christophe Leroy (CS GROUP)
2026-11-17 15:41         ` Arnd Bergmann
2026-11-17 12:49   ` sashiko-bot
2026-11-16 12:48 ` [PATCH v3 05/10] ARM: add CONFIG_VMSPLIT_2G_OPT option Arnd Bergmann
2026-11-16 12:48 ` [PATCH v3 06/10] arch/*: increase lowmem size to avoid highmem use Arnd Bergmann
2026-11-17 12:49   ` sashiko-bot
2026-11-18  9:35     ` Arnd Bergmann [this message]
2026-11-16 12:48 ` [PATCH v3 07/10] ARM: defconfig: turn off highmem in favor of CONFIG_VMSPLIT_2G_OPT Arnd Bergmann
2026-11-16 12:48 ` [PATCH v3 08/10] mm: remove ARCH_NEEDS_KMAP_HIGH_GET Arnd Bergmann
2026-11-17 10:05   ` David Hildenbrand (Arm)
2026-11-16 12:48 ` [PATCH v3 09/10] mm: drop HIGHPTE support altogether Arnd Bergmann
2026-11-16 12:48 ` [PATCH v3 10/10] mm: print pte in __print_bad_page_map_pgtable() Arnd Bergmann
2026-11-16 13:00   ` Mike Rapoport
2026-11-17 12:50   ` sashiko-bot
2026-11-18  7:32     ` Arnd Bergmann
2026-11-18  9:26       ` David Hildenbrand (Arm)
2026-11-17 10:07 ` [PATCH v3 00/10] mm: highmem cleanups David Hildenbrand (Arm)

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=0829a44d-fab9-439a-b80e-4791fc72ba0b@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreas@gaisler.com \
    --cc=arnd@kernel.org \
    --cc=bp@alien8.de \
    --cc=chleroy@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@kernel.org \
    --cc=hpa@zytor.com \
    --cc=jgg@nvidia.com \
    --cc=l.stach@pengutronix.de \
    --cc=linusw@kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@armlinux.org.uk \
    --cc=ljs@kernel.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=maddy@linux.ibm.com \
    --cc=malin.jonsson@est.tech \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=monstr@monstr.eu \
    --cc=mpe@ellerman.id.au \
    --cc=nm@ti.com \
    --cc=npiggin@gmail.com \
    --cc=richard@nod.at \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=surenb@google.com \
    --cc=tglx@linutronix.de \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox