Skip to content

Commit 38e0257

Browse files
D Scott Phillipsctmarinas
authored andcommitted
arm64: errata: Fix exec handling in erratum 1418040 workaround
The erratum 1418040 workaround enables CNTVCT_EL1 access trapping in EL0 when executing compat threads. The workaround is applied when switching between tasks, but the need for the workaround could also change at an exec(), when a non-compat task execs a compat binary or vice versa. Apply the workaround in arch_setup_new_exec(). This leaves a small window of time between SET_PERSONALITY and arch_setup_new_exec where preemption could occur and confuse the old workaround logic that compares TIF_32BIT between prev and next. Instead, we can just read cntkctl to make sure it's in the state that the next task needs. I measured cntkctl read time to be about the same as a mov from a general-purpose register on N1. Update the workaround logic to examine the current value of cntkctl instead of the previous task's compat state. Fixes: d49f7d7 ("arm64: Move handling of erratum 1418040 into C code") Cc: <[email protected]> # 5.9.x Signed-off-by: D Scott Phillips <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 31e833b commit 38e0257

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

arch/arm64/kernel/process.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -439,34 +439,26 @@ static void entry_task_switch(struct task_struct *next)
439439

440440
/*
441441
* ARM erratum 1418040 handling, affecting the 32bit view of CNTVCT.
442-
* Assuming the virtual counter is enabled at the beginning of times:
443-
*
444-
* - disable access when switching from a 64bit task to a 32bit task
445-
* - enable access when switching from a 32bit task to a 64bit task
442+
* Ensure access is disabled when switching to a 32bit task, ensure
443+
* access is enabled when switching to a 64bit task.
446444
*/
447-
static void erratum_1418040_thread_switch(struct task_struct *prev,
448-
struct task_struct *next)
445+
static void erratum_1418040_thread_switch(struct task_struct *next)
449446
{
450-
bool prev32, next32;
451-
u64 val;
452-
453-
if (!IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040))
454-
return;
455-
456-
prev32 = is_compat_thread(task_thread_info(prev));
457-
next32 = is_compat_thread(task_thread_info(next));
458-
459-
if (prev32 == next32 || !this_cpu_has_cap(ARM64_WORKAROUND_1418040))
447+
if (!IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040) ||
448+
!this_cpu_has_cap(ARM64_WORKAROUND_1418040))
460449
return;
461450

462-
val = read_sysreg(cntkctl_el1);
463-
464-
if (!next32)
465-
val |= ARCH_TIMER_USR_VCT_ACCESS_EN;
451+
if (is_compat_thread(task_thread_info(next)))
452+
sysreg_clear_set(cntkctl_el1, ARCH_TIMER_USR_VCT_ACCESS_EN, 0);
466453
else
467-
val &= ~ARCH_TIMER_USR_VCT_ACCESS_EN;
454+
sysreg_clear_set(cntkctl_el1, 0, ARCH_TIMER_USR_VCT_ACCESS_EN);
455+
}
468456

469-
write_sysreg(val, cntkctl_el1);
457+
static void erratum_1418040_new_exec(void)
458+
{
459+
preempt_disable();
460+
erratum_1418040_thread_switch(current);
461+
preempt_enable();
470462
}
471463

472464
/*
@@ -501,7 +493,7 @@ __notrace_funcgraph struct task_struct *__switch_to(struct task_struct *prev,
501493
contextidr_thread_switch(next);
502494
entry_task_switch(next);
503495
ssbs_thread_switch(next);
504-
erratum_1418040_thread_switch(prev, next);
496+
erratum_1418040_thread_switch(next);
505497
ptrauth_thread_switch_user(next);
506498

507499
/*
@@ -611,6 +603,7 @@ void arch_setup_new_exec(void)
611603
current->mm->context.flags = mmflags;
612604
ptrauth_thread_init_user();
613605
mte_thread_init_user();
606+
erratum_1418040_new_exec();
614607

615608
if (task_spec_ssb_noexec(current)) {
616609
arch_prctl_spec_ctrl_set(current, PR_SPEC_STORE_BYPASS,

0 commit comments

Comments
 (0)