ublk: BATCH_IO fixes
Subsystems (3)
cover ublk: BATCH_IO fixes
Hi Jens,
The 1st two patches fix two issues found by Claude.
The 3rd patch fixes test name in test_stress_08.sh and test_stress_09.sh.
Thanks,
Ming
Ming Lei (3):
ublk: move ublk_mark_io_ready() out of __ublk_fetch()
ublk: fix canceling flag handling in batch I/O recovery
selftests: ublk: fix test name
drivers/block/ublk_drv.c | 17 +++++++++++++---- tools/testing/selftests/ublk/test_stress_08.sh | 2 +- tools/testing/selftests/ublk/test_stress_09.sh | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-)
Signature · 1 line
2.47.0
PATCH 1/3 ublk: move ublk_mark_io_ready() out of __ublk_fetch()
ublk_batch_prep_io() calls __ublk_fetch() while holding io->lock spinlock. When the last IO makes the device ready, ublk_mark_io_ready() tries to acquire ub->cancel_mutex which can sleep, causing a sleeping-while-atomic bug.
Fix by moving ublk_mark_io_ready() out of __ublk_fetch() and into the callers (ublk_fetch and ublk_batch_prep_io) after the spinlock is released.
--- drivers/block/ublk_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/block/ublk_drv.c +5 -1
@@ -3064,7 +3064,6 @@ static int __ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub,WRITE_ONCE (io->task,NULL ); else WRITE_ONCE(io->task, get_task_struct(current)); -ublk_mark_io_ready (ub, q_id);return 0 ; }
@@ -3083,6 +3082,8 @@ static int ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub, ret =__ublk_fetch (cmd, ub, io, q_id);if (!ret) ret =ublk_config_io_buf (ub, io, cmd, buf_addr,NULL ); +if (!ret) +ublk_mark_io_ready (ub, q_id);mutex_unlock (&ub->mutex);return ret; }
@@ -3484,6 +3485,9 @@ static int ublk_batch_prep_io(struct ublk_queue *ubq, io->buf = buf;ublk_io_unlock (io); +if (!ret) +ublk_mark_io_ready (data->ub, ubq->q_id); +return ret; }
Signature · 1 line
2.47.0
PATCH 2/3 ublk: fix canceling flag handling in batch I/O recovery
In reply to Ming LeiTwo issues with ubq->canceling flag handling:
1) In ublk_queue_reset_io_flags(), ubq->canceling is set outside cancel_lock, violating the locking requirement. Move it inside the spinlock-protected section.
2) In ublk_batch_unprep_io(), when rolling back after a batch prep failure, if the queue became ready during prep (which cleared canceling), the flag is not restored when the queue becomes not-ready again. This allows new requests to be queued to uninitialized IO slots.
Fix by restoring ubq->canceling = true under cancel_lock when the queue transitions from ready to not-ready during rollback.
--- drivers/block/ublk_drv.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/block/ublk_drv.c +8 -3
@@ -2806,9 +2806,9 @@ static void ublk_queue_reset_io_flags(struct ublk_queue *ubq)spin_lock (&ubq->cancel_lock);for (j =0 ; j < ubq->q_depth; j++) ubq->ios[j].flags &= ~UBLK_IO_FLAG_CANCELED ; + ubq->canceling = false;spin_unlock (&ubq->cancel_lock); ubq->fail_io = false; - ubq->canceling = false; }/* device can only be started after all IOs are ready */
@@ -3435,10 +3435,15 @@ static int ublk_batch_unprep_io(struct ublk_queue *ubq,/* * If queue was ready before this decrement, it won't be anymore, -* so we need to decrement the queue ready count too. +* so we need to decrement the queue ready count and restore the +* canceling flag to prevent new requests from being queued. */ -if (ublk_queue_ready (ubq)) +if (ublk_queue_ready (ubq)) { data->ub->nr_queue_ready--; +spin_lock (&ubq->cancel_lock); + ubq->canceling = true; +spin_unlock (&ubq->cancel_lock); + } ubq->nr_io_ready--;ublk_io_lock (io);
Signature · 1 line
2.47.0
PATCH 3/3 selftests: ublk: fix test name
In reply to Ming LeiFix the two added test name.
--- tools/testing/selftests/ublk/test_stress_08.sh | 2 +- tools/testing/selftests/ublk/test_stress_09.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/ublk/test_stress_08.sh +1 -1
@@ -2,7 +2,7 @@ # SPDX-License-Identifier: GPL-2.0 . "$(cd "$(dirname "$0")" && pwd)"/test_common.sh -TID="stress_06" +TID="stress_08" ERR_CODE=0 ublk_io_and_remove()
tools/testing/selftests/ublk/test_stress_09.sh +1 -1
@@ -2,7 +2,7 @@ # SPDX-License-Identifier: GPL-2.0 . "$(cd "$(dirname "$0")" && pwd)"/test_common.sh -TID="stress_07" +TID="stress_09" ERR_CODE=0 ublk_io_and_kill_daemon()
Signature · 1 line
2.47.0
Quoted 8 lines · Ming Lei
The 1st two patches fix two issues found by Claude.
The 3rd patch fixes test name in
test_stress_08.shandtest_stress_09.sh.Thanks,
Ming[...]
Applied, thanks!
[1/3] ublk: move ublk_mark_io_ready() out of __ublk_fetch()
commit: dbc635c4be7eba1d0e0fe0275a289ee3ccc63d72
[2/3] ublk: fix canceling flag handling in batch I/O recovery
commit: e4c4bfec2bb8db9963d87e8ccdf89cd9e485d7b6
[3/3] selftests: ublk: fix test name
commit: e4d3fc6a22f53e5bbe51e28b43cb32bc130d9f87Best regards,
Signature · 1 line
Jens Axboe