Received: by 10.223.185.111 with SMTP id b44csp73855wrg; Fri, 9 Mar 2018 01:10:21 -0800 (PST) X-Google-Smtp-Source: AG47ELuge7avT1jYYcTksUuGhZPh3QkV7tNFuMFWkh5YH2KJYgNf4nBbGl9nuSTJ5hbRgk3mgpjs X-Received: by 10.98.62.196 with SMTP id y65mr29060086pfj.24.1520586621050; Fri, 09 Mar 2018 01:10:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520586621; cv=none; d=google.com; s=arc-20160816; b=izYz3cd7bxf6SMTb5j7PZtKKicsYDkYNhMK9r7tiw8E1fGSxN2w+dsS0p5xvB/gjLq V5IOApUTEcd55Oh61OCjhylX5505a07rx85BuRKGE8DvEwUrGriWcL22lqvPFMUR0Ncp VjM29nTb4A6au3OdkKVOkOt/oP7ObrMjNNNyK2vA6qPYNKWkNrYg2JjeqeNOENq1nMwc D5fEmSuSbgopsFAokZdAdIh+qA4ZVm+dEojfpTTyMv1XHrJyPicxFOfxe+KuBLyTBZ4Z hlHv1kGxXEdGdHgDd/HandaCCHiBSMwR2FOdnixNVKsMfuby7LfVTKfbY6mf/SWgBVLl wOEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=U7fDofD5Y/SToU3LEGxhxqr0HXpTIinA1Aiuu5Cy+F8=; b=zYBu25DmrVWurNPaBS5o9lW/qTn0LaypbHJk1P9zjFXtaCWvQnKvCej5jFQ0FW8zoK LL5//CTeyZZHiNRcB//g4bY0XLZuUAtbopPVRyLRBAgPnrjgY8/0LxMiN8ujL5Nv7PGS nnRd5R1S0PX8vR6A6hglmirk9n7RoiMyBe9LAOVd30MadlqBiHc+bbRtPg0mUmhb8NuN V4nlojsgeDOanY35XXcZMqoFKM3Vb+MAD/Iu078LA3uAesxoPM75balwL/57fxmT6zK6 Ef/1B7UyeX3Ad7FzzwcuVK/9v04LZpB5aZ09o0X8VR/zC7clBkG/uf+XgJIwj4uCeJZN hEzg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si485957pfe.255.2018.03.09.01.10.06; Fri, 09 Mar 2018 01:10:21 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751169AbeCIJIo (ORCPT + 99 others); Fri, 9 Mar 2018 04:08:44 -0500 Received: from terminus.zytor.com ([198.137.202.136]:37979 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750909AbeCIJIm (ORCPT ); Fri, 9 Mar 2018 04:08:42 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w2998IP9031501; Fri, 9 Mar 2018 01:08:18 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w2998I3j031496; Fri, 9 Mar 2018 01:08:18 -0800 Date: Fri, 9 Mar 2018 01:08:18 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Kan Liang Message-ID: Cc: kan.liang@linux.intel.com, peterz@infradead.org, torvalds@linux-foundation.org, tglx@linutronix.de, acme@redhat.com, jolsa@redhat.com, alexander.shishkin@linux.intel.com, hpa@zytor.com, mingo@kernel.org, linux-kernel@vger.kernel.org, vincent.weaver@maine.edu, fengguang.wu@intel.com, eranian@google.com Reply-To: fengguang.wu@intel.com, vincent.weaver@maine.edu, eranian@google.com, mingo@kernel.org, hpa@zytor.com, jolsa@redhat.com, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, acme@redhat.com, kan.liang@linux.intel.com, peterz@infradead.org, torvalds@linux-foundation.org In-Reply-To: <6f44ee84-56f8-79f1-559b-08e371eaeb78@linux.intel.com> References: <6f44ee84-56f8-79f1-559b-08e371eaeb78@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf/x86/intel: Properly save/restore the PMU state in the NMI handler Git-Commit-ID: 82d71ed0277efc45360828af8c4e4d40e1b45352 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 82d71ed0277efc45360828af8c4e4d40e1b45352 Gitweb: https://git.kernel.org/tip/82d71ed0277efc45360828af8c4e4d40e1b45352 Author: Kan Liang AuthorDate: Tue, 20 Feb 2018 02:11:50 -0800 Committer: Ingo Molnar CommitDate: Fri, 9 Mar 2018 08:22:18 +0100 perf/x86/intel: Properly save/restore the PMU state in the NMI handler The PMU is disabled in intel_pmu_handle_irq(), but cpuc->enabled is not updated accordingly. This is fine in current usage because no-one checks it - but fix it for future code: for example, the drain_pebs() will be modified to fix an auto-reload bug. Properly save/restore the old PMU state. Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Cc: acme@kernel.org Cc: kernel test robot Link: http://lkml.kernel.org/r/6f44ee84-56f8-79f1-559b-08e371eaeb78@linux.intel.com Signed-off-by: Ingo Molnar --- arch/x86/events/intel/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 6b6c1717787d..1ba7ca7b675d 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -2201,9 +2201,15 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) int bit, loops; u64 status; int handled; + int pmu_enabled; cpuc = this_cpu_ptr(&cpu_hw_events); + /* + * Save the PMU state. + * It needs to be restored when leaving the handler. + */ + pmu_enabled = cpuc->enabled; /* * No known reason to not always do late ACK, * but just in case do it opt-in. @@ -2211,6 +2217,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs) if (!x86_pmu.late_ack) apic_write(APIC_LVTPC, APIC_DM_NMI); intel_bts_disable_local(); + cpuc->enabled = 0; __intel_pmu_disable_all(); handled = intel_pmu_drain_bts_buffer(); handled += intel_bts_interrupt(); @@ -2320,7 +2327,8 @@ again: done: /* Only restore PMU state when it's active. See x86_pmu_disable(). */ - if (cpuc->enabled) + cpuc->enabled = pmu_enabled; + if (pmu_enabled) __intel_pmu_enable_all(0, true); intel_bts_enable_local();