AFAIK, kmalloc in fact CANNOT know if it could sleep or not. As it was explained to me in the
in_atomic() thread on LKML, that information just doesn't exist in the kernel right now. You
simply have to know in which context you are, and tell everyone about it (thus, GFP_ATOMIC).