All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Ingo Molnar <mingo@kernel.org>, Paul Mackerras <paulus@samba.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Fengguang Wu <fengguang.wu@intel.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 3.10 03/40] perf: Prevent false warning in perf_swevent_add
Date: Mon,  9 Jun 2014 15:48:34 -0700	[thread overview]
Message-ID: <20140609224839.327090724@linuxfoundation.org> (raw)
In-Reply-To: <20140609224839.127615063@linuxfoundation.org>

3.10-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Jiri Olsa <jolsa@redhat.com>

commit 39af6b1678afa5880dda7e375cf3f9d395087f6d upstream.

The perf cpu offline callback takes down all cpu context
events and releases swhash->swevent_hlist.

This could race with task context software event being just
scheduled on this cpu via perf_swevent_add while cpu hotplug
code already cleaned up event's data.

The race happens in the gap between the cpu notifier code
and the cpu being actually taken down. Note that only cpu
ctx events are terminated in the perf cpu hotplug code.

It's easily reproduced with:
  $ perf record -e faults perf bench sched pipe

while putting one of the cpus offline:
  # echo 0 > /sys/devices/system/cpu/cpu1/online

Console emits following warning:
  WARNING: CPU: 1 PID: 2845 at kernel/events/core.c:5672 perf_swevent_add+0x18d/0x1a0()
  Modules linked in:
  CPU: 1 PID: 2845 Comm: sched-pipe Tainted: G        W    3.14.0+ #256
  Hardware name: Intel Corporation Montevina platform/To be filled by O.E.M., BIOS AMVACRB1.86C.0066.B00.0805070703 05/07/2008
   0000000000000009 ffff880077233ab8 ffffffff81665a23 0000000000200005
   0000000000000000 ffff880077233af8 ffffffff8104732c 0000000000000046
   ffff88007467c800 0000000000000002 ffff88007a9cf2a0 0000000000000001
  Call Trace:
   [<ffffffff81665a23>] dump_stack+0x4f/0x7c
   [<ffffffff8104732c>] warn_slowpath_common+0x8c/0xc0
   [<ffffffff8104737a>] warn_slowpath_null+0x1a/0x20
   [<ffffffff8110fb3d>] perf_swevent_add+0x18d/0x1a0
   [<ffffffff811162ae>] event_sched_in.isra.75+0x9e/0x1f0
   [<ffffffff8111646a>] group_sched_in+0x6a/0x1f0
   [<ffffffff81083dd5>] ? sched_clock_local+0x25/0xa0
   [<ffffffff811167e6>] ctx_sched_in+0x1f6/0x450
   [<ffffffff8111757b>] perf_event_sched_in+0x6b/0xa0
   [<ffffffff81117a4b>] perf_event_context_sched_in+0x7b/0xc0
   [<ffffffff81117ece>] __perf_event_task_sched_in+0x43e/0x460
   [<ffffffff81096f1e>] ? put_lock_stats.isra.18+0xe/0x30
   [<ffffffff8107b3c8>] finish_task_switch+0xb8/0x100
   [<ffffffff8166a7de>] __schedule+0x30e/0xad0
   [<ffffffff81172dd2>] ? pipe_read+0x3e2/0x560
   [<ffffffff8166b45e>] ? preempt_schedule_irq+0x3e/0x70
   [<ffffffff8166b45e>] ? preempt_schedule_irq+0x3e/0x70
   [<ffffffff8166b464>] preempt_schedule_irq+0x44/0x70
   [<ffffffff816707f0>] retint_kernel+0x20/0x30
   [<ffffffff8109e60a>] ? lockdep_sys_exit+0x1a/0x90
   [<ffffffff812a4234>] lockdep_sys_exit_thunk+0x35/0x67
   [<ffffffff81679321>] ? sysret_check+0x5/0x56

Fixing this by tracking the cpu hotplug state and displaying
the WARN only if current cpu is initialized properly.

Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1396861448-10097-1-git-send-email-jolsa@redhat.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 kernel/events/core.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5044,6 +5044,9 @@ struct swevent_htable {
 
 	/* Recursion avoidance in each contexts */
 	int				recursion[PERF_NR_CONTEXTS];
+
+	/* Keeps track of cpu being initialized/exited */
+	bool				online;
 };
 
 static DEFINE_PER_CPU(struct swevent_htable, swevent_htable);
@@ -5290,8 +5293,14 @@ static int perf_swevent_add(struct perf_
 	hwc->state = !(flags & PERF_EF_START);
 
 	head = find_swevent_head(swhash, event);
-	if (WARN_ON_ONCE(!head))
+	if (!head) {
+		/*
+		 * We can race with cpu hotplug code. Do not
+		 * WARN if the cpu just got unplugged.
+		 */
+		WARN_ON_ONCE(swhash->online);
 		return -EINVAL;
+	}
 
 	hlist_add_head_rcu(&event->hlist_entry, head);
 
@@ -7395,6 +7404,7 @@ static void __cpuinit perf_event_init_cp
 	struct swevent_htable *swhash = &per_cpu(swevent_htable, cpu);
 
 	mutex_lock(&swhash->hlist_mutex);
+	swhash->online = true;
 	if (swhash->hlist_refcount > 0) {
 		struct swevent_hlist *hlist;
 
@@ -7452,6 +7462,7 @@ static void perf_event_exit_cpu(int cpu)
 	perf_event_exit_cpu_context(cpu);
 
 	mutex_lock(&swhash->hlist_mutex);
+	swhash->online = false;
 	swevent_hlist_release(swhash);
 	mutex_unlock(&swhash->hlist_mutex);
 }



  parent reply	other threads:[~2014-06-09 23:05 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-09 22:48 [PATCH 3.10 00/40] 3.10.43-stable review Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 01/40] sched: Use CPUPRI_NR_PRIORITIES instead of MAX_RT_PRIO in cpupri check Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 02/40] sched: Sanitize irq accounting madness Greg Kroah-Hartman
2014-06-09 22:48 ` Greg Kroah-Hartman [this message]
2014-06-09 22:48 ` [PATCH 3.10 04/40] perf: Limit perf_event_attr::sample_period to 63 bits Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 05/40] perf: Fix race in removing an event Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 06/40] perf evsel: Fix printing of perf_event_paranoid message Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 07/40] mm/memory-failure.c: fix memory leak by race between poison and unpoison Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 08/40] Documentation: fix DOCBOOKS=... building Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 09/40] hwmon: (ntc_thermistor) Fix dependencies Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 10/40] hwmon: (ntc_thermistor) Fix OF device ID mapping Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 11/40] drm/gf119-/disp: fix nasty bug which can clobber SOR0s clock setup Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 16/40] ARM: OMAP4: Fix the boot regression with CPU_IDLE enabled Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 17/40] ARM: 8051/1: put_user: fix possible data corruption in put_user Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 18/40] dm cache: always split discards on cache block boundaries Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 19/40] sched: Fix hotplug vs. set_cpus_allowed_ptr() Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 20/40] drm/i915: Only copy back the modified fields to userspace from execbuffer Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 21/40] md: always set MD_RECOVERY_INTR when aborting a reshape or other "resync" Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 22/40] md: always set MD_RECOVERY_INTR when interrupting a reshape thread Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 24/40] Staging: speakup: Move pasting into a work item Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 25/40] staging: comedi: ni_daq_700: add mux settling delay Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 26/40] ALSA: hda/realtek - Correction of fixup codes for PB V7900 laptop Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 27/40] ALSA: hda/realtek - Fix COEF widget NID for ALC260 replacer fixup Greg Kroah-Hartman
2014-06-09 22:48 ` [PATCH 3.10 28/40] USB: ftdi_sio: add NovaTech OrionLXm product ID Greg Kroah-Hartman
2014-06-09 22:49 ` [PATCH 3.10 31/40] USB: serial: option: add support for Novatel E371 PCIe card Greg Kroah-Hartman
2014-06-09 22:49 ` [PATCH 3.10 32/40] USB: io_ti: fix firmware download on big-endian machines (part 2) Greg Kroah-Hartman
2014-06-09 22:49 ` [PATCH 3.10 33/40] USB: Avoid runtime suspend loops for HCDs that cant handle suspend/resume Greg Kroah-Hartman
2014-06-09 22:49 ` [PATCH 3.10 34/40] mm: rmap: fix use-after-free in __put_anon_vma Greg Kroah-Hartman
2014-06-09 22:49 ` [PATCH 3.10 35/40] iser-target: Add missing target_put_sess_cmd for ImmedateData failure Greg Kroah-Hartman
2014-06-09 22:49 ` [PATCH 3.10 36/40] perf: Drop sample rate when sampling is too slow Greg Kroah-Hartman
2014-06-09 22:49 ` [PATCH 3.10 37/40] perf: Fix interrupt handler timing harness Greg Kroah-Hartman
2014-06-09 22:49 ` [PATCH 3.10 38/40] perf: Enforce 1 as lower limit for perf_event_max_sample_rate Greg Kroah-Hartman
2014-06-09 22:49 ` [PATCH 3.10 39/40] ARM: perf: hook up perf_sample_event_took around pmu irq handling Greg Kroah-Hartman
2014-06-09 22:49 ` [PATCH 3.10 40/40] netfilter: Fix potential use after free in ip6_route_me_harder() Greg Kroah-Hartman
2014-06-10 15:16 ` [PATCH 3.10 00/40] 3.10.43-stable review Guenter Roeck

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=20140609224839.327090724@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=acme@redhat.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=fengguang.wu@intel.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.