@@ -103,7 +103,7 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
#define switchcase_hpm(__uref, __mref, __csr) \
case __csr: \
- if (sbi_hart_mhpm_mask(scratch) & (1 << (__csr - __uref)))\
+ if (sbi_hart_mhpm_mask(scratch) & BIT(__csr - __uref)) \
return SBI_ENOTSUPP; \
if (!hpm_allowed(__csr - __uref, prev_mode, virt)) \
return SBI_ENOTSUPP; \
@@ -512,7 +512,7 @@ static int hart_detect_features(struct sbi_scratch *scratch, bool cold_boot)
if (!trap.cause) { \
csr_write_allowed(__csr, &trap, 1UL); \
if (!trap.cause && csr_swap(__csr, oldval) == 1UL) { \
- (hfeatures->__mask) |= 1 << (__csr - CSR_MCYCLE); \
+ (hfeatures->__mask) |= BIT(__csr - CSR_MCYCLE); \
} \
}
The HPM feature detector and CSR emulator build mhpm_mask bits with a plain signed 1. Both macro families expand through counter 31, so the last expansion evaluates 1 << 31 and shifts a signed int into its sign bit. Use BIT() at both sites. The mask is unsigned and bit 31 is part of the represented HPM counter set. Fixes: c744ed77b18c ("lib: sbi_pmu: Enable noncontigous hpm event and counters") Fixes: ee1f83ca848d ("lib: sbi_pmu: remove mhpm_count field in hart feature") Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn> --- lib/sbi/sbi_emulate_csr.c | 2 +- lib/sbi/sbi_hart.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) base-commit: 4e79fd7de59f1b2899092c1a84ce68c8ebc68f93