null_blk: Fix locking in zoned mode
authorDamien Le Moal <damien.lemoal@wdc.com>
Thu, 29 Oct 2020 11:05:00 +0000 (20:05 +0900)
committerJens Axboe <axboe@kernel.dk>
Thu, 29 Oct 2020 13:27:30 +0000 (07:27 -0600)
commitaa1c09cb65e2ed17cb8e652bc7ec84e0af1229eb
treefbb60901dd8ed079fe2f191e88b9f636c4f55d19
parentf9c9104288da543cd64f186f9e2fba389f415630
null_blk: Fix locking in zoned mode

When the zoned mode is enabled in null_blk, Serializing read, write
and zone management operations for each zone is necessary to protect
device level information for managing zone resources (zone open and
closed counters) as well as each zone condition and write pointer
position. Commit 35bc10b2eafb ("null_blk: synchronization fix for
zoned device") introduced a spinlock to implement this serialization.
However, when memory backing is also enabled, GFP_NOIO memory
allocations are executed under the spinlock, resulting in might_sleep()
warnings. Furthermore, the zone_lock spinlock is locked/unlocked using
spin_lock_irq/spin_unlock_irq, similarly to the memory backing code with
the nullb->lock spinlock. This nested use of irq locks wrecks the irq
enabled/disabled state.

Fix all this by introducing a bitmap for per-zone lock, with locking
implemented using wait_on_bit_lock_io() and clear_and_wake_up_bit().
This locking mechanism allows keeping a zone locked while executing
null_process_cmd(), serializing all operations to the zone while
allowing to sleep during memory backing allocation with GFP_NOIO.
Device level zone resource management information is protected using
a spinlock which is not held while executing null_process_cmd();

Fixes: 35bc10b2eafb ("null_blk: synchronization fix for zoned device")
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/null_blk.h
drivers/block/null_blk_zoned.c