Skip to content

Commit 05ab803

Browse files
SiFiveHollandpalmer-dabbelt
authored andcommitted
riscv: Save/restore envcfg CSR during CPU suspend
The value of the [ms]envcfg CSR is lost when entering a nonretentive idle state, so the CSR must be rewritten when resuming the CPU. Cc: <stable@vger.kernel.org> # v6.7+ Fixes: 43c16d5 ("RISC-V: Enable cbo.zero in usermode") Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Link: https://lore.kernel.org/r/20240228065559.3434837-4-samuel.holland@sifive.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 4774848 commit 05ab803

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

arch/riscv/include/asm/suspend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct suspend_context {
1414
struct pt_regs regs;
1515
/* Saved and restored by high-level functions */
1616
unsigned long scratch;
17+
unsigned long envcfg;
1718
unsigned long tvec;
1819
unsigned long ie;
1920
#ifdef CONFIG_MMU

arch/riscv/kernel/suspend.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
void suspend_save_csrs(struct suspend_context *context)
1616
{
1717
context->scratch = csr_read(CSR_SCRATCH);
18+
if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG))
19+
context->envcfg = csr_read(CSR_ENVCFG);
1820
context->tvec = csr_read(CSR_TVEC);
1921
context->ie = csr_read(CSR_IE);
2022

@@ -36,6 +38,8 @@ void suspend_save_csrs(struct suspend_context *context)
3638
void suspend_restore_csrs(struct suspend_context *context)
3739
{
3840
csr_write(CSR_SCRATCH, context->scratch);
41+
if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_XLINUXENVCFG))
42+
csr_write(CSR_ENVCFG, context->envcfg);
3943
csr_write(CSR_TVEC, context->tvec);
4044
csr_write(CSR_IE, context->ie);
4145

0 commit comments

Comments
 (0)