linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Kan Liang <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
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
Subject: [tip:perf/core] perf/x86/intel: Properly save/restore the PMU state in the NMI handler
Date: Fri, 9 Mar 2018 01:08:18 -0800	[thread overview]
Message-ID: <tip-82d71ed0277efc45360828af8c4e4d40e1b45352@git.kernel.org> (raw)
In-Reply-To: <6f44ee84-56f8-79f1-559b-08e371eaeb78@linux.intel.com>

Commit-ID:  82d71ed0277efc45360828af8c4e4d40e1b45352
Gitweb:     https://git.kernel.org/tip/82d71ed0277efc45360828af8c4e4d40e1b45352
Author:     Kan Liang <kan.liang@linux.intel.com>
AuthorDate: Tue, 20 Feb 2018 02:11:50 -0800
Committer:  Ingo Molnar <mingo@kernel.org>
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 <kan.liang@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: acme@kernel.org
Cc: kernel test robot <fengguang.wu@intel.com>
Link: http://lkml.kernel.org/r/6f44ee84-56f8-79f1-559b-08e371eaeb78@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 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();
 

  reply	other threads:[~2018-03-09  9:08 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-12 22:20 [PATCH V4 0/5] bugs fix for auto-reload mmap read and rdpmc read kan.liang
2018-02-12 22:20 ` [PATCH V4 1/5] perf/x86/intel: Fix event update for auto-reload kan.liang
2018-02-17  6:21   ` [perf/x86/intel] 41e062cd2e: WARNING:at_arch/x86/events/intel/ds.c:#intel_pmu_save_and_restart_reload kernel test robot
2018-02-19 12:44     ` Peter Zijlstra
2018-02-20 18:59       ` Liang, Kan
2018-03-09  9:08         ` tip-bot for Kan Liang [this message]
2018-02-21 10:32   ` [PATCH V4 1/5] perf/x86/intel: Fix event update for auto-reload Peter Zijlstra
2018-02-21 13:43     ` Liang, Kan
2018-02-21 13:45       ` Peter Zijlstra
2018-03-09  9:08   ` [tip:perf/core] " tip-bot for Kan Liang
2018-02-12 22:20 ` [PATCH V4 2/5] perf/x86: Introduce read function for x86_pmu kan.liang
2018-03-09  9:09   ` [tip:perf/core] perf/x86: Introduce a ->read() callback in 'struct x86_pmu' tip-bot for Kan Liang
2018-02-12 22:20 ` [PATCH V4 3/5] perf/x86/intel/ds: Introduce read function for auto-reload event kan.liang
2018-03-09  9:09   ` [tip:perf/core] perf/x86/intel/ds: Introduce ->read() function for auto-reload events and flush the PEBS buffer there tip-bot for Kan Liang
2018-02-12 22:20 ` [PATCH V4 4/5] perf/x86/intel: Fix pmu read for auto-reload kan.liang
2018-03-09  9:10   ` [tip:perf/core] perf/x86/intel: Fix PMU " tip-bot for Kan Liang
2018-02-12 22:20 ` [PATCH V4 5/5] perf/x86: Fix: disable userspace RDPMC usage for large PEBS kan.liang
2018-03-09  9:10   ` [tip:perf/core] perf/x86/intel: Disable " tip-bot for Kan Liang
2018-03-09 14:31     ` Vince Weaver
2018-03-09 17:42       ` Peter Zijlstra
2018-03-09 18:53         ` Liang, Kan
2018-03-09 19:10         ` Vince Weaver
2018-03-12 14:08           ` Liang, Kan
2018-03-20 11:15   ` [tip:perf/urgent] " tip-bot for Kan Liang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-82d71ed0277efc45360828af8c4e4d40e1b45352@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=fengguang.wu@intel.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=vincent.weaver@maine.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).