Except that each ID field should be not greater than that of host, PerfMon must be 0b0100 (PMUv3 for Armv8.1). Signed-off-by: zhanghailiang <zhang.zhanghailiang@xxxxxxxxxx> Signed-off-by: Peng Liang <liangpeng10@xxxxxxxxxx> --- arch/arm64/kvm/sys_regs.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 2ea165d09c7b..aac62f6fa846 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1323,6 +1323,32 @@ static int set_raz_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, return __set_id_reg(vcpu, rd, uaddr, true); } +static int set_id_dfr0_el1(struct kvm_vcpu *vcpu, + const struct sys_reg_desc *rd, + const struct kvm_one_reg *reg, void __user *uaddr) +{ + u32 reg_id = sys_reg((u32)rd->Op0, (u32)rd->Op1, (u32)rd->CRn, + (u32)rd->CRm, (u32)rd->Op2); + int err; + u64 val; + + err = reg_from_user(&val, uaddr, sys_reg_to_index(rd)); + if (err) + return err; + + err = check_features(reg_id, val); + if (err) + return err; + + /* Limit guests to PMUv3 for ARMv8.1 */ + if (cpuid_feature_extract_signed_field(val, ID_DFR0_PERFMON_SHIFT) != + ID_DFR0_PERFMON_8_1) + return -EINVAL; + + __vcpu_sys_reg(vcpu, ID_REG_INDEX(reg_id)) = val; + return 0; +} + static int set_id_aa64pfr0_el1(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, const struct kvm_one_reg *reg, void __user *uaddr) @@ -1642,7 +1668,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { /* CRm=1 */ ID_SANITISED(ID_PFR0_EL1), ID_SANITISED(ID_PFR1_EL1), - ID_SANITISED(ID_DFR0_EL1), + { SYS_DESC(SYS_ID_DFR0_EL1), access_id_reg, .get_user = get_id_reg, .set_user = set_id_dfr0_el1 }, ID_HIDDEN(ID_AFR0_EL1), ID_SANITISED(ID_MMFR0_EL1), ID_SANITISED(ID_MMFR1_EL1), -- 2.26.2