summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtish Patra <[email protected]>2025-05-13 17:25:15 -0700
committerAnup Patel <[email protected]>2025-07-21 16:33:03 +0530
commit5b305e30a55d93d507006dd11685bdeb7e7207e8 (patch)
tree75d41afc273af88b80659378ca93dbc2f81bf01d
parent663b05a5f745f6b1360f073587bb57fe9af6a40a (diff)
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 <[email protected]> Signed-off-by: Atish Patra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
-rw-r--r--lib/sbi/sbi_hart.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index 054a405c..6a2d7d6f 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -49,10 +49,10 @@ static void mstatus_init(struct sbi_scratch *scratch)
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') &&
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.