KVM: arm64: Hoist PMUv3 check into KVM_ARM_VCPU_INIT ioctl handler
authorOliver Upton <oliver.upton@linux.dev>
Wed, 20 Sep 2023 19:50:30 +0000 (19:50 +0000)
committerOliver Upton <oliver.upton@linux.dev>
Thu, 21 Sep 2023 18:13:28 +0000 (18:13 +0000)
Test that the system supports PMUv3 before ever getting to
kvm_reset_vcpu().

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Link: https://lore.kernel.org/r/20230920195036.1169791-3-oliver.upton@linux.dev
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/kvm/arm.c
arch/arm64/kvm/reset.c

index 8b5094343f84bbc18c47fd7f18aa6388e64b4beb..18cbd3c9a4d777dfb11e3289c1e365c930b76cb5 100644 (file)
@@ -1197,6 +1197,9 @@ static unsigned long system_supported_vcpu_features(void)
        if (!cpus_have_final_cap(ARM64_HAS_32BIT_EL1))
                clear_bit(KVM_ARM_VCPU_EL1_32BIT, &features);
 
+       if (!kvm_arm_support_pmu_v3())
+               clear_bit(KVM_ARM_VCPU_PMU_V3, &features);
+
        return features;
 }
 
index 7a65a35ee4ac4165b4147c724d28b59f8150a0d2..5b5c74cb901d7a1ddc8931d75a12459e793167fc 100644 (file)
@@ -255,11 +255,6 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
        else
                pstate = VCPU_RESET_PSTATE_EL1;
 
-       if (kvm_vcpu_has_pmu(vcpu) && !kvm_arm_support_pmu_v3()) {
-               ret = -EINVAL;
-               goto out;
-       }
-
        /* Reset core registers */
        memset(vcpu_gp_regs(vcpu), 0, sizeof(*vcpu_gp_regs(vcpu)));
        memset(&vcpu->arch.ctxt.fp_regs, 0, sizeof(vcpu->arch.ctxt.fp_regs));