dm bufio: simplify DM_BUFIO_CLIENT_NO_SLEEP locking
authorMike Snitzer <snitzer@kernel.org>
Sat, 6 Aug 2022 02:58:33 +0000 (22:58 -0400)
committerMike Snitzer <snitzer@kernel.org>
Tue, 9 Aug 2022 23:12:14 +0000 (19:12 -0400)
commitb33b6fdca3f0380c101e2adae5644777d6530fe5
tree66de843e37d7ba139884dbd35b0fec9fa3f56b83
parent12907efde6ad984f2d76cc1a7dbaae132384d8a5
dm bufio: simplify DM_BUFIO_CLIENT_NO_SLEEP locking

Historically none of the bufio code runs in interrupt context but with
the use of DM_BUFIO_CLIENT_NO_SLEEP a bufio client can, see: commit
5721d4e5a9cd ("dm verity: Add optional "try_verify_in_tasklet" feature")
That said, the new tasklet usecase still doesn't require interrupts be
disabled by bufio (let alone conditionally restore them).

Yet with PREEMPT_RT, and falling back from tasklet to workqueue, care
must be taken to properly synchronize between softirq and process
context, otherwise ABBA deadlock may occur. While it is unnecessary to
disable bottom-half preemption within a tasklet, we must consistently do
so in process context to ensure locking is in the proper order.

Fix these issues by switching from spin_lock_irq{save,restore} to using
spin_{lock,unlock}_bh instead. Also remove the 'spinlock_flags' member
in dm_bufio_client struct (that can be used unsafely if bufio must
recurse on behalf of some caller, e.g. block layer's submit_bio).

Fixes: 5721d4e5a9cd ("dm verity: Add optional "try_verify_in_tasklet" feature")
Reported-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-bufio.c