Skip to content

Commit dc802f2

Browse files
Marc Zyngierwilldeacon
authored andcommitted
arm64: Rework ARM_ERRATUM_1414080 handling
The current handling of erratum 1414080 has the side effect that cntkctl_el1 can get changed for both 32 and 64bit tasks. This isn't a problem so far, but if we ever need to mitigate another of these errata on the 64bit side, we'd better keep the messing with cntkctl_el1 local to 32bit tasks. For that, make sure that on entering the kernel from a 32bit tasks, userspace access to cntvct gets enabled, and disabled returning to userspace, while it never gets changed for 64bit tasks. Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected] [will: removed branch instructions per Mark's review comments] Signed-off-by: Will Deacon <[email protected]>
1 parent 4b661d6 commit dc802f2

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

arch/arm64/kernel/entry.S

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ alternative_cb_end
167167
stp x28, x29, [sp, #16 * 14]
168168

169169
.if \el == 0
170+
.if \regsize == 32
171+
// If we're returning from a 32-bit task on a system affected by
172+
// 1418040 then re-enable userspace access to the virtual counter.
173+
#ifdef CONFIG_ARM64_ERRATUM_1418040
174+
alternative_if ARM64_WORKAROUND_1418040
175+
mrs x0, cntkctl_el1
176+
orr x0, x0, #2 // ARCH_TIMER_USR_VCT_ACCESS_EN
177+
msr cntkctl_el1, x0
178+
alternative_else_nop_endif
179+
#endif
180+
.endif
170181
clear_gp_regs
171182
mrs x21, sp_el0
172183
ldr_this_cpu tsk, __entry_task, x20
@@ -320,6 +331,14 @@ alternative_else_nop_endif
320331
tst x22, #PSR_MODE32_BIT // native task?
321332
b.eq 3f
322333

334+
#ifdef CONFIG_ARM64_ERRATUM_1418040
335+
alternative_if ARM64_WORKAROUND_1418040
336+
mrs x0, cntkctl_el1
337+
bic x0, x0, #2 // ARCH_TIMER_USR_VCT_ACCESS_EN
338+
msr cntkctl_el1, x0
339+
alternative_else_nop_endif
340+
#endif
341+
323342
#ifdef CONFIG_ARM64_ERRATUM_845719
324343
alternative_if ARM64_WORKAROUND_845719
325344
#ifdef CONFIG_PID_IN_CONTEXTIDR
@@ -331,21 +350,6 @@ alternative_if ARM64_WORKAROUND_845719
331350
alternative_else_nop_endif
332351
#endif
333352
3:
334-
#ifdef CONFIG_ARM64_ERRATUM_1418040
335-
alternative_if_not ARM64_WORKAROUND_1418040
336-
b 4f
337-
alternative_else_nop_endif
338-
/*
339-
* if (x22.mode32 == cntkctl_el1.el0vcten)
340-
* cntkctl_el1.el0vcten = ~cntkctl_el1.el0vcten
341-
*/
342-
mrs x1, cntkctl_el1
343-
eon x0, x1, x22, lsr #3
344-
tbz x0, #1, 4f
345-
eor x1, x1, #2 // ARCH_TIMER_USR_VCT_ACCESS_EN
346-
msr cntkctl_el1, x1
347-
4:
348-
#endif
349353
scs_save tsk, x0
350354

351355
/* No kernel C function calls after this as user keys are set. */

0 commit comments

Comments
 (0)