mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Tao Cui <cui.tao@linux.dev>, Jens Axboe <axboe@kernel.dk>
Cc: Keith Busch <kbusch@kernel.org>, Jan Kara <jack@suse.cz>,
	Ming Lei <tom.leiming@gmail.com>,
	Damien Le Moal <dlemoal@kernel.org>,
	Hannes Reinecke <hare@kernel.org>,
	Zhao Gongyi <zhaogongyi@bytedance.com>,
	stable@vger.kernel.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, cuitao@kylinos.cn
Subject: Re: [PATCH] loop: fix stale dma_alignment when direct I/O is silently dropped
Date: Tue, 24 Nov 2026 08:37:51 -0800	[thread overview]
Message-ID: <207069e4-6c99-40b3-ac0c-7ffe675a0c9f@acm.org> (raw)
In-Reply-To: <96ffc97d-62bc-4a91-ae3d-9baa28ef500b@linux.dev>

On 11/24/26 2:56 AM, Tao Cui wrote:
 > I noticed the sashiko report [1].  The lock order in loop_set_status()
 > is indeed different from 06a2ff603f1f, but I think the reported
 > deadlock cannot be reached through this code.  The queue is frozen and
 > fully drained before queue_limits_start_update() takes q->limits_lock,
 > and nothing between start_update() and commit_update() blocks, so the
 > new code never waits for anything while holding the lock.

Whether or not a deadlock can be triggered, I expect lockdep to complain
about this patch. blk_mq_freeze_queue() acquires q->io_lockdep_map and
that map is only released by blk_mq_unfreeze_queue(). Hence, calling
queue_limits_start_update() between these two calls records the
dependency q_usage_counter(io) -> limits_lock. The opposite order is
already used by loop_set_dio(), loop_set_block_size() and
queue_limits_commit_update_frozen(). This is the same complaint that has
been fixed by commit 06a2ff603f1f ("loop: Fix recently introduced lock
inversion"). A lockdep complaint is a problem by itself since it
disables lockdep and hence hides later reports. Has this patch been
tested with lockdep enabled?

 > I am more worried about the suggested reorder: with start_update()
 > before blk_mq_freeze_queue(), loop_set_status() would hold limits_lock
 > while draining, and an in-flight write-zeroes request on an
 > unsupported backing file would block in loop_clear_limits() on that
 > lock while holding a queue usage counter, so the freeze would never
 > complete.

That scenario is not specific to loop_set_status(). loop_set_dio(),
loop_set_block_size() and the sysfs store methods already hold
limits_lock while freezing the queue. Making loop_set_status() follow
the same convention does not introduce a new class of problems. The
proper fix is the loop_clear_limits() rework, so please make this patch
depend on "loop: defer the queue limits clear to a workqueue" instead of
deviating from the locking convention.

 > The snapshot taken before the drain could also overwrite a concurrent
 > loop_clear_limits() commit.

I don't think that can happen. limits_lock is held from
queue_limits_start_update() until queue_limits_commit_update(), so
loop_clear_limits() cannot commit anything in between.

 > So I would like to keep the patch as it stands, but happy to discuss
 > further.

Please call queue_limits_start_update() before blk_mq_freeze_queue() in
loop_set_status() and call loop_set_dma_limit() and
queue_limits_commit_update() after loop_update_dio().

A few more comments about the patch itself:
- lo_can_use_dio() is now evaluated twice, once before the limits are
   committed and once in loop_update_dio(), and both results must agree.
   That seems fragile to me. Please consider documenting this
   requirement above loop_set_dma_limit().
- With this patch every LOOP_SET_STATUS call updates the queue limits.
   Can that be restricted to the case where LO_FLAGS_DIRECT_IO has been
   cleared?
- Please mention in the patch description that the stale limit is too
   strict rather than too permissive, in other words, that the effect is
   that O_DIRECT I/O with 512-byte aligned buffers is rejected.
- How has this patch been tested? A blktests test would be welcome.
- Please use 12 characters for the commit ID in the Fixes: tag.

Thanks,

Bart.

      reply	other threads:[~2026-11-24 16:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  9:33 Tao Cui
2026-11-24 10:56 ` Tao Cui
2026-11-24 16:37   ` Bart Van Assche [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=207069e4-6c99-40b3-ac0c-7ffe675a0c9f@acm.org \
    --to=bvanassche@acm.org \
    --cc=axboe@kernel.dk \
    --cc=cui.tao@linux.dev \
    --cc=cuitao@kylinos.cn \
    --cc=dlemoal@kernel.org \
    --cc=hare@kernel.org \
    --cc=jack@suse.cz \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tom.leiming@gmail.com \
    --cc=zhaogongyi@bytedance.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

all inboxes | Powered by JetHome®