* [PULL 1/5] target/riscv: Remove redundant insn length check for zama16b
2024-08-06 6:25 [PULL 0/5] riscv-to-apply queue Alistair Francis
@ 2024-08-06 6:25 ` Alistair Francis
2024-08-06 6:25 ` [PULL 2/5] target/riscv: Add MXLEN check for F/D/Q applies to zama16b Alistair Francis
` (4 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Alistair Francis @ 2024-08-06 6:25 UTC (permalink / raw)
To: qemu-devel; +Cc: alistair23, LIU Zhiwei, Alistair Francis, Richard Henderson
From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Compressed encodings also applies to zama16b.
https://github.com/riscv/riscv-isa-manual/pull/1557
Suggested-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20240802072417.659-2-zhiwei_liu@linux.alibaba.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/insn_trans/trans_rvd.c.inc | 4 ++--
target/riscv/insn_trans/trans_rvf.c.inc | 4 ++--
target/riscv/insn_trans/trans_rvi.c.inc | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_trans/trans_rvd.c.inc
index 1f5fac65a2..0ac42c3223 100644
--- a/target/riscv/insn_trans/trans_rvd.c.inc
+++ b/target/riscv/insn_trans/trans_rvd.c.inc
@@ -47,7 +47,7 @@ static bool trans_fld(DisasContext *ctx, arg_fld *a)
REQUIRE_FPU;
REQUIRE_EXT(ctx, RVD);
- if (ctx->cfg_ptr->ext_zama16b && (ctx->cur_insn_len != 2)) {
+ if (ctx->cfg_ptr->ext_zama16b) {
memop |= MO_ATOM_WITHIN16;
}
@@ -67,7 +67,7 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a)
REQUIRE_FPU;
REQUIRE_EXT(ctx, RVD);
- if (ctx->cfg_ptr->ext_zama16b && (ctx->cur_insn_len != 2)) {
+ if (ctx->cfg_ptr->ext_zama16b) {
memop |= MO_ATOM_WITHIN16;
}
diff --git a/target/riscv/insn_trans/trans_rvf.c.inc b/target/riscv/insn_trans/trans_rvf.c.inc
index f771aa1939..0222a728df 100644
--- a/target/riscv/insn_trans/trans_rvf.c.inc
+++ b/target/riscv/insn_trans/trans_rvf.c.inc
@@ -48,7 +48,7 @@ static bool trans_flw(DisasContext *ctx, arg_flw *a)
REQUIRE_FPU;
REQUIRE_EXT(ctx, RVF);
- if (ctx->cfg_ptr->ext_zama16b && (ctx->cur_insn_len != 2)) {
+ if (ctx->cfg_ptr->ext_zama16b) {
memop |= MO_ATOM_WITHIN16;
}
@@ -70,7 +70,7 @@ static bool trans_fsw(DisasContext *ctx, arg_fsw *a)
REQUIRE_FPU;
REQUIRE_EXT(ctx, RVF);
- if (ctx->cfg_ptr->ext_zama16b && (ctx->cur_insn_len != 2)) {
+ if (ctx->cfg_ptr->ext_zama16b) {
memop |= MO_ATOM_WITHIN16;
}
diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc
index 98e3806d5e..fab5c06719 100644
--- a/target/riscv/insn_trans/trans_rvi.c.inc
+++ b/target/riscv/insn_trans/trans_rvi.c.inc
@@ -268,7 +268,7 @@ static bool gen_load(DisasContext *ctx, arg_lb *a, MemOp memop)
{
bool out;
- if (ctx->cfg_ptr->ext_zama16b && (ctx->cur_insn_len != 2)) {
+ if (ctx->cfg_ptr->ext_zama16b) {
memop |= MO_ATOM_WITHIN16;
}
decode_save_opc(ctx);
@@ -369,7 +369,7 @@ static bool gen_store_i128(DisasContext *ctx, arg_sb *a, MemOp memop)
static bool gen_store(DisasContext *ctx, arg_sb *a, MemOp memop)
{
- if (ctx->cfg_ptr->ext_zama16b && (ctx->cur_insn_len != 2)) {
+ if (ctx->cfg_ptr->ext_zama16b) {
memop |= MO_ATOM_WITHIN16;
}
decode_save_opc(ctx);
--
2.45.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PULL 2/5] target/riscv: Add MXLEN check for F/D/Q applies to zama16b
2024-08-06 6:25 [PULL 0/5] riscv-to-apply queue Alistair Francis
2024-08-06 6:25 ` [PULL 1/5] target/riscv: Remove redundant insn length check for zama16b Alistair Francis
@ 2024-08-06 6:25 ` Alistair Francis
2024-08-06 6:25 ` [PULL 3/5] target/riscv: Relax fld alignment requirement Alistair Francis
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Alistair Francis @ 2024-08-06 6:25 UTC (permalink / raw)
To: qemu-devel; +Cc: alistair23, LIU Zhiwei, Alistair Francis, Richard Henderson
From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Zama16b loads and stores of no more than MXLEN bits defined in the F, D, and Q
extensions.
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20240802072417.659-3-zhiwei_liu@linux.alibaba.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/insn_trans/trans_rvd.c.inc | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_trans/trans_rvd.c.inc
index 0ac42c3223..49682292b8 100644
--- a/target/riscv/insn_trans/trans_rvd.c.inc
+++ b/target/riscv/insn_trans/trans_rvd.c.inc
@@ -47,7 +47,11 @@ static bool trans_fld(DisasContext *ctx, arg_fld *a)
REQUIRE_FPU;
REQUIRE_EXT(ctx, RVD);
- if (ctx->cfg_ptr->ext_zama16b) {
+ /*
+ * Zama16b applies to loads and stores of no more than MXLEN bits defined
+ * in the F, D, and Q extensions.
+ */
+ if ((get_xl_max(ctx) >= MXL_RV64) && ctx->cfg_ptr->ext_zama16b) {
memop |= MO_ATOM_WITHIN16;
}
@@ -67,7 +71,7 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a)
REQUIRE_FPU;
REQUIRE_EXT(ctx, RVD);
- if (ctx->cfg_ptr->ext_zama16b) {
+ if ((get_xl_max(ctx) >= MXL_RV64) && ctx->cfg_ptr->ext_zama16b) {
memop |= MO_ATOM_WITHIN16;
}
--
2.45.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PULL 3/5] target/riscv: Relax fld alignment requirement
2024-08-06 6:25 [PULL 0/5] riscv-to-apply queue Alistair Francis
2024-08-06 6:25 ` [PULL 1/5] target/riscv: Remove redundant insn length check for zama16b Alistair Francis
2024-08-06 6:25 ` [PULL 2/5] target/riscv: Add MXLEN check for F/D/Q applies to zama16b Alistair Francis
@ 2024-08-06 6:25 ` Alistair Francis
2024-08-06 6:25 ` [PULL 4/5] target/riscv: Add asserts for out-of-bound access Alistair Francis
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Alistair Francis @ 2024-08-06 6:25 UTC (permalink / raw)
To: qemu-devel; +Cc: alistair23, LIU Zhiwei, Alistair Francis, Richard Henderson
From: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
According to the risc-v specification:
"FLD and FSD are only guaranteed to execute atomically if the effective
address is naturally aligned and XLEN≥64."
We currently implement fld as MO_ATOM_IFALIGN when XLEN < 64, which does
not violate the rules. But it will hide some problems. So relax it to
MO_ATOM_NONE.
Signed-off-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20240802072417.659-4-zhiwei_liu@linux.alibaba.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/insn_trans/trans_rvd.c.inc | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/target/riscv/insn_trans/trans_rvd.c.inc b/target/riscv/insn_trans/trans_rvd.c.inc
index 49682292b8..8a46124f98 100644
--- a/target/riscv/insn_trans/trans_rvd.c.inc
+++ b/target/riscv/insn_trans/trans_rvd.c.inc
@@ -48,11 +48,17 @@ static bool trans_fld(DisasContext *ctx, arg_fld *a)
REQUIRE_EXT(ctx, RVD);
/*
- * Zama16b applies to loads and stores of no more than MXLEN bits defined
- * in the F, D, and Q extensions.
+ * FLD and FSD are only guaranteed to execute atomically if the effective
+ * address is naturally aligned and XLEN≥64. Also, zama16b applies to
+ * loads and stores of no more than MXLEN bits defined in the F, D, and
+ * Q extensions.
*/
- if ((get_xl_max(ctx) >= MXL_RV64) && ctx->cfg_ptr->ext_zama16b) {
+ if (get_xl_max(ctx) == MXL_RV32) {
+ memop |= MO_ATOM_NONE;
+ } else if (ctx->cfg_ptr->ext_zama16b) {
memop |= MO_ATOM_WITHIN16;
+ } else {
+ memop |= MO_ATOM_IFALIGN;
}
decode_save_opc(ctx);
@@ -71,8 +77,12 @@ static bool trans_fsd(DisasContext *ctx, arg_fsd *a)
REQUIRE_FPU;
REQUIRE_EXT(ctx, RVD);
- if ((get_xl_max(ctx) >= MXL_RV64) && ctx->cfg_ptr->ext_zama16b) {
+ if (get_xl_max(ctx) == MXL_RV32) {
+ memop |= MO_ATOM_NONE;
+ } else if (ctx->cfg_ptr->ext_zama16b) {
memop |= MO_ATOM_WITHIN16;
+ } else {
+ memop |= MO_ATOM_IFALIGN;
}
decode_save_opc(ctx);
--
2.45.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PULL 4/5] target/riscv: Add asserts for out-of-bound access
2024-08-06 6:25 [PULL 0/5] riscv-to-apply queue Alistair Francis
` (2 preceding siblings ...)
2024-08-06 6:25 ` [PULL 3/5] target/riscv: Relax fld alignment requirement Alistair Francis
@ 2024-08-06 6:25 ` Alistair Francis
2024-08-06 6:25 ` [PULL 5/5] roms/opensbi: Update to v1.5.1 Alistair Francis
2024-08-06 9:42 ` [PULL 0/5] riscv-to-apply queue Richard Henderson
5 siblings, 0 replies; 11+ messages in thread
From: Alistair Francis @ 2024-08-06 6:25 UTC (permalink / raw)
To: qemu-devel; +Cc: alistair23, Atish Patra, Peter Maydell, Alistair Francis
From: Atish Patra <atishp@rivosinc.com>
Coverity complained about the possible out-of-bounds access with
counter_virt/counter_virt_prev because these two arrays are
accessed with privilege mode. However, these two arrays are accessed
only when virt is enabled. Thus, the privilege mode can't be M mode.
Add the asserts anyways to detect any wrong usage of these arrays
in the future.
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Atish Patra <atishp@rivosinc.com>
Fixes: Coverity CID 1558459
Fixes: Coverity CID 1558462
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20240724-fixes-v1-1-4a64596b0d64@rivosinc.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/pmu.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/target/riscv/pmu.c b/target/riscv/pmu.c
index 3cc0b3648c..e05ab067d2 100644
--- a/target/riscv/pmu.c
+++ b/target/riscv/pmu.c
@@ -204,6 +204,7 @@ static void riscv_pmu_icount_update_priv(CPURISCVState *env,
}
if (env->virt_enabled) {
+ g_assert(env->priv <= PRV_S);
counter_arr = env->pmu_fixed_ctrs[1].counter_virt;
snapshot_prev = env->pmu_fixed_ctrs[1].counter_virt_prev;
} else {
@@ -212,6 +213,7 @@ static void riscv_pmu_icount_update_priv(CPURISCVState *env,
}
if (new_virt) {
+ g_assert(newpriv <= PRV_S);
snapshot_new = env->pmu_fixed_ctrs[1].counter_virt_prev;
} else {
snapshot_new = env->pmu_fixed_ctrs[1].counter_prev;
@@ -242,6 +244,7 @@ static void riscv_pmu_cycle_update_priv(CPURISCVState *env,
}
if (env->virt_enabled) {
+ g_assert(env->priv <= PRV_S);
counter_arr = env->pmu_fixed_ctrs[0].counter_virt;
snapshot_prev = env->pmu_fixed_ctrs[0].counter_virt_prev;
} else {
@@ -250,6 +253,7 @@ static void riscv_pmu_cycle_update_priv(CPURISCVState *env,
}
if (new_virt) {
+ g_assert(newpriv <= PRV_S);
snapshot_new = env->pmu_fixed_ctrs[0].counter_virt_prev;
} else {
snapshot_new = env->pmu_fixed_ctrs[0].counter_prev;
--
2.45.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PULL 5/5] roms/opensbi: Update to v1.5.1
2024-08-06 6:25 [PULL 0/5] riscv-to-apply queue Alistair Francis
` (3 preceding siblings ...)
2024-08-06 6:25 ` [PULL 4/5] target/riscv: Add asserts for out-of-bound access Alistair Francis
@ 2024-08-06 6:25 ` Alistair Francis
2024-08-06 9:42 ` [PULL 0/5] riscv-to-apply queue Richard Henderson
5 siblings, 0 replies; 11+ messages in thread
From: Alistair Francis @ 2024-08-06 6:25 UTC (permalink / raw)
To: qemu-devel; +Cc: alistair23, Daniel Henrique Barboza, Alistair Francis
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
A new minor version of OpenSBI was just released after our bump to
OpenSBI 1.5. It contains significant bug fixes that it's worth doing
a new update for QEMU 9.1.
Submodule roms/opensbi 455de672dd..43cace6c36:
> lib: sbi: check result of pmp_get() in is_pmp_entry_mapped()
> lib: sbi: fwft: fix incorrect size passed to sbi_zalloc()
> lib: sbi: dbtr: fix potential NULL pointer dereferences
> include: Adjust Sscofpmf mhpmevent mask for upper 8 bits
> lib: sbi_hsm: Save/restore menvcfg only when it exists
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Message-ID: <20240805120259.1705016-2-dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
.../opensbi-riscv32-generic-fw_dynamic.bin | Bin 268312 -> 268312 bytes
.../opensbi-riscv64-generic-fw_dynamic.bin | Bin 272504 -> 272504 bytes
roms/opensbi | 2 +-
3 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin b/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin
index 7ec260ff40..b2e740010b 100644
Binary files a/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin and b/pc-bios/opensbi-riscv32-generic-fw_dynamic.bin differ
diff --git a/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin b/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin
index 090c0cf6ac..018b4731a7 100644
Binary files a/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin and b/pc-bios/opensbi-riscv64-generic-fw_dynamic.bin differ
diff --git a/roms/opensbi b/roms/opensbi
index 455de672dd..43cace6c36 160000
--- a/roms/opensbi
+++ b/roms/opensbi
@@ -1 +1 @@
-Subproject commit 455de672dd7c2aa1992df54dfb08dc11abbc1b1a
+Subproject commit 43cace6c3671e5172d0df0a8963e552bb04b7b20
--
2.45.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PULL 0/5] riscv-to-apply queue
2024-08-06 6:25 [PULL 0/5] riscv-to-apply queue Alistair Francis
` (4 preceding siblings ...)
2024-08-06 6:25 ` [PULL 5/5] roms/opensbi: Update to v1.5.1 Alistair Francis
@ 2024-08-06 9:42 ` Richard Henderson
5 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2024-08-06 9:42 UTC (permalink / raw)
To: Alistair Francis, qemu-devel; +Cc: Alistair Francis
On 8/6/24 16:25, Alistair Francis wrote:
> The following changes since commit e7207a9971dd41618b407030902b0b2256deb664:
>
> Merge tag 'for-upstream' ofhttps://gitlab.com/bonzini/qemu into staging (2024-08-06 08:02:34 +1000)
>
> are available in the Git repository at:
>
> https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240806-2
>
> for you to fetch changes up to b3a34eb90d8264bd73ccb25295b1a7e271a9029c:
>
> roms/opensbi: Update to v1.5.1 (2024-08-06 15:01:01 +1000)
>
> ----------------------------------------------------------------
> RISC-V PR for 9.1
>
> * roms/opensbi: update to v1.5.1
> * target/riscv: Add asserts for out-of-bound access
> * Remove redundant insn length check for zama16b
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/9.1 as appropriate.
r~
^ permalink raw reply [flat|nested] 11+ messages in thread