Skip to contentSkip to conversation

Add eager FP and RISC-V vector context switching support

PATCH Superseded [email protected] 2 participants 8 messages Apr 6 – Apr 8

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add eager FP and RISC-V vector context switching support

Hi Radim, Samuel,
Thank you for taking out time and reviewing the patches,
has been some insightful comment and appreciate your inputs and feedback.

I have covered all your comments, please can you have a look and let me know.

I have tested this across the 2 s-mode domains doing context switch and both floating point and vector retains the values across the context.

Thanks and Regards,
Dave

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#1 lore raw

PATCH v4 1/3 lib: sbi: Add RISC-V vector context save/restore support

From: Dave Patel <[email protected]>

Eager context switch: Add support for saving and restoring RISC-V vector extension state in OpenSBI. This introduces a per-hart vector context structure and helper routines to perform full context save and restore.

The vector context includes vcsr CSRs along with storage for all 32 vector registers. The register state is saved and restored using byte-wise vector load/store instructions (vs8r/vl8r).

The implementation follows an eager context switching model where the entire vector state is saved and restored on every context switch. This provides a simple and deterministic mechanism without requiring lazy trap-based management.

Notes:
- The SBI_MAX_VLENB is configured using CONFIG_SBI_MAX_VLENB.

---
 include/sbi/sbi_vector.h |  29 ++++++++
 lib/sbi/Kconfig          |   4 +
 lib/sbi/objects.mk       |   1 +
 lib/sbi/sbi_vector.c     | 154 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 188 insertions(+)
 create mode 100644 include/sbi/sbi_vector.h
 create mode 100644 lib/sbi/sbi_vector.c
include/sbi/sbi_vector.h new file +29 -0
new file mode 100644
index 00000000..13048716
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (c) 2026 RISCstar Solutions.
+ *
+ * Authors:
+ *   Dave Patel <[email protected]>
+ */
+
+#ifndef __SBI_VECTOR_H__
+#define __SBI_VECTOR_H__
+
+#include <sbi/sbi_types.h>
+
+#define SBI_MAX_VLENB CONFIG_SBI_MAX_VLENB
+
+struct sbi_vector_context {
+	unsigned long vcsr;
+	unsigned long vstart;
+
+	/* size depends on VLEN */
+	uint8_t vregs[32 * SBI_MAX_VLENB];
+};
+
+void sbi_vector_save(struct sbi_vector_context *dst);
+void sbi_vector_restore(const struct sbi_vector_context *src);
+int sbi_vector_domain_init(void);
+
+#endif //__SBI_VECTOR_H__
+
lib/sbi/Kconfig +4 -0
index 8479f861..b2432150 100644
@@ -74,4 +74,8 @@ config SBI_ECALL_VIRQ
 	bool "VIRQ extension"
 	default y
 
+config SBI_MAX_VLENB
+	int "Vector VLENB size"
+	default 256
+
 endmenu
lib/sbi/objects.mk +1 -0
index 68fc2036..ecb2b54e 100644
@@ -109,3 +109,4 @@ libsbi-objs-y += sbi_trap_v_ldst.o
 libsbi-objs-y += sbi_unpriv.o
 libsbi-objs-y += sbi_expected_trap.o
 libsbi-objs-y += sbi_cppc.o
+libsbi-objs-y += sbi_vector.o
lib/sbi/sbi_vector.c new file +154 -0

154 lines not on this page · raw message

--
2.43.0

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#2 lore raw

Re: [PATCH v4 1/3] lib: sbi: Add RISC-V vector context save/restore support

Hi Dave,

Quoted 34 lines · On 2026-04-06 2:31 PM, [email protected] wrote:

From: Dave Patel <[email protected]>

Eager context switch: Add support for saving and restoring RISC-V vector extension state in OpenSBI. This introduces a per-hart vector context structure and helper routines to perform full context save and restore.

The vector context includes vcsr CSRs along with storage for all 32 vector registers. The register state is saved and restored using byte-wise vector load/store instructions (vs8r/vl8r).

The implementation follows an eager context switching model where the entire vector state is saved and restored on every context switch. This provides a simple and deterministic mechanism without requiring lazy trap-based management.

