QEMU RISC-V priv spec version fixes
cover QEMU RISC-V priv spec version fixes
This series covers few fixes discovered while trying to detect priv spec version on QEMU virt machine and QEMU sifive_u machine.
These patches can also be found in riscv_priv_version_fixes_v1 branch at:
https://github.com/avpatel/qemu.git
Anup Patel (3):
target/riscv: Don't force update priv spec version to latest target/riscv: Add dummy mcountinhibit CSR for priv spec v1.11 or
higher
target/riscv: Consider priv spec version when generating ISA string
target/riscv/cpu.c | 46 ++++++++++++++++++++++------------------- target/riscv/cpu_bits.h | 3 +++ target/riscv/csr.c | 2 ++ 3 files changed, 30 insertions(+), 21 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 target/riscv: Don't force update priv spec version to latest
The riscv_cpu_realize() sets priv spec verion to v1.12 when it is when "env->priv_ver == 0" (i.e. default v1.10) because the enum value of priv spec v1.10 is zero.
Due to above issue, the sifive_u machine will see priv spec v1.12 instead of priv spec v1.10.
To fix this issue, we set latest priv spec version (i.e. v1.12) for base rv64/rv32 cpu and riscv_cpu_realize() will override priv spec version only when "cpu->cfg.priv_spec != NULL".
--- target/riscv/cpu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
target/riscv/cpu.c +6 -4
@@ -169,6 +169,8 @@ static void rv64_base_cpu_init(Object *obj)CPURISCVState *env = &RISCV_CPU (obj)->env;/* We set this in the realise function */ set_misa (env,MXL_RV64 ,0 ); +/* Set latest version of privileged specification */ +set_priv_version (env,PRIV_VERSION_1_12_0 ); }static void rv64_sifive_u_cpu_init (Object *obj)
@@ -204,6 +206,8 @@ static void rv32_base_cpu_init(Object *obj)CPURISCVState *env = &RISCV_CPU (obj)->env;/* We set this in the realise function */ set_misa (env,MXL_RV32 ,0 ); +/* Set latest version of privileged specification */ +set_priv_version (env,PRIV_VERSION_1_12_0 ); }static void rv32_sifive_u_cpu_init (Object *obj)
@@ -509,7 +513,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)CPURISCVState *env = &cpu->env;RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev);CPUClass *cc =CPU_CLASS (mcc); -int priv_version =0 ; +int priv_version =-1 ;Error *local_err =NULL ;cpu_exec_realizefn (cs, &local_err);
@@ -533,10 +537,8 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } -if (priv_version) { +if (priv_version >=PRIV_VERSION_1_10_0 ) {set_priv_version (env, priv_version); - }else if (!env->priv_ver) { -set_priv_version (env,PRIV_VERSION_1_12_0 ); }if (cpu->cfg.mmu) {
Signature · 1 line
2.34.1
PATCH 2/3 target/riscv: Add dummy mcountinhibit CSR for priv spec v1.11 or higher
In reply to Anup PatelThe mcountinhibit CSR is mandatory for priv spec v1.11 or higher. For implementation that don't want to implement can simply have a dummy mcountinhibit which always zero.
the CSR ops.")
--- target/riscv/cpu_bits.h | 3 +++ target/riscv/csr.c | 2 ++ 2 files changed, 5 insertions(+)
target/riscv/cpu_bits.h +3 -0
@@ -159,6 +159,9 @@#define CSR_MTVEC 0x305#define CSR_MCOUNTEREN 0x306 +/* Machine Counter Setup */ +#define CSR_MCOUNTINHIBIT 0x320 +/* 32-bit only */ #define CSR_MSTATUSH 0x310
target/riscv/csr.c +2 -0
@@ -3391,6 +3391,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MIE] = { "mie", any, NULL, NULL, rmw_mie }, [CSR_MTVEC] = { "mtvec", any, read_mtvec, write_mtvec }, [CSR_MCOUNTEREN] = { "mcounteren", any, read_mcounteren, write_mcounteren }, + [CSR_MCOUNTINHIBIT] = { "mcountinhibit", any, read_zero, write_ignore, + .min_priv_ver = PRIV_VERSION_1_11_0 }, [CSR_MSTATUSH] = { "mstatush", any32, read_mstatush, write_mstatush },
Signature · 1 line
2.34.1
PATCH 3/3 target/riscv: Consider priv spec version when generating ISA string
In reply to Anup PatelMost of the multi-letter extensions (such as Svpbmt, Svnapot, Svinval, etc) are only available after Priv spec v1.12 so ISA string generation should check the minimum required priv spec version for all extensions.
device tree")
--- target/riscv/cpu.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)
target/riscv/cpu.c +19 -17
@@ -44,6 +44,7 @@ static const char riscv_single_letter_exts[] = "IEMAFDQCPVH";struct isa_ext_data {const char *name;bool enabled; +uint32_t min_priv_ver; };const char *const riscv_int_regnames[] = {
@@ -974,7 +975,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)device_class_set_props (dc, riscv_cpu_properties); } -#define ISA_EDATA_ENTRY (name, prop) {#name, cpu->cfg.prop} +#define ISA_EDATA_ENTRY (name, prop, priv) {#name, cpu->cfg.prop, priv}static void riscv_isa_string_ext (RISCVCPU *cpu,char **isa_str,int max_str_len) {
@@ -1000,25 +1001,26 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { -ISA_EDATA_ENTRY (zfh, ext_zfh), -ISA_EDATA_ENTRY (zfhmin, ext_zfhmin), -ISA_EDATA_ENTRY (zfinx, ext_zfinx), -ISA_EDATA_ENTRY (zhinx, ext_zhinx), -ISA_EDATA_ENTRY (zhinxmin, ext_zhinxmin), -ISA_EDATA_ENTRY (zdinx, ext_zdinx), -ISA_EDATA_ENTRY (zba, ext_zba), -ISA_EDATA_ENTRY (zbb, ext_zbb), -ISA_EDATA_ENTRY (zbc, ext_zbc), -ISA_EDATA_ENTRY (zbs, ext_zbs), -ISA_EDATA_ENTRY (zve32f, ext_zve32f), -ISA_EDATA_ENTRY (zve64f, ext_zve64f), -ISA_EDATA_ENTRY (svinval, ext_svinval), -ISA_EDATA_ENTRY (svnapot, ext_svnapot), -ISA_EDATA_ENTRY (svpbmt, ext_svpbmt), +ISA_EDATA_ENTRY (zfh, ext_zfh,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zfhmin, ext_zfhmin,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zfinx, ext_zfinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zhinx, ext_zhinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zhinxmin, ext_zhinxmin,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zdinx, ext_zdinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zba, ext_zba,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbb, ext_zbb,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbc, ext_zbc,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbs, ext_zbs,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zve32f, ext_zve32f,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zve64f, ext_zve64f,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svinval, ext_svinval,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svnapot, ext_svnapot,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svpbmt, ext_svpbmt,PRIV_VERSION_1_12_0 ), };for (i =0 ; i <ARRAY_SIZE (isa_edata_arr); i++) { -if (isa_edata_arr[i].enabled) { +if (isa_edata_arr[i].enabled && + cpu->env.priv_ver >= isa_edata_arr[i].min_priv_ver) { new =g_strconcat (old,"_" , isa_edata_arr[i].name,NULL );g_free (old); old = new;
Signature · 1 line
2.34.1
Re: [PATCH 1/3] target/riscv: Don't force update priv spec version to latest
In reply to Anup PatelQuoted 67 lines · Anup Patel
The
riscv_cpu_realize()sets priv spec verion to v1.12 when it is when "env->priv_ver== 0" (i.e. default v1.10) because the enum value of priv spec v1.10 is zero.Due to above issue, the
sifive_umachine will see priv spec v1.12 instead of priv spec v1.10.To fix this issue, we set latest priv spec version (i.e. v1.12) for base rv64/rv32 cpu and
riscv_cpu_realize()will override priv spec version only when "cpu->cfg.priv_spec!= NULL".Fixes 7100fe6c2441 ("target/riscv: Enable privileged spec version 1.12")Signed-off-by Anup Patel <[email protected]>--- target/riscv/cpu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)target/riscv/cpu.c +5
-1@@ -169,6 +169,8 @@ static void rv64_base_cpu_init(Object *obj)CPURISCVState *env = &RISCV_CPU (obj)->env;/* We set this in the realise function */ set_misa (env,MXL_RV64 ,0 ); +/* Set latest version of privileged specification */ +set_priv_version (env,PRIV_VERSION_1_12_0 ); }static void rv64_sifive_u_cpu_init (Object *obj)@@ -204,6 +206,8 @@ static void rv32_base_cpu_init(Object *obj)CPURISCVState *env = &RISCV_CPU (obj)->env;/* We set this in the realise function */ set_misa (env,MXL_RV32 ,0 ); +/* Set latest version of privileged specification */ +set_priv_version (env,PRIV_VERSION_1_12_0 ); }static void rv32_sifive_u_cpu_init (Object *obj)@@ -509,7 +513,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)CPURISCVState *env = &cpu->env;RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev);CPUClass *cc =CPU_CLASS (mcc); -int priv_version =0 ; +int priv_version =-1 ;Error *local_err =NULL ;cpu_exec_realizefn(cs, &local_err);target/riscv/cpu.c +1
-3@@ -533,10 +537,8 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } -if (priv_version) { +if (priv_version >=PRIV_VERSION_1_10_0 ) {set_priv_version (env, priv_version); - }else if (!env->priv_ver) { -set_priv_version (env,PRIV_VERSION_1_12_0 ); }if (cpu->cfg.mmu) {--
2.34.1
Re: [PATCH 3/3] target/riscv: Consider priv spec version when generating ISA string
In reply to Anup PatelHi Anup,
If we want to limit the generated ISA string to/after a specific privilege spec version.
Shouldn't we also check the privilege spec version when these extensions are enabled?
Otherwise, it's possible that one extension is enabled,
but the privilege spec version is smaller than the one in which the extension is supported.
(This is possible if user specifies the privileged spec version through the command line.)
The ISA string therefore won't include the enabled extension.
Regards,
Frank Chang
Quoted 84 lines · Anup Patel
Most of the multi-letter extensions (such as Svpbmt, Svnapot, Svinval, etc) are only available after Priv spec v1.12 so ISA string generation should check the minimum required priv spec version for all extensions.
Fixes a775398be2e ("target/riscv: Add isa extenstion strings to thedevice tree")
Signed-off-by Anup Patel <[email protected]>--- target/riscv/cpu.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)target/riscv/cpu.c +1
-0@@ -44,6 +44,7 @@ static const char riscv_single_letter_exts[] ="IEMAFDQCPVH" ;struct isa_ext_data {const char *name;bool enabled; +uint32_t min_priv_ver; };const char * const riscv_int_regnames[] = {
target/riscv/cpu.c +1
-1@@ -974,7 +975,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)device_class_set_props (dc, riscv_cpu_properties); } -#define ISA_EDATA_ENTRY (name, prop) {#name, cpu->cfg.prop} +#define ISA_EDATA_ENTRY (name, prop, priv) {#name, cpu->cfg.prop, priv} static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int
max_str_len)
{target/riscv/cpu.c +17
-16@@ -1000,25 +1001,26 @@ static void riscv_isa_string_ext(RISCVCPU *cpu,char **isa_str, int max_str_len) * extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { -ISA_EDATA_ENTRY (zfh, ext_zfh), -ISA_EDATA_ENTRY (zfhmin, ext_zfhmin), -ISA_EDATA_ENTRY (zfinx, ext_zfinx), -ISA_EDATA_ENTRY (zhinx, ext_zhinx), -ISA_EDATA_ENTRY (zhinxmin, ext_zhinxmin), -ISA_EDATA_ENTRY (zdinx, ext_zdinx), -ISA_EDATA_ENTRY (zba, ext_zba), -ISA_EDATA_ENTRY (zbb, ext_zbb), -ISA_EDATA_ENTRY (zbc, ext_zbc), -ISA_EDATA_ENTRY (zbs, ext_zbs), -ISA_EDATA_ENTRY (zve32f, ext_zve32f), -ISA_EDATA_ENTRY (zve64f, ext_zve64f), -ISA_EDATA_ENTRY (svinval, ext_svinval), -ISA_EDATA_ENTRY (svnapot, ext_svnapot), -ISA_EDATA_ENTRY (svpbmt, ext_svpbmt), +ISA_EDATA_ENTRY (zfh, ext_zfh,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zfhmin, ext_zfhmin,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zfinx, ext_zfinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zhinx, ext_zhinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zhinxmin, ext_zhinxmin,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zdinx, ext_zdinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zba, ext_zba,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbb, ext_zbb,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbc, ext_zbc,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbs, ext_zbs,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zve32f, ext_zve32f,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zve64f, ext_zve64f,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svinval, ext_svinval,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svnapot, ext_svnapot,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svpbmt, ext_svpbmt,PRIV_VERSION_1_12_0 ), };for (i =0 ; i <ARRAY_SIZE (isa_edata_arr); i++) { -if (isa_edata_arr[i].enabled) { +if (isa_edata_arr[i].enabled && + cpu->env.priv_ver >= isa_edata_arr[i].min_priv_ver) { new =g_strconcat (old,"_" , isa_edata_arr[i].name,NULL );g_free (old);old = new;--
2.34.1
Re: [PATCH 2/3] target/riscv: Add dummy mcountinhibit CSR for priv spec v1.11 or higher
In reply to Anup PatelQuoted 49 lines · Anup Patel
The mcountinhibit CSR is mandatory for priv spec v1.11 or higher. For implementation that don't want to implement can simply have a dummy mcountinhibit which always zero.
Fixes a4b2fa433125 ("target/riscv: Introduce privilege version field inthe CSR ops.")
Signed-off-by Anup Patel <[email protected]>--- target/riscv/cpu_bits.h | 3 +++ target/riscv/csr.c | 2 ++ 2 files changed, 5 insertions(+)target/riscv/cpu_bits.h +3
-0@@ -159,6 +159,9 @@#define CSR_MTVEC 0x305#define CSR_MCOUNTEREN 0x306 +/* Machine Counter Setup */ +#define CSR_MCOUNTINHIBIT 0x320 +/* 32-bit only */ #define CSR_MSTATUSH 0x310target/riscv/csr.c +2
-0@@ -3391,6 +3391,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MIE ] = {"mie" , any,NULL ,NULL , rmw_mie }, [CSR_MTVEC ] = {"mtvec" , any, read_mtvec, write_mtvec }, [CSR_MCOUNTEREN ] = {"mcounteren" , any, read_mcounteren, write_mcounteren }, + [CSR_MCOUNTINHIBIT ] = {"mcountinhibit" , any, read_zero, write_ignore, + .min_priv_ver =
PRIV_VERSION_1_11_0},[
CSR_MSTATUSH] = { "mstatush", any32,read_mstatush,write_mstatush},--
2.34.1
Re: [PATCH 3/3] target/riscv: Consider priv spec version when generating ISA string
In reply to Frank ChangQuoted 9 lines · Frank Chang
Hi Anup,
If we want to limit the generated ISA string to/after a specific privilege spec version. Shouldn't we also check the privilege spec version when these extensions are enabled? Otherwise, it's possible that one extension is enabled,
but the privilege spec version is smaller than the one in which the extension is supported. (This is possible if user specifies the privileged spec version through the command line.) The ISA string therefore won't include the enabled extension.
This patch is only a temporary fix for the sifive_u machine where I am seeing some
of these new extensions available in ISA string.
We need a separate series to have the priv spec version influence individual extension
enabling/disabling.
Regards,
Anup
Quoted 86 lines
Regards,
Frank ChangQuoted 80 lines · Anup Patel
Most of the multi-letter extensions (such as Svpbmt, Svnapot, Svinval, etc) are only available after Priv spec v1.12 so ISA string generation should check the minimum required priv spec version for all extensions.
Fixes a775398be2e ("target/riscv: Add isa extenstion strings to thedevice tree")
Signed-off-by Anup Patel <[email protected]>--- target/riscv/cpu.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)target/riscv/cpu.c +19
-18@@ -44,6 +44,7 @@ static const char riscv_single_letter_exts[] = "IEMAFDQCPVH";struct isa_ext_data {const char *name;bool enabled; +uint32_t min_priv_ver; };const char *const riscv_int_regnames[] = {@@ -974,7 +975,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)device_class_set_props (dc, riscv_cpu_properties); } -#define ISA_EDATA_ENTRY (name, prop) {#name, cpu->cfg.prop} +#define ISA_EDATA_ENTRY (name, prop, priv) {#name, cpu->cfg.prop, priv}static void riscv_isa_string_ext (RISCVCPU *cpu,char **isa_str,int max_str_len) {@@ -1000,25 +1001,26 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { -ISA_EDATA_ENTRY (zfh, ext_zfh), -ISA_EDATA_ENTRY (zfhmin, ext_zfhmin), -ISA_EDATA_ENTRY (zfinx, ext_zfinx), -ISA_EDATA_ENTRY (zhinx, ext_zhinx), -ISA_EDATA_ENTRY (zhinxmin, ext_zhinxmin), -ISA_EDATA_ENTRY (zdinx, ext_zdinx), -ISA_EDATA_ENTRY (zba, ext_zba), -ISA_EDATA_ENTRY (zbb, ext_zbb), -ISA_EDATA_ENTRY (zbc, ext_zbc), -ISA_EDATA_ENTRY (zbs, ext_zbs), -ISA_EDATA_ENTRY (zve32f, ext_zve32f), -ISA_EDATA_ENTRY (zve64f, ext_zve64f), -ISA_EDATA_ENTRY (svinval, ext_svinval), -ISA_EDATA_ENTRY (svnapot, ext_svnapot), -ISA_EDATA_ENTRY (svpbmt, ext_svpbmt), +ISA_EDATA_ENTRY (zfh, ext_zfh,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zfhmin, ext_zfhmin,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zfinx, ext_zfinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zhinx, ext_zhinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zhinxmin, ext_zhinxmin,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zdinx, ext_zdinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zba, ext_zba,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbb, ext_zbb,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbc, ext_zbc,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbs, ext_zbs,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zve32f, ext_zve32f,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zve64f, ext_zve64f,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svinval, ext_svinval,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svnapot, ext_svnapot,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svpbmt, ext_svpbmt,PRIV_VERSION_1_12_0 ), };for (i =0 ; i <ARRAY_SIZE (isa_edata_arr); i++) { -if (isa_edata_arr[i].enabled) { +if (isa_edata_arr[i].enabled && + cpu->env.priv_ver >= isa_edata_arr[i].min_priv_ver) { new =g_strconcat (old,"_" , isa_edata_arr[i].name,NULL );g_free (old); old = new; --2.34.1
Frank Chang
Reviewed-byRe: [PATCH 3/3] target/riscv: Consider priv spec version when generating ISA string
Quoted 16 lines · Anup Patel
Quoted 4 lines · Frank Chang
Hi Anup,
If we want to limit the generated ISA string to/after a specific
privilege spec version.
Quoted 1 line
Shouldn't we also check the privilege spec version when these extensions
are enabled?
Quoted 2 lines
Otherwise, it's possible that one extension is enabled, but the privilege spec version is smaller than the one in which the
extension is supported.
Quoted 1 line
(This is possible if user specifies the privileged spec version through
the command line.)
Quoted 1 line
The ISA string therefore won't include the enabled extension.
Quoted 8 lines
This patch is only a temporary fix for the
sifive_umachine where I am seeing some
of these new extensions available in ISA string.We need a separate series to have the priv spec version influence individual extension
enabling/disabling.
If that's the case,
Quoted 96 lines
Regards,
AnupQuoted 6 lines
Regards,
Frank ChangOn Fri, Apr 29, 2022 at 11:49 PM Anup Patel <[email protected]>
Quoted 12 lines · wrote:
Quoted 12 lines
Most of the multi-letter extensions (such as Svpbmt, Svnapot, Svinval, etc) are only available after Priv spec v1.12 so ISA string generation should check the minimum required priv spec version for all extensions.
Fixes a775398be2e ("target/riscv: Add isa extenstion strings to thedevice tree")
Signed-off-by Anup Patel <[email protected]>--- target/riscv/cpu.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)Quoted 5 lines
target/riscv/cpu.c static const char riscv_single_letter_exts[] =
Quoted 5 lines
target/riscv/cpu.c +0
-0@@ -44,6 +44,7 @@ static const char riscv_single_letter_exts[] ="IEMAFDQCPVH";
Quoted 8 lines
target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c,
Quoted 8 lines
target/riscv/cpu.c +1
-0struct isa_ext_data {const char *name;bool enabled; +uint32_t min_priv_ver; };const char *const riscv_int_regnames[] = {@@ -974,7 +975,7 @@ static void riscv_cpu_class_init(ObjectClass *c,void *data)
Quoted 7 lines
target/riscv/cpu.c static void riscv_cpu_class_init(ObjectClass *c, void *data)
Quoted 7 lines
target/riscv/cpu.c +1
-1device_class_set_props (dc, riscv_cpu_properties); } -#define ISA_EDATA_ENTRY (name, prop) {#name, cpu->cfg.prop} +#define ISA_EDATA_ENTRY (name, prop, priv) {#name, cpu->cfg.prop, priv} static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int
max_str_len)Quoted 2 lines
target/riscv/cpu.c static void riscv_isa_string_ext(RISCVCPU *cpu,
Quoted 2 lines
target/riscv/cpu.c +0
-0{@@ -1000,25 +1001,26 @@ static void riscv_isa_string_ext(RISCVCPU *cpu,char **isa_str, int
max_str_len)Quoted 46 lines
Quoted 46 lines
target/riscv/cpu.c +17
-17* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { -ISA_EDATA_ENTRY (zfh, ext_zfh), -ISA_EDATA_ENTRY (zfhmin, ext_zfhmin), -ISA_EDATA_ENTRY (zfinx, ext_zfinx), -ISA_EDATA_ENTRY (zhinx, ext_zhinx), -ISA_EDATA_ENTRY (zhinxmin, ext_zhinxmin), -ISA_EDATA_ENTRY (zdinx, ext_zdinx), -ISA_EDATA_ENTRY (zba, ext_zba), -ISA_EDATA_ENTRY (zbb, ext_zbb), -ISA_EDATA_ENTRY (zbc, ext_zbc), -ISA_EDATA_ENTRY (zbs, ext_zbs), -ISA_EDATA_ENTRY (zve32f, ext_zve32f), -ISA_EDATA_ENTRY (zve64f, ext_zve64f), -ISA_EDATA_ENTRY (svinval, ext_svinval), -ISA_EDATA_ENTRY (svnapot, ext_svnapot), -ISA_EDATA_ENTRY (svpbmt, ext_svpbmt), +ISA_EDATA_ENTRY (zfh, ext_zfh,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zfhmin, ext_zfhmin,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zfinx, ext_zfinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zhinx, ext_zhinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zhinxmin, ext_zhinxmin,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zdinx, ext_zdinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zba, ext_zba,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbb, ext_zbb,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbc, ext_zbc,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbs, ext_zbs,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zve32f, ext_zve32f,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zve64f, ext_zve64f,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svinval, ext_svinval,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svnapot, ext_svnapot,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svpbmt, ext_svpbmt,PRIV_VERSION_1_12_0 ), };for (i =0 ; i <ARRAY_SIZE (isa_edata_arr); i++) { -if (isa_edata_arr[i].enabled) { +if (isa_edata_arr[i].enabled && + cpu->env.priv_ver >= isa_edata_arr[i].min_priv_ver) { new =g_strconcat (old,"_" , isa_edata_arr[i].name,NULL );g_free (old); old = new; --2.34.1
Re: [PATCH 1/3] target/riscv: Don't force update priv spec version to latest
In reply to Anup PatelQuoted 8 lines · Anup Patel
The
riscv_cpu_realize()sets priv spec verion to v1.12 when it is when "env->priv_ver== 0" (i.e. default v1.10) because the enum value of priv spec v1.10 is zero.Due to above issue, the
sifive_umachine will see priv spec v1.12 instead of priv spec v1.10.
Quoted 6 lines
To fix this issue, we set latest priv spec version (i.e. v1.12) for base rv64/rv32 cpu and
riscv_cpu_realize()will override priv spec version only when "cpu->cfg.priv_spec!= NULL".Fixes 7100fe6c2441 ("target/riscv: Enable privileged spec version 1.12")Signed-off-by Anup Patel <[email protected]>
Alistair
Quoted 51 lines
--- target/riscv/cpu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)target/riscv/cpu.c +6
-5@@ -169,6 +169,8 @@ static void rv64_base_cpu_init(Object *obj)CPURISCVState *env = &RISCV_CPU (obj)->env;/* We set this in the realise function */ set_misa (env,MXL_RV64 ,0 ); +/* Set latest version of privileged specification */ +set_priv_version (env,PRIV_VERSION_1_12_0 ); }static void rv64_sifive_u_cpu_init (Object *obj)@@ -204,6 +206,8 @@ static void rv32_base_cpu_init(Object *obj)CPURISCVState *env = &RISCV_CPU (obj)->env;/* We set this in the realise function */ set_misa (env,MXL_RV32 ,0 ); +/* Set latest version of privileged specification */ +set_priv_version (env,PRIV_VERSION_1_12_0 ); }static void rv32_sifive_u_cpu_init (Object *obj)@@ -509,7 +513,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)CPURISCVState *env = &cpu->env;RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev);CPUClass *cc =CPU_CLASS (mcc); -int priv_version =0 ; +int priv_version =-1 ;Error *local_err =NULL ;cpu_exec_realizefn (cs, &local_err);@@ -533,10 +537,8 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } -if (priv_version) { +if (priv_version >=PRIV_VERSION_1_10_0 ) {set_priv_version (env, priv_version); - }else if (!env->priv_ver) { -set_priv_version (env,PRIV_VERSION_1_12_0 ); }if (cpu->cfg.mmu) { --2.34.1
Re: [PATCH 2/3] target/riscv: Add dummy mcountinhibit CSR for priv spec v1.11 or higher
In reply to Anup PatelQuoted 8 lines · Anup Patel
The mcountinhibit CSR is mandatory for priv spec v1.11 or higher. For implementation that don't want to implement can simply have a dummy mcountinhibit which always zero.
Fixes a4b2fa433125 ("target/riscv: Introduce privilege version field inthe CSR ops.")
Signed-off-by Anup Patel <[email protected]>
Alistair
Quoted 36 lines
--- target/riscv/cpu_bits.h | 3 +++ target/riscv/csr.c | 2 ++ 2 files changed, 5 insertions(+)target/riscv/cpu_bits.h +3
-0@@ -159,6 +159,9 @@#define CSR_MTVEC 0x305#define CSR_MCOUNTEREN 0x306 +/* Machine Counter Setup */ +#define CSR_MCOUNTINHIBIT 0x320 +/* 32-bit only */ #define CSR_MSTATUSH 0x310target/riscv/csr.c +2
-1@@ -3391,6 +3391,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MIE] = { "mie", any, NULL, NULL, rmw_mie }, [CSR_MTVEC] = { "mtvec", any, read_mtvec, write_mtvec }, [CSR_MCOUNTEREN] = { "mcounteren", any, read_mcounteren, write_mcounteren }, + [CSR_MCOUNTINHIBIT] = { "mcountinhibit", any, read_zero, write_ignore, + .min_priv_ver = PRIV_VERSION_1_11_0 }, [CSR_MSTATUSH] = { "mstatush", any32, read_mstatush, write_mstatush }, --2.34.1
Re: [PATCH 2/3] target/riscv: Add dummy mcountinhibit CSR for priv spec v1.11 or higher
In reply to Anup PatelHi Anup,
I found that Atish has already submitted a patch to implement the mcountinhibit CSR:
https://www.mail-archive.com/[email protected]/msg879349.html
Regards,
Frank Chang
Quoted 49 lines · Anup Patel
The mcountinhibit CSR is mandatory for priv spec v1.11 or higher. For implementation that don't want to implement can simply have a dummy mcountinhibit which always zero.
Fixes a4b2fa433125 ("target/riscv: Introduce privilege version field inthe CSR ops.")
Signed-off-by Anup Patel <[email protected]>--- target/riscv/cpu_bits.h | 3 +++ target/riscv/csr.c | 2 ++ 2 files changed, 5 insertions(+)target/riscv/cpu_bits.h +3
-0@@ -159,6 +159,9 @@#define CSR_MTVEC 0x305#define CSR_MCOUNTEREN 0x306 +/* Machine Counter Setup */ +#define CSR_MCOUNTINHIBIT 0x320 +/* 32-bit only */ #define CSR_MSTATUSH 0x310target/riscv/csr.c +2
-0@@ -3391,6 +3391,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MIE ] = {"mie" , any,NULL ,NULL , rmw_mie }, [CSR_MTVEC ] = {"mtvec" , any, read_mtvec, write_mtvec }, [CSR_MCOUNTEREN ] = {"mcounteren" , any, read_mcounteren, write_mcounteren }, + [CSR_MCOUNTINHIBIT ] = {"mcountinhibit" , any, read_zero, write_ignore, + .min_priv_ver =
PRIV_VERSION_1_11_0},[
CSR_MSTATUSH] = { "mstatush", any32,read_mstatush,write_mstatush},--
2.34.1
Re: [PATCH 3/3] target/riscv: Consider priv spec version when generating ISA string
In reply to Anup PatelQuoted 12 lines · Anup Patel
Quoted 9 lines · Frank Chang
Hi Anup,
If we want to limit the generated ISA string to/after a specific privilege spec version. Shouldn't we also check the privilege spec version when these extensions are enabled? Otherwise, it's possible that one extension is enabled,
but the privilege spec version is smaller than the one in which the extension is supported. (This is possible if user specifies the privileged spec version through the command line.) The ISA string therefore won't include the enabled extension.
Quoted 7 lines
This patch is only a temporary fix for the
sifive_umachine where I am seeing some
of these new extensions available in ISA string.We need a separate series to have the priv spec version influence individual extension
enabling/disabling.
I agree with Frank, I think it makes more sense to just never enable the extension instead of not telling the guest it's enabled.
Alistair
Quoted 91 lines
Regards,
AnupQuoted 86 lines
Regards,
Frank ChangQuoted 80 lines · Anup Patel
Most of the multi-letter extensions (such as Svpbmt, Svnapot, Svinval, etc) are only available after Priv spec v1.12 so ISA string generation should check the minimum required priv spec version for all extensions.
Fixes a775398be2e ("target/riscv: Add isa extenstion strings to thedevice tree")
Signed-off-by Anup Patel <[email protected]>--- target/riscv/cpu.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)target/riscv/cpu.c +19
-18@@ -44,6 +44,7 @@ static const char riscv_single_letter_exts[] = "IEMAFDQCPVH";struct isa_ext_data {const char *name;bool enabled; +uint32_t min_priv_ver; };const char *const riscv_int_regnames[] = {@@ -974,7 +975,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)device_class_set_props (dc, riscv_cpu_properties); } -#define ISA_EDATA_ENTRY (name, prop) {#name, cpu->cfg.prop} +#define ISA_EDATA_ENTRY (name, prop, priv) {#name, cpu->cfg.prop, priv}static void riscv_isa_string_ext (RISCVCPU *cpu,char **isa_str,int max_str_len) {@@ -1000,25 +1001,26 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)* extensions by an underscore. */ struct isa_ext_data isa_edata_arr[] = { -ISA_EDATA_ENTRY (zfh, ext_zfh), -ISA_EDATA_ENTRY (zfhmin, ext_zfhmin), -ISA_EDATA_ENTRY (zfinx, ext_zfinx), -ISA_EDATA_ENTRY (zhinx, ext_zhinx), -ISA_EDATA_ENTRY (zhinxmin, ext_zhinxmin), -ISA_EDATA_ENTRY (zdinx, ext_zdinx), -ISA_EDATA_ENTRY (zba, ext_zba), -ISA_EDATA_ENTRY (zbb, ext_zbb), -ISA_EDATA_ENTRY (zbc, ext_zbc), -ISA_EDATA_ENTRY (zbs, ext_zbs), -ISA_EDATA_ENTRY (zve32f, ext_zve32f), -ISA_EDATA_ENTRY (zve64f, ext_zve64f), -ISA_EDATA_ENTRY (svinval, ext_svinval), -ISA_EDATA_ENTRY (svnapot, ext_svnapot), -ISA_EDATA_ENTRY (svpbmt, ext_svpbmt), +ISA_EDATA_ENTRY (zfh, ext_zfh,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zfhmin, ext_zfhmin,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zfinx, ext_zfinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zhinx, ext_zhinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zhinxmin, ext_zhinxmin,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zdinx, ext_zdinx,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zba, ext_zba,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbb, ext_zbb,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbc, ext_zbc,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zbs, ext_zbs,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zve32f, ext_zve32f,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (zve64f, ext_zve64f,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svinval, ext_svinval,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svnapot, ext_svnapot,PRIV_VERSION_1_12_0 ), +ISA_EDATA_ENTRY (svpbmt, ext_svpbmt,PRIV_VERSION_1_12_0 ), };for (i =0 ; i <ARRAY_SIZE (isa_edata_arr); i++) { -if (isa_edata_arr[i].enabled) { +if (isa_edata_arr[i].enabled && + cpu->env.priv_ver >= isa_edata_arr[i].min_priv_ver) { new =g_strconcat (old,"_" , isa_edata_arr[i].name,NULL );g_free (old); old = new; --2.34.1
Re: [PATCH 2/3] target/riscv: Add dummy mcountinhibit CSR for priv spec v1.11 or higher
In reply to Frank ChangQuoted 6 lines · Frank Chang
Hi Anup,
I found that Atish has already submitted a patch to implement the mcountinhibit CSR:
https://www.mail-archive.com/[email protected]/msg879349.html
Yeah. I think it depends on which series is merged first. The PMU series actually uses mcountinhibit.
However, latest OpenSBI patches detect priv version v1.11 based on mcountinhibit presence.
We need mcountinhibit support to test any v1.12 patches anyways.
If PMU patches are merged first, we don't need this patch.
Quoted 48 lines
Regards,
Frank ChangQuoted 44 lines · Anup Patel
The mcountinhibit CSR is mandatory for priv spec v1.11 or higher. For implementation that don't want to implement can simply have a dummy mcountinhibit which always zero.
Fixes a4b2fa433125 ("target/riscv: Introduce privilege version field inthe CSR ops.")
Signed-off-by Anup Patel <[email protected]>--- target/riscv/cpu_bits.h | 3 +++ target/riscv/csr.c | 2 ++ 2 files changed, 5 insertions(+)target/riscv/cpu_bits.h +3
-0@@ -159,6 +159,9 @@#define CSR_MTVEC 0x305#define CSR_MCOUNTEREN 0x306 +/* Machine Counter Setup */ +#define CSR_MCOUNTINHIBIT 0x320 +/* 32-bit only */ #define CSR_MSTATUSH 0x310target/riscv/csr.c +2
-1@@ -3391,6 +3391,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MIE] = { "mie", any, NULL, NULL, rmw_mie }, [CSR_MTVEC] = { "mtvec", any, read_mtvec, write_mtvec }, [CSR_MCOUNTEREN] = { "mcounteren", any, read_mcounteren, write_mcounteren }, + [CSR_MCOUNTINHIBIT] = { "mcountinhibit", any, read_zero, write_ignore, + .min_priv_ver = PRIV_VERSION_1_11_0 }, [CSR_MSTATUSH] = { "mstatush", any32, read_mstatush, write_mstatush }, --2.34.1
Signature · 2 lines
Regards, Atish
Re: [PATCH 1/3] target/riscv: Don't force update priv spec version to latest
In reply to Anup PatelQuoted 62 lines · Anup Patel
The
riscv_cpu_realize()sets priv spec verion to v1.12 when it is when "env->priv_ver== 0" (i.e. default v1.10) because the enum value of priv spec v1.10 is zero.Due to above issue, the
sifive_umachine will see priv spec v1.12 instead of priv spec v1.10.To fix this issue, we set latest priv spec version (i.e. v1.12) for base rv64/rv32 cpu and
riscv_cpu_realize()will override priv spec version only when "cpu->cfg.priv_spec!= NULL".Fixes 7100fe6c2441 ("target/riscv: Enable privileged spec version 1.12")Signed-off-by Anup Patel <[email protected]>--- target/riscv/cpu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)target/riscv/cpu.c +6
-5@@ -169,6 +169,8 @@ static void rv64_base_cpu_init(Object *obj)CPURISCVState *env = &RISCV_CPU (obj)->env;/* We set this in the realise function */ set_misa (env,MXL_RV64 ,0 ); +/* Set latest version of privileged specification */ +set_priv_version (env,PRIV_VERSION_1_12_0 ); }static void rv64_sifive_u_cpu_init (Object *obj)@@ -204,6 +206,8 @@ static void rv32_base_cpu_init(Object *obj)CPURISCVState *env = &RISCV_CPU (obj)->env;/* We set this in the realise function */ set_misa (env,MXL_RV32 ,0 ); +/* Set latest version of privileged specification */ +set_priv_version (env,PRIV_VERSION_1_12_0 ); }static void rv32_sifive_u_cpu_init (Object *obj)@@ -509,7 +513,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)CPURISCVState *env = &cpu->env;RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev);CPUClass *cc =CPU_CLASS (mcc); -int priv_version =0 ; +int priv_version =-1 ;Error *local_err =NULL ;cpu_exec_realizefn (cs, &local_err);@@ -533,10 +537,8 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } -if (priv_version) { +if (priv_version >=PRIV_VERSION_1_10_0 ) {set_priv_version (env, priv_version); - }else if (!env->priv_ver) { -set_priv_version (env,PRIV_VERSION_1_12_0 ); }if (cpu->cfg.mmu) { --
Quoted 2 lines
2.34.1
Signature · 2 lines
Regards, Atish