Re: [PATCH,RFC] perf: panic due to inclied cpu context task_ctxvalue

From: Oleg Nesterov
Date: Mon Mar 28 2011 - 14:06:07 EST


On 03/28, Peter Zijlstra wrote:
>
> Another fun race, suppose we do properly remove task_ctx and is_active,
> but then the task gets scheduled back in before free_event() gets around
> to disabling the jump_label..

Yes, this too...

Well, ignoring the HAVE_JUMP_LABEL case... perhaps we can split
perf_sched_events into 2 counters? I mean,

atomic_t perf_sched_events_in, perf_sched_events_out;

static inline void perf_event_task_sched_in(struct task_struct *task)
{
COND_STMT(&perf_sched_events_in, __perf_event_task_sched_in(task));
}

static inline
void perf_event_task_sched_out(struct task_struct *task, struct task_struct *next)
{
perf_sw_event(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 1, NULL, 0);

COND_STMT(&perf_sched_events_out, __perf_event_task_sched_out(task, next));
}

void perf_sched_events_inc(void)
{
atomic_inc(&perf_sched_events_out);
smp_mb__after_atomic_inc();
atomic_inc(&perf_sched_events_in);
}

void perf_sched_events_dec(void)
{
if (atomic_dec_and_test(&perf_sched_events_in))
synchronize_sched();
atomic_dec(&perf_sched_events_out);
}

The last 2 helpers should be used instead of jump_label_inc/dec.



Or we can remove COND_STMT() from perf_event_task_sched_out(). Say,
__perf_event_task_sched_in() can set PF_PERF_XXX or something, then
perf_event_task_sched_out() can check this bit.


As for HAVE_JUMP_LABEL, I still can't understand why this test-case
triggers the problem. But jump_label_inc/dec logic looks obviously
racy.

jump_label_dec:

if (atomic_dec_and_test(key))
jump_label_disable(key);

Another thread can create the PERF_ATTACH_TASK event in between
and call jump_label_update(JUMP_LABEL_ENABLE) first. Looks like,
jump_label_update() should ensure that "type" matches the state
of the "*key" under jump_label_lock().

But perhaps I misread this code completely.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/