Skip to contentSkip to conversation

target/riscv: Set the correct exception for implict G-stage translation fail

PATCH Applied Jason Chien 3 participants 4 messages Jun 27, 2023 – Jul 3, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: Set the correct exception for implict G-stage translation fail

The privileged spec states:
For a memory access made to support VS-stage address translation (such as to read/write a VS-level page table), permissions are checked as though for a load or store, not for the original access type. However, any exception is always reported for the original access type (instruction, load, or store/AMO).

The current implementation converts the access type to LOAD if implicit G-stage translation fails which results in only reporting "Load guest-page fault". This commit removes the convertion of access type, so the reported exception conforms to the spec.

---
 target/riscv/cpu_helper.c | 1 -
 1 file changed, 1 deletion(-)
target/riscv/cpu_helper.c +0 -1
index a944f25694..ff2a1469dc 100644
@@ -1277,7 +1277,6 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
         if (ret == TRANSLATE_G_STAGE_FAIL) {
             first_stage_error = false;
             two_stage_indirect_error = true;
-            access_type = MMU_DATA_LOAD;
         }
 
         qemu_log_mask(CPU_LOG_MMU,
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Jason Chien

The privileged spec states:
For a memory access made to support VS-stage address translation (such as to read/write a VS-level page table), permissions are checked as though for a load or store, not for the original access type. However, any exception is always reported for the original access type (instruction, load, or store/AMO).

Quoted 7 lines

The current implementation converts the access type to LOAD if implicit G-stage translation fails which results in only reporting "Load guest-page fault". This commit removes the convertion of access type, so the reported exception conforms to the spec.

---

Quoted 15 lines
  target/riscv/cpu_helper.c | 1 -
  1 file changed, 1 deletion(-)
target/riscv/cpu_helper.c +0 -1
index a944f25694..ff2a1469dc 100644
@@ -1277,7 +1277,6 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
          if (ret == TRANSLATE_G_STAGE_FAIL) {
              first_stage_error = false;
              two_stage_indirect_error = true;
-            access_type = MMU_DATA_LOAD;
          }
 
          qemu_log_mask(CPU_LOG_MMU,
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jason Chien
Quoted 8 lines · Jason Chien

The privileged spec states:
For a memory access made to support VS-stage address translation (such as to read/write a VS-level page table), permissions are checked as though for a load or store, not for the original access type. However, any exception is always reported for the original access type (instruction, load, or store/AMO).

Quoted 6 lines

The current implementation converts the access type to LOAD if implicit G-stage translation fails which results in only reporting "Load guest-page fault". This commit removes the convertion of access type, so the reported exception conforms to the spec.

Alistair

Quoted 20 lines
---
 target/riscv/cpu_helper.c | 1 -
 1 file changed, 1 deletion(-)
target/riscv/cpu_helper.c +0 -2
index a944f25694..ff2a1469dc 100644
@@ -1277,7 +1277,6 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
         if (ret == TRANSLATE_G_STAGE_FAIL) {
             first_stage_error = false;
             two_stage_indirect_error = true;
-            access_type = MMU_DATA_LOAD;
         }
 
         qemu_log_mask(CPU_LOG_MMU,
--

2.17.1

#3 lore raw
In reply to Jason Chien
Quoted 8 lines · Jason Chien

The privileged spec states:
For a memory access made to support VS-stage address translation (such as to read/write a VS-level page table), permissions are checked as though for a load or store, not for the original access type. However, any exception is always reported for the original access type (instruction, load, or store/AMO).

Quoted 6 lines

The current implementation converts the access type to LOAD if implicit G-stage translation fails which results in only reporting "Load guest-page fault". This commit removes the convertion of access type, so the reported exception conforms to the spec.

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 20 lines
---
 target/riscv/cpu_helper.c | 1 -
 1 file changed, 1 deletion(-)
target/riscv/cpu_helper.c +0 -2
index a944f25694..ff2a1469dc 100644
@@ -1277,7 +1277,6 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
         if (ret == TRANSLATE_G_STAGE_FAIL) {
             first_stage_error = false;
             two_stage_indirect_error = true;
-            access_type = MMU_DATA_LOAD;
         }
 
         qemu_log_mask(CPU_LOG_MMU,
--

2.17.1