Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4790108ybc; Fri, 15 Nov 2019 10:06:26 -0800 (PST) X-Google-Smtp-Source: APXvYqztdqyuxoAfRwTXvuSrENj+UuT45srtHu8WyVy8LQxKjpaaLkl4enOp0MSODg/VUH0l8ygT X-Received: by 2002:adf:ed4e:: with SMTP id u14mr17278134wro.132.1573841186699; Fri, 15 Nov 2019 10:06:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573841186; cv=none; d=google.com; s=arc-20160816; b=eFwsOlPf+OpR/NFKWRE/vvme1T5jkV9oSu9zCBBgVfHwFRBvWR43ZeOUCVr/jh1vNj 8tAy1XXJ/pCPEitqyVfPI4IWLdp+Vn36Hw/VQUdoum0SKwlMHFgdmRZd/qXpLpGcjmFv 5GZgSa0af2jsaY621eOzp1bvCwgm7EY4jIJJ2wEeytk7W6zNMRMkWzeXNPpPesRL47yw qRMLnkD34YNmKMEeFoqBqSJDh46YsF97Rxmy4RJXze5yN4b5pcQYMO7BzvYBvwMtPguv Msdairse79Z5aYPJJk74tQwDeappLTcCjlP3YMWeYvpYfhghGRpm9pTU+EFlsn1g1PXJ 2NMA== 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:references:cc:to:from:subject; bh=cI92K7EvUfOgHz6FRkz9TOfECc6/7TXHj7vsjuCAOwo=; b=PC8PVOLx4k3jyRaM3DcgkmZFbrbAvI6eqbxGOuDCiNUcsDeuq0cKCVKtrlAdbYoTyA dVfAk6mseODxDLshDuP+S0y0sYH8w8ziYxHbKLso3jjYwjPxO7vadnV068m0GxwLIP+k gT4TH1n+FVHgr5RFDZWV+oVhc6EiOFZCHTfXUEE4/aLNB0vTJTJsqtj7YtbyZhGC26Bj 0XZerVnEVji1ejCoDT6PwNLhY/PQVf7hIoGHY+vcoi4cXVu3FvqlrK9+g7rK0VTvfKEL XVAVfmvWc8w3D4Lwn0UvRot9j6lB6Dv2iIC36wtN6fB1xL1A/DNm9uAtB9GPdElbGgpz /6tQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id b3si7643715edn.202.2019.11.15.10.06.01; Fri, 15 Nov 2019 10:06:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726786AbfKOSEx (ORCPT + 99 others); Fri, 15 Nov 2019 13:04:53 -0500 Received: from mga11.intel.com ([192.55.52.93]:31139 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726182AbfKOSEx (ORCPT ); Fri, 15 Nov 2019 13:04:53 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Nov 2019 10:04:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,309,1569308400"; d="scan'208";a="203644131" Received: from linux.intel.com ([10.54.29.200]) by fmsmga007.fm.intel.com with ESMTP; 15 Nov 2019 10:04:52 -0800 Received: from [10.251.5.106] (kliang2-mobl.ccr.corp.intel.com [10.251.5.106]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by linux.intel.com (Postfix) with ESMTPS id AE057580472; Fri, 15 Nov 2019 10:04:51 -0800 (PST) Subject: Re: [PATCH] perf/x86/intel: Avoid PEBS_ENABLE MSR access in PMI From: "Liang, Kan" To: Peter Zijlstra Cc: acme@redhat.com, mingo@kernel.org, linux-kernel@vger.kernel.org, ak@linux.intel.com, eranian@google.com References: <20191115133917.24424-1-kan.liang@linux.intel.com> <20191115140739.GM4131@hirez.programming.kicks-ass.net> Message-ID: <3e117702-c07f-bd58-9931-766c2698b5d7@linux.intel.com> Date: Fri, 15 Nov 2019 13:04:50 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: 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 On 11/15/2019 9:46 AM, Liang, Kan wrote: > > > On 11/15/2019 9:07 AM, Peter Zijlstra wrote: >> On Fri, Nov 15, 2019 at 05:39:17AM -0800, kan.liang@linux.intel.com >> wrote: >>> From: Kan Liang >>> >>> The perf PMI handler, intel_pmu_handle_irq(), currently does >>> unnecessary MSR accesses when PEBS is enabled. >>> >>> When entering the handler, global ctrl is explicitly disabled. All >>> counters do not count anymore. It doesn't matter if the PEBS is >>> enabled or disabled. Furthermore, cpuc->pebs_enabled is not changed >>> in PMI. The PEBS status doesn't change. The PEBS_ENABLE MSR doesn't need >>> to be changed either. >> >> PMI can throttle, and iirc x86_pmu_stop() ends up in >> intel_pmu_pebs_disable() >> > > Right, the declaration is inaccurate. I will fix it in v2. > But the patch still works for the case of PMI throttle. > The intel_pmu_pebs_disable() will update cpuc->pebs_enabled and > unconditionally modify MSR_IA32_PEBS_ENABLE. It seems not true for a corner case. PMI may land after cpuc->enabled=0 in x86_pmu_disable() and PMI throttle may be triggered for the PMI. For this rare case, intel_pmu_pebs_disable() will not touch MSR_IA32_PEBS_ENABLE. I don't have a test case for this rare corner case. But I think we may have to handle it in PMI handler as well. I will add the codes as below to V2. diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index bc6468329c52..7198a372a5ab 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -2620,6 +2624,15 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status) handled++; x86_pmu.drain_pebs(regs); status &= x86_pmu.intel_ctrl | GLOBAL_STATUS_TRACE_TOPAPMI; + + /* + * PMI may land after cpuc->enabled=0 in x86_pmu_disable() and + * PMI throttle may be triggered for the PMI. + * For this rare case, intel_pmu_pebs_disable() will not touch + * MSR_IA32_PEBS_ENABLE. Explicitly disable the PEBS here. + */ + if (unlikely(!cpuc->enabled && !cpuc->pebs_enabled)) + wrmsrl(MSR_IA32_PEBS_ENABLE, 0); } Thanks, Kan > When exiting the handler, current perf re-write the PEBS MSR according > to the updated cpuc->pebs_enabled, which is still unnecessary. >