Received: by 10.192.165.148 with SMTP id m20csp1660451imm; Thu, 3 May 2018 03:21:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrWaMAVGRR6fl2w/UEt196u65L2gHx156L5uTzh0f2Od6+nsc1VCialcqWVWCZ1DO1636rT X-Received: by 2002:a65:498e:: with SMTP id r14-v6mr18302225pgs.78.1525342891500; Thu, 03 May 2018 03:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525342891; cv=none; d=google.com; s=arc-20160816; b=LbE2Lvgt/aOpWaTtDlwiKMnnHUQo6Ag7xkSUK2mMxYVZMHNh4Jhr/QZbkhWhOseh8T M0jmHnCFVMtnqe3mtI3JGOWIbCbT82ZyD+Ly23/nUNS2TSw+zuVd+CFxHx0T40Tj0ro+ n+p6qTimeIAOcCxMSG7aA6fGXxeKP9CIjj/IPXrTyScCZRm50KTbnObrkkyvwC6hoHIq NQpH+wLefmKID3Vz1o1qM9nhJDR+26IO8Wyzvbr2Ai0BIRj9hKmZwupcmQxprSPjr3by E6tfT1Ld0v3MysG40w537arMhvsE1XPdY6xurI5SZyUfO2Gc0A9AMECm+258FmTLN8Gl KULQ== 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=DVNJimaoOGIAQUb1lM+vg9mFT4dYgi42Q7wDBjJCcLw=; b=MFrJEEI251ua6YGtoWA522nIvHnBB949LGA3WzBbBqixjfsu2NX0YMVSGO/WFjibTU rsqqexmS8k0Sz9wODA1/ljoGoglTQuwjofimDUWe9nDrNASQeF24kRsqjEORW4UAU42E 54XwvF+g9f70NgpBtKoeeAQueeraDlhgXbONcsilxrUvVlcQh/m3xhmStUhCPWmU1jDx bVDGcT4V2RcNmZp7c98l8uvzH/1b79Bmls97u5uqKLJTLiLnLxwWFo2R8OuxmcCTzs8W D0m/uDILeFGKh3R4WqhRsySfn5br4VqSVcHHdLymqmmUvtIIw7Cs5RMP6cUrq+0PYHlm FnJA== 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 77si13526677pfz.334.2018.05.03.03.21.17; Thu, 03 May 2018 03:21:31 -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 S1752274AbeECKT1 (ORCPT + 99 others); Thu, 3 May 2018 06:19:27 -0400 Received: from mga06.intel.com ([134.134.136.31]:65500 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751847AbeECKTU (ORCPT ); Thu, 3 May 2018 06:19:20 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 May 2018 03:19:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,358,1520924400"; d="scan'208";a="36546511" Received: from unknown (HELO skx-d.bj.intel.com) ([10.238.154.68]) by fmsmga007.fm.intel.com with ESMTP; 03 May 2018 03:19:17 -0700 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, peterz@infradead.org, chao.p.peng@linux.intel.com, Luwei Kang Subject: [PATCH v7 07/13] KVM: x86: Add Intel Processor Trace cpuid emulation Date: Thu, 3 May 2018 20:13:22 +0800 Message-Id: <1525349608-10352-8-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1525349608-10352-1-git-send-email-luwei.kang@intel.com> References: <1525349608-10352-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 c25775f..03875aa 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1025,6 +1025,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 82055b9..e04bf67 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -336,6 +336,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 = @@ -393,7 +394,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 = @@ -423,7 +424,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; @@ -595,6 +596,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 80ea262..23a1ef9 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -5877,6 +5877,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; @@ -7102,6 +7107,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 8680cd5..27cf417 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -9563,6 +9563,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; @@ -12790,6 +12795,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