Skip to contentSkip to conversation

target/riscv: Fix mret exception cause when no pmp rule is configured

PATCH Applied Bin Meng 3 participants 4 messages Dec 5, 2022 – Dec 7, 2022 RISC-V

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH 1/1 target/riscv: Fix mret exception cause when no pmp rule is configured

The priv spec v1.12 says:

If no PMP entry matches an M-mode access, the access succeeds. If no PMP entry matches an S-mode or U-mode access, but at least one PMP entry is implemented, the access fails. Failed accesses generate an instruction, load, or store access-fault exception.

At present the exception cause is set to 'illegal instruction' but should have been 'instruction access fault'.

Fixes d102f19a2085 ("target/riscv/pmp: Raise exception if no PMP entry is configured")

---

 target/riscv/op_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/op_helper.c +1 -1
index 09f1f5185d..d7af7f056b 100644
@@ -202,7 +202,7 @@ target_ulong helper_mret(CPURISCVState *env)
 
     if (riscv_feature(env, RISCV_FEATURE_PMP) &&
         !pmp_get_num_rules(env) && (prev_priv != PRV_M)) {
-        riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
+        riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, GETPC());
     }
 
     target_ulong prev_virt = get_field(env->mstatus, MSTATUS_MPV);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Bin Meng

The priv spec v1.12 says:

  If no PMP entry matches an M-mode access, the access succeeds. If no PMP entry matches an S-mode or U-mode access, but at least one PMP entry is implemented, the access fails. Failed accesses generate
  an instruction, load, or store access-fault exception.

At present the exception cause is set to 'illegal instruction' but should have been 'instruction access fault'.

Quoted 7 lines
Fixes d102f19a2085 ("target/riscv/pmp: Raise exception if no PMP

entry is configured")

---

 target/riscv/op_helper.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
target/riscv/op_helper.c +0 -0
index 09f1f5185d..d7af7f056b 100644
@@ -202,7 +202,7 @@ target_ulong helper_mret(CPURISCVState *env)


     if (riscv_feature(env, RISCV_FEATURE_PMP) && !pmp_get_num_rules(env) && (prev_priv != PRV_M)) { -        riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
+        riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, GETPC());
     }

     target_ulong prev_virt = get_field(env->mstatus, MSTATUS_MPV);

Reviewed-by on v1 1/1
#2 lore raw
In reply to Bin Meng
Quoted 8 lines · Bin Meng

The priv spec v1.12 says:

If no PMP entry matches an M-mode access, the access succeeds. If no PMP entry matches an S-mode or U-mode access, but at least one PMP entry is implemented, the access fails. Failed accesses generate an instruction, load, or store access-fault exception.

Quoted 5 lines

At present the exception cause is set to 'illegal instruction' but should have been 'instruction access fault'.

Fixes d102f19a2085 ("target/riscv/pmp: Raise exception if no PMP entry is configured")

Alistair

Quoted 22 lines

---

 target/riscv/op_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/op_helper.c +1 -2
index 09f1f5185d..d7af7f056b 100644
@@ -202,7 +202,7 @@ target_ulong helper_mret(CPURISCVState *env)
 
     if (riscv_feature(env, RISCV_FEATURE_PMP) &&
         !pmp_get_num_rules(env) && (prev_priv != PRV_M)) {
-        riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
+        riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, GETPC());
     }
 
     target_ulong prev_virt = get_field(env->mstatus, MSTATUS_MPV);
--

2.34.1

#3 lore raw
In reply to Bin Meng
Quoted 8 lines · Bin Meng

The priv spec v1.12 says:

If no PMP entry matches an M-mode access, the access succeeds. If no PMP entry matches an S-mode or U-mode access, but at least one PMP entry is implemented, the access fails. Failed accesses generate an instruction, load, or store access-fault exception.

Quoted 5 lines

At present the exception cause is set to 'illegal instruction' but should have been 'instruction access fault'.

Fixes d102f19a2085 ("target/riscv/pmp: Raise exception if no PMP entry is configured")

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 22 lines

---

 target/riscv/op_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/op_helper.c +1 -2
index 09f1f5185d..d7af7f056b 100644
@@ -202,7 +202,7 @@ target_ulong helper_mret(CPURISCVState *env)
 
     if (riscv_feature(env, RISCV_FEATURE_PMP) &&
         !pmp_get_num_rules(env) && (prev_priv != PRV_M)) {
-        riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC());
+        riscv_raise_exception(env, RISCV_EXCP_INST_ACCESS_FAULT, GETPC());
     }
 
     target_ulong prev_virt = get_field(env->mstatus, MSTATUS_MPV);
--

2.34.1