+++ /dev/null
-From b2f60a8fdcd51dddc0245e1e6dce33d3e2064b4a Mon Sep 17 00:00:00 2001
-From: Liran Alon <liran.alon@oracle.com>
-Date: Mon, 25 Mar 2019 21:09:17 +0200
-Subject: KVM: nVMX: Expose RDPMC-exiting only when guest supports PMU
-
-[ Upstream commit e51bfdb68725dc052d16241ace40ea3140f938aa ]
-
-Issue was discovered when running kvm-unit-tests on KVM running as L1 on
-top of Hyper-V.
-
-When vmx_instruction_intercept unit-test attempts to run RDPMC to test
-RDPMC-exiting, it is intercepted by L1 KVM which it's EXIT_REASON_RDPMC
-handler raise #GP because vCPU exposed by Hyper-V doesn't support PMU.
-Instead of unit-test expectation to be reflected with EXIT_REASON_RDPMC.
-
-The reason vmx_instruction_intercept unit-test attempts to run RDPMC
-even though Hyper-V doesn't support PMU is because L1 expose to L2
-support for RDPMC-exiting. Which is reasonable to assume that is
-supported only in case CPU supports PMU to being with.
-
-Above issue can easily be simulated by modifying
-vmx_instruction_intercept config in x86/unittests.cfg to run QEMU with
-"-cpu host,+vmx,-pmu" and run unit-test.
-
-To handle issue, change KVM to expose RDPMC-exiting only when guest
-supports PMU.
-
-Reported-by: Saar Amar <saaramar@microsoft.com>
-Reviewed-by: Mihai Carabas <mihai.carabas@oracle.com>
-Reviewed-by: Jim Mattson <jmattson@google.com>
-Signed-off-by: Liran Alon <liran.alon@oracle.com>
-Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-Signed-off-by: Sasha Levin <sashal@kernel.org>
----
- arch/x86/kvm/vmx/vmx.c | 25 +++++++++++++++++++++++++
- 1 file changed, 25 insertions(+)
-
-diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
-index da6fdd5434a17..8f0426d46ba3c 100644
---- a/arch/x86/kvm/vmx/vmx.c
-+++ b/arch/x86/kvm/vmx/vmx.c
-@@ -6982,6 +6982,30 @@ static void nested_vmx_entry_exit_ctls_update(struct kvm_vcpu *vcpu)
- }
- }
-
-+static bool guest_cpuid_has_pmu(struct kvm_vcpu *vcpu)
-+{
-+ struct kvm_cpuid_entry2 *entry;
-+ union cpuid10_eax eax;
-+
-+ entry = kvm_find_cpuid_entry(vcpu, 0xa, 0);
-+ if (!entry)
-+ return false;
-+
-+ eax.full = entry->eax;
-+ return (eax.split.version_id > 0);
-+}
-+
-+static void nested_vmx_procbased_ctls_update(struct kvm_vcpu *vcpu)
-+{
-+ struct vcpu_vmx *vmx = to_vmx(vcpu);
-+ bool pmu_enabled = guest_cpuid_has_pmu(vcpu);
-+
-+ if (pmu_enabled)
-+ vmx->nested.msrs.procbased_ctls_high |= CPU_BASED_RDPMC_EXITING;
-+ else
-+ vmx->nested.msrs.procbased_ctls_high &= ~CPU_BASED_RDPMC_EXITING;
-+}
-+
- static void update_intel_pt_cfg(struct kvm_vcpu *vcpu)
- {
- struct vcpu_vmx *vmx = to_vmx(vcpu);
-@@ -7070,6 +7094,7 @@ static void vmx_cpuid_update(struct kvm_vcpu *vcpu)
- if (nested_vmx_allowed(vcpu)) {
- nested_vmx_cr_fixed1_bits_update(vcpu);
- nested_vmx_entry_exit_ctls_update(vcpu);
-+ nested_vmx_procbased_ctls_update(vcpu);
- }
-
- if (boot_cpu_has(X86_FEATURE_INTEL_PT) &&
---
-2.20.1
-
+++ /dev/null
-From 203d4ce96d1c7e027a30a3eeb5a623834bbf0d26 Mon Sep 17 00:00:00 2001
-From: Liran Alon <liran.alon@oracle.com>
-Date: Mon, 25 Mar 2019 21:10:17 +0200
-Subject: KVM: x86: Raise #GP when guest vCPU do not support PMU
-
-[ Upstream commit 672ff6cff80ca43bf3258410d2b887036969df5f ]
-
-Before this change, reading a VMware pseduo PMC will succeed even when
-PMU is not supported by guest. This can easily be seen by running
-kvm-unit-test vmware_backdoors with "-cpu host,-pmu" option.
-
-Reviewed-by: Mihai Carabas <mihai.carabas@oracle.com>
-Signed-off-by: Liran Alon <liran.alon@oracle.com>
-Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-Signed-off-by: Sasha Levin <sashal@kernel.org>
----
- arch/x86/kvm/pmu.c | 4 ++++
- 1 file changed, 4 insertions(+)
-
-diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
-index 58ead7db71a31..e39741997893a 100644
---- a/arch/x86/kvm/pmu.c
-+++ b/arch/x86/kvm/pmu.c
-@@ -281,9 +281,13 @@ static int kvm_pmu_rdpmc_vmware(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)
- int kvm_pmu_rdpmc(struct kvm_vcpu *vcpu, unsigned idx, u64 *data)
- {
- bool fast_mode = idx & (1u << 31);
-+ struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
- struct kvm_pmc *pmc;
- u64 ctr_val;
-
-+ if (!pmu->version)
-+ return 1;
-+
- if (is_vmware_backdoor_pmc(idx))
- return kvm_pmu_rdpmc_vmware(vcpu, idx, data);
-
---
-2.20.1
-