[PATCH 23/26] KVM: x86: Handle Intel PT CPUID adjustment in vendor code

From: Sean Christopherson
Date: Wed Jan 29 2020 - 18:47:03 EST


Move the Processor Trace CPUID adjustment into vendor code to eliminate
an instance of the undesirable "unsigned f_* = *_supported ? F(*) : 0"
pattern in the common CPUID handling code, and to pave the way toward
eventually removing ->pt_supported().

No functional change intended.

Signed-off-by: Sean Christopherson <sean.j.christopherson@xxxxxxxxx>
---
arch/x86/kvm/cpuid.c | 3 +--
arch/x86/kvm/svm.c | 1 +
arch/x86/kvm/vmx/vmx.c | 2 ++
3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 75971c254b4d..eb61a1d83598 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -321,7 +321,6 @@ static int __do_cpuid_func_emulated(struct kvm_cpuid_entry2 *entry,

static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index)
{
- unsigned f_intel_pt = kvm_x86_ops->pt_supported() ? F(INTEL_PT) : 0;
unsigned f_la57;

/* cpuid 7.0.ebx */
@@ -330,7 +329,7 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry, int index)
F(BMI2) | F(ERMS) | F(INVPCID) | F(RTM) | F(MPX) | F(RDSEED) |
F(ADX) | F(SMAP) | F(AVX512IFMA) | F(AVX512F) | F(AVX512PF) |
F(AVX512ER) | F(AVX512CD) | F(CLFLUSHOPT) | F(CLWB) | F(AVX512DQ) |
- F(SHA_NI) | F(AVX512BW) | F(AVX512VL) | f_intel_pt;
+ F(SHA_NI) | F(AVX512BW) | F(AVX512VL) | F(INTEL_PT);

/* cpuid 7.0.ecx*/
const u32 kvm_cpuid_7_0_ecx_x86_features =
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 7d6f46399e5a..350cdf91a576 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -6066,6 +6066,7 @@ static void svm_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)
cpuid_entry_clear(entry, X86_FEATURE_PKU);
cpuid_entry_clear(entry, X86_FEATURE_MPX);
cpuid_entry_clear(entry, X86_FEATURE_INVPCID);
+ cpuid_entry_clear(entry, X86_FEATURE_INTEL_PT);
break;
case 0x80000001:
if (nested)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 941ac7296735..35134dbed2f0 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -7149,6 +7149,8 @@ static void vmx_set_supported_cpuid(struct kvm_cpuid_entry2 *entry)
cpuid_entry_clear(entry, X86_FEATURE_MPX);
if (!cpu_has_vmx_invpcid())
cpuid_entry_clear(entry, X86_FEATURE_INVPCID);
+ if (!vmx_pt_mode_is_host_guest())
+ cpuid_entry_clear(entry, X86_FEATURE_INTEL_PT);

if (vmx_umip_emulated())
cpuid_entry_set(entry, X86_FEATURE_UMIP);
--
2.24.1