Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3163695ybk; Mon, 18 May 2020 20:10:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeAlQ6ilbF8OCVSzytaGZUCFH54/QnBpXiA3DsRjOry8Hu1XyG1O2MGrdukLRa0YcEn9Fj X-Received: by 2002:a17:906:7750:: with SMTP id o16mr17590601ejn.12.1589857827671; Mon, 18 May 2020 20:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589857827; cv=none; d=google.com; s=arc-20160816; b=fH4t2hXgM2CJJBLqB4bDiR83JCOYeMHPJI49zzKfBddlT5ss1irb2WCmdlfOJWMja2 gwQNyI2bN1xHwZnMi6LM7fFP67swLz08kQgcMBdpLd4RMtecGsRUcY+pSRzhhXJuNiCm SsB2hjnXe8HCHPuPXaHsEFV6YFl2XelOU2X9A4h3W3hE72dXTxkEywwSf3PVAECNmO+R guLcatA6JLxe9PT4WVGF8C/nXTd+8PPRuUv5D4Xt2SVtugvpLBob//hcLn72q2gtj8Gb 0Ly7tpGPvgP4cMMFTGH6Zx+ylR4m+TMw1Dk9tS1vBr4DCvWzCKsMEE3G7LHA9JYCWvkX 5gRQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject:ironport-sdr :ironport-sdr; bh=QPGDNzM8oOTQi9Gw6Rmrrtm5ThL4webaelbK6Mof+Ak=; b=fvTcxoNCwPYyws+hy6+Rgb3046bl1W6EkQHNIpaNKjclIlU+H12mtjiAk3ycBgR3QP kjFPff4lhLXsf7SgVQl4THBsxow8nOKQHnUIS889o2CUBEbuddiiF7j8hxM4d0aCesJQ NisBlx4JxWniARasW+6a/TMexjDXHwkUYOh5gLzAY9nVq3QFiInkhMxia6zLcL4qZNos yQ12/nnuJpP5sJly4X/hljgT+KW4xSdVQiub5Fa0jG+rktb6mQzOZmaIjf+1zVlkbdra f2O6lMq2PsHH7txfKrgtIQIE3Fz/wc92OnerY+nEg9ktNN22EOL5YSH31AKN3c3at0rU 49Mg== 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 ce6si331355edb.379.2020.05.18.20.10.04; Mon, 18 May 2020 20:10:27 -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 S1726831AbgESDIs (ORCPT + 99 others); Mon, 18 May 2020 23:08:48 -0400 Received: from mga12.intel.com ([192.55.52.136]:47219 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbgESDIr (ORCPT ); Mon, 18 May 2020 23:08:47 -0400 IronPort-SDR: 8jSU3MrGz4qQdBslgq1HhH9Uyn5Eq8+GSqxh6PO04igOhxuDuxjt//dedSVDov8yq+yTlUfagS NbPmXy99M8uw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2020 20:08:47 -0700 IronPort-SDR: UNiJIVy9L3nV2FcocPuxfstsqx+jvmEZPZEtOpRSyRido8uPiQibjcdRaYo50vrue0pb82YSU7 4O82+YOsRyoQ== X-IronPort-AV: E=Sophos;i="5.73,408,1583222400"; d="scan'208";a="439459187" Received: from likexu-mobl1.ccr.corp.intel.com (HELO [10.238.4.141]) ([10.238.4.141]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2020 20:08:43 -0700 Subject: Re: [PATCH v11 05/11] perf/x86: Keep LBR stack unchanged in host context for guest LBR event To: Peter Zijlstra Cc: Paolo Bonzini , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , ak@linux.intel.com, wei.w.wang@intel.com References: <20200514083054.62538-1-like.xu@linux.intel.com> <20200514083054.62538-6-like.xu@linux.intel.com> <20200518120205.GF277222@hirez.programming.kicks-ass.net> From: Like Xu Organization: Intel OTC Message-ID: Date: Tue, 19 May 2020 11:08:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200518120205.GF277222@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, Thanks for the clear attitude and code refinement. On 2020/5/18 20:02, Peter Zijlstra wrote: > On Thu, May 14, 2020 at 04:30:48PM +0800, Like Xu wrote: >> @@ -544,7 +562,12 @@ void intel_pmu_lbr_enable_all(bool pmi) >> { >> struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); >> >> - if (cpuc->lbr_users) >> + /* >> + * When the LBR hardware is scheduled for a guest LBR event, >> + * the guest will dis/enables LBR itself at the appropriate time, >> + * including configuring MSR_LBR_SELECT. >> + */ >> + if (cpuc->lbr_users && !cpuc->guest_lbr_enabled) >> __intel_pmu_lbr_enable(pmi); >> } > > No!, that should be done through perf_event_attr::exclude_host, as I > believe all the other KVM event do it. > Sure, I could reuse cpuc->intel_ctrl_guest_mask to rewrite this part: diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index d788edb7c1f9..f1243e8211ca 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -2189,7 +2189,8 @@ static void intel_pmu_disable_event(struct perf_event *event) } else if (idx == INTEL_PMC_IDX_FIXED_BTS) { intel_pmu_disable_bts(); intel_pmu_drain_bts_buffer(); - } + } else if (idx == INTEL_PMC_IDX_FIXED_VLBR) + intel_clear_masks(event, idx); /* * Needs to be called after x86_pmu_disable_event, @@ -2271,7 +2272,8 @@ static void intel_pmu_enable_event(struct perf_event *event) if (!__this_cpu_read(cpu_hw_events.enabled)) return; intel_pmu_enable_bts(hwc->config); - } + } else if (idx == INTEL_PMC_IDX_FIXED_VLBR) + intel_set_masks(event, idx); } static void intel_pmu_add_event(struct perf_event *event) diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index b8dabf1698d6..1b30c76815dd 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -552,11 +552,19 @@ void intel_pmu_lbr_del(struct perf_event *event) perf_sched_cb_dec(event->ctx->pmu); } +static inline bool vlbr_is_enabled(void) +{ + struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); + + return test_bit(INTEL_PMC_IDX_FIXED_VLBR, + (unsigned long *)&cpuc->intel_ctrl_guest_mask); +} + void intel_pmu_lbr_enable_all(bool pmi) { struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); - if (cpuc->lbr_users) + if (cpuc->lbr_users && !vlbr_is_enabled()) __intel_pmu_lbr_enable(pmi); } @@ -564,7 +572,7 @@ void intel_pmu_lbr_disable_all(void) { struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); - if (cpuc->lbr_users) + if (cpuc->lbr_users && !vlbr_is_enabled()) __intel_pmu_lbr_disable(); } @@ -706,7 +714,8 @@ void intel_pmu_lbr_read(void) * This could be smarter and actually check the event, * but this simple approach seems to work for now. */ - if (!cpuc->lbr_users || cpuc->lbr_users == cpuc->lbr_pebs_users) + if (!cpuc->lbr_users || vlbr_is_enabled() || + cpuc->lbr_users == cpuc->lbr_pebs_users) return; if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32) Is this acceptable to you ? If you have more comments on the patchset, please let me know. Thanks, Like Xu