target/riscv: deprecate riscv_cpu_options[]
v4 cover target/riscv: deprecate riscv_cpu_options[]
Hi,
This new version contains changes due to a rebase with current riscv-to-apply.next, after "[PATCH v13 00/26] riscv: RVA22 profiles support" was queued.
Most notable change is a new patch (12) that was added to handle 'cbop_blocksize' - zicbop was added by the profile work that just got queued and was missing from v3.
A wrong 'cbom_blocksize' reference in patch 10 was also fixed.
Patches based on Alistair's riscv-to-apply.next.
Patches missing acks: 10, 12, 15, 16, 17
Changes from v3:
- patch 10:
- changed wrong cbom_blocksize ref to cboz_blocksize
- patch 12 (new):
- move cbop_blocksize to riscv_cpu_properties[]
- v3 link: https://lore.kernel.org/qemu-riscv/[email protected]/
Daniel Henrique Barboza (17):
target/riscv/cpu_cfg.h: remove unused fields
target/riscv: make riscv_cpu_is_vendor() public target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[] target/riscv: move 'mmu' to riscv_cpu_properties[] target/riscv: move 'pmp' to riscv_cpu_properties[] target/riscv: rework 'priv_spec'
target/riscv: rework 'vext_spec'
target/riscv: move 'vlen' to riscv_cpu_properties[] target/riscv: move 'elen' to riscv_cpu_properties[] target/riscv: create finalize_features() for KVM target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[] target/riscv: move 'cbop_blocksize' to riscv_cpu_properties[] target/riscv: move 'cboz_blocksize' to riscv_cpu_properties[] target/riscv: remove riscv_cpu_options[] target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[] target/riscv/cpu.c: move 'mimpid' to riscv_cpu_properties[] target/riscv/cpu.c: move 'marchid' to riscv_cpu_properties[]
target/riscv/cpu.c | 755 ++++++++++++++++++++++++++++------- target/riscv/cpu.h | 8 +- target/riscv/cpu_cfg.h | 4 - target/riscv/kvm/kvm-cpu.c | 94 +++-- target/riscv/kvm/kvm_riscv.h | 1 + target/riscv/tcg/tcg-cpu.c | 63 --- 6 files changed, 676 insertions(+), 249 deletions(-)
Signature · 1 line
2.43.0
PATCH v4 1/17 target/riscv/cpu_cfg.h: remove unused fields
user_spec, bext_spec and bext_ver aren't being used.
--- target/riscv/cpu.h | 1 - target/riscv/cpu_cfg.h | 2 -- 2 files changed, 3 deletions(-)
target/riscv/cpu.h +0 -1
@@ -180,7 +180,6 @@ struct CPUArchState {target_ulong guest_phys_fault_addr;target_ulong priv_ver; -target_ulong bext_ver;target_ulong vext_ver;/* RISCVMXL, but uint32_t for vmstate migration */
target/riscv/cpu_cfg.h +0 -2
@@ -140,8 +140,6 @@ struct RISCVCPUConfig {uint32_t pmu_mask;char *priv_spec; -char *user_spec; -char *bext_spec;char *vext_spec;uint16_t vlen;uint16_t elen;
Signature · 1 line
2.43.0
PATCH v4 2/17 target/riscv: make riscv_cpu_is_vendor() public
In reply to Daniel Henrique BarbozaWe'll use this function in target/riscv/cpu.c to implement setters that won't allow vendor CPU options to be changed.
--- target/riscv/cpu.c | 5 +++++ target/riscv/cpu.h | 1 + target/riscv/tcg/tcg-cpu.c | 5 ----- 3 files changed, 6 insertions(+), 5 deletions(-)
target/riscv/cpu.c +5 -0
@@ -190,6 +190,11 @@ void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en) *ext_enabled = en; } +bool riscv_cpu_is_vendor (Object *cpu_obj) +{ +return object_dynamic_cast (cpu_obj,TYPE_RISCV_VENDOR_CPU ) !=NULL ; +} +const char *const riscv_int_regnames[] = {"x0/zero" ,"x1/ra" ,"x2/sp" ,"x3/gp" ,"x4/tp" ,"x5/t0" ,"x6/t1" ,"x7/t2" ,"x8/s0" ,"x9/s1" ,"x10/a0" ,"x11/a1" ,"x12/a2" ,"x13/a3" ,
target/riscv/cpu.h +1 -0
@@ -773,6 +773,7 @@ enum riscv_pmu_event_idx {void isa_ext_update_enabled (RISCVCPU *cpu,uint32_t ext_offset,bool en);bool isa_ext_is_enabled (RISCVCPU *cpu,uint32_t ext_offset);void riscv_cpu_set_misa (CPURISCVState *env,RISCVMXL mxl,uint32_t ext); +bool riscv_cpu_is_vendor (Object *cpu_obj); typedef struct RISCVCPUMultiExtConfig { const char *name;
target/riscv/tcg/tcg-cpu.c +0 -5
@@ -917,11 +917,6 @@ static bool riscv_cpu_is_generic(Object *cpu_obj)return object_dynamic_cast (cpu_obj,TYPE_RISCV_DYNAMIC_CPU ) !=NULL ; } -static bool riscv_cpu_is_vendor (Object *cpu_obj) -{ -return object_dynamic_cast (cpu_obj,TYPE_RISCV_VENDOR_CPU ) !=NULL ; -} -/* * We'll get here via the following path: *
Signature · 1 line
2.43.0
PATCH v4 3/17 target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[]
In reply to Daniel Henrique BarbozaEvery property in riscv_cpu_options[] will be migrated to riscv_cpu_properties[]. This will make their default values init earlier, allowing cpu_init() functions to overwrite them. We'll also implement common getters and setters that both accelerators will use, allowing them to share validations that TCG is doing.
At the same time, some options (namely 'vlen', 'elen' and the cache blocksizes) need a way of tracking if the user set a value for them. This is benign for TCG since the cost of always validating these values are small, but for KVM we need syscalls to read the host values to make the validations, thus knowing whether the user didn't touch the values makes a difference.
We'll track user setting for these properties using a hash, like we do in the TCG driver. All riscv cpu options will update this hash in case the user sets it. The KVM driver will use this hash to minimize the amount of syscalls done.
For now, both 'pmu-mask' and 'pmu-num' shouldn't be changed for vendor CPUs. The existing setter for 'pmu-num' is changed to add this restriction. New getters and setters are required for 'pmu-mask'
While we're at it, add a 'static' modifier to 'prop_pmu_num' since we're not exporting it.
--- target/riscv/cpu.c | 91 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 7 deletions(-)
target/riscv/cpu.c +84 -7
@@ -58,6 +58,15 @@ bool riscv_cpu_is_32bit(RISCVCPU *cpu)return riscv_cpu_mxl (&cpu->env) ==MXL_RV32 ; } +/* Hash that stores general user set numeric options */ +static GHashTable *general_user_opts; + +static void cpu_option_add_user_setting (const char *optname,uint32_t value) +{ +g_hash_table_insert (general_user_opts, (gpointer )optname, +GUINT_TO_POINTER (value)); +} +#define ISA_EXT_DATA_ENTRY (_name, _min_ver, _prop) \ {#_name, _min_ver, CPU_CFG_OFFSET(_prop)}
@@ -1258,11 +1267,15 @@ static void riscv_cpu_post_init(Object *obj)static void riscv_cpu_init (Object *obj) { +RISCVCPU *cpu =RISCV_CPU (obj); +#ifndef CONFIG_USER_ONLY qdev_init_gpio_in (DEVICE (obj), riscv_cpu_set_irq,IRQ_LOCAL_MAX +IRQ_LOCAL_GUEST_MAX );#endif /* CONFIG_USER_ONLY */ + general_user_opts =g_hash_table_new (g_str_hash, g_str_equal); +/* * The timer and performance counters extensions were supported * in QEMU before they were added as discrete extensions in the
@@ -1272,6 +1285,9 @@ static void riscv_cpu_init(Object *obj)*/ RISCV_CPU (obj)->cfg.ext_zicntr = true;RISCV_CPU (obj)->cfg.ext_zihpm = true; + +/* Default values for non-bool cpu properties */ + cpu->cfg.pmu_mask =MAKE_64BIT_MASK (3 ,16 ); } typedef struct misa_ext_info {
@@ -1480,26 +1496,46 @@ const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[] = { DEFINE_PROP_END_OF_LIST(), }; +static void cpu_set_prop_err (RISCVCPU *cpu,const char *propname, +Error **errp) +{ + g_autofree char *cpuname = riscv_cpu_get_name(cpu); +error_setg (errp,"CPU '%s' does not allow changing the value of '%s'" , + cpuname, propname); +} +static void prop_pmu_num_set (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {RISCVCPU *cpu =RISCV_CPU (obj); -uint8_t pmu_num; +uint8_t pmu_num, curr_pmu_num; +uint32_t pmu_mask;visit_type_uint8 (v, name, &pmu_num, errp); + curr_pmu_num =ctpop32 (cpu->cfg.pmu_mask); + +if (pmu_num != curr_pmu_num &&riscv_cpu_is_vendor (obj)) { +cpu_set_prop_err (cpu, name, errp); +error_append_hint (errp,"Current '%s' val: %u\n" , + name, curr_pmu_num); +return ; + } +if (pmu_num > (RV_MAX_MHPMCOUNTERS -3 )) {error_setg (errp,"Number of counters exceeds maximum available" );return ; }if (pmu_num ==0 ) { - cpu->cfg.pmu_mask =0 ; + pmu_mask =0 ; }else { - cpu->cfg.pmu_mask =MAKE_64BIT_MASK (3 , pmu_num); + pmu_mask =MAKE_64BIT_MASK (3 , pmu_num); }warn_report ("\"pmu-num\" property is deprecated; use \"pmu-mask\"" ); + cpu->cfg.pmu_mask = pmu_mask; +cpu_option_add_user_setting ("pmu-mask" , pmu_mask); } static void prop_pmu_num_get(Object *obj, Visitor *v, const char *name,
@@ -1511,16 +1547,54 @@ static void prop_pmu_num_get(Object *obj, Visitor *v, const char *name,visit_type_uint8 (v, name, &pmu_num, errp); } -const PropertyInfo prop_pmu_num = { +static const PropertyInfo prop_pmu_num = { .name ="pmu-num" , .get = prop_pmu_num_get, .set = prop_pmu_num_set, }; -Property riscv_cpu_options[] = { -DEFINE_PROP_UINT32 ("pmu-mask" ,RISCVCPU , cfg.pmu_mask,MAKE_64BIT_MASK (3 ,16 )), - {.name ="pmu-num" , .info = &prop_pmu_num},/* Deprecated */ +static void prop_pmu_mask_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +uint32_t value; +uint8_t pmu_num; +visit_type_uint32 (v, name, &value, errp); + +if (value != cpu->cfg.pmu_mask &&riscv_cpu_is_vendor (obj)) { +cpu_set_prop_err (cpu, name, errp); +error_append_hint (errp,"Current '%s' val: %x\n" , + name, cpu->cfg.pmu_mask); +return ; + } + + pmu_num =ctpop32 (value); + +if (pmu_num > (RV_MAX_MHPMCOUNTERS -3 )) { +error_setg (errp,"Number of counters exceeds maximum available" ); +return ; + } + +cpu_option_add_user_setting (name, value); + cpu->cfg.pmu_mask = value; +} + +static void prop_pmu_mask_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint8_t pmu_mask =RISCV_CPU (obj)->cfg.pmu_mask; + +visit_type_uint8 (v, name, &pmu_mask, errp); +} + +static const PropertyInfo prop_pmu_mask = { + .name ="pmu-mask" , + .get = prop_pmu_mask_get, + .set = prop_pmu_mask_set, +}; + +Property riscv_cpu_options[] = {DEFINE_PROP_BOOL ("mmu" ,RISCVCPU , cfg.mmu, true),DEFINE_PROP_BOOL ("pmp" ,RISCVCPU , cfg.pmp, true),
@@ -1607,6 +1681,9 @@ RISCVCPUProfile *riscv_profiles[] = {static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("debug" ,RISCVCPU , cfg.debug, true), + {.name ="pmu-mask" , .info = &prop_pmu_mask}, + {.name ="pmu-num" , .info = &prop_pmu_num},/* Deprecated */ + #ifndef CONFIG_USER_ONLYDEFINE_PROP_UINT64 ("resetvec" ,RISCVCPU , env.resetvec,DEFAULT_RSTVEC ), #endif
Signature · 1 line
2.43.0
PATCH v4 4/17 target/riscv: move 'mmu' to riscv_cpu_properties[]
In reply to Daniel Henrique BarbozaCommit 7f0bdfb5bfc ("target/riscv/cpu.c: remove cfg setup from riscv_cpu_init()") already did some of the work by making some cpu_init() functions to explictly enable their own 'mmu' default.
The generic CPUs didn't get update by that commit, so they are still relying on the defaults set by the 'mmu' option. But having 'mmu' and 'pmp' being default=true will force CPUs that doesn't implement these options to set them to 'false' in their cpu_init(), which isn't ideal.
We'll move 'mmu' to riscv_cpu_properties[] without any defaults, i.e. the default will be 'false'. Compensate it by manually setting 'mmu = true' to the generic CPUs that requires it.
Implement a setter for it to forbid the 'mmu' setting to be changed for vendor CPUs. This will allow the option to exist for all CPUs and, at the same time, protect vendor CPUs from undesired changes:
$ ./build/qemu-system-riscv64 -M virt -cpu sifive-e51,mmu=true qemu-system-riscv64: can't apply global sifive-e51-riscv-cpu.mmu=true: CPU 'sifive-e51' does not allow changing the value of 'mmu'
--- target/riscv/cpu.c | 55 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-)
target/riscv/cpu.c +51 -4
@@ -437,6 +437,8 @@ static void riscv_max_cpu_init(Object *obj)CPURISCVState *env = &cpu->env;RISCVMXL mlx =MXL_RV64 ; + cpu->cfg.mmu = true; +#ifdef TARGET_RISCV32 mlx =MXL_RV32 ;#endif
@@ -451,7 +453,11 @@ static void riscv_max_cpu_init(Object *obj)#if defined(TARGET_RISCV64 )static void rv64_base_cpu_init (Object *obj) { -CPURISCVState *env = &RISCV_CPU (obj)->env; +RISCVCPU *cpu =RISCV_CPU (obj); +CPURISCVState *env = &cpu->env; + + cpu->cfg.mmu = true; +/* We set this in the realise function */ riscv_cpu_set_misa (env,MXL_RV64 ,0 );/* Set latest version of privileged specification */
@@ -569,13 +575,18 @@ static void rv64_veyron_v1_cpu_init(Object *obj)static void rv128_base_cpu_init (Object *obj) { +RISCVCPU *cpu =RISCV_CPU (obj); +CPURISCVState *env = &cpu->env; +if (qemu_tcg_mttcg_enabled ()) {/* Missing 128-bit aligned atomics */ error_report ("128-bit RISC-V currently does not work with Multi " "Threaded TCG. Please use: -accel tcg,thread=single" );exit (EXIT_FAILURE ); } -CPURISCVState *env = &RISCV_CPU (obj)->env; + + cpu->cfg.mmu = true; +/* We set this in the realise function */ riscv_cpu_set_misa (env,MXL_RV128 ,0 );/* Set latest version of privileged specification */
@@ -609,7 +620,11 @@ static void rv64i_bare_cpu_init(Object *obj)#else static void rv32_base_cpu_init (Object *obj) { -CPURISCVState *env = &RISCV_CPU (obj)->env; +RISCVCPU *cpu =RISCV_CPU (obj); +CPURISCVState *env = &cpu->env; + + cpu->cfg.mmu = true; +/* We set this in the realise function */ riscv_cpu_set_misa (env,MXL_RV32 ,0 );/* Set latest version of privileged specification */
@@ -1594,8 +1609,38 @@ static const PropertyInfo prop_pmu_mask = { .set = prop_pmu_mask_set, }; +static void prop_mmu_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +bool value; + +visit_type_bool (v, name, &value, errp); + +if (cpu->cfg.mmu != value &&riscv_cpu_is_vendor (obj)) { +cpu_set_prop_err (cpu,"mmu" , errp); +return ; + } + +cpu_option_add_user_setting (name, value); + cpu->cfg.mmu = value; +} + +static void prop_mmu_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool value =RISCV_CPU (obj)->cfg.mmu; + +visit_type_bool (v, name, &value, errp); +} + +static const PropertyInfo prop_mmu = { + .name ="mmu" , + .get = prop_mmu_get, + .set = prop_mmu_set, +}; +Property riscv_cpu_options[] = { -DEFINE_PROP_BOOL ("mmu" ,RISCVCPU , cfg.mmu, true),DEFINE_PROP_BOOL ("pmp" ,RISCVCPU , cfg.pmp, true),DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),
@@ -1684,6 +1729,8 @@ static Property riscv_cpu_properties[] = { {.name = "pmu-mask", .info = &prop_pmu_mask}, {.name = "pmu-num", .info = &prop_pmu_num}, /* Deprecated */ + {.name = "mmu", .info = &prop_mmu}, +#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),#endif
Signature · 1 line
2.43.0
PATCH v4 5/17 target/riscv: move 'pmp' to riscv_cpu_properties[]
In reply to Daniel Henrique BarbozaMove 'pmp' to riscv_cpu_properties[], creating a new setter() for it that forbids 'pmp' to be changed in vendor CPUs, like we did with the 'mmu' option.
We'll also have to manually set 'pmp = true' to generic CPUs that were still relying on the previous default to set it.
--- target/riscv/cpu.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
target/riscv/cpu.c +36 -2
@@ -438,6 +438,7 @@ static void riscv_max_cpu_init(Object *obj)RISCVMXL mlx =MXL_RV64 ; cpu->cfg.mmu = true; + cpu->cfg.pmp = true;#ifdef TARGET_RISCV32 mlx =MXL_RV32 ;
@@ -457,6 +458,7 @@ static void rv64_base_cpu_init(Object *obj)CPURISCVState *env = &cpu->env; cpu->cfg.mmu = true; + cpu->cfg.pmp = true;/* We set this in the realise function */ riscv_cpu_set_misa (env,MXL_RV64 ,0 );
@@ -586,6 +588,7 @@ static void rv128_base_cpu_init(Object *obj) } cpu->cfg.mmu = true; + cpu->cfg.pmp = true;/* We set this in the realise function */ riscv_cpu_set_misa (env,MXL_RV128 ,0 );
@@ -624,6 +627,7 @@ static void rv32_base_cpu_init(Object *obj)CPURISCVState *env = &cpu->env; cpu->cfg.mmu = true; + cpu->cfg.pmp = true;/* We set this in the realise function */ riscv_cpu_set_misa (env,MXL_RV32 ,0 );
@@ -1640,9 +1644,38 @@ static const PropertyInfo prop_mmu = { .set = prop_mmu_set, }; -Property riscv_cpu_options[] = { -DEFINE_PROP_BOOL ("pmp" ,RISCVCPU , cfg.pmp, true), +static void prop_pmp_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +bool value; + +visit_type_bool (v, name, &value, errp); +if (cpu->cfg.pmp != value &&riscv_cpu_is_vendor (obj)) { +cpu_set_prop_err (cpu, name, errp); +return ; + } + +cpu_option_add_user_setting (name, value); + cpu->cfg.pmp = value; +} + +static void prop_pmp_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool value =RISCV_CPU (obj)->cfg.pmp; + +visit_type_bool (v, name, &value, errp); +} + +static const PropertyInfo prop_pmp = { + .name ="pmp" , + .get = prop_pmp_get, + .set = prop_pmp_set, +}; + +Property riscv_cpu_options[] = {DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec),
@@ -1730,6 +1763,7 @@ static Property riscv_cpu_properties[] = { {.name = "pmu-num", .info = &prop_pmu_num}, /* Deprecated */ {.name = "mmu", .info = &prop_mmu}, + {.name = "pmp", .info = &prop_pmp},#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
Signature · 1 line
2.43.0
PATCH v4 6/17 target/riscv: rework 'priv_spec'
In reply to Daniel Henrique Barboza'priv_spec' and 'vext_spec' are two string options used as a fancy way of setting integers in the CPU state (cpu->env.priv_ver and cpu->env.vext_ver). It requires us to deal with string parsing and to store them in cpu_cfg.
We must support these string options, but we don't need to store them. We have a precedence for this kind of arrangement in target/ppc/compat.c, ppc_compat_prop_get|set, getters and setters used for the 'max-cpu-compat' class property of the pseries ppc64 machine. We'll do the same with both 'priv_spec' and 'vext_spec'.
For 'priv_spec', the validation from riscv_cpu_validate_priv_spec() will be done by the prop_priv_spec_set() setter, while also preventing it to be changed for vendor CPUs. Add two helpers that converts env->priv_ver back and forth to its string representation. These helpers allow us to get a string and set 'env->priv_ver' and return a string giving the current env->priv_ver value. In other words, make the cpu->cfg.priv_spec string obsolete.
Last but not the least, move the reworked 'priv_spec' option to riscv_cpu_properties[].
After all said and done, we don't need to store the 'priv_spec' string in the CPU state, and we're now protecting vendor CPUs from priv_ver changes:
$ ./build/qemu-system-riscv64 -M virt -cpu sifive-e51,priv_spec="v1.12.0"
qemu-system-riscv64: can't apply global sifive-e51-riscv-cpu.priv_spec=v1.12.0:
CPU 'sifive-e51' does not allow changing the value of 'priv_spec'
Current 'priv_spec' val: v1.10.0
$--- target/riscv/cpu.c | 73 +++++++++++++++++++++++++++++++++++++- target/riscv/cpu.h | 3 ++ target/riscv/cpu_cfg.h | 1 - target/riscv/tcg/tcg-cpu.c | 29 --------------- 4 files changed, 75 insertions(+), 31 deletions(-)
target/riscv/cpu.c +72 -1
@@ -1675,8 +1675,77 @@ static const PropertyInfo prop_pmp = { .set = prop_pmp_set, }; +static int priv_spec_from_str (const char *priv_spec_str) +{ +int priv_version =-1 ; + +if (!g_strcmp0 (priv_spec_str,PRIV_VER_1_12_0_STR )) { + priv_version =PRIV_VERSION_1_12_0 ; + }else if (!g_strcmp0 (priv_spec_str,PRIV_VER_1_11_0_STR )) { + priv_version =PRIV_VERSION_1_11_0 ; + }else if (!g_strcmp0 (priv_spec_str,PRIV_VER_1_10_0_STR )) { + priv_version =PRIV_VERSION_1_10_0 ; + } + +return priv_version; +} + +static const char *priv_spec_to_str (int priv_version) +{ +switch (priv_version) { +case PRIV_VERSION_1_10_0 : +return PRIV_VER_1_10_0_STR ; +case PRIV_VERSION_1_11_0 : +return PRIV_VER_1_11_0_STR ; +case PRIV_VERSION_1_12_0 : +return PRIV_VER_1_12_0_STR ; +default : +return NULL ; + } +} + +static void prop_priv_spec_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); + g_autofree char *value = NULL; +int priv_version =-1 ; + +visit_type_str (v, name, &value, errp); + + priv_version =priv_spec_from_str (value); +if (priv_version <0 ) { +error_setg (errp,"Unsupported privilege spec version '%s'" , value); +return ; + } + +if (priv_version != cpu->env.priv_ver &&riscv_cpu_is_vendor (obj)) { +cpu_set_prop_err (cpu, name, errp); +error_append_hint (errp,"Current '%s' val: %s\n" , name, +object_property_get_str (obj, name,NULL )); +return ; + } + +cpu_option_add_user_setting (name, priv_version); + cpu->env.priv_ver = priv_version; +} + +static void prop_priv_spec_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +const char *value =priv_spec_to_str (cpu->env.priv_ver); + +visit_type_str (v, name, (char **)&value, errp); +} + +static const PropertyInfo prop_priv_spec = { + .name ="priv_spec" , + .get = prop_priv_spec_get, + .set = prop_priv_spec_set, +}; +Property riscv_cpu_options[] = { -DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec),DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),
@@ -1765,6 +1834,8 @@ static Property riscv_cpu_properties[] = { {.name = "mmu", .info = &prop_mmu}, {.name = "pmp", .info = &prop_pmp}, + {.name = "priv_spec", .info = &prop_priv_spec}, +#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),#endif
target/riscv/cpu.h +3 -0
@@ -93,6 +93,9 @@ typedef struct riscv_cpu_profile {extern RISCVCPUProfile *riscv_profiles[];/* Privileged specification version */ +#define PRIV_VER_1_10_0_STR "v1.10.0" +#define PRIV_VER_1_11_0_STR "v1.11.0" +#define PRIV_VER_1_12_0_STR "v1.12.0"enum {PRIV_VERSION_1_10_0 =0 ,PRIV_VERSION_1_11_0 ,
target/riscv/cpu_cfg.h +0 -1
@@ -139,7 +139,6 @@ struct RISCVCPUConfig {bool ext_XVentanaCondOps;uint32_t pmu_mask; -char *priv_spec;char *vext_spec;uint16_t vlen;uint16_t elen;
target/riscv/tcg/tcg-cpu.c +0 -29
@@ -295,29 +295,6 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) } } -static void riscv_cpu_validate_priv_spec (RISCVCPU *cpu,Error **errp) -{ -CPURISCVState *env = &cpu->env; -int priv_version =-1 ; - -if (cpu->cfg.priv_spec) { -if (!g_strcmp0 (cpu->cfg.priv_spec,"v1.12.0" )) { - priv_version =PRIV_VERSION_1_12_0 ; - }else if (!g_strcmp0 (cpu->cfg.priv_spec,"v1.11.0" )) { - priv_version =PRIV_VERSION_1_11_0 ; - }else if (!g_strcmp0 (cpu->cfg.priv_spec,"v1.10.0" )) { - priv_version =PRIV_VERSION_1_10_0 ; - }else { -error_setg (errp, -"Unsupported privilege spec version '%s'" , - cpu->cfg.priv_spec); -return ; - } - - env->priv_ver = priv_version; - } -} -static void riscv_cpu_validate_v (CPURISCVState *env,RISCVCPUConfig *cfg,Error **errp) {
@@ -876,12 +853,6 @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)CPURISCVState *env = &cpu->env;Error *local_err =NULL ; -riscv_cpu_validate_priv_spec (cpu, &local_err); -if (local_err !=NULL ) { -error_propagate (errp, local_err); -return ; - } -riscv_cpu_validate_misa_priv (env, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);
Signature · 1 line
2.43.0
PATCH v4 7/17 target/riscv: rework 'vext_spec'
In reply to Daniel Henrique BarbozaThe same rework did in 'priv_spec' is done for 'vext_spec'. This time is simpler, since we only accept one value ("v1.0") and we'll always have env->vext_ver set to VEXT_VERSION_1_00_0, thus we don't need helpers to convert string to 'vext_ver' back and forth like we needed for 'priv_spec'.
--- target/riscv/cpu.c | 35 +++++++++++++++++++++++++++++++++-- target/riscv/cpu.h | 1 + target/riscv/cpu_cfg.h | 1 - target/riscv/tcg/tcg-cpu.c | 15 --------------- 4 files changed, 34 insertions(+), 18 deletions(-)
target/riscv/cpu.c +33 -2
@@ -1307,6 +1307,7 @@ static void riscv_cpu_init(Object *obj)/* Default values for non-bool cpu properties */ cpu->cfg.pmu_mask =MAKE_64BIT_MASK (3 ,16 ); + cpu->env.vext_ver =VEXT_VERSION_1_00_0 ; } typedef struct misa_ext_info {
@@ -1745,9 +1746,38 @@ static const PropertyInfo prop_priv_spec = { .set = prop_priv_spec_set, }; -Property riscv_cpu_options[] = { -DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec), +static void prop_vext_spec_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); + g_autofree char *value = NULL; +visit_type_str (v, name, &value, errp); + +if (g_strcmp0 (value,VEXT_VER_1_00_0_STR ) !=0 ) { +error_setg (errp,"Unsupported vector spec version '%s'" , value); +return ; + } + +cpu_option_add_user_setting (name,VEXT_VERSION_1_00_0 ); + cpu->env.vext_ver =VEXT_VERSION_1_00_0 ; +} + +static void prop_vext_spec_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +const char *value =VEXT_VER_1_00_0_STR ; + +visit_type_str (v, name, (char **)&value, errp); +} + +static const PropertyInfo prop_vext_spec = { + .name ="vext_spec" , + .get = prop_vext_spec_get, + .set = prop_vext_spec_set, +}; + +Property riscv_cpu_options[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ),
@@ -1835,6 +1865,7 @@ static Property riscv_cpu_properties[] = { {.name = "pmp", .info = &prop_pmp}, {.name = "priv_spec", .info = &prop_priv_spec}, + {.name = "vext_spec", .info = &prop_vext_spec},#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
target/riscv/cpu.h +1 -0
@@ -105,6 +105,7 @@ enum { };#define VEXT_VERSION_1_00_0 0x00010000 +#define VEXT_VER_1_00_0_STR "v1.0"enum {TRANSLATE_SUCCESS ,
target/riscv/cpu_cfg.h +0 -1
@@ -139,7 +139,6 @@ struct RISCVCPUConfig {bool ext_XVentanaCondOps;uint32_t pmu_mask; -char *vext_spec;uint16_t vlen;uint16_t elen;uint16_t cbom_blocksize;
target/riscv/tcg/tcg-cpu.c +0 -15
@@ -321,21 +321,6 @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, "in the range [8, 64]");return ; } - -if (cfg->vext_spec) { -if (!g_strcmp0 (cfg->vext_spec,"v1.0" )) { - env->vext_ver =VEXT_VERSION_1_00_0 ; - }else { -error_setg (errp,"Unsupported vector spec version '%s'" , - cfg->vext_spec); -return ; - } - }else if (env->vext_ver ==0 ) { -qemu_log ("vector version is not specified, " -"use the default value v1.0\n" ); - - env->vext_ver =VEXT_VERSION_1_00_0 ; - } }static void riscv_cpu_disable_priv_spec_isa_exts (RISCVCPU *cpu)
Signature · 1 line
2.43.0
PATCH v4 8/17 target/riscv: move 'vlen' to riscv_cpu_properties[]
In reply to Daniel Henrique BarbozaTurning 'vlen' into a class property will allow its default value to be overwritten by cpu_init() later on, solving the issue we have now where CPU specific settings are getting overwritten by the default.
Common validation bits are moved from riscv_cpu_validate_v() to prop_vlen_set() to be shared with KVM.
And, as done with every option we migrated to riscv_cpu_properties[], vendor CPUs can't have their 'vlen' value changed.
--- target/riscv/cpu.c | 45 +++++++++++++++++++++++++++++++++++++- target/riscv/tcg/tcg-cpu.c | 5 ----- 2 files changed, 44 insertions(+), 6 deletions(-)
target/riscv/cpu.c +44 -1
@@ -29,6 +29,7 @@#include "qapi/visitor.h" #include "qemu/error-report.h" #include "hw/qdev-properties.h" +#include "hw/core/qdev-prop-internal.h" #include "migration/vmstate.h" #include "fpu/softfloat-helpers.h" #include "sysemu/kvm.h"
@@ -1307,6 +1308,7 @@ static void riscv_cpu_init(Object *obj)/* Default values for non-bool cpu properties */ cpu->cfg.pmu_mask =MAKE_64BIT_MASK (3 ,16 ); + cpu->cfg.vlen =128 ; cpu->env.vext_ver =VEXT_VERSION_1_00_0 ; }
@@ -1777,8 +1779,47 @@ static const PropertyInfo prop_vext_spec = { .set = prop_vext_spec_set, }; +static void prop_vlen_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +uint16_t value; + +if (!visit_type_uint16 (v, name, &value, errp)) { +return ; + } + +if (!is_power_of_2 (value)) { +error_setg (errp,"Vector extension VLEN must be power of 2" ); +return ; + } + +if (value != cpu->cfg.vlen &&riscv_cpu_is_vendor (obj)) { +cpu_set_prop_err (cpu, name, errp); +error_append_hint (errp,"Current '%s' val: %u\n" , + name, cpu->cfg.vlen); +return ; + } + +cpu_option_add_user_setting (name, value); + cpu->cfg.vlen = value; +} + +static void prop_vlen_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint16_t value =RISCV_CPU (obj)->cfg.vlen; + +visit_type_uint16 (v, name, &value, errp); +} + +static const PropertyInfo prop_vlen = { + .name ="vlen" , + .get = prop_vlen_get, + .set = prop_vlen_set, +}; +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 ),
@@ -1867,6 +1908,8 @@ static Property riscv_cpu_properties[] = { {.name = "priv_spec", .info = &prop_priv_spec}, {.name = "vext_spec", .info = &prop_vext_spec}, + {.name = "vlen", .info = &prop_vlen}, +#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),#endif
target/riscv/tcg/tcg-cpu.c +0 -5
@@ -298,11 +298,6 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp)static void riscv_cpu_validate_v (CPURISCVState *env,RISCVCPUConfig *cfg,Error **errp) { -if (!is_power_of_2 (cfg->vlen)) { -error_setg (errp,"Vector extension VLEN must be power of 2" ); -return ; - } -if (cfg->vlen >RV_VLEN_MAX || cfg->vlen <128 ) {error_setg (errp, "Vector extension implementation only supports VLEN "
Signature · 1 line
2.43.0
PATCH v4 9/17 target/riscv: move 'elen' to riscv_cpu_properties[]
In reply to Daniel Henrique BarbozaDo the same thing we did with 'vlen' in the previous patch with 'elen'.
--- target/riscv/cpu.c | 44 ++++++++++++++++++++++++++++++++++++-- target/riscv/tcg/tcg-cpu.c | 5 ----- 2 files changed, 42 insertions(+), 7 deletions(-)
target/riscv/cpu.c +42 -2
@@ -1309,6 +1309,7 @@ static void riscv_cpu_init(Object *obj)/* Default values for non-bool cpu properties */ cpu->cfg.pmu_mask =MAKE_64BIT_MASK (3 ,16 ); cpu->cfg.vlen =128 ; + cpu->cfg.elen =64 ; cpu->env.vext_ver =VEXT_VERSION_1_00_0 ; }
@@ -1819,9 +1820,47 @@ static const PropertyInfo prop_vlen = { .set = prop_vlen_set, }; -Property riscv_cpu_options[] = { -DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +static void prop_elen_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +uint16_t value; + +if (!visit_type_uint16 (v, name, &value, errp)) { +return ; + } + +if (!is_power_of_2 (value)) { +error_setg (errp,"Vector extension ELEN must be power of 2" ); +return ; + } + +if (value != cpu->cfg.elen &&riscv_cpu_is_vendor (obj)) { +cpu_set_prop_err (cpu, name, errp); +error_append_hint (errp,"Current '%s' val: %u\n" , + name, cpu->cfg.elen); +return ; + } + +cpu_option_add_user_setting (name, value); + cpu->cfg.elen = value; +} +static void prop_elen_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint16_t value =RISCV_CPU (obj)->cfg.elen; + +visit_type_uint16 (v, name, &value, errp); +} + +static const PropertyInfo prop_elen = { + .name ="elen" , + .get = prop_elen_get, + .set = prop_elen_set, +}; + +Property riscv_cpu_options[] = {DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , cfg.cbom_blocksize,64 ),DEFINE_PROP_UINT16 ("cbop_blocksize" ,RISCVCPU , cfg.cbop_blocksize,64 ),DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , cfg.cboz_blocksize,64 ),
@@ -1909,6 +1948,7 @@ static Property riscv_cpu_properties[] = { {.name = "vext_spec", .info = &prop_vext_spec}, {.name = "vlen", .info = &prop_vlen}, + {.name = "elen", .info = &prop_elen},#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
target/riscv/tcg/tcg-cpu.c +0 -5
@@ -305,11 +305,6 @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,return ; } -if (!is_power_of_2 (cfg->elen)) { -error_setg (errp,"Vector extension ELEN must be power of 2" ); -return ; - } -if (cfg->elen >64 || cfg->elen <8 ) {error_setg (errp, "Vector extension implementation only supports ELEN "
Signature · 1 line
2.43.0
PATCH v4 10/17 target/riscv: create finalize_features() for KVM
In reply to Daniel Henrique BarbozaTo turn cbom_blocksize and cboz_blocksize into class properties we need KVM specific changes.
KVM is creating its own version of these options with a customized setter() that prevents users from picking an invalid value during init() time. This comes at the cost of duplicating each option that KVM supports. This will keep happening for each new shared option KVM implements in the future.
We can avoid that by using the same property TCG uses and adding specific KVM handling during finalize() time, like TCG already does with riscv_tcg_cpu_finalize_features(). To do that, the common CPU property offers a way of knowing if an option was user set or not, sparing us from doing unneeded syscalls.
riscv_kvm_cpu_finalize_features() is then created using the same KVMScratch CPU we already use during init() time, since finalize() time is still too early to use the official KVM CPU for it. cbom_blocksize and cboz_blocksize are then handled during finalize() in the same way they're handled by their KVM specific setter.
With this change we can proceed with the blocksize changes in the common code without breaking the KVM driver.
--- target/riscv/cpu.c | 16 +++++++--- target/riscv/cpu.h | 1 + target/riscv/kvm/kvm-cpu.c | 59 ++++++++++++++++++++++++++++++++++++ target/riscv/kvm/kvm_riscv.h | 1 + 4 files changed, 72 insertions(+), 5 deletions(-)
target/riscv/cpu.c +11 -5
@@ -68,6 +68,11 @@ static void cpu_option_add_user_setting(const char *optname, uint32_t value) GUINT_TO_POINTER(value)); } +bool riscv_cpu_option_set (const char *optname) +{ +return g_hash_table_contains (general_user_opts, optname); +} +#define ISA_EXT_DATA_ENTRY (_name, _min_ver, _prop) \ {#_name, _min_ver, CPU_CFG_OFFSET(_prop)}
@@ -1104,17 +1109,18 @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp) }#endif -/* -* KVM accel does not have a specialized finalize() -* callback because its extensions are validated -* in the get()/set() callbacks of each property. -*/ if (tcg_enabled ()) {riscv_tcg_cpu_finalize_features (cpu, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ; } + }else if (kvm_enabled ()) { +riscv_kvm_cpu_finalize_features (cpu, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + } } }
target/riscv/cpu.h +1 -0
@@ -510,6 +510,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, bool probe, uintptr_t retaddr);char *riscv_isa_string (RISCVCPU *cpu);void riscv_cpu_list (void ); +bool riscv_cpu_option_set (const char *optname);#define cpu_list riscv_cpu_list#define cpu_mmu_index riscv_cpu_mmu_index
target/riscv/kvm/kvm-cpu.c +59 -0
65 lines not on this page · raw message
target/riscv/kvm/kvm_riscv.h +1 -0
@@ -27,5 +27,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, uint64_t guest_num);void riscv_kvm_aplic_request (void *opaque,int irq,int level);int kvm_riscv_sync_mpstate_to_kvm (RISCVCPU *cpu,int state); +void riscv_kvm_cpu_finalize_features (RISCVCPU *cpu,Error **errp);#endif
Signature · 1 line
2.43.0
Re: [PATCH v4 10/17] target/riscv: create finalize_features() for KVM
Quoted 22 lines · Daniel Henrique Barboza
To turn
cbom_blocksizeandcboz_blocksizeinto class properties we need KVM specific changes.KVM is creating its own version of these options with a customized
setter()that prevents users from picking an invalid value duringinit()time. This comes at the cost of duplicating each option that KVM supports. This will keep happening for each new shared option KVM implements in the future.We can avoid that by using the same property TCG uses and adding specific KVM handling during
finalize()time, like TCG already does withriscv_tcg_cpu_finalize_features(). To do that, the common CPU property offers a way of knowing if an option was user set or not, sparing us from doing unneeded syscalls.
riscv_kvm_cpu_finalize_features()is then created using the same KVMScratch CPU we already use duringinit()time, sincefinalize()time is still too early to use the official KVM CPU for it.cbom_blocksizeandcboz_blocksizeare then handled duringfinalize()in the same way they're handled by their KVM specific setter.
Quoted 4 lines
With this change we can proceed with the blocksize changes in the common code without breaking the KVM driver.
Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 144 lines
--- target/riscv/cpu.c | 16 +++++++--- target/riscv/cpu.h | 1 + target/riscv/kvm/kvm-cpu.c | 59 ++++++++++++++++++++++++++++++++++++ target/riscv/kvm/kvm_riscv.h | 1 + 4 files changed, 72 insertions(+), 5 deletions(-)target/riscv/cpu.c +11
-5@@ -68,6 +68,11 @@ static void cpu_option_add_user_setting(const char *optname, uint32_t value) GUINT_TO_POINTER(value)); } +bool riscv_cpu_option_set (const char *optname) +{ +return g_hash_table_contains (general_user_opts, optname); +} +#define ISA_EXT_DATA_ENTRY (_name, _min_ver, _prop) \ {#_name, _min_ver, CPU_CFG_OFFSET(_prop)}@@ -1104,17 +1109,18 @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp) }#endif -/* -* KVM accel does not have a specialized finalize() -* callback because its extensions are validated -* in the get()/set() callbacks of each property. -*/ if (tcg_enabled ()) {riscv_tcg_cpu_finalize_features (cpu, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);return ; } + }else if (kvm_enabled ()) { +riscv_kvm_cpu_finalize_features (cpu, &local_err); +if (local_err !=NULL ) { +error_propagate (errp, local_err); +return ; + } } }target/riscv/cpu.h +1
-0@@ -510,6 +510,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, bool probe, uintptr_t retaddr);char *riscv_isa_string (RISCVCPU *cpu);void riscv_cpu_list (void ); +bool riscv_cpu_option_set (const char *optname);#define cpu_list riscv_cpu_list#define cpu_mmu_index riscv_cpu_mmu_indextarget/riscv/kvm/kvm-cpu.c +59
-0@@ -1493,6 +1493,65 @@ static void kvm_cpu_instance_init(CPUState *cs) } } +void riscv_kvm_cpu_finalize_features (RISCVCPU *cpu,Error **errp) +{ +CPURISCVState *env = &cpu->env; +KVMScratchCPU kvmcpu; +struct kvm_one_reg reg; +uint64_t val; +int ret; + +/* short-circuit without spinning the scratch CPU */ +if (!cpu->cfg.ext_zicbom && !cpu->cfg.ext_zicboz) { +return ; + } + +if (!kvm_riscv_create_scratch_vcpu (&kvmcpu)) { +error_setg (errp,"Unable to create scratch KVM cpu" ); +return ; + } + +if (cpu->cfg.ext_zicbom && +riscv_cpu_option_set (kvm_cbom_blocksize.name)) { + + reg.id =kvm_riscv_reg_id_ulong (env,KVM_REG_RISCV_CONFIG , + kvm_cbom_blocksize.kvm_reg_id); + reg.addr = (uint64_t )&val; + ret =ioctl (kvmcpu.cpufd,KVM_GET_ONE_REG , ®); +if (ret !=0 ) { +error_setg (errp,"Unable to read cbom_blocksize, error %d" , errno); +return ; + } + +if (cpu->cfg.cbom_blocksize != val) { +error_setg (errp,"Unable to set cbom_blocksize to a different " +"value than the host (%lu)" , val); +return ; + } + } + +if (cpu->cfg.ext_zicboz && +riscv_cpu_option_set (kvm_cboz_blocksize.name)) { + + reg.id =kvm_riscv_reg_id_ulong (env,KVM_REG_RISCV_CONFIG , + kvm_cboz_blocksize.kvm_reg_id); + reg.addr = (uint64_t )&val; + ret =ioctl (kvmcpu.cpufd,KVM_GET_ONE_REG , ®); +if (ret !=0 ) { +error_setg (errp,"Unable to read cboz_blocksize, error %d" , errno); +return ; + } + +if (cpu->cfg.cboz_blocksize != val) { +error_setg (errp,"Unable to set cboz_blocksize to a different " +"value than the host (%lu)" , val); +return ; + } + } + +kvm_riscv_destroy_scratch_vcpu (&kvmcpu); +} +static void kvm_cpu_accel_class_init (ObjectClass *oc,void *data) {AccelCPUClass *acc =ACCEL_CPU_CLASS (oc);target/riscv/kvm/kvm_riscv.h +1
-1@@ -27,5 +27,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, uint64_t guest_num);void riscv_kvm_aplic_request (void *opaque,int irq,int level);int kvm_riscv_sync_mpstate_to_kvm (RISCVCPU *cpu,int state); +void riscv_kvm_cpu_finalize_features (RISCVCPU *cpu,Error **errp);#endif --2.43.0
PATCH v4 11/17 target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[]
In reply to Daniel Henrique BarbozaAfter adding a KVM finalize() implementation, turn cbom_blocksize into a class property. Follow the same design we used with 'vlen' and 'elen'.
The duplicated 'cbom_blocksize' KVM property can be removed from kvm_riscv_add_cpu_user_properties().
--- target/riscv/cpu.c | 39 +++++++++++++++++++++++++++++++++++++- target/riscv/kvm/kvm-cpu.c | 4 ---- 2 files changed, 38 insertions(+), 5 deletions(-)
target/riscv/cpu.c +38 -1
@@ -1316,6 +1316,7 @@ static void riscv_cpu_init(Object *obj) cpu->cfg.pmu_mask =MAKE_64BIT_MASK (3 ,16 ); cpu->cfg.vlen =128 ; cpu->cfg.elen =64 ; + cpu->cfg.cbom_blocksize =64 ; cpu->env.vext_ver =VEXT_VERSION_1_00_0 ; }
@@ -1866,8 +1867,42 @@ static const PropertyInfo prop_elen = { .set = prop_elen_set, }; +static void prop_cbom_blksize_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +uint16_t value; + +if (!visit_type_uint16 (v, name, &value, errp)) { +return ; + } + +if (value != cpu->cfg.cbom_blocksize &&riscv_cpu_is_vendor (obj)) { +cpu_set_prop_err (cpu, name, errp); +error_append_hint (errp,"Current '%s' val: %u\n" , + name, cpu->cfg.cbom_blocksize); +return ; + } + +cpu_option_add_user_setting (name, value); + cpu->cfg.cbom_blocksize = value; +} + +static void prop_cbom_blksize_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint16_t value =RISCV_CPU (obj)->cfg.cbom_blocksize; + +visit_type_uint16 (v, name, &value, errp); +} + +static const PropertyInfo prop_cbom_blksize = { + .name ="cbom_blocksize" , + .get = prop_cbom_blksize_get, + .set = prop_cbom_blksize_set, +}; +Property riscv_cpu_options[] = { -DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , cfg.cbom_blocksize,64 ),DEFINE_PROP_UINT16 ("cbop_blocksize" ,RISCVCPU , cfg.cbop_blocksize,64 ),DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , cfg.cboz_blocksize,64 ),
@@ -1956,6 +1991,8 @@ static Property riscv_cpu_properties[] = { {.name = "vlen", .info = &prop_vlen}, {.name = "elen", .info = &prop_elen}, + {.name = "cbom_blocksize", .info = &prop_cbom_blksize}, +#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),#endif
target/riscv/kvm/kvm-cpu.c +0 -4
@@ -484,10 +484,6 @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) NULL, multi_cfg); } -object_property_add (cpu_obj,"cbom_blocksize" ,"uint16" , -NULL , kvm_cpu_set_cbomz_blksize, -NULL , &kvm_cbom_blocksize); -object_property_add (cpu_obj,"cboz_blocksize" ,"uint16" ,NULL , kvm_cpu_set_cbomz_blksize,NULL , &kvm_cboz_blocksize);
Signature · 1 line
2.43.0
PATCH v4 12/17 target/riscv: move 'cbop_blocksize' to riscv_cpu_properties[]
In reply to Daniel Henrique BarbozaDo the same we did with 'cbom_blocksize' in the previous patch.
--- target/riscv/cpu.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
target/riscv/cpu.c +37 -1
@@ -1317,6 +1317,7 @@ static void riscv_cpu_init(Object *obj) cpu->cfg.vlen =128 ; cpu->cfg.elen =64 ; cpu->cfg.cbom_blocksize =64 ; + cpu->cfg.cbop_blocksize =64 ; cpu->env.vext_ver =VEXT_VERSION_1_00_0 ; }
@@ -1902,8 +1903,42 @@ static const PropertyInfo prop_cbom_blksize = { .set = prop_cbom_blksize_set, }; +static void prop_cbop_blksize_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +uint16_t value; + +if (!visit_type_uint16 (v, name, &value, errp)) { +return ; + } + +if (value != cpu->cfg.cbop_blocksize &&riscv_cpu_is_vendor (obj)) { +cpu_set_prop_err (cpu, name, errp); +error_append_hint (errp,"Current '%s' val: %u\n" , + name, cpu->cfg.cbop_blocksize); +return ; + } + +cpu_option_add_user_setting (name, value); + cpu->cfg.cbop_blocksize = value; +} + +static void prop_cbop_blksize_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint16_t value =RISCV_CPU (obj)->cfg.cbop_blocksize; + +visit_type_uint16 (v, name, &value, errp); +} + +static const PropertyInfo prop_cbop_blksize = { + .name ="cbop_blocksize" , + .get = prop_cbop_blksize_get, + .set = prop_cbop_blksize_set, +}; +Property riscv_cpu_options[] = { -DEFINE_PROP_UINT16 ("cbop_blocksize" ,RISCVCPU , cfg.cbop_blocksize,64 ),DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , cfg.cboz_blocksize,64 ),DEFINE_PROP_END_OF_LIST (),
@@ -1992,6 +2027,7 @@ static Property riscv_cpu_properties[] = { {.name = "elen", .info = &prop_elen}, {.name = "cbom_blocksize", .info = &prop_cbom_blksize}, + {.name = "cbop_blocksize", .info = &prop_cbop_blksize},#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
Signature · 1 line
2.43.0
Re: [PATCH v4 12/17] target/riscv: move 'cbop_blocksize' to riscv_cpu_properties[]
Quoted 4 lines · Daniel Henrique Barboza
Do the same we did with '
cbom_blocksize' in the previous patch.Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 72 lines
--- target/riscv/cpu.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)target/riscv/cpu.c +37
-2@@ -1317,6 +1317,7 @@ static void riscv_cpu_init(Object *obj) cpu->cfg.vlen =128 ; cpu->cfg.elen =64 ; cpu->cfg.cbom_blocksize =64 ; + cpu->cfg.cbop_blocksize =64 ; cpu->env.vext_ver =VEXT_VERSION_1_00_0 ; }@@ -1902,8 +1903,42 @@ static const PropertyInfo prop_cbom_blksize = { .set = prop_cbom_blksize_set, }; +static void prop_cbop_blksize_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +uint16_t value; + +if (!visit_type_uint16 (v, name, &value, errp)) { +return ; + } + +if (value != cpu->cfg.cbop_blocksize &&riscv_cpu_is_vendor (obj)) { +cpu_set_prop_err (cpu, name, errp); +error_append_hint (errp,"Current '%s' val: %u\n" , + name, cpu->cfg.cbop_blocksize); +return ; + } + +cpu_option_add_user_setting (name, value); + cpu->cfg.cbop_blocksize = value; +} + +static void prop_cbop_blksize_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint16_t value =RISCV_CPU (obj)->cfg.cbop_blocksize; + +visit_type_uint16 (v, name, &value, errp); +} + +static const PropertyInfo prop_cbop_blksize = { + .name ="cbop_blocksize" , + .get = prop_cbop_blksize_get, + .set = prop_cbop_blksize_set, +}; +Property riscv_cpu_options[] = { -DEFINE_PROP_UINT16 ("cbop_blocksize" ,RISCVCPU , cfg.cbop_blocksize,64 ),DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , cfg.cboz_blocksize,64 ),DEFINE_PROP_END_OF_LIST (),@@ -1992,6 +2027,7 @@ static Property riscv_cpu_properties[] = { {.name = "elen", .info = &prop_elen}, {.name = "cbom_blocksize", .info = &prop_cbom_blksize}, + {.name = "cbop_blocksize", .info = &prop_cbop_blksize},#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC), --2.43.0
PATCH v4 13/17 target/riscv: move 'cboz_blocksize' to riscv_cpu_properties[]
In reply to Daniel Henrique BarbozaAnd remove the now unused kvm_cpu_set_cbomz_blksize() setter.
--- target/riscv/cpu.c | 38 +++++++++++++++++++++++++++++++++++++- target/riscv/kvm/kvm-cpu.c | 28 ---------------------------- 2 files changed, 37 insertions(+), 29 deletions(-)
target/riscv/cpu.c +37 -1
@@ -1318,6 +1318,7 @@ static void riscv_cpu_init(Object *obj) cpu->cfg.elen =64 ; cpu->cfg.cbom_blocksize =64 ; cpu->cfg.cbop_blocksize =64 ; + cpu->cfg.cboz_blocksize =64 ; cpu->env.vext_ver =VEXT_VERSION_1_00_0 ; }
@@ -1938,8 +1939,42 @@ static const PropertyInfo prop_cbop_blksize = { .set = prop_cbop_blksize_set, }; +static void prop_cboz_blksize_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +uint16_t value; + +if (!visit_type_uint16 (v, name, &value, errp)) { +return ; + } + +if (value != cpu->cfg.cboz_blocksize &&riscv_cpu_is_vendor (obj)) { +cpu_set_prop_err (cpu, name, errp); +error_append_hint (errp,"Current '%s' val: %u\n" , + name, cpu->cfg.cboz_blocksize); +return ; + } + +cpu_option_add_user_setting (name, value); + cpu->cfg.cboz_blocksize = value; +} + +static void prop_cboz_blksize_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint16_t value =RISCV_CPU (obj)->cfg.cboz_blocksize; + +visit_type_uint16 (v, name, &value, errp); +} + +static const PropertyInfo prop_cboz_blksize = { + .name ="cboz_blocksize" , + .get = prop_cboz_blksize_get, + .set = prop_cboz_blksize_set, +}; +Property riscv_cpu_options[] = { -DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , cfg.cboz_blocksize,64 ),DEFINE_PROP_END_OF_LIST (), };
@@ -2028,6 +2063,7 @@ static Property riscv_cpu_properties[] = { {.name = "cbom_blocksize", .info = &prop_cbom_blksize}, {.name = "cbop_blocksize", .info = &prop_cbop_blksize}, + {.name = "cboz_blocksize", .info = &prop_cboz_blksize},#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
target/riscv/kvm/kvm-cpu.c +0 -28
@@ -343,30 +343,6 @@ static KVMCPUConfig kvm_cboz_blocksize = { .kvm_reg_id = KVM_REG_RISCV_CONFIG_REG(zicboz_block_size) }; -static void kvm_cpu_set_cbomz_blksize (Object *obj,Visitor *v, -const char *name, -void *opaque,Error **errp) -{ -KVMCPUConfig *cbomz_cfg = opaque; -RISCVCPU *cpu =RISCV_CPU (obj); -uint16_t value, *host_val; - -if (!visit_type_uint16 (v, name, &value, errp)) { -return ; - } - - host_val =kvmconfig_get_cfg_addr (cpu, cbomz_cfg); - -if (value != *host_val) { -error_report ("Unable to set %s to a different value than " -"the host (%u)" , - cbomz_cfg->name, *host_val); -exit (EXIT_FAILURE ); - } - - cbomz_cfg->user_set = true; -} -static void kvm_riscv_update_cpu_cfg_isa_ext (RISCVCPU *cpu,CPUState *cs) {CPURISCVState *env = &cpu->env;
@@ -484,10 +460,6 @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) NULL, multi_cfg); } -object_property_add (cpu_obj,"cboz_blocksize" ,"uint16" , -NULL , kvm_cpu_set_cbomz_blksize, -NULL , &kvm_cboz_blocksize); -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);
Signature · 1 line
2.43.0
PATCH v4 14/17 target/riscv: remove riscv_cpu_options[]
In reply to Daniel Henrique BarbozaThe array is empty and can be removed.
--- target/riscv/cpu.c | 5 ----- target/riscv/cpu.h | 1 - target/riscv/kvm/kvm-cpu.c | 9 --------- target/riscv/tcg/tcg-cpu.c | 4 ---- 4 files changed, 19 deletions(-)
target/riscv/cpu.c +0 -5
@@ -1974,11 +1974,6 @@ static const PropertyInfo prop_cboz_blksize = { .set = prop_cboz_blksize_set, }; -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
target/riscv/cpu.h +0 -1
@@ -791,7 +791,6 @@ 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[]; typedef struct isa_ext_data { const char *name;
target/riscv/kvm/kvm-cpu.c +0 -9
@@ -1446,19 +1446,10 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,static void kvm_cpu_instance_init (CPUState *cs) {Object *obj =OBJECT (RISCV_CPU (cs)); -DeviceState *dev =DEVICE (obj);riscv_init_kvm_registers (obj);kvm_riscv_add_cpu_user_properties (obj); - -for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) { -/* Check if we have a specific KVM handler for the option */ -if (object_property_find (obj, prop->name)) { -continue ; - } -qdev_property_add_static (dev, prop); - } }void riscv_kvm_cpu_finalize_features (RISCVCPU *cpu,Error **errp)
target/riscv/tcg/tcg-cpu.c +0 -4
@@ -1267,10 +1267,6 @@ 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.43.0
PATCH v4 15/17 target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[]
In reply to Daniel Henrique BarbozaKeep all class properties in riscv_cpu_properties[].
--- target/riscv/cpu.c | 69 +++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 32 deletions(-)
target/riscv/cpu.c +37 -32
@@ -1974,6 +1974,41 @@ static const PropertyInfo prop_cboz_blksize = { .set = prop_cboz_blksize_set, }; +static void prop_mvendorid_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool dynamic_cpu =riscv_cpu_is_dynamic (obj); +RISCVCPU *cpu =RISCV_CPU (obj); +uint32_t prev_val = cpu->cfg.mvendorid; +uint32_t value; + +if (!visit_type_uint32 (v, name, &value, errp)) { +return ; + } + +if (!dynamic_cpu && prev_val != value) { +error_setg (errp,"Unable to change %s mvendorid (0x%x)" , +object_get_typename (obj), prev_val); +return ; + } + + cpu->cfg.mvendorid = value; +} + +static void prop_mvendorid_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint32_t value =RISCV_CPU (obj)->cfg.mvendorid; + +visit_type_uint32 (v, name, &value, errp); +} + +static const PropertyInfo prop_mvendorid = { + .name ="mvendorid" , + .get = prop_mvendorid_get, + .set = prop_mvendorid_set, +}; +/* * RVA22U64 defines some 'named features' or 'synthetic extensions' * that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa
@@ -2060,6 +2095,8 @@ static Property riscv_cpu_properties[] = { {.name = "cbop_blocksize", .info = &prop_cbop_blksize}, {.name = "cboz_blocksize", .info = &prop_cboz_blksize}, + {.name = "mvendorid", .info = &prop_mvendorid}, +#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),#endif
@@ -2140,35 +2177,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = { };#endif -static void cpu_set_mvendorid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -bool dynamic_cpu =riscv_cpu_is_dynamic (obj); -RISCVCPU *cpu =RISCV_CPU (obj); -uint32_t prev_val = cpu->cfg.mvendorid; -uint32_t value; - -if (!visit_type_uint32 (v, name, &value, errp)) { -return ; - } - -if (!dynamic_cpu && prev_val != value) { -error_setg (errp,"Unable to change %s mvendorid (0x%x)" , -object_get_typename (obj), prev_val); -return ; - } - - cpu->cfg.mvendorid = value; -} - -static void cpu_get_mvendorid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint32_t value =RISCV_CPU (obj)->cfg.mvendorid; - -visit_type_uint32 (v, name, &value, errp); -} -static void cpu_set_mimpid (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
@@ -2278,9 +2286,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->gdb_arch_name = riscv_gdb_arch_name; cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; -object_class_property_add (c,"mvendorid" ,"uint32" , cpu_get_mvendorid, - cpu_set_mvendorid,NULL ,NULL ); -object_class_property_add (c,"mimpid" ,"uint64" , cpu_get_mimpid, cpu_set_mimpid,NULL ,NULL );
Signature · 1 line
2.43.0
Re: [PATCH v4 15/17] target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[]
Quoted 4 lines · Daniel Henrique Barboza
Keep all class properties in riscv_cpu_properties[].
Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 109 lines
--- target/riscv/cpu.c | 69 +++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 32 deletions(-)target/riscv/cpu.c +37
-33@@ -1974,6 +1974,41 @@ static const PropertyInfo prop_cboz_blksize = { .set = prop_cboz_blksize_set, }; +static void prop_mvendorid_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool dynamic_cpu =riscv_cpu_is_dynamic (obj); +RISCVCPU *cpu =RISCV_CPU (obj); +uint32_t prev_val = cpu->cfg.mvendorid; +uint32_t value; + +if (!visit_type_uint32 (v, name, &value, errp)) { +return ; + } + +if (!dynamic_cpu && prev_val != value) { +error_setg (errp,"Unable to change %s mvendorid (0x%x)" , +object_get_typename (obj), prev_val); +return ; + } + + cpu->cfg.mvendorid = value; +} + +static void prop_mvendorid_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint32_t value =RISCV_CPU (obj)->cfg.mvendorid; + +visit_type_uint32 (v, name, &value, errp); +} + +static const PropertyInfo prop_mvendorid = { + .name ="mvendorid" , + .get = prop_mvendorid_get, + .set = prop_mvendorid_set, +}; +/* * RVA22U64 defines some 'named features' or 'synthetic extensions' * that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa @@ -2060,6 +2095,8 @@ static Property riscv_cpu_properties[] = { {.name = "cbop_blocksize", .info = &prop_cbop_blksize}, {.name = "cboz_blocksize", .info = &prop_cboz_blksize}, + {.name = "mvendorid", .info = &prop_mvendorid}, +#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),#endif @@ -2140,35 +2177,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = { };#endif -static void cpu_set_mvendorid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -bool dynamic_cpu =riscv_cpu_is_dynamic (obj); -RISCVCPU *cpu =RISCV_CPU (obj); -uint32_t prev_val = cpu->cfg.mvendorid; -uint32_t value; - -if (!visit_type_uint32 (v, name, &value, errp)) { -return ; - } - -if (!dynamic_cpu && prev_val != value) { -error_setg (errp,"Unable to change %s mvendorid (0x%x)" , -object_get_typename (obj), prev_val); -return ; - } - - cpu->cfg.mvendorid = value; -} - -static void cpu_get_mvendorid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint32_t value =RISCV_CPU (obj)->cfg.mvendorid; - -visit_type_uint32 (v, name, &value, errp); -} -static void cpu_set_mimpid (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {@@ -2278,9 +2286,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->gdb_arch_name = riscv_gdb_arch_name; cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; -object_class_property_add (c,"mvendorid" ,"uint32" , cpu_get_mvendorid, - cpu_set_mvendorid,NULL ,NULL ); -object_class_property_add (c,"mimpid" ,"uint64" , cpu_get_mimpid, cpu_set_mimpid,NULL ,NULL ); --2.43.0
PATCH v4 16/17 target/riscv/cpu.c: move 'mimpid' to riscv_cpu_properties[]
In reply to Daniel Henrique BarbozaKeep all class properties in riscv_cpu_properties[].
--- target/riscv/cpu.c | 68 ++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 32 deletions(-)
target/riscv/cpu.c +36 -32
@@ -2009,6 +2009,41 @@ static const PropertyInfo prop_mvendorid = { .set = prop_mvendorid_set, }; +static void prop_mimpid_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool dynamic_cpu =riscv_cpu_is_dynamic (obj); +RISCVCPU *cpu =RISCV_CPU (obj); +uint64_t prev_val = cpu->cfg.mimpid; +uint64_t value; + +if (!visit_type_uint64 (v, name, &value, errp)) { +return ; + } + +if (!dynamic_cpu && prev_val != value) { +error_setg (errp,"Unable to change %s mimpid (0x%" PRIu64")" , +object_get_typename (obj), prev_val); +return ; + } + + cpu->cfg.mimpid = value; +} + +static void prop_mimpid_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value =RISCV_CPU (obj)->cfg.mimpid; + +visit_type_uint64 (v, name, &value, errp); +} + +static const PropertyInfo prop_mimpid = { + .name ="mimpid" , + .get = prop_mimpid_get, + .set = prop_mimpid_set, +}; +/* * RVA22U64 defines some 'named features' or 'synthetic extensions' * that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa
@@ -2096,6 +2131,7 @@ static Property riscv_cpu_properties[] = { {.name = "cboz_blocksize", .info = &prop_cboz_blksize}, {.name = "mvendorid", .info = &prop_mvendorid}, + {.name = "mimpid", .info = &prop_mimpid},#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
@@ -2177,35 +2213,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = { };#endif -static void cpu_set_mimpid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -bool dynamic_cpu =riscv_cpu_is_dynamic (obj); -RISCVCPU *cpu =RISCV_CPU (obj); -uint64_t prev_val = cpu->cfg.mimpid; -uint64_t value; - -if (!visit_type_uint64 (v, name, &value, errp)) { -return ; - } - -if (!dynamic_cpu && prev_val != value) { -error_setg (errp,"Unable to change %s mimpid (0x%" PRIu64")" , -object_get_typename (obj), prev_val); -return ; - } - - cpu->cfg.mimpid = value; -} - -static void cpu_get_mimpid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint64_t value =RISCV_CPU (obj)->cfg.mimpid; - -visit_type_uint64 (v, name, &value, errp); -} -static void cpu_set_marchid (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
@@ -2286,9 +2293,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->gdb_arch_name = riscv_gdb_arch_name; cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; -object_class_property_add (c,"mimpid" ,"uint64" , cpu_get_mimpid, - cpu_set_mimpid,NULL ,NULL ); -object_class_property_add (c,"marchid" ,"uint64" , cpu_get_marchid, cpu_set_marchid,NULL ,NULL );
Signature · 1 line
2.43.0
Re: [PATCH v4 16/17] target/riscv/cpu.c: move 'mimpid' to riscv_cpu_properties[]
Quoted 4 lines · Daniel Henrique Barboza
Keep all class properties in riscv_cpu_properties[].
Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 108 lines
--- target/riscv/cpu.c | 68 ++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 32 deletions(-)target/riscv/cpu.c +36
-33@@ -2009,6 +2009,41 @@ static const PropertyInfo prop_mvendorid = { .set = prop_mvendorid_set, }; +static void prop_mimpid_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool dynamic_cpu =riscv_cpu_is_dynamic (obj); +RISCVCPU *cpu =RISCV_CPU (obj); +uint64_t prev_val = cpu->cfg.mimpid; +uint64_t value; + +if (!visit_type_uint64 (v, name, &value, errp)) { +return ; + } + +if (!dynamic_cpu && prev_val != value) { +error_setg (errp,"Unable to change %s mimpid (0x%" PRIu64")" , +object_get_typename (obj), prev_val); +return ; + } + + cpu->cfg.mimpid = value; +} + +static void prop_mimpid_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value =RISCV_CPU (obj)->cfg.mimpid; + +visit_type_uint64 (v, name, &value, errp); +} + +static const PropertyInfo prop_mimpid = { + .name ="mimpid" , + .get = prop_mimpid_get, + .set = prop_mimpid_set, +}; +/* * RVA22U64 defines some 'named features' or 'synthetic extensions' * that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa @@ -2096,6 +2131,7 @@ static Property riscv_cpu_properties[] = { {.name = "cboz_blocksize", .info = &prop_cboz_blksize}, {.name = "mvendorid", .info = &prop_mvendorid}, + {.name = "mimpid", .info = &prop_mimpid},#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),@@ -2177,35 +2213,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = { };#endif -static void cpu_set_mimpid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -bool dynamic_cpu =riscv_cpu_is_dynamic (obj); -RISCVCPU *cpu =RISCV_CPU (obj); -uint64_t prev_val = cpu->cfg.mimpid; -uint64_t value; - -if (!visit_type_uint64 (v, name, &value, errp)) { -return ; - } - -if (!dynamic_cpu && prev_val != value) { -error_setg (errp,"Unable to change %s mimpid (0x%" PRIu64")" , -object_get_typename (obj), prev_val); -return ; - } - - cpu->cfg.mimpid = value; -} - -static void cpu_get_mimpid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint64_t value =RISCV_CPU (obj)->cfg.mimpid; - -visit_type_uint64 (v, name, &value, errp); -} -static void cpu_set_marchid (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {@@ -2286,9 +2293,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->gdb_arch_name = riscv_gdb_arch_name; cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; -object_class_property_add (c,"mimpid" ,"uint64" , cpu_get_mimpid, - cpu_set_mimpid,NULL ,NULL ); -object_class_property_add (c,"marchid" ,"uint64" , cpu_get_marchid, cpu_set_marchid,NULL ,NULL ); --2.43.0
PATCH v4 17/17 target/riscv/cpu.c: move 'marchid' to riscv_cpu_properties[]
In reply to Daniel Henrique BarbozaKeep all class properties in riscv_cpu_properties[].
--- target/riscv/cpu.c | 110 +++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 53 deletions(-)
target/riscv/cpu.c +57 -53
@@ -2044,6 +2044,62 @@ static const PropertyInfo prop_mimpid = { .set = prop_mimpid_set, }; +static void prop_marchid_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool dynamic_cpu =riscv_cpu_is_dynamic (obj); +RISCVCPU *cpu =RISCV_CPU (obj); +uint64_t prev_val = cpu->cfg.marchid; +uint64_t value, invalid_val; +uint32_t mxlen =0 ; + +if (!visit_type_uint64 (v, name, &value, errp)) { +return ; + } + +if (!dynamic_cpu && prev_val != value) { +error_setg (errp,"Unable to change %s marchid (0x%" PRIu64")" , +object_get_typename (obj), prev_val); +return ; + } + +switch (riscv_cpu_mxl (&cpu->env)) { +case MXL_RV32 : + mxlen =32 ; +break ; +case MXL_RV64 : +case MXL_RV128 : + mxlen =64 ; +break ; +default : +g_assert_not_reached (); + } + + invalid_val =1LL << (mxlen -1 ); + +if (value == invalid_val) { +error_setg (errp,"Unable to set marchid with MSB (%u) bit set " +"and the remaining bits zero" , mxlen); +return ; + } + + cpu->cfg.marchid = value; +} + +static void prop_marchid_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value =RISCV_CPU (obj)->cfg.marchid; + +visit_type_uint64 (v, name, &value, errp); +} + +static const PropertyInfo prop_marchid = { + .name ="marchid" , + .get = prop_marchid_get, + .set = prop_marchid_set, +}; +/* * RVA22U64 defines some 'named features' or 'synthetic extensions' * that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa
@@ -2132,6 +2188,7 @@ static Property riscv_cpu_properties[] = { {.name = "mvendorid", .info = &prop_mvendorid}, {.name = "mimpid", .info = &prop_mimpid}, + {.name = "marchid", .info = &prop_marchid},#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
@@ -2213,56 +2270,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = { };#endif -static void cpu_set_marchid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -bool dynamic_cpu =riscv_cpu_is_dynamic (obj); -RISCVCPU *cpu =RISCV_CPU (obj); -uint64_t prev_val = cpu->cfg.marchid; -uint64_t value, invalid_val; -uint32_t mxlen =0 ; - -if (!visit_type_uint64 (v, name, &value, errp)) { -return ; - } - -if (!dynamic_cpu && prev_val != value) { -error_setg (errp,"Unable to change %s marchid (0x%" PRIu64")" , -object_get_typename (obj), prev_val); -return ; - } - -switch (riscv_cpu_mxl (&cpu->env)) { -case MXL_RV32 : - mxlen =32 ; -break ; -case MXL_RV64 : -case MXL_RV128 : - mxlen =64 ; -break ; -default : -g_assert_not_reached (); - } - - invalid_val =1LL << (mxlen -1 ); - -if (value == invalid_val) { -error_setg (errp,"Unable to set marchid with MSB (%u) bit set " -"and the remaining bits zero" , mxlen); -return ; - } - - cpu->cfg.marchid = value; -} - -static void cpu_get_marchid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint64_t value =RISCV_CPU (obj)->cfg.marchid; - -visit_type_uint64 (v, name, &value, errp); -} -static void riscv_cpu_class_init (ObjectClass *c,void *data) {RISCVCPUClass *mcc =RISCV_CPU_CLASS (c);
@@ -2293,9 +2300,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->gdb_arch_name = riscv_gdb_arch_name; cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; -object_class_property_add (c,"marchid" ,"uint64" , cpu_get_marchid, - cpu_set_marchid,NULL ,NULL ); -device_class_set_props (dc, riscv_cpu_properties); }
Signature · 1 line
2.43.0
Re: [PATCH v4 17/17] target/riscv/cpu.c: move 'marchid' to riscv_cpu_properties[]
Quoted 4 lines · Daniel Henrique Barboza
Keep all class properties in riscv_cpu_properties[].
Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 150 lines
--- target/riscv/cpu.c | 110 +++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 53 deletions(-)target/riscv/cpu.c +57
-54@@ -2044,6 +2044,62 @@ static const PropertyInfo prop_mimpid = { .set = prop_mimpid_set, }; +static void prop_marchid_set (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +bool dynamic_cpu =riscv_cpu_is_dynamic (obj); +RISCVCPU *cpu =RISCV_CPU (obj); +uint64_t prev_val = cpu->cfg.marchid; +uint64_t value, invalid_val; +uint32_t mxlen =0 ; + +if (!visit_type_uint64 (v, name, &value, errp)) { +return ; + } + +if (!dynamic_cpu && prev_val != value) { +error_setg (errp,"Unable to change %s marchid (0x%" PRIu64")" , +object_get_typename (obj), prev_val); +return ; + } + +switch (riscv_cpu_mxl (&cpu->env)) { +case MXL_RV32 : + mxlen =32 ; +break ; +case MXL_RV64 : +case MXL_RV128 : + mxlen =64 ; +break ; +default : +g_assert_not_reached (); + } + + invalid_val =1LL << (mxlen -1 ); + +if (value == invalid_val) { +error_setg (errp,"Unable to set marchid with MSB (%u) bit set " +"and the remaining bits zero" , mxlen); +return ; + } + + cpu->cfg.marchid = value; +} + +static void prop_marchid_get (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +uint64_t value =RISCV_CPU (obj)->cfg.marchid; + +visit_type_uint64 (v, name, &value, errp); +} + +static const PropertyInfo prop_marchid = { + .name ="marchid" , + .get = prop_marchid_get, + .set = prop_marchid_set, +}; +/* * RVA22U64 defines some 'named features' or 'synthetic extensions' * that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa @@ -2132,6 +2188,7 @@ static Property riscv_cpu_properties[] = { {.name = "mvendorid", .info = &prop_mvendorid}, {.name = "mimpid", .info = &prop_mimpid}, + {.name = "marchid", .info = &prop_marchid},#ifndef CONFIG_USER_ONLY DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),@@ -2213,56 +2270,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = { };#endif -static void cpu_set_marchid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -bool dynamic_cpu =riscv_cpu_is_dynamic (obj); -RISCVCPU *cpu =RISCV_CPU (obj); -uint64_t prev_val = cpu->cfg.marchid; -uint64_t value, invalid_val; -uint32_t mxlen =0 ; - -if (!visit_type_uint64 (v, name, &value, errp)) { -return ; - } - -if (!dynamic_cpu && prev_val != value) { -error_setg (errp,"Unable to change %s marchid (0x%" PRIu64")" , -object_get_typename (obj), prev_val); -return ; - } - -switch (riscv_cpu_mxl (&cpu->env)) { -case MXL_RV32 : - mxlen =32 ; -break ; -case MXL_RV64 : -case MXL_RV128 : - mxlen =64 ; -break ; -default : -g_assert_not_reached (); - } - - invalid_val =1LL << (mxlen -1 ); - -if (value == invalid_val) { -error_setg (errp,"Unable to set marchid with MSB (%u) bit set " -"and the remaining bits zero" , mxlen); -return ; - } - - cpu->cfg.marchid = value; -} - -static void cpu_get_marchid (Object *obj,Visitor *v,const char *name, -void *opaque,Error **errp) -{ -uint64_t value =RISCV_CPU (obj)->cfg.marchid; - -visit_type_uint64 (v, name, &value, errp); -} -static void riscv_cpu_class_init (ObjectClass *c,void *data) {RISCVCPUClass *mcc =RISCV_CPU_CLASS (c);@@ -2293,9 +2300,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) cc->gdb_arch_name = riscv_gdb_arch_name; cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; -object_class_property_add (c,"marchid" ,"uint64" , cpu_get_marchid, - cpu_set_marchid,NULL ,NULL ); -device_class_set_props (dc, riscv_cpu_properties); } --2.43.0
Hi Daniel,
Quoted 15 lines · Daniel Henrique Barboza
Hi,
This new version contains changes due to a rebase with current riscv-to-apply.next, after "[PATCH v13 00/26] riscv: RVA22 profiles support" was queued.
Most notable change is a new patch (12) that was added to handle '
cbop_blocksize' - zicbop was added by the profile work that just got queued and was missing from v3.A wrong '
cbom_blocksize' reference in patch 10 was also fixed.Patches based on Alistair's riscv-to-apply.next.
Quoted 10 lines
Patches missing acks: 10, 12, 15, 16, 17
Changes from v3:
- patch 10:
- changed wrongcbom_blocksizeref tocboz_blocksize
- patch 12 (new):
- movecbop_blocksizeto riscv_cpu_properties[]
- v3 link: https://lore.kernel.org/qemu-riscv/[email protected]/
This series work fine in my tests as well, thank you! (sorry for the delay)
TCG part:
Quoted 31 lines
Daniel Henrique Barboza (17):
target/riscv/cpu_cfg.h: remove unused fields
target/riscv: makeriscv_cpu_is_vendor()public target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[] target/riscv: move 'mmu' to riscv_cpu_properties[] target/riscv: move 'pmp' to riscv_cpu_properties[] target/riscv: rework 'priv_spec'
target/riscv: rework 'vext_spec'
target/riscv: move 'vlen' to riscv_cpu_properties[] target/riscv: move 'elen' to riscv_cpu_properties[] target/riscv: createfinalize_features()for KVM target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[] target/riscv: move 'cbop_blocksize' to riscv_cpu_properties[] target/riscv: move 'cboz_blocksize' to riscv_cpu_properties[] target/riscv: remove riscv_cpu_options[]target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[]target/riscv/cpu.c: move 'mimpid' to riscv_cpu_properties[]target/riscv/cpu.c: move 'marchid' to riscv_cpu_properties[]target/riscv/cpu.c | 755 ++++++++++++++++++++++++++++------- target/riscv/cpu.h | 8 +- target/riscv/cpu_cfg.h | 4 - target/riscv/kvm/kvm-cpu.c | 94 +++-- target/riscv/kvm/kvm_riscv.h | 1 + target/riscv/tcg/tcg-cpu.c | 63 --- 6 files changed, 676 insertions(+), 249 deletions(-)--
2.43.0
Quoted 25 lines · Daniel Henrique Barboza
Hi,
This new version contains changes due to a rebase with current riscv-to-apply.next, after "[PATCH v13 00/26] riscv: RVA22 profiles support" was queued.
Most notable change is a new patch (12) that was added to handle '
cbop_blocksize' - zicbop was added by the profile work that just got queued and was missing from v3.A wrong '
cbom_blocksize' reference in patch 10 was also fixed.Patches based on Alistair's riscv-to-apply.next.
Patches missing acks: 10, 12, 15, 16, 17
Changes from v3:
- patch 10:
- changed wrongcbom_blocksizeref tocboz_blocksize
- patch 12 (new):
- movecbop_blocksizeto riscv_cpu_properties[]
- v3 link: https://lore.kernel.org/qemu-riscv/[email protected]/
Quoted 10 lines
Daniel Henrique Barboza (17):
target/riscv/cpu_cfg.h: remove unused fields
target/riscv: makeriscv_cpu_is_vendor()public target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[] target/riscv: move 'mmu' to riscv_cpu_properties[] target/riscv: move 'pmp' to riscv_cpu_properties[] target/riscv: rework 'priv_spec'
target/riscv: rework 'vext_spec'
target/riscv: move 'vlen' to riscv_cpu_properties[] target/riscv: move 'elen' to riscv_cpu_properties[]
I've applied the first few patches to the RISC-V tree, the others don't apply. Do you mind rebasing them and sending them again?
Alistair
Quoted 21 lines
target/riscv: create
finalize_features()for KVM target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[] target/riscv: move 'cbop_blocksize' to riscv_cpu_properties[] target/riscv: move 'cboz_blocksize' to riscv_cpu_properties[] target/riscv: remove riscv_cpu_options[]target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[]target/riscv/cpu.c: move 'mimpid' to riscv_cpu_properties[]target/riscv/cpu.c: move 'marchid' to riscv_cpu_properties[]target/riscv/cpu.c | 755 ++++++++++++++++++++++++++++------- target/riscv/cpu.h | 8 +- target/riscv/cpu_cfg.h | 4 - target/riscv/kvm/kvm-cpu.c | 94 +++-- target/riscv/kvm/kvm_riscv.h | 1 + target/riscv/tcg/tcg-cpu.c | 63 --- 6 files changed, 676 insertions(+), 249 deletions(-)--
2.43.0