public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Shishkin <alexander.shishkin@linux.intel.com>
To: Peter Zijlstra <a.p.zijlstra@chello.nl>, Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>,
	linux-kernel@vger.kernel.org, jolsa@redhat.com,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>
Subject: [PATCH v1 1/6] perf: Disable PMU around address filter adjustment
Date: Tue, 12 Jun 2018 10:51:12 +0300	[thread overview]
Message-ID: <20180612075117.65420-2-alexander.shishkin@linux.intel.com> (raw)
In-Reply-To: <20180612075117.65420-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 4e1a1bf8d867..0f5cd1b08dbd 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6299,6 +6299,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) {
@@ -6313,6 +6319,8 @@ static void perf_event_addr_filters_exec(struct perf_event *event, void *data)
 		event->addr_filters_gen++;
 	raw_spin_unlock_irqrestore(&ifh->lock, flags);
 
+	perf_pmu_enable(event->pmu);
+
 	if (restart)
 		perf_event_stop(event, 1);
 }
@@ -6993,6 +7001,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,
@@ -7008,6 +7018,8 @@ static void __perf_addr_filters_adjust(struct perf_event *event, void *data)
 		event->addr_filters_gen++;
 	raw_spin_unlock_irqrestore(&ifh->lock, flags);
 
+	perf_pmu_enable(event->pmu);
+
 	if (restart)
 		perf_event_stop(event, 1);
 }
@@ -8261,6 +8273,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;
@@ -8279,6 +8293,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.17.1


  reply	other threads:[~2018-06-12  7:51 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-12  7:51 [PATCH v1 0/6] perf: Add AUX data sampling Alexander Shishkin
2018-06-12  7:51 ` Alexander Shishkin [this message]
2018-06-12 20:11   ` [PATCH v1 1/6] perf: Disable PMU around address filter adjustment Peter Zijlstra
2018-06-12  7:51 ` [PATCH v1 2/6] perf: Disable IRQs in address filter sync path Alexander Shishkin
2018-06-12  7:51 ` [PATCH v1 3/6] perf: Add an iterator for AUX data Alexander Shishkin
2018-06-12  7:51 ` [PATCH v1 4/6] perf: Allow using AUX data in perf samples Alexander Shishkin
2018-06-14 19:25   ` Peter Zijlstra
2018-06-14 19:39     ` Peter Zijlstra
2018-06-19 10:51       ` Alexander Shishkin
2018-06-14 19:30   ` Peter Zijlstra
2018-06-14 19:47   ` Peter Zijlstra
2018-06-19 11:00     ` Alexander Shishkin
2018-06-14 20:03   ` Peter Zijlstra
2018-06-14 20:20   ` Peter Zijlstra
2018-06-19 10:47     ` Alexander Shishkin
2018-06-21 20:16       ` Peter Zijlstra
2018-10-02 14:00         ` Alexander Shishkin
2019-08-09 12:32         ` Alexander Shishkin
2019-09-26 12:04           ` Alexander Shishkin
2019-09-26 14:44           ` Peter Zijlstra
2019-09-30 11:50             ` Alexander Shishkin
2018-06-12  7:51 ` [PATCH v1 5/6] perf: Drop PERF_FLAG_FD_OUTPUT Alexander Shishkin
2018-06-12  7:51 ` [PATCH v1 6/6] perf: Allow set-output for task contexts of different types Alexander Shishkin
2018-06-14 19:36   ` Peter Zijlstra

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=20180612075117.65420-2-alexander.shishkin@linux.intel.com \
    --to=alexander.shishkin@linux.intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    /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