Notes:
- The SBI_MAX_VLENB is configured using CONFIG_SBI_MAX_VLENB.

---
 include/sbi/sbi_vector.h |  29 ++++++++
 lib/sbi/Kconfig          |   4 +
 lib/sbi/objects.mk       |   1 +
 lib/sbi/sbi_vector.c     | 154 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 188 insertions(+)
 create mode 100644 include/sbi/sbi_vector.h
 create mode 100644 lib/sbi/sbi_vector.c
include/sbi/sbi_vector.h new file +0 -0
new file mode 100644
index 00000000..13048716

include/sbi/sbi_vector.h line 1

Quoted 1 line
include/sbi/sbi_vector.h new file +1 -0
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0

This license is not compatible with the OpenSBI project. You need to release these changes under a compatible license (assuming you are able to do so, i.e. they are not derived from GPL code, etc. I am not a lawyer).

Quoted 181 lines
include/sbi/sbi_vector.h new file +28 -0
+ *
+ * Copyright (c) 2026 RISCstar Solutions.
+ *
+ * Authors:
+ *   Dave Patel <[email protected]>
+ */
+
+#ifndef __SBI_VECTOR_H__
+#define __SBI_VECTOR_H__
+
+#include <sbi/sbi_types.h>
+
+#define SBI_MAX_VLENB CONFIG_SBI_MAX_VLENB
+
+struct sbi_vector_context {
+	unsigned long vcsr;
+	unsigned long vstart;
+
+	/* size depends on VLEN */
+	uint8_t vregs[32 * SBI_MAX_VLENB];
+};
+
+void sbi_vector_save(struct sbi_vector_context *dst);
+void sbi_vector_restore(const struct sbi_vector_context *src);
+int sbi_vector_domain_init(void);
+
+#endif //__SBI_VECTOR_H__
+
lib/sbi/Kconfig +4 -0
index 8479f861..b2432150 100644
@@ -74,4 +74,8 @@ config SBI_ECALL_VIRQ
 	bool "VIRQ extension"
 	default y
 
+config SBI_MAX_VLENB
+	int "Vector VLENB size"
+	default 256
+
 endmenu
lib/sbi/objects.mk +1 -0
index 68fc2036..ecb2b54e 100644
@@ -109,3 +109,4 @@ libsbi-objs-y += sbi_trap_v_ldst.o
 libsbi-objs-y += sbi_unpriv.o
 libsbi-objs-y += sbi_expected_trap.o
 libsbi-objs-y += sbi_cppc.o
