arm64: KVM: PMU: Inject UNDEF on non-privileged accesses
authorMarc Zyngier <marc.zyngier@arm.com>
Mon, 27 Mar 2017 16:03:39 +0000 (17:03 +0100)
committerChristoffer Dall <cdall@linaro.org>
Sun, 9 Apr 2017 14:49:13 +0000 (07:49 -0700)
access_pminten() and access_pmuserenr() can only be accessed when
the CPU is in a priviledged mode. If it is not, let's inject an
UNDEF exception.

Reviewed-by: Christoffer Dall <cdall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
arch/arm64/kvm/sys_regs.c

index 750c129..d343c0f 100644 (file)
@@ -709,8 +709,10 @@ static bool access_pminten(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
        if (!kvm_arm_pmu_v3_ready(vcpu))
                return trap_raz_wi(vcpu, p, r);
 
-       if (!vcpu_mode_priv(vcpu))
+       if (!vcpu_mode_priv(vcpu)) {
+               kvm_inject_undefined(vcpu);
                return false;
+       }
 
        if (p->is_write) {
                u64 val = p->regval & mask;
@@ -780,8 +782,10 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
                return trap_raz_wi(vcpu, p, r);
 
        if (p->is_write) {
-               if (!vcpu_mode_priv(vcpu))
+               if (!vcpu_mode_priv(vcpu)) {
+                       kvm_inject_undefined(vcpu);
                        return false;
+               }
 
                vcpu_sys_reg(vcpu, PMUSERENR_EL0) = p->regval
                                                    & ARMV8_PMU_USERENR_MASK;