Received: by 10.223.164.221 with SMTP id h29csp3779828wrb; Tue, 31 Oct 2017 04:52:25 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TFDkGRpqAUgBMqRrXJ7jZg9UrtZsIs5LdlQrbf/M/sqbpgB6fY8Z1GDDj7WlNOwo0BbdYt X-Received: by 10.84.225.145 with SMTP id u17mr1612113plj.309.1509450745153; Tue, 31 Oct 2017 04:52:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509450745; cv=none; d=google.com; s=arc-20160816; b=cNN/jvkrFXnl05v/Yp+/jq5+LefMbuO4gO1aQQp1eRQebEo+/cRme92oJlHB/D+ofK AOnwSm8Haw/FtDtMW7eQijgGlohtFpToYtPOR5Ds5C/CqtRnnFFbT9ImfeApNG1pYkCA 0UaR+LXOpOnlzjFW+G6hjg2ypASMDwfbDvYe3dyuiiSKBuI4gcMeUqHwFpUWFH+WuOZW 3sRwV8vjDhs0Tzo6+Wx7aD+jinBNDGFNkFuYy1Xr3RWNPulw97LrD24T6pQUZ77gAI7z OZeCV6E4YYbkFqVr+rLPz9tHE3kNNimQ/DBxJa5J9H+A83mRcjhQu0mAHt3z/hRp5V54 4+fw== 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=ahVMgVonX/9yQhkensSO0rxQ7cRR/k/JFewZevLJIKY=; b=tM66ND4nY+iMciiKMOoEXCHzMpr9361SymgIPwjtocLhMlykKFMa4u9vMDZ53Kj0Da QojDBpHYKRUA08UP1AaqF4GyQqXnE4zSN1OAicPeVB+/McGungrhawzPWkD2jNZ4hHSW m6VXPI/uWgayWxqJYYD820OsBo2+CtBVqn4tOCOaWTVntNemLFHy07hYfRmLjmRyBPY9 yiSAOC47SMArYd8P2kXrhhFV/oWjtQtYq96imnv2Ax3YSZGq7Fnqa+pzxtMoTRk48igB 7/mg/Ibi7EBKUp6ZkIUB3lI+4fjTGxzqIH5wQUzen3ThSJb2yPiqOpLj3F4LDoMEty5H 58qA== 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 y23si1502903pfa.140.2017.10.31.04.52.11; Tue, 31 Oct 2017 04:52:25 -0700 (PDT) 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 S932699AbdJaLvB (ORCPT + 99 others); Tue, 31 Oct 2017 07:51:01 -0400 Received: from mga02.intel.com ([134.134.136.20]:23209 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932283AbdJaLtW (ORCPT ); Tue, 31 Oct 2017 07:49:22 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Oct 2017 04:49:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,323,1505804400"; d="scan'208";a="915804330" Received: from vmm.bj.intel.com ([10.238.135.172]) by FMSMGA003.fm.intel.com with ESMTP; 31 Oct 2017 04:49:09 -0700 From: Luwei Kang To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Luwei Kang Subject: [patch v2 4/8] KVM: x86: add Intel processor trace cpuid emulataion Date: Tue, 31 Oct 2017 06:05:13 +0800 Message-Id: <1509401117-15521-5-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509401117-15521-1-git-send-email-luwei.kang@intel.com> References: <1509401117-15521-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 cpuid to guest. Signed-off-by: Chao Peng Signed-off-by: Luwei Kang --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/cpuid.c | 23 +++++++++++++++++++++-- arch/x86/kvm/svm.c | 6 ++++++ arch/x86/kvm/vmx.c | 6 ++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index c73e493..14f4b81 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1004,6 +1004,7 @@ struct kvm_x86_ops { void (*handle_external_intr)(struct kvm_vcpu *vcpu); bool (*mpx_supported)(void); bool (*xsaves_supported)(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 0099e10..ef19a11 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -70,6 +70,7 @@ u64 kvm_supported_xcr0(void) /* These are scattered features in cpufeatures.h. */ #define KVM_CPUID_BIT_AVX512_4VNNIW 2 #define KVM_CPUID_BIT_AVX512_4FMAPS 3 +#define KVM_CPUID_BIT_INTEL_PT 25 #define KF(x) bit(KVM_CPUID_BIT_##x) int kvm_update_cpuid(struct kvm_vcpu *vcpu) @@ -327,6 +328,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, unsigned f_invpcid = kvm_x86_ops->invpcid_supported() ? F(INVPCID) : 0; unsigned f_mpx = kvm_mpx_supported() ? F(MPX) : 0; unsigned f_xsaves = kvm_x86_ops->xsaves_supported() ? F(XSAVES) : 0; + unsigned f_intel_pt = kvm_x86_ops->pt_supported() ? KF(INTEL_PT) : 0; /* cpuid 1.edx */ const u32 kvm_cpuid_1_edx_x86_features = @@ -379,7 +381,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 = @@ -407,7 +409,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; @@ -578,6 +580,23 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, } break; } + /* Intel PT */ + case 0x14: { + int t, times = entry->eax & 0xffffffff; + + 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 0e68f0b..015c824 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -5174,6 +5174,11 @@ static bool svm_xsaves_supported(void) return false; } +static bool svm_pt_supported(void) +{ + return false; +} + static bool svm_has_wbinvd_exit(void) { return true; @@ -5485,6 +5490,7 @@ static void svm_setup_mce(struct kvm_vcpu *vcpu) .invpcid_supported = svm_invpcid_supported, .mpx_supported = svm_mpx_supported, .xsaves_supported = svm_xsaves_supported, + .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 cb0928d..26fe9e7 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -9163,6 +9163,11 @@ static bool vmx_xsaves_supported(void) SECONDARY_EXEC_XSAVES; } +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; @@ -12107,6 +12112,7 @@ static void vmx_setup_mce(struct kvm_vcpu *vcpu) .handle_external_intr = vmx_handle_external_intr, .mpx_supported = vmx_mpx_supported, .xsaves_supported = vmx_xsaves_supported, + .pt_supported = vmx_pt_supported, .check_nested_events = vmx_check_nested_events, -- 1.8.3.1 From 1584350559299018665@xxx Fri Nov 17 21:33:56 +0000 2017 X-GM-THRID: 1584154447667820390 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread