@samitouri / QOSamiQemu / commits / 55cd59813f

hvf/arm: expose FEAT_SME2 to guest if available

Starting from M4 cores and MacOS 15.2 SDK, HVF can virtualise FEAT_SME2. Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Reviewed-by: Mohamed Mediouni <mohamed@unpredictable.fr> Message-id: 20260306-sme2-hvf-v7-2-e72eeda41ed3@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Manos Pitsidianakis committed Mar 6, 2026 at 14:45 UTC 55cd59813f148fd8adf00d8be8f36f623ec28ba9
1 file changed +23 -13
target/arm/hvf/hvf.c
+23 -13
@@ -315,6 +315,7 @@ typedef struct ARMHostCPUFeatures {
315 uint64_t features;
316 uint64_t midr;
317 uint32_t reset_sctlr;
318 + uint32_t sme_vq_supported;
319 const char *dtb_compatible;
320 } ARMHostCPUFeatures;
321
@@ -1106,6 +1107,24 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
1107 r |= hv_vcpu_config_get_feature_reg(config, regs[i].reg,
1108 &host_isar.idregs[regs[i].index]);
1109 }
1110 +
1111 + if (__builtin_available(macOS 15.2, *)) {
1112 + static const struct sme_isar_regs {
1113 + hv_feature_reg_t reg;
1114 + ARMIDRegisterIdx index;
1115 + } sme_regs[] = {
1116 + { HV_FEATURE_REG_ID_AA64SMFR0_EL1, ID_AA64SMFR0_EL1_IDX },
1117 + { HV_FEATURE_REG_ID_AA64ZFR0_EL1, ID_AA64ZFR0_EL1_IDX },
1118 + };
1119 +
1120 + if (hvf_arm_sme2_supported()) {
1121 + for (i = 0; i < ARRAY_SIZE(sme_regs); i++) {
1122 + r |= hv_vcpu_config_get_feature_reg(config, sme_regs[i].reg,
1123 + &host_isar.idregs[sme_regs[i].index]);
1124 + }
1125 + }
1126 + }
1127 +
1128 os_release(config);
1129
1130 /*
@@ -1121,19 +1140,6 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
1140
1141 clamp_id_aa64mmfr0_parange_to_ipa_size(&host_isar);
1142
1124 - /*
1125 - * Disable SME, which is not properly handled by QEMU hvf yet.
1126 - * To allow this through we would need to:
1127 - * - make sure that the SME state is correctly handled in the
1128 - * get_registers/put_registers functions
1129 - * - get the SME-specific CPU properties to work with accelerators
1130 - * other than TCG
1131 - * - fix any assumptions we made that SME implies SVE (since
1132 - * on the M4 there is SME but not SVE)
1133 - */
1134 - SET_IDREG(&host_isar, ID_AA64PFR1,
1135 - GET_IDREG(&host_isar, ID_AA64PFR1) & ~R_ID_AA64PFR1_SME_MASK);
1136 -
1143 ahcf->isar = host_isar;
1144
1145 /*
@@ -1148,6 +1154,8 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
1154 */
1155 ahcf->reset_sctlr |= 0x00800000;
1156
1157 + ahcf->sme_vq_supported = hvf_arm_sme2_supported() ? hvf_arm_sme2_get_svl() : 0;
1158 +
1159 /* Make sure we don't advertise AArch32 support for EL0/EL1 */
1160 if ((GET_IDREG(&host_isar, ID_AA64PFR0) & 0xff) != 0x11) {
1161 return false;
@@ -1199,6 +1207,7 @@ void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu)
1207 cpu->env.features = arm_host_cpu_features.features;
1208 cpu->midr = arm_host_cpu_features.midr;
1209 cpu->reset_sctlr = arm_host_cpu_features.reset_sctlr;
1210 + cpu->sme_vq.supported = arm_host_cpu_features.sme_vq_supported;
1211 }
1212
1213 void hvf_arch_vcpu_destroy(CPUState *cpu)
@@ -1343,6 +1352,7 @@ int hvf_arch_init_vcpu(CPUState *cpu)
1352 arm_cpu->isar.idregs[ID_AA64MMFR0_EL1_IDX]);
1353 assert_hvf_ok(ret);
1354
1355 + aarch64_add_sme_properties(OBJECT(cpu));
1356 return 0;
1357 }
1358