+libsbi-objs-y += sbi_vector.o
lib/sbi/sbi_vector.c new file +125 -0
new file mode 100644
index 00000000..85134f8b
@@ -0,0 +1,154 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (c) 2026 RISCstar Solutions.
+ *
+ * Authors:
+ *	 Dave Patel <[email protected]>
+ */
+
+#include <sbi/sbi_domain.h>
+#include <sbi/riscv_encoding.h>
+#include <sbi/riscv_asm.h>
+#include <sbi/sbi_vector.h>
+#include <sbi/sbi_types.h>
+#include <sbi/sbi_hart.h>
+#include <sbi/sbi_error.h>
+#include <sbi/sbi_console.h>
+
+#ifdef OPENSBI_CC_SUPPORT_VECTOR
+
+static inline unsigned long vector_vlenb(void)
+{
+	unsigned long vlenb = 0;
+
+	asm volatile (
+		".option push\n\t"
+		".option arch, +v\n\t"
+		"csrr %0, vlenb\n\t"
+		".option pop\n\t"
+		: "=r"(vlenb)
+		:
+		: "memory");
+
+	return vlenb;
+}
+
+void sbi_vector_save(struct sbi_vector_context *dst)
+{
+	if (!dst)
+		return;
+
+#define READ_CSR(dst, csr)				\
+	({						\
+		asm volatile (				\
+			"	.option push\n\t"	\
+			"	.option arch, +v\n\t"	\
+			"	csrr %0, " #csr "\n\t"	\
+			"	.option pop\n\t"	\
+			:	"=r"(dst)		\
+			:				\
+			:	"memory");		\
+	})						\
+
+	/* Step 1: Save CSRs */
+	READ_CSR(dst->vcsr,   vcsr);
+	READ_CSR(dst->vstart, vstart);
+
+#undef READ_CSR
+
+	ulong vlenb = vector_vlenb();
+	uint8_t *base = dst->vregs;
+
+	/* Step 3: Save vector registers */
+#define SAVE_VREG(i)						\
+	({							\
+	asm volatile(						\
+		"	.option push\n\t"			\
+		"	.option arch, +v\n\t"			\
+		"	vs8r.v v" #i ", (%0)\n\t"		\
+		"	.option pop\n\t"			\
+		::	"r"(base + (i) * vlenb)	: "memory");	\
+	})							\
+
+	SAVE_VREG(0);
+	SAVE_VREG(8);
+	SAVE_VREG(16);
+	SAVE_VREG(24);
+
+#undef SAVE_VREG
+}
+
+void sbi_vector_restore(const struct sbi_vector_context *src)
+{
+	if (!src)
+		return;
+
+	const uint8_t *base = src->vregs;
+	ulong vlenb = vector_vlenb();
+
+	/* Step 2: Restore vector registers */
+#define RESTORE_VREG(i)					\
+	({							\
+	asm volatile(						\
+		"	.option push\n\t"			\
+		"	.option arch, +v\n\t"			\
+		"	vl8r.v v" #i ", (%0)\n\t"		\
+		"	.option pop\n\t"			\
+		::	"r"(base + (i) * vlenb) : "memory");	\
+	 })							\
+
+	RESTORE_VREG(0);
+	RESTORE_VREG(8);
+	RESTORE_VREG(16);
+	RESTORE_VREG(24);
+#undef RESTORE_VREG
+
+	/* Step 3: Restore CSR's last */
+#define WRITE_CSR(csr, val)			\
+	({					\
+	asm volatile(				\
+		"	.option push\n\t"	\
+		"	.option arch, +v\n\t"	\
+		"	csrw " #csr ", %0\n\t"	\
+		"	.option pop\n\t"	\
+		:				\
+		:	"r"(val)		\
+		:	"memory");		\
+	 })					\
+
+	/* Restore CSRs first */
+	WRITE_CSR(vcsr,   src->vcsr);
+	WRITE_CSR(vstart, src->vstart);
+#undef WRITE_CSR
+}
+
+int sbi_vector_domain_init(void)

lib/sbi/sbi_vector.c line 135

Quoted 10 lines
lib/sbi/sbi_vector.c new file +10 -0
+{
+	csr_set(CSR_MSTATUS, MSTATUS_VS);
+	ulong vlenb = vector_vlenb();
+
+	if (vlenb > SBI_MAX_VLENB) {
+		sbi_printf("[Vector ERR:] vlenb range error\n");
+		return SBI_ERR_BAD_RANGE;
+	}
+
+	csr_clear(CSR_MSTATUS, MSTATUS_VS);

What is the purpose of this CSR write? If you want to set the initial state of the vector registers, this doesn't accomplish that; you have to write the vector registers.

Regards,
Samuel

Quoted 22 lines
lib/sbi/sbi_vector.c new file +19 -1
+	return SBI_OK;
+}
+
+#else
+
+void sbi_vector_save(struct sbi_vector_context *dst)
+{
+}
+
+void sbi_vector_restore(const struct sbi_vector_context *src)
+{
+}
+
+int sbi_vector_domain_init(void)
+{
+	return SBI_OK;
+}
+
+#endif /* OPENSBI_CC_SUPPORT_VECTOR */
--

2.43.0

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
author
#3 lore raw

Re: [PATCH v4 1/3] lib: sbi: Add RISC-V vector context save/restore support

Quoted 31 lines · Samuel Holland

Hi Dave,

Quoted 28 lines · On 2026-04-06 2:31 PM, [email protected] wrote:

From: Dave Patel <[email protected]>

Eager context switch: Add support for saving and restoring RISC-V vector extension state in OpenSBI. This introduces a per-hart vector context structure and helper routines to perform full context save and restore.

