From: Vladimir Isaev <vvisaev@gmail.com>
To: qemu-devel@nongnu.org
Cc: palmer@dabbelt.com, alistair.francis@wdc.com,
liwei1518@gmail.com, daniel.barboza@oss.qualcomm.com,
zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com,
qemu-riscv@nongnu.org, joel@jms.id.au, npiggin@gmail.com,
Vladimir Isaev <vvisaev@gmail.com>
Subject: [PATCH v2 1/2] riscv: csr: do not drop C bit on misa write
Date: Mon, 17 Aug 2026 18:06:37 +0300 [thread overview]
Message-ID: <20260817150653.40357-2-vvisaev@gmail.com> (raw)
In-Reply-To: <20260817150653.40357-1-vvisaev@gmail.com>
According to spec:
> Writing misa may increase IALIGN, e.g., by disabling the "C" extension.
> If an instruction that would write misa increases IALIGN, and the
> subsequent instruction’s address is not IALIGN-bit aligned, the
> write to misa is suppressed, leaving misa unchanged.
So attempt to disable C extension if next instruction is not aligned should not
change the misa.
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Vladimir Isaev <vvisaev@gmail.com>
---
target/riscv/tcg/csr.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/target/riscv/tcg/csr.c b/target/riscv/tcg/csr.c
index 36f2004bc5..dbfb3381ef 100644
--- a/target/riscv/tcg/csr.c
+++ b/target/riscv/tcg/csr.c
@@ -2182,9 +2182,13 @@ static RISCVException write_misa(CPURISCVState *env, int csrno,
/* Mask extensions that are not supported by this hart */
val &= env->misa_ext_mask;
- /* Suppress 'C' if next instruction is not aligned. */
- if ((val & RVC) && (get_next_pc(env, ra) & 3) != 0) {
- val &= ~RVC;
+ /* drop write if RVC is cleared and next instruction is not aligned */
+ if ((env->misa_ext & RVC) && !(val & RVC) &&
+ (get_next_pc(env, ra) & 3) != 0) {
+ qemu_log_mask(LOG_GUEST_ERROR, "Unable to write MISA ext value "
+ "0x%x, MISA.C disable failed\n", env->misa_ext);
+
+ return RISCV_EXCP_NONE;
}
/* Disable RVG if any of its dependencies are disabled */
--
2.55.0
next prev parent reply other threads:[~2026-08-17 15:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 15:06 [PATCH v2 0/2] Fix alignment check for misa write Vladimir Isaev
2026-08-17 15:06 ` Vladimir Isaev [this message]
2026-08-17 15:06 ` [PATCH v2 2/2] tests/tcg/riscv64: add misa write test Vladimir Isaev
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=20260817150653.40357-2-vvisaev@gmail.com \
--to=vvisaev@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=chao.liu@processmission.com \
--cc=daniel.barboza@oss.qualcomm.com \
--cc=joel@jms.id.au \
--cc=liwei1518@gmail.com \
--cc=npiggin@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--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.