mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-08-09 06:14:34 +02:00
Commit7af5b901e8("ARM: 9358/2: Implement PAN for LPAE by TTBR0 page table walks disablement") implemented PAN for LPAE kernels by setting TTBCR.EPD0 on every kernel entry, disabling TTBR0 page-table walks while running in kernel mode. The commit correctly updated cpu_suspend() in arch/arm/kernel/suspend.c, but missed two other code paths that switch the CPU to the identity mapping before jumping to low-PA (TTBR0-range) physical addresses: 1. setup_mm_for_reboot() in arch/arm/mm/idmap.c, used by the kexec reboot path. With TTBCR.EPD0 still set, the subsequent branch to the identity-mapped cpu_v7_reset causes a PrefetchAbort because the TTBR0 page-table walk needed to resolve the identity-mapped address is disabled. This manifests as a hard hang or "bad PC value" panic on LPAE kernels booted on CPUs that strictly enforce EPD0 for instruction fetch (e.g. Cortex-A53 in AArch32 mode) while the same image may accidentally work on Cortex-A15 due to microarchitectural differences in EPD0 enforcement. 2. arch_restore_image() in arch/arm/kernel/hibernate.c, which calls cpu_switch_mm(idmap_pgd, &init_mm) directly without going through setup_mm_for_reboot(), leaving TTBCR.EPD0 set while the identity mapping is active. Fix both sites by calling uaccess_save_and_enable() before switching to the identity mapping, mirroring what the original commit did for cpu_suspend(). Assisted-by: Cursor:claude-sonnet-4.6 Fixes:7af5b901e8("ARM: 9358/2: Implement PAN for LPAE by TTBR0 page table walks disablement") Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Linus Walleij <linusw@kernel.org> Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
116 lines
3.2 KiB
C
116 lines
3.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Hibernation support specific for ARM
|
|
*
|
|
* Derived from work on ARM hibernation support by:
|
|
*
|
|
* Ubuntu project, hibernation support for mach-dove
|
|
* Copyright (C) 2010 Nokia Corporation (Hiroshi Doyu)
|
|
* Copyright (C) 2010 Texas Instruments, Inc. (Teerth Reddy et al.)
|
|
* https://lkml.org/lkml/2010/6/18/4
|
|
* https://lists.linux-foundation.org/pipermail/linux-pm/2010-June/027422.html
|
|
* https://patchwork.kernel.org/patch/96442/
|
|
*
|
|
* Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl>
|
|
*/
|
|
|
|
#include <linux/mm.h>
|
|
#include <linux/suspend.h>
|
|
#include <asm/system_misc.h>
|
|
#include <asm/idmap.h>
|
|
#include <asm/suspend.h>
|
|
#include <asm/page.h>
|
|
#include <asm/sections.h>
|
|
#include <asm/uaccess.h>
|
|
#include "reboot.h"
|
|
|
|
int pfn_is_nosave(unsigned long pfn)
|
|
{
|
|
unsigned long nosave_begin_pfn = virt_to_pfn(&__nosave_begin);
|
|
unsigned long nosave_end_pfn = virt_to_pfn(&__nosave_end - 1);
|
|
|
|
return (pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn);
|
|
}
|
|
|
|
void notrace save_processor_state(void)
|
|
{
|
|
WARN_ON(num_online_cpus() != 1);
|
|
local_fiq_disable();
|
|
}
|
|
|
|
void notrace restore_processor_state(void)
|
|
{
|
|
local_fiq_enable();
|
|
}
|
|
|
|
/*
|
|
* Snapshot kernel memory and reset the system.
|
|
*
|
|
* swsusp_save() is executed in the suspend finisher so that the CPU
|
|
* context pointer and memory are part of the saved image, which is
|
|
* required by the resume kernel image to restart execution from
|
|
* swsusp_arch_suspend().
|
|
*
|
|
* soft_restart is not technically needed, but is used to get success
|
|
* returned from cpu_suspend.
|
|
*
|
|
* When soft reboot completes, the hibernation snapshot is written out.
|
|
*/
|
|
static int notrace arch_save_image(unsigned long unused)
|
|
{
|
|
int ret;
|
|
|
|
ret = swsusp_save();
|
|
if (ret == 0)
|
|
_soft_restart(virt_to_idmap(cpu_resume), false);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Save the current CPU state before suspend / poweroff.
|
|
*/
|
|
int notrace swsusp_arch_suspend(void)
|
|
{
|
|
return cpu_suspend(0, arch_save_image);
|
|
}
|
|
|
|
/*
|
|
* Restore page contents for physical pages that were in use during loading
|
|
* hibernation image. Switch to idmap_pgd so the physical page tables
|
|
* are overwritten with the same contents.
|
|
*/
|
|
static void notrace arch_restore_image(void *unused)
|
|
{
|
|
struct pbe *pbe;
|
|
|
|
/*
|
|
* With CONFIG_CPU_TTBR0_PAN enabled, TTBCR.EPD0 is set to block
|
|
* TTBR0 page-table walks. The identity mapping used here lives at
|
|
* low (user-space) virtual addresses and is only reachable via
|
|
* TTBR0, so re-enable those walks before switching page tables.
|
|
* On non-PAN kernels this is a no-op.
|
|
*/
|
|
if (IS_ENABLED(CONFIG_CPU_TTBR0_PAN))
|
|
uaccess_save_and_enable();
|
|
cpu_switch_mm(idmap_pgd, &init_mm);
|
|
for (pbe = restore_pblist; pbe; pbe = pbe->next)
|
|
copy_page(pbe->orig_address, pbe->address);
|
|
|
|
_soft_restart(virt_to_idmap(cpu_resume), false);
|
|
}
|
|
|
|
static u64 resume_stack[PAGE_SIZE/2/sizeof(u64)] __nosavedata;
|
|
|
|
/*
|
|
* Resume from the hibernation image.
|
|
* Due to the kernel heap / data restore, stack contents change underneath
|
|
* and that would make function calls impossible; switch to a temporary
|
|
* stack within the nosave region to avoid that problem.
|
|
*/
|
|
int swsusp_arch_resume(void)
|
|
{
|
|
call_with_stack(arch_restore_image, 0,
|
|
resume_stack + ARRAY_SIZE(resume_stack));
|
|
return 0;
|
|
}
|