riscv: vector: do not pass task_struct into riscv_v_vstate_{save,restore}()
authorAndy Chiu <andy.chiu@sifive.com>
Mon, 15 Jan 2024 05:59:26 +0000 (05:59 +0000)
committerPalmer Dabbelt <palmer@rivosinc.com>
Tue, 16 Jan 2024 15:13:59 +0000 (07:13 -0800)
riscv_v_vstate_{save,restore}() can operate only on the knowlege of
struct __riscv_v_ext_state, and struct pt_regs. Let the caller decides
which should be passed into the function. Meanwhile, the kernel-mode
Vector is going to introduce another vstate, so this also makes functions
potentially able to be reused.

Signed-off-by: Andy Chiu <andy.chiu@sifive.com>
Acked-by: Conor Dooley <conor.dooley@microchip.com>
Tested-by: Björn Töpel <bjorn@rivosinc.com>
Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Link: https://lore.kernel.org/r/20240115055929.4736-8-andy.chiu@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/entry-common.h
arch/riscv/include/asm/vector.h
arch/riscv/kernel/kernel_mode_vector.c
arch/riscv/kernel/ptrace.c
arch/riscv/kernel/signal.c

index 19023c430a9b587e0c24e0ceb07c7a444f05e557..2293e535f8659af02ef2e52ce1752827c415532e 100644 (file)
@@ -16,7 +16,7 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
                 * We are already called with irq disabled, so go without
                 * keeping track of riscv_v_flags.
                 */
-               riscv_v_vstate_restore(current, regs);
+               riscv_v_vstate_restore(&current->thread.vstate, regs);
        }
 }
 
index 961c4e3d1b620f36c7b05b7e1eb67f85e4183e1c..d7507952062999f25d234ad39f71dcd8aa39dc46 100644 (file)
@@ -171,23 +171,19 @@ static inline void riscv_v_vstate_discard(struct pt_regs *regs)
        __riscv_v_vstate_dirty(regs);
 }
 
-static inline void riscv_v_vstate_save(struct task_struct *task,
+static inline void riscv_v_vstate_save(struct __riscv_v_ext_state *vstate,
                                       struct pt_regs *regs)
 {
        if ((regs->status & SR_VS) == SR_VS_DIRTY) {
-               struct __riscv_v_ext_state *vstate = &task->thread.vstate;
-
                __riscv_v_vstate_save(vstate, vstate->datap);
                __riscv_v_vstate_clean(regs);
        }
 }
 
-static inline void riscv_v_vstate_restore(struct task_struct *task,
+static inline void riscv_v_vstate_restore(struct __riscv_v_ext_state *vstate,
                                          struct pt_regs *regs)
 {
        if ((regs->status & SR_VS) != SR_VS_OFF) {
-               struct __riscv_v_ext_state *vstate = &task->thread.vstate;
-
                __riscv_v_vstate_restore(vstate, vstate->datap);
                __riscv_v_vstate_clean(regs);
        }
@@ -208,7 +204,7 @@ static inline void __switch_to_vector(struct task_struct *prev,
        struct pt_regs *regs;
 
        regs = task_pt_regs(prev);
-       riscv_v_vstate_save(prev, regs);
+       riscv_v_vstate_save(&prev->thread.vstate, regs);
        riscv_v_vstate_set_restore(next, task_pt_regs(next));
 }
 
@@ -226,8 +222,8 @@ static inline bool riscv_v_vstate_query(struct pt_regs *regs) { return false; }
 static inline bool riscv_v_vstate_ctrl_user_allowed(void) { return false; }
 #define riscv_v_vsize (0)
 #define riscv_v_vstate_discard(regs)           do {} while (0)
-#define riscv_v_vstate_save(task, regs)                do {} while (0)
-#define riscv_v_vstate_restore(task, regs)     do {} while (0)
+#define riscv_v_vstate_save(vstate, regs)      do {} while (0)
+#define riscv_v_vstate_restore(vstate, regs)   do {} while (0)
 #define __switch_to_vector(__prev, __next)     do {} while (0)
 #define riscv_v_vstate_off(regs)               do {} while (0)
 #define riscv_v_vstate_on(regs)                        do {} while (0)
index 8422c881f4529d9b2158f5c78e3f64edd0ef069a..241a8f834e1ce17bd4fd3570ffd645cc7833aa2f 100644 (file)
@@ -97,7 +97,7 @@ void kernel_vector_begin(void)
 
        get_cpu_vector_context();
 
-       riscv_v_vstate_save(current, task_pt_regs(current));
+       riscv_v_vstate_save(&current->thread.vstate, task_pt_regs(current));
 
        riscv_v_enable();
 }
index 7b93bcbdf9fab25057f70d1377843bbdcab48479..e8515aa9d80bf82fd6ff2598664b9fe18a6b1de3 100644 (file)
@@ -101,7 +101,7 @@ static int riscv_vr_get(struct task_struct *target,
         */
        if (target == current) {
                get_cpu_vector_context();
-               riscv_v_vstate_save(current, task_pt_regs(current));
+               riscv_v_vstate_save(&current->thread.vstate, task_pt_regs(current));
                put_cpu_vector_context();
        }
 
index aca4a12c84162ccbfa09566cea2322386417500f..5d69f4db9e8f38012bd4f583353ccbb3ce520465 100644 (file)
@@ -87,7 +87,7 @@ static long save_v_state(struct pt_regs *regs, void __user **sc_vec)
        WARN_ON(unlikely(!IS_ALIGNED((unsigned long)datap, 16)));
 
        get_cpu_vector_context();
-       riscv_v_vstate_save(current, regs);
+       riscv_v_vstate_save(&current->thread.vstate, regs);
        put_cpu_vector_context();
 
        /* Copy everything of vstate but datap. */