From: Tao Cui <cui.tao@linux.dev>
To: Bart Van Assche <bvanassche@acm.org>,
axboe@kernel.dk, hch@lst.de,
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: cui.tao@linux.dev, cuitao@kylinos.cn,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Subject: Re: [PATCH v8] loop: defer the queue limits clear to a workqueue
Date: Thu, 26 Nov 2026 18:06:16 +0800 [thread overview]
Message-ID: <7ad89439-5921-4dce-8da1-7c9321930ce9@linux.dev> (raw)
In-Reply-To: <20261126054223.176824-1-cui.tao@linux.dev>
Hello, Bart,
在 2026/11/26 13:42, Tao Cui 写道:
> From: Tao Cui <cuitao@kylinos.cn>
>
> loop_clear_limits() calls queue_limits_commit_update() directly from
> 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, such
> as bio splitting reading max_hw_sectors and the discard path reading
> max_hw_discard_sectors, letting 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 around the limits update. The
> unsupported modes live under a new mutex, lo->clear_limits_lock,
> guarded by a backing-file check that drops records from a racing
> unbind or rebind. The work item is scheduled while holding that
> lock, so an unbind resets the verdicts under the lock before calling
> cancel_work_sync() and cannot miss a schedule from a request that is
> still in flight. Requests that arrive while the clear is in flight
> fail quietly, so the console report stays at the first failure.
> loop_remove() also cancels the work item before the queue becomes
> unreachable.
>
Sashiko reported three issues against v8 [1]; all are real and fixed in
v9 below, so v8 can be skipped.
> Does freezing lo->lo_queue before queue_limits_start_update() invert the
> block layer lock ordering between queue freeze and q->limits_lock?
Yes, the work item froze first. v9 takes limits_lock before freezing,
like loop_set_dio() and loop_set_block_size().
The splat and deadlock part I could not reproduce: since f1be1788a32e
("block: model freeze & enter queue as lock for supporting lockdep")
the freeze path annotates io_lockdep_map as a trylock, so the reversed
order does not become a recorded dependency, and requests never take
limits_lock so a freezing caller's drain always completes. Interleaved
LOOP_SET_BLOCK_SIZE, LOOP_SET_DIRECT_IO, write-zeroes and rebind churn
under PROVE_LOCKING stay quiet on both v8 and v9. FWIW the same
applies to loop_set_status() in my dma-alignment patch: I'll reorder it
in v2 for consistency rather than wait for a report.
> If LOOP_SET_BLOCK_SIZE is called on a bound loop device after an
> unsupported mode has been recorded in lo->clear_limits_seen, can the
> cleared queue limits end up permanently re-enabled?
Yes. v9 resets clear_limits_seen inside the recompute's freeze so the
next failure reschedules the clear.
> Can calling lo_unsupported() when !bdev_max_discard_sectors(lo->lo_device)
> falsely disable FALLOC_FL_ZERO_RANGE or latch FALLOC_FL_PUNCH_HOLE when
> discard was only disabled via sysfs?
Yes. v9 gates on the per-mode hardware limits instead of the shared
bdev_max_discard_sectors().
Tested with PROVE_LOCKING enabled: loop/011, the concurrency sweep, the
interleave and the mkfs/unbind stress run clean, v8 as a negative
control included.
Thanks,
Tao.
[1] https://sashiko.dev/#/patchset/20261126054223.176824-1-cui.tao@linux.dev
prev parent reply other threads:[~2026-11-26 10:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 5:42 [PATCH v8] loop: defer the queue limits clear to a workqueue Tao Cui
2026-11-26 10:06 ` Tao Cui [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7ad89439-5921-4dce-8da1-7c9321930ce9@linux.dev \
--to=cui.tao@linux.dev \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=cuitao@kylinos.cn \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=shinichiro.kawasaki@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox