Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp976460pxx; Thu, 29 Oct 2020 21:01:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzz88AABzI9qp4axE5qzTVB2em/475RSyUDlAm9Aza1/Ye51IGKJmDWmUuMOwRrCqroPmds X-Received: by 2002:a50:d65c:: with SMTP id c28mr233152edj.279.1604030513936; Thu, 29 Oct 2020 21:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604030513; cv=none; d=google.com; s=arc-20160816; b=zg8Y0vtn113N/amEISfh3Mz+3ZrGZ3mZKazRLmJbm9LDWxT9oPLA6R/vyTGJ5itle8 VDzL0kK0QWMQBicuj9fda+zHHL+kjENfPVdaF/fxGkA8VPVk6t+9DDzzYffjnqyqSDIG XTLoGwJGMjpFXeH2BhbZT62nalyRaOUqDqa22bSC8n9ynIgl7+XB3amTmL3731SlxZZz fL2EfK6WcymZTMF38dNXK74ZDdao8hP3jzLrLC7UcrsbioAsGsneuEpOewaLauGFdqfp MkVKXYnDUS9uIUT4WFLDAsrIkguXKShuPZgGgTvoSnNQIQBxo5qv1gFYQoTvl8W4kFlf GV3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=+ErA91OjE97h3VzEPxecsrHkGRuBgMvzIR5m0jvoPwA=; b=h1kNrMbsQQ+0aRRF6u2iomP6MGvb3aOxwEBr49mCZyv8/js6yK118b2UPY8yRil2uQ 4nEFtGplGLDt55NpyouS2xpWXotktUs+g/ArBXcsiUfE7scOTlpG6+XO80cAfChF9avK g441PbPcIov4jitqNaQ29XByIK8Bdu9lPgT410A+UNoOatXLUYaoU8KKXoGrBLZPRLPL /1guHHqkixsEyrqGfrkIpREnYKs/p35KZPkQnbs0N1G4+KkNk/4kxohCyjyQVXb3rT7r p8FuBy2XHuMbGSAwN4v5F1Dw3YY7PB15BhcZ4yocnIEK7FVu2ASYRaNZvfaxZXt8mpSX 5g6w== 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 p9si3298998eja.144.2020.10.29.21.01.32; Thu, 29 Oct 2020 21:01:53 -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 S1726518AbgJ3D46 (ORCPT + 99 others); Thu, 29 Oct 2020 23:56:58 -0400 Received: from mga09.intel.com ([134.134.136.24]:4254 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726510AbgJ3D45 (ORCPT ); Thu, 29 Oct 2020 23:56:57 -0400 IronPort-SDR: V6C64PRa/kHFFRYdpwkMwIbVnd+QBMHKI6TPLL53IP40EcOrOvYHOdRBEaSPin11eUc9AEevEq GPcQ8khAs/QA== X-IronPort-AV: E=McAfee;i="6000,8403,9789"; a="168685748" X-IronPort-AV: E=Sophos;i="5.77,432,1596524400"; d="scan'208";a="168685748" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2020 20:56:56 -0700 IronPort-SDR: FgOetFluXbyOFh4FUi4MoRUghkSwXD86YQvNsrPaVPs18W/FKMh22rOMc9T/mWTXZT3L5fYxkJ bOjh7PDqZgcg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,432,1596524400"; d="scan'208";a="525770454" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by fmsmga006.fm.intel.com with ESMTP; 29 Oct 2020 20:56:54 -0700 From: Like Xu To: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND v13 07/10] KVM: vmx/pmu: Reduce the overhead of LBR pass-through or cancellation Date: Fri, 30 Oct 2020 11:52:17 +0800 Message-Id: <20201030035220.102403-8-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201030035220.102403-1-like.xu@linux.intel.com> References: <20201030035220.102403-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the LBR records 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 | 13 +++++++++++++ arch/x86/kvm/vmx/vmx.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 6b3319dbfa72..72a6dd6ca0ac 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -562,6 +562,7 @@ static void intel_pmu_init(struct kvm_vcpu *vcpu) vmx_get_perf_capabilities() : 0; lbr_desc->records.nr = 0; lbr_desc->event = NULL; + lbr_desc->already_passthrough = false; } static void intel_pmu_reset(struct kvm_vcpu *vcpu) @@ -607,12 +608,24 @@ static void vmx_update_intercept_for_lbr_msrs(struct kvm_vcpu *vcpu, bool set) static inline void vmx_disable_lbr_msrs_passthrough(struct kvm_vcpu *vcpu) { + struct lbr_desc *lbr_desc = vcpu_to_lbr_desc(vcpu); + + if (!lbr_desc->already_passthrough) + return; + vmx_update_intercept_for_lbr_msrs(vcpu, true); + lbr_desc->already_passthrough = false; } static inline void vmx_enable_lbr_msrs_passthrough(struct kvm_vcpu *vcpu) { + struct lbr_desc *lbr_desc = vcpu_to_lbr_desc(vcpu); + + 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 2bd866c5a4e4..1869f5090e40 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -90,6 +90,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