I’m writing a linux kernel module that provides a (virtual) block device (so no actual hardware IO is performed).
Currently I’m using spin_lock_irqsave / spin_unlock_irqrestore to handle locks.
There is only one function running in non-process context, and this is the make_request function of the block device.
Would it be safe to use spin_lock_bh / spin_unlock_bh to handle locks? I guess that simple spin_lock is insufficient, since make_request is not run by a process (is this correct?).
Thanks in advance.
Your make_request function actually does run in process context. The only caller of
q->make_request_fnis the block layer’sgeneric_make_request(), which assumes process context (eg look at its use ofcurrent). And as another example, drivers/md/md.c hasmd_make_request()which explicitly sleeps on a waitqueue.So you are completely safe using plain
spin_lock()/spin_unlock()as long as all the rest of your code is process context too.