linux-stable/drivers/block
Ilya Dryomov b75b017b3f rbd: take header_rwsem in rbd_dev_refresh() only when updating
commit 0b207d02bd upstream.

rbd_dev_refresh() has been holding header_rwsem across header and
parent info read-in unnecessarily for ages.  With commit 870611e487
("rbd: get snapshot context after exclusive lock is ensured to be
held"), the potential for deadlocks became much more real owning to
a) header_rwsem now nesting inside lock_rwsem and b) rw_semaphores
not allowing new readers after a writer is registered.

For example, assuming that I/O request 1, I/O request 2 and header
read-in request all target the same OSD:

1. I/O request 1 comes in and gets submitted
2. watch error occurs
3. rbd_watch_errcb() takes lock_rwsem for write, clears owner_cid and
   releases lock_rwsem
4. after reestablishing the watch, rbd_reregister_watch() calls
   rbd_dev_refresh() which takes header_rwsem for write and submits
   a header read-in request
5. I/O request 2 comes in: after taking lock_rwsem for read in
   __rbd_img_handle_request(), it blocks trying to take header_rwsem
   for read in rbd_img_object_requests()
6. another watch error occurs
7. rbd_watch_errcb() blocks trying to take lock_rwsem for write
8. I/O request 1 completion is received by the messenger but can't be
   processed because lock_rwsem won't be granted anymore
9. header read-in request completion can't be received, let alone
   processed, because the messenger is stranded

Change rbd_dev_refresh() to take header_rwsem only for actually
updating rbd_dev->header.  Header and parent info read-in don't need
any locking.

Cc: stable@vger.kernel.org # 0b035401c5: rbd: move rbd_dev_refresh() definition
Cc: stable@vger.kernel.org # 510a7330c8: rbd: decouple header read-in from updating rbd_dev->header
Cc: stable@vger.kernel.org # c10311776f: rbd: decouple parent info read-in from updating rbd_dev
Cc: stable@vger.kernel.org
Fixes: 870611e487 ("rbd: get snapshot context after exclusive lock is ensured to be held")
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Reviewed-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-10-10 21:59:05 +02:00
..
aoe
drbd drbd: correctly submit flush bio on barrier 2023-05-17 11:50:31 +02:00
mtip32xx block: fix surprise removal for drivers calling blk_set_queue_dying 2022-02-23 12:03:15 +01:00
null_blk null_blk: Always check queue mode setting from configfs 2023-05-24 17:36:46 +01:00
paride pcd: fix error codes in pcd_init_unit() 2023-09-19 12:23:04 +02:00
rnbd block/rnbd: replace REQ_OP_FLUSH with REQ_OP_WRITE 2023-06-09 10:32:21 +02:00
rsxx block: handle bio_split_to_limits() NULL return 2023-01-18 11:48:58 +01:00
xen-blkback xen-blkback: Advertise feature-persistent as user requested 2022-09-08 12:28:05 +02:00
zram zram: do not lookup algorithm in backends table 2022-08-25 11:40:34 +02:00
amiflop.c block: drop unused includes in <linux/genhd.h> 2022-03-16 14:23:46 +01:00
ataflop.c block: drop unused includes in <linux/genhd.h> 2022-03-16 14:23:46 +01:00
brd.c brd: mark as nowait compatible 2023-03-17 08:48:51 +01:00
cryptoloop.c cryptoloop: add a deprecation warning 2021-08-27 10:44:54 -06:00
floppy.c floppy: Fix memory leak in do_floppy_init() 2022-12-31 13:14:47 +01:00
Kconfig remove the sx8 block driver 2023-06-14 11:12:59 +02:00
loop.c block: rename GENHD_FL_NO_PART_SCAN to GENHD_FL_NO_PART 2023-09-19 12:23:02 +02:00
loop.h loop: reduce the loop_ctl_mutex scope 2021-09-03 22:14:40 -06:00
Makefile remove the sx8 block driver 2023-06-14 11:12:59 +02:00
n64cart.c block: rename GENHD_FL_NO_PART_SCAN to GENHD_FL_NO_PART 2023-09-19 12:23:02 +02:00
nbd.c nbd: Fix debugfs_create_dir error checking 2023-06-09 10:32:21 +02:00
pktcdvd.c block: handle bio_split_to_limits() NULL return 2023-01-18 11:48:58 +01:00
ps3disk.c
ps3vram.c block: handle bio_split_to_limits() NULL return 2023-01-18 11:48:58 +01:00
rbd.c rbd: take header_rwsem in rbd_dev_refresh() only when updating 2023-10-10 21:59:05 +02:00
rbd_types.h
sunvdc.c block: sunvdc: add check for mdesc_grab() returning NULL 2023-03-22 13:31:27 +01:00
swim.c block: drop unused includes in <linux/genhd.h> 2022-03-16 14:23:46 +01:00
swim3.c
swim_asm.S
virtio_blk.c virtio-blk: modify the value type of num in virtio_queue_rq() 2022-07-12 16:35:11 +02:00
xen-blkfront.c xen/blkfront: Only check REQ_FUA for writes 2023-06-21 15:59:13 +02:00
z2ram.c