Re: [PATCH v7] loop: defer the queue limits clear to a workqueue

From: Tao Cui

Date: Wed Nov 25 2026 - 21:09:35 EST


Hello, Bart,

在 2026/11/25 00:56, Bart Van Assche 写道:
> On 11/24/26 12:10 AM, Tao Cui wrote:
>> For v8, my plan is to stop deciding whether to quiet a request at
>> queue_rq() time and instead quiet repeated failures at the point of
>> failure. The verdicts remain recorded for the lifetime of the backing
>> file and are cleared only on rebind or unbind. loop_clear_limits()
>> reports whether a verdict is new, and repeated failures mark only
>> their own request quiet. That guarantees the first failure for each
>> mode is reported, regardless of how dispatch and queue freezing
>> interleave.
>>
>> [ ... ]
>>
>> Does this approach look reasonable to you? If so, I'll send the
>> already tested patch as v8.
>
> That approach sounds reasonable to me. If the verdicts are kept for the
> lifetime of the backing file, I think the following simplifications are
> possible:
> - The clear_limits_pending member variable is no longer needed. The
>   work function can read the mask with the unsupported modes without
>   resetting it.
> - lo_fallocate() can return -EOPNOTSUPP without calling
>   file->f_op->fallocate() if the mode is already known to be
>   unsupported.
>
Thanks. v8 follows with all of this addressed.

Both are in: the work item reads the mask without resetting it, and
lo_fallocate() skips the fallocate probe when the mode is already
known to be unsupported.

> Tracking the verdicts per mode also fixes the following issue in v7:
> clear_limits_pending is not per mode, so a failed discard suppresses
> the error message for the first write-zeroes failure.
>
Right. The verdicts are per mode and stay recorded for the lifetime
of the backing file, so a failed discard no longer suppresses the
first write-zeroes report.
> A few more comments about v7 that also apply to v8:
> - loop_clear_limits() calls schedule_work() after clear_limits_lock has
>   been unlocked. Can a request that passed the lo->lo_backing_file
>   check queue the work item after cancel_work_sync() has been called
>   by __loop_clr_fd() or loop_remove()? Since lo_free_disk() no longer
>   cancels the work item, I think that would result in a use-after-free.
>   How about calling schedule_work() while holding clear_limits_lock and
>   resetting the state before calling cancel_work_sync() in
>   __loop_clr_fd()?
v8 does exactly that: schedule_work() now happens while
clear_limits_lock is held, and __loop_clr_fd() resets the verdicts
before calling cancel_work_sync(). A verdict that passes the
backing-file check queues the work item before the lock is released,
so the reset is ordered after any pending schedule and
cancel_work_sync() cannot miss it. loop_remove() needs no
reordering: after __loop_clr_fd() has reset the verdicts no further
schedule can happen, so its cancel stays as the backstop it already
was.

> - The code that resets clear_limits_mode occurs three times. Please
>   introduce a helper function. Is the reset in
>   loop_assign_backing_file() needed since __loop_clr_fd() already
>   resets the state and since loop_clear_limits() ignores failures for
>   a backing file that is no longer current?
I dropped the reset in loop_assign_backing_file() instead of moving
it: since d4fabede1da0 ("loop: remove support for swapping loop fds")
its only caller is loop_configure(), which requires an unbound device,
so the verdicts are always zero there. That leaves __loop_clr_fd()
as the only reset site, so there is no helper to add anymore.

> - The work function freezes the queue and commits the queue limits even
>   if no mode has been recorded. Please return early in that case.
> - The changelog for v7 is missing. Please include a "Changes since v7"
>   and a "Changes since v6" section in v8.
>
Both done: the work item returns early when the verdicts are already
reset, and the changelog has both "Changes since v6" and "Changes
since v7" sections.

Re-tested after these changes: a concurrency sweep at 2, 4, 8, 16 and
32 threads logs exactly one error per run, whereas v7 starts reporting
duplicate errors at eight threads. Sixty rounds of mkfs-kill/unbind
stress also completed without warnings.

Thanks,
Tao.

> Thanks,
>
> Bart.