Skip to contentSkip to conversation

perf_event: Switch to internal refcount, fix race with close()

tip:perf/urgent tip-bot for Al Viro 1 participant 1 message Sep 4, 2012 1 message not in the archive perf events

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Commit-ID:  a6fa941d94b411bbd2b6421ffbde6db3c93e65ab
Gitweb:     http://git.kernel.org/tip/a6fa941d94b411bbd2b6421ffbde6db3c93e65ab
Author:     Al Viro <[email protected]>
AuthorDate: Mon, 20 Aug 2012 14:59:25 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 4 Sep 2012 17:29:22 +0200

perf_event: Switch to internal refcount, fix race with close()

Don't mess with file refcounts (or keep a reference to file, for that matter) in perf_event. Use explicit refcount of its own instead. Deal with the race between the final reference to event going away and new children getting created for it by use of atomic_long_inc_not_zero() in inherit_event(); just have the latter free what it had allocated and return NULL, that works out just fine (children of siblings of something doomed are created as singletons, same as if the child of leader had been created and immediately killed).

---
 include/linux/perf_event.h |    2 +-
 kernel/events/core.c       |   62 +++++++++++++++++++++++--------------------
 2 files changed, 34 insertions(+), 30 deletions(-)
include/linux/perf_event.h +1 -1
index 7602ccb..ad04dfc 100644
@@ -926,7 +926,7 @@ struct perf_event {
 	struct hw_perf_event		hw;
 
 	struct perf_event_context	*ctx;
-	struct file			*filp;
+	atomic_long_t			refcount;
 
 	/*
 	 * These accumulate total time (in nanoseconds) that children
kernel/events/core.c +33 -29

160 lines not on this page · raw message