Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3599091pxb; Sun, 31 Jan 2021 22:37:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYfE7C/A6SJj2yD5wDgtjF63bnAy0bnue1sGvzFuu9K6+i4o7tnWTM0TZnsSIUtf7id38c X-Received: by 2002:a17:906:1c17:: with SMTP id k23mr16012164ejg.255.1612161435810; Sun, 31 Jan 2021 22:37:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612161435; cv=none; d=google.com; s=arc-20160816; b=kUrDyUvDJdNaQ2bzXkuYgNhVwafgdmdrKpTjTXkmpdpNX/XMtCCp4wkxT9v343WJHm RW3NNLrObm1gobZL7MpxGEIDjqA9DzOF6ADe7xtieL5LavPdl7ggCcHoRJ1UFvQczcVw RRZM2nbf1qfdlpetZLtxw9Ttx805iLOuU8hG9Oq6aIxtNossXt91LEXpzDuMetPJK9pu rHpvEI131OoLrBKPCZVIlEfj7YU7bAAx/UgwEC11XznusLNKIUeEspO4rmno+VXW8xCX cMIBeA8voKeI9XuxSw8sZeRPpyXFtzxlBYXHz3X6+UmzUFRVv11wolCq6RB3pHoyirfB yz1w== 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=vxKoM0c43047T+3HeeF70ETn5UIWJPAXV0BPAJIQt1o=; b=k9VFjDdYWgHMeyQUVGxJT2cyRzqb8v0sUUoDM/DoMyZTdMy5ySpmmQ1GUgPlIPCP+2 RfiWrsAP9rMOZP3hH0R98mZkm2U48od0dxsqrPesOFLmQ6TuEx2heNq3mBl6j+Rowj1v v3ULz91QRQXi01boXnB32jhRUhczDeCF+LYD/0pLp1fbyEYUo9unMd1fGNFKnzAp3OKf 2B6sLIi2eKVP9DKXj5ITMb8S43A1wKjdM9xCO8o1mfpOWg+TFH0l8wxYRClD7EgjZ2Sn F+uqalmdTCG8uINCwWp+nnDKumcwdTOq7/X4EZ66SHC5b29NBCQnZSpHN4lPurCemgVH qgHg== 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 g24si2615844ejf.739.2021.01.31.22.36.52; Sun, 31 Jan 2021 22:37:15 -0800 (PST) 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 S232094AbhBAGeT (ORCPT + 99 others); Mon, 1 Feb 2021 01:34:19 -0500 Received: from mga14.intel.com ([192.55.52.115]:26662 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232122AbhBAGK0 (ORCPT ); Mon, 1 Feb 2021 01:10:26 -0500 IronPort-SDR: nBA9B+YJaami8y8u2Te6h1RVOrQscx7koabazhk9w8wj2h02UJ/YHHjU5CBWFcpcXZVnX9psXn YpZ6cui3MxWw== X-IronPort-AV: E=McAfee;i="6000,8403,9881"; a="179860892" X-IronPort-AV: E=Sophos;i="5.79,391,1602572400"; d="scan'208";a="179860892" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2021 22:08:20 -0800 IronPort-SDR: SmZu/epYWqJg2KowbBnFA0dfDjJKq4ol5vn0Wq401xaOZDcJ5fgpcAmnvlzoAxEVgk7OnT5tKa KdiYaVXUYk+w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,391,1602572400"; d="scan'208";a="368980347" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by fmsmga008.fm.intel.com with ESMTP; 31 Jan 2021 22:08:18 -0800 From: Like Xu To: Paolo Bonzini , Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , ak@linux.intel.com, wei.w.wang@intel.com, kan.liang@intel.com, alex.shi@linux.alibaba.com, kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v14 07/11] KVM: vmx/pmu: Reduce the overhead of LBR pass-through or cancellation Date: Mon, 1 Feb 2021 14:01:48 +0800 Message-Id: <20210201060152.370069-1-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210201051039.255478-1-like.xu@linux.intel.com> References: <20210201051039.255478-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 Reviewed-by: Andi Kleen --- 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 287fc14f0445..60f395e18446 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -550,6 +550,7 @@ static void intel_pmu_init(struct kvm_vcpu *vcpu) vcpu->arch.perf_capabilities = 0; lbr_desc->records.nr = 0; lbr_desc->event = NULL; + lbr_desc->msr_passthrough = false; } static void intel_pmu_reset(struct kvm_vcpu *vcpu) @@ -596,12 +597,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->msr_passthrough) + return; + vmx_update_intercept_for_lbr_msrs(vcpu, true); + lbr_desc->msr_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->msr_passthrough) + return; + vmx_update_intercept_for_lbr_msrs(vcpu, false); + lbr_desc->msr_passthrough = true; } /* diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 863bb3fe73d4..4d6a2624a204 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; + + /* True if LBRs are marked as not intercepted in the MSR bitmap */ + bool msr_passthrough; }; /* -- 2.29.2