Going to resend the series… again… without this commit because the SDK in the 
CI is the macOS 15.1 one instead of 15.2.

> On 7. Mar 2026, at 10:06, Mohamed Mediouni <[email protected]> wrote:
> 
> Signed-off-by: Mohamed Mediouni <[email protected]>
> ---
> target/arm/hvf/hvf.c        | 77 +++++++++++--------------------------
> target/arm/hvf/sysreg.c.inc | 14 +++----
> 2 files changed, 29 insertions(+), 62 deletions(-)
> 
> diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
> index 2cb4c4aa4e..4630d76930 100644
> --- a/target/arm/hvf/hvf.c
> +++ b/target/arm/hvf/hvf.c
> @@ -481,7 +481,9 @@ static const struct hvf_reg_match hvf_sme2_preg_match[] = 
> {
> 
> #define DEF_SYSREG(HVF_ID, ...) \
>   QEMU_BUILD_BUG_ON(HVF_ID != 
> KVMID_TO_HVF(KVMID_AA64_SYS_REG64(__VA_ARGS__)));
> -#define DEF_SYSREG_15_02(...)
> +
> +#define DEF_SYSREG_SME2(HVF_ID, ...) \
> +  QEMU_BUILD_BUG_ON(HVF_ID != 
> KVMID_TO_HVF(KVMID_AA64_SYS_REG64(__VA_ARGS__)));
> 
> #define DEF_SYSREG_EL2(HVF_ID, ...) \
>   QEMU_BUILD_BUG_ON(HVF_ID != 
> KVMID_TO_HVF(KVMID_AA64_SYS_REG64(__VA_ARGS__)));
> @@ -495,13 +497,13 @@ static const struct hvf_reg_match hvf_sme2_preg_match[] 
> = {
> #include "sysreg.c.inc"
> 
> #undef DEF_SYSREG
> -#undef DEF_SYSREG_15_02
> +#undef DEF_SYSREG_SME2
> #undef DEF_SYSREG_EL2
> #undef DEF_SYSREG_VGIC
> #undef DEF_SYSREG_VGIC_EL2
> 
> #define DEF_SYSREG(HVF_ID, op0, op1, crn, crm, op2)  {HVF_ID},
> -#define DEF_SYSREG_15_02(...)
> +#define DEF_SYSREG_SME2(HVF_ID, op0, op1, crn, crm, op2)  {HVF_ID, .sme2 = 
> true},
> #define DEF_SYSREG_EL2(HVF_ID, op0, op1, crn, crm, op2)  {HVF_ID, .el2 = 
> true},
> #define DEF_SYSREG_VGIC(HVF_ID, op0, op1, crn, crm, op2)  {HVF_ID, .vgic = 
> true},
> #define DEF_SYSREG_VGIC_EL2(HVF_ID, op0, op1, crn, crm, op2)  {HVF_ID, true, 
> true},
> @@ -510,6 +512,7 @@ struct hvf_sreg {
>     hv_sys_reg_t sreg;
>     bool vgic;
>     bool el2;
> +    bool sme2;
> };
> 
> static struct hvf_sreg hvf_sreg_list[] = {
> @@ -517,30 +520,13 @@ static struct hvf_sreg hvf_sreg_list[] = {
> };
> 
> #undef DEF_SYSREG
> -#undef DEF_SYSREG_15_02
> +#undef DEF_SYSREG_SME2
> #undef DEF_SYSREG_EL2
> #undef DEF_SYSREG_VGIC
> #undef DEF_SYSREG_VGIC_EL2
> 
> #pragma clang diagnostic pop
> 
> -#define DEF_SYSREG(...)
> -#define DEF_SYSREG_15_02(HVF_ID, op0, op1, crn, crm, op2) {HVF_ID},
> -#define DEF_SYSREG_EL2(...)
> -#define DEF_SYSREG_VGIC(...)
> -#define DEF_SYSREG_VGIC_EL2(...)
> -
> -API_AVAILABLE(macos(15.2))
> -static struct hvf_sreg hvf_sreg_list_sme2[] = {
> -#include "sysreg.c.inc"
> -};
> -
> -#undef DEF_SYSREG
> -#undef DEF_SYSREG_15_02
> -#undef DEF_SYSREG_EL2
> -#undef DEF_SYSREG_VGIC
> -#undef DEF_SYSREG_VGIC_EL2
> -
> /*
>  * For FEAT_SME2 migration, we need to store PSTATE.{SM,ZA} bits which are
>  * accessible with the SVCR pseudo-register. However, in the HVF API this is
> @@ -1357,23 +1343,11 @@ int hvf_arch_init_vcpu(CPUState *cpu)
>     hv_return_t ret;
>     int i;
> 
> -    if (__builtin_available(macOS 15.2, *)) {
> -        if (hvf_arm_sme2_supported()) {
> -            sregs_match_len += ARRAY_SIZE(hvf_sreg_list_sme2) + 1;
> -        }
> -
> -#define DEF_SYSREG_15_02(HVF_ID, ...) \
> -        g_assert(HVF_ID == KVMID_TO_HVF(KVMID_AA64_SYS_REG64(__VA_ARGS__)));
> -#define DEF_SYSREG(...)
> -#define DEF_SYSREG_EL2(...)
> -#define DEF_SYSREG_VGIC(...)
> -#define DEF_SYSREG_VGIC_EL2(...)
> -
> -#include "sysreg.c.inc"
> -
> -#undef DEF_SYSREG
> -#undef DEF_SYSREG_15_02
> +    if (hvf_arm_sme2_supported()) {
> +        /* SVCR will be added at the end. */
> +        sregs_match_len += 1;
>     }
> +
>     env->aarch64 = true;
> 
>     /* system count frequency sanity check */
> @@ -1408,31 +1382,24 @@ int hvf_arch_init_vcpu(CPUState *cpu)
>             continue;
>         }
> 
> +        if (hvf_sreg_list[i].sme2 && !hvf_arm_sme2_supported()) {
> +            continue;
> +        }
> +
>         if (ri) {
>             assert(!(ri->type & ARM_CP_NO_RAW));
>             arm_cpu->cpreg_indexes[sregs_cnt++] = kvm_id;
>         }
>     }
> -    if (__builtin_available(macOS 15.2, *)) {
> -        if (hvf_arm_sme2_supported()) {
> -            for (i = 0; i < ARRAY_SIZE(hvf_sreg_list_sme2); i++) {
> -                hv_sys_reg_t hvf_id = hvf_sreg_list_sme2[i].sreg;
> -                uint64_t kvm_id = HVF_TO_KVMID(hvf_id);
> -                uint32_t key = kvm_to_cpreg_id(kvm_id);
> -                const ARMCPRegInfo *ri = 
> get_arm_cp_reginfo(arm_cpu->cp_regs, key);
> 
> -                if (ri) {
> -                    assert(!(ri->type & ARM_CP_NO_RAW));
> -                    arm_cpu->cpreg_indexes[sregs_cnt++] = kvm_id;
> -                }
> -            }
> -            /*
> -             * Add SVCR last. It is elsewhere assumed its index is after
> -             * hvf_sreg_list and hvf_sreg_list_sme2.
> -             */
> -            arm_cpu->cpreg_indexes[sregs_cnt++] = HVF_TO_KVMID(SVCR);
> -        }
> +    if (hvf_arm_sme2_supported()) {
> +        /*
> +         * Add SVCR last. It is elsewhere assumed its index is after
> +         * hvf_sreg_list.
> +         */
> +        arm_cpu->cpreg_indexes[sregs_cnt++] = HVF_TO_KVMID(SVCR);
>     }
> +
>     arm_cpu->cpreg_array_len = sregs_cnt;
>     arm_cpu->cpreg_vmstate_array_len = sregs_cnt;
> 
> diff --git a/target/arm/hvf/sysreg.c.inc b/target/arm/hvf/sysreg.c.inc
> index c11dbf274e..2d29c2feec 100644
> --- a/target/arm/hvf/sysreg.c.inc
> +++ b/target/arm/hvf/sysreg.c.inc
> @@ -146,13 +146,13 @@ DEF_SYSREG(HV_SYS_REG_CNTV_CTL_EL0, 3, 3, 14, 3, 1)
> DEF_SYSREG(HV_SYS_REG_CNTV_CVAL_EL0, 3, 3, 14, 3, 2)
> DEF_SYSREG(HV_SYS_REG_SP_EL1, 3, 4, 4, 1, 0)
> 
> -DEF_SYSREG_15_02(HV_SYS_REG_SMCR_EL1, 3, 0, 1, 2, 6)
> -DEF_SYSREG_15_02(HV_SYS_REG_SMPRI_EL1, 3, 0, 1, 2, 4)
> -DEF_SYSREG_15_02(HV_SYS_REG_TPIDR2_EL0, 3, 3, 13, 0, 5)
> -DEF_SYSREG_15_02(HV_SYS_REG_ID_AA64ZFR0_EL1, 3, 0, 0, 4, 4)
> -DEF_SYSREG_15_02(HV_SYS_REG_ID_AA64SMFR0_EL1, 3, 0, 0, 4, 5)
> -DEF_SYSREG_15_02(HV_SYS_REG_SMPRI_EL1, 3, 0, 1, 2, 4)
> -DEF_SYSREG_15_02(HV_SYS_REG_SMCR_EL1, 3, 0, 1, 2, 6)
> +DEF_SYSREG_SME2(HV_SYS_REG_SMCR_EL1, 3, 0, 1, 2, 6)
> +DEF_SYSREG_SME2(HV_SYS_REG_SMPRI_EL1, 3, 0, 1, 2, 4)
> +DEF_SYSREG_SME2(HV_SYS_REG_TPIDR2_EL0, 3, 3, 13, 0, 5)
> +DEF_SYSREG_SME2(HV_SYS_REG_ID_AA64ZFR0_EL1, 3, 0, 0, 4, 4)
> +DEF_SYSREG_SME2(HV_SYS_REG_ID_AA64SMFR0_EL1, 3, 0, 0, 4, 5)
> +DEF_SYSREG_SME2(HV_SYS_REG_SMPRI_EL1, 3, 0, 1, 2, 4)
> +DEF_SYSREG_SME2(HV_SYS_REG_SMCR_EL1, 3, 0, 1, 2, 6)
> /*
>  * Block these because of the same issue as virtual counters in
>  * that caused the revert in 28b0ed32b32c7e5094cf2f1ec9c0645c65fad2aa
> -- 
> 2.50.1 (Apple Git-155)
> 
> 


Reply via email to