Skip to contentSkip to conversation

perf: Fix perf_sched_count derailment

PATCH New Alexander Shishkin 2 participants 2 messages Mar 2, 2016 – Mar 8, 2016

Subsystems (2)
lore
Share & tools
lore

Alexander Shishkin

author reviewer
#0 lore raw

PATCH 1/1 perf: Fix perf_sched_count derailment

The error path in perf_event_open() is such that asking for a sampling event on a pmu that doesn't generate interrupts will end up in dropping the perf_sched_count even though it hasn't been incremented for this event yet.

Given a sufficient amount of these calls, we'll end up disabling scheduler's jump label even though we'd still have active events in the system, thereby facilitating the arrival of the infernal regions upon us.

I'm fixing this by moving account_event() inside perf_event_alloc().

---
 kernel/events/core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/events/core.c +3 -4
index ce54a68493..1d47d59bb1 100644
@@ -8101,6 +8101,9 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
 		}
 	}
 
+	/* symmetric to unaccount_event() in _free_event() */
+	account_event(event);
+
 	return event;
 
 err_per_task:
@@ -8464,8 +8467,6 @@ SYSCALL_DEFINE5(perf_event_open,
 		}
 	}
 
-	account_event(event);
-
 	/*
 	 * Special case software events and allow them to be part of
 	 * any hardware group.
@@ -8762,8 +8763,6 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
 	/* Mark owner so we could distinguish it from user events. */
 	event->owner = TASK_TOMBSTONE;
 
-	account_event(event);
-
 	ctx = find_get_context(event->pmu, task, event);
 	if (IS_ERR(ctx)) {
 		err = PTR_ERR(ctx);
Signature · 1 line
2.7.0
#1 lore raw

[tip:perf/core] perf/core: Fix perf_sched_count derailment

perf/core: Fix perf_sched_count derailment
Commit-ID:  927a5570855836e5d5859a80ce7e91e963545e8f
Gitweb:     http://git.kernel.org/tip/927a5570855836e5d5859a80ce7e91e963545e8f
Author:     Alexander Shishkin <[email protected]>
AuthorDate: Wed, 2 Mar 2016 13:24:14 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 8 Mar 2016 12:18:31 +0100

perf/core: Fix perf_sched_count derailment

The error path in perf_event_open() is such that asking for a sampling event on a PMU that doesn't generate interrupts will end up in dropping the perf_sched_count even though it hasn't been incremented for this event yet.

Given a sufficient amount of these calls, we'll end up disabling scheduler's jump label even though we'd still have active events in the system, thereby facilitating the arrival of the infernal regions upon us.

I'm fixing this by moving account_event() inside perf_event_alloc().

---
 kernel/events/core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/events/core.c +3 -4
index 5dcc0bd..b723149 100644
@@ -8000,6 +8000,9 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
 		}
 	}
 
+	/* symmetric to unaccount_event() in _free_event() */
+	account_event(event);
+
 	return event;
 
 err_per_task:
@@ -8363,8 +8366,6 @@ SYSCALL_DEFINE5(perf_event_open,
 		}
 	}
 
-	account_event(event);
-
 	/*
 	 * Special case software events and allow them to be part of
 	 * any hardware group.
@@ -8661,8 +8662,6 @@ perf_event_create_kernel_counter(struct perf_event_attr *attr, int cpu,
 	/* Mark owner so we could distinguish it from user events. */
 	event->owner = TASK_TOMBSTONE;
 
-	account_event(event);
-
 	ctx = find_get_context(event->pmu, task, event);
 	if (IS_ERR(ctx)) {
 		err = PTR_ERR(ctx);