Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

arm64: hibernate: avoid potential TLB conflict

In create_safe_exec_page we install a set of global mappings in TTBR0,
then subsequently invalidate TLBs. While TTBR0 points at the zero page,
and the TLBs should be free of stale global entries, we may have stale
ASID-tagged entries (e.g. from the EFI runtime services mappings) for
the same VAs. Per the ARM ARM these ASID-tagged entries may conflict
with newly-allocated global entries, and we must follow a
Break-Before-Make approach to avoid issues resulting from this.

This patch reworks create_safe_exec_page to invalidate TLBs while the
zero page is still in place, ensuring that there are no potential
conflicts when the new TTBR0 value is installed. As a single CPU is
online while this code executes, we do not need to perform broadcast TLB
maintenance, and can call local_flush_tlb_all(), which also subsumes
some barriers. The remaining assembly is converted to use write_sysreg()
and isb().

Other than this, we safely manipulate TTBRs in the hibernate dance. The
code we install as part of the new TTBR0 mapping (the hibernated
kernel's swsusp_arch_suspend_exit) installs a zero page into TTBR1,
invalidates TLBs, then installs its preferred value. Upon being restored
to the middle of swsusp_arch_suspend, the new image will call
__cpu_suspend_exit, which will call cpu_uninstall_idmap, installing the
zero page in TTBR0 and invalidating all TLB entries.

Fixes: 82869ac57b5d ("arm64: kernel: Add support for hibernate/suspend-to-disk")
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: James Morse <james.morse@arm.com>
Tested-by: James Morse <james.morse@arm.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: <stable@vger.kernel.org> # 4.7+
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

Mark Rutland and committed by
Catalin Marinas
0194e760 9adeb8e7

+17 -6
+17 -6
arch/arm64/kernel/hibernate.c
··· 35 35 #include <asm/sections.h> 36 36 #include <asm/smp.h> 37 37 #include <asm/suspend.h> 38 + #include <asm/sysreg.h> 38 39 #include <asm/virt.h> 39 40 40 41 /* ··· 218 217 set_pte(pte, __pte(virt_to_phys((void *)dst) | 219 218 pgprot_val(PAGE_KERNEL_EXEC))); 220 219 221 - /* Load our new page tables */ 222 - asm volatile("msr ttbr0_el1, %0;" 223 - "isb;" 224 - "tlbi vmalle1is;" 225 - "dsb ish;" 226 - "isb" : : "r"(virt_to_phys(pgd))); 220 + /* 221 + * Load our new page tables. A strict BBM approach requires that we 222 + * ensure that TLBs are free of any entries that may overlap with the 223 + * global mappings we are about to install. 224 + * 225 + * For a real hibernate/resume cycle TTBR0 currently points to a zero 226 + * page, but TLBs may contain stale ASID-tagged entries (e.g. for EFI 227 + * runtime services), while for a userspace-driven test_resume cycle it 228 + * points to userspace page tables (and we must point it at a zero page 229 + * ourselves). Elsewhere we only (un)install the idmap with preemption 230 + * disabled, so T0SZ should be as required regardless. 231 + */ 232 + cpu_set_reserved_ttbr0(); 233 + local_flush_tlb_all(); 234 + write_sysreg(virt_to_phys(pgd), ttbr0_el1); 235 + isb(); 227 236 228 237 *phys_dst_addr = virt_to_phys((void *)dst); 229 238