On 5/7/26 12:07 PM, Shameer Kolothum Thodi wrote: > >> -----Original Message----- >> From: Eric Auger <[email protected]> >> Sent: 03 May 2026 08:33 >> 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 08/17] target/arm/kvm: Introduce >> kvm_get_writable_id_regs >> >> External email: Use caution opening links or attachments >> >> >> From: Cornelia Huck <[email protected]> >> >> Add an helper to retrieve the writable id reg bitmask. The >> status of the query is stored in the CPU struct so that an >> an error, if any, can be reported on vcpu realize(). >> >> Signed-off-by: Eric Auger <[email protected]> >> Signed-off-by: Cornelia Huck <[email protected]> >> --- >> target/arm/cpu.h | 26 ++++++++++++++++++++++++++ >> target/arm/kvm.c | 32 ++++++++++++++++++++++++++++++++ >> target/arm/kvm_arm.h | 3 +++ >> 3 files changed, 61 insertions(+) >> >> diff --git a/target/arm/cpu.h b/target/arm/cpu.h >> index be14a47c35..2aa22360d2 100644 >> --- a/target/arm/cpu.h >> +++ b/target/arm/cpu.h >> @@ -866,6 +866,26 @@ typedef struct { >> uint32_t map, init, supported; >> } ARMVQMap; >> >> +typedef enum ARMIdRegsState { >> + WRITABLE_ID_REGS_UNKNOWN, >> + WRITABLE_ID_REGS_NOT_DISCOVERABLE, >> + WRITABLE_ID_REGS_FAILED, >> + WRITABLE_ID_REGS_AVAIL, >> +} ARMIdRegsState; >> + >> +/* >> + * The following structures are for the purpose of mapping the output of >> + * KVM_ARM_GET_REG_WRITABLE_MASKS that also may cover id registers >> we do >> + * not support in QEMU >> + * ID registers in op0==3, op1=={0,1,3}, crn=0, crm=={0-7}, op2=={0-7}, >> + * as used by the KVM_ARM_GET_REG_WRITABLE_MASKS ioctl call. >> + */ >> +#define NR_ID_REG_MASKS (3 * 8 * 8) > Probably can re-use KVM_ARM_FEATURE_ID_RANGE_SIZE here. > Looks like used for the same purpose in: > tools/testing/selftests/kvm/arm64/set_id_regs.c removed. The writable_map array is now dynamically allocated in kvm_arch_init_vcpu() Thanks Eric > > Thanks, > Shameer >> + >> +typedef struct IdRegMap { >> + uint64_t regs[NR_ID_REG_MASKS]; /* writable masks for registers */ >> +} IdRegMap; >> + >> /* REG is ID_XXX */ >> #define FIELD_DP64_IDREG(ISAR, REG, FIELD, VALUE) \ >> ({ \ >> @@ -1054,6 +1074,12 @@ struct ArchCPU { >> */ >> bool host_cpu_probe_failed; >> >> + /* >> + * state of writable id regs query used to report an error, if any, >> + * on vcpu model realize >> + */ >> + ARMIdRegsState writable_id_regs_status; >> + >> /* QOM property to indicate we should use the back-compat CNTFRQ >> default */ >> bool backcompat_cntfrq; >> >> diff --git a/target/arm/kvm.c b/target/arm/kvm.c >> index d4a68874b8..f06a60804d 100644 >> --- a/target/arm/kvm.c >> +++ b/target/arm/kvm.c >> @@ -51,6 +51,7 @@ const KVMCapabilityInfo >> kvm_arch_required_capabilities[] = { >> static bool cap_has_mp_state; >> static bool cap_has_inject_serror_esr; >> static bool cap_has_inject_ext_dabt; >> +static int cap_writable_id_regs; >> >> /** >> * ARMHostCPUFeatures: information about the host CPU (identified >> @@ -499,6 +500,37 @@ void >> kvm_arm_set_cpu_features_from_host(ARMCPU *cpu) >> env->features = arm_host_cpu_features.features; >> } >> >> +int kvm_arm_get_writable_id_regs(ARMCPU *cpu, IdRegMap *idregmap) >> +{ >> + struct reg_mask_range range = { >> + .range = 0, /* up to now only a single range is supported */ >> + .addr = (uint64_t)idregmap, >> + }; >> + int ret; >> + >> + if (!kvm_enabled()) { >> + cpu->writable_id_regs_status = >> WRITABLE_ID_REGS_NOT_DISCOVERABLE; >> + return -ENOSYS; >> + } >> + >> + cap_writable_id_regs = >> + kvm_check_extension(kvm_state, >> KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES); >> + >> + if (!cap_writable_id_regs || >> + !(cap_writable_id_regs & (1 << KVM_ARM_FEATURE_ID_RANGE))) { >> + cpu->writable_id_regs_status = >> WRITABLE_ID_REGS_NOT_DISCOVERABLE; >> + return -ENOSYS; >> + } >> + >> + ret = kvm_vm_ioctl(kvm_state, KVM_ARM_GET_REG_WRITABLE_MASKS, >> &range); >> + if (ret) { >> + cpu->writable_id_regs_status = WRITABLE_ID_REGS_FAILED; >> + return ret; >> + } >> + cpu->writable_id_regs_status = WRITABLE_ID_REGS_AVAIL; >> + return ret; >> +} >> + >> static bool kvm_no_adjvtime_get(Object *obj, Error **errp) >> { >> return !ARM_CPU(obj)->kvm_adjvtime; >> diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h >> index e7c40fb003..b22a56fc17 100644 >> --- a/target/arm/kvm_arm.h >> +++ b/target/arm/kvm_arm.h >> @@ -240,4 +240,7 @@ void arm_gic_cap_kvm_probe(GICCapability *v2, >> GICCapability *v3); >> */ >> char *kvm_print_register_name(uint64_t regidx); >> >> +typedef struct IdRegMap IdRegMap; >> +int kvm_arm_get_writable_id_regs(ARMCPU *cpu, IdRegMap *idregmap); >> + >> #endif >> -- >> 2.53.0
