Tetsuo Handa wrote:So, it is impossible to know whether I am inside a spinlock or not.
OK. That's not what I want to do.
I want to make sure that my code (not a device driver) is called only from a context where use of down()/mutex_lock()/kmalloc(GFP_KERNEL)/
get_user_pages()/kmap() etc. are permitted.
Is "if (in_atomic()) return;" check a correct method for avoiding deadlocks when my code was accidentally called from a context
where use of down()/mutex_lock()/kmalloc(GFP_KERNEL)/get_user_pages()/
kmap() etc. are not permitted?
You shouldn't sleep while holding a spinlock. As soon as another thread
attempts to take the spinlock, it will be stuck in a busy-wait loop.--