[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251007115840.2320557-7-geomatsi@gmail.com>
Date: Tue, 7 Oct 2025 14:58:22 +0300
From: Sergey Matyukevich <geomatsi@...il.com>
To: linux-riscv@...ts.infradead.org,
linux-kselftest@...r.kernel.org
Cc: linux-kernel@...r.kernel.org,
Paul Walmsley <pjw@...nel.org>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
Alexandre Ghiti <alex@...ti.fr>,
Oleg Nesterov <oleg@...hat.com>,
Shuah Khan <shuah@...nel.org>,
Jisheng Zhang <jszhang@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Thomas Huth <thuth@...hat.com>,
Charlie Jenkins <charlie@...osinc.com>,
Andy Chiu <andybnac@...il.com>,
Han Gao <rabenda.cn@...il.com>,
Samuel Holland <samuel.holland@...ive.com>,
Nam Cao <namcao@...utronix.de>,
Joel Granados <joel.granados@...nel.org>,
Clément Léger <cleger@...osinc.com>,
Conor Dooley <conor.dooley@...rochip.com>,
Sergey Matyukevich <geomatsi@...il.com>
Subject: [PATCH v2 6/6] riscv: vector: initialize vlenb on the first context switch
The vstate in thread_struct is zeroed when the vector context is
initialized. That includes read-only register vlenb, which holds
the vector register length in bytes. This zeroed state persists
until mstatus.VS becomes 'dirty' and a context switch saves the
actual hardware values.
This can expose the zero vlenb value to the user-space in early
debug scenarios, e.g. when ptrace attaches to a traced process
early, before any vector instruction except the first one was
executed.
Fix this by forcing the vector context save on the first context switch.
Signed-off-by: Sergey Matyukevich <geomatsi@...il.com>
---
arch/riscv/kernel/vector.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c
index 901e67adf576..3dd22a71aa18 100644
--- a/arch/riscv/kernel/vector.c
+++ b/arch/riscv/kernel/vector.c
@@ -120,6 +120,7 @@ static int riscv_v_thread_zalloc(struct kmem_cache *cache,
ctx->datap = datap;
memset(ctx, 0, offsetof(struct __riscv_v_ext_state, datap));
+
return 0;
}
@@ -216,8 +217,11 @@ bool riscv_v_first_use_handler(struct pt_regs *regs)
force_sig(SIGBUS);
return true;
}
+
riscv_v_vstate_on(regs);
riscv_v_vstate_set_restore(current, regs);
+ set_tsk_thread_flag(current, TIF_RISCV_V_FORCE_SAVE);
+
return true;
}
--
2.51.0
Powered by blists - more mailing lists