The vector context includes vcsr CSRs along with storage for all 32 vector registers. The register state is saved and restored using byte-wise vector load/store instructions (vs8r/vl8r).

The implementation follows an eager context switching model where the entire vector state is saved and restored on every context switch. This provides a simple and deterministic mechanism without requiring lazy trap-based management.

Notes:
- The SBI_MAX_VLENB is configured using CONFIG_SBI_MAX_VLENB.

---
 include/sbi/sbi_vector.h |  29 ++++++++
 lib/sbi/Kconfig          |   4 +
 lib/sbi/objects.mk       |   1 +
 lib/sbi/sbi_vector.c     | 154 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 188 insertions(+)
 create mode 100644 include/sbi/sbi_vector.h
 create mode 100644 lib/sbi/sbi_vector.c
Quoted 12 lines

include/sbi/sbi_vector.h line 1

Quoted 7 lines
include/sbi/sbi_vector.h new file +1 -0
new file mode 100644
index 00000000..13048716
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0

This license is not compatible with the OpenSBI project. You need to release these changes under a compatible license (assuming you are able to do so, i.e. they are not derived from GPL code, etc. I am not a lawyer).

Thanks, I have updated to match the Opensbi standards.

Quoted 187 lines
Quoted 187 lines
include/sbi/sbi_vector.h new file +28 -0
+ *
+ * Copyright (c) 2026 RISCstar Solutions.
+ *
+ * Authors:
+ *   Dave Patel <[email protected]>
+ */
+
+#ifndef __SBI_VECTOR_H__
+#define __SBI_VECTOR_H__
+
+#include <sbi/sbi_types.h>
+
+#define SBI_MAX_VLENB CONFIG_SBI_MAX_VLENB
+
+struct sbi_vector_context {
+	unsigned long vcsr;
+	unsigned long vstart;
+
+	/* size depends on VLEN */
+	uint8_t vregs[32 * SBI_MAX_VLENB];
+};
+
+void sbi_vector_save(struct sbi_vector_context *dst);
+void sbi_vector_restore(const struct sbi_vector_context *src);
+int sbi_vector_domain_init(void);
+
+#endif //__SBI_VECTOR_H__
+
lib/sbi/Kconfig +4 -0
index 8479f861..b2432150 100644
@@ -74,4 +74,8 @@ config SBI_ECALL_VIRQ
 	bool "VIRQ extension"
 	default y
 
+config SBI_MAX_VLENB
+	int "Vector VLENB size"
+	default 256
+
 endmenu
lib/sbi/objects.mk +1 -0
index 68fc2036..ecb2b54e 100644
@@ -109,3 +109,4 @@ libsbi-objs-y += sbi_trap_v_ldst.o
 libsbi-objs-y += sbi_unpriv.o
 libsbi-objs-y += sbi_expected_trap.o
 libsbi-objs-y += sbi_cppc.o
