[PATCH v2 2/3] riscv: vector: allow non-preemptible kernel-mode vector with IRQs off
Andy Chiu
tchiu at tenstorrent.com
Tue Jul 14 22:16:21 PDT 2026
Similar to commit 7137a203b251 ("arm64/fpsimd: Permit kernel mode NEON
with IRQs off"), we are upgrading get/put_cpu_vector_context such that
kvm_arch_vcpu_load/put can be safely called under both irq off and
regular process context.
Also, export both symbols so kvm module can call into it.
Signed-off-by: Andy Chiu <tchiu at tenstorrent.com>
---
Changelog v2:
- new patch since v2
---
arch/riscv/include/asm/simd.h | 8 ++------
arch/riscv/kernel/kernel_mode_vector.c | 18 ++++++++++++------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/arch/riscv/include/asm/simd.h b/arch/riscv/include/asm/simd.h
index adb50f3ec205..678c8b97cd49 100644
--- a/arch/riscv/include/asm/simd.h
+++ b/arch/riscv/include/asm/simd.h
@@ -44,12 +44,8 @@ static __must_check inline bool may_use_simd(void)
if (!riscv_preempt_v_started(current))
return true;
}
- /*
- * Non-preemptible kernel-mode Vector temporarily disables bh. So we
- * must not return true on irq_disabled(). Otherwise we would fail the
- * lockdep check calling local_bh_enable()
- */
- return !irqs_disabled() && !(riscv_v_flags() & RISCV_KERNEL_MODE_V);
+
+ return !(riscv_v_flags() & RISCV_KERNEL_MODE_V);
}
#else /* ! CONFIG_RISCV_ISA_V */
diff --git a/arch/riscv/kernel/kernel_mode_vector.c b/arch/riscv/kernel/kernel_mode_vector.c
index 307ac369c3d4..6627e1a82e19 100644
--- a/arch/riscv/kernel/kernel_mode_vector.c
+++ b/arch/riscv/kernel/kernel_mode_vector.c
@@ -55,13 +55,16 @@ void get_cpu_vector_context(void)
* disable softirqs so it is impossible for softirqs to nest
* get_cpu_vector_context() when kernel is actively using Vector.
*/
- if (!IS_ENABLED(CONFIG_PREEMPT_RT))
- local_bh_disable();
- else
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
+ if (!irqs_disabled())
+ local_bh_disable();
+ } else {
preempt_disable();
+ }
riscv_v_start(RISCV_KERNEL_MODE_V);
}
+EXPORT_SYMBOL_GPL(get_cpu_vector_context);
/*
* Release the CPU vector context.
@@ -74,11 +77,14 @@ void put_cpu_vector_context(void)
{
riscv_v_stop(RISCV_KERNEL_MODE_V);
- if (!IS_ENABLED(CONFIG_PREEMPT_RT))
- local_bh_enable();
- else
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT)) {
+ if (!irqs_disabled())
+ local_bh_enable();
+ } else {
preempt_enable();
+ }
}
+EXPORT_SYMBOL_GPL(put_cpu_vector_context);
#ifdef CONFIG_RISCV_ISA_V_PREEMPTIVE
static __always_inline u32 *riscv_v_flags_ptr(void)
--
2.43.0
More information about the kvm-riscv
mailing list