Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1636691imj; Thu, 14 Feb 2019 09:31:18 -0800 (PST) X-Google-Smtp-Source: AHgI3IZsKKY1W7ZrOs1T9uv/5GmupITtRAkHkTv9M0kYYXuXytUlpDg9IB+fgZvGIDijusg64jNS X-Received: by 2002:a17:902:2aa8:: with SMTP id j37mr5160749plb.226.1550165478086; Thu, 14 Feb 2019 09:31:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550165478; cv=none; d=google.com; s=arc-20160816; b=JctAaxIGEUceHm5DtWJhSuc+kDkJocjbcTOxFANP7aV/O8p7For45knHk3th5rqUgj LlxyKNdc3RC+abFsLlw1erzwLUZClk+m6t3NBblz7gelVRO+6KtG0BdtkHH7MaYK6B4a B2Nr2UGFWg7xTu4urxAN/afLyI+g6gEyTyGVa1eJnSsRgq42LgdGWnc348Fo4x3rS2cF tIc/74XzYRmfxUlf29AsvCnMZN1R6w+hTPIWiDT/Z3k1WOm0o/hSMZIZbHk2ez2FANtO WMkYGHai/u+7yooa9wDEBnZ5ry5L+O2fLUd4fQ8N3zkasFzw8OwKye1BnJBRBo5sfa2/ rxuA== 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=yQsbzwupLcBEkmeW5PDaMZEp/prZJIx37r66vHKzx4s=; b=uSCI3jq0Wo5prkLFjeJq8kfKyTy0/nloNksQZp0uUtJ8W15Q+Aq32JtpDylodtzeur 0BSuV9p0YzJJoszZXUC/9On6SJPsMnVRNJtt+Dl8YILWewsJe69MuJXjzN5K6n4d8TKR IoGs8VTGtrjscTb6DtNcBnKUunDaQDyQwTe14N2vsZyvrHz8zUxUyY1r94Z5sl7ymTej wIDMAesYsLPJHve6gFmDBpFVqzCjyNmAjiDf5vckc1qS3rmb2+WwBi/petNUXvPmb+jg KwGS6ImYrAWQ1afgS8jav+S5WYndL+WliHkl0ZAOv6MGZc9GWFwZKsHvkSM0AvDZ9S4U Dktw== 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 o28si2999187pgm.238.2019.02.14.09.31.02; Thu, 14 Feb 2019 09:31:18 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438001AbfBNJnT (ORCPT + 99 others); Thu, 14 Feb 2019 04:43:19 -0500 Received: from mga09.intel.com ([134.134.136.24]:32226 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395247AbfBNJnN (ORCPT ); Thu, 14 Feb 2019 04:43:13 -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 orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Feb 2019 01:43:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,368,1544515200"; d="scan'208";a="124411831" Received: from devel-ww.sh.intel.com ([10.239.48.128]) by fmsmga008.fm.intel.com with ESMTP; 14 Feb 2019 01:43:10 -0800 From: Wei Wang To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com, ak@linux.intel.com, peterz@infradead.org Cc: kan.liang@intel.com, mingo@redhat.com, rkrcmar@redhat.com, like.xu@intel.com, wei.w.wang@intel.com, jannh@google.com, arei.gonglei@huawei.com, jmattson@google.com Subject: [PATCH v5 12/12] KVM/VMX/vPMU: support to report GLOBAL_STATUS_LBRS_FROZEN Date: Thu, 14 Feb 2019 17:06:14 +0800 Message-Id: <1550135174-5423-13-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550135174-5423-1-git-send-email-wei.w.wang@intel.com> References: <1550135174-5423-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 Arch v4 supports streamlined Freeze_LBR_on_PMI, so we set the GLOBAL_STATUS_LBRS_FROZEN bit when the guest reads the global status msr with freezing lbr in use. Signed-off-by: Wei Wang Cc: Paolo Bonzini Cc: Andi Kleen --- arch/x86/kvm/vmx/pmu_intel.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index bf40941..80d3fcf 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -420,6 +420,25 @@ static bool intel_pmu_access_lbr_msr(struct kvm_vcpu *vcpu, return ret; } +static void intel_pmu_get_global_status(struct kvm_pmu *pmu, + struct msr_data *msr_info) +{ + u64 guest_debugctl, freeze_lbr_bits = DEBUGCTLMSR_FREEZE_LBRS_ON_PMI | + DEBUGCTLMSR_LBR; + + if (!pmu->global_status) { + msr_info->data = 0; + return; + } + + msr_info->data = pmu->global_status; + if (pmu->version >= 4) { + guest_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL); + if ((guest_debugctl & freeze_lbr_bits) == freeze_lbr_bits) + msr_info->data |= GLOBAL_STATUS_LBRS_FROZEN; + } +} + static int intel_pmu_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) { struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); @@ -431,7 +450,7 @@ static int intel_pmu_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) msr_info->data = pmu->fixed_ctr_ctrl; return 0; case MSR_CORE_PERF_GLOBAL_STATUS: - msr_info->data = pmu->global_status; + intel_pmu_get_global_status(pmu, msr_info); return 0; case MSR_CORE_PERF_GLOBAL_CTRL: msr_info->data = pmu->global_ctrl; -- 2.7.4