I am trying to debug a kernel code, because of a “scheduling while in atomic” that is crashing my system. In some point of an actual kernel module I added a line for calling a function defined in another kernel module (this one made by me). The call is:
mycallback(svc, skb);
And mycallback() function returns int. So I have 2 questions:
-
Is it safe to call a non-void function inside the kernel without asigning its result to a variable?
-
If the code where
mycallback()is called would be spin_locked or something like that, would it be safe? Would it be spin_locked/atomic or I might sleep and compromise the kernel?
Yes.
If the code that calls
mycallback()can hold a spinlock,mycallback()must not call any functions that can sleep. If you do try to sleep while holding a spinlock, you will see the “Scheduling while atomic” crash that you’ve described.Potentially sleeping functions include
copy_to_user(),copy_from_user(),kmalloc()(without theGFP_ATOMICflag),mutex_lock()and a lot more beside.