Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp193465ybt; Sat, 13 Jun 2020 01:16:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwz9By+D4qPFPWf96KUmVnnJ4bSdbRMZh2xWLGanEQA9jU8QGHL0qe1CVJs92jUynriEQ6Q X-Received: by 2002:a17:906:edb6:: with SMTP id sa22mr4507659ejb.393.1592036193982; Sat, 13 Jun 2020 01:16:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592036193; cv=none; d=google.com; s=arc-20160816; b=DrTEEdp5yAmN4izdoGIeX+qjhIanytUOx/qrHL3o0ZgXE+sEzn3Yc6tmDUM2TDeL40 Tq88YZ7VFoikeyhvMbFWAqdZaFI35mFZcIFVSdELXmw7ke5b0lUAii5U9cqF0f6qVu5k V5/6e6rmMn/5oTvOO2gQn96LufhaHU8H67REE+1JL98Y/SBcC8oKnUFd7Uf+kQbR1K7D th8Y12PQmuYK0s7pVlUv9snLc8lQNGMTDe7v0Fh0fvHxVHu60d5O8Y7yNN7gpfxv7wdX MIHzc3h95gr2IXgFztr3nRb6vcX9nn5WkFb+jXc7pQE64GtYu+HrqD2CHrZrakEv04gS TjBQ== 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=pyMRAkl5KBy5BNeVSS6VB1vOYaoKjCfxx2VxuFJZRBM=; b=L6AtDTOIYjWTfVr5BwYpJ/V+oIXrsW/LEhIrDqftL8xwdHeUQtPCcH+TcGkiJpFq3x 6XfHujgHGiVnCEAXBuLU22itKNXOc74B4XnOsgRSTeuCaWxEwmUvxXmyEtW/d6b74uyi lxxR7zZO82BfQ3eNeLjcI9FJiimfIoGxJZoiHFX5KvxzycV4qZ4WFQWKKkmKcogA25o5 WC3AmU+4np5FPOPaBIaBnY0LianGlwMMWMRaQXx0+vs4eL9XpVyTZ2K9pGUXqWpRNdz7 PnaFLCVRFryZzPZiJkRxds5iN7pjdaJwLrg9uX3tE5ihVZeJchLM35Biod8/JFTLorPB ptpA== 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 m27si5563924ejd.630.2020.06.13.01.15.42; Sat, 13 Jun 2020 01:16:33 -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 S1726590AbgFMILl (ORCPT + 99 others); Sat, 13 Jun 2020 04:11:41 -0400 Received: from mga07.intel.com ([134.134.136.100]:64588 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726553AbgFMILf (ORCPT ); Sat, 13 Jun 2020 04:11:35 -0400 IronPort-SDR: ROT/FVHTNhFtjDcxJ2n4uSZ5SoYC89vC0Al4d9tBXqtoAO/gkBi288w8VXZDmPy2Q1DdZxGN4g yH2k/sAYE+7g== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2020 01:11:34 -0700 IronPort-SDR: DsydGXdWvck1TnL/AtC4qj2yDMHJCD7/zQgLXVI3sRRGgrSiuaDcE7wf5HHOtaCtpDyrvEHnf0 W2jVNiH5HSGA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,506,1583222400"; d="scan'208";a="474467453" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by fmsmga006.fm.intel.com with ESMTP; 13 Jun 2020 01:11:32 -0700 From: Like Xu To: Paolo Bonzini Cc: Peter Zijlstra , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , ak@linux.intel.com, wei.w.wang@intel.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Like Xu Subject: [PATCH v12 10/11] KVM: vmx/pmu: Reduce the overhead of LBR pass-through or cancellation Date: Sat, 13 Jun 2020 16:09:55 +0800 Message-Id: <20200613080958.132489-11-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200613080958.132489-1-like.xu@linux.intel.com> References: <20200613080958.132489-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 When the LBR record msrs has already been pass-through, there is no need to call vmx_update_intercept_for_lbr_msrs() again and again, and vice versa. Signed-off-by: Like Xu --- arch/x86/kvm/vmx/pmu_intel.c | 1 + arch/x86/kvm/vmx/vmx.c | 12 ++++++++++++ arch/x86/kvm/vmx/vmx.h | 3 +++ 3 files changed, 16 insertions(+) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 85a675004cbb..75ba0444b4d1 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -614,6 +614,7 @@ static void intel_pmu_init(struct kvm_vcpu *vcpu) vmx_get_perf_capabilities() : 0; lbr_desc->lbr.nr = 0; lbr_desc->event = NULL; + lbr_desc->already_passthrough = false; } static void intel_pmu_reset(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 58a8af433741..800a26e3b571 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -3880,12 +3880,24 @@ static void vmx_update_intercept_for_lbr_msrs(struct kvm_vcpu *vcpu, bool set) static inline void vmx_lbr_disable_passthrough(struct kvm_vcpu *vcpu) { + struct lbr_desc *lbr_desc = &to_vmx(vcpu)->lbr_desc; + + if (!lbr_desc->already_passthrough) + return; + vmx_update_intercept_for_lbr_msrs(vcpu, true); + lbr_desc->already_passthrough = false; } static inline void vmx_lbr_enable_passthrough(struct kvm_vcpu *vcpu) { + struct lbr_desc *lbr_desc = &to_vmx(vcpu)->lbr_desc; + + if (lbr_desc->already_passthrough) + return; + vmx_update_intercept_for_lbr_msrs(vcpu, false); + lbr_desc->already_passthrough = true; } /* diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index c67ce758412e..c931463f75d9 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -102,6 +102,9 @@ struct lbr_desc { * The records may be inaccurate if the host reclaims the LBR. */ struct perf_event *event; + + /* A flag to reduce the overhead of LBR pass-through or cancellation. */ + bool already_passthrough; }; /* -- 2.21.3