Skip to content

Commit 956895b

Browse files
AndybnACTpalmer-dabbelt
authored andcommitted
riscv: vector: make Vector always available for softirq context
The goal of this patch is to provide full support of Vector in kernel softirq context. So that some of the crypto alogrithms won't need scalar fallbacks. By disabling bottom halves in active kernel-mode Vector, softirq will not be able to nest on top of any kernel-mode Vector. So, softirq context is able to use Vector whenever it runs. After this patch, Vector context cannot start with irqs disabled. Otherwise local_bh_enable() may run in a wrong context. Disabling bh is not enough for RT-kernel to prevent preeemption. So we must disable preemption, which also implies disabling bh on RT. Related-to: commit 696207d ("arm64/sve: Make kernel FPU protection RT friendly") Related-to: commit 66c3ec5 ("arm64: neon: Forbid when irqs are disabled") Signed-off-by: Andy Chiu <[email protected]> Reviewed-by: Eric Biggers <[email protected]> Tested-by: Björn Töpel <[email protected]> Tested-by: Lad Prabhakar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent ecd2ada commit 956895b

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

arch/riscv/include/asm/processor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ struct pt_regs;
7878
* following meaning:
7979
*
8080
* - bit 0: indicates whether the in-kernel Vector context is active. The
81-
* activation of this state disables the preemption.
81+
* activation of this state disables the preemption. On a non-RT kernel, it
82+
* also disable bh.
8283
*/
8384
#define RISCV_KERNEL_MODE_V 0x1
8485

arch/riscv/include/asm/simd.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ static __must_check inline bool may_use_simd(void)
2828
/*
2929
* RISCV_KERNEL_MODE_V is only set while preemption is disabled,
3030
* and is clear whenever preemption is enabled.
31+
*
32+
* Kernel-mode Vector temporarily disables bh. So we must not return
33+
* true on irq_disabled(). Otherwise we would fail the lockdep check
34+
* calling local_bh_enable()
3135
*/
32-
return !in_hardirq() && !in_nmi() && !(riscv_v_flags() & RISCV_KERNEL_MODE_V);
36+
return !in_hardirq() && !in_nmi() && !irqs_disabled() && !(riscv_v_flags() & RISCV_KERNEL_MODE_V);
3337
}
3438

3539
#else /* ! CONFIG_RISCV_ISA_V */

arch/riscv/kernel/kernel_mode_vector.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ static inline void riscv_v_stop(u32 flags)
4646
*/
4747
void get_cpu_vector_context(void)
4848
{
49-
preempt_disable();
49+
/*
50+
* disable softirqs so it is impossible for softirqs to nest
51+
* get_cpu_vector_context() when kernel is actively using Vector.
52+
*/
53+
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
54+
local_bh_disable();
55+
else
56+
preempt_disable();
5057

5158
riscv_v_start(RISCV_KERNEL_MODE_V);
5259
}
@@ -62,7 +69,10 @@ void put_cpu_vector_context(void)
6269
{
6370
riscv_v_stop(RISCV_KERNEL_MODE_V);
6471

65-
preempt_enable();
72+
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
73+
local_bh_enable();
74+
else
75+
preempt_enable();
6676
}
6777

6878
/*

0 commit comments

Comments
 (0)