]> rtime.felk.cvut.cz Git - lisovros/linux_canprio.git/commitdiff
perf: Fix inherit vs. context rotation bug
authorThomas Gleixner <tglx@linutronix.de>
Wed, 24 Nov 2010 09:05:55 +0000 (10:05 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 9 Dec 2010 21:33:25 +0000 (13:33 -0800)
commit dddd3379a619a4cb8247bfd3c94ca9ae3797aa2e upstream.

It was found that sometimes children of tasks with inherited events had
one extra event. Eventually it turned out to be due to the list rotation
no being exclusive with the list iteration in the inheritance code.

Cure this by temporarily disabling the rotation while we inherit the events.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
include/linux/perf_event.h
kernel/perf_event.c

index 716f99b682c1a57fb3b6f1f72e90aec3982ca5fd..1d42c6ecd00a3d0b885c84f36e0c38dca976eee4 100644 (file)
@@ -788,6 +788,7 @@ struct perf_event_context {
        int                             nr_active;
        int                             is_active;
        int                             nr_stat;
+       int                             rotate_disable;
        atomic_t                        refcount;
        struct task_struct              *task;
 
index 03bb8974bc905f8e5624eee2f45bb0407d76fa4c..65b09a836cc3bdaed508cb1e050a174170241a8a 100644 (file)
@@ -1620,8 +1620,12 @@ static void rotate_ctx(struct perf_event_context *ctx)
 {
        raw_spin_lock(&ctx->lock);
 
-       /* Rotate the first entry last of non-pinned groups */
-       list_rotate_left(&ctx->flexible_groups);
+       /*
+        * Rotate the first entry last of non-pinned groups. Rotation might be
+        * disabled by the inheritance code.
+        */
+       if (!ctx->rotate_disable)
+               list_rotate_left(&ctx->flexible_groups);
 
        raw_spin_unlock(&ctx->lock);
 }
@@ -5622,6 +5626,7 @@ int perf_event_init_task(struct task_struct *child)
        struct perf_event *event;
        struct task_struct *parent = current;
        int inherited_all = 1;
+       unsigned long flags;
        int ret = 0;
 
        child->perf_event_ctxp = NULL;
@@ -5662,6 +5667,15 @@ int perf_event_init_task(struct task_struct *child)
                        break;
        }
 
+       /*
+        * We can't hold ctx->lock when iterating the ->flexible_group list due
+        * to allocations, but we need to prevent rotation because
+        * rotate_ctx() will change the list from interrupt context.
+        */
+       raw_spin_lock_irqsave(&parent_ctx->lock, flags);
+       parent_ctx->rotate_disable = 1;
+       raw_spin_unlock_irqrestore(&parent_ctx->lock, flags);
+
        list_for_each_entry(event, &parent_ctx->flexible_groups, group_entry) {
                ret = inherit_task_group(event, parent, parent_ctx, child,
                                         &inherited_all);
@@ -5669,6 +5683,10 @@ int perf_event_init_task(struct task_struct *child)
                        break;
        }
 
+       raw_spin_lock_irqsave(&parent_ctx->lock, flags);
+       parent_ctx->rotate_disable = 0;
+       raw_spin_unlock_irqrestore(&parent_ctx->lock, flags);
+
        child_ctx = child->perf_event_ctxp;
 
        if (child_ctx && inherited_all) {