mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 15:31:22 +01:00
lib: sbi: Only enable TM bit in scounteren
The S-mode should disable Cycle and instruction counter for user space to avoid side channel attacks. The Linux kernel already does this so that any random user space code shouldn't be able to monitor cycle/instruction without higher privilege mode involvement. Remove the CY/IR bits in scountern in OpenSBI. Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Atish Patra <atishp@rivosinc.com> Link: https://lore.kernel.org/r/20250513-fix_scounteren-v1-1-01018e0c0b0a@rivosinc.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
@@ -49,10 +49,10 @@ static void mstatus_init(struct sbi_scratch *scratch)
|
|||||||
|
|
||||||
csr_write(CSR_MSTATUS, mstatus_val);
|
csr_write(CSR_MSTATUS, mstatus_val);
|
||||||
|
|
||||||
/* Disable user mode usage of all perf counters except default ones (CY, TM, IR) */
|
/* Disable user mode usage of all perf counters except TM */
|
||||||
if (misa_extension('S') &&
|
if (misa_extension('S') &&
|
||||||
sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
|
sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
|
||||||
csr_write(CSR_SCOUNTEREN, 7);
|
csr_write(CSR_SCOUNTEREN, 0x02);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OpenSBI doesn't use any PMU counters in M-mode.
|
* OpenSBI doesn't use any PMU counters in M-mode.
|
||||||
|
Reference in New Issue
Block a user