Skip to content

riscv: gate counter CSRs on mcounteren at every priv version - #2392

Open
carlosqwqqwq wants to merge 1 commit into
unicorn-engine:masterfrom
carlosqwqqwq:fix/riscv-counter-csr-mcounteren
Open

riscv: gate counter CSRs on mcounteren at every priv version#2392
carlosqwqqwq wants to merge 1 commit into
unicorn-engine:masterfrom
carlosqwqqwq:fix/riscv-counter-csr-mcounteren

Conversation

@carlosqwqqwq

@carlosqwqqwq carlosqwqqwq commented Aug 12, 2026

Copy link
Copy Markdown

riscv: gate counter CSRs on mcounteren at every priv version

Fixes #2387

Problem

The ctr predicate returns success for every counter CSR when priv_ver > 1.09, so U/S-mode hpmcounter* (and cycle/time/instret) reads retire even with mcounteren=0. The enabling comment confuses mcounteren (readability) with mcountinhibit (incrementing).

Change

qemu/target/riscv/csr.c ctr(): remove the priv_ver > PRIV_VERSION_1_09_1 early-success branch so the mcounteren/scounteren checks apply at every priv version, mirroring upstream QEMU master. The proposed change is source-only and contains no test-framework or repository-local changes.

Regression scope

Verify that M-mode counter access is unaffected, S/U-mode accesses are gated by mcounteren/scounteren, and existing counter and CSR tests remain unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RISC-V: U-mode hpmcounter* reads retire even with mcounteren=0

1 participant