linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org, vince@deater.net,
	eranian@google.com, Arnaldo Carvalho de Melo <acme@infradead.org>,
	tglx@linutronix.de, ak@linux.intel.com,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>
Subject: [RFC PATCH 5/6] perf: Disable PMU around address filter adjustment
Date: Fri, 23 Sep 2016 14:27:25 +0300	[thread overview]
Message-ID: <20160923112726.5890-6-alexander.shishkin@linux.intel.com> (raw)
In-Reply-To: <20160923112726.5890-1-alexander.shishkin@linux.intel.com>

If the PMU is used for AUX data sampling, the hardware event that triggers
it may come in during a critical section of address filters adjustment (if
it's delivered as NMI) and in turn call the address filter sync code,
causing a spinlock recursion.

To prevent this, disable the PMU around these critical sections, so that
AUX sampling won't take place there.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 kernel/events/core.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index fdb20fdeb1..f6582df1c9 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6377,6 +6377,12 @@ static void perf_event_addr_filters_exec(struct perf_event *event, void *data)
 	if (!has_addr_filter(event))
 		return;
 
+	/*
+	 * if sampling kicks in in the critical section,
+	 * we risk spinlock recursion on the ifh::lock
+	 */
+	perf_pmu_disable(event->pmu);
+
 	raw_spin_lock_irqsave(&ifh->lock, flags);
 	list_for_each_entry(filter, &ifh->list, entry) {
 		if (filter->inode) {
@@ -6387,6 +6393,8 @@ static void perf_event_addr_filters_exec(struct perf_event *event, void *data)
 		count++;
 	}
 
+	perf_pmu_enable(event->pmu);
+
 	if (restart)
 		event->addr_filters_gen++;
 	raw_spin_unlock_irqrestore(&ifh->lock, flags);
@@ -6942,6 +6950,8 @@ static void __perf_addr_filters_adjust(struct perf_event *event, void *data)
 	if (!file)
 		return;
 
+	perf_pmu_disable(event->pmu);
+
 	raw_spin_lock_irqsave(&ifh->lock, flags);
 	list_for_each_entry(filter, &ifh->list, entry) {
 		if (perf_addr_filter_match(filter, file, off,
@@ -6953,6 +6963,8 @@ static void __perf_addr_filters_adjust(struct perf_event *event, void *data)
 		count++;
 	}
 
+	perf_pmu_enable(event->pmu);
+
 	if (restart)
 		event->addr_filters_gen++;
 	raw_spin_unlock_irqrestore(&ifh->lock, flags);
@@ -8126,6 +8138,8 @@ static void perf_event_addr_filters_apply(struct perf_event *event)
 
 	down_read(&mm->mmap_sem);
 
+	perf_pmu_disable(event->pmu);
+
 	raw_spin_lock_irqsave(&ifh->lock, flags);
 	list_for_each_entry(filter, &ifh->list, entry) {
 		event->addr_filters_offs[count] = 0;
@@ -8144,6 +8158,8 @@ static void perf_event_addr_filters_apply(struct perf_event *event)
 	event->addr_filters_gen++;
 	raw_spin_unlock_irqrestore(&ifh->lock, flags);
 
+	perf_pmu_enable(event->pmu);
+
 	up_read(&mm->mmap_sem);
 
 	mmput(mm);
-- 
2.9.3

  parent reply	other threads:[~2016-09-23 11:30 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-23 11:27 [RFC PATCH 0/6] perf: Add AUX data sampling Alexander Shishkin
2016-09-23 11:27 ` [RFC PATCH 1/6] perf: Move mlock accounting to ring buffer allocation Alexander Shishkin
2016-09-23 12:14   ` Peter Zijlstra
2016-09-23 14:27     ` Alexander Shishkin
2016-09-23 15:27       ` Peter Zijlstra
2016-09-23 15:58         ` Alexander Shishkin
2016-09-23 17:26     ` Andi Kleen
2016-09-23 20:28       ` Peter Zijlstra
2016-09-26  8:27         ` Alexander Shishkin
2016-09-26  9:03           ` Peter Zijlstra
2016-09-26 12:39             ` Alexander Shishkin
2016-09-26 16:13             ` Alexander Shishkin
2016-09-23 11:27 ` [RFC PATCH 2/6] perf: Add api to (de-)allocate AUX buffers for kernel counters Alexander Shishkin
2016-09-23 11:27 ` [RFC PATCH 3/6] perf: Add a helper for looking up pmus by type Alexander Shishkin
2016-09-23 11:27 ` [RFC PATCH 4/6] perf: Add infrastructure for using AUX data in perf samples Alexander Shishkin
2016-09-23 11:27 ` Alexander Shishkin [this message]
2016-09-23 11:27 ` [RFC PATCH 6/6] perf: Disable IRQs in address filter sync path Alexander Shishkin
2016-09-26 16:18   ` Alexander Shishkin
2016-10-04 16:49     ` Mathieu Poirier
2016-09-23 11:49 ` [RFC PATCH 0/6] perf: Add AUX data sampling Peter Zijlstra
2016-09-23 17:19   ` Andi Kleen
2016-09-23 20:35     ` Peter Zijlstra
2016-09-23 22:34       ` Andi Kleen

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=20160923112726.5890-6-alexander.shishkin@linux.intel.com \
    --to=alexander.shishkin@linux.intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@infradead.org \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=vince@deater.net \
    /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).