riscv: vector: refactor riscv_v_start_kernel_context

Refactor riscv_v_start_kernel_context() to drop `is_nested` variable and
simplify the logic.

This introduces no functional change and works as a preparatory patch for
the kernel-mode vector fix.

Signed-off-by: Andy Chiu <tchiu@tenstorrent.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260803215250.824417-2-tchiu@tenstorrent.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Andy Chiu 2026-08-03 16:52:40 -05:00 committed by Anup Patel
parent df81f80c35
commit 8f798d6d7f

View File

@ -121,7 +121,7 @@ static int riscv_v_stop_kernel_context(void)
return 0;
}
static int riscv_v_start_kernel_context(bool *is_nested)
static int riscv_v_start_kernel_context(void)
{
struct __riscv_v_ext_state *kvstate, *uvstate;
@ -131,7 +131,6 @@ static int riscv_v_start_kernel_context(bool *is_nested)
if (riscv_preempt_v_started(current)) {
WARN_ON(riscv_v_ctx_get_depth() == 0);
*is_nested = true;
get_cpu_vector_context();
if (riscv_preempt_v_dirty(current)) {
__riscv_v_vstate_save(kvstate, kvstate->datap);
@ -148,6 +147,7 @@ static int riscv_v_start_kernel_context(bool *is_nested)
__riscv_v_vstate_save(uvstate, uvstate->datap);
}
riscv_preempt_v_clear_dirty(current);
riscv_v_vstate_set_restore(current, task_pt_regs(current));
return 0;
}
@ -187,7 +187,7 @@ asmlinkage void riscv_v_context_nesting_end(struct pt_regs *regs)
}
}
#else
#define riscv_v_start_kernel_context(nested) (-ENOENT)
#define riscv_v_start_kernel_context() (-ENOENT)
#define riscv_v_stop_kernel_context() (-ENOENT)
#endif /* CONFIG_RISCV_ISA_V_PREEMPTIVE */
@ -206,20 +206,16 @@ asmlinkage void riscv_v_context_nesting_end(struct pt_regs *regs)
*/
void kernel_vector_begin(void)
{
bool nested = false;
if (WARN_ON(!(has_vector() || has_xtheadvector())))
return;
BUG_ON(!may_use_simd());
if (riscv_v_start_kernel_context(&nested)) {
if (riscv_v_start_kernel_context()) {
get_cpu_vector_context();
riscv_v_vstate_save(&current->thread.vstate, task_pt_regs(current));
}
if (!nested)
riscv_v_vstate_set_restore(current, task_pt_regs(current));
}
riscv_v_enable();
}