@@ -78,7 +78,8 @@ struct pt_regs;
* following meaning:
*
* - bit 0: indicates whether the in-kernel Vector context is active. The
- * activation of this state disables the preemption.
+ * activation of this state disables the preemption. On a non-RT kernel, it
+ * also disable bh.
*/
#define RISCV_KERNEL_MODE_V 0x1
@@ -28,8 +28,12 @@ static __must_check inline bool may_use_simd(void)
/*
* RISCV_KERNEL_MODE_V is only set while preemption is disabled,
* and is clear whenever preemption is enabled.
+ *
+ * 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 !in_hardirq() && !in_nmi() && !(riscv_v_flags() & RISCV_KERNEL_MODE_V);
+ return !in_hardirq() && !in_nmi() && !irqs_disabled() && !(riscv_v_flags() & RISCV_KERNEL_MODE_V);
}
#else /* ! CONFIG_RISCV_ISA_V */
@@ -46,7 +46,14 @@ static inline void riscv_v_stop(u32 flags)
*/
void get_cpu_vector_context(void)
{
- preempt_disable();
+ /*
+ * 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
+ preempt_disable();
riscv_v_start(RISCV_KERNEL_MODE_V);
}
@@ -62,7 +69,10 @@ void put_cpu_vector_context(void)
{
riscv_v_stop(RISCV_KERNEL_MODE_V);
- preempt_enable();
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+ local_bh_enable();
+ else
+ preempt_enable();
}
/*