+libsbi-objs-y += sbi_vector.o
lib/sbi/sbi_vector.c new file +131 -0
new file mode 100644
index 00000000..85134f8b
@@ -0,0 +1,154 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (c) 2026 RISCstar Solutions.
+ *
+ * Authors:
+ *	 Dave Patel <[email protected]>
+ */
+
+#include <sbi/sbi_domain.h>
+#include <sbi/riscv_encoding.h>
+#include <sbi/riscv_asm.h>
+#include <sbi/sbi_vector.h>
+#include <sbi/sbi_types.h>
+#include <sbi/sbi_hart.h>
+#include <sbi/sbi_error.h>
+#include <sbi/sbi_console.h>
+
+#ifdef OPENSBI_CC_SUPPORT_VECTOR
+
+static inline unsigned long vector_vlenb(void)
+{
+	unsigned long vlenb = 0;
+
+	asm volatile (
+		".option push\n\t"
+		".option arch, +v\n\t"
+		"csrr %0, vlenb\n\t"
+		".option pop\n\t"
+		: "=r"(vlenb)
+		:
+		: "memory");
+
+	return vlenb;
+}
+
+void sbi_vector_save(struct sbi_vector_context *dst)
+{
+	if (!dst)
+		return;
+
+#define READ_CSR(dst, csr)				\
+	({						\
+		asm volatile (				\
+			"	.option push\n\t"	\
+			"	.option arch, +v\n\t"	\
+			"	csrr %0, " #csr "\n\t"	\
+			"	.option pop\n\t"	\
+			:	"=r"(dst)		\
+			:				\
+			:	"memory");		\
+	})						\
+
+	/* Step 1: Save CSRs */
+	READ_CSR(dst->vcsr,   vcsr);
+	READ_CSR(dst->vstart, vstart);
+
+#undef READ_CSR
+
+	ulong vlenb = vector_vlenb();
+	uint8_t *base = dst->vregs;
+
+	/* Step 3: Save vector registers */
+#define SAVE_VREG(i)						\
+	({							\
+	asm volatile(						\
+		"	.option push\n\t"			\
+		"	.option arch, +v\n\t"			\
+		"	vs8r.v v" #i ", (%0)\n\t"		\
+		"	.option pop\n\t"			\
+		::	"r"(base + (i) * vlenb)	: "memory");	\
+	})							\
+
+	SAVE_VREG(0);
+	SAVE_VREG(8);
+	SAVE_VREG(16);
+	SAVE_VREG(24);
+
+#undef SAVE_VREG
+}
+
+void sbi_vector_restore(const struct sbi_vector_context *src)
+{
+	if (!src)
+		return;
+
+	const uint8_t *base = src->vregs;
+	ulong vlenb = vector_vlenb();
+
+	/* Step 2: Restore vector registers */
+#define RESTORE_VREG(i)					\
+	({							\
+	asm volatile(						\
+		"	.option push\n\t"			\
+		"	.option arch, +v\n\t"			\
+		"	vl8r.v v" #i ", (%0)\n\t"		\
+		"	.option pop\n\t"			\
+		::	"r"(base + (i) * vlenb) : "memory");	\
+	 })							\
+
+	RESTORE_VREG(0);
+	RESTORE_VREG(8);
+	RESTORE_VREG(16);
+	RESTORE_VREG(24);
+#undef RESTORE_VREG
+
+	/* Step 3: Restore CSR's last */
+#define WRITE_CSR(csr, val)			\
+	({					\
+	asm volatile(				\
+		"	.option push\n\t"	\
+		"	.option arch, +v\n\t"	\
+		"	csrw " #csr ", %0\n\t"	\
+		"	.option pop\n\t"	\
+		:				\
+		:	"r"(val)		\
+		:	"memory");		\
+	 })					\
+
+	/* Restore CSRs first */
+	WRITE_CSR(vcsr,   src->vcsr);
+	WRITE_CSR(vstart, src->vstart);
+#undef WRITE_CSR
+}
+
+int sbi_vector_domain_init(void)
+{
+	csr_set(CSR_MSTATUS, MSTATUS_VS);
+	ulong vlenb = vector_vlenb();
+
+	if (vlenb > SBI_MAX_VLENB) {
+		sbi_printf("[Vector ERR:] vlenb range error\n");
Quoted 9 lines

lib/sbi/sbi_vector.c line 135

Quoted 4 lines
lib/sbi/sbi_vector.c new file +4 -0
+		return SBI_ERR_BAD_RANGE;
+	}
+
+	csr_clear(CSR_MSTATUS, MSTATUS_VS);

What is the purpose of this CSR write? If you want to set the initial state of the vector registers, this doesn't accomplish that; you have to write the vector registers.

The code is to check the vlen at the startup, the csr set is used so that the vector operation can be performed and cleared to bring it back to it's original state.

Quoted 17 lines

Regards,
Samuel

Quoted 14 lines
lib/sbi/sbi_vector.c new file +14 -0
+	return SBI_OK;
+}
+
+#else
+
+void sbi_vector_save(struct sbi_vector_context *dst)
+{
+}
+
+void sbi_vector_restore(const struct sbi_vector_context *src)
+{
+}
+
+int sbi_vector_domain_init(void)
Quoted 9 lines
Quoted 8 lines
lib/sbi/sbi_vector.c new file +5 -1
+{
+	return SBI_OK;
+}
+
+#endif /* OPENSBI_CC_SUPPORT_VECTOR */
--

