Received: by 10.223.185.116 with SMTP id b49csp2081616wrg; Sun, 4 Mar 2018 17:59:51 -0800 (PST) X-Google-Smtp-Source: AG47ELsvfj7lTZaY/fuXxkNcfel9sa7/goIq5j91O6IT6eacG8Em9qfcBnR8uCRuH7MRbWOBbThf X-Received: by 2002:a17:902:8f97:: with SMTP id z23-v6mr11627780plo.162.1520215191024; Sun, 04 Mar 2018 17:59:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520215190; cv=none; d=google.com; s=arc-20160816; b=Tr7j0XKb21WC4bYCtC7Zz9KZYan+HPfUA2uTENSQ6oxViWt228HAn52CRodHpxvCDm EJA50QB3mDk5+C7SVs3rFw4rgllKPAtZZMla44goy8Ff9cCRNoNg4787YoYgXEl23Hb0 nRKcsoJmmTCSmvuqekhBeJCVeNA2U93AdVhqfrfI1uon6y3sd2XLXSO3zeSCNID/FLwp HdK5XFR1pWNngWvoKsCD0OF/P6eoOLSV+/UW3cyo4v1EQlM6QC2FWuzFFvqXTlRzbV4d v5TwB/1VgcKL4nLGZmsvgcIqgyiVa0ID3K2XmLFmyodKol/LyC+cCZJzW1YvC+15FBU4 xqfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=OJis+fmwMGDWGR7xF7AyxzFlx7czQ6qzMu7OvXTFqGI=; b=R/lSJTMg3WibbpkAa4wyYOPuV+bHYeJoTcTv4Z0OzpFO7/BkVlL6ld7frp9A+09511 b0EzpxewCyJV/3FgzgfKIj/bfZIpbJX7FFEW1SCa+4KbtnUhc6zPdsoxxQHJ4fb6BCnl 43fsNONoYNVARukR8P2b+x9Sut86eSiKPzJfKA7bu7ezjGXK1GCi3qFFY/oxlKqfWcWl ZzPD0j8tGiutP/HXeO1B+mMThoPOD8Ydo5x7Zr2zlam3TGGxFnJquAhCyIQM7gwXlZ6V wMS0axwWtF7t4a0CSsanzY9lGOwXTMm0hkqQPi5wjScM2AdmxMhrv8EqnuBLC2M+I3Su hh3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q14-v6si1371401pls.140.2018.03.04.17.59.36; Sun, 04 Mar 2018 17:59:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932613AbeCEB5O (ORCPT + 99 others); Sun, 4 Mar 2018 20:57:14 -0500 Received: from mga14.intel.com ([192.55.52.115]:39574 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932548AbeCEB5D (ORCPT ); Sun, 4 Mar 2018 20:57:03 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Mar 2018 17:57:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,425,1515484800"; d="scan'208";a="21986080" Received: from vmm.bj.intel.com ([10.238.135.172]) by fmsmga008.fm.intel.com with ESMTP; 04 Mar 2018 17:57:01 -0800 From: Luwei Kang To: kvm@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com, linux-kernel@vger.kernel.org, joro@8bytes.org, Chao Peng , Luwei Kang Subject: [PATCH v5 05/11] KVM: x86: Add Intel Processor Trace cpuid emulation Date: Sun, 4 Mar 2018 20:07:15 +0800 Message-Id: <1520165241-15819-6-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520165241-15819-1-git-send-email-luwei.kang@intel.com> References: <1520165241-15819-1-git-send-email-luwei.kang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chao Peng Expose Intel Processor Trace to guest only when PT work in HOST_GUEST mode. Signed-off-by: Chao Peng Signed-off-by: Luwei Kang --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/cpuid.c | 22 ++++++++++++++++++++-- arch/x86/kvm/svm.c | 6 ++++++ arch/x86/kvm/vmx.c | 6 ++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index df6720f..31422c0 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1032,6 +1032,7 @@ struct kvm_x86_ops { bool (*mpx_supported)(void); bool (*xsaves_supported)(void); bool (*umip_emulated)(void); + bool (*pt_supported)(void); int (*check_nested_events)(struct kvm_vcpu *vcpu, bool external_intr); diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index b671fc2..6fdb6b5 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -331,6 +331,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, unsigned f_mpx = kvm_mpx_supported() ? F(MPX) : 0; unsigned f_xsaves = kvm_x86_ops->xsaves_supported() ? F(XSAVES) : 0; unsigned f_umip = kvm_x86_ops->umip_emulated() ? F(UMIP) : 0; + unsigned f_intel_pt = kvm_x86_ops->pt_supported() ? F(INTEL_PT) : 0; /* cpuid 1.edx */ const u32 kvm_cpuid_1_edx_x86_features = @@ -388,7 +389,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, 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(SHA_NI) | F(AVX512BW) | F(AVX512VL) | f_intel_pt; /* cpuid 0xD.1.eax */ const u32 kvm_cpuid_D_1_eax_x86_features = @@ -418,7 +419,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, switch (function) { case 0: - entry->eax = min(entry->eax, (u32)0xd); + entry->eax = min(entry->eax, (u32)(f_intel_pt ? 0x14 : 0xd)); break; case 1: entry->edx &= kvm_cpuid_1_edx_x86_features; @@ -590,6 +591,23 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, } break; } + /* Intel PT */ + case 0x14: { + int t, times = entry->eax; + + if (!f_intel_pt) + break; + + entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; + for (t = 1; t <= times; ++t) { + if (*nent >= maxnent) + goto out; + do_cpuid_1_ent(&entry[t], function, t); + entry[t].flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; + ++*nent; + } + break; + } case KVM_CPUID_SIGNATURE: { static const char signature[12] = "KVMKVMKVM\0\0"; const u32 *sigptr = (const u32 *)signature; diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 312f33f..0041035 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -5719,6 +5719,11 @@ static bool svm_umip_emulated(void) return false; } +static bool svm_pt_supported(void) +{ + return false; +} + static bool svm_has_wbinvd_exit(void) { return true; @@ -6939,6 +6944,7 @@ static int svm_unregister_enc_region(struct kvm *kvm, .mpx_supported = svm_mpx_supported, .xsaves_supported = svm_xsaves_supported, .umip_emulated = svm_umip_emulated, + .pt_supported = svm_pt_supported, .set_supported_cpuid = svm_set_supported_cpuid, diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index aba747b..7a0e48c 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -9311,6 +9311,11 @@ static bool vmx_umip_emulated(void) SECONDARY_EXEC_DESC; } +static bool vmx_pt_supported(void) +{ + return (pt_mode == PT_MODE_HOST_GUEST); +} + static void vmx_recover_nmi_blocking(struct vcpu_vmx *vmx) { u32 exit_intr_info; @@ -12455,6 +12460,7 @@ static int enable_smi_window(struct kvm_vcpu *vcpu) .mpx_supported = vmx_mpx_supported, .xsaves_supported = vmx_xsaves_supported, .umip_emulated = vmx_umip_emulated, + .pt_supported = vmx_pt_supported, .check_nested_events = vmx_check_nested_events, -- 1.8.3.1