[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
sleeping function called from invalid context
I've made the following changes to kernel/exit.c:
fastcall NORET_TYPE void do_exit(long code)
{
struct task_struct *tsk = current;
int group_dead;
if(tsk->pk)
__do_abort(tsk->pk, 0);
profile_task_exit(tsk);
...
...
exit_mm(tsk);
...
}
Now, __do_abort is a function that I've written that internally calls
might_sleep() and then calls kmem_cache_alloc. When __do_abort gets
called (tsk->pk != NULL; ofcourse), I see the following error in
dmesg:
[ 5266.639222] note: test2[2414] exited with preempt_count 2
[ 5266.639293] Debug: sleeping function called from invalid context at
include/linux/rwsem.h:43
[ 5266.639836] in_atomic():1, irqs_disabled():0
[ 5266.640037] [<c011d431>] __might_sleep+0xa1/0xc0
[ 5266.640612] [<c0124928>] exit_mm+0x38/0x2b0
[ 5266.640734] [<c01257a7>] do_exit+0xe7/0x840
This pretty much means, we called a function that sleeps, while the
kernel was locked (CONFIG_PREMPT=y). The code path, for this reads as
follows:
exit_mm() -> calls down_read(...) -> which in turn calls __might_sleep
and there the following check is made:
if ((in_atomic() || irqs_disabled()) && ...) {
...
}
and in our case in_atomic is 1.
So my question is why is this detected at exit_mm()? Why is this not
detected in __do_abort() where I have a might_sleep() check? Earlier
when I had Profiling enabled, the same error was detected at
profile_task_exit(tsk); which also does a down_read(...).
Any hints will be appreciated,
Thanks,
./hareesh
PS: when I remove kmem_cache_alloc from the body of __do_abort() the
errors go away.
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/