Skip to content

Commit db8830a

Browse files
Marc ZyngierAkhil Narang
authored andcommitted
arm64: Move BP hardening to check_and_switch_context
We call arm64_apply_bp_hardening() from post_ttbr_update_workaround, which has the unexpected consequence of being triggered on every exception return to userspace when ARM64_SW_TTBR0_PAN is selected, even if no context switch actually occured. This is a bit suboptimal, and it would be more logical to only invalidate the branch predictor when we actually switch to a different mm. In order to solve this, move the call to arm64_apply_bp_hardening() into check_and_switch_context(), where we're guaranteed to pick a different mm context. Change-Id: I28f2fb09b77544e5ead095e9dad1ad64b2b3ae36 Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Git-commit: a8e4c0a Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git Signed-off-by: Srinivas Ramana <sramana@codeaurora.org>
1 parent beec421 commit db8830a

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

arch/arm64/mm/context.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ void check_and_switch_context(struct mm_struct *mm, unsigned int cpu)
191191
raw_spin_unlock_irqrestore(&cpu_asid_lock, flags);
192192

193193
switch_mm_fastpath:
194+
195+
arm64_apply_bp_hardening();
196+
194197
/*
195198
* Defer TTBR0_EL1 setting for user threads to uaccess_enable() when
196199
* emulating PAN.
@@ -202,7 +205,6 @@ void check_and_switch_context(struct mm_struct *mm, unsigned int cpu)
202205
/* Errata workaround post TTBRx_EL1 update. */
203206
asmlinkage void post_ttbr_update_workaround(void)
204207
{
205-
arm64_apply_bp_hardening();
206208
}
207209

208210
static int asids_init(void)

0 commit comments

Comments
 (0)