Skip to contentSkip to conversation

target/loongarch: Fix CSR.DMW0-3.VSEG check

PATCH In review Jiajie Chen 2 participants 2 messages Jun 14, 2023 – Jun 16, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/loongarch: Fix CSR.DMW0-3.VSEG check

The previous code checks whether the highest 16 bits of virtual address equal to that of CSR.DMW0-3. This is incorrect according to the spec, and is corrected to compare only the highest four bits instead.

---
 target/loongarch/tlb_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/loongarch/tlb_helper.c +2 -2
index cce1db1e0a..6e00190547 100644
@@ -185,10 +185,10 @@ static int get_physical_address(CPULoongArchState *env, hwaddr *physical,
     }
 
     plv = kernel_mode | (user_mode << R_CSR_DMW_PLV3_SHIFT);
-    base_v = address >> TARGET_VIRT_ADDR_SPACE_BITS;
+    base_v = address >> R_CSR_DMW_VSEG_SHIFT;
     /* Check direct map window */
     for (int i = 0; i < 4; i++) {
-        base_c = env->CSR_DMW[i] >> TARGET_VIRT_ADDR_SPACE_BITS;
+        base_c = FIELD_EX64(env->CSR_DMW[i], CSR_DMW, VSEG);
         if ((plv & env->CSR_DMW[i]) && (base_c == base_v)) {
             *physical = dmw_va2pa(address);
             *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jiajie Chen

The previous code checks whether the highest 16 bits of virtual address equal to that of CSR.DMW0-3. This is incorrect according to the spec, and is corrected to compare only the highest four bits instead.

---
  target/loongarch/tlb_helper.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Thanks.
Song Gao

Quoted 17 lines
target/loongarch/tlb_helper.c +2 -2
index cce1db1e0a..6e00190547 100644
@@ -185,10 +185,10 @@ static int get_physical_address(CPULoongArchState *env, hwaddr *physical,
      }
 
      plv = kernel_mode | (user_mode << R_CSR_DMW_PLV3_SHIFT);
-    base_v = address >> TARGET_VIRT_ADDR_SPACE_BITS;
+    base_v = address >> R_CSR_DMW_VSEG_SHIFT;
      /* Check direct map window */
      for (int i = 0; i < 4; i++) {
-        base_c = env->CSR_DMW[i] >> TARGET_VIRT_ADDR_SPACE_BITS;
+        base_c = FIELD_EX64(env->CSR_DMW[i], CSR_DMW, VSEG);
          if ((plv & env->CSR_DMW[i]) && (base_c == base_v)) {
              *physical = dmw_va2pa(address);
              *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;