All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juliet Mathis <julietmathis2004@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org,
	Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>,
	Alistair Francis <alistair.francis@wdc.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Weiwei Li <liwei1518@gmail.com>,
	Chao Liu <chao.liu@processmission.com>,
	Liu Zhiwei <zhiwei_liu@linux.alibaba.com>,
	Juliet Mathis <julietmathis2004@gmail.com>,
	Samarth Sarda <samarthsarda@utexas.edu>,
	Dana Coates <elladana.coates@gmail.com>
Subject: [PATCH] target/riscv: fix scountinhibit clearing non-S-mode mcountinhibit bits
Date: Tue,  1 Dec 2026 12:13:01 -0600	[thread overview]
Message-ID: <20261201181301.2133-1-julietmathis2004@gmail.com> (raw)

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



                 reply	other threads:[~2026-12-01 18:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201181301.2133-1-julietmathis2004@gmail.com \
    --to=julietmathis2004@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=chao.liu@processmission.com \
    --cc=daniel.barboza@oss.qualcomm.com \
    --cc=elladana.coates@gmail.com \
    --cc=liwei1518@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=samarthsarda@utexas.edu \
    --cc=zhiwei_liu@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.