Re: [PATCH] ublk: avoid ublk_io_release() called after ublk char dev is closed
From: Ming Lei <hidden>
Date: 2025-08-25 01:51:12
On Sat, Aug 23, 2025 at 10:55 AM Ming Lei [off-list ref] wrote:
When running test_stress_04.sh, the following warning is triggered: WARNING: CPU: 1 PID: 135 at drivers/block/ublk_drv.c:1933 ublk_ch_release+0x423/0x4b0 [ublk_drv] This happens when the daemon is abruptly killed: - some references may still be held, because registering IO buffer doesn't grab ublk char device reference OR - io->task_registered_buffers won't be cleared because io buffer is released from non-daemon context For zero-copy and auto buffer register modes, I/O reference crosses syscalls, so IO reference may not be dropped naturally when ublk server is killed abruptly. However, when releasing io_uring context, it is guaranteed that the reference is dropped finally, see io_sqe_buffers_unregister() from io_ring_ctx_free(). Fix this by adding ublk_drain_io_references() that: - Waits for active I/O references dropped - Reinitializes io->ref and io->task_registered_buffers to clean state This way won't hang because releasing ublk char device doesn't depend on unregistering sqe buffers in do_exit().
Actually io_uring file close may rely on ublk char dev close, so still has hang risk, will send V2 for addressing it. Thanks,