Skip to contentSkip to conversation

target/riscv: Bugfix reserved bits in PTE for RV64

PATCH Superseded [email protected] 2 participants 3 messages Sep 24, 2019 RISC-V

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/riscv: Bugfix reserved bits in PTE for RV64

From: Guo Ren <[email protected]>

Highest 10 bits of PTE are reserved in riscv-privileged, ref: [1], so we need to ignore them. They can not be a part of ppn.

1: The RISC-V Instruction Set Manual, Volume II: Privileged Architecture
4.4 Sv39: Page-Based 39-bit Virtual-Memory System
4.5 Sv48: Page-Based 48-bit Virtual-Memory System

---
 target/riscv/cpu_helper.c | 1 +
 1 file changed, 1 insertion(+)
target/riscv/cpu_helper.c +1 -0
index 87dd6a6..3c5e8f6 100644
@@ -260,6 +260,7 @@ restart:
         target_ulong pte = ldl_phys(cs->as, pte_addr);
 #elif defined(TARGET_RISCV64)
         target_ulong pte = ldq_phys(cs->as, pte_addr);
+        pte = pte << 10 >> 10;
 #endif
         hwaddr ppn = pte >> PTE_PPN_SHIFT;
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 21 lines · On Mon, Sep 23, 2019 at 10:01 PM <[email protected]> wrote:

From: Guo Ren <[email protected]>

Highest 10 bits of PTE are reserved in riscv-privileged, ref: [1], so we need to ignore them. They can not be a part of ppn.

1: The RISC-V Instruction Set Manual, Volume II: Privileged Architecture
4.4 Sv39: Page-Based 39-bit Virtual-Memory System
4.5 Sv48: Page-Based 48-bit Virtual-Memory System

---
 target/riscv/cpu_helper.c | 1 +
 1 file changed, 1 insertion(+)
target/riscv/cpu_helper.c +0 -0
index 87dd6a6..3c5e8f6 100644

target/riscv/cpu_helper.c restart: · line 263

Quoted 4 lines
target/riscv/cpu_helper.c +1 -0
@@ -260,6 +260,7 @@ restart:
         target_ulong pte = ldl_phys(cs->as, pte_addr);
 #elif defined(TARGET_RISCV64)
         target_ulong pte = ldq_phys(cs->as, pte_addr);
+        pte = pte << 10 >> 10;

You can just AND with a mask instead of shifting both directions.

Alistair

Quoted 6 lines
target/riscv/cpu_helper.c +0 -1
 #endif
         hwaddr ppn = pte >> PTE_PPN_SHIFT;
 
--

2.7.4

author
#2 lore raw

Ok, In fact it's wrong patch, don't try it. pte is destroyed.

Sorry for that, I'll send V2.

Quoted 38 lines · Alistair Francis
Quoted 21 lines · On Mon, Sep 23, 2019 at 10:01 PM <[email protected]> wrote:

From: Guo Ren <[email protected]>

Highest 10 bits of PTE are reserved in riscv-privileged, ref: [1], so we need to ignore them. They can not be a part of ppn.

1: The RISC-V Instruction Set Manual, Volume II: Privileged Architecture
4.4 Sv39: Page-Based 39-bit Virtual-Memory System
4.5 Sv48: Page-Based 48-bit Virtual-Memory System

---
 target/riscv/cpu_helper.c | 1 +
 1 file changed, 1 insertion(+)
target/riscv/cpu_helper.c +0 -0
index 87dd6a6..3c5e8f6 100644

target/riscv/cpu_helper.c restart: · line 263

Quoted 4 lines
target/riscv/cpu_helper.c +1 -0
@@ -260,6 +260,7 @@ restart:
         target_ulong pte = ldl_phys(cs->as, pte_addr);
 #elif defined(TARGET_RISCV64)
         target_ulong pte = ldq_phys(cs->as, pte_addr);
+        pte = pte << 10 >> 10;

You can just AND with a mask instead of shifting both directions.

Alistair

Quoted 6 lines
target/riscv/cpu_helper.c +0 -1
 #endif
         hwaddr ppn = pte >> PTE_PPN_SHIFT;
 
--

2.7.4

Signature · 4 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/