target/arm: Allow SME-only TCG CPUs
v2 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.
Changes since v1:
* reorder patches to put the ones that affect SME+SVE CPUs and are worth backporting to stable first
* change approach to fixing the smcr_write() assertion
* fix a non-SME-aware assert in aarch64_sve_narrow_vq()
* correct a bug in how we report the vector registers in the gdbstub: this fixes the problem where gdb hit an internal error when we emulate SME-only CPU
* squash FEAT_SME_FA64 on SME-only CPUs
This has still not really had a great deal of testing, but I think it's now good enough to remove the RFC tag.
thanks
-- PMM
Peter Maydell (6):
target/arm: Account for SME in aarch64_sve_narrow_vq() assertion target/arm: Report correct vector width in gdbstub when SME present target/arm: Handle SME-only CPUs in sve_vqm1_for_el_sm() target/arm: Handle SME-without-SVE on change of EL target/arm: Squash FEAT_SME_FA64 if FEAT_SVE is not present target/arm: Permit configurations with SME but not SVE
docs/system/arm/cpu-features.rst | 10 ++++++++-- target/arm/cpu.c | 10 ---------- target/arm/cpu64.c | 5 +++++ target/arm/gdbstub64.c | 12 ++++++------ target/arm/helper.c | 14 ++++++++++---- target/arm/internals.h | 9 +++++++++ 6 files changed, 38 insertions(+), 22 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/6 target/arm: Account for SME in aarch64_sve_narrow_vq() assertion
In aarch64_sve_narrow_vq() we assert that the new VQ is within the maximum supported range for the CPU. We forgot to update this to account for SME, which might have a different maximum.
Update the assert to permit any VQ which is valid for either SVE or SME.
---
CC stable on this one, because it might also be a problem for a CPU with both SME and SVE but where the SVE max VL is less than the SME max VL.
--- target/arm/helper.c | 2 +- target/arm/internals.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
target/arm/helper.c +1 -1
@@ -10076,7 +10076,7 @@ void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq)uint64_t pmask;assert (vq >=1 && vq <=ARM_MAX_VQ ); -assert (vq <=env_archcpu (env)->sve_max_vq); +assert (vq <=arm_max_vq (env_archcpu (env)));/* Zap the high bits of the zregs. */ for (i =0 ; i <32 ; i++) {
target/arm/internals.h +9 -0
@@ -1808,6 +1808,15 @@ static inline uint64_t arm_mdcr_el2_eff(CPUARMState *env) ((1 << (1 -1 )) | (1 << (2 -1 )) | \ (1 << (4 -1 )) | (1 << (8 -1 )) | (1 << (16 -1 ))) +/* +* Return the maximum SVE/SME VQ for this CPU. This defines +* the maximum possible size of the Zn vector registers. + */ +static inline int arm_max_vq (ARMCPU *cpu) +{ +return MAX (cpu->sve_max_vq, cpu->sme_max_vq); +} +/* * Return true if it is possible to take a fine-grained-trap to EL2. */
Signature · 1 line
2.43.0
Re: [PATCH v2 1/6] target/arm: Account for SME in aarch64_sve_narrow_vq() assertion
Quoted 9 lines · Peter Maydell
In
aarch64_sve_narrow_vq()we assert that the new VQ is within the maximum supported range for the CPU. We forgot to update this to account for SME, which might have a different maximum.Update the assert to permit any VQ which is valid for either SVE or SME.
Signed-off-by Peter Maydell <[email protected]>
Quoted 8 lines
---
CC stable on this one, because it might also be a problem for a CPU with both SME and SVE but where the SVE max VL is less than the SME max VL.--- target/arm/helper.c | 2 +- target/arm/internals.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
Re: [PATCH v2 1/6] target/arm: Account for SME in aarch64_sve_narrow_vq() assertion
In reply to Peter MaydellQuoted 9 lines · Peter Maydell
In
aarch64_sve_narrow_vq()we assert that the new VQ is within the maximum supported range for the CPU. We forgot to update this to account for SME, which might have a different maximum.Update the assert to permit any VQ which is valid for either SVE or SME.
Signed-off-by Peter Maydell <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH v2 1/6] target/arm: Account for SME in aarch64_sve_narrow_vq() assertion
In reply to Peter MaydellQuoted 9 lines · Peter Maydell
In
aarch64_sve_narrow_vq()we assert that the new VQ is within the maximum supported range for the CPU. We forgot to update this to account for SME, which might have a different maximum.Update the assert to permit any VQ which is valid for either SVE or SME.
Signed-off-by Peter Maydell<[email protected]>
Quoted 8 lines
---
CC stable on this one, because it might also be a problem for a CPU with both SME and SVE but where the SVE max VL is less than the SME max VL.--- target/arm/helper.c | 2 +- target/arm/internals.h | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
r~
PATCH v2 2/6 target/arm: Report correct vector width in gdbstub when SME present
In reply to Peter MaydellOur gdbstub implementation of the org.gnu.gdb.aarch64.sve feature doesn't account for SME correctly. We always report the Zn vector registers with a width based on the maximum SVE vector register size, even though SME's maximum size could be larger.
This is particularly bad in the case of a CPU with SME but not SVE, because there the SVE vector width will be zero. If we report the Zn registers in the XML as having a zero width then gdb falls over with an internal 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.
Report the Zn registers with their correct size. This matches how we already handle the 'vg' pseudoregister in org.gnu.gdb.aarch64.sve: we call sve_vqm1_for_el(), which returns the vector size accounting for SME, not the pure SVE vector size.
---
We should make sure we have agreement on the gdb side about the interpretation of this bit of the protocol. See this gdb mailing list email:
https://sourceware.org/pipermail/gdb/2026-January/052056.html
--- target/arm/gdbstub64.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
target/arm/gdbstub64.c +6 -6
@@ -158,7 +158,7 @@ int aarch64_gdb_get_sve_reg(CPUState *cs, GByteArray *buf, int reg) case 0 ... 31: {int vq, len =0 ; -for (vq =0 ; vq < cpu->sve_max_vq; vq++) { +for (vq =0 ; vq <arm_max_vq (cpu); vq++) { len +=gdb_get_reg128 (buf, env->vfp.zregs[reg].d[vq *2 +1 ], env->vfp.zregs[reg].d[vq *2 ]);
@@ -174,7 +174,7 @@ int aarch64_gdb_get_sve_reg(CPUState *cs, GByteArray *buf, int reg) {int preg = reg -34 ;int vq, len =0 ; -for (vq =0 ; vq < cpu->sve_max_vq; vq = vq +4 ) { +for (vq =0 ; vq <arm_max_vq (cpu); vq = vq +4 ) { len +=gdb_get_reg64 (buf, env->vfp.pregs[preg].p[vq /4 ]); }return len;
@@ -208,7 +208,7 @@ int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) case 0 ... 31: {int vq, len =0 ; -for (vq =0 ; vq < cpu->sve_max_vq; vq++) { +for (vq =0 ; vq <arm_max_vq (cpu); vq++) {if (target_big_endian ()) { env->vfp.zregs[reg].d[vq *2 +1 ] =ldq_p (buf); buf +=8 ;
@@ -233,7 +233,7 @@ int aarch64_gdb_set_sve_reg(CPUState *cs, uint8_t *buf, int reg) {int preg = reg -34 ;int vq, len =0 ; -for (vq =0 ; vq < cpu->sve_max_vq; vq = vq +4 ) { +for (vq =0 ; vq <arm_max_vq (cpu); vq = vq +4 ) { env->vfp.pregs[preg].p[vq /4 ] =ldq_p (buf); buf +=8 ; len +=8 ;
@@ -540,8 +540,8 @@ static void output_vector_union_type(GDBFeatureBuilder *builder, int reg_width,GDBFeature *arm_gen_dynamic_svereg_feature (CPUState *cs,int base_reg) {ARMCPU *cpu =ARM_CPU (cs); -int reg_width = cpu->sve_max_vq *128 ; -int pred_width = cpu->sve_max_vq *16 ; +int reg_width =arm_max_vq (cpu) *128 ; +int pred_width =arm_max_vq (cpu) *16 ;GDBFeatureBuilder builder;char *name;int reg =0 ;
Signature · 1 line
2.43.0
Re: [PATCH v2 2/6] target/arm: Report correct vector width in gdbstub when SME present
Quoted 23 lines · Peter Maydell
Our gdbstub implementation of the org.gnu.gdb.aarch64.sve feature doesn't account for SME correctly. We always report the Zn vector registers with a width based on the maximum SVE vector register size, even though SME's maximum size could be larger.
This is particularly bad in the case of a CPU with SME but not SVE, because there the SVE vector width will be zero. If we report the Zn registers in the XML as having a zero width then gdb falls over with an internal 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.Report the Zn registers with their correct size. This matches how we already handle the 'vg' pseudoregister in org.gnu.gdb.aarch64.sve: we call
sve_vqm1_for_el(), which returns the vector size accounting for SME, not the pure SVE vector size.Signed-off-by Peter Maydell <[email protected]>
Quoted 8 lines
---
We should make sure we have agreement on the gdb side about the interpretation of this bit of the protocol. See this gdb mailing list email:
https://sourceware.org/pipermail/gdb/2026-January/052056.html--- target/arm/gdbstub64.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Re: [PATCH v2 2/6] target/arm: Report correct vector width in gdbstub when SME present
In reply to Peter MaydellQuoted 16 lines · Peter Maydell
Our gdbstub implementation of the org.gnu.gdb.aarch64.sve feature doesn't account for SME correctly. We always report the Zn vector registers with a width based on the maximum SVE vector register size, even though SME's maximum size could be larger.
This is particularly bad in the case of a CPU with SME but not SVE, because there the SVE vector width will be zero. If we report the Zn registers in the XML as having a zero width then gdb falls over with an internal 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.
Quoted 7 lines
Report the Zn registers with their correct size. This matches how we already handle the 'vg' pseudoregister in org.gnu.gdb.aarch64.sve: we call
sve_vqm1_for_el(), which returns the vector size accounting for SME, not the pure SVE vector size.Signed-off-by Peter Maydell <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH v2 3/6 target/arm: Handle SME-only CPUs in sve_vqm1_for_el_sm()
In reply to Peter MaydellIn sve_vqm1_for_el_sm(), we implicitly assume that the CPU has SVE:
if called with sm == false for non-streaming mode, we try to return a vector length from svq_vq. This hits the "assert(sm)" at the bettom of the function in an SME-only CPU where sve_vq.map is zero.
Add code to handle the "SME-only CPU not in streaming mode" case: we report an effective VL of 128 bits, which is what the architecture rule R_KXKNK says should be used when SVE instructions are disabled or trapped but floating point instructions are enabled.
--- target/arm/helper.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
target/arm/helper.c +7 -1
@@ -4763,7 +4763,7 @@ int sme_exception_el(CPUARMState *env, int el) }/* -* Given that SVE is enabled, return the vector length for EL. +* Given that SVE or SME is enabled, return the vector length for EL. */ uint32_t sve_vqm1_for_el_sm (CPUARMState *env,int el,bool sm) {
@@ -4775,6 +4775,12 @@ uint32_t sve_vqm1_for_el_sm(CPUARMState *env, int el, bool sm)if (sm) { cr = env->vfp.smcr_el; map = cpu->sme_vq.map; + }else if (map ==0 ) { +/* +* SME-only CPU not in streaming mode: effective VL +* is 128 bits, per R_KXKNK. +*/ +return 0 ; }if (el <=1 && !el_is_in_host (env, el)) {
Signature · 1 line
2.43.0
Re: [PATCH v2 3/6] target/arm: Handle SME-only CPUs in sve_vqm1_for_el_sm()
Quoted 11 lines · Peter Maydell
In
sve_vqm1_for_el_sm(), we implicitly assume that the CPU has SVE:
if called with sm == false for non-streaming mode, we try to return a vector length fromsvq_vq. This hits the "assert(sm)" at the bettom of the function in an SME-only CPU where sve_vq.map is zero.Add code to handle the "SME-only CPU not in streaming mode" case: we report an effective VL of 128 bits, which is what the architecture rule
R_KXKNKsays should be used when SVE instructions are disabled or trapped but floating point instructions are enabled.Signed-off-by Peter Maydell <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH v2 3/6] target/arm: Handle SME-only CPUs in sve_vqm1_for_el_sm()
In reply to Peter MaydellQuoted 10 lines · Peter Maydell
In
sve_vqm1_for_el_sm(), we implicitly assume that the CPU has SVE:
if called with sm == false for non-streaming mode, we try to return a vector length fromsvq_vq. This hits the "assert(sm)" at the bettom of the function in an SME-only CPU where sve_vq.map is zero.Add code to handle the "SME-only CPU not in streaming mode" case: we report an effective VL of 128 bits, which is what the architecture rule
R_KXKNKsays should be used when SVE instructions are disabled or trapped but floating point instructions are enabled.
Quoted 4 lines
Signed-off-by Peter Maydell<[email protected]>--- target/arm/helper.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
r~
PATCH v2 4/6 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
@@ -10127,8 +10127,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: [PATCH v2 4/6] target/arm: Handle SME-without-SVE on change of EL
target/arm/helper.c void aarch64_sve_change_el(CPUARMState *env, int old_el,
Quoted 17 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.Reviewed-by Richard Henderson <[email protected]>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@@ -10127,8 +10127,8 @@ void aarch64_sve_change_el(CPUARMState *env, int old_el,
Could we rename the method? Maybe aarch64_vq_change_el()?
Quoted 10 lines
target/arm/helper.c +2
-2int 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 ; }
Re: [PATCH v2 4/6] target/arm: Handle SME-without-SVE on change of EL
In reply to Peter MaydellQuoted 8 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.Reviewed-by Richard Henderson <[email protected]>Signed-off-by Peter Maydell <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH v2 5/6 target/arm: Squash FEAT_SME_FA64 if FEAT_SVE is not present
In reply to Peter MaydellFEAT_SME_FA64 allows Streaming SVE code to access the whole SVE instruction set; it requires FEAT_SVE to be present. If we have a CPU with SME but not SVE, squash the FA64 bit in arm_cpu_sme_finalize().
This doesn't have any effect at the moment because we don't let the user create an SME-without-SVE CPU, but we are about to lift that restriction.
--- target/arm/cpu64.c | 5 +++++ 1 file changed, 5 insertions(+)
target/arm/cpu64.c +5 -0
@@ -363,6 +363,11 @@ void arm_cpu_sme_finalize(ARMCPU *cpu, Error **errp) cpu->sme_vq.map = vq_map; cpu->sme_max_vq =32 -clz32 (vq_map); + +if (!cpu_isar_feature (aa64_sve, cpu)) { +/* FEAT_SME_FA64 requires SVE, not just SME */ +FIELD_DP64_IDREG (&cpu->isar,ID_AA64SMFR0 ,FA64 ,0 ); + } }static bool cpu_arm_get_sme (Object *obj,Error **errp)
Signature · 1 line
2.43.0
Re: [PATCH v2 5/6] target/arm: Squash FEAT_SME_FA64 if FEAT_SVE is not present
Quoted 5 lines · Peter Maydell
FEAT_SME_FA64allows Streaming SVE code to access the whole SVE instruction set; it requiresFEAT_SVEto be present. If we have a CPU with SME but not SVE, squash the FA64 bit inarm_cpu_sme_finalize().
Quoted 8 lines
This doesn't have any effect at the moment because we don't let the user create an SME-without-SVE CPU, but we are about to lift that restriction.
Signed-off-by Peter Maydell<[email protected]>--- target/arm/cpu64.c | 5 +++++ 1 file changed, 5 insertions(+)
r~
PATCH v2 6/6 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. Mention this in the CPU property documentation.
--- docs/system/arm/cpu-features.rst | 10 ++++++++-- target/arm/cpu.c | 10 ---------- 2 files changed, 8 insertions(+), 12 deletions(-)
docs/system/arm/cpu-features.rst +8 -2
@@ -318,12 +318,18 @@ SVE CPU Property Parsing Semantics provided an error will be generated. To avoid this error, one must enable at least one vector length prior to enabling SVE. + 10) Disabling SVE does not automatically disable SME. If you want to + disable both you must use ``sve=off,sme=off``. In particular, + for the ``max`` CPU, ``sve=off`` alone will give you a CPU with + SME only (and which therefore still has the SVE vector registers). + Most users will want to disable both at once. + SVE CPU Property Examples ------------------------- - 1) Disable SVE:: + 1) Disable SVE and SME:: - $ qemu-system-aarch64 -M virt -cpu max,sve=off + $ qemu-system-aarch64 -M virt -cpu max,sve=off,sme=off 2) Implicitly enable all vector lengths for the ``max`` CPU type::
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: [PATCH v2 6/6] target/arm: Permit configurations with SME but not SVE
Quoted 38 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. Mention this in the CPU property documentation.
Reviewed-by Richard Henderson <[email protected]>Signed-off-by Peter Maydell <[email protected]>--- docs/system/arm/cpu-features.rst | 10 ++++++++-- target/arm/cpu.c | 10 ---------- 2 files changed, 8 insertions(+), 12 deletions(-)docs/system/arm/cpu-features.rst +6
-0@@ -318,12 +318,18 @@ SVE CPU Property Parsing Semantics provided an error will be generated. To avoid this error, one must enable at least one vector length prior to enabling SVE. + 10) Disabling SVE does not automatically disable SME. If you want to + disable both you must use ``sve=off,sme=off``. In particular, + for the ``max`` CPU, ``sve=off`` alone will give you a CPU with + SME only (and which therefore still has the SVE vector registers). + Most users will want to disable both at once. +
docs/system/arm/cpu-features.rst SVE CPU Property Parsing Semantics · line 334
Quoted 10 lines
docs/system/arm/cpu-features.rst +2
-2SVE CPU Property Examples ------------------------- - 1) Disable SVE:: + 1) Disable SVE and SME:: - $ qemu-system-aarch64 -M virt -cpu max,sve=off + $ qemu-system-aarch64 -M virt -cpu max,sve=off,sme=off 2) Implicitly enable all vector lengths for the ``max`` CPU type::
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro