RVA22U64 profile support
v5 cover RVA22U64 profile support
Based-on: [email protected] ("[PATCH v3 0/4] riscv: zicntr/zihpm flags and disable support")
Hi,
This patch contains a change proposed by Drew in v4: document in the code, in the profile description, our reasoning behind assuming that QEMU already support all cache related named features/synthetic extensions.
It also contains a new patch (patch 1). This patch adds support for the zic64b named feature, which is a fancy way the RVA22U64 spec found to mandate 64 bytes cache blocks. QEMU already assumes a 64 byte default value for them, but in v4 we weren't considering the use case where the user enables the RVA22U64 profile and then happens to change the block sizes, i.e. a profile violation.
We're implementing it by adding the flag and, if the flag is user (or profile) set, and we're not using 64 bytes cache blocks (meaning the user changed the block sizes in the command line), send an user warning and disable the flag. zic64b is an 'almost extension' in a sense that we're not adding it in the riscv,isa DT.
I am aware that the existence of these exotic "named features that aren't real extensions" profile-only flags in QEMU will raise questions (How will the kernel detect it if we're not writing the riscv,isa DT? Will it imply that if all cache sizes are 64 then we have a zic64b system?). We'll add zic64b and any other named feature in the riscv,isa when/if it makes sense. For now we just want to get RVA22U64 out of the door as feature-complete as possible.
No other changes made. Patches based on top of:
[PATCH v3 0/4] riscv: zicntr/zihpm flags and disable support
Patches missing acks: patch 1
Changes from v4:
- patch 1 (new):
- add zic64b support
- patch 2 (former 1):
- add a comment in the profile definition explaining that QEMU does not implement cache and we consider all cache-related named features as
always enabled
- add zic64b in the profile definition
- v4 link: https://lore.kernel.org/qemu-riscv/[email protected]/
Daniel Henrique Barboza (10):
target/riscv/tcg: add 'zic64b' support target/riscv: add rva22u64 profile definition target/riscv/kvm: add 'rva22u64' flag as unavailable target/riscv/tcg: add user flag for profile support target/riscv/tcg: add MISA user options hash target/riscv/tcg: add riscv_cpu_write_misa_bit() target/riscv/tcg: handle profile MISA bits target/riscv/tcg: add hash table insert helpers target/riscv/tcg: honor user choice for G MISA bits target/riscv/tcg: warn if profile exts are disabled
target/riscv/cpu.c | 43 +++++- target/riscv/cpu.h | 15 ++ target/riscv/cpu_cfg.h | 1 + target/riscv/kvm/kvm-cpu.c | 7 +- target/riscv/tcg/tcg-cpu.c | 275 +++++++++++++++++++++++++++++++------ 5 files changed, 296 insertions(+), 45 deletions(-)
Signature · 1 line
2.41.0
PATCH v5 1/10 target/riscv/tcg: add 'zic64b' support
zic64b is defined in the RVA22U64 profile [1] as a named feature for "Cache blocks must be 64 bytes in size, naturally aligned in the address space". It's a fantasy name for 64 bytes cache blocks. RVA22U64 mandates this feature, meaning that applications using it expects 64 bytes cache blocks.
In theory we're already compliant to it since we're using 64 bytes cache block sizes by default, but nothing is stopping users from enabling a profile and changing the cache block size at the same time.
We'll add zic64b as a 'named feature', not a regular extension, in a sense that we won't write it in riscv,isa. It'll be used solely to track whether the user changed cache sizes and if we should warn about it.
zic64b is default to 'true' since we're already using 64 bytes blocks. If any cache block size (cbom_blocksize or cboz_blocksize) is changed to something different than 64, zic64b is set to 'false' and, if zic64b was set to 'true' in the command line, also throw an user warning.
Our profile implementation set mandatory extensions as if users enabled them in the command line, so this logic will extend to the future RVA22U64 implementation as well.
[1] https://github.com/riscv/riscv-profiles/releases/download/v1.0/profiles.pdf
--- target/riscv/cpu.c | 12 ++++++++++-- target/riscv/cpu.h | 3 +++ target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 26 ++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-)
target/riscv/cpu.c +10 -2
@@ -1394,6 +1394,12 @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { DEFINE_PROP_END_OF_LIST(), }; +const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = { +MULTI_EXT_CFG_BOOL ("zic64b" , zic64b, true), + +DEFINE_PROP_END_OF_LIST (), +}; +/* Deprecated entries marked for future removal */ const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[] = {MULTI_EXT_CFG_BOOL ("Zifencei" , ext_zifencei, true),
@@ -1423,8 +1429,10 @@ Property riscv_cpu_options[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), -DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , cfg.cbom_blocksize,64 ), -DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , cfg.cboz_blocksize,64 ), +DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , + cfg.cbom_blocksize,CB_DEF_VALUE ), +DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , + cfg.cboz_blocksize,CB_DEF_VALUE ), DEFINE_PROP_END_OF_LIST(), };
target/riscv/cpu.h +3 -0
@@ -64,6 +64,8 @@ extern const uint32_t misa_bits[];const char *riscv_get_misa_ext_name (uint32_t bit);const char *riscv_get_misa_ext_description (uint32_t bit); +#define CB_DEF_VALUE 64 +#define CPU_CFG_OFFSET (_prop) offsetof(struct RISCVCPUConfig, _prop)/* Privileged specification version */
@@ -745,6 +747,7 @@ typedef struct RISCVCPUMultiExtConfig {extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[];extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[];extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; +extern const RISCVCPUMultiExtConfig riscv_cpu_named_features[];extern const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[];extern Property riscv_cpu_options[];
target/riscv/cpu_cfg.h +1 -0
@@ -107,6 +107,7 @@ struct RISCVCPUConfig {bool ext_smepmp;bool rvv_ta_all_1s;bool rvv_ma_all_1s; +bool zic64b;uint32_t mvendorid;uint64_t marchid;
target/riscv/tcg/tcg-cpu.c +26 -0
@@ -264,6 +264,27 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) } } +static void riscv_cpu_validate_zic64b (RISCVCPU *cpu) +{ +const char *warn ="zic64b set to 'true' but %s is set to %u. " +"zic64b changed to 'false'" ; +bool send_warn =cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (zic64b)); + +if (cpu->cfg.cbom_blocksize !=CB_DEF_VALUE ) { + cpu->cfg.zic64b = false; +if (send_warn) { +warn_report (warn,"cbom_blocksize" , cpu->cfg.cbom_blocksize); + } + } + +if (cpu->cfg.cboz_blocksize !=CB_DEF_VALUE ) { + cpu->cfg.zic64b = false; +if (send_warn) { +warn_report (warn,"cboz_blocksize" , cpu->cfg.cboz_blocksize); + } + } +} +/* * Check consistency between chosen extensions while setting * cpu->cfg accordingly.
@@ -394,6 +415,10 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)return ; } +if (cpu->cfg.zic64b) { +riscv_cpu_validate_zic64b (cpu); + } +if (cpu->cfg.ext_zvfh) {cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zvfhmin), true); }
@@ -889,6 +914,7 @@ static void riscv_cpu_add_user_properties(Object *obj)riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_extensions);riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_vendor_exts);riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_experimental_exts); +riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_named_features);riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_deprecated_exts);
Signature · 1 line
2.41.0
Re: [PATCH v5 01/10] target/riscv/tcg: add 'zic64b' support
Quoted 112 lines · Daniel Henrique Barboza
zic64b is defined in the RVA22U64 profile [1] as a named feature for "Cache blocks must be 64 bytes in size, naturally aligned in the address space". It's a fantasy name for 64 bytes cache blocks. RVA22U64 mandates this feature, meaning that applications using it expects 64 bytes cache blocks.
In theory we're already compliant to it since we're using 64 bytes cache block sizes by default, but nothing is stopping users from enabling a profile and changing the cache block size at the same time.
We'll add zic64b as a 'named feature', not a regular extension, in a sense that we won't write it in riscv,isa. It'll be used solely to track whether the user changed cache sizes and if we should warn about it.
zic64b is default to 'true' since we're already using 64 bytes blocks. If any cache block size (
cbom_blocksizeorcboz_blocksize) is changed to something different than 64, zic64b is set to 'false' and, if zic64b was set to 'true' in the command line, also throw an user warning.Our profile implementation set mandatory extensions as if users enabled them in the command line, so this logic will extend to the future RVA22U64 implementation as well.
[1] https://github.com/riscv/riscv-profiles/releases/download/v1.0/profiles.pdf
Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/riscv/cpu.c | 12 ++++++++++-- target/riscv/cpu.h | 3 +++ target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 26 ++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-)target/riscv/cpu.c +10
-2@@ -1394,6 +1394,12 @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { DEFINE_PROP_END_OF_LIST(), }; +const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = { +MULTI_EXT_CFG_BOOL ("zic64b" , zic64b, true), + +DEFINE_PROP_END_OF_LIST (), +}; +/* Deprecated entries marked for future removal */ const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[] = {MULTI_EXT_CFG_BOOL ("Zifencei" , ext_zifencei, true),@@ -1423,8 +1429,10 @@ Property riscv_cpu_options[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), -DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , cfg.cbom_blocksize,64 ), -DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , cfg.cboz_blocksize,64 ), +DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , + cfg.cbom_blocksize,CB_DEF_VALUE ), +DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , + cfg.cboz_blocksize,CB_DEF_VALUE ), DEFINE_PROP_END_OF_LIST(), };target/riscv/cpu.h +3
-0@@ -64,6 +64,8 @@ extern const uint32_t misa_bits[];const char *riscv_get_misa_ext_name (uint32_t bit);const char *riscv_get_misa_ext_description (uint32_t bit); +#define CB_DEF_VALUE 64 +#define CPU_CFG_OFFSET (_prop) offsetof(struct RISCVCPUConfig, _prop)/* Privileged specification version */ @@ -745,6 +747,7 @@ typedef struct RISCVCPUMultiExtConfig {extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[];extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[];extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; +extern const RISCVCPUMultiExtConfig riscv_cpu_named_features[];extern const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[];extern Property riscv_cpu_options[];target/riscv/cpu_cfg.h +1
-0@@ -107,6 +107,7 @@ struct RISCVCPUConfig {bool ext_smepmp;bool rvv_ta_all_1s;bool rvv_ma_all_1s; +bool zic64b;uint32_t mvendorid;uint64_t marchid;target/riscv/tcg/tcg-cpu.c +8
-0@@ -264,6 +264,27 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) } } +static void riscv_cpu_validate_zic64b (RISCVCPU *cpu) +{ +const char *warn ="zic64b set to 'true' but %s is set to %u. " +"zic64b changed to 'false'" ; +bool send_warn =cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (zic64b)); + +if (cpu->cfg.cbom_blocksize !=CB_DEF_VALUE ) { + cpu->cfg.zic64b = false;
target/riscv/tcg/tcg-cpu.c static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) · line 284
Quoted 10 lines
target/riscv/tcg/tcg-cpu.c +10
-0+if (send_warn) { +warn_report (warn,"cbom_blocksize" , cpu->cfg.cbom_blocksize); + } + } + +if (cpu->cfg.cboz_blocksize !=CB_DEF_VALUE ) { + cpu->cfg.zic64b = false; +if (send_warn) { +warn_report (warn,"cboz_blocksize" , cpu->cfg.cboz_blocksize); + }
I think if a user does X=1,X=2 and expects X to be the superposition of 1 and 2 they should get an error instead of a warning, and that's what zic64b=on,cbom_blocksize=128 would effectively be asking to do, so let's error out here instead of warn.
target/riscv/tcg/tcg-cpu.c void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) · line 420
Quoted 13 lines
target/riscv/tcg/tcg-cpu.c +6
-0+ } +} +/* * Check consistency between chosen extensions while setting * cpu->cfg accordingly. @@ -394,6 +415,10 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)return ; } +if (cpu->cfg.zic64b) { +riscv_cpu_validate_zic64b (cpu); + }
We set this on by default, so if a user just gives cbom_blocksize=128, then we'll get the warning (or failure). They'd have to do zic64b=off,cbom_blocksize=128 instead to avoid it. I think zic64b needs to be off by default and then automatically turn on during cpu finalize if all blocksize properties are 64.
Quoted 15 lines
target/riscv/tcg/tcg-cpu.c +2
-0+if (cpu->cfg.ext_zvfh) {cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zvfhmin), true); }@@ -889,6 +914,7 @@ static void riscv_cpu_add_user_properties(Object *obj)riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_extensions);riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_vendor_exts);riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_experimental_exts); +riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_named_features);riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_deprecated_exts);Signature · 1 line
2.41.0
Thanks,
drew
Re: [PATCH v5 01/10] target/riscv/tcg: add 'zic64b' support
In reply to Daniel Henrique BarbozaQuoted 77 lines · Daniel Henrique Barboza
zic64b is defined in the RVA22U64 profile [1] as a named feature for "Cache blocks must be 64 bytes in size, naturally aligned in the address space". It's a fantasy name for 64 bytes cache blocks. RVA22U64 mandates this feature, meaning that applications using it expects 64 bytes cache blocks.
In theory we're already compliant to it since we're using 64 bytes cache block sizes by default, but nothing is stopping users from enabling a profile and changing the cache block size at the same time.
We'll add zic64b as a 'named feature', not a regular extension, in a sense that we won't write it in riscv,isa. It'll be used solely to track whether the user changed cache sizes and if we should warn about it.
zic64b is default to 'true' since we're already using 64 bytes blocks. If any cache block size (
cbom_blocksizeorcboz_blocksize) is changed to something different than 64, zic64b is set to 'false' and, if zic64b was set to 'true' in the command line, also throw an user warning.Our profile implementation set mandatory extensions as if users enabled them in the command line, so this logic will extend to the future RVA22U64 implementation as well.
[1] https://github.com/riscv/riscv-profiles/releases/download/v1.0/profiles.pdf
Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/riscv/cpu.c | 12 ++++++++++-- target/riscv/cpu.h | 3 +++ target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 26 ++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-)target/riscv/cpu.c +10
-2@@ -1394,6 +1394,12 @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { DEFINE_PROP_END_OF_LIST(), }; +const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = { +MULTI_EXT_CFG_BOOL ("zic64b" , zic64b, true), + +DEFINE_PROP_END_OF_LIST (), +}; +/* Deprecated entries marked for future removal */ const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[] = {MULTI_EXT_CFG_BOOL ("Zifencei" , ext_zifencei, true),@@ -1423,8 +1429,10 @@ Property riscv_cpu_options[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), -DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , cfg.cbom_blocksize,64 ), -DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , cfg.cboz_blocksize,64 ), +DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , + cfg.cbom_blocksize,CB_DEF_VALUE ), +DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , + cfg.cboz_blocksize,CB_DEF_VALUE ), DEFINE_PROP_END_OF_LIST(), };target/riscv/cpu.h +2
-0@@ -64,6 +64,8 @@ extern const uint32_t misa_bits[];const char *riscv_get_misa_ext_name (uint32_t bit);const char *riscv_get_misa_ext_description (uint32_t bit); +#define CB_DEF_VALUE 64 +#define CPU_CFG_OFFSET (_prop) offsetof(struct RISCVCPUConfig, _prop)/* Privileged specification version */
target/riscv/cpu.h typedef struct RISCVCPUMultiExtConfig { · line 750
Quoted 4 lines
target/riscv/cpu.h +1
-0@@ -745,6 +747,7 @@ typedef struct RISCVCPUMultiExtConfig {extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[];extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[];extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; +extern const RISCVCPUMultiExtConfig riscv_cpu_named_features[];
We should add a line like
riscv_obj_add_multiext_props(obj, qdict_out, riscv_cpu_named_features);
to cpu-model-expansion. zic64b is actually exactly what we need there in order to describe the blocksize with a boolean, since we don't have any way to expose the blocksize right now with that query.
Thanks,
drew
Re: [PATCH v5 01/10] target/riscv/tcg: add 'zic64b' support
In reply to Daniel Henrique BarbozaQuoted 14 lines · Daniel Henrique Barboza
zic64b is defined in the RVA22U64 profile [1] as a named feature for "Cache blocks must be 64 bytes in size, naturally aligned in the address space". It's a fantasy name for 64 bytes cache blocks. RVA22U64 mandates this feature, meaning that applications using it expects 64 bytes cache blocks.
In theory we're already compliant to it since we're using 64 bytes cache block sizes by default, but nothing is stopping users from enabling a profile and changing the cache block size at the same time.
We'll add zic64b as a 'named feature', not a regular extension, in a sense that we won't write it in riscv,isa. It'll be used solely to track whether the user changed cache sizes and if we should warn about it.
Quoted 8 lines
zic64b is default to 'true' since we're already using 64 bytes blocks. If any cache block size (
cbom_blocksizeorcboz_blocksize) is changed to something different than 64, zic64b is set to 'false' and, if zic64b was set to 'true' in the command line, also throw an user warning.Our profile implementation set mandatory extensions as if users enabled them in the command line, so this logic will extend to the future RVA22U64 implementation as well.
I talked with Andrew offline. We think that, ***for now***, it's overcomplicated and a bit confusing to have these half-extensions to be user set. Most of them are internal aspects of the implementation that we're already complying or something that do not apply to us (e.g. cache-related features).
We'll not show these flags to users. We'll also add more code in query-cpu-model-expansion to expose them, given that they won't be ordinary user flags like the others.
As for this patch, we'll not no longer expose zic64b to users. It'll be an internal flag that we'll enable or disable based on the blocksizes alone.
I emphasized 'for now' at the start because there's always the possibility of having to treat these named extensions more like regular expansions, adding them in riscv,isa and so on. That's not the case for now, so let's simplify while we can.
Thanks,
Daniel
Quoted 125 lines
[1] https://github.com/riscv/riscv-profiles/releases/download/v1.0/profiles.pdf
Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/riscv/cpu.c | 12 ++++++++++-- target/riscv/cpu.h | 3 +++ target/riscv/cpu_cfg.h | 1 + target/riscv/tcg/tcg-cpu.c | 26 ++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-)target/riscv/cpu.c +10
-2@@ -1394,6 +1394,12 @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { DEFINE_PROP_END_OF_LIST(), }; +const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = { +MULTI_EXT_CFG_BOOL ("zic64b" , zic64b, true), + +DEFINE_PROP_END_OF_LIST (), +}; +/* Deprecated entries marked for future removal */ const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[] = {MULTI_EXT_CFG_BOOL ("Zifencei" , ext_zifencei, true),@@ -1423,8 +1429,10 @@ Property riscv_cpu_options[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), -DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , cfg.cbom_blocksize,64 ), -DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , cfg.cboz_blocksize,64 ), +DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , + cfg.cbom_blocksize,CB_DEF_VALUE ), +DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , + cfg.cboz_blocksize,CB_DEF_VALUE ), DEFINE_PROP_END_OF_LIST(), };target/riscv/cpu.h +3
-0@@ -64,6 +64,8 @@ extern const uint32_t misa_bits[];const char *riscv_get_misa_ext_name (uint32_t bit);const char *riscv_get_misa_ext_description (uint32_t bit); +#define CB_DEF_VALUE 64 +#define CPU_CFG_OFFSET (_prop) offsetof(struct RISCVCPUConfig, _prop)/* Privileged specification version */ @@ -745,6 +747,7 @@ typedef struct RISCVCPUMultiExtConfig {extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[];extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[];extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; +extern const RISCVCPUMultiExtConfig riscv_cpu_named_features[];extern const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[];extern Property riscv_cpu_options[];target/riscv/cpu_cfg.h +1
-0@@ -107,6 +107,7 @@ struct RISCVCPUConfig {bool ext_smepmp;bool rvv_ta_all_1s;bool rvv_ma_all_1s; +bool zic64b;uint32_t mvendorid;uint64_t marchid;target/riscv/tcg/tcg-cpu.c +26
-0@@ -264,6 +264,27 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) } } +static void riscv_cpu_validate_zic64b (RISCVCPU *cpu) +{ +const char *warn ="zic64b set to 'true' but %s is set to %u. " +"zic64b changed to 'false'" ; +bool send_warn =cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (zic64b)); + +if (cpu->cfg.cbom_blocksize !=CB_DEF_VALUE ) { + cpu->cfg.zic64b = false; +if (send_warn) { +warn_report (warn,"cbom_blocksize" , cpu->cfg.cbom_blocksize); + } + } + +if (cpu->cfg.cboz_blocksize !=CB_DEF_VALUE ) { + cpu->cfg.zic64b = false; +if (send_warn) { +warn_report (warn,"cboz_blocksize" , cpu->cfg.cboz_blocksize); + } + } +} +/* * Check consistency between chosen extensions while setting * cpu->cfg accordingly. @@ -394,6 +415,10 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)return ; } +if (cpu->cfg.zic64b) { +riscv_cpu_validate_zic64b (cpu); + } +if (cpu->cfg.ext_zvfh) {cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zvfhmin), true); }@@ -889,6 +914,7 @@ static void riscv_cpu_add_user_properties(Object *obj)riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_extensions);riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_vendor_exts);riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_experimental_exts); +riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_named_features);riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_deprecated_exts);
PATCH v5 2/10 target/riscv: add rva22u64 profile definition
In reply to Daniel Henrique BarbozaThe rva22U64 profile, described in:
https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#rva22-profiles
Contains a set of CPU extensions aimed for 64-bit userspace applications. Enabling this set to be enabled via a single user flag makes it convenient to enable a predictable set of features for the CPU, giving users more predicability when running/testing their workloads.
QEMU implements all possible extensions of this profile. The exception is Zicbop (Cache-Block Prefetch Operations) that is not available since QEMU RISC-V does not implement a cache model. For this same reason all the so called 'synthetic extensions' described in the profile that are cache related are ignored (Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa, Zicclsm).
An abstraction called RISCVCPUProfile is created to store the profile. 'ext_offsets' contains mandatory extensions that QEMU supports. Same thing with the 'misa_ext' mask. Optional extensions must be enabled manually in the command line if desired.
The design here is to use the common target/riscv/cpu.c file to store the profile declaration and export it to the accelerator files. Each accelerator is then responsible to expose it (or not) to users and how to enable the extensions.
Next patches will implement the profile for TCG and KVM.
--- target/riscv/cpu.c | 31 +++++++++++++++++++++++++++++++ target/riscv/cpu.h | 12 ++++++++++++ 2 files changed, 43 insertions(+)
target/riscv/cpu.c +31 -0
@@ -1437,6 +1437,37 @@ Property riscv_cpu_options[] = { DEFINE_PROP_END_OF_LIST(), }; +/* +* RVA22U64 defines some 'named features' or 'synthetic extensions' +* that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa +* and Zicclsm. We do not implement caching in QEMU so we'll consider +* all these named features as always enabled. +* +* There's no riscv,isa update for them (and for zic64b) at this +* moment. +*/ +static RISCVCPUProfile RVA22U64 = { + .name ="rva22u64" , + .misa_ext =RVI |RVM |RVA |RVF |RVD |RVC , + .ext_offsets = { +CPU_CFG_OFFSET (ext_zicsr),CPU_CFG_OFFSET (ext_zihintpause), +CPU_CFG_OFFSET (ext_zba),CPU_CFG_OFFSET (ext_zbb), +CPU_CFG_OFFSET (ext_zbs),CPU_CFG_OFFSET (ext_zfhmin), +CPU_CFG_OFFSET (ext_zkt),CPU_CFG_OFFSET (ext_zicntr), +CPU_CFG_OFFSET (ext_zihpm),CPU_CFG_OFFSET (ext_zicbom), +CPU_CFG_OFFSET (ext_zicboz), + +/* mandatory named features for this profile */ +CPU_CFG_OFFSET (zic64b), + +RISCV_PROFILE_EXT_LIST_END + } +}; + +RISCVCPUProfile *riscv_profiles[] = { + &RVA22U64 ,NULL , +}; +static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("debug" ,RISCVCPU , cfg.debug, true),
target/riscv/cpu.h +12 -0
@@ -68,6 +68,18 @@ const char *riscv_get_misa_ext_description(uint32_t bit);#define CPU_CFG_OFFSET (_prop) offsetof(struct RISCVCPUConfig, _prop) +typedef struct riscv_cpu_profile { +const char *name; +uint32_t misa_ext; +bool enabled; +bool user_set; +const int32_t ext_offsets[]; +}RISCVCPUProfile ; + +#define RISCV_PROFILE_EXT_LIST_END -1 + +extern RISCVCPUProfile *riscv_profiles[]; +/* Privileged specification version */ enum {PRIV_VERSION_1_10_0 =0 ,
Signature · 1 line
2.41.0
Re: [PATCH v5 02/10] target/riscv: add rva22u64 profile definition
Quoted 4 lines · Daniel Henrique Barboza
The rva22U64 profile, described in:
https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc#rva22-profiles
Quoted 8 lines
Contains a set of CPU extensions aimed for 64-bit userspace applications. Enabling this set to be enabled via a single user flag makes it convenient to enable a predictable set of features for the CPU, giving users more predicability when running/testing their workloads.
QEMU implements all possible extensions of this profile. The exception is Zicbop (Cache-Block Prefetch Operations) that is not available since QEMU RISC-V does not implement a cache model.
I think we should add zicbop now. Its instructions won't cause illegal instruction traps according to commit 59cb29d6a514 ("target/riscv: add Zicbop cbo.prefetch{i, r, m} placeholder") and the instructions are just hints anyway, so there's no need for QEMU to implement anything. So, let's add the CPU property and its corresponding blocksize property, and when zicbop is enabled add it to the ISA string and when its blocksize isn't 64 bytes, disable zic64b.
Quoted 4 lines
For this same reason all
the so called 'synthetic extensions' described in the profile that are cache related are ignored (Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa, Zicclsm).
I won't ack/nack the exclusion of these, since I don't know enough about what they mean nor how TCG is or is not able to comply with what they mean. So I'll take your word for it that, at most, we'd need to add them to an ISA string to fully "support" them. OIOW, the current profile's only "fault" regarding these "extensions" is it isn't describing them in some way and fixing that wouldn't require any changes beyond extending the ISA string.
Quoted 25 lines
An abstraction called RISCVCPUProfile is created to store the profile. '
ext_offsets' contains mandatory extensions that QEMU supports. Same thing with the 'misa_ext' mask. Optional extensions must be enabled manually in the command line if desired.The design here is to use the common
target/riscv/cpu.cfile to store the profile declaration and export it to the accelerator files. Each accelerator is then responsible to expose it (or not) to users and how to enable the extensions.Next patches will implement the profile for TCG and KVM.
Signed-off-by Daniel Henrique Barboza <[email protected]>Acked-by Alistair Francis <[email protected]>--- target/riscv/cpu.c | 31 +++++++++++++++++++++++++++++++ target/riscv/cpu.h | 12 ++++++++++++ 2 files changed, 43 insertions(+)target/riscv/cpu.c +0
-0
target/riscv/cpu.c Property riscv_cpu_options[] = { · line 1441
Quoted 5 lines
target/riscv/cpu.c +2
-0@@ -1437,6 +1437,37 @@ Property riscv_cpu_options[] = { DEFINE_PROP_END_OF_LIST(), }; +/* +* RVA22U64 defines some 'named features' or 'synthetic extensions'
^ extra space
target/riscv/cpu.c Property riscv_cpu_options[] = { · line 1446
Quoted 5 lines
target/riscv/cpu.c +5
-0+* that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa +* and Zicclsm. We do not implement caching in QEMU so we'll consider +* all these named features as always enabled. +* +* There's no riscv,isa update for them (and for zic64b) at this
(nor for zic64b, despite it having a cfg offset)
Quoted 12 lines
target/riscv/cpu.c +12
-0+* moment. +*/ +static RISCVCPUProfile RVA22U64 = { + .name ="rva22u64" , + .misa_ext =RVI |RVM |RVA |RVF |RVD |RVC , + .ext_offsets = { +CPU_CFG_OFFSET (ext_zicsr),CPU_CFG_OFFSET (ext_zihintpause), +CPU_CFG_OFFSET (ext_zba),CPU_CFG_OFFSET (ext_zbb), +CPU_CFG_OFFSET (ext_zbs),CPU_CFG_OFFSET (ext_zfhmin), +CPU_CFG_OFFSET (ext_zkt),CPU_CFG_OFFSET (ext_zicntr), +CPU_CFG_OFFSET (ext_zihpm),CPU_CFG_OFFSET (ext_zicbom), +CPU_CFG_OFFSET (ext_zicboz),
target/riscv/cpu.c Property riscv_cpu_options[] = { · line 1468
Quoted 10 lines
target/riscv/cpu.c +10
-0+ +/* mandatory named features for this profile */ +CPU_CFG_OFFSET (zic64b), + + RISCV_PROFILE_EXT_LIST_END + } +}; + +RISCVCPUProfile *riscv_profiles[] = { + &RVA22U64 ,NULL ,
I'd put the NULL on its own line, otherwise when we add the next profile we'll need to modify the rva22u64 line too.
Quoted 31 lines
target/riscv/cpu.c +2
-0+}; +static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("debug" ,RISCVCPU , cfg.debug, true),target/riscv/cpu.h +12
-0@@ -68,6 +68,18 @@ const char *riscv_get_misa_ext_description(uint32_t bit);#define CPU_CFG_OFFSET (_prop) offsetof(struct RISCVCPUConfig, _prop) +typedef struct riscv_cpu_profile { +const char *name; +uint32_t misa_ext; +bool enabled; +bool user_set; +const int32_t ext_offsets[]; +}RISCVCPUProfile ; + +#define RISCV_PROFILE_EXT_LIST_END -1 + +extern RISCVCPUProfile *riscv_profiles[]; +/* Privileged specification version */ enum {PRIV_VERSION_1_10_0 =0 ,Signature · 1 line
2.41.0
Other than the nits and my wishy-washy-ness on the synthetic extensions,
Thanks,
drew
PATCH v5 3/10 target/riscv/kvm: add 'rva22u64' flag as unavailable
In reply to Daniel Henrique BarbozaKVM does not have the means to support enabling the rva22u64 profile. The main reasons are:
- we're missing support for some mandatory rva22u64 extensions in the KVM module;
- we can't make promises about enabling a profile since it all depends on host support in the end.
We'll revisit this decision in the future if needed. For now mark the 'rva22u64' profile as unavailable when running a KVM CPU:
$ qemu-system-riscv64 -machine virt,accel=kvm -cpu rv64,rva22u64=true
qemu-system-riscv64: can't apply global rv64-riscv-cpu.rva22u64=true:
'rva22u64' is not available with KVM--- target/riscv/kvm/kvm-cpu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
target/riscv/kvm/kvm-cpu.c +6 -1
@@ -393,7 +393,7 @@ static void cpu_set_cfg_unavailable(Object *obj, Visitor *v, }if (value) { -error_setg (errp,"extension %s is not available with KVM" , +error_setg (errp,"'%s' is not available with KVM" , propname); } }
@@ -474,6 +474,11 @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)riscv_cpu_add_kvm_unavail_prop_array (cpu_obj, riscv_cpu_extensions);riscv_cpu_add_kvm_unavail_prop_array (cpu_obj, riscv_cpu_vendor_exts);riscv_cpu_add_kvm_unavail_prop_array (cpu_obj, riscv_cpu_experimental_exts); + +/* We don't have the needed KVM support for profiles */ +for (i =0 ; riscv_profiles[i] !=NULL ; i++) { +riscv_cpu_add_kvm_unavail_prop (cpu_obj, riscv_profiles[i]->name); + } }static int kvm_riscv_get_regs_core (CPUState *cs)
Signature · 1 line
2.41.0
PATCH v5 4/10 target/riscv/tcg: add user flag for profile support
In reply to Daniel Henrique BarbozaThe TCG emulation implements all the extensions described in the RVA22U64 profile, both mandatory and optional. The mandatory extensions will be enabled via the profile flag. We'll leave the optional extensions to be enabled by hand.
Given that this is the first profile we're implementing in TCG we'll need some ground work first:
- all profiles declared in riscv_profiles[] will be exposed to users. TCG is the main accelerator we're considering when adding profile support in QEMU, so for now it's safe to assume that all profiles in riscv_profiles[] will be relevant to TCG;
- we'll not support user profile settings for vendor CPUs. The flags will still be exposed but users won't be able to change them. The idea is that vendor CPUs in the future can enable profiles internally in their cpu_init() functions, showing to the external world that the CPU supports a certain profile. But users won't be able to enable/disable it;
- Setting a profile to 'true' means 'enable all mandatory extensions of this profile, setting it to 'false' means disabling all its mandatory extensions. Regular left-to-right option order will determine the resulting CPU configuration, i.e. the following QEMU command line:
-cpu rv64,zicbom=false,zifencei=false,rva22u64=true
Enables all rva22u64 mandatory extensions, including 'zicbom' and 'zifencei', while this other command line:
-cpu rv64,rva22u64=true,zicbom=false,zifencei=false
Enables all mandatory rva22u64 extensions, and then disable both zicbom and zifencei.
For now we'll handle multi-letter extensions only. MISA extensions need additional steps that we'll take care later.
--- target/riscv/tcg/tcg-cpu.c | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
target/riscv/tcg/tcg-cpu.c +53 -0
@@ -794,6 +794,57 @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) } } +static void cpu_set_profile (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPUProfile *profile = opaque; +RISCVCPU *cpu =RISCV_CPU (obj); +bool value; +int i, ext_offset; + +if (object_dynamic_cast (obj,TYPE_RISCV_DYNAMIC_CPU ) ==NULL ) { +error_setg (errp,"Profile %s only available for generic CPUs" , + profile->name); +return ; + } + +if (!visit_type_bool (v, name, &value, errp)) { +return ; + } + + profile->user_set = true; + profile->enabled = value; + +for (i =0 ; profile->ext_offsets[i] !=RISCV_PROFILE_EXT_LIST_END ; i++) { + ext_offset = profile->ext_offsets[i]; + +g_hash_table_insert (multi_ext_user_opts, +GUINT_TO_POINTER (ext_offset), + (gpointer )profile->enabled); +isa_ext_update_enabled (cpu, ext_offset, profile->enabled); + } +} + +static void cpu_get_profile (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPUProfile *profile = opaque; +bool value = profile->enabled; + +visit_type_bool (v, name, &value, errp); +} + +static void riscv_cpu_add_profiles (Object *cpu_obj) +{ +for (int i =0 ; riscv_profiles[i] !=NULL ; i++) { +const RISCVCPUProfile *profile = riscv_profiles[i]; + +object_property_add (cpu_obj, profile->name,"bool" , + cpu_get_profile, cpu_set_profile, +NULL , (void *)profile); + } +} +static bool cpu_ext_is_deprecated (const char *ext_name) {return isupper (ext_name[0 ]);
@@ -918,6 +969,8 @@ static void riscv_cpu_add_user_properties(Object *obj)riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_deprecated_exts); +riscv_cpu_add_profiles (obj); +for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) {qdev_property_add_static (DEVICE (obj), prop); }
Signature · 1 line
2.41.0
PATCH v5 5/10 target/riscv/tcg: add MISA user options hash
In reply to Daniel Henrique BarbozaWe already track user choice for multi-letter extensions because we needed to honor user choice when enabling/disabling extensions during realize(). We refrained from adding the same mechanism for MISA extensions since we didn't need it.
Profile support requires tne need to check for user choice for MISA extensions, so let's add the corresponding hash now. It works like the existing multi-letter hash (multi_ext_user_opts) but tracking MISA bits options in the cpu_set_misa_ext_cfg() callback.
Note that we can't re-use the same hash from multi-letter extensions because that hash uses cpu->cfg offsets as keys, while for MISA extensions we're using MISA bits as keys.
After adding the user hash in cpu_set_misa_ext_cfg(), setting default values with object_property_set_bool() in add_misa_properties() will end up marking the user choice hash with them. Set the default value manually to avoid it.
--- target/riscv/tcg/tcg-cpu.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
target/riscv/tcg/tcg-cpu.c +14 -1
@@ -34,6 +34,7 @@/* Hash that stores user set extensions */ static GHashTable *multi_ext_user_opts; +static GHashTable *misa_ext_user_opts;static bool cpu_cfg_ext_is_user_set (uint32_t ext_offset) {
@@ -706,6 +707,10 @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,return ; } +g_hash_table_insert (misa_ext_user_opts, +GUINT_TO_POINTER (misa_bit), + (gpointer )value); + prev_val = env->misa_ext & misa_bit;if (value == prev_val) {
@@ -769,6 +774,7 @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {*/ static void riscv_cpu_add_misa_properties (Object *cpu_obj) { +CPURISCVState *env = &RISCV_CPU (cpu_obj)->env;bool use_def_vals =riscv_cpu_is_generic (cpu_obj);int i;
@@ -789,7 +795,13 @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) NULL, (void *)misa_cfg);object_property_set_description (cpu_obj, name, desc);if (use_def_vals) { -object_property_set_bool (cpu_obj, name, misa_cfg->enabled,NULL ); +if (misa_cfg->enabled) { + env->misa_ext |= bit; + env->misa_ext_mask |= bit; + }else { + env->misa_ext &= ~bit; + env->misa_ext_mask &= ~bit; + } } } }
@@ -1021,6 +1033,7 @@ static void tcg_cpu_instance_init(CPUState *cs)RISCVCPU *cpu =RISCV_CPU (cs);Object *obj =OBJECT (cpu); + misa_ext_user_opts =g_hash_table_new (NULL , g_direct_equal); multi_ext_user_opts =g_hash_table_new (NULL , g_direct_equal);riscv_cpu_add_user_properties (obj);
Signature · 1 line
2.41.0
PATCH v5 6/10 target/riscv/tcg: add riscv_cpu_write_misa_bit()
In reply to Daniel Henrique BarbozaWe have two instances of the setting/clearing a MISA bit from env->misa_ext and env->misa_ext_mask pattern. And the next patch will end up adding one more.
Create a helper to avoid code repetition.
--- target/riscv/tcg/tcg-cpu.c | 44 ++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-)
target/riscv/tcg/tcg-cpu.c +23 -21
@@ -42,6 +42,20 @@ static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) GUINT_TO_POINTER(ext_offset)); } +static void riscv_cpu_write_misa_bit (RISCVCPU *cpu,uint32_t bit, +bool enabled) +{ +CPURISCVState *env = &cpu->env; + +if (enabled) { + env->misa_ext |= bit; + env->misa_ext_mask |= bit; + }else { + env->misa_ext &= ~bit; + env->misa_ext_mask &= ~bit; + } +} +static void riscv_cpu_synchronize_from_tb (CPUState *cs,const TranslationBlock *tb) {
@@ -717,20 +731,14 @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,return ; } -if (value) { -if (!generic_cpu) { - g_autofree char *cpuname = riscv_cpu_get_name(cpu); -error_setg (errp,"'%s' CPU does not allow enabling extensions" , - cpuname); -return ; - } - - env->misa_ext |= misa_bit; - env->misa_ext_mask |= misa_bit; - }else { - env->misa_ext &= ~misa_bit; - env->misa_ext_mask &= ~misa_bit; +if (value && !generic_cpu) { + g_autofree char *cpuname = riscv_cpu_get_name(cpu); +error_setg (errp,"'%s' CPU does not allow enabling extensions" , + cpuname); +return ; } + +riscv_cpu_write_misa_bit (cpu, misa_bit, value); } static void cpu_get_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
@@ -774,7 +782,6 @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {*/ static void riscv_cpu_add_misa_properties (Object *cpu_obj) { -CPURISCVState *env = &RISCV_CPU (cpu_obj)->env;bool use_def_vals =riscv_cpu_is_generic (cpu_obj);int i;
@@ -795,13 +802,8 @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) NULL, (void *)misa_cfg);object_property_set_description (cpu_obj, name, desc);if (use_def_vals) { -if (misa_cfg->enabled) { - env->misa_ext |= bit; - env->misa_ext_mask |= bit; - }else { - env->misa_ext &= ~bit; - env->misa_ext_mask &= ~bit; - } +riscv_cpu_write_misa_bit (RISCV_CPU (cpu_obj), bit, + misa_cfg->enabled); } } }
Signature · 1 line
2.41.0
PATCH v5 7/10 target/riscv/tcg: handle profile MISA bits
In reply to Daniel Henrique BarbozaThe profile support is handling multi-letter extensions only. Let's add support for MISA bits as well.
We'll go through every known MISA bit. If the profile doesn't declare the bit as mandatory, ignore it. Otherwise, set or clear the bit in env->misa_ext and env->misa_ext_mask depending on whether the profile was set to 'true' or 'false'.
--- target/riscv/tcg/tcg-cpu.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
target/riscv/tcg/tcg-cpu.c +13 -0
@@ -829,6 +829,19 @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name, profile->user_set = true; profile->enabled = value; +for (i =0 ; misa_bits[i] !=0 ; i++) { +uint32_t bit = misa_bits[i]; + +if (!(profile->misa_ext & bit)) { +continue ; + } + +g_hash_table_insert (misa_ext_user_opts, +GUINT_TO_POINTER (bit), + (gpointer )value); +riscv_cpu_write_misa_bit (cpu, bit, profile->enabled); + } +for (i =0 ; profile->ext_offsets[i] !=RISCV_PROFILE_EXT_LIST_END ; i++) { ext_offset = profile->ext_offsets[i];
Signature · 1 line
2.41.0
PATCH v5 8/10 target/riscv/tcg: add hash table insert helpers
In reply to Daniel Henrique BarbozaLatest patches added several g_hash_table_insert() patterns. Add two helpers, one for each user hash, to make the code cleaner.
--- target/riscv/tcg/tcg-cpu.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
target/riscv/tcg/tcg-cpu.c +16 -12
@@ -42,6 +42,18 @@ static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) GUINT_TO_POINTER(ext_offset)); } +static void cpu_cfg_ext_add_user_opt (uint32_t ext_offset,bool value) +{ +g_hash_table_insert (multi_ext_user_opts,GUINT_TO_POINTER (ext_offset), + (gpointer )value); +} + +static void cpu_misa_ext_add_user_opt (uint32_t bit,bool value) +{ +g_hash_table_insert (misa_ext_user_opts,GUINT_TO_POINTER (bit), + (gpointer )value); +} +static void riscv_cpu_write_misa_bit (RISCVCPU *cpu,uint32_t bit,bool enabled) {
@@ -721,9 +733,7 @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,return ; } -g_hash_table_insert (misa_ext_user_opts, -GUINT_TO_POINTER (misa_bit), - (gpointer )value); +cpu_misa_ext_add_user_opt (misa_bit, value); prev_val = env->misa_ext & misa_bit;
@@ -836,18 +846,14 @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name,continue ; } -g_hash_table_insert (misa_ext_user_opts, -GUINT_TO_POINTER (bit), - (gpointer )value); +cpu_misa_ext_add_user_opt (bit, profile->enabled);riscv_cpu_write_misa_bit (cpu, bit, profile->enabled); }for (i =0 ; profile->ext_offsets[i] !=RISCV_PROFILE_EXT_LIST_END ; i++) { ext_offset = profile->ext_offsets[i]; -g_hash_table_insert (multi_ext_user_opts, -GUINT_TO_POINTER (ext_offset), - (gpointer )profile->enabled); +cpu_cfg_ext_add_user_opt (ext_offset, profile->enabled);isa_ext_update_enabled (cpu, ext_offset, profile->enabled); } }
@@ -910,9 +916,7 @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, multi_ext_cfg->name, lower); } -g_hash_table_insert (multi_ext_user_opts, -GUINT_TO_POINTER (multi_ext_cfg->offset), - (gpointer )value); +cpu_cfg_ext_add_user_opt (multi_ext_cfg->offset, value); prev_val =isa_ext_is_enabled (cpu, multi_ext_cfg->offset);
Signature · 1 line
2.41.0
PATCH v5 9/10 target/riscv/tcg: honor user choice for G MISA bits
In reply to Daniel Henrique BarbozaRVG behaves like a profile: a single flag enables a set of bits. Right now we're considering user choice when handling RVG and zicsr/zifencei and ignoring user choice on MISA bits.
We'll add user warnings for profiles when the user disables its mandatory extensions in the next patch. We'll do the same thing with RVG now to keep consistency between RVG and profile handling.
First and foremost, create a new RVG only helper to avoid clogging riscv_cpu_validate_set_extensions(). We do not want to annoy users with RVG warnings like we did in the past (see 9b9741c38f), thus we'll only warn if RVG was user set and the user disabled a RVG extension in the command line.
For every RVG MISA bit (IMAFD), zicsr and zifencei, the logic then becomes:
- if enabled, do nothing;
- if disabled and not user set, enable it;
- if disabled and user set, throw a warning that it's a RVG mandatory extension.
This same logic will be used for profiles in the next patch.
Note that this is a behavior change, where we would error out if the user disabled either zicsr or zifencei. As long as users are explicitly disabling things in the command line we'll let them have a go at it, at least in this step. We'll error out later in the validation if needed.
Other notable changes from the previous RVG code:
- use riscv_cpu_write_misa_bit() instead of manually updating both env->misa_ext and env->misa_ext_mask;
- set zicsr and zifencei directly. We're already checking if they were user set and priv version will never fail for these extensions, making cpu_cfg_ext_auto_update() redundant.
--- target/riscv/tcg/tcg-cpu.c | 73 +++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 25 deletions(-)
target/riscv/tcg/tcg-cpu.c +48 -25
@@ -42,6 +42,12 @@ static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) GUINT_TO_POINTER(ext_offset)); } +static bool cpu_misa_ext_is_user_set (uint32_t misa_bit) +{ +return g_hash_table_contains (misa_ext_user_opts, +GUINT_TO_POINTER (misa_bit)); +} +static void cpu_cfg_ext_add_user_opt (uint32_t ext_offset,bool value) { g_hash_table_insert(multi_ext_user_opts, GUINT_TO_POINTER(ext_offset),
@@ -312,6 +318,46 @@ static void riscv_cpu_validate_zic64b(RISCVCPU *cpu) } } +static void riscv_cpu_validate_g (RISCVCPU *cpu) +{ +const char *warn_msg ="RVG mandates disabled extension %s" ; +uint32_t g_misa_bits[] = {RVI ,RVM ,RVA ,RVF ,RVD }; +bool send_warn =cpu_misa_ext_is_user_set (RVG ); + +for (int i =0 ; i <ARRAY_SIZE (g_misa_bits); i++) { +uint32_t bit = g_misa_bits[i]; + +if (riscv_has_ext (&cpu->env, bit)) { +continue ; + } + +if (!cpu_misa_ext_is_user_set (bit)) { +riscv_cpu_write_misa_bit (cpu, bit, true); +continue ; + } + +if (send_warn) { +warn_report (warn_msg,riscv_get_misa_ext_name (bit)); + } + } + +if (!cpu->cfg.ext_zicsr) { +if (!cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zicsr))) { + cpu->cfg.ext_zicsr = true; + }else if (send_warn) { +warn_report (warn_msg,"zicsr" ); + } + } + +if (!cpu->cfg.ext_zifencei) { +if (!cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zifencei))) { + cpu->cfg.ext_zifencei = true; + }else if (send_warn) { +warn_report (warn_msg,"zifencei" ); + } + } +} +/* * Check consistency between chosen extensions while setting * cpu->cfg accordingly.
@@ -321,31 +367,8 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)CPURISCVState *env = &cpu->env;Error *local_err =NULL ; -/* Do some ISA extension error checking */ -if (riscv_has_ext (env,RVG ) && - !(riscv_has_ext (env,RVI ) &&riscv_has_ext (env,RVM ) && -riscv_has_ext (env,RVA ) &&riscv_has_ext (env,RVF ) && -riscv_has_ext (env,RVD ) && - cpu->cfg.ext_zicsr && cpu->cfg.ext_zifencei)) { - -if (cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zicsr)) && - !cpu->cfg.ext_zicsr) { -error_setg (errp,"RVG requires Zicsr but user set Zicsr to false" ); -return ; - } - -if (cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zifencei)) && - !cpu->cfg.ext_zifencei) { -error_setg (errp,"RVG requires Zifencei but user set " -"Zifencei to false" ); -return ; - } - -cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zicsr), true); -cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zifencei), true); - - env->misa_ext |=RVI |RVM |RVA |RVF |RVD ; - env->misa_ext_mask |=RVI |RVM |RVA |RVF |RVD ; +if (riscv_has_ext (env,RVG )) { +riscv_cpu_validate_g (cpu); }if (riscv_has_ext (env,RVI ) &&riscv_has_ext (env,RVE )) {
Signature · 1 line
2.41.0
PATCH v5 10/10 target/riscv/tcg: warn if profile exts are disabled
In reply to Daniel Henrique BarbozaEnabling a profile and then disabling some of its mandatory extensions is a valid use. It can be useful for debugging and testing. But the common expected use of enabling a profile is to enable all its mandatory extensions.
Add an user warning when mandatory extensions from an enabled profile are disabled in the command line, like we're already doing with RVG.
After this patch, this will throw warnings:
-cpu rv64,rva22u64=true,zihintpause=false,zicbom=false,zicboz=false
qemu-system-riscv64: warning: Profile rva22u64 mandates disabled extension zihintpause
qemu-system-riscv64: warning: Profile rva22u64 mandates disabled extension zicbom
qemu-system-riscv64: warning: Profile rva22u64 mandates disabled extension zicboz
Note that the following will NOT throw warnings because the profile is being enabled last, hence all its mandatory extensions will be enabled:
-cpu rv64,zihintpause=false,zicbom=false,zicboz=false,rva22u64=true
--- target/riscv/tcg/tcg-cpu.c | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
target/riscv/tcg/tcg-cpu.c +57 -0
@@ -147,6 +147,22 @@ static int cpu_cfg_ext_get_min_version(uint32_t ext_offset)g_assert_not_reached (); } +static const char *cpu_cfg_ext_get_name (uint32_t ext_offset) +{ +const RISCVIsaExtData *edata; + +for (edata = isa_edata_arr; edata && edata->name; edata++) { +if (edata->ext_enable_offset != ext_offset) { +continue ; + } + +return edata->name; + } + +g_assert_not_reached (); +} + +static void cpu_cfg_ext_auto_update (RISCVCPU *cpu,uint32_t ext_offset,bool value) {
@@ -644,11 +660,52 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)riscv_cpu_disable_priv_spec_isa_exts (cpu); } +static void riscv_cpu_validate_profile (RISCVCPU *cpu, +RISCVCPUProfile *profile) +{ +const char *warn_msg ="Profile %s mandates disabled extension %s" ; +int i; + +for (i =0 ; misa_bits[i] !=0 ; i++) { +uint32_t bit = misa_bits[i]; + +if (!(profile->misa_ext & bit)) { +continue ; + } + +if (!riscv_has_ext (&cpu->env, bit)) { +warn_report (warn_msg, profile->name,riscv_get_misa_ext_name (bit)); + } + } + +for (i =0 ; profile->ext_offsets[i] !=RISCV_PROFILE_EXT_LIST_END ; i++) { +int ext_offset = profile->ext_offsets[i]; + +if (!isa_ext_is_enabled (cpu, ext_offset)) { +warn_report (warn_msg, profile->name, +cpu_cfg_ext_get_name (ext_offset)); + } + } +} + +static void riscv_cpu_validate_profiles (RISCVCPU *cpu) +{ +for (int i =0 ; riscv_profiles[i] !=NULL ; i++) { +RISCVCPUProfile *profile = riscv_profiles[i]; + +if (profile->user_set && profile->enabled) { +riscv_cpu_validate_profile (cpu, profile); + } + } +} +void riscv_tcg_cpu_finalize_features (RISCVCPU *cpu,Error **errp) {CPURISCVState *env = &cpu->env;Error *local_err =NULL ; +riscv_cpu_validate_profiles (cpu); +riscv_cpu_validate_priv_spec (cpu, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);
Signature · 1 line
2.41.0