Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2491481ybg; Fri, 31 Jul 2020 00:50:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqJ+d9G5lKQYvvoG8hy+6pzXeJw5hfK4ToNupoUtThEOvrpZkRxrS0TsMxo4B4ZVrqXz31 X-Received: by 2002:a05:6402:508:: with SMTP id m8mr2534004edv.279.1596181817519; Fri, 31 Jul 2020 00:50:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596181817; cv=none; d=google.com; s=arc-20160816; b=0wXXQsRweUnXf9jIxjVW5PXmOtsRSVmlm7A960SHUri/MaSFRV5/Lomgoi0eyc39kJ VEQTen7tj3bOdcxvzBTn1RrveBtVNib9SbFt4PUrxhhRBu9F9HtwJROsSupUN6CsAB06 bhLMVWcwScsVoWVsp/nsqtV2o4VQWiAhJKcwpFAFPU/ZdI2wI3tAHE+tnHaI4VOIacRQ +qcVog1M6CviLtKW1LQa1VrZ1Q5M1AxApwVsL/i9I+/vfnJ4FK4xBfmyZUBa41UfCIQz SYffNIJeFVDWFpF8GALlN20AcLXvHdbMMxCP4ateC7JQ8k0D0TujJHairbTv1sJVhu0w tTkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=FyzrN6AbE6ZQTe03R8FzkKWxX9gR8A0bRiSRm/i7uZ4=; b=FttvEu6sMcjg02e0EUPcAQpxCMFxzyUjSfCVpdoIiGSsLsge/esqgCdPlnciNp7lfL 9UyR3SEKREQ4SFXEVp+NdSogDw+5Dp4zmftEZ6qMBlJY2ZAa17S2OX5yhCaqTOcez6Wu mkUoR24gjL/B/EliES4yVSW2AYCetVwM9BZk2e9dnFMvxpl3AfYHKqrOnexFpr7lkXjR LeXGRTQGrXB28AF7XXrWOupgaSn1LPxIxLdhk54FyYoy9jQWgdgp/aKm3Aq/bXDQozhw 6vmyHLuvwDk021Yq6bH8K7+iwZEF87npTHe5r+DGSq34EU+x9I/qHKtfdzCiKkYgevID hZbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id c18si4508837eds.417.2020.07.31.00.49.55; Fri, 31 Jul 2020 00:50:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1731764AbgGaHqM (ORCPT + 99 others); Fri, 31 Jul 2020 03:46:12 -0400 Received: from mga11.intel.com ([192.55.52.93]:55461 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731644AbgGaHqK (ORCPT ); Fri, 31 Jul 2020 03:46:10 -0400 IronPort-SDR: Z5dev1k7U1NMNtjsAmpUMnuXJaFUCsL3Pn4cU2Ba3oOIbxs5BZAiPeGRmKblr1NQ2EkX0bEkMV Jk9wys9d2DVQ== X-IronPort-AV: E=McAfee;i="6000,8403,9698"; a="149570524" X-IronPort-AV: E=Sophos;i="5.75,417,1589266800"; d="scan'208";a="149570524" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jul 2020 00:46:10 -0700 IronPort-SDR: msUrVnsDtmIKJt5oocn+KSxrZnkGpctPtKLu2OOmm/eqISy1c5F1uVJl06a7WUCpbSgDkec2lz M/V7k0Z8Z5fQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,417,1589266800"; d="scan'208";a="323160577" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by fmsmga002.fm.intel.com with ESMTP; 31 Jul 2020 00:46:08 -0700 From: Like Xu To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Wanpeng Li , Jim Mattson Cc: Vitaly Kuznetsov , Joerg Roedel , wei.w.wang@intel.com, linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH 1/6] KVM: vmx/pmu: Add VMCS field check before exposing LBR_FMT Date: Fri, 31 Jul 2020 15:43:57 +0800 Message-Id: <20200731074402.8879-2-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200731074402.8879-1-like.xu@linux.intel.com> References: <20200731074402.8879-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If guest LBR_FMT is exposed on KVM, KVM needs to have guest state field GUEST_IA32_DEBUGCTL and MSR_IA32_DEBUGCTLMSR vmx switch support. Fixes: f93d622139de ("KVM: vmx/pmu: Expose LBR_FMT in the MSR_IA32_PERF_CAPABILITIES") Signed-off-by: Like Xu --- arch/x86/kvm/vmx/capabilities.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index 5829f4e9a7e0..f5f0586f4cd7 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -372,6 +372,12 @@ static inline bool vmx_pt_mode_is_host_guest(void) return pt_mode == PT_MODE_HOST_GUEST; } +static inline bool cpu_has_vmx_lbr(void) +{ + return (vmcs_config.vmexit_ctrl & VM_EXIT_SAVE_DEBUG_CONTROLS) && + (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_DEBUG_CONTROLS); +} + static inline u64 vmx_get_perf_capabilities(void) { /* @@ -383,7 +389,8 @@ static inline u64 vmx_get_perf_capabilities(void) if (boot_cpu_has(X86_FEATURE_PDCM)) rdmsrl(MSR_IA32_PERF_CAPABILITIES, perf_cap); - perf_cap |= perf_cap & PMU_CAP_LBR_FMT; + if (cpu_has_vmx_lbr()) + perf_cap |= perf_cap & PMU_CAP_LBR_FMT; return perf_cap; } -- 2.21.3