OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: sbi: Only enable TM bit in scounteren
@ 2025-05-14  0:25 Atish Patra
  2025-05-14  0:35 ` Jessica Clarke
  0 siblings, 1 reply; 6+ messages in thread
From: Atish Patra @ 2025-05-14  0:25 UTC (permalink / raw)
  To: anup; +Cc: opensbi, Atish Patra

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.

Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
To: anup Patel <anup@brainfault.org>
Cc: opensbi@lists.infradead.org
---
 lib/sbi/sbi_hart.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index fc4925b57625..177f356b7b77 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.

---
base-commit: 316daaf1c299c29ac46e52145f65521f48ec63b5
change-id: 20250512-fix_scounteren-8b7b682bb864
--
Regards,
Atish patra


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-07-21 11:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-14  0:25 [PATCH] lib: sbi: Only enable TM bit in scounteren Atish Patra
2025-05-14  0:35 ` Jessica Clarke
2025-05-14  0:49   ` Samuel Holland
2025-05-14  0:56     ` Jessica Clarke
2025-05-14  7:34   ` Atish Patra
2025-07-21 10:53     ` Anup Patel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox