* [PATCH v3 0/6] Fix Zjpm implementation
@ 2025-12-11 16:38 frank.chang
2025-12-11 16:38 ` [PATCH v3 1/6] target/riscv: fix address masking frank.chang
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: frank.chang @ 2025-12-11 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, open list:RISC-V TCG CPUs,
Frank Chang
From: Frank Chang <frank.chang@sifive.com>
The current Zjpm implementation has the following issues:
1. The address is shifted before obtaining the correct PMLEN value.
2. riscv_pm_get_pmm() does not handle effective privilege mode correctly.
3. mstatus.MPRV does not affect virtual-machine load/store instructions.
4. Sign extension for virtual-machine load/store instructions (HLV.* and
HSV.*) must be performed when vsatp.MODE != Bare.
This patchset fixes the above issues and also renames
riscv_pm_get_virt_pmm() to riscv_pm_get_vm_ldst_pmm(), as the helper
is only used when checking the PMM configuration for virtual-machine
load/store instructions, rather than for VS/VU modes.
Changelog:
v3:
* Move riscv_cpu_eff_priv() to the header file and declare it as a
static inline function.
* Fix the MXR check bugs pointed out by Radim Krčmář.
v2:
* Check effective privilege mode in riscv_pm_get_pmm().
* Fix pointer masking for virtual-machine load/store instructions
(HLV.* and HSV.*).
* Rename riscv_pm_get_virt_pmm() to riscv_pm_get_vm_ldst_pmm().
Frank Chang (5):
target/riscv: Add a helper to return the current effective priv mode
target/riscv: Fix pointer masking PMM field selection logic
target/riscv: Fix pointer masking for virtual-machine load/store insns
target/riscv: Rename riscv_pm_get_virt_pmm() to
riscv_pm_get_vm_ldst_pmm()
target/riscv: Fix pointer masking translation mode check bug
Yong-Xuan Wang (1):
target/riscv: fix address masking
target/riscv/cpu.h | 41 +++++++++++++-
target/riscv/cpu_helper.c | 110 +++++++++++++++++++++++++++----------
target/riscv/internals.h | 8 +--
target/riscv/tcg/tcg-cpu.c | 4 +-
4 files changed, 124 insertions(+), 39 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 1/6] target/riscv: fix address masking
2025-12-11 16:38 [PATCH v3 0/6] Fix Zjpm implementation frank.chang
@ 2025-12-11 16:38 ` frank.chang
2025-12-11 16:38 ` [PATCH v3 2/6] target/riscv: Add a helper to return the current effective priv mode frank.chang
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: frank.chang @ 2025-12-11 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, open list:RISC-V TCG CPUs,
Yong-Xuan Wang
From: Yong-Xuan Wang <yongxuan.wang@sifive.com>
The pmlen should get the corresponding value before shifting address.
Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
target/riscv/internals.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/riscv/internals.h b/target/riscv/internals.h
index 172296f12e2..9b3f01144d2 100644
--- a/target/riscv/internals.h
+++ b/target/riscv/internals.h
@@ -203,8 +203,8 @@ static inline target_ulong adjust_addr_body(CPURISCVState *env,
if (!is_virt_addr) {
signext = riscv_cpu_virt_mem_enabled(env);
}
- addr = addr << pmlen;
pmlen = riscv_pm_get_pmlen(pmm);
+ addr = addr << pmlen;
/* sign/zero extend masked address by N-1 bit */
if (signext) {
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/6] target/riscv: Add a helper to return the current effective priv mode
2025-12-11 16:38 [PATCH v3 0/6] Fix Zjpm implementation frank.chang
2025-12-11 16:38 ` [PATCH v3 1/6] target/riscv: fix address masking frank.chang
@ 2025-12-11 16:38 ` frank.chang
2025-12-11 16:38 ` [PATCH v3 3/6] target/riscv: Fix pointer masking PMM field selection logic frank.chang
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: frank.chang @ 2025-12-11 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, open list:RISC-V TCG CPUs,
Frank Chang
From: Frank Chang <frank.chang@sifive.com>
This helper returns the current effective privilege mode.
Signed-off-by: Frank Chang <frank.chang@sifive.com>
---
target/riscv/cpu.h | 37 +++++++++++++++++++++++++++++++++++++
target/riscv/cpu_helper.c | 15 +++++----------
2 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 8899bf7667a..f59052fe7dc 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -799,6 +799,43 @@ static inline RISCVMXL riscv_cpu_sxl(CPURISCVState *env)
}
#endif
+/*
+ * Returns the current effective privilege mode.
+ *
+ * @env: CPURISCVState
+ * @priv: The returned effective privilege mode.
+ * @virt: The returned effective virtualization mode.
+ *
+ * Returns true if the effective privilege mode is modified.
+ */
+static inline QEMU_ALWAYS_INLINE
+bool riscv_cpu_eff_priv(CPURISCVState *env, int *priv, bool *virt)
+{
+ int mode = env->priv;
+ bool virt_enabled = false;
+ bool mode_modified = false;
+
+#ifndef CONFIG_USER_ONLY
+ if (mode == PRV_M && get_field(env->mstatus, MSTATUS_MPRV)) {
+ mode = get_field(env->mstatus, MSTATUS_MPP);
+ virt_enabled = get_field(env->mstatus, MSTATUS_MPV) && (mode != PRV_M);
+ mode_modified = true;
+ } else {
+ virt_enabled = env->virt_enabled;
+ }
+#endif
+
+ if (priv) {
+ *priv = mode;
+ }
+
+ if (virt) {
+ *virt = virt_enabled;
+ }
+
+ return mode_modified;
+}
+
static inline bool riscv_cpu_allow_16bit_insn(const RISCVCPUConfig *cfg,
target_long priv_ver,
uint32_t misa_ext)
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index dd6c861a90e..da6e2d8fe3a 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -45,19 +45,14 @@ int riscv_env_mmu_index(CPURISCVState *env, bool ifetch)
#else
bool virt = env->virt_enabled;
int mode = env->priv;
+ bool mode_modified = false;
/* All priv -> mmu_idx mapping are here */
if (!ifetch) {
- uint64_t status = env->mstatus;
-
- if (mode == PRV_M && get_field(status, MSTATUS_MPRV)) {
- mode = get_field(env->mstatus, MSTATUS_MPP);
- virt = get_field(env->mstatus, MSTATUS_MPV) &&
- (mode != PRV_M);
- if (virt) {
- status = env->vsstatus;
- }
- }
+ mode_modified = riscv_cpu_eff_priv(env, &mode, &virt);
+ uint64_t status = (mode_modified && virt) ? env->vsstatus :
+ env->mstatus;
+
if (mode == PRV_S && get_field(status, MSTATUS_SUM)) {
mode = MMUIdx_S_SUM;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 3/6] target/riscv: Fix pointer masking PMM field selection logic
2025-12-11 16:38 [PATCH v3 0/6] Fix Zjpm implementation frank.chang
2025-12-11 16:38 ` [PATCH v3 1/6] target/riscv: fix address masking frank.chang
2025-12-11 16:38 ` [PATCH v3 2/6] target/riscv: Add a helper to return the current effective priv mode frank.chang
@ 2025-12-11 16:38 ` frank.chang
2025-12-11 16:38 ` [PATCH v3 4/6] target/riscv: Fix pointer masking for virtual-machine load/store insns frank.chang
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: frank.chang @ 2025-12-11 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, open list:RISC-V TCG CPUs,
Frank Chang
From: Frank Chang <frank.chang@sifive.com>
mstatus.MPV only records the previous virtualization state, and does not
affect pointer masking according to the Zjpm specification.
This patch rewrites riscv_pm_get_pmm() to follow the architectural
definition of Smmpm, Smnpm, and Ssnpm.
The resulting PMM selection logic for each mode is summarized below:
* mstatus.MXR = 1: pointer masking disabled
* Smmpm + Smnpm + Ssnpm:
M-mode: mseccfg.PMM
S-mode: menvcfg.PMM
U-mode: senvcfg.PMM
VS-mode: henvcfg.PMM
VU-mode: senvcfg.PMM
* Smmpm + Smnpm (RVS implemented):
M-mode: mseccfg.PMM
S-mode: menvcfg.PMM
U/VS/VU: disabled (Ssnpm not present)
* Smmpm + Smnpm (RVS not implemented):
M-mode: mseccfg.PMM
U-mode: menvcfg.PMM
S/VS/VU: disabled (no S-mode)
* Smmpm only:
M-mode: mseccfg.PMM
Other existing modes: pointer masking disabled
Signed-off-by: Frank Chang <frank.chang@sifive.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
target/riscv/cpu_helper.c | 51 +++++++++++++++++++++++++++++++++------
1 file changed, 44 insertions(+), 7 deletions(-)
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index da6e2d8fe3a..4347153d794 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -131,13 +131,47 @@ bool riscv_env_smode_dbltrp_enabled(CPURISCVState *env, bool virt)
#endif
}
+/*
+ * Returns the effective PMM field.
+ *
+ * @env: CPURISCVState
+ *
+ * The PMM field selection logic for each effective privilege mode
+ * is as follows:
+ *
+ * - mstatus.MXR = 1: disabled
+ *
+ * - Smmpm + Smnpm + Ssnpm:
+ * M-mode: mseccfg.PMM
+ * S-mode: menvcfg.PMM
+ * U-mode: senvcfg.PMM
+ * VS-mode: henvcfg.PMM
+ * VU-mode: senvcfg.PMM
+ *
+ * - Smmpm + Smnpm (RVS implemented):
+ * M-mode: mseccfg.PMM
+ * S-mode: menvcfg.PMM
+ * U/VS/VU: disabled (Ssnpm not present)
+ *
+ * - Smmpm + Smnpm (RVS not implemented):
+ * M-mode: mseccfg.PMM
+ * U-mode: menvcfg.PMM
+ * S/VS/VU: disabled (no S-mode)
+ *
+ * - Smmpm only:
+ * M-mode: mseccfg.PMM
+ * Other existing modes: disabled
+ */
RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env)
{
#ifndef CONFIG_USER_ONLY
- int priv_mode = cpu_address_mode(env);
+ int priv_mode;
+ bool virt;
+
+ riscv_cpu_eff_priv(env, &priv_mode, &virt);
- if (get_field(env->mstatus, MSTATUS_MPRV) &&
- get_field(env->mstatus, MSTATUS_MXR)) {
+ if ((priv_mode != PRV_M && get_field(env->mstatus, MSTATUS_MXR)) ||
+ (virt && get_field(env->vsstatus, MSTATUS_MXR))) {
return PMM_FIELD_DISABLED;
}
@@ -149,12 +183,14 @@ RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env)
}
break;
case PRV_S:
- if (riscv_cpu_cfg(env)->ext_smnpm) {
- if (get_field(env->mstatus, MSTATUS_MPV)) {
- return get_field(env->henvcfg, HENVCFG_PMM);
- } else {
+ if (!virt) {
+ if (riscv_cpu_cfg(env)->ext_smnpm) {
return get_field(env->menvcfg, MENVCFG_PMM);
}
+ } else {
+ if (riscv_cpu_cfg(env)->ext_ssnpm) {
+ return get_field(env->henvcfg, HENVCFG_PMM);
+ }
}
break;
case PRV_U:
@@ -171,6 +207,7 @@ RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env)
default:
g_assert_not_reached();
}
+
return PMM_FIELD_DISABLED;
#else
return PMM_FIELD_DISABLED;
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 4/6] target/riscv: Fix pointer masking for virtual-machine load/store insns
2025-12-11 16:38 [PATCH v3 0/6] Fix Zjpm implementation frank.chang
` (2 preceding siblings ...)
2025-12-11 16:38 ` [PATCH v3 3/6] target/riscv: Fix pointer masking PMM field selection logic frank.chang
@ 2025-12-11 16:38 ` frank.chang
2025-12-11 16:38 ` [PATCH v3 5/6] target/riscv: Rename riscv_pm_get_virt_pmm() to riscv_pm_get_vm_ldst_pmm() frank.chang
2025-12-11 16:38 ` [PATCH v3 6/6] target/riscv: Fix pointer masking translation mode check bug frank.chang
5 siblings, 0 replies; 7+ messages in thread
From: frank.chang @ 2025-12-11 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, open list:RISC-V TCG CPUs,
Frank Chang
From: Frank Chang <frank.chang@sifive.com>
The effective privilege of explicit memory accesses made by
virtual-machine load/store instructions (HLV.* and HSV.*) is controlled
by hstatus.SPVP. mstatus.MPRV does not affect these virtual-machine
load/store instructions.
Signed-off-by: Frank Chang <frank.chang@sifive.com>
---
target/riscv/cpu_helper.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index 4347153d794..8f2a7234184 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -217,16 +217,23 @@ RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env)
RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env)
{
#ifndef CONFIG_USER_ONLY
- int priv_mode = cpu_address_mode(env);
+ int priv_mode;
+
+ if (!riscv_cpu_cfg(env)->ext_ssnpm ||
+ get_field(env->mstatus, MSTATUS_MXR) ||
+ get_field(env->vsstatus, MSTATUS_MXR)) {
+ return PMM_FIELD_DISABLED;
+ }
+
+ priv_mode = get_field(env->hstatus, HSTATUS_SPVP);
- if (priv_mode == PRV_U) {
- return get_field(env->hstatus, HSTATUS_HUPMM);
+ if (priv_mode == PRV_S) {
+ /* Effective privilege mode: VS */
+ return get_field(env->henvcfg, HENVCFG_PMM);
} else {
- if (get_field(env->hstatus, HSTATUS_SPVP)) {
- return get_field(env->henvcfg, HENVCFG_PMM);
- } else {
- return get_field(env->senvcfg, SENVCFG_PMM);
- }
+ /* Effective privilege mode: VU */
+ return (env->priv == PRV_U) ? get_field(env->hstatus, HSTATUS_HUPMM) :
+ get_field(env->senvcfg, SENVCFG_PMM);
}
#else
return PMM_FIELD_DISABLED;
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 5/6] target/riscv: Rename riscv_pm_get_virt_pmm() to riscv_pm_get_vm_ldst_pmm()
2025-12-11 16:38 [PATCH v3 0/6] Fix Zjpm implementation frank.chang
` (3 preceding siblings ...)
2025-12-11 16:38 ` [PATCH v3 4/6] target/riscv: Fix pointer masking for virtual-machine load/store insns frank.chang
@ 2025-12-11 16:38 ` frank.chang
2025-12-11 16:38 ` [PATCH v3 6/6] target/riscv: Fix pointer masking translation mode check bug frank.chang
5 siblings, 0 replies; 7+ messages in thread
From: frank.chang @ 2025-12-11 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, open list:RISC-V TCG CPUs,
Frank Chang
From: Frank Chang <frank.chang@sifive.com>
Rename riscv_pm_get_virt_pmm() to riscv_pm_get_vm_ldst_pmm() to better
reflect its actual usage. This function is used when checking the PMM
field for virtual-machine load/store instructions (HLV.* and HSV.*),
rather than for VS/VU modes.
Signed-off-by: Frank Chang <frank.chang@sifive.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
target/riscv/cpu.h | 2 +-
target/riscv/cpu_helper.c | 2 +-
target/riscv/internals.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index f59052fe7dc..b4cf86e4f61 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -883,7 +883,7 @@ bool riscv_cpu_is_32bit(RISCVCPU *cpu);
bool riscv_cpu_virt_mem_enabled(CPURISCVState *env);
RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env);
-RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env);
+RISCVPmPmm riscv_pm_get_vm_ldst_pmm(CPURISCVState *env);
uint32_t riscv_pm_get_pmlen(RISCVPmPmm pmm);
RISCVException riscv_csrr(CPURISCVState *env, int csrno,
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index 8f2a7234184..f6856a10bb5 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -214,7 +214,7 @@ RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env)
#endif
}
-RISCVPmPmm riscv_pm_get_virt_pmm(CPURISCVState *env)
+RISCVPmPmm riscv_pm_get_vm_ldst_pmm(CPURISCVState *env)
{
#ifndef CONFIG_USER_ONLY
int priv_mode;
diff --git a/target/riscv/internals.h b/target/riscv/internals.h
index 9b3f01144d2..b17b661e2a8 100644
--- a/target/riscv/internals.h
+++ b/target/riscv/internals.h
@@ -190,7 +190,7 @@ static inline target_ulong adjust_addr_body(CPURISCVState *env,
/* get pmm field depending on whether addr is */
if (is_virt_addr) {
- pmm = riscv_pm_get_virt_pmm(env);
+ pmm = riscv_pm_get_vm_ldst_pmm(env);
} else {
pmm = riscv_pm_get_pmm(env);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 6/6] target/riscv: Fix pointer masking translation mode check bug
2025-12-11 16:38 [PATCH v3 0/6] Fix Zjpm implementation frank.chang
` (4 preceding siblings ...)
2025-12-11 16:38 ` [PATCH v3 5/6] target/riscv: Rename riscv_pm_get_virt_pmm() to riscv_pm_get_vm_ldst_pmm() frank.chang
@ 2025-12-11 16:38 ` frank.chang
5 siblings, 0 replies; 7+ messages in thread
From: frank.chang @ 2025-12-11 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, open list:RISC-V TCG CPUs,
Frank Chang, Radim Krčmář
From: Frank Chang <frank.chang@sifive.com>
When running with virtualization in VS/VU mode, or when executing the
virtual-machine load/store instructions (HLV.* and HSV.*), the type of
address that determines which pointer masking rules apply should be
checked against vsatp rather than satp.
As a result, sign extension also applies to the virtual-machine
load/store instructions.
Signed-off-by: Frank Chang <frank.chang@sifive.com>
Reviewed-by: Radim Krčmář <rkrcmar@ventanamicro.com>
---
target/riscv/cpu.h | 2 +-
target/riscv/cpu_helper.c | 19 +++++++++++++++----
target/riscv/internals.h | 4 +---
target/riscv/tcg/tcg-cpu.c | 4 ++--
4 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index b4cf86e4f61..93c837024a0 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -881,7 +881,7 @@ static inline uint32_t vext_get_vlmax(uint32_t vlenb, uint32_t vsew,
bool riscv_cpu_is_32bit(RISCVCPU *cpu);
-bool riscv_cpu_virt_mem_enabled(CPURISCVState *env);
+bool riscv_cpu_virt_mem_enabled(CPURISCVState *env, bool is_vm_ldst);
RISCVPmPmm riscv_pm_get_pmm(CPURISCVState *env);
RISCVPmPmm riscv_pm_get_vm_ldst_pmm(CPURISCVState *env);
uint32_t riscv_pm_get_pmlen(RISCVPmPmm pmm);
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index f6856a10bb5..587adaeec73 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -240,16 +240,27 @@ RISCVPmPmm riscv_pm_get_vm_ldst_pmm(CPURISCVState *env)
#endif
}
-bool riscv_cpu_virt_mem_enabled(CPURISCVState *env)
+bool riscv_cpu_virt_mem_enabled(CPURISCVState *env, bool is_vm_ldst)
{
#ifndef CONFIG_USER_ONLY
int satp_mode = 0;
- int priv_mode = cpu_address_mode(env);
+ uint64_t satp;
+ int priv_mode;
+ bool virt = false;
+
+ if (!is_vm_ldst) {
+ riscv_cpu_eff_priv(env, &priv_mode, &virt);
+ } else {
+ priv_mode = get_field(env->hstatus, HSTATUS_SPVP);
+ virt = true;
+ }
+
+ satp = virt ? env->vsatp : env->satp;
if (riscv_cpu_mxl(env) == MXL_RV32) {
- satp_mode = get_field(env->satp, SATP32_MODE);
+ satp_mode = get_field(satp, SATP32_MODE);
} else {
- satp_mode = get_field(env->satp, SATP64_MODE);
+ satp_mode = get_field(satp, SATP64_MODE);
}
return ((satp_mode != VM_1_10_MBARE) && (priv_mode != PRV_M));
diff --git a/target/riscv/internals.h b/target/riscv/internals.h
index b17b661e2a8..38d438fbf93 100644
--- a/target/riscv/internals.h
+++ b/target/riscv/internals.h
@@ -200,9 +200,7 @@ static inline target_ulong adjust_addr_body(CPURISCVState *env,
return addr;
}
- if (!is_virt_addr) {
- signext = riscv_cpu_virt_mem_enabled(env);
- }
+ signext = riscv_cpu_virt_mem_enabled(env, is_virt_addr);
pmlen = riscv_pm_get_pmlen(pmm);
addr = addr << pmlen;
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 440626ddfad..2b4bcefa0c9 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -104,7 +104,7 @@ static TCGTBCPUState riscv_get_tb_cpu_state(CPUState *cs)
RISCVCPU *cpu = env_archcpu(env);
RISCVExtStatus fs, vs;
uint32_t flags = 0;
- bool pm_signext = riscv_cpu_virt_mem_enabled(env);
+ bool pm_signext = riscv_cpu_virt_mem_enabled(env, false);
if (cpu->cfg.ext_zve32x) {
/*
@@ -255,7 +255,7 @@ static vaddr riscv_pointer_wrap(CPUState *cs, int mmu_idx,
return result;
}
- pm_signext = riscv_cpu_virt_mem_enabled(env);
+ pm_signext = riscv_cpu_virt_mem_enabled(env, false);
if (pm_signext) {
return sextract64(result, 0, 64 - pm_len);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-12-11 16:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-11 16:38 [PATCH v3 0/6] Fix Zjpm implementation frank.chang
2025-12-11 16:38 ` [PATCH v3 1/6] target/riscv: fix address masking frank.chang
2025-12-11 16:38 ` [PATCH v3 2/6] target/riscv: Add a helper to return the current effective priv mode frank.chang
2025-12-11 16:38 ` [PATCH v3 3/6] target/riscv: Fix pointer masking PMM field selection logic frank.chang
2025-12-11 16:38 ` [PATCH v3 4/6] target/riscv: Fix pointer masking for virtual-machine load/store insns frank.chang
2025-12-11 16:38 ` [PATCH v3 5/6] target/riscv: Rename riscv_pm_get_virt_pmm() to riscv_pm_get_vm_ldst_pmm() frank.chang
2025-12-11 16:38 ` [PATCH v3 6/6] target/riscv: Fix pointer masking translation mode check bug frank.chang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).