shithub: riscv

Download patch

ref: 4091eb6fcd02ae5162423788f7da23544a28a3a6
parent: 8bcc99861e091e22f0950be771fdb1f1c01a35a0
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Apr 12 16:06:00 EDT 2025

kernel/arm64: fix procsetup() TPIDR_EL0 potentially not getting reset to 0 on exec

We have to be carefull with the order here.

Imagine we get preepted immediately after we set p->tpidr = 0,
procsave() would override up->tpidr again with the current
register value. once we get switched back in, we then
execute syswr(TPIDR_EL0, p->tpidr), failing to reset the
register to 0.

So the correct order is to first set the register, and
then we can (optionally) set p->tpidr = 0 (doesnt matter).

--- a/sys/src/9/arm64/trap.c
+++ b/sys/src/9/arm64/trap.c
@@ -505,8 +505,8 @@
 procsetup(Proc *p)
 {
 	fpuprocsetup(p);
+	syswr(TPIDR_EL0, 0);
 	p->tpidr = 0;
-	syswr(TPIDR_EL0, p->tpidr);
 }
 
 void
--