All of lore.kernel.org
 help / color / mirror / Atom feed
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
Subject: Re: [PATCH] loop: defer the queue limits clear to a workqueue
Date: Sat, 26 Sep 2026 19:20:57 +0800	[thread overview]
Message-ID: <3c89b96c-29f6-4e9c-bbd0-4c5866636261@linux.dev> (raw)
In-Reply-To: <bcf71ef1-427f-47ff-9880-c87ef0654259@acm.org>

Hi Bart,

在 2026/9/26 00:22, Bart Van Assche 写道:
> On 9/24/26 6:29 PM, Tao Cui wrote:
>> 在 2026/9/25 02:01, Bart Van Assche 写道:
>>> On 9/24/26 3:20 AM, Tao Cui wrote:
>>>>        queue_limits_commit_update(lo->lo_queue, &lim);
>>>> +    mutex_unlock(&lo->clear_limits_lock);
>>>
>>> Since the mutex_lock(&lo->clear_limits_lock) call occurs after
>>> queue_limits_start_update(), please move the
>>> mutex_unlock(&lo->clear_limits_lock) call above the
>>> queue_limits_commit_update() call. This has no impact on
>>> correctness nor on the lock nesting order but makes the code
>>> easier to follow.
>>>
>>
>> On moving mutex_unlock() above queue_limits_commit_update(): with
>> the generation counters removed, the mutex is what keeps consuming
>> clear_limits_mode and committing the resulting queue limits atomic
>> with respect to a rebind. blk_mq_freeze_queue() is
>> reference-counted, so the workfn and loop_change_fd() can both hold
>> a freeze concurrently. If the workfn drops the mutex after consuming
>> a non-zero mode but before queue_limits_commit_update(),
>> loop_change_fd() could install a new backing file in that window,
>> and the pending clear would then be committed to the new file. Since
>> loop_change_fd() does not recompute the queue limits afterward, the
>> incorrectly cleared discard limits would persist until the next
>> reconfiguration.
>>
>> For that reason, I'd prefer to keep the mutex held until after
>> queue_limits_commit_update(). I can add a comment explaining this if
>> that would help.
> 
> This seems fragile to me. Can this race be solved by calling
> cancel_work_sync(&lo->clear_limits_work) before the backing file is
> changed?
> 

I looked into this, and that works. The freeze in loop_change_fd()
first drains all in-flight requests, so once it returns no further
clear_limits_work can be queued from the old backing file. Calling
cancel_work_sync() immediately afterwards ensures that any already
queued or running work has finished before the backing file
changes. I'll do the same in __loop_clr_fd().

With that, the mutex only protects clear_limits_mode, and
mutex_unlock() can move back above queue_limits_commit_update().
I'll send v6 with the generation counters removed and
mutex_unlock() moved above queue_limits_commit_update().

Thanks,
Tao.

> Thanks,
> 
> Bart.


  reply	other threads:[~2026-09-26 11:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 10:20 [PATCH] loop: defer the queue limits clear to a workqueue Tao Cui
2026-09-24 10:32 ` Tao Cui
2026-09-24 18:01 ` Bart Van Assche
2026-09-25  1:29   ` Tao Cui
2026-09-25 16:22     ` Bart Van Assche
2026-09-26 11:20       ` Tao Cui [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-08-28  7:20 Tao Cui
2026-08-28 16:34 ` Bart Van Assche
2026-08-31 13:34   ` Tao Cui
2026-08-31 16:25 ` Bart Van Assche
2026-09-01 13:14   ` Tao Cui
2026-09-01 17:29 ` Bart Van Assche

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=3c89b96c-29f6-4e9c-bbd0-4c5866636261@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 \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.