Skip to content

Commit 9366a12

Browse files
cyrilbur-tenstorrentgregkh
authored andcommitted
riscv: uaccess: Only restore the CSR_STATUS SUM bit
commit 265d6ab upstream. During switch to csrs will OR the value of the register into the corresponding csr. In this case we're only interested in restoring the SUM bit not the entire register. Signed-off-by: Cyril Bur <cyrilbur@tenstorrent.com> Link: https://lore.kernel.org/r/20250522160954.429333-1-cyrilbur@tenstorrent.com Co-developed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Fixes: 788aa64 ("riscv: save the SR_SUM status over switches") Link: https://lore.kernel.org/r/20250602121543.1544278-1-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@dabbelt.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3ff0a89 commit 9366a12

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

arch/riscv/include/asm/processor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct thread_struct {
103103
struct __riscv_d_ext_state fstate;
104104
unsigned long bad_cause;
105105
unsigned long envcfg;
106-
unsigned long status;
106+
unsigned long sum;
107107
u32 riscv_v_flags;
108108
u32 vstate_ctrl;
109109
struct __riscv_v_ext_state vstate;

arch/riscv/kernel/asm-offsets.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void asm_offsets(void)
3434
OFFSET(TASK_THREAD_S9, task_struct, thread.s[9]);
3535
OFFSET(TASK_THREAD_S10, task_struct, thread.s[10]);
3636
OFFSET(TASK_THREAD_S11, task_struct, thread.s[11]);
37-
OFFSET(TASK_THREAD_STATUS, task_struct, thread.status);
37+
OFFSET(TASK_THREAD_SUM, task_struct, thread.sum);
3838

3939
OFFSET(TASK_TI_CPU, task_struct, thread_info.cpu);
4040
OFFSET(TASK_TI_PREEMPT_COUNT, task_struct, thread_info.preempt_count);
@@ -347,8 +347,8 @@ void asm_offsets(void)
347347
offsetof(struct task_struct, thread.s[11])
348348
- offsetof(struct task_struct, thread.ra)
349349
);
350-
DEFINE(TASK_THREAD_STATUS_RA,
351-
offsetof(struct task_struct, thread.status)
350+
DEFINE(TASK_THREAD_SUM_RA,
351+
offsetof(struct task_struct, thread.sum)
352352
- offsetof(struct task_struct, thread.ra)
353353
);
354354

arch/riscv/kernel/entry.S

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,15 @@ SYM_FUNC_START(__switch_to)
399399
REG_S s11, TASK_THREAD_S11_RA(a3)
400400

401401
/* save the user space access flag */
402-
li s0, SR_SUM
403-
csrr s1, CSR_STATUS
404-
REG_S s1, TASK_THREAD_STATUS_RA(a3)
402+
csrr s0, CSR_STATUS
403+
REG_S s0, TASK_THREAD_SUM_RA(a3)
405404

406405
/* Save the kernel shadow call stack pointer */
407406
scs_save_current
408407
/* Restore context from next->thread */
409-
REG_L s0, TASK_THREAD_STATUS_RA(a4)
408+
REG_L s0, TASK_THREAD_SUM_RA(a4)
409+
li s1, SR_SUM
410+
and s0, s0, s1
410411
csrs CSR_STATUS, s0
411412
REG_L ra, TASK_THREAD_RA_RA(a4)
412413
REG_L sp, TASK_THREAD_SP_RA(a4)

0 commit comments

Comments
 (0)