* [PATCH] target/riscv: fix scountinhibit clearing non-S-mode mcountinhibit bits
@ 2026-12-01 18:13 Juliet Mathis
0 siblings, 0 replies; only message in thread
From: Juliet Mathis @ 2026-12-01 18:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Daniel Henrique Barboza, Alistair Francis,
Palmer Dabbelt, Weiwei Li, Chao Liu, Liu Zhiwei, Juliet Mathis,
Samarth Sarda, Dana Coates
According to the Smcdeleg specification, scountinhibit is a masked alias
of mcountinhibit. mcountinhibit includes bits for counters delegated
to S-mode and counters that are not. A write to scountinhibit should
not change the mcountinhibit bits of counters that are not delegated
to S-mode.
write_scountinhibit() calls write_mcountinhibit() with the intersection
of the value being written and the env->mcounteren, which clears the
mcountinhibit bits that are not delegated to S-mode.
Merge the bits that are not delegated with the bits that are delegated
from the value being written. This preserves the mcountinhibit bits
that are not delegated to S-mode.
Fixes: 6247dc2ef70b ("target/riscv: Add counter delegation/configuration support")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4831
Signed-off-by: Samarth Sarda <samarthsarda@utexas.edu>
Signed-off-by: Dana Coates <elladana.coates@gmail.com>
Signed-off-by: Juliet Mathis <julietmathis2004@gmail.com>
---
target/riscv/tcg/csr.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/target/riscv/tcg/csr.c b/target/riscv/tcg/csr.c
index af444e3e6f..da2bd767c8 100644
--- a/target/riscv/tcg/csr.c
+++ b/target/riscv/tcg/csr.c
@@ -3164,7 +3164,10 @@ static RISCVException read_scountinhibit(CPURISCVState *env, int csrno,
static RISCVException write_scountinhibit(CPURISCVState *env, int csrno,
target_ulong val, uintptr_t ra)
{
- return write_mcountinhibit(env, csrno, val & env->mcounteren, ra);
+ target_ulong inhibit = (env->mcountinhibit & ~env->mcounteren) |
+ (val & env->mcounteren);
+
+ return write_mcountinhibit(env, csrno, inhibit, ra);
}
static RISCVException read_mcounteren(CPURISCVState *env, int csrno,
--
2.56.1.windows.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-01 18:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 18:13 [PATCH] target/riscv: fix scountinhibit clearing non-S-mode mcountinhibit bits Juliet Mathis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.