OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] lib: sbi_hart: Retrun zero lenght of mhpmcounter when probing failed
@ 2026-09-10 18:20 Evgenii Prokopiev
  0 siblings, 0 replies; only message in thread
From: Evgenii Prokopiev @ 2026-09-10 18:20 UTC (permalink / raw)
  To: opensbi; +Cc: Evgenii Prokopiev

If writing access is not allowed, it will raise a trap, but we increase
the number of allowed bits to 32 in this approach, which isn't right.
There must be a write of 0.

Move the operation of increasing allowed bits into the 'if' condition.

Signed-off-by: Evgenii Prokopiev <eestelle0626@gmail.com>
---
 lib/sbi/sbi_hart.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index bee88557..3a9b6c8f 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -450,16 +450,18 @@ static int hart_mhpm_get_allowed_bits(void)
 		val = csr_read_allowed(CSR_MHPMCOUNTER3, &trap);
 		if (trap.cause)
 			return 0;
+
+		num_bits = sbi_fls(val) + 1;
 	}
-	num_bits = sbi_fls(val) + 1;
 #if __riscv_xlen == 32
 	csr_write_allowed(CSR_MHPMCOUNTER3H, &trap, val);
 	if (!trap.cause) {
 		val = csr_read_allowed(CSR_MHPMCOUNTER3H, &trap);
 		if (trap.cause)
 			return num_bits;
+
+		num_bits += sbi_fls(val) + 1;
 	}
-	num_bits += sbi_fls(val) + 1;
 
 #endif
 
-- 
2.50.1 (Apple Git-155)


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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-10 18:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-10 18:20 [RFC PATCH] lib: sbi_hart: Retrun zero lenght of mhpmcounter when probing failed Evgenii Prokopiev

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