Re: keventd_create_kthread
From: Rusty Russell
Date: Thu Feb 19 2004 - 04:55:45 EST
In message <Pine.LNX.4.58.0402190205040.16515@xxxxxxxxxxxxxxxxxxxxxxxx> you write:
> The current wait_task_inactive() code seems to be OK on x86.
> Context-switching cannot be preempted. The goal of wait_task_inactive() is
> to wait for the task to unschedule on a CPU. If that's due to preempt then
> it's due to preempt.
No, because it can come back at any time 8(
> that in any modern interface. Why does keventd_create_kthread() need
> wait_task_inactive()?
Um, the code was taken from sched.c to kthread:
2.6.3 migration_thread():
set_current_state(TASK_UNINTERRUPTIBLE);
schedule();
2.6.3 migration_call():
kernel_thread(migration_thread, &startup, CLONE_KERNEL);
wait_for_completion(&startup.startup_done);
wait_task_inactive(startup.task);
startup.task->thread_info->cpu = cpu;
startup.task->cpus_allowed = cpumask_of_cpu(cpu);
So, if the migration thread has been preempted immediately before
schedule(), wait_task_inactive returns, but it can come back from
preempt while we're messing with startup.task->thread_info->cpu.
Now, the latter part is wrapped in kthread_bind(), which should really
be doing the wait_task_inactive itself (doing it in kthread_create is
overzealous). But the race is still there.
Hope that clarifies,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
-
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/