diff options
author | Like Xu <like.xu@linux.intel.com> | 2020-07-08 09:44:09 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-07-09 13:08:37 +0200 |
commit | 632a4cf57fd1bfae24f05c71398d367ca51940f1 (patch) | |
tree | 4be0dae19083fedebad26f649a634b9f30f007f0 /arch/x86/kvm/pmu.c | |
parent | KVM: x86: take as_id into account when checking PGD (diff) | |
download | linux-632a4cf57fd1bfae24f05c71398d367ca51940f1.tar.xz linux-632a4cf57fd1bfae24f05c71398d367ca51940f1.zip |
KVM/x86: pmu: Fix #GP condition check for RDPMC emulation
In guest protected mode, if the current privilege level
is not 0 and the PCE flag in the CR4 register is cleared,
we will inject a #GP for RDPMC usage.
Signed-off-by: Like Xu <like.xu@linux.intel.com>
Message-Id: <20200708074409.39028-1-like.xu@linux.intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/pmu.c')
-rw-r--r-- | arch/x86/kvm/pmu.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index b86346903f2e..67741d2a0308 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -372,6 +372,11 @@ int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data) if (!pmc) return 1; + if (!(kvm_read_cr4(vcpu) & X86_CR4_PCE) && + (kvm_x86_ops.get_cpl(vcpu) != 0) && + (kvm_read_cr0(vcpu) & X86_CR0_PE)) + return 1; + *data = pmc_read_counter(pmc) & mask; return 0; } |