> -----Original Message-----
> From: Eric Auger <[email protected]>
> Sent: 03 May 2026 08:34
> To: [email protected]; [email protected]; qemu-
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected]; Shameer Kolothum Thodi
> <[email protected]>; [email protected]
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]
> Subject: [PATCH v4 15/17] arm/cpu: Expose writable ID reg field properties on
> the kvm host vcpu model
> 
> External email: Use caution opening links or attachments
> 
> 
> If the host supports KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES and
> KVM_ARM_GET_REG_WRITABLE_MASKS ioctl successfully retrieved the mask
> of writable fields for all ID regs, expose uint64 SYSREG properties
> for all the writable ID reg fields exposed by the host kernel which
> can be matched in target/arm/cpu-sysreg-properties.c.
> 
> Properties are named  SYSREG_<REG>_<FIELD> with REG and FIELD
> being those used in linux arch/arm64/tools/sysreg or in the AARCHMRS
> Registers.json.
> 
> This is achieved by matching the writable fields retrieved from the
> host kernel against the generated description of ID regs and their
> fields in target/arm/cpu-sysreg-properties.c.
> 
> An example of invocation is:
> -cpu host,SYSREG_ID_AA64ISAR0_EL1_DP=0x0
> which sets DP field of ID_AA64ISAR0_EL1 to 0.
> 
> [CH: add properties to the host model instead of introducing a new
> "custom" model]
> Signed-off-by: Eric Auger <[email protected]>
> Signed-off-by: Cornelia Huck <[email protected]>
> ---
>  target/arm/cpu.c   | 12 ++++++++++++
>  target/arm/cpu64.c | 23 ++++++++++++++++++++++-
>  2 files changed, 34 insertions(+), 1 deletion(-)
> 
> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
> index 10feb639c4..10ce4eb0cb 100644
> --- a/target/arm/cpu.c
> +++ b/target/arm/cpu.c
> @@ -1824,6 +1824,18 @@ static void arm_cpu_realizefn(DeviceState *dev,
> Error **errp)
>          return;
>      }
> 
> +    /*
> +     * If we failed to retrieve the set of writable ID registers for the 
> "host"
> +     * CPU model, report it here. No error if the interface for discovering
> +     * writable ID registers is not available.
> +     * In case we did get the set of writable ID registers, set the features 
> to
> +     * the configured values here and perform some sanity checks.
> +     */
> +    if (cpu->writable_id_regs_status == WRITABLE_ID_REGS_FAILED) {
> +        error_setg(errp, "Failed to discover writable id registers");
> +        return;
> +    }
> +
>      if (!cpu->gt_cntfrq_hz) {
>          /*
>           * 0 means "the board didn't set a value, use the default". (We also
> diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
> index 1b3d3fb245..d66cb00a21 100644
> --- a/target/arm/cpu64.c
> +++ b/target/arm/cpu64.c
> @@ -852,6 +852,8 @@ static void
> kvm_arm_set_cpreg_mig_tolerances(ARMCPU *cpu)
>  static void aarch64_host_initfn(Object *obj)
>  {
>      ARMCPU *cpu = ARM_CPU(obj);
> +    bool expose_id_regs = true;
> +    int ret;

The above will be unused for non KVM builds.

> 
>  #if defined(CONFIG_NITRO)
>      if (nitro_enabled()) {
> @@ -862,8 +864,27 @@ static void aarch64_host_initfn(Object *obj)
> 
>  #if defined(CONFIG_KVM)
>      kvm_arm_set_cpreg_mig_tolerances(cpu);
> -    kvm_arm_set_cpu_features_from_host(cpu, false);
> +
> +    cpu->writable_map = g_malloc(sizeof(IdRegMap));

Does kernel clear the buffer before setting writable mask?

> +    /* discover via KVM_ARM_GET_REG_WRITABLE_MASKS */
> +    ret = kvm_arm_get_writable_id_regs(cpu, cpu->writable_map);
> +    if (ret == -ENOSYS) {
> +        /* legacy: continue without writable id regs */
> +        expose_id_regs = false;
> +    } else if (ret) {
> +        /* function will have marked an error */
> +        return;
> +    }

Should free and NULL writable_map for both error paths above.

Thanks,
Shameer

> +
> +    kvm_arm_set_cpu_features_from_host(cpu, expose_id_regs);
>      aarch64_add_sve_properties(obj);
> +
> +    if (expose_id_regs) {
> +        /* generate SYSREG properties according to writable masks */
> +        kvm_arm_expose_idreg_properties(cpu, arm64_id_regs);
> +    }
> +
>  #elif defined(CONFIG_HVF)
>      hvf_arm_set_cpu_features_from_host(cpu);
>  #elif defined(CONFIG_WHPX)
> --
> 2.53.0


Reply via email to