From: Bart Van Assche <bvanassche@acm.org>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
Jens Axboe <axboe@kernel.dk>, Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Brian Foster <bfoster@redhat.com>,
Damien Le Moal <dlemoal@kernel.org>,
Hillf Danton <hdanton@sina.com>,
Markus Elfring <Markus.Elfring@web.de>,
Ming Lei <tom.leiming@gmail.com>, Qu Wenruo <wqu@suse.com>,
Tao Cui <cui.tao@linux.dev>, kernel test robot <lkp@intel.com>,
linux-block <linux-block@vger.kernel.org>,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH 2/2] loop: Perform __loop_clr_fd() after disk->open_mutex is dropped.
Date: Tue, 15 Sep 2026 10:36:25 -0700 [thread overview]
Message-ID: <e8fd7e8c-4a14-49d6-8bce-16fd44d864b9@acm.org> (raw)
In-Reply-To: <6fdefda9-c7e4-4368-8d9a-280043b4051e@I-love.SAKURA.ne.jp>
On 9/11/26 6:22 PM, Tetsuo Handa wrote:
> On 2026/09/12 10:02, Bart Van Assche wrote:
>> On 9/11/26 3:18 PM, Tetsuo Handa wrote:
>>> On 2026/09/12 5:03, Bart Van Assche wrote:
>>>> On 9/10/26 2:44 AM, Tetsuo Handa wrote:
>>>>> On 2026/09/10 4:33, Bart Van Assche wrote:
>>>>>> __loop_clr_fd() is queued from the lo_post_release() callback and hence
>>>>>> may be called concurrently with or after another thread has called
>>>>>> bdev_open(). Hence, lo->lo->state should be checked instead of assuming
>>>>>> that it equals Lo_rundown.
>>>>>
>>>>> No, __loop_clr_fd() is queued from the lo_release() callback.
>>>>
>>>> Yes, it is *queued* from the lo_release() callback function but there is
>>>> no guarantee that __loop_clr_fd() has started before bdev_open() is
>>>> called again.
>>>
>>> Since lo->lo_state was set to Lo_rundown by lo_release(), lo_open() will return -ENXIO.
>>> What can go wrong if bdev_open() is called again before __loop_clr_fd() starts?
>>
>> This breaks LO_FLAGS_AUTOCLEAR, isn't it?
>
> Why do you think so?
>
> App1 App2 system_long_wq
> Calls lo_release().
> Schedules __loop_clr_fd().
> Calls lo_open() but fails with -ENXIO.
> Starts __loop_clr_fd().
> Calls lo_post_release().
> Starts waiting for completion of __loop_clr_fd().
> Finishes __loop_clr_fd().
> Finishes waiting for completion of __loop_clr_fd().
>
> Calls lo_open() again and succeeds.
> Calls lo_open() again and succeeds.
>
> App1's open() after close() is succeeding.
> App2's open() being temporarily failing with -ENXIO should be acceptable.
> If App2 wants to avoid repeatedly failing with -ENXIO, App2 should use
> ioctl(LOOP_CTL_GET_FREE) before open().
Userspace applications and tests (such as mount/umount, losetup,
systemd, and xfstests) expect that:
1. Teardown of a loop device with LO_FLAGS_AUTOCLEAR completes
synchronously during the final close() (in lo_release()), releasing
the backing file references (fput()).
2. Calling open() immediately after close() succeeds (allowing the loop
device to be immediately reallocated, reopened, or configured in
Lo_unbound state).
There is evidence of this in the history of drivers/block/loop.c:
* The Asynchronous Autoclear Regression & Revert (Commits 322c4293ecc5
and bf23747ee053) In December 2021, commit 322c4293ecc5
("loop: make autoclear operation asynchronous") attempted to break a
circular lock dependency by offloading autoclear (__loop_clr_fd())
from lo_release() to a workqueue (system_long_wq).
* In February 2022, commit bf23747ee053 ("loop: revert 'make autoclear
operation asynchronous'") had to revert that change after xfstests
broke. The commit message explicitly states:
"The kernel test robot is reporting that xfstest which does
umount ext2 on xfs
umount xfs
sequence started failing, for commit 322c4293ecc58110 ("loop: make
autoclear operation asynchronous") removed a guarantee that fput() of
backing file is processed before lo_release() from close() returns to
user mode."
When autoclear was asynchronous, close() returned before the device
was unbound and before the backing file was released, breaking
immediate reuse and subsequent filesystem unmounts.
Bart.
next prev parent reply other threads:[~2026-09-15 17:36 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 10:48 [PATCH 1/2] block: Add post_release() operation Tetsuo Handa
2026-09-09 10:49 ` [PATCH 2/2] loop: Perform __loop_clr_fd() after disk->open_mutex is dropped Tetsuo Handa
2026-09-09 19:33 ` Bart Van Assche
2026-09-10 9:44 ` Tetsuo Handa
2026-09-11 20:03 ` Bart Van Assche
2026-09-11 22:18 ` Tetsuo Handa
2026-09-12 1:02 ` Bart Van Assche
2026-09-12 1:22 ` Tetsuo Handa
2026-09-15 17:36 ` Bart Van Assche [this message]
2026-09-15 22:38 ` Tetsuo Handa
2026-09-17 22:18 ` Tetsuo Handa
2026-09-18 0:59 ` Bart Van Assche
2026-09-10 11:53 ` [PATCH 1/2] block: Add post_release() operation Gary Guo
2026-09-10 12:14 ` Tetsuo Handa
2026-09-11 19:54 ` Bart Van Assche
2026-09-11 22:34 ` Tetsuo Handa
2026-09-12 0:31 ` Bart Van Assche
2026-09-12 1:43 ` Tetsuo Handa
-- strict thread matches above, loose matches on Subject: below --
2026-09-16 19:51 [PATCH 0/2] loop: Fix teardown Bart Van Assche
2026-09-16 19:51 ` [PATCH 2/2] loop: Perform __loop_clr_fd() after disk->open_mutex is dropped Bart Van Assche
2026-09-16 22:47 ` Tetsuo Handa
2026-09-16 23:05 ` Bart Van Assche
2026-09-17 0:16 ` Tetsuo Handa
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=e8fd7e8c-4a14-49d6-8bce-16fd44d864b9@acm.org \
--to=bvanassche@acm.org \
--cc=Markus.Elfring@web.de \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=bfoster@redhat.com \
--cc=cui.tao@linux.dev \
--cc=dlemoal@kernel.org \
--cc=hch@lst.de \
--cc=hdanton@sina.com \
--cc=linux-block@vger.kernel.org \
--cc=lkp@intel.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=rust-for-linux@vger.kernel.org \
--cc=tom.leiming@gmail.com \
--cc=viro@zeniv.linux.org.uk \
--cc=wqu@suse.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