Re: kthread_stop insanity (Re: [[DEBUG] force] 2642458962: BUG: unable to handle kernel paging request at ffffc90000997f18)

From: Linus Torvalds
Date: Tue Jun 28 2016 - 17:40:59 EST


On Tue, Jun 28, 2016 at 2:35 PM, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Tue, Jun 28, 2016 at 2:21 PM, Andy Lutomirski <luto@xxxxxxxxxxxxxx> wrote:
>
>> If so, that seems considerably more complicated than just adding a reference count.
>
> Fair enough.

Ahh, and if you put the reference count just in the task_struct (next
to the ->stack pointer), then I guess that's particularly trivial.

Then try_get_task_stack(tsk) becomes

void *try_get_task_stack(struct task_struct *tsk)
{
void *stack = tsk->stack;
if (!atomic_inc_not_zero(&tsk->stackref))
stack = NULL;
return stack;
}

ok, color me convinced.

Linus