2.43.0

Hi Samuel,
Please see inline above.
Thanks
Dave

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#4 lore raw

PATCH v4 2/3 lib: sbi: Add floating-point context save/restore support.

In reply to [email protected]

From: Dave Patel <[email protected]>

Add support for saving and restoring RISC-V floating-point (F/D) extension state in OpenSBI. This introduces a floating-point context structure and helper routines to perform full context save and restore.

The floating-point context includes storage for all 32 FPi registers (f0–f31) along with the fcsr control and status register. The register state is saved and restored using double-precision load/store instructions (fsd/fld), and single-precision load/store instructions (fsw/flw) on an RV64 system with F and D-extension support.

The implementation follows an eager context switching model where the entire FP state is saved and restored on every context switch. This avoids the need for trap-based lazy management and keeps the design simple and deterministic.

---
 include/sbi/sbi_fp.h |  25 ++++++
 lib/sbi/objects.mk   |   1 +
 lib/sbi/sbi_fp.c     | 191 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 217 insertions(+)
 create mode 100644 include/sbi/sbi_fp.h
 create mode 100644 lib/sbi/sbi_fp.c
include/sbi/sbi_fp.h new file +25 -0
new file mode 100644
index 00000000..962150a3
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (c) 2026 RISCstar Solutions.
+ *
+ * Authors:
+ *   Dave Patel <[email protected]>
+ */
+#ifndef __SBI_FP_H__
+#define __SBI_FP_H__
+
+#include <sbi/sbi_types.h>
+
+struct sbi_fp_context {
+#if __riscv_d
+	uint64_t f[32];
+#else
+	uint32_t f[32];
+#endif
+	uint32_t fcsr;
+};
+
+void sbi_fp_save(struct sbi_fp_context *dst);
+void sbi_fp_restore(const struct sbi_fp_context *src);
+
+#endif //__SBI_VECTOR_H__
lib/sbi/objects.mk +1 -0
index ecb2b54e..8b4a22c0 100644
@@ -110,3 +110,4 @@ libsbi-objs-y += sbi_unpriv.o
 libsbi-objs-y += sbi_expected_trap.o
 libsbi-objs-y += sbi_cppc.o
 libsbi-objs-y += sbi_vector.o
+libsbi-objs-y += sbi_fp.o
lib/sbi/sbi_fp.c new file +191 -0

191 lines not on this page · raw message

--
2.43.0

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#5 lore raw

PATCH v4 3/3 lib: sbi: domain FP/Vector context support for context switch

In reply to [email protected]

From: Dave Patel <[email protected]>

This patch adds proper support for per-domain floating-point (FP) and vector (V) contexts in the domain context switch logic. Each domain now maintains its own FP and vector state, which is saved and restored during domain switches.

Changes include:

- Added fp_ctx and vec_ctx members to struct sbi_domain.
- Introduced sbi_vector_domain_init for vlen check
to allocate and free per-domain FP and vector context.
- Modified sbi_domain_register() to initialize FP/Vector context per domain.
- Updated switch_to_next_domain_context() to save/restore FP and vector contexts safely:
- Ensures FS/VS fields in mstatus are enabled (set to Initial) only if Off.
- Added runtime checks for FP and vector extensions where needed.

This improves support for multi-domain systems with FP and Vector extensions, and prevents corruption of FP/Vector state during domain switches.

---
 include/sbi/sbi_domain.h     |  6 ++++++
 lib/sbi/sbi_domain.c         |  6 ++++++
 lib/sbi/sbi_domain_context.c | 12 ++++++++++++
 3 files changed, 24 insertions(+)
include/sbi/sbi_domain.h +6 -0
index 882b62c2..318d3a9a 100644
@@ -16,6 +16,8 @@
 #include <sbi/sbi_hartmask.h>
 #include <sbi/sbi_domain_context.h>
 #include <sbi/sbi_domain_data.h>
+#include <sbi/sbi_vector.h>
+#include <sbi/sbi_fp.h>
 
 struct sbi_scratch;
 
