Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp936315imm; Thu, 6 Sep 2018 12:30:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZf8+D9KE4PuYmR41D3opL+WtD0MKVTRP0vieNMraQKU4vjzxmTFvEbLDvyqNumZybWzd79 X-Received: by 2002:a63:8e4a:: with SMTP id k71-v6mr4406670pge.45.1536262210840; Thu, 06 Sep 2018 12:30:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536262210; cv=none; d=google.com; s=arc-20160816; b=jkUFhQySHDFzIQt1MRABT13vkQqI4BesvFZ4i4OJUaTjBQDmaDitk2vvkBwCAVvCps 9bpixQ/eo58McBQBhBsPodYTXaPV25arB22h4CUefQk/zvbCbkP0UJTCyD0XXvkJhqbt ILHtdGCkAmFjuaa/MAurka9pVe8VoPrGRl4y4CMPqrw6kUy4YoT0c1TM+3Q8UlSs4dx3 0+OODIr2v2zOjYelRPwD8WMzdjMJtl6dlCv71QfBV5j5yqlQ2rQ/enuodyuxQ1qXEKp1 3riHODEXBsVpQ4X7WEqegUR4naPaNWyJrFXMC/fqGZtZX8I6wlgzzsOpIe/KoDruYjVH fw7w== 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; bh=262ZpntMDtnuKiSXhCsA4Ar3r9JbBTPAINVW2Z/rVyo=; b=vUtMBKkYXA7f95gXR1zh2HbuCa/GOQqh/0QFNb2NOxakqDJrFsqz6nF5VuSOKutMtO aQi+/c16OU/uMmRpb6cnAgpw1MAinll5A+y1314Eg1DBa0poh5EshVYylnQ2gNA/F223 xyhzmrupvOq7HWtES+AormJk48K9MjQq8y8E4196N1XjDtRHwaIgol1MSoaSf5cHtBEo 8gGFw/fzvgSUXzl/uGoTE7oOOfcabhQbVr7Uhodjab8Bc9ljiBEPfpxaDvF4rmLvHt6B p0mFTaVz+txPLpJPvtyOrsv7yIcitHILq+eM/5za3Ghadwh5XrmSIv/F+59ZHZ0/6eca Vytw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r11-v6si6263626pgj.46.2018.09.06.12.29.55; Thu, 06 Sep 2018 12:30:10 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728482AbeIFQgz (ORCPT + 99 others); Thu, 6 Sep 2018 12:36:55 -0400 Received: from mga18.intel.com ([134.134.136.126]:62809 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728048AbeIFQgS (ORCPT ); Thu, 6 Sep 2018 12:36:18 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Sep 2018 05:00:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,338,1531810800"; d="scan'208";a="71046793" Received: from devel-ww.sh.intel.com ([10.239.48.110]) by orsmga008.jf.intel.com with ESMTP; 06 Sep 2018 05:00:55 -0700 From: Wei Wang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, ak@linux.intel.com Cc: kan.liang@intel.com, peterz@infradead.org, mingo@redhat.com, rkrcmar@redhat.com, like.xu@intel.com, wei.w.wang@intel.com Subject: [PATCH v2 4/8] KVM/x86: expose MSR_IA32_PERF_CAPABILITIES to the guest Date: Thu, 6 Sep 2018 19:30:52 +0800 Message-Id: <1536233456-12173-5-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1536233456-12173-1-git-send-email-wei.w.wang@intel.com> References: <1536233456-12173-1-git-send-email-wei.w.wang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Bits [0, 5] of MSR_IA32_PERF_CAPABILITIES tell about the format of the addresses stored in the LBR stack. Expose those bits to the guest when the guest lbr feature is enabled. Signed-off-by: Like Xu Signed-off-by: Wei Wang Cc: Paolo Bonzini Cc: Andi Kleen --- arch/x86/include/asm/perf_event.h | 2 ++ arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/vmx.c | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index f40e80a..161165f 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -79,6 +79,8 @@ #define ARCH_PERFMON_BRANCH_MISSES_RETIRED 6 #define ARCH_PERFMON_EVENTS_COUNT 7 +#define PERF_CAP_MASK_LBR_FMT 0x3f + /* * Intel "Architectural Performance Monitoring" CPUID * detection/enumeration details: diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 7bcfa61..3b8a57b 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -365,7 +365,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, F(XMM3) | F(PCLMULQDQ) | 0 /* DTES64, MONITOR */ | 0 /* DS-CPL, VMX, SMX, EST */ | 0 /* TM2 */ | F(SSSE3) | 0 /* CNXT-ID */ | 0 /* Reserved */ | - F(FMA) | F(CX16) | 0 /* xTPR Update, PDCM */ | + F(FMA) | F(CX16) | 0 /* xTPR Update*/ | F(PDCM) | F(PCID) | 0 /* Reserved, DCA */ | F(XMM4_1) | F(XMM4_2) | F(X2APIC) | F(MOVBE) | F(POPCNT) | 0 /* Reserved*/ | F(AES) | F(XSAVE) | 0 /* OSXSAVE */ | F(AVX) | diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 7a62c1c..d5eba8e 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -4134,6 +4134,13 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) !guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP)) return 1; /* Otherwise falls through */ + case MSR_IA32_PERF_CAPABILITIES: + if (!boot_cpu_has(X86_FEATURE_PDCM)) + return 1; + msr_info->data = native_read_msr(MSR_IA32_PERF_CAPABILITIES); + if (vcpu->kvm->arch.guest_lbr) + msr_info->data &= PERF_CAP_MASK_LBR_FMT; + break; default: msr = find_msr_entry(vmx, msr_info->index); if (msr) { -- 2.7.4