LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Gabriel Paubert <paubert@iram.es>
To: Matt Turner <mattst88@gmail.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] powerpc/powermac: Fix low_sleep_handler with STRICT_KERNEL_RWX
Date: Fri, 20 Nov 2026 08:26:36 +0100	[thread overview]
Message-ID: <av_2LFCIUP-xHvEb@lt-gp.iram.es> (raw)
In-Reply-To: <20261119-pmac-sleep-strict-rwx-v1-1-9068dc16d59e@gmail.com>

On Thu, Nov 19, 2026 at 04:26:19PM -0500, Matt Turner wrote:
> Before sleeping, low_sleep_handler() stores the ROM wakeup vectors and
> the 'Lars' magic at physical addresses 0x0-0x84. It does so through the
> kernel linear mapping at KERNELBASE with data relocation on. With
> CONFIG_STRICT_KERNEL_RWX, that page is the start of kernel text and is
> mapped read-only, so the first store takes a DSI and PMU sleep oopses
> with interrupts disabled, leaving the machine hung:
> 
>   NIP [c0033018] low_sleep_handler+0x198/0x1b4
>   LR [c0032ff4] low_sleep_handler+0x174/0x1b4
>   DAR: c0000000 DSISR: 0a000000
>   [f2169d20] [c086df18] powerbook_sleep+0x86c/0xbe4 (unreliable)
>   [f2169db0] [c00b1178] suspend_devices_and_enter+0x680/0x700
>   [f2169e00] [c00b1428] pm_suspend+0x230/0x25c
>   [f2169e20] [c00af7dc] state_store+0x74/0xd0
> 
> Turn off MSR[DR] around the stores and write to physical address 0
> directly, as flush_disable_75x() and flush_disable_745x() already do
> for their cache flushes. The ROM reads these locations with the MMU
> off, so physical address 0 is where they belong anyway.
> 
> The stores stay ahead of the low_cpu_offline_self entry point, so the
> CPU hotplug path is unchanged. pmac32-cpufreq also calls
> low_sleep_handler() and gets the same fix.
> 
> The Linux PTE for page 0 has been read-only since STRICT_KERNEL_RWX was
> first enabled for PPC32, and the BATs since commit 63b2bc619565
> ("powerpc/mm/32s: Use BATs for STRICT_KERNEL_RWX").
> 
> Tested with suspend to RAM on an iMac G4 (PowerMac6,1, 7448). Not
> tested on Grackle machines or with pmac32-cpufreq.
> 
> Fixes: 95902e6c8864 ("powerpc/mm: Implement STRICT_KERNEL_RWX on PPC32")
> Signed-off-by: Matt Turner <mattst88@gmail.com>
> ---
>  arch/powerpc/platforms/powermac/sleep.S | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/powermac/sleep.S b/arch/powerpc/platforms/powermac/sleep.S
> index 822ed70cdcbf..750cb0160b4c 100644
> --- a/arch/powerpc/platforms/powermac/sleep.S
> +++ b/arch/powerpc/platforms/powermac/sleep.S
> @@ -184,19 +184,31 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
>  	addi	r5,r5,grackle_wake_up@l
>  	tophys(r5,r5)
>  	stw	r5,SL_PC(r11)
> -	lis	r4,KERNELBASE@h
>  	tophys(r5,r11)
>  	addi	r5,r5,SL_PC
>  	lis	r6,MAGIC@ha
>  	addi	r6,r6,MAGIC@l
> -	stw	r5,0(r4)
> -	stw	r6,4(r4)
> -	/* Setup stuffs at 0x80-0x84 for Core99 */
>  	lis	r3,core99_wake_up@ha
>  	addi	r3,r3,core99_wake_up@l
>  	tophys(r3,r3)
> +
> +	/* With STRICT_KERNEL_RWX, the kernel mapping of page 0 is
> +	 * read-only. Write the vectors with data relocation off.
> +	 */
> +	mfmsr	r7
> +	rlwinm	r8,r7,0,~MSR_DR
> +	sync
> +	mtmsr	r8
> +	isync
> +	li	r4,0

Actually this instruction is not needed, just s/r4/0/ where r4 is used
as a base address. (If you put r0 instead, the assembler may complain).

Not really critical, this is just my MOOD (Micro Optimization Of the Day).

Best regards,
Gabriel

> +	stw	r5,0(r4)
> +	stw	r6,4(r4)
> +	/* Setup stuffs at 0x80-0x84 for Core99 */
>  	stw	r3,0x80(r4)
>  	stw	r5,0x84(r4)
> +	sync
> +	mtmsr	r7
> +	isync
>  
>  	.globl	low_cpu_offline_self
>  low_cpu_offline_self:
> 
> ---
> base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd
> change-id: 20261119-pmac-sleep-strict-rwx-57e5dcacee55
> 
> Best regards,
> --  
> Matt Turner <mattst88@gmail.com>
> 
> 
 

 



      reply	other threads:[~2026-11-20  7:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 21:26 [PATCH] powerpc/powermac: Fix low_sleep_handler with STRICT_KERNEL_RWX Matt Turner
2026-11-20  7:26 ` Gabriel Paubert [this message]

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=av_2LFCIUP-xHvEb@lt-gp.iram.es \
    --to=paubert@iram.es \
    --cc=chleroy@kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mattst88@gmail.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=ritesh.list@gmail.com \
    --cc=sshegde@linux.ibm.com \
    /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