target/arm: Allow SME-only TCG CPUs
cover target/arm: Allow SME-only TCG CPUs
These patches add support to TCG for a CPU with SME but not SVE. We originally prevented users from doing that in the run-up to a release, in commit f7767ca30179 ("target/arm: Disable SME if SVE is disabled") by forcing SME to off if SVE wasn't implemented. This was a simple way to avoid users hitting an assertion failure.
I tracked down exactly why we were getting that assertion failure, and fixed another "assumes SME implies SME" issue I spotted in the code while I was auditing the various callers of sve_vqm1_sve_for_el(). This lets us remove the hack we originally put in.
This is an RFC because:
* I tested that we can boot a kernel and it detects SME, but don't have an SME guest workload to hand that does much with registers, vector length, etc.
* having "-cpu max,sve=off" now give you this oddball "SME only" config is perhaps surprising to users. We could perhaps flag this up in cpu-features.rst somewhere.
* as noted in the other thread that adds hvf support for SME-only CPUs, it turns out that gdb will crash if you connect it to our debug stub in this config.
But I think the first two patches are worth getting reviewed and into the tree even if we haven't figured out yet if we want to hold off until we have an idea what to do about gdb.
Peter Maydell (3):
target/arm: Make smcr_write() handle SME-without-SVE target/arm: Handle SME-without-SVE on change of EL target/arm: Permit configurations with SME but not SVE
target/arm/cpu.c | 10 ---------- target/arm/helper.c | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 18 deletions(-)
Signature · 1 line
2.43.0
RFC PATCH 1/3 target/arm: Make smcr_write() handle SME-without-SVE
Currently smcr_write() implicitly assumes that SME implies SVE, because it will call sve_vqm1_sve_for_el() when SMCR.SM is 0, and sve_vqm1_sve_for_el() will assert in that situation.
This is the only place where we call that function without it being guarded by a check on whether SVE is implemented. Adjust smcr_write() so that it also avoids asking for the SVE vector length when SVE is not implemented.
---
I did think about making sve_vqm1_sve_for_el() return some value rather than asserting, but (a) what would be the right value? and (b) this was the only place that needed fixing.
--- target/arm/helper.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
target/arm/helper.c +13 -6
@@ -4936,12 +4936,12 @@ static void smcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) {int cur_el =arm_current_el (env); -int old_len =sve_vqm1_for_el (env, cur_el); +ARMCPU *cpu =env_archcpu (env); +int old_len =cpu_isar_feature (aa64_sve, cpu) ?sve_vqm1_for_el (env, cur_el) :0 ;uint64_t valid_mask =R_SMCR_LEN_MASK |R_SMCR_FA64_MASK ; -int new_len;QEMU_BUILD_BUG_ON (ARM_MAX_VQ >R_SMCR_LEN_MASK +1 ); -if (cpu_isar_feature (aa64_sme2,env_archcpu (env))) { +if (cpu_isar_feature (aa64_sme2, cpu)) { valid_mask |=R_SMCR_EZT0_MASK ; } value &= valid_mask;
@@ -4953,10 +4953,17 @@ static void smcr_write(CPUARMState *env, const ARMCPRegInfo *ri,* current values for simplicity. But for QEMU internals, we must still * apply the narrower SVL to the Zregs and Pregs -- see the comment * above aarch64_sve_narrow_vq. +* +* If the CPU has only SME and not SVE, then turning streaming mode +* on and off can't ever change the SVL; we must avoid calling +* sve_vqm1_for_el() to ask for the SVE vector length when SM is 0 +* because it will assert. */ - new_len =sve_vqm1_for_el (env, cur_el); -if (new_len < old_len) { -aarch64_sve_narrow_vq (env, new_len +1 ); +if (cpu_isar_feature (aa64_sve, cpu)) { +int new_len =sve_vqm1_for_el (env, cur_el); +if (new_len < old_len) { +aarch64_sve_narrow_vq (env, new_len +1 ); + } } }
Signature · 1 line
2.43.0
Re: [RFC PATCH 1/3] target/arm: Make smcr_write() handle SME-without-SVE
Quoted 48 lines · Peter Maydell
Currently
smcr_write()implicitly assumes that SME implies SVE, because it will callsve_vqm1_sve_for_el()when SMCR.SM is 0, andsve_vqm1_sve_for_el()will assert in that situation.This is the only place where we call that function without it being guarded by a check on whether SVE is implemented. Adjust
smcr_write()so that it also avoids asking for the SVE vector length when SVE is not implemented.Signed-off-by Peter Maydell <[email protected]>---
I did think about makingsve_vqm1_sve_for_el()return some value rather than asserting, but (a) what would be the right value? and (b) this was the only place that needed fixing.--- target/arm/helper.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)target/arm/helper.c +8
-3@@ -4936,12 +4936,12 @@ static void smcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) {int cur_el =arm_current_el (env); -int old_len =sve_vqm1_for_el (env, cur_el); +ARMCPU *cpu =env_archcpu (env); +int old_len =cpu_isar_feature (aa64_sve, cpu) ?sve_vqm1_for_el (env, cur_el) :0 ;uint64_t valid_mask =R_SMCR_LEN_MASK |R_SMCR_FA64_MASK ; -int new_len;QEMU_BUILD_BUG_ON (ARM_MAX_VQ >R_SMCR_LEN_MASK +1 ); -if (cpu_isar_feature (aa64_sme2,env_archcpu (env))) { +if (cpu_isar_feature (aa64_sme2, cpu)) { valid_mask |=R_SMCR_EZT0_MASK ; } value &= valid_mask;@@ -4953,10 +4953,17 @@ static void smcr_write(CPUARMState *env, const ARMCPRegInfo *ri,* current values for simplicity. But for QEMU internals, we must still * apply the narrower SVL to the Zregs and Pregs -- see the comment * above aarch64_sve_narrow_vq. +* +* If the CPU has only SME and not SVE, then turning streaming mode +* on and off can't ever change the SVL; we must avoid calling +* sve_vqm1_for_el() to ask for the SVE vector length when SM is 0 +* because it will assert.
target/arm/helper.c static void smcr_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 4967
Quoted 10 lines
target/arm/helper.c +5
-3*/ - new_len =sve_vqm1_for_el (env, cur_el); -if (new_len < old_len) { -aarch64_sve_narrow_vq (env, new_len +1 ); +if (cpu_isar_feature (aa64_sve, cpu)) { +int new_len =sve_vqm1_for_el (env, cur_el); +if (new_len < old_len) { +aarch64_sve_narrow_vq (env, new_len +1 ); + } }
This isn't right -- I forgot that SMCR also has the SME vector length, so old_len / new_len can be different here and we need to call narrow_vq for that case.
Also aarch64_sve_narrow_vq() does this:
assert(vq <= env_archcpu(env)->sve_max_vq);
and I think that should be asserting that the new vq is <= MAX(sve_max_vq, sme_max_vq).
-- PMM
RFC PATCH 2/3 target/arm: Handle SME-without-SVE on change of EL
In reply to Peter Maydellaarch64_sve_change_el() currently assumes that SME implies SVE, and will return without doing anything if SVE is not implemented, skipping a possible requirement to change the vector register state because the SME vector length has changed. Update it to handle SME also.
--- target/arm/helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/arm/helper.c +2 -2
@@ -10128,8 +10128,8 @@ void aarch64_sve_change_el(CPUARMState *env, int old_el,int old_len, new_len;bool old_a64, new_a64, sm; -/* Nothing to do if no SVE. */ -if (!cpu_isar_feature (aa64_sve, cpu)) { +/* Nothing to do if no SVE or SME. */ +if (!cpu_isar_feature (aa64_sve, cpu) && !cpu_isar_feature (aa64_sme, cpu)) {return ; }
Signature · 1 line
2.43.0
Re: [RFC PATCH 2/3] target/arm: Handle SME-without-SVE on change of EL
Quoted 16 lines · Peter Maydell
aarch64_sve_change_el()currently assumes that SME implies SVE, and will return without doing anything if SVE is not implemented, skipping a possible requirement to change the vector register state because the SME vector length has changed. Update it to handle SME also.Signed-off-by Peter Maydell <[email protected]>--- target/arm/helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/arm/helper.c +0
-0
target/arm/helper.c void aarch64_sve_change_el(CPUARMState *env, int old_el, · line 10135
Quoted 10 lines
target/arm/helper.c +2
-2@@ -10128,8 +10128,8 @@ void aarch64_sve_change_el(CPUARMState *env, int old_el,int old_len, new_len;bool old_a64, new_a64, sm; -/* Nothing to do if no SVE. */ -if (!cpu_isar_feature (aa64_sve, cpu)) { +/* Nothing to do if no SVE or SME. */ +if (!cpu_isar_feature (aa64_sve, cpu) && !cpu_isar_feature (aa64_sme, cpu)) {return ; }
r~
RFC PATCH 3/3 target/arm: Permit configurations with SME but not SVE
In reply to Peter MaydellIn commit f7767ca30179 ("target/arm: Disable SME if SVE is disabled") we added code that forces SME to be disabled if SVE is disabled. This was something we did in the run-up to a release to avoid an assertion failure in smcr_write() if the user disabled SVE on the 'max' CPU without disabling SME also.
Now that we have corrected the code so that it doesn't assert in an SME-without-SVE setup, we can let users select it.
This effectively reverts f7767ca30179.
Note that this now means that command lines like "-cpu max,sve=off" which used to turn off SME and SVE will now give you a CPU with SME but not SVE. This is permitted by our loose "max can always give you extra stuff" rules, but may be unexpected to users.
In particular, gdb crashes when told about a CPU with only SME via the gdbstub register XML with this error:
(gdb) target remote :1234
Remote debugging using :1234
/build/gdb-1WjiBe/gdb-15.0.50.20240403/gdb/aarch64-tdep.c:3066: internal-error: aarch64_pseudo_register_type: bad register number 160 A problem internal to GDB has been detected,
further debugging may prove unreliable.
--- target/arm/cpu.c | 10 ---------- 1 file changed, 10 deletions(-)
target/arm/cpu.c +0 -10
@@ -1571,16 +1571,6 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp)return ; } -/* -* FEAT_SME is not architecturally dependent on FEAT_SVE (unless -* FEAT_SME_FA64 is present). However our implementation currently -* assumes it, so if the user asked for sve=off then turn off SME also. -* (KVM doesn't currently support SME at all.) -*/ -if (cpu_isar_feature (aa64_sme, cpu) && !cpu_isar_feature (aa64_sve, cpu)) { -object_property_set_bool (OBJECT (cpu),"sme" , false, &error_abort); - } -arm_cpu_sme_finalize (cpu, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);
Signature · 1 line
2.43.0
Re: [RFC PATCH 3/3] target/arm: Permit configurations with SME but not SVE
Quoted 42 lines · Peter Maydell
In commit
f7767ca30179("target/arm: Disable SME if SVE is disabled") we added code that forces SME to be disabled if SVE is disabled. This was something we did in the run-up to a release to avoid an assertion failure insmcr_write()if the user disabled SVE on the 'max' CPU without disabling SME also.Now that we have corrected the code so that it doesn't assert in an SME-without-SVE setup, we can let users select it.
This effectively reverts
f7767ca30179.Note that this now means that command lines like "-cpu max,sve=off" which used to turn off SME and SVE will now give you a CPU with SME but not SVE. This is permitted by our loose "max can always give you extra stuff" rules, but may be unexpected to users.
In particular, gdb crashes when told about a CPU with only SME via the gdbstub register XML with this error:
(gdb) target remote :1234
Remote debugging using :1234
/build/gdb-1WjiBe/gdb-15.0.50.20240403/gdb/aarch64-tdep.c:3066: internal-error:aarch64_pseudo_register_type: bad register number 160 A problem internal to GDB has been detected,
further debugging may prove unreliable.Signed-off-by Peter Maydell <[email protected]>--- target/arm/cpu.c | 10 ---------- 1 file changed, 10 deletions(-)target/arm/cpu.c +0
-3@@ -1571,16 +1571,6 @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp)return ; } -/* -* FEAT_SME is not architecturally dependent on FEAT_SVE (unless -* FEAT_SME_FA64 is present). However our implementation currently
target/arm/cpu.c void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp) · line 1576
Quoted 10 lines
target/arm/cpu.c +0
-7-* assumes it, so if the user asked for sve=off then turn off SME also. -* (KVM doesn't currently support SME at all.) -*/ -if (cpu_isar_feature (aa64_sme, cpu) && !cpu_isar_feature (aa64_sve, cpu)) { -object_property_set_bool (OBJECT (cpu),"sme" , false, &error_abort); - } -arm_cpu_sme_finalize (cpu, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);
We do need to squash FA64 if sve=off, probably in arm_cpu_sme_finalize, perhaps as a previous patch.
Anyway, as far as this goes,
r~