Message ID | 20250404174435.3288106-15-mark.rutland@arm.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | arm64: Preparatory FPSIMD/SVE/SME fixes | expand |
On Fri, Apr 04, 2025 at 06:44:35PM +0100, Mark Rutland wrote: > During a context-switch, tls_thread_switch() reads and writes a task's > thread_struct::tpidr2_el0 field. Other code shouldn't access this field > for an active task, as such accesses would form a data-race with a > concurrent context-switch. Reviewed-by: Mark Brown <broonie@kernel.org>
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index b27357aeba065..a4e3d4273a360 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -476,13 +476,12 @@ extern int preserve_sve_context(void __user *ctx); static int preserve_tpidr2_context(struct tpidr2_context __user *ctx) { + u64 tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0); int err = 0; - current->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0); - __put_user_error(TPIDR2_MAGIC, &ctx->head.magic, err); __put_user_error(sizeof(*ctx), &ctx->head.size, err); - __put_user_error(current->thread.tpidr2_el0, &ctx->tpidr2, err); + __put_user_error(tpidr2_el0, &ctx->tpidr2, err); return err; }
During a context-switch, tls_thread_switch() reads and writes a task's thread_struct::tpidr2_el0 field. Other code shouldn't access this field for an active task, as such accesses would form a data-race with a concurrent context-switch. The usage in preserve_tpidr2_context() is suspicious, but benign as any race with a context switch will write the same value back to current->thread.tpidr2_el0. Make this clearer and match restore_tpidr2_context() by using a temporary variable instead, avoiding the (benign) data-race. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Marc Zyngier <maz@kernel.org> Cc: Mark Brown <broonie@kernel.org> Cc: Will Deacon <will@kernel.org> --- arch/arm64/kernel/signal.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)