lib: sbi_pmu: Fix race on pmu_ctr_write_hw

On platforms where a bit of mcountinhibit cannot be set to 1,
and when on rv32, pmu_ctr_write_hw() was given value whose lower
bits were close to 2^32, the write could miss the lower bit overflow.

Signed-off-by: Jakub Janeczko <kuba@ev1.pl>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20261024195739.585621-1-kuba@ev1.pl
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Jakub Janeczko authored and Anup Patel committed 2026-10-25 13:42:21 +05:30
1 parent 9f37e25f80
commit 16fa280b69
1 file changed
+1 -1
+1 -1
View File
@@ -393,8 +393,8 @@ static void pmu_ctr_write_hw(uint32_t cidx, uint64_t ival)
{
#if __riscv_xlen == 32
csr_write_num(CSR_MCYCLE + cidx, 0);
csr_write_num(CSR_MCYCLE + cidx, ival & 0xFFFFFFFF);
csr_write_num(CSR_MCYCLEH + cidx, ival >> BITS_PER_LONG);
csr_write_num(CSR_MCYCLE + cidx, ival & 0xFFFFFFFF);
#else
csr_write_num(CSR_MCYCLE + cidx, ival);
#endif