@@ -451,28 +451,28 @@ static int set_id_dfr0_el1(struct kvm_vcpu *vcpu,
if (kvm_vcpu_has_pmu(vcpu) != valid_pmu)
return -EINVAL;
- if (valid_pmu) {
- mutex_lock(&vcpu->kvm->arch.config_lock);
- ret = set_id_reg(vcpu, rd, val);
- if (ret) {
- mutex_unlock(&vcpu->kvm->arch.config_lock);
- return ret;
- }
+ if (!valid_pmu) {
+ /* Ignore the PerfMon field in val */
+ perfmon = FIELD_GET(ID_DFR0_EL1_PerfMon_MASK, read_id_reg(vcpu, rd));
+ val &= ~ID_DFR0_EL1_PerfMon_MASK;
+ val |= FIELD_PREP(ID_DFR0_EL1_PerfMon_MASK, perfmon);
+ }
- IDREG(vcpu->kvm, SYS_ID_AA64DFR0_EL1) &= ~ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer);
- IDREG(vcpu->kvm, SYS_ID_AA64DFR0_EL1) |=
- FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer), perfmon_to_pmuver(perfmon));
+ mutex_lock(&vcpu->kvm->arch.config_lock);
+ ret = set_id_reg(vcpu, rd, val);
+ if (ret) {
mutex_unlock(&vcpu->kvm->arch.config_lock);
- } else {
- /* We can only differ with PerfMon, and anything else is an error */
- val ^= read_id_reg(vcpu, rd);
- val &= ~ARM64_FEATURE_MASK(ID_DFR0_EL1_PerfMon);
- if (val)
- return -EINVAL;
+ return ret;
+ }
+ IDREG(vcpu->kvm, SYS_ID_AA64DFR0_EL1) &= ~ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer);
+ IDREG(vcpu->kvm, SYS_ID_AA64DFR0_EL1) |=
+ FIELD_PREP(ARM64_FEATURE_MASK(ID_AA64DFR0_EL1_PMUVer), perfmon_to_pmuver(perfmon));
+
+ if (!valid_pmu)
assign_bit(KVM_ARCH_FLAG_VCPU_HAS_IMP_DEF_PMU, &vcpu->kvm->arch.flags,
perfmon == ID_DFR0_EL1_PerfMon_IMPDEF);
- }
+ mutex_unlock(&vcpu->kvm->arch.config_lock);
return 0;
}
@@ -560,7 +560,7 @@ static struct id_reg_desc id_reg_descs[KVM_ARM_ID_REG_NUM] = {
.set_user = set_id_dfr0_el1,
.visibility = aa32_id_visibility, },
.ftr_bits = ftr_id_dfr0,
- .writable_mask = ID_DFR0_EL1_PerfMon_MASK,
+ .writable_mask = GENMASK(63, 0),
.read_kvm_sanitised_reg = read_sanitised_id_dfr0_el1,
},
ID_HIDDEN(ID_AFR0_EL1),
All valid fields in ID_DFR0_EL1 are writable from usrespace with this change. Signed-off-by: Jing Zhang <jingzhangos@google.com> --- arch/arm64/kvm/id_regs.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)