From: wangyang <wangyang25@otcaix.iscas.ac.cn>
To: qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, Palmer Dabbelt <palmer@dabbelt.com>,
Alistair Francis <alistair.francis@wdc.com>,
Weiwei Li <liweiwei@iscas.ac.cn>,
Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>,
Liu Zhiwei <zhiwei_liu@c-sky.com>
Subject: [PATCH] target/riscv: gate envcfg CBO fields on extensions
Date: Thu, 15 Oct 2026 08:05:51 +0000 [thread overview]
Message-ID: <6AD08960.0F1C24.05843@cstnet.cn> (raw)
The envcfg CBO fields are provided by Zicbom and Zicboz. Keep them
read-only zero when the corresponding extension is absent in all three
envcfg CSRs.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4225
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: wangyang <wangyang25@otcaix.iscas.ac.cn>
---
target/riscv/tcg/csr.c | 37 +++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/target/riscv/tcg/csr.c b/target/riscv/tcg/csr.c
index 061bc9d..96c513b 100644
--- a/target/riscv/tcg/csr.c
+++ b/target/riscv/tcg/csr.c
@@ -3224,10 +3224,19 @@ static RISCVException write_menvcfg(CPURISCVState *env, int csrno,
target_ulong val, uintptr_t ra)
{
const RISCVCPUConfig *cfg = riscv_cpu_cfg(env);
- uint64_t mask = MENVCFG_FIOM | MENVCFG_CBIE | MENVCFG_CBCFE |
- MENVCFG_CBZE;
+ uint64_t mask = MENVCFG_FIOM;
bool stce_changed = false;
+ /* CBIE/CBCFE are read-only zero when Zicbom is not implemented. */
+ if (cfg->ext_zicbom) {
+ mask |= MENVCFG_CBIE | MENVCFG_CBCFE;
+ }
+
+ /* CBZE is read-only zero when Zicboz is not implemented. */
+ if (cfg->ext_zicboz) {
+ mask |= MENVCFG_CBZE;
+ }
+
/*
* menvcfg.LPE (Zicfilp) and menvcfg.SSE (Zicfiss) reside in the low
* 32 bits and are defined for both RV32 and RV64, so they must be
@@ -3328,8 +3337,18 @@ static RISCVException read_senvcfg(CPURISCVState *env, int csrno,
static RISCVException write_senvcfg(CPURISCVState *env, int csrno,
target_ulong val, uintptr_t ra)
{
- uint64_t mask = SENVCFG_FIOM | SENVCFG_CBIE | SENVCFG_CBCFE | SENVCFG_CBZE;
+ uint64_t mask = SENVCFG_FIOM;
RISCVException ret;
+
+ /* CBIE/CBCFE are read-only zero when Zicbom is not implemented. */
+ if (env_archcpu(env)->cfg.ext_zicbom) {
+ mask |= SENVCFG_CBIE | SENVCFG_CBCFE;
+ }
+
+ /* CBZE is read-only zero when Zicboz is not implemented. */
+ if (env_archcpu(env)->cfg.ext_zicboz) {
+ mask |= SENVCFG_CBZE;
+ }
/* Update PMM field only if the value is valid according to Zjpm v1.0 */
if (env_archcpu(env)->cfg.ext_ssnpm &&
riscv_cpu_mxl(env) == MXL_RV64 &&
@@ -3386,10 +3405,20 @@ static RISCVException write_henvcfg(CPURISCVState *env, int csrno,
target_ulong val, uintptr_t ra)
{
const RISCVCPUConfig *cfg = riscv_cpu_cfg(env);
- uint64_t mask = HENVCFG_FIOM | HENVCFG_CBIE | HENVCFG_CBCFE | HENVCFG_CBZE;
+ uint64_t mask = HENVCFG_FIOM;
RISCVException ret;
bool stce_changed = false;
+ /* CBIE/CBCFE are read-only zero when Zicbom is not implemented. */
+ if (cfg->ext_zicbom) {
+ mask |= HENVCFG_CBIE | HENVCFG_CBCFE;
+ }
+
+ /* CBZE is read-only zero when Zicboz is not implemented. */
+ if (cfg->ext_zicboz) {
+ mask |= HENVCFG_CBZE;
+ }
+
ret = smstateen_acc_ok(env, 0, SMSTATEEN0_HSENVCFG);
if (ret != RISCV_EXCP_NONE) {
return ret;
--
2.43.0
next reply other threads:[~2026-10-15 8:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 8:05 wangyang [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-10-15 7:53 [PATCH] target/riscv: gate envcfg CBO fields on extensions wangyang
2026-10-15 3:11 wangyang
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=6AD08960.0F1C24.05843@cstnet.cn \
--to=wangyang25@otcaix.iscas.ac.cn \
--cc=alistair.francis@wdc.com \
--cc=daniel.barboza@oss.qualcomm.com \
--cc=liweiwei@iscas.ac.cn \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=zhiwei_liu@c-sky.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.