From: Gleb Pesin via B4 Relay <devnull+dormancygrace.gmail.com@kernel.org>
To: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
Andy Chiu <tchiu@tenstorrent.com>,
Charlie Jenkins <thecharlesjenkins@gmail.com>,
stable@vger.kernel.org, Gleb Pesin <dormancygrace@gmail.com>
Subject: [PATCH 3/3] riscv: Disable the xtheadvector unit on kernel entry
Date: Tue, 06 Oct 2026 03:35:56 +0300 [thread overview]
Message-ID: <20261006-riscv-xtheadvector-vs-v1-3-b00e5abc9f7a@gmail.com> (raw)
In-Reply-To: <20261006-riscv-xtheadvector-vs-v1-0-b00e5abc9f7a@gmail.com>
From: Gleb Pesin <dormancygrace@gmail.com>
handle_exception clears SR_FS_VS on entry so that stray floating-point
or vector instructions in the kernel raise an illegal-instruction
exception. xtheadvector keeps its vector status in SR_VS_THEAD
(sstatus bits 24:23), which that mask does not cover. On 64-bit kernels
bit 23 happens to be cleared as SR_SPELP, so the T-Head field is only
partly reset: DIRTY becomes CLEAN, and the vector unit stays enabled in
the kernel after a trap from a context that used it.
Clear the whole SR_VS_THEAD field on cores with xtheadvector. The status
saved in pt_regs still holds the interrupted value, so the vector state
is restored on return exactly as before. Other cores keep the current
mask, because bit 24 is not part of the vector status there.
Fixes: d863910eabaf ("riscv: vector: Support xtheadvector save/restore")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Gleb Pesin <dormancygrace@gmail.com>
---
arch/riscv/kernel/entry.S | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index d799c4e56..aeb99c20b 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -16,6 +16,8 @@
#include <asm/thread_info.h>
#include <asm/asm-offsets.h>
#include <asm/errata_list.h>
+#include <asm/vendor_extensions.h>
+#include <asm/vendor_extensions/thead.h>
#include <linux/sizes.h>
.section .irqentry.text, "ax"
@@ -176,9 +178,14 @@ SYM_CODE_START(handle_exception)
* actual user copy routines.
*
* Disable the FPU/Vector to detect illegal usage of floating point
- * or vector in kernel space.
+ * or vector in kernel space. xtheadvector keeps its vector status in
+ * a different sstatus field; those bits are reserved elsewhere.
*/
- li t0, SR_SUM | SR_FS_VS
+ ALTERNATIVE(__stringify(li t0, SR_SUM | SR_FS_VS),
+ __stringify(li t0, SR_SUM | SR_FS_VS | SR_VS_THEAD),
+ THEAD_VENDOR_ID,
+ RISCV_VENDOR_EXT_ALTERNATIVES_BASE + RISCV_ISA_VENDOR_EXT_XTHEADVECTOR,
+ CONFIG_RISCV_ISA_XTHEADVECTOR)
#ifdef CONFIG_64BIT
li t1, SR_ELP
or t0, t0, t1
--
2.53.0
prev parent reply other threads:[~2026-10-06 0:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 0:35 [PATCH 0/3] riscv: Fix xtheadvector vector status handling Gleb Pesin via B4 Relay
2026-10-06 0:35 ` [PATCH 1/3] riscv: vector: Check the xtheadvector status field in riscv_v_is_on() Gleb Pesin via B4 Relay
2026-10-06 0:35 ` [PATCH 2/3] riscv: Make the vendor extension headers usable from assembly Gleb Pesin via B4 Relay
2026-10-06 0:35 ` Gleb Pesin via B4 Relay [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261006-riscv-xtheadvector-vs-v1-3-b00e5abc9f7a@gmail.com \
--to=devnull+dormancygrace.gmail.com@kernel.org \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=dormancygrace@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tchiu@tenstorrent.com \
--cc=thecharlesjenkins@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®