target/riscv: Support Smpmpmt extension
PATCH v3 1/1 target/riscv: Support Smpmpmt extension
The Smpmpmt extension provides a mechanism to control memory attributes at the granularity of PMP (Physical Memory Protection) registers, similar to how Svpbmt controls memory attributes at the page level.
Version 0.6
https://github.com/riscv/riscv-isa-manual/blob/smpmpmt/src/smpmpmt.adoc#svpbmt
---
v2:
Place smpmpmt in the correct riscv,isa order.
v3:
Add note comment in pmp_hart_has_privs() explaining that MT field is stored but not acted upon during access checks.
--- target/riscv/cpu.c | 2 ++ target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/pmp.c | 16 ++++++++++++++++ target/riscv/pmp.h | 1 + 4 files changed, 20 insertions(+)
target/riscv/cpu.c +2 -0
@@ -223,6 +223,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (smcsrind,PRIV_VERSION_1_13_0 , ext_smcsrind),ISA_EXT_DATA_ENTRY (smdbltrp,PRIV_VERSION_1_13_0 , ext_smdbltrp),ISA_EXT_DATA_ENTRY (smepmp,PRIV_VERSION_1_12_0 , ext_smepmp), +ISA_EXT_DATA_ENTRY (smpmpmt,PRIV_VERSION_1_12_0 , ext_smpmpmt),ISA_EXT_DATA_ENTRY (smrnmi,PRIV_VERSION_1_12_0 , ext_smrnmi),ISA_EXT_DATA_ENTRY (smmpm,PRIV_VERSION_1_13_0 , ext_smmpm), ISA_EXT_DATA_ENTRY(smnpm, PRIV_VERSION_1_13_0, ext_smnpm),
@@ -1276,6 +1277,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {MULTI_EXT_CFG_BOOL ("smaia" , ext_smaia, false),MULTI_EXT_CFG_BOOL ("smdbltrp" , ext_smdbltrp, false),MULTI_EXT_CFG_BOOL ("smepmp" , ext_smepmp, false), +MULTI_EXT_CFG_BOOL ("smpmpmt" , ext_smpmpmt, false),MULTI_EXT_CFG_BOOL ("smrnmi" , ext_smrnmi, false),MULTI_EXT_CFG_BOOL ("smmpm" , ext_smmpm, false), MULTI_EXT_CFG_BOOL("smnpm", ext_smnpm, false),
target/riscv/cpu_cfg_fields.h.inc +1 -0
@@ -59,6 +59,7 @@ BOOL_FIELD(ext_svadu) BOOL_FIELD(ext_svinval) BOOL_FIELD(ext_svnapot) BOOL_FIELD(ext_svpbmt) +BOOL_FIELD(ext_smpmpmt) BOOL_FIELD(ext_svrsw60t59b) BOOL_FIELD(ext_svvptc) BOOL_FIELD(ext_svukte)
target/riscv/pmp.c +16 -0
@@ -165,6 +165,18 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val) "ignoring pmpcfg write - invalid\n"); }else {uint8_t a_field =pmp_get_a_field (val); + +if (!riscv_cpu_cfg (env)->ext_smpmpmt) { +/* If smpmpmt not supported, clear the MTMATCH bit */ + val &= ~PMP_MTMATCH ; + }else if ((val &PMP_MTMATCH ) ==PMP_MTMATCH ) { +/* +* If trying to set reserved value (0x3) for MT field, +* preserve the original MT field from current config. +*/ + val = (val & ~PMP_MTMATCH ) | + (env->pmp_state.pmp[pmp_index].cfg_reg &PMP_MTMATCH ); + }/* * When granularity g >= 1 (i.e., granularity > 4 bytes), * the NA4 (Naturally Aligned 4-byte) mode is not selectable
@@ -355,6 +367,10 @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, pmp_priv_t privs,* Check if the address has required RWX privs to complete desired operation * Return true if a pmp rule match or default match * Return false if no match +* +* Note: The MT (Memory Type) field from Smpmpmt extension is stored in +* pmpcfg but is not acted upon during access checks. Cache attributes +* have no functional impact in QEMU emulation. */ bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr, target_ulong size, pmp_priv_t privs,
target/riscv/pmp.h +1 -0
@@ -29,6 +29,7 @@ typedef enum {PMP_WRITE =1 <<1 ,PMP_EXEC =1 <<2 ,PMP_AMATCH = (3 <<3 ), +PMP_MTMATCH = (3 <<5 ), PMP_LOCK = 1 << 7 } pmp_priv_t;
Signature · 1 line
2.48.1
Quoted 11 lines · Jay Chang
The Smpmpmt extension provides a mechanism to control memory attributes at the granularity of PMP (Physical Memory Protection) registers, similar to how Svpbmt controls memory attributes at the page level.
Version 0.6
https://github.com/riscv/riscv-isa-manual/blob/smpmpmt/src/smpmpmt.adoc#svpbmtSigned-off-by Jay Chang <[email protected]>Reviewed-by Daniel Henrique Barboza <[email protected]>Reviewed-by Frank Chang <[email protected]>
Alistair
Quoted 98 lines
---
v2:
Place smpmpmt in the correct riscv,isa order.
v3:
Add note comment inpmp_hart_has_privs()explaining that MT field is stored but not acted upon during access checks.Signed-off-by Jay Chang <[email protected]>--- target/riscv/cpu.c | 2 ++ target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/pmp.c | 16 ++++++++++++++++ target/riscv/pmp.h | 1 + 4 files changed, 20 insertions(+)target/riscv/cpu.c +2
-0@@ -223,6 +223,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (smcsrind,PRIV_VERSION_1_13_0 , ext_smcsrind),ISA_EXT_DATA_ENTRY (smdbltrp,PRIV_VERSION_1_13_0 , ext_smdbltrp),ISA_EXT_DATA_ENTRY (smepmp,PRIV_VERSION_1_12_0 , ext_smepmp), +ISA_EXT_DATA_ENTRY (smpmpmt,PRIV_VERSION_1_12_0 , ext_smpmpmt),ISA_EXT_DATA_ENTRY (smrnmi,PRIV_VERSION_1_12_0 , ext_smrnmi),ISA_EXT_DATA_ENTRY (smmpm,PRIV_VERSION_1_13_0 , ext_smmpm), ISA_EXT_DATA_ENTRY(smnpm, PRIV_VERSION_1_13_0, ext_smnpm),@@ -1276,6 +1277,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {MULTI_EXT_CFG_BOOL ("smaia" , ext_smaia, false),MULTI_EXT_CFG_BOOL ("smdbltrp" , ext_smdbltrp, false),MULTI_EXT_CFG_BOOL ("smepmp" , ext_smepmp, false), +MULTI_EXT_CFG_BOOL ("smpmpmt" , ext_smpmpmt, false),MULTI_EXT_CFG_BOOL ("smrnmi" , ext_smrnmi, false),MULTI_EXT_CFG_BOOL ("smmpm" , ext_smmpm, false), MULTI_EXT_CFG_BOOL("smnpm", ext_smnpm, false),target/riscv/cpu_cfg_fields.h.inc +1
-0@@ -59,6 +59,7 @@ BOOL_FIELD(ext_svadu) BOOL_FIELD(ext_svinval) BOOL_FIELD(ext_svnapot) BOOL_FIELD(ext_svpbmt) +BOOL_FIELD(ext_smpmpmt) BOOL_FIELD(ext_svrsw60t59b) BOOL_FIELD(ext_svvptc) BOOL_FIELD(ext_svukte)target/riscv/pmp.c +16
-0@@ -165,6 +165,18 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val) "ignoring pmpcfg write - invalid\n"); }else {uint8_t a_field =pmp_get_a_field (val); + +if (!riscv_cpu_cfg (env)->ext_smpmpmt) { +/* If smpmpmt not supported, clear the MTMATCH bit */ + val &= ~PMP_MTMATCH ; + }else if ((val &PMP_MTMATCH ) ==PMP_MTMATCH ) { +/* +* If trying to set reserved value (0x3) for MT field, +* preserve the original MT field from current config. +*/ + val = (val & ~PMP_MTMATCH ) | + (env->pmp_state.pmp[pmp_index].cfg_reg &PMP_MTMATCH ); + }/* * When granularity g >= 1 (i.e., granularity > 4 bytes), * the NA4 (Naturally Aligned 4-byte) mode is not selectable @@ -355,6 +367,10 @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, pmp_priv_t privs,* Check if the address has required RWX privs to complete desired operation * Return true if a pmp rule match or default match * Return false if no match +* +* Note: The MT (Memory Type) field from Smpmpmt extension is stored in +* pmpcfg but is not acted upon during access checks. Cache attributes +* have no functional impact in QEMU emulation. */ bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr, target_ulong size, pmp_priv_t privs,target/riscv/pmp.h +1
-1@@ -29,6 +29,7 @@ typedef enum {PMP_WRITE =1 <<1 ,PMP_EXEC =1 <<2 ,PMP_AMATCH = (3 <<3 ), +PMP_MTMATCH = (3 <<5 ), PMP_LOCK = 1 << 7 } pmp_priv_t; --2.48.1
Alistair Francis
AppliedQuoted 11 lines · Jay Chang
The Smpmpmt extension provides a mechanism to control memory attributes at the granularity of PMP (Physical Memory Protection) registers, similar to how Svpbmt controls memory attributes at the page level.
Version 0.6
https://github.com/riscv/riscv-isa-manual/blob/smpmpmt/src/smpmpmt.adoc#svpbmtSigned-off-by Jay Chang <[email protected]>Reviewed-by Daniel Henrique Barboza <[email protected]>Reviewed-by Frank Chang <[email protected]>
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 98 lines
---
v2:
Place smpmpmt in the correct riscv,isa order.
v3:
Add note comment inpmp_hart_has_privs()explaining that MT field is stored but not acted upon during access checks.Signed-off-by Jay Chang <[email protected]>--- target/riscv/cpu.c | 2 ++ target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/pmp.c | 16 ++++++++++++++++ target/riscv/pmp.h | 1 + 4 files changed, 20 insertions(+)target/riscv/cpu.c +2
-0@@ -223,6 +223,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (smcsrind,PRIV_VERSION_1_13_0 , ext_smcsrind),ISA_EXT_DATA_ENTRY (smdbltrp,PRIV_VERSION_1_13_0 , ext_smdbltrp),ISA_EXT_DATA_ENTRY (smepmp,PRIV_VERSION_1_12_0 , ext_smepmp), +ISA_EXT_DATA_ENTRY (smpmpmt,PRIV_VERSION_1_12_0 , ext_smpmpmt),ISA_EXT_DATA_ENTRY (smrnmi,PRIV_VERSION_1_12_0 , ext_smrnmi),ISA_EXT_DATA_ENTRY (smmpm,PRIV_VERSION_1_13_0 , ext_smmpm), ISA_EXT_DATA_ENTRY(smnpm, PRIV_VERSION_1_13_0, ext_smnpm),@@ -1276,6 +1277,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {MULTI_EXT_CFG_BOOL ("smaia" , ext_smaia, false),MULTI_EXT_CFG_BOOL ("smdbltrp" , ext_smdbltrp, false),MULTI_EXT_CFG_BOOL ("smepmp" , ext_smepmp, false), +MULTI_EXT_CFG_BOOL ("smpmpmt" , ext_smpmpmt, false),MULTI_EXT_CFG_BOOL ("smrnmi" , ext_smrnmi, false),MULTI_EXT_CFG_BOOL ("smmpm" , ext_smmpm, false), MULTI_EXT_CFG_BOOL("smnpm", ext_smnpm, false),target/riscv/cpu_cfg_fields.h.inc +1
-0@@ -59,6 +59,7 @@ BOOL_FIELD(ext_svadu) BOOL_FIELD(ext_svinval) BOOL_FIELD(ext_svnapot) BOOL_FIELD(ext_svpbmt) +BOOL_FIELD(ext_smpmpmt) BOOL_FIELD(ext_svrsw60t59b) BOOL_FIELD(ext_svvptc) BOOL_FIELD(ext_svukte)target/riscv/pmp.c +16
-0@@ -165,6 +165,18 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val) "ignoring pmpcfg write - invalid\n"); }else {uint8_t a_field =pmp_get_a_field (val); + +if (!riscv_cpu_cfg (env)->ext_smpmpmt) { +/* If smpmpmt not supported, clear the MTMATCH bit */ + val &= ~PMP_MTMATCH ; + }else if ((val &PMP_MTMATCH ) ==PMP_MTMATCH ) { +/* +* If trying to set reserved value (0x3) for MT field, +* preserve the original MT field from current config. +*/ + val = (val & ~PMP_MTMATCH ) | + (env->pmp_state.pmp[pmp_index].cfg_reg &PMP_MTMATCH ); + }/* * When granularity g >= 1 (i.e., granularity > 4 bytes), * the NA4 (Naturally Aligned 4-byte) mode is not selectable @@ -355,6 +367,10 @@ static bool pmp_hart_has_privs_default(CPURISCVState *env, pmp_priv_t privs,* Check if the address has required RWX privs to complete desired operation * Return true if a pmp rule match or default match * Return false if no match +* +* Note: The MT (Memory Type) field from Smpmpmt extension is stored in +* pmpcfg but is not acted upon during access checks. Cache attributes +* have no functional impact in QEMU emulation. */ bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr, target_ulong size, pmp_priv_t privs,target/riscv/pmp.h +1
-1@@ -29,6 +29,7 @@ typedef enum {PMP_WRITE =1 <<1 ,PMP_EXEC =1 <<2 ,PMP_AMATCH = (3 <<3 ), +PMP_MTMATCH = (3 <<5 ), PMP_LOCK = 1 << 7 } pmp_priv_t; --2.48.1