Chapter 9. What Functions Are Safe To Call From Interrupts?

Table of Contents

Some Functions Which Sleep
Some Functions Which Don't Sleep

Many functions in the kernel sleep (ie. call schedule()) directly or indirectly: you can never call them while holding a spinlock, or with preemption disabled. This also means you need to be in user context: calling them from an interrupt is illegal.

Some Functions Which Sleep

The most common ones are listed below, but you usually have to read the code to find out if other calls are safe. If everyone else who calls it can sleep, you probably need to be able to sleep, too. In particular, registration and deregistration functions usually expect to be called from user context, and can sleep.

  • Accesses to userspace:

    • copy_from_user()

    • copy_to_user()

    • get_user()

    • put_user()

  • kmalloc(GFP_KERNEL)

  • down_interruptible() and down()

    There is a down_trylock() which can be used inside interrupt context, as it will not sleep. up() will also never sleep.