@@ -217,6 +219,10 @@ struct sbi_domain {
 	bool fw_region_inited;
 	/** per-domain wired-IRQ courier state */
 	void *virq_priv;
+	/** per-domain float context state */
+	struct sbi_fp_context fp_ctx;
+	/** per-domain vector context state */
+	struct sbi_vector_context vec_ctx;
 };
 
 /** The root domain instance */
lib/sbi/sbi_domain.c +6 -0
index 498a1d56..424204eb 100644
@@ -19,6 +19,8 @@
 #include <sbi/sbi_scratch.h>
 #include <sbi/sbi_string.h>
 #include <sbi/sbi_virq.h>
+#include <sbi/sbi_vector.h>
+#include <sbi/sbi_fp.h>
 
 SBI_LIST_HEAD(domain_list);
 
@@ -1007,6 +1009,10 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)
 	if (rc)
 		goto fail_free_root_hmask;
 
+	rc = sbi_vector_domain_init();
+	if (rc)
+		goto fail_free_root_hmask;
+
 	return 0;
 
 fail_free_root_hmask:
lib/sbi/sbi_domain_context.c +12 -0
index 158f4990..f646c7d4 100644
@@ -18,6 +18,9 @@
 #include <sbi/sbi_domain_context.h>
 #include <sbi/sbi_platform.h>
 #include <sbi/sbi_trap.h>
+#include <sbi/sbi_vector.h>
+#include <sbi/sbi_fp.h>
+
 
 /** Context representation for a hart within a domain */
 struct hart_context {
@@ -143,6 +146,15 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
 	if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSQOSID))
 		ctx->srmcfg	= csr_swap(CSR_SRMCFG, dom_ctx->srmcfg);
 
+	/* Make sure FS and VS is on before context switch */
+	csr_set(CSR_MSTATUS, MSTATUS_FS | MSTATUS_VS);
+
+	/* Eager context switch F and V */
+	sbi_fp_save(&current_dom->fp_ctx);
+	sbi_fp_restore(&target_dom->fp_ctx);
+	sbi_vector_save(&current_dom->vec_ctx);
+	sbi_vector_restore(&target_dom->vec_ctx);
+
 	/* Save current trap state and restore target domain's trap state */
 	trap_ctx = sbi_trap_get_context(scratch);
 	sbi_memcpy(&ctx->trap_ctx, trap_ctx, sizeof(*trap_ctx));

--
2.43.0

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
#6 lore raw
In reply to [email protected]

Hi Dave,

Quoted 6 lines · On 2026-04-06 2:31 PM, [email protected] wrote:

Hi Radim, Samuel,
Thank you for taking out time and reviewing the patches,
has been some insightful comment and appreciate your inputs and feedback.

I have covered all your comments, please can you have a look and let me know.

You need to include a changelog in your cover letter when sending a new version of a patch series, describing the changes you made to each patch. You can't expect reviewers to go back and find your previous series and diff them to find out what you changed.

Regards,
Samuel

Quoted 7 lines

I have tested this across the 2 s-mode domains doing context switch and both floating point and vector retains the values across the context.

Thanks and Regards,
Dave

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
author
#7 lore raw

On Mon, 6 Apr 2026, 23:33 Samuel Holland, <[email protected]> wrote:

Hi Dave,

On 2026-04-06 2:31 PM, [email protected] wrote:
>
> Hi Radim, Samuel,
>                 Thank you for taking out time and reviewing the patches,
> has been some insightful comment and appreciate your inputs and feedback.
>
> I have covered all your comments, please can you have a look and let me know.

You need to include a changelog in your cover letter when sending a new version
of a patch series, describing the changes you made to each patch. You can't
expect reviewers to go back and find your previous series and diff them to find
out what you changed.

Regards,
Samuel

> I have tested this across the 2 s-mode domains doing context switch and both
> floating point and vector retains the values across the context. >
> Thanks and Regards,
> Dave
>
> Signed-off-by: Dave Patel <[email protected]>

Hi Samuel,

Thanks, I've updated with the change log to the cover letter now.

Thanks
Dave

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi