Skip to content

Commit d6c78f1

Browse files
AndybnACTpalmer-dabbelt
authored andcommitted
riscv: vector: do not pass task_struct into riscv_v_vstate_{save,restore}()
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 <[email protected]> Acked-by: Conor Dooley <[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 a93fdaf commit d6c78f1

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

arch/riscv/include/asm/entry-common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
1616
* We are already called with irq disabled, so go without
1717
* keeping track of riscv_v_flags.
1818
*/
19-
riscv_v_vstate_restore(current, regs);
19+
riscv_v_vstate_restore(&current->thread.vstate, regs);
2020
}
2121
}
2222

arch/riscv/include/asm/vector.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,19 @@ static inline void riscv_v_vstate_discard(struct pt_regs *regs)
171171
__riscv_v_vstate_dirty(regs);
172172
}
173173

174-
static inline void riscv_v_vstate_save(struct task_struct *task,
174+
static inline void riscv_v_vstate_save(struct __riscv_v_ext_state *vstate,
175175
struct pt_regs *regs)
176176
{
177177
if ((regs->status & SR_VS) == SR_VS_DIRTY) {
178-
struct __riscv_v_ext_state *vstate = &task->thread.vstate;
179-
180178
__riscv_v_vstate_save(vstate, vstate->datap);
181179
__riscv_v_vstate_clean(regs);
182180
}
183181
}
184182

185-
static inline void riscv_v_vstate_restore(struct task_struct *task,
183+
static inline void riscv_v_vstate_restore(struct __riscv_v_ext_state *vstate,
186184
struct pt_regs *regs)
187185
{
188186
if ((regs->status & SR_VS) != SR_VS_OFF) {
189-
struct __riscv_v_ext_state *vstate = &task->thread.vstate;
190-
191187
__riscv_v_vstate_restore(vstate, vstate->datap);
192188
__riscv_v_vstate_clean(regs);
193189
}
@@ -208,7 +204,7 @@ static inline void __switch_to_vector(struct task_struct *prev,
208204
struct pt_regs *regs;
209205

210206
regs = task_pt_regs(prev);
211-
riscv_v_vstate_save(prev, regs);
207+
riscv_v_vstate_save(&prev->thread.vstate, regs);
212208
riscv_v_vstate_set_restore(next, task_pt_regs(next));
213209
}
214210

@@ -226,8 +222,8 @@ static inline bool riscv_v_vstate_query(struct pt_regs *regs) { return false; }
226222
static inline bool riscv_v_vstate_ctrl_user_allowed(void) { return false; }
227223
#define riscv_v_vsize (0)
228224
#define riscv_v_vstate_discard(regs) do {} while (0)
229-
#define riscv_v_vstate_save(task, regs) do {} while (0)
230-
#define riscv_v_vstate_restore(task, regs) do {} while (0)
225+
#define riscv_v_vstate_save(vstate, regs) do {} while (0)
226+
#define riscv_v_vstate_restore(vstate, regs) do {} while (0)
231227
#define __switch_to_vector(__prev, __next) do {} while (0)
232228
#define riscv_v_vstate_off(regs) do {} while (0)
233229
#define riscv_v_vstate_on(regs) do {} while (0)

arch/riscv/kernel/kernel_mode_vector.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void kernel_vector_begin(void)
9797

9898
get_cpu_vector_context();
9999

100-
riscv_v_vstate_save(current, task_pt_regs(current));
100+
riscv_v_vstate_save(&current->thread.vstate, task_pt_regs(current));
101101

102102
riscv_v_enable();
103103
}

arch/riscv/kernel/ptrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int riscv_vr_get(struct task_struct *target,
101101
*/
102102
if (target == current) {
103103
get_cpu_vector_context();
104-
riscv_v_vstate_save(current, task_pt_regs(current));
104+
riscv_v_vstate_save(&current->thread.vstate, task_pt_regs(current));
105105
put_cpu_vector_context();
106106
}
107107

arch/riscv/kernel/signal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static long save_v_state(struct pt_regs *regs, void __user **sc_vec)
8787
WARN_ON(unlikely(!IS_ALIGNED((unsigned long)datap, 16)));
8888

8989
get_cpu_vector_context();
90-
riscv_v_vstate_save(current, regs);
90+
riscv_v_vstate_save(&current->thread.vstate, regs);
9191
put_cpu_vector_context();
9292

9393
/* Copy everything of vstate but datap. */

0 commit comments

Comments
 (0)