Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp16337pxb; Thu, 7 Jan 2021 17:49:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyG1sk+6JPx6zp6MKS3SUfH277BoH4szCjuxrQBPnYeKPR4YP4XuE59WpyFYVCK+dKjX2m6 X-Received: by 2002:a05:6402:1286:: with SMTP id w6mr3689456edv.351.1610070580795; Thu, 07 Jan 2021 17:49:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610070580; cv=none; d=google.com; s=arc-20160816; b=g5IJveI2zbFb/QEiWsphiLig/E2KfbZWf3XU36SdTzDk3OUsdW5LmB3eM9rOWLe5RG jE0xXDy6W1wWGyBHbq866hAXnb5JjtfY9+Ist8YfEzCZRXjCbwODia799VBNpltU7kzP uxztbM+jq+NQret+AC/9Lz64/WE+BXsCUOsgeox2UJSRgYCMyKmCTVF/Ow06B1f1q4iW 1gRoqScbKepavbyRc1Mauuprb4f8iO0xHa0UwoUp1VXHkXgWIZ/nJdBUFbML2USOAW0A sR01nJv0+DdMNbGCzouGD5LV69JA65zcafpnphycpsDucN3uoQdbvwOwvp+b6ACk2R9w /aeQ== 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=mSAhb7ulWhpuEEN7r+G7b/HIIG0pDRnrfzuwTlZdlPk=; b=MCBwlaL94sLaBzuodCLhlwbbsu4ukm40CkmpDnqj1ul8AJmCQGRAn0x1RCaMoyZcnI WFkYMSxyTqxOce3grhF5mnoFprnRuVUvmslZOoPaRHNZYWenLZehwsxnUZJDlvFtNHGz /r0/Dx5pqmnPi1CDMQqMgHx2HjxkkTjFZmaLS99uNuCbGjVC+40AE0BlbfWDYJMPan+R /FFqBt0oNpRlY5PQnRvqIKdtJCw7lSU+T1HEeklmAt4/YFbyj4eaLjHzEM9OEZLECcyq +qA+xDf8m6s3yvViX44pM0dzytOycGTEzmneM/WSf6F4PsY3SVWgl5qs4+gL6NujP1Tj 69uw== 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 y12si3088148ejq.432.2021.01.07.17.49.17; Thu, 07 Jan 2021 17:49:40 -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 S1729977AbhAHBre (ORCPT + 99 others); Thu, 7 Jan 2021 20:47:34 -0500 Received: from mga09.intel.com ([134.134.136.24]:27995 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729552AbhAHBre (ORCPT ); Thu, 7 Jan 2021 20:47:34 -0500 IronPort-SDR: cHKzTVQdw6Kf5Y85H02hDlTRcNLidgmxMH6bbTxBNz3dDn83oTW5WoxLQcFAuGHup8LkqUzrgu H2C53ofpJg1A== X-IronPort-AV: E=McAfee;i="6000,8403,9857"; a="177672405" X-IronPort-AV: E=Sophos;i="5.79,330,1602572400"; d="scan'208";a="177672405" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jan 2021 17:43:29 -0800 IronPort-SDR: 3xIHeUASsErE4WcrB9BqCPaC3ceRlZNEm/CAg3an5IheGEC93Nj/xuJccc85yoq5cLLFBWlV4J ehghsyZFGrOA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,330,1602572400"; d="scan'208";a="379938093" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga008.jf.intel.com with ESMTP; 07 Jan 2021 17:43:25 -0800 From: Like Xu To: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , ak@linux.intel.com, wei.w.wang@intel.com, kan.liang@intel.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RESEND v13 07/10] KVM: vmx/pmu: Reduce the overhead of LBR pass-through or cancellation Date: Fri, 8 Jan 2021 09:37:01 +0800 Message-Id: <20210108013704.134985-8-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210108013704.134985-1-like.xu@linux.intel.com> References: <20210108013704.134985-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 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 863bb3fe73d4..b79244bd44bb 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.29.2