Re: [PATCH] loop: defer the queue limits clear to a workqueue
From: Bart Van Assche
Date: Fri Aug 28 2026 - 12:34:58 EST
On 8/28/26 12:20 AM, Tao Cui wrote:
loop_clear_limits() calls queue_limits_commit_update() directly fromPlease help with reviewing this patch, which seems more complete to me
the loop workqueue that processes the request. That does a
non-atomic struct assignment to q->limits without freezing the queue,
which races with lockless readers of q->limits on other CPUs - bio
splitting reads max_hw_sectors, the discard path reads
max_hw_discard_sectors - and can let them observe torn values. The
trigger is a discard or write-zeroes request on a loop device whose
backing file does not support the corresponding fallocate operation.
The code already has an XXX comment saying this should move to a
workqueue. Do that: schedule a work item on the system workqueue,
where it is safe to freeze the queue and update the limits using
queue_limits_commit_update_frozen(). Accumulate pending modes in
lo->clear_limits_mode so that failures between scheduling and
execution of the work item are not lost, and cancel the work item
before the device is freed. If the device is reconfigured to a
backing file that does support the operation in that window, the
stale clear takes effect and discard is disabled until the next
reconfiguration.
than this patch:
https://lore.kernel.org/linux-block/c2ab2547-63b3-48cf-87c1-fc53219e360a@xxxxxxxxxxxxxxxxxxx/
Thanks,
Bart.