Re: [PATCH v7] loop: defer the queue limits clear to a workqueue
From: Bart Van Assche
Date: Tue Nov 24 2026 - 11:57:01 EST
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.
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.
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()?
- 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?
- 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.
Thanks,
Bart.