qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] target/riscv: FIX xATP_MODE validation
@ 2024-01-09 14:59 Irina Ryapolova
  2024-01-09 14:59 ` [PATCH v3 2/2] target/riscv: UPDATE xATP write CSR Irina Ryapolova
  2024-02-15  3:43 ` [PATCH v3 1/2] target/riscv: FIX xATP_MODE validation Alistair Francis
  0 siblings, 2 replies; 5+ messages in thread
From: Irina Ryapolova @ 2024-01-09 14:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, palmer, alistair.francis, bin.meng, liwei1518,
	dbarboza, zhiwei_liu, Irina Ryapolova

The SATP register is an SXLEN-bit read/write WARL register. It means that CSR fields are only defined
for a subset of bit encodings, but allow any value to be written while guaranteeing to return a legal
value whenever read (See riscv-privileged-20211203, SATP CSR).

For example on rv64 we are trying to write to SATP CSR val = 0x1000000000000000 (SATP_MODE = 1 - Reserved for standard use)
and after that we are trying to read SATP_CSR. We read from the SATP CSR value = 0x1000000000000000, which is not a correct
operation (return illegal value).

Signed-off-by: Irina Ryapolova <irina.ryapolova@syntacore.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
Changes for v2:
  -used satp_mode.map instead of satp_mode.supported
Changes for v3:
  -patch formatting corrected
---
 target/riscv/csr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index fde7ce1a53..735fb27be7 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -1278,8 +1278,8 @@ static RISCVException read_mstatus(CPURISCVState *env, int csrno,
 
 static bool validate_vm(CPURISCVState *env, target_ulong vm)
 {
-    return (vm & 0xf) <=
-           satp_mode_max_from_map(riscv_cpu_cfg(env)->satp_mode.map);
+    uint64_t mode_supported = riscv_cpu_cfg(env)->satp_mode.map;
+    return get_field(mode_supported, (1 << vm));
 }
 
 static target_ulong legalize_mpp(CPURISCVState *env, target_ulong old_mpp,
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-16  0:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-09 14:59 [PATCH v3 1/2] target/riscv: FIX xATP_MODE validation Irina Ryapolova
2024-01-09 14:59 ` [PATCH v3 2/2] target/riscv: UPDATE xATP write CSR Irina Ryapolova
2024-02-15  3:45   ` Alistair Francis
2024-02-16  0:33   ` Alistair Francis
2024-02-15  3:43 ` [PATCH v3 1/2] target/riscv: FIX xATP_MODE validation Alistair Francis

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).