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 <[email protected]>
> ---
> 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 <[email protected]>
>
>