support subsets of virtual memory extension
cover support subsets of virtual memory extension
This patchset implements virtual memory related RISC-V extensions: Svnapot version 0.1, Svinval vesion 0.1, Svpbmt version 0.1.
Specification:
https://github.com/riscv/virtual-memory/tree/main/specs
The port is available here:
https://github.com/plctlab/plct-qemu/tree/plct-vritmem-upstream
To test svinval implementation, specify cpu argument with 'x-svinval=true'. Other two extensions are enabled by default.
This implementation can pass the riscv-tests for rv64ssvnapot.
liweiwei (3):
target/riscv: add support for svnapot extension
target/riscv: add support for svinval extension
target/riscv: add support for svpbmt extension
target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/cpu_bits.h | 5 ++ target/riscv/cpu_helper.c | 25 +++++-- target/riscv/insn32.decode | 7 ++ target/riscv/insn_trans/trans_svinval.c.inc | 75 +++++++++++++++++++++ target/riscv/translate.c | 1 + 7 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 target/riscv/insn_trans/trans_svinval.c.inc
Signature · 1 line
2.17.1
RFC PATCH 1/3 target/riscv: add support for svnapot extension
--- target/riscv/cpu_bits.h | 1 + target/riscv/cpu_helper.c | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-)
target/riscv/cpu_bits.h +1 -0
@@ -473,6 +473,7 @@ typedef enum {#define PTE_A 0x040/* Accessed */ #define PTE_D 0x080/* Dirty */ #define PTE_SOFT 0x300/* Reserved for Software */ +#define PTE_N 0x8000000000000000/* Page table PPN shift amount */ #define PTE_PPN_SHIFT 10
target/riscv/cpu_helper.c +12 -6
@@ -588,7 +588,7 @@ restart:return TRANSLATE_FAIL ; } -hwaddr ppn = pte >>PTE_PPN_SHIFT ; +hwaddr ppn = (pte & ~(target_ulong )PTE_N ) >>PTE_PPN_SHIFT ;if (!(pte &PTE_V )) {/* Invalid PTE */
@@ -668,8 +668,17 @@ restart:/* for superpage mappings, make a fake leaf PTE for the TLB's benefit. */ target_ulong vpn = addr >>PGSHIFT ; - *physical = ((ppn | (vpn & ((1L << ptshift) -1 ))) <<PGSHIFT ) | - (addr & ~TARGET_PAGE_MASK ); + +int napot_bits = ((pte &PTE_N ) ? (ctzl (ppn) +1 ) :0 ); +if (((pte &PTE_N ) && ((ppn ==0 ) || (i != (levels -1 )))) || + (napot_bits !=0 && napot_bits !=4 )) { +return TRANSLATE_FAIL ; + } + + *physical = (((ppn & ~(((target_ulong )1 << napot_bits) -1 )) | + (vpn & (((target_ulong )1 << napot_bits) -1 )) | + (vpn & (((target_ulong )1 << ptshift) -1 )) + ) <<PGSHIFT ) | (addr & ~TARGET_PAGE_MASK );/* set permissions on the TLB entry */ if ((pte &PTE_R ) || ((pte &PTE_X ) && mxr)) {
@@ -856,7 +865,6 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, ret =get_physical_address (env, &pa, &prot, address, &env->guest_phys_fault_addr, access_type, mmu_idx, true, true, false); -/* * A G-stage exception may be triggered during two state lookup. * And the env->guest_phys_fault_addr has already been set in
@@ -879,7 +887,6 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, ret =get_physical_address (env, &pa, &prot2, im_address,NULL , access_type, mmu_idx, false, true, false); - qemu_log_mask(CPU_LOG_MMU, "%s 2nd-stage address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx " prot %d\n",
@@ -914,7 +921,6 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,/* Single stage lookup */ ret =get_physical_address (env, &pa, &prot, address,NULL , access_type, mmu_idx, true, false, false); - qemu_log_mask(CPU_LOG_MMU, "%s address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx " prot %d\n",
Signature · 1 line
2.17.1
Re: [RFC PATCH 1/3] target/riscv: add support for svnapot extension
Quoted 1 line · liweiwei
Can you add a commit message that describes what you are changing?
Alistair
Quoted 80 lines
Signed-off-by liweiwei <[email protected]>Signed-off-by wangjunqiang <[email protected]>--- target/riscv/cpu_bits.h | 1 + target/riscv/cpu_helper.c | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-)target/riscv/cpu_bits.h +1
-0@@ -473,6 +473,7 @@ typedef enum {#define PTE_A 0x040/* Accessed */ #define PTE_D 0x080/* Dirty */ #define PTE_SOFT 0x300/* Reserved for Software */ +#define PTE_N 0x8000000000000000/* Page table PPN shift amount */ #define PTE_PPN_SHIFT 10target/riscv/cpu_helper.c +12
-7@@ -588,7 +588,7 @@ restart:return TRANSLATE_FAIL ; } -hwaddr ppn = pte >>PTE_PPN_SHIFT ; +hwaddr ppn = (pte & ~(target_ulong )PTE_N ) >>PTE_PPN_SHIFT ;if (!(pte &PTE_V )) {/* Invalid PTE */ @@ -668,8 +668,17 @@ restart:/* for superpage mappings, make a fake leaf PTE for the TLB's benefit. */ target_ulong vpn = addr >>PGSHIFT ; - *physical = ((ppn | (vpn & ((1L << ptshift) -1 ))) <<PGSHIFT ) | - (addr & ~TARGET_PAGE_MASK ); + +int napot_bits = ((pte &PTE_N ) ? (ctzl (ppn) +1 ) :0 ); +if (((pte &PTE_N ) && ((ppn ==0 ) || (i != (levels -1 )))) || + (napot_bits !=0 && napot_bits !=4 )) { +return TRANSLATE_FAIL ; + } + + *physical = (((ppn & ~(((target_ulong )1 << napot_bits) -1 )) | + (vpn & (((target_ulong )1 << napot_bits) -1 )) | + (vpn & (((target_ulong )1 << ptshift) -1 )) + ) <<PGSHIFT ) | (addr & ~TARGET_PAGE_MASK );/* set permissions on the TLB entry */ if ((pte &PTE_R ) || ((pte &PTE_X ) && mxr)) {@@ -856,7 +865,6 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, ret =get_physical_address (env, &pa, &prot, address, &env->guest_phys_fault_addr, access_type, mmu_idx, true, true, false); -/* * A G-stage exception may be triggered during two state lookup. * And the env->guest_phys_fault_addr has already been set in @@ -879,7 +887,6 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, ret =get_physical_address (env, &pa, &prot2, im_address,NULL , access_type, mmu_idx, false, true, false); - qemu_log_mask(CPU_LOG_MMU, "%s 2nd-stage address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx " prot %d\n",@@ -914,7 +921,6 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,/* Single stage lookup */ ret =get_physical_address (env, &pa, &prot, address,NULL , access_type, mmu_idx, true, false, false); - qemu_log_mask(CPU_LOG_MMU, "%s address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx " prot %d\n", --2.17.1
RFC PATCH 2/3 target/riscv: add support for svinval extension
In reply to liweiwei--- target/riscv/cpu.c | 1 + target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 7 ++ target/riscv/insn_trans/trans_svinval.c.inc | 75 +++++++++++++++++++++ target/riscv/translate.c | 1 + 5 files changed, 85 insertions(+) create mode 100644 target/riscv/insn_trans/trans_svinval.c.inc
target/riscv/cpu.c +1 -0
@@ -641,6 +641,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("x-zbs" ,RISCVCPU , cfg.ext_zbs, false),DEFINE_PROP_BOOL ("x-h" ,RISCVCPU , cfg.ext_h, false),DEFINE_PROP_BOOL ("x-j" ,RISCVCPU , cfg.ext_j, false), +DEFINE_PROP_BOOL ("x-svinval" ,RISCVCPU , cfg.ext_svinval, false),DEFINE_PROP_BOOL ("x-v" ,RISCVCPU , cfg.ext_v, false),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec), DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),
target/riscv/cpu.h +1 -0
@@ -312,6 +312,7 @@ struct RISCVCPU {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_svinval;char *priv_spec;char *user_spec;
target/riscv/insn32.decode +7 -0
@@ -726,3 +726,10 @@ binv 0110100 .......... 001 ..... 0110011 @r binvi 01101. ........... 001 ..... 0010011 @sh bset 0010100 .......... 001 ..... 0110011 @r bseti 00101. ........... 001 ..... 0010011 @sh + +# *** Svinval Standard Extension *** +sinval_vma 0001011 ..... ..... 000 00000 1110011 @sfence_vma +sfence_w_inval 0001100 00000 00000 000 00000 1110011 +sfence_inval_ir 0001100 00001 00000 000 00000 1110011 +hinval_vvma 0011011 ..... ..... 000 00000 1110011 @hfence_vvma +hinval_gvma 0111011 ..... ..... 000 00000 1110011 @hfence_gvma
target/riscv/insn_trans/trans_svinval.c.inc new file +75 -0
75 lines not on this page · raw message
target/riscv/translate.c +1 -0
@@ -575,6 +575,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvv.c.inc" #include "insn_trans/trans_rvb.c.inc" #include "insn_trans/trans_privileged.c.inc" +#include "insn_trans/trans_svinval.c.inc" /* Include the auto-generated decoder for 16 bit insn */ #include "decode-insn16.c.inc"
Signature · 1 line
2.17.1
RFC PATCH 3/3 target/riscv: add support for svpbmt extension
In reply to liweiweiIt uses two PTE bits, but QEMU is sequentially consistent, So it has no effect on QEMU currently.
--- target/riscv/cpu_bits.h | 4 ++++ target/riscv/cpu_helper.c | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)
target/riscv/cpu_bits.h +4 -0
@@ -473,7 +473,11 @@ typedef enum {#define PTE_A 0x040/* Accessed */ #define PTE_D 0x080/* Dirty */ #define PTE_SOFT 0x300/* Reserved for Software */ +#define PTE_RSVD 0x1FC0000000000000/* Reserved for future use */ +#define PTE_PBMT 0x6000000000000000/* Page-based memory types */ #define PTE_N 0x8000000000000000 +#define PTE_ATTR 0xFFC0000000000000/* All attributes bits */ +/* Page table PPN shift amount */ #define PTE_PPN_SHIFT 10
target/riscv/cpu_helper.c +7 -2
@@ -588,13 +588,18 @@ restart:return TRANSLATE_FAIL ; } -hwaddr ppn = (pte & ~(target_ulong )PTE_N ) >>PTE_PPN_SHIFT ; +hwaddr ppn = (pte & ~(target_ulong )PTE_ATTR ) >>PTE_PPN_SHIFT ; -if (!(pte &PTE_V )) { +if (pte &PTE_RSVD ) { +return TRANSLATE_FAIL ; + }else if (!(pte &PTE_V )) {/* Invalid PTE */ return TRANSLATE_FAIL ; }else if (!(pte & (PTE_R |PTE_W |PTE_X ))) {/* Inner PTE, continue walking */ +if (pte & (PTE_D |PTE_A |PTE_U |PTE_N |PTE_PBMT )) { +return TRANSLATE_FAIL ; + } base = ppn <<PGSHIFT ; }else if ((pte & (PTE_R |PTE_W |PTE_X )) ==PTE_W ) {/* Reserved leaf PTE flags: PTE_W */
Signature · 1 line
2.17.1
Re: [RFC PATCH 3/3] target/riscv: add support for svpbmt extension
Am Sonntag, 28. November 2021, 14:52:55 CET schrieb liweiwei:
Quoted 4 lines
It uses two PTE bits, but QEMU is sequentially consistent, So it has no effect on QEMU currently.
Signed-off-by liweiwei <[email protected]>Signed-off-by wangjunqiang <[email protected]>
with the Linux svpbmt patchset
Thanks
Heiko
Quoted 47 lines
--- target/riscv/cpu_bits.h | 4 ++++ target/riscv/cpu_helper.c | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-)target/riscv/cpu_bits.h +4
-0@@ -473,7 +473,11 @@ typedef enum {#define PTE_A 0x040/* Accessed */ #define PTE_D 0x080/* Dirty */ #define PTE_SOFT 0x300/* Reserved for Software */ +#define PTE_RSVD 0x1FC0000000000000/* Reserved for future use */ +#define PTE_PBMT 0x6000000000000000/* Page-based memory types */ #define PTE_N 0x8000000000000000 +#define PTE_ATTR 0xFFC0000000000000/* All attributes bits */ +/* Page table PPN shift amount */ #define PTE_PPN_SHIFT 10target/riscv/cpu_helper.c +7
-2@@ -588,13 +588,18 @@ restart:return TRANSLATE_FAIL ; } -hwaddr ppn = (pte & ~(target_ulong )PTE_N ) >>PTE_PPN_SHIFT ; +hwaddr ppn = (pte & ~(target_ulong )PTE_ATTR ) >>PTE_PPN_SHIFT ; -if (!(pte &PTE_V )) { +if (pte &PTE_RSVD ) { +return TRANSLATE_FAIL ; + }else if (!(pte &PTE_V )) {/* Invalid PTE */ return TRANSLATE_FAIL ; }else if (!(pte & (PTE_R |PTE_W |PTE_X ))) {/* Inner PTE, continue walking */ +if (pte & (PTE_D |PTE_A |PTE_U |PTE_N |PTE_PBMT )) { +return TRANSLATE_FAIL ; + } base = ppn <<PGSHIFT ; }else if ((pte & (PTE_R |PTE_W |PTE_X )) ==PTE_W ) {/* Reserved leaf PTE flags: PTE_W */