mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: paulmck@linux.vnet.ibm.com
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-kernel@vger.kernel.org, mingo@elte.hu,
	laijs@cn.fujitsu.com, dipankar@in.ibm.com,
	akpm@linux-foundation.org, josh@joshtriplett.org,
	dvhltc@us.ibm.com, niv@us.ibm.com, tglx@linutronix.de,
	peterz@infradead.org, rostedt@goodmis.org,
	Valdis.Kletnieks@vt.edu, dhowells@redhat.com
Subject: [PATCH 05/10] perf_event: __rcu annotations
Date: Wed, 24 Feb 2010 21:04:01 +0100	[thread overview]
Message-ID: <1267041846-10469-6-git-send-email-arnd@arndb.de> (raw)
In-Reply-To: <1267041846-10469-1-git-send-email-arnd@arndb.de>
In-Reply-To: <20100223180127.GF6700@linux.vnet.ibm.com>

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 include/linux/perf_event.h |   10 ++++----
 include/linux/sched.h      |    2 +-
 kernel/perf_event.c        |   52 ++++++++++++++++++++++----------------------
 3 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index a177698..c0d85e3 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -569,11 +569,11 @@ typedef void (*perf_overflow_handler_t)(struct perf_event *, int,
 struct perf_event {
 #ifdef CONFIG_PERF_EVENTS
 	struct list_head		group_entry;
-	struct list_head		event_entry;
+	struct rcu_list_head		event_entry;
 	struct list_head		sibling_list;
 	int				nr_siblings;
 	struct perf_event		*group_leader;
-	struct perf_event		*output;
+	struct perf_event __rcu		*output;
 	const struct pmu		*pmu;
 
 	enum perf_event_active_state	state;
@@ -634,7 +634,7 @@ struct perf_event {
 	/* mmap bits */
 	struct mutex			mmap_mutex;
 	atomic_t			mmap_count;
-	struct perf_mmap_data		*data;
+	struct perf_mmap_data __rcu	*data;
 
 	/* poll related */
 	wait_queue_head_t		waitq;
@@ -682,7 +682,7 @@ struct perf_event_context {
 	struct mutex			mutex;
 
 	struct list_head		group_list;
-	struct list_head		event_list;
+	struct rcu_list_head		event_list;
 	int				nr_events;
 	int				nr_active;
 	int				is_active;
@@ -700,7 +700,7 @@ struct perf_event_context {
 	 * These fields let us detect when two contexts have both
 	 * been cloned (inherited) from a common ancestor.
 	 */
-	struct perf_event_context	*parent_ctx;
+	struct perf_event_context	__rcu *parent_ctx;
 	u64				parent_gen;
 	u64				generation;
 	int				pin_count;
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 52a33eb..f14d925 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1502,7 +1502,7 @@ struct task_struct {
 	struct futex_pi_state *pi_state_cache;
 #endif
 #ifdef CONFIG_PERF_EVENTS
-	struct perf_event_context *perf_event_ctxp;
+	struct perf_event_context __rcu *perf_event_ctxp;
 	struct mutex perf_event_mutex;
 	struct list_head perf_event_list;
 #endif
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 2ae7409..18701de 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -150,7 +150,7 @@ static void put_ctx(struct perf_event_context *ctx)
 {
 	if (atomic_dec_and_test(&ctx->refcount)) {
 		if (ctx->parent_ctx)
-			put_ctx(ctx->parent_ctx);
+			put_ctx(__rcu_dereference(ctx->parent_ctx));
 		if (ctx->task)
 			put_task_struct(ctx->task);
 		call_rcu(&ctx->rcu_head, free_ctx);
@@ -160,7 +160,7 @@ static void put_ctx(struct perf_event_context *ctx)
 static void unclone_ctx(struct perf_event_context *ctx)
 {
 	if (ctx->parent_ctx) {
-		put_ctx(ctx->parent_ctx);
+		put_ctx(__rcu_dereference(ctx->parent_ctx));
 		ctx->parent_ctx = NULL;
 	}
 }
@@ -1129,8 +1129,8 @@ static void __perf_event_sync_stat(struct perf_event *event,
 	perf_event_update_userpage(next_event);
 }
 
-#define list_next_entry(pos, member) \
-	list_entry(pos->member.next, typeof(*pos), member)
+#define list_next_entry_rcu(pos, member) \
+	list_entry_rcu(pos->member.next, typeof(*pos), member)
 
 static void perf_event_sync_stat(struct perf_event_context *ctx,
 				   struct perf_event_context *next_ctx)
@@ -1142,10 +1142,10 @@ static void perf_event_sync_stat(struct perf_event_context *ctx,
 
 	update_context_time(ctx);
 
-	event = list_first_entry(&ctx->event_list,
+	event = list_first_entry_rcu(&ctx->event_list,
 				   struct perf_event, event_entry);
 
-	next_event = list_first_entry(&next_ctx->event_list,
+	next_event = list_first_entry_rcu(&next_ctx->event_list,
 					struct perf_event, event_entry);
 
 	while (&event->event_entry != &ctx->event_list &&
@@ -1153,8 +1153,8 @@ static void perf_event_sync_stat(struct perf_event_context *ctx,
 
 		__perf_event_sync_stat(event, next_event);
 
-		event = list_next_entry(event, event_entry);
-		next_event = list_next_entry(next_event, event_entry);
+		event = list_next_entry_rcu(event, event_entry);
+		next_event = list_next_entry_rcu(next_event, event_entry);
 	}
 }
 
@@ -1173,7 +1173,7 @@ void perf_event_task_sched_out(struct task_struct *task,
 				 struct task_struct *next, int cpu)
 {
 	struct perf_cpu_context *cpuctx = &per_cpu(perf_cpu_context, cpu);
-	struct perf_event_context *ctx = task->perf_event_ctxp;
+	struct perf_event_context *ctx = rcu_dereference(task->perf_event_ctxp);
 	struct perf_event_context *next_ctx;
 	struct perf_event_context *parent;
 	struct pt_regs *regs;
@@ -1187,7 +1187,7 @@ void perf_event_task_sched_out(struct task_struct *task,
 
 	rcu_read_lock();
 	parent = rcu_dereference(ctx->parent_ctx);
-	next_ctx = next->perf_event_ctxp;
+	next_ctx = rcu_dereference(next->perf_event_ctxp);
 	if (parent && next_ctx &&
 	    rcu_dereference(next_ctx->parent_ctx) == parent) {
 		/*
@@ -1206,8 +1206,8 @@ void perf_event_task_sched_out(struct task_struct *task,
 			 * XXX do we need a memory barrier of sorts
 			 * wrt to rcu_dereference() of perf_event_ctxp
 			 */
-			task->perf_event_ctxp = next_ctx;
-			next->perf_event_ctxp = ctx;
+			__rcu_assign_pointer(task->perf_event_ctxp, next_ctx);
+			__rcu_assign_pointer(next->perf_event_ctxp, ctx);
 			ctx->task = next;
 			next_ctx->task = task;
 			do_switch = 0;
@@ -1329,7 +1329,7 @@ __perf_event_sched_in(struct perf_event_context *ctx,
 void perf_event_task_sched_in(struct task_struct *task, int cpu)
 {
 	struct perf_cpu_context *cpuctx = &per_cpu(perf_cpu_context, cpu);
-	struct perf_event_context *ctx = task->perf_event_ctxp;
+	struct perf_event_context *ctx = __rcu_dereference(task->perf_event_ctxp);
 
 	if (likely(!ctx))
 		return;
@@ -1470,7 +1470,7 @@ void perf_event_task_tick(struct task_struct *curr, int cpu)
 		return;
 
 	cpuctx = &per_cpu(perf_cpu_context, cpu);
-	ctx = curr->perf_event_ctxp;
+	ctx = rcu_dereference(curr->perf_event_ctxp);
 
 	perf_ctx_adjust_freq(&cpuctx->ctx);
 	if (ctx)
@@ -1501,7 +1501,7 @@ static void perf_event_enable_on_exec(struct task_struct *task)
 	int enabled = 0;
 
 	local_irq_save(flags);
-	ctx = task->perf_event_ctxp;
+	ctx = __rcu_dereference(task->perf_event_ctxp);
 	if (!ctx || !ctx->nr_events)
 		goto out;
 
@@ -1591,7 +1591,7 @@ __perf_event_init_context(struct perf_event_context *ctx,
 	raw_spin_lock_init(&ctx->lock);
 	mutex_init(&ctx->mutex);
 	INIT_LIST_HEAD(&ctx->group_list);
-	INIT_LIST_HEAD(&ctx->event_list);
+	INIT_LIST_HEAD_RCU(&ctx->event_list);
 	atomic_set(&ctx->refcount, 1);
 	ctx->task = task;
 }
@@ -2366,7 +2366,7 @@ static void perf_mmap_data_free_rcu(struct rcu_head *rcu_head)
 
 static void perf_mmap_data_release(struct perf_event *event)
 {
-	struct perf_mmap_data *data = event->data;
+	struct perf_mmap_data *data = __rcu_dereference(event->data);
 
 	WARN_ON(atomic_read(&event->mmap_count));
 
@@ -2387,7 +2387,7 @@ static void perf_mmap_close(struct vm_area_struct *vma)
 
 	WARN_ON_ONCE(event->ctx->parent_ctx);
 	if (atomic_dec_and_mutex_lock(&event->mmap_count, &event->mmap_mutex)) {
-		unsigned long size = perf_data_size(event->data);
+		unsigned long size = perf_data_size(__rcu_dereference(event->data));
 		struct user_struct *user = current_user();
 
 		atomic_long_sub((size >> PAGE_SHIFT) + 1, &user->locked_vm);
@@ -4421,7 +4421,7 @@ perf_event_alloc(struct perf_event_attr *attr,
 	INIT_LIST_HEAD(&event->child_list);
 
 	INIT_LIST_HEAD(&event->group_entry);
-	INIT_LIST_HEAD(&event->event_entry);
+	INIT_LIST_HEAD_RCU(&event->event_entry);
 	INIT_LIST_HEAD(&event->sibling_list);
 	init_waitqueue_head(&event->waitq);
 
@@ -4629,7 +4629,7 @@ static int perf_event_set_output(struct perf_event *event, int output_fd)
 
 set:
 	mutex_lock(&event->mmap_mutex);
-	old_output = event->output;
+	old_output = __rcu_dereference(event->output);
 	rcu_assign_pointer(event->output, output_event);
 	mutex_unlock(&event->mmap_mutex);
 
@@ -4999,7 +4999,7 @@ void perf_event_exit_task(struct task_struct *child)
 	 * scheduled, so we are now safe from rescheduling changing
 	 * our context.
 	 */
-	child_ctx = child->perf_event_ctxp;
+	child_ctx = __rcu_dereference(child->perf_event_ctxp);
 	__perf_event_task_sched_out(child_ctx);
 
 	/*
@@ -5062,7 +5062,7 @@ again:
  */
 void perf_event_free_task(struct task_struct *task)
 {
-	struct perf_event_context *ctx = task->perf_event_ctxp;
+	struct perf_event_context *ctx = __rcu_dereference(task->perf_event_ctxp);
 	struct perf_event *event, *tmp;
 
 	if (!ctx)
@@ -5160,7 +5160,7 @@ int perf_event_init_task(struct task_struct *child)
 			}
 
 			__perf_event_init_context(child_ctx, child);
-			child->perf_event_ctxp = child_ctx;
+			__rcu_assign_pointer(child->perf_event_ctxp, child_ctx);
 			get_task_struct(child);
 		}
 
@@ -5183,13 +5183,13 @@ int perf_event_init_task(struct task_struct *child)
 		 */
 		cloned_ctx = rcu_dereference(parent_ctx->parent_ctx);
 		if (cloned_ctx) {
-			child_ctx->parent_ctx = cloned_ctx;
+			__rcu_assign_pointer(child_ctx->parent_ctx, cloned_ctx);
 			child_ctx->parent_gen = parent_ctx->parent_gen;
 		} else {
-			child_ctx->parent_ctx = parent_ctx;
+			__rcu_assign_pointer(child_ctx->parent_ctx, parent_ctx);
 			child_ctx->parent_gen = parent_ctx->generation;
 		}
-		get_ctx(child_ctx->parent_ctx);
+		get_ctx(__rcu_dereference(child_ctx->parent_ctx));
 	}
 
 	mutex_unlock(&parent_ctx->mutex);
-- 
1.6.3.3


  parent reply	other threads:[~2010-02-24 20:06 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-23  1:04 [PATCH tip/core/rcu 0/21] v6 add lockdep-based diagnostics to rcu_dereference() Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 01/21] rcu: introduce lockdep-based checking to RCU read-side primitives Paul E. McKenney
2010-02-25 10:09   ` [tip:core/rcu] rcu: Introduce " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 02/21] rcu: add lockdep-enabled variants of rcu_dereference() Paul E. McKenney
2010-02-25 10:09   ` [tip:core/rcu] rcu: Add " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 03/21] rcu: integrate rcu_dereference_check() message into lockdep Paul E. McKenney
2010-02-25 10:09   ` [tip:core/rcu] rcu: Integrate " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 04/21] rcu: disable lockdep checking in RCU list-traversal primitives Paul E. McKenney
2010-02-25 10:10   ` [tip:core/rcu] rcu: Disable " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 05/21] net: add checking to rcu_dereference() primitives Paul E. McKenney
2010-02-25 10:10   ` [tip:core/rcu] net: Add " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 06/21] sched: use lockdep-based checking on rcu_dereference() Paul E. McKenney
2010-02-25 10:11   ` [tip:core/rcu] sched: Use " tip-bot for Paul E. McKenney
2010-02-25 11:06   ` [tip:core/rcu] sched, cgroups: Fix module export tip-bot for Ingo Molnar
2010-02-23  1:04 ` [PATCH tip/core/rcu 07/21] sched: better name for for_each_domain_rd Paul E. McKenney
2010-02-25 10:11   ` [tip:core/rcu] sched: Better " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 08/21] vfs: apply lockdep-based checking to rcu_dereference() uses Paul E. McKenney
2010-02-25 10:11   ` [tip:core/rcu] vfs: Apply " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 09/21] vfs: abstract rcu_dereference_check for files-fdtable use Paul E. McKenney
2010-02-25 10:11   ` [tip:core/rcu] vfs: Abstract " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 10/21] radix-tree: disable RCU lockdep checking in radix tree Paul E. McKenney
2010-02-25 10:12   ` [tip:core/rcu] radix-tree: Disable " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 11/21] idr: apply lockdep-based diagnostics to rcu_dereference() uses Paul E. McKenney
2010-02-25 10:12   ` [tip:core/rcu] idr: Apply " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 12/21] security: apply lockdep-based checking " Paul E. McKenney
2010-02-25 10:12   ` [tip:core/rcu] security: Apply " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 13/21] rcu: documentation update for CONFIG_PROVE_RCU Paul E. McKenney
2010-02-25 10:12   ` [tip:core/rcu] rcu: Documentation " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 14/21] rcu: fix citation of Mathieu's dissertation Paul E. McKenney
2010-02-25 10:13   ` [tip:core/rcu] rcu: Fix " tip-bot for Paul E. McKenney
2010-02-23  1:04 ` [PATCH tip/core/rcu 15/21] rcu: accelerate grace period if last non-dynticked CPU Paul E. McKenney
2010-02-25 10:13   ` [tip:core/rcu] rcu: Accelerate " tip-bot for Paul E. McKenney
2010-02-23  1:05 ` [PATCH tip/core/rcu 16/21] rcu: use canonical URL for Mathieu's dissertation Paul E. McKenney
2010-02-25 10:13   ` [tip:core/rcu] rcu: Use " tip-bot for Paul E. McKenney
2010-02-23  1:05 ` [PATCH tip/core/rcu 17/21] rcu: stop overflowing signed integers Paul E. McKenney
2010-02-25 10:14   ` [tip:core/rcu] rcu: Stop " tip-bot for Paul E. McKenney
2010-02-23  1:05 ` [PATCH tip/core/rcu 18/21] rcu: Convert to raw_spinlocks Paul E. McKenney
2010-02-25 10:14   ` [tip:core/rcu] " tip-bot for Paul E. McKenney
2010-02-23  1:05 ` [PATCH tip/core/rcu 19/21] rcu: fix deadlock in TREE_PREEMPT_RCU CPU stall detection Paul E. McKenney
2010-02-25 10:14   ` [tip:core/rcu] rcu: Fix " tip-bot for Paul E. McKenney
2010-02-23  1:05 ` [PATCH tip/core/rcu 20/21] rcu: fix rcutorture mod_timer argument to delay one jiffy Paul E. McKenney
2010-02-25 10:14   ` [tip:core/rcu] rcu: Fix " tip-bot for Paul E. McKenney
2010-02-23  1:05 ` [PATCH tip/core/rcu 21/21] rcu: add RCU_CPU_STALL_VERBOSE to dump detailed per-task information Paul E. McKenney
2010-02-25 10:15   ` [tip:core/rcu] rcu: Add " tip-bot for Paul E. McKenney
2010-02-23 12:59 ` [PATCH tip/core/rcu 0/21] v6 add lockdep-based diagnostics to rcu_dereference() Arnd Bergmann
2010-02-23 13:15   ` Mathieu Desnoyers
2010-02-23 14:35     ` Paul E. McKenney
2010-02-23 15:54     ` Arnd Bergmann
2010-02-23 16:16       ` Paul E. McKenney
2010-02-23 17:15         ` Arnd Bergmann
2010-02-23 18:01           ` Paul E. McKenney
2010-02-24 20:03             ` [PATCH 00/10] __rcu annotations, first draft Arnd Bergmann
2010-02-24 22:18               ` Paul E. McKenney
2010-02-25  8:37               ` Ingo Molnar
2010-02-24 20:03             ` [PATCH 01/10] rcu: define __rcu address space modifier for sparse Arnd Bergmann
2010-02-24 20:12               ` Mathieu Desnoyers
2010-02-24 20:22                 ` Arnd Bergmann
2010-02-24 20:03             ` [PATCH 02/10] rcu: annotated list rcu code Arnd Bergmann
2010-02-24 20:15               ` Mathieu Desnoyers
2010-02-24 20:32                 ` Arnd Bergmann
2010-02-24 20:03             ` [PATCH 03/10] cgroups: __rcu annotations Arnd Bergmann
2010-02-24 20:04             ` [PATCH 04/10] credentials: rcu annotation Arnd Bergmann
2010-02-24 20:04             ` Arnd Bergmann [this message]
2010-02-24 20:04             ` [PATCH 06/10] audit: __rcu annotations Arnd Bergmann
2010-02-24 20:04             ` [PATCH 07/10] module: " Arnd Bergmann
2010-02-24 20:13               ` Alexey Dobriyan
2010-02-24 20:26                 ` Arnd Bergmann
2010-02-24 22:17                   ` Paul E. McKenney
2010-02-24 23:07                     ` Arnd Bergmann
2010-02-24 23:59                       ` Paul E. McKenney
2010-02-25 17:06                         ` Paul E. McKenney
2010-02-25 18:10                           ` Arnd Bergmann
2010-02-25 20:05                             ` Paul E. McKenney
2010-02-26  2:12                               ` Paul E. McKenney
2010-02-24 20:04             ` [PATCH 08/10] pid: " Arnd Bergmann
2010-02-24 20:04             ` [PATCH 09/10] notifiers: " Arnd Bergmann
2010-02-24 20:04             ` [PATCH 10/10] scheduler: " Arnd Bergmann
2010-02-23 13:28   ` [PATCH tip/core/rcu 0/21] v6 add lockdep-based diagnostics to rcu_dereference() Paul E. McKenney
2010-02-25 10:00 ` Ingo Molnar
2010-02-25 10:01   ` Ingo Molnar
2010-02-25 12:04     ` Ingo Molnar
2010-02-25 18:18       ` Paul E. McKenney
2010-02-25 21:36         ` Paul E. McKenney
2010-02-25 21:22       ` Ingo Molnar

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=1267041846-10469-6-git-send-email-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=dvhltc@us.ibm.com \
    --cc=josh@joshtriplett.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@elte.hu \
    --cc=niv@us.ibm.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®