Skip to contentSkip to conversation

arm64: errata: Fix exec handling in erratum 1418040 workaround

PATCH Superseded D Scott Phillips 2 participants 2 messages Dec 15, 2021 – Dec 16, 2021

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: errata: Fix exec handling in erratum 1418040 workaround

The erratum 1418040 workaround changes vct access trapping when switching between compat and non-compat threads. The workaround logic assumes that the hardware vct trapping state matches the previous task's compat-ness. However, when a non-compat task execs a compat binary or vice versa, the cntkctl state and task compat-ness get out of sync. Keep the hardware trapping state in sync with the task personality.

Fixes d49f7d7376d0 ("arm64: Move handling of erratum 1418040 into C code")
Cc <[email protected]> # 5.4.x
---
 arch/arm64/include/asm/elf.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
arch/arm64/include/asm/elf.h +20 -0
index 97932fbf973d..463ff8f00aa7 100644
@@ -160,8 +160,18 @@ typedef struct user_fpsimd_state elf_fpregset_t;
 
 #define SET_PERSONALITY(ex)						\
 ({									\
+	if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040))			\
+		preempt_disable();					\
 	clear_thread_flag(TIF_32BIT);					\
 	current->personality &= ~READ_IMPLIES_EXEC;			\
+	if (this_cpu_has_cap(ARM64_WORKAROUND_1418040)) {		\
+		u64 val;						\
+		val = read_sysreg(cntkctl_el1);				\
+		val |= ARCH_TIMER_USR_VCT_ACCESS_EN;			\
+		write_sysreg(val, cntkctl_el1);				\
+	}								\
+	if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040))			\
+		preempt_enable();					\
 })
 
 /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
@@ -223,7 +233,17 @@ int compat_elf_check_arch(const struct elf32_hdr *);
  */
 #define COMPAT_SET_PERSONALITY(ex)					\
 ({									\
+	if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040))			\
+		preempt_disable();					\
 	set_thread_flag(TIF_32BIT);					\
+	if (this_cpu_has_cap(ARM64_WORKAROUND_1418040)) {		\
+		u64 val;						\
+		val = read_sysreg(cntkctl_el1);				\
+		val &= ~ARCH_TIMER_USR_VCT_ACCESS_EN;			\
+		write_sysreg(val, cntkctl_el1);				\
+	}								\
+	if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040))			\
+		preempt_enable();					\
  })
 #ifdef CONFIG_COMPAT_VDSO
 #define COMPAT_ARCH_DLINFO						\
Signature · 7 lines
2.31.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 46 lines · D Scott Phillips

The erratum 1418040 workaround changes vct access trapping when switching between compat and non-compat threads. The workaround logic assumes that the hardware vct trapping state matches the previous task's compat-ness. However, when a non-compat task execs a compat binary or vice versa, the cntkctl state and task compat-ness get out of sync. Keep the hardware trapping state in sync with the task personality.

Fixes d49f7d7376d0 ("arm64: Move handling of erratum 1418040 into C code")
Cc <[email protected]> # 5.4.x
---
 arch/arm64/include/asm/elf.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
arch/arm64/include/asm/elf.h +13 -0
index 97932fbf973d..463ff8f00aa7 100644
@@ -160,8 +160,18 @@ typedef struct user_fpsimd_state elf_fpregset_t;
 
 #define SET_PERSONALITY(ex)						\
 ({									\
+	if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040))			\
+		preempt_disable();					\
 	clear_thread_flag(TIF_32BIT);					\
 	current->personality &= ~READ_IMPLIES_EXEC;			\
+	if (this_cpu_has_cap(ARM64_WORKAROUND_1418040)) {		\
+		u64 val;						\
+		val = read_sysreg(cntkctl_el1);				\
+		val |= ARCH_TIMER_USR_VCT_ACCESS_EN;			\
+		write_sysreg(val, cntkctl_el1);				\
+	}								\
+	if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040))			\
+		preempt_enable();					\
 })
 
 /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
@@ -223,7 +233,17 @@ int compat_elf_check_arch(const struct elf32_hdr *);
  */
 #define COMPAT_SET_PERSONALITY(ex)					\
 ({									\
+	if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040))			\
+		preempt_disable();					\
 	set_thread_flag(TIF_32BIT);					\
+	if (this_cpu_has_cap(ARM64_WORKAROUND_1418040)) {		\

arch/arm64/include/asm/elf.h int compat_elf_check_arch(const struct elf32_hdr *); · line 249

Quoted 10 lines
arch/arm64/include/asm/elf.h +7 -0
+		u64 val;						\
+		val = read_sysreg(cntkctl_el1);				\
+		val &= ~ARCH_TIMER_USR_VCT_ACCESS_EN;			\
+		write_sysreg(val, cntkctl_el1);				\
+	}								\
+	if (IS_ENABLED(CONFIG_ARM64_ERRATUM_1418040))			\
+		preempt_enable();					\
  })
 #ifdef CONFIG_COMPAT_VDSO
 #define COMPAT_ARCH_DLINFO						\

I'd have opted for the use of sysreg_clear_set() instead of the open-coded RMW, as it would elide the write-back in most cases.

This looks otherwise OK to me. With that fixed:

	M.
Signature · 6 lines
Without deviation from the norm, progress is not possible.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel