Skip to contentSkip to conversation

perf/core: fix unlock balance in perf_init_event

PATCH Applied Qian Cai 3 participants 5 messages Nov 6, 2019 – Nov 13, 2019 perf events

lore
Share & tools
lore

Qian Cai

author
#0 lore raw

PATCH 1/1 perf/core: fix unlock balance in perf_init_event

The -next commit "perf/core: Optimize perf_init_event()" [1] introduced an unlock imbalance in perf_init_event() where it calls "goto again" and then only repeat rcu_read_unlock().

WARNING: bad unlock balance detected! perf_event_open/6185 is trying to release lock (rcu_read_lock) at:

  [<ffffffffb5eb4039>] perf_event_alloc+0xbb9/0x17f0
  but there are no more locks to release!
  other info that might help us debug this:
  2 locks held by perf_event_open/6185:
  #0: ffff888526780b50 (&sig->cred_guard_mutex){+.+.}, at: __do_sys_perf_event_open+0x6ee/0x1460
  #1: ffffffffb866b4e8 (&pmus_srcu){....}, at: perf_event_alloc+0xab8/0x17f0
  Call Trace:
   dump_stack+0xa0/0xea
   print_unlock_imbalance_bug.cold.40+0xb1/0xb6
   lock_release+0x349/0x4b0
   perf_event_alloc+0xbcf/0x17f0
   __do_sys_perf_event_open+0x1e2/0x1460
   __x64_sys_perf_event_open+0x62/0x70
   do_syscall_64+0xcc/0xaec
   entry_SYSCALL_64_after_hwframe+0x49/0xbe

[1] https://lore.kernel.org/lkml/[email protected]/

---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
index cfd89b4a02d8..8226d6ecdb86 100644
@@ -10307,7 +10307,6 @@ static struct pmu *perf_init_event(struct perf_event *event)
 			goto unlock;
 	}
 
-	rcu_read_lock();
 	/*
 	 * PERF_TYPE_HARDWARE and PERF_TYPE_HW_CACHE
 	 * are often aliases for PERF_TYPE_RAW.
@@ -10317,6 +10316,7 @@ static struct pmu *perf_init_event(struct perf_event *event)
 		type = PERF_TYPE_RAW;
 
 again:
+	rcu_read_lock();
 	pmu = idr_find(&pmu_idr, type);
 	rcu_read_unlock();
 	if (pmu) {
Signature · 1 line
2.21.0 (Apple Git-122)
maintainer
#1 lore raw
Quoted 22 lines · Qian Cai

The -next commit "perf/core: Optimize perf_init_event()" [1] introduced an unlock imbalance in perf_init_event() where it calls "goto again" and then only repeat rcu_read_unlock().

WARNING: bad unlock balance detected! perf_event_open/6185 is trying to release lock (rcu_read_lock) at:

  [<ffffffffb5eb4039>] perf_event_alloc+0xbb9/0x17f0
  but there are no more locks to release!
  other info that might help us debug this:
  2 locks held by perf_event_open/6185:
  #0: ffff888526780b50 (&sig->cred_guard_mutex){+.+.}, at: __do_sys_perf_event_open+0x6ee/0x1460
  #1: ffffffffb866b4e8 (&pmus_srcu){....}, at: perf_event_alloc+0xab8/0x17f0
  Call Trace:
   dump_stack+0xa0/0xea
   print_unlock_imbalance_bug.cold.40+0xb1/0xb6
   lock_release+0x349/0x4b0
   perf_event_alloc+0xbcf/0x17f0
   __do_sys_perf_event_open+0x1e2/0x1460
   __x64_sys_perf_event_open+0x62/0x70
   do_syscall_64+0xcc/0xaec
   entry_SYSCALL_64_after_hwframe+0x49/0xbe
Quoted 1 line

[1] https://lore.kernel.org/lkml/[email protected]/

You wanted to write:

Fixes 66d258c5b048 ("perf/core: Optimize perf_init_event()")

instead, right? Fixed that for you.

Quoted 28 lines
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
index cfd89b4a02d8..8226d6ecdb86 100644
@@ -10307,7 +10307,6 @@ static struct pmu *perf_init_event(struct perf_event *event)
 			goto unlock;
 	}
 
-	rcu_read_lock();
 	/*
 	 * PERF_TYPE_HARDWARE and PERF_TYPE_HW_CACHE
 	 * are often aliases for PERF_TYPE_RAW.
@@ -10317,6 +10316,7 @@ static struct pmu *perf_init_event(struct perf_event *event)
 		type = PERF_TYPE_RAW;
 
 again:
+	rcu_read_lock();
 	pmu = idr_find(&pmu_idr, type);
 	rcu_read_unlock();
 	if (pmu) {
Signature · 1 line
2.21.0 (Apple Git-122)
author
#2 lore raw
Quoted 9 lines · Peter Zijlstra

You wanted to write:

Fixes 66d258c5b048 ("perf/core: Optimize perf_init_event()")

instead, right? Fixed that for you.

I was not too sure about if the hashes are stable for commits only in the -tip tree. If they remain the same even after merged into the mainline, and then yes.

maintainer
#3 lore raw
Quoted 6 lines · Qian Cai
Quoted 6 lines · Peter Zijlstra

You wanted to write:

Quoted 7 lines
Quoted 3 lines
Fixes 66d258c5b048 ("perf/core: Optimize perf_init_event()")

instead, right? Fixed that for you.

I was not too sure about if the hashes are stable for commits only in the -tip tree. If they remain the same even after merged into the mainline, and then yes.

-tip commits are generally stable.

merge bot Applied
#4 lore raw

[tip: perf/core] perf/core: Fix unlock balance in perf_init_event()

In reply to Qian Cai
The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     deb0c3c29d552ab81ecd5481bb83bf2f4e41927d
Gitweb:        https://git.kernel.org/tip/deb0c3c29d552ab81ecd5481bb83bf2f4e41927d
Author:        Qian Cai <[email protected]>
AuthorDate:    Wed, 06 Nov 2019 00:29:35 -05:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Wed, 13 Nov 2019 11:06:13 +01:00

perf/core: Fix unlock balance in perf_init_event()

Commit:

66d258c5b048 ("perf/core: Optimize perf_init_event()")

introduced an unlock imbalance in perf_init_event() where it calls "goto again" and then only repeat rcu_read_unlock().

Cc Alexander Shishkin <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc David Ahern <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vince Weaver <[email protected]>
Fixes 66d258c5b048 ("perf/core: Optimize perf_init_event()")
---
 kernel/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
index 6cb6d68..8d65e03 100644
@@ -10307,7 +10307,6 @@ static struct pmu *perf_init_event(struct perf_event *event)
 			goto unlock;
 	}
 
-	rcu_read_lock();
 	/*
 	 * PERF_TYPE_HARDWARE and PERF_TYPE_HW_CACHE
 	 * are often aliases for PERF_TYPE_RAW.
@@ -10317,6 +10316,7 @@ static struct pmu *perf_init_event(struct perf_event *event)
 		type = PERF_TYPE_RAW;
 
 again:
+	rcu_read_lock();
 	pmu = idr_find(&pmu_idr, type);
 	rcu_read_unlock();
 	if (pmu) {