target/riscv/cpu.c: satp-mode=bare changes
cover target/riscv/cpu.c: satp-mode=bare changes
Greetings,
Here are two mostly trivial patches related to satp-mode=bare support.
Patches based on alistair/riscv-to-apply.next.
Daniel Henrique Barboza (2):
target/riscv/cpu.c: add 'svbare' satp-mode target/riscv/cpu.c: do not default to svbare for bare CPUs
target/riscv/cpu.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 target/riscv/cpu.c: add 'svbare' satp-mode
Seems like we forgot to add a flag to set satp-mode=bare. What we're doing instead is to set the CPU default satp-mode to 'off' to set it to bare ... assuming we know the default satp-mode. Otherwise one needs to do -cpu X,sv39=off,sv48=off,sv57=off,sv64=off to get a bare-mode CPU.
Add a flag to make this process easier. The name choice is based on the fact that I didn't find many references to 'mbare' in RISC-V docs, but 'svbare' is a flag name that toolchain uses to set satp-mode=bare. Might as well use the same name to help with cross project compat.
After this patch:
$ ./build/qemu-system-riscv64 -M virt,dumpdtb=fdt.dtb -cpu rv64
$ dtc -I dtb -O dts fdt.dtb | grep mmu-type
mmu-type = "riscv,sv57";
$ ./build/qemu-system-riscv64 -M virt,dumpdtb=fdt.dtb -cpu rv64,svbare=on
$ dtc -I dtb -O dts fdt.dtb | grep mmu-type
mmu-type = "riscv,none";--- target/riscv/cpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target/riscv/cpu.c +4 -1
@@ -421,7 +421,7 @@ int riscv_cpu_max_xlen(RISCVCPUClass *mcc)#ifndef CONFIG_USER_ONLY static uint8_t satp_mode_from_str (const char *satp_mode_str) { -if (!strncmp (satp_mode_str,"mbare" ,5 )) { +if (!strncmp (satp_mode_str,"svbare" ,6 )) {return VM_1_10_MBARE ; }
@@ -1053,6 +1053,9 @@ void riscv_add_satp_mode_properties(Object *obj) {RISCVCPU *cpu =RISCV_CPU (obj); +object_property_add (obj,"svbare" ,"bool" , cpu_riscv_get_satp, + cpu_riscv_set_satp,NULL , &cpu->satp_modes); +if (cpu->env.misa_mxl ==MXL_RV32 ) {object_property_add (obj,"sv32" ,"bool" , cpu_riscv_get_satp, cpu_riscv_set_satp,NULL , &cpu->satp_modes);
Signature · 1 line
2.43.0
Re: [PATCH 1/2] target/riscv/cpu.c: add 'svbare' satp-mode
Quoted 13 lines · Daniel Henrique Barboza
Seems like we forgot to add a flag to set satp-mode=bare. What we're doing instead is to set the CPU default satp-mode to 'off' to set it to bare ... assuming we know the default satp-mode. Otherwise one needs to do -cpu X,sv39=off,sv48=off,sv57=off,sv64=off to get a bare-mode CPU.
Add a flag to make this process easier. The name choice is based on the fact that I didn't find many references to 'mbare' in RISC-V docs, but 'svbare' is a flag name that toolchain uses to set satp-mode=bare. Might as well use the same name to help with cross project compat.
After this patch:
Quoted 8 lines
$ ./build/qemu-system-riscv64 -M virt,dumpdtb=fdt.dtb -cpu rv64 $ dtc -I dtb -O dts fdt.dtb | grep mmu-type mmu-type = "riscv,sv57"; $ ./build/qemu-system-riscv64 -M virt,dumpdtb=fdt.dtb -cpu rv64,svbare=on $ dtc -I dtb -O dts fdt.dtb | grep mmu-type mmu-type = "riscv,none";Signed-off-by Daniel Henrique Barboza <[email protected]>
Alistair
Quoted 31 lines
--- target/riscv/cpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)target/riscv/cpu.c +4
-2@@ -421,7 +421,7 @@ int riscv_cpu_max_xlen(RISCVCPUClass *mcc)#ifndef CONFIG_USER_ONLY static uint8_t satp_mode_from_str (const char *satp_mode_str) { -if (!strncmp (satp_mode_str,"mbare" ,5 )) { +if (!strncmp (satp_mode_str,"svbare" ,6 )) {return VM_1_10_MBARE ; }@@ -1053,6 +1053,9 @@ void riscv_add_satp_mode_properties(Object *obj) {RISCVCPU *cpu =RISCV_CPU (obj); +object_property_add (obj,"svbare" ,"bool" , cpu_riscv_get_satp, + cpu_riscv_set_satp,NULL , &cpu->satp_modes); +if (cpu->env.misa_mxl ==MXL_RV32 ) {object_property_add (obj,"sv32" ,"bool" , cpu_riscv_get_satp, cpu_riscv_set_satp,NULL , &cpu->satp_modes); --2.43.0
Alistair Francis
AppliedRe: [PATCH 1/2] target/riscv/cpu.c: add 'svbare' satp-mode
In reply to Daniel Henrique BarbozaQuoted 13 lines · Daniel Henrique Barboza
Seems like we forgot to add a flag to set satp-mode=bare. What we're doing instead is to set the CPU default satp-mode to 'off' to set it to bare ... assuming we know the default satp-mode. Otherwise one needs to do -cpu X,sv39=off,sv48=off,sv57=off,sv64=off to get a bare-mode CPU.
Add a flag to make this process easier. The name choice is based on the fact that I didn't find many references to 'mbare' in RISC-V docs, but 'svbare' is a flag name that toolchain uses to set satp-mode=bare. Might as well use the same name to help with cross project compat.
After this patch:
Quoted 8 lines
$ ./build/qemu-system-riscv64 -M virt,dumpdtb=fdt.dtb -cpu rv64 $ dtc -I dtb -O dts fdt.dtb | grep mmu-type mmu-type = "riscv,sv57"; $ ./build/qemu-system-riscv64 -M virt,dumpdtb=fdt.dtb -cpu rv64,svbare=on $ dtc -I dtb -O dts fdt.dtb | grep mmu-type mmu-type = "riscv,none";Signed-off-by Daniel Henrique Barboza <[email protected]>
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 31 lines
--- target/riscv/cpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)target/riscv/cpu.c +4
-2@@ -421,7 +421,7 @@ int riscv_cpu_max_xlen(RISCVCPUClass *mcc)#ifndef CONFIG_USER_ONLY static uint8_t satp_mode_from_str (const char *satp_mode_str) { -if (!strncmp (satp_mode_str,"mbare" ,5 )) { +if (!strncmp (satp_mode_str,"svbare" ,6 )) {return VM_1_10_MBARE ; }@@ -1053,6 +1053,9 @@ void riscv_add_satp_mode_properties(Object *obj) {RISCVCPU *cpu =RISCV_CPU (obj); +object_property_add (obj,"svbare" ,"bool" , cpu_riscv_get_satp, + cpu_riscv_set_satp,NULL , &cpu->satp_modes); +if (cpu->env.misa_mxl ==MXL_RV32 ) {object_property_add (obj,"sv32" ,"bool" , cpu_riscv_get_satp, cpu_riscv_set_satp,NULL , &cpu->satp_modes); --2.43.0
PATCH 2/2 target/riscv/cpu.c: do not default to svbare for bare CPUs
In reply to Daniel Henrique BarbozaBack when we added bare CPUs (rv64i and friends) we didn't had a way of easily setting satp-mode to 'bare' in the command line, so we decided that if the user didn't specify a satp-mode we would limit the CPU to max_satp_mode = bare.
We don't need to do that anymore now that we can set 'svbare' in the command line, thus users can confortably set 'svbare=on' if they want.
Besides, setting svbare if no satp-mode is provided in the command line just for bare CPUs, while every other CPU will default to its max_satp_mode value, is yet another random stuff users have to deal with for no good reason. And, on top of all that, this will make it weirder to use CPUs that uses bare CPUs as their parent type.
Remove this special handling for bare CPUs.
--- target/riscv/cpu.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)
target/riscv/cpu.c +1 -19
@@ -510,21 +510,6 @@ static bool get_satp_mode_supported(RISCVCPU *cpu, uint16_t *supported) }return true; } - -/* Set the satp mode to the max supported */ -static void set_satp_mode_default_map (RISCVCPU *cpu) -{ -/* -* Bare CPUs do not default to the max available. -* Users must set a valid satp_mode in the command -* line. Otherwise, leave the existing max_satp_mode -* in place. -*/ -if (object_dynamic_cast (OBJECT (cpu),TYPE_RISCV_BARE_CPU ) !=NULL ) { -warn_report ("No satp mode set. Defaulting to 'bare'" ); - cpu->cfg.max_satp_mode =VM_1_10_MBARE ; - } -}#endif #ifndef CONFIG_USER_ONLY
@@ -896,10 +881,7 @@ static void riscv_cpu_satp_mode_finalize(RISCVCPU *cpu, Error **errp) }if (cpu->satp_modes.map ==0 ) { -if (cpu->satp_modes.init ==0 ) { -/* If unset by the user, we fallback to the default satp mode. */ -set_satp_mode_default_map (cpu); - }else { +if (cpu->satp_modes.init !=0 ) {/* * Find the lowest level that was disabled and then enable the * first valid level below which can be found in
Signature · 1 line
2.43.0
Re: [PATCH 2/2] target/riscv/cpu.c: do not default to svbare for bare CPUs
Quoted 9 lines · Daniel Henrique Barboza
Back when we added bare CPUs (rv64i and friends) we didn't had a way of easily setting satp-mode to 'bare' in the command line, so we decided that if the user didn't specify a satp-mode we would limit the CPU to
max_satp_mode= bare.We don't need to do that anymore now that we can set 'svbare' in the command line, thus users can confortably set 'svbare=on' if they want.
Quoted 7 lines
Besides, setting svbare if no satp-mode is provided in the command line just for bare CPUs, while every other CPU will default to its
max_satp_modevalue, is yet another random stuff users have to deal with for no good reason. And, on top of all that, this will make it weirder to use CPUs that uses bare CPUs as their parent type.Remove this special handling for bare CPUs.
This is a breaking change though. I think this should follow our deprecation process.
Although I'm not sure we even want to make this change. The idea of the bare CPUs was to disable everything by default (which we don't do, but that doesn't mean we should be worse at it)
Alistair
Quoted 48 lines
Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/riscv/cpu.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)target/riscv/cpu.c +1
-20@@ -510,21 +510,6 @@ static bool get_satp_mode_supported(RISCVCPU *cpu, uint16_t *supported) }return true; } - -/* Set the satp mode to the max supported */ -static void set_satp_mode_default_map (RISCVCPU *cpu) -{ -/* -* Bare CPUs do not default to the max available. -* Users must set a valid satp_mode in the command -* line. Otherwise, leave the existing max_satp_mode -* in place. -*/ -if (object_dynamic_cast (OBJECT (cpu),TYPE_RISCV_BARE_CPU ) !=NULL ) { -warn_report ("No satp mode set. Defaulting to 'bare'" ); - cpu->cfg.max_satp_mode =VM_1_10_MBARE ; - } -}#endif #ifndef CONFIG_USER_ONLY @@ -896,10 +881,7 @@ static void riscv_cpu_satp_mode_finalize(RISCVCPU *cpu, Error **errp) }if (cpu->satp_modes.map ==0 ) { -if (cpu->satp_modes.init ==0 ) { -/* If unset by the user, we fallback to the default satp mode. */ -set_satp_mode_default_map (cpu); - }else { +if (cpu->satp_modes.init !=0 ) {/* * Find the lowest level that was disabled and then enable the * first valid level below which can be found in -- 2.43.0
Re: [PATCH 2/2] target/riscv/cpu.c: do not default to svbare for bare CPUs
Quoted 17 lines · Alistair Francis
Quoted 15 lines · Daniel Henrique Barboza
Back when we added bare CPUs (rv64i and friends) we didn't had a way of easily setting satp-mode to 'bare' in the command line, so we decided that if the user didn't specify a satp-mode we would limit the CPU to
max_satp_mode= bare.We don't need to do that anymore now that we can set 'svbare' in the command line, thus users can confortably set 'svbare=on' if they want.
Besides, setting svbare if no satp-mode is provided in the command line just for bare CPUs, while every other CPU will default to its
max_satp_modevalue, is yet another random stuff users have to deal with for no good reason. And, on top of all that, this will make it weirder to use CPUs that uses bare CPUs as their parent type.
Quoted 4 lines
Quoted 1 line
Remove this special handling for bare CPUs.
This is a breaking change though. I think this should follow our deprecation process.
I don't consider this a breaking change because we're changing the default to a higher satp mode. Existing software that is running these CPUs with 'bare' will keep working because the satp mode in use is defined by the firmware. A software using 'bare' does not care, or it definitely shouldn't care at least, if the underlying virtual CPU happens to support more satp modes.
The most impactful different here is to CPUs that might be created using 'Bare' as a parent. We don't have that ATM but I did do that in the riscv-server-ref board at some point. This new CPU will have the same satp behavior as the Bare CPU, i.e. the default max_satp_mode will be defaulted to 'bare' too, ignoring any cfg.max_satp_mode that this new CPU made at its own init.
Maybe we need more debate on this. I'm okay with applying just patch 1 for now while we dwell on this one a bit.
Quoted 4 lines
Although I'm not sure we even want to make this change. The idea of the bare CPUs was to disable everything by default (which we don't do, but that doesn't mean we should be worse at it)
I think we do a good job with bare CPUs, although from my understanding the most usage they have is to be a backbone for the profile CPUs.
Cheers,
Daniel
Quoted 51 lines
Alistair
Quoted 48 lines
Signed-off-by Daniel Henrique Barboza <[email protected]>--- target/riscv/cpu.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)target/riscv/cpu.c +1
-20@@ -510,21 +510,6 @@ static bool get_satp_mode_supported(RISCVCPU *cpu, uint16_t *supported) }return true; } - -/* Set the satp mode to the max supported */ -static void set_satp_mode_default_map (RISCVCPU *cpu) -{ -/* -* Bare CPUs do not default to the max available. -* Users must set a valid satp_mode in the command -* line. Otherwise, leave the existing max_satp_mode -* in place. -*/ -if (object_dynamic_cast (OBJECT (cpu),TYPE_RISCV_BARE_CPU ) !=NULL ) { -warn_report ("No satp mode set. Defaulting to 'bare'" ); - cpu->cfg.max_satp_mode =VM_1_10_MBARE ; - } -}#endif #ifndef CONFIG_USER_ONLY @@ -896,10 +881,7 @@ static void riscv_cpu_satp_mode_finalize(RISCVCPU *cpu, Error **errp) }if (cpu->satp_modes.map ==0 ) { -if (cpu->satp_modes.init ==0 ) { -/* If unset by the user, we fallback to the default satp mode. */ -set_satp_mode_default_map (cpu); - }else { +if (cpu->satp_modes.init !=0 ) {/* * Find the lowest level that was disabled and then enable the * first valid level below which can be found in -- 2.43.0