Skip to contentSkip to conversation

target/riscv: Validate the mode in write_vstvec

PATCH Applied Jiayi Li 3 participants 4 messages Jul 1, 2024 – Jul 8, 2024 RISC-V

lore
Share & tools
lore

Jiayi Li

author
#0 lore raw

PATCH 1/1 target/riscv: Validate the mode in write_vstvec

Base on the riscv-privileged spec, vstvec substitutes for the usual stvec. Therefore, the encoding of the MODE should also be restricted to 0 and 1.

---
 target/riscv/csr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
target/riscv/csr.c +6 -1
index 432c59dc66..f9229d92ab 100644
@@ -3791,7 +3791,12 @@ static RISCVException read_vstvec(CPURISCVState *env, int csrno,
 static RISCVException write_vstvec(CPURISCVState *env, int csrno,
                                    target_ulong val)
 {
-    env->vstvec = val;
+    /* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */
+    if ((val & 3) < 2) {
+        env->vstvec = val;
+    } else {
+        qemu_log_mask(LOG_UNIMP, "CSR_VSTVEC: reserved mode not supported\n");
+    }
     return RISCV_EXCP_NONE;
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jiayi Li

Base on the riscv-privileged spec, vstvec substitutes for the usual stvec. Therefore, the encoding of the MODE should also be restricted to 0 and 1.

Alistair

Quoted 26 lines
---
 target/riscv/csr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
target/riscv/csr.c +6 -2
index 432c59dc66..f9229d92ab 100644
@@ -3791,7 +3791,12 @@ static RISCVException read_vstvec(CPURISCVState *env, int csrno,
 static RISCVException write_vstvec(CPURISCVState *env, int csrno,
                                    target_ulong val)
 {
-    env->vstvec = val;
+    /* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */
+    if ((val & 3) < 2) {
+        env->vstvec = val;
+    } else {
+        qemu_log_mask(LOG_UNIMP, "CSR_VSTVEC: reserved mode not supported\n");
+    }
     return RISCV_EXCP_NONE;
 }
 
--

2.25.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to Jiayi Li
Quoted 13 lines · Jiayi Li

Base on the riscv-privileged spec, vstvec substitutes for the usual stvec. Therefore, the encoding of the MODE should also be restricted to 0 and 1.

---
  target/riscv/csr.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
target/riscv/csr.c +0 -0
index 432c59dc66..f9229d92ab 100644

target/riscv/csr.c static RISCVException read_vstvec(CPURISCVState *env, int csrno, · line 3799

Quoted 10 lines
target/riscv/csr.c +6 -1
@@ -3791,7 +3791,12 @@ static RISCVException read_vstvec(CPURISCVState *env, int csrno,
  static RISCVException write_vstvec(CPURISCVState *env, int csrno,
                                     target_ulong val)
  {
-    env->vstvec = val;
+    /* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */
+    if ((val & 3) < 2) {
+        env->vstvec = val;
+    } else {
+        qemu_log_mask(LOG_UNIMP, "CSR_VSTVEC: reserved mode not supported\n");
+    }

By the way,  you can get the all the reviewers mail by checking the patch with scripts/getmaintainer.pl.

Otherwise,

Zhiwei

Quoted 3 lines
target/riscv/csr.c +0 -0
      return RISCV_EXCP_NONE;
  }
 
#3 lore raw
In reply to Jiayi Li
Quoted 5 lines · Jiayi Li

Base on the riscv-privileged spec, vstvec substitutes for the usual stvec. Therefore, the encoding of the MODE should also be restricted to 0 and 1.

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 26 lines
---
 target/riscv/csr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
target/riscv/csr.c +6 -2
index 432c59dc66..f9229d92ab 100644
@@ -3791,7 +3791,12 @@ static RISCVException read_vstvec(CPURISCVState *env, int csrno,
 static RISCVException write_vstvec(CPURISCVState *env, int csrno,
                                    target_ulong val)
 {
-    env->vstvec = val;
+    /* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */
+    if ((val & 3) < 2) {
+        env->vstvec = val;
+    } else {
+        qemu_log_mask(LOG_UNIMP, "CSR_VSTVEC: reserved mode not supported\n");
+    }
     return RISCV_EXCP_NONE;
 }
 
--

2.25.1