Linux block layer
 help / color / mirror / Atom feed
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: Wed, 9 Sep 2026 12:33:17 -0700	[thread overview]
Message-ID: <3883b05e-0a34-43f7-b2a9-a46d2b0c5ffc@acm.org> (raw)
In-Reply-To: <9f1273a7-6dfe-46bb-966f-fe08876f4375@I-love.SAKURA.ne.jp>

On 9/9/26 3:49 AM, Tetsuo Handa wrote:
> -static void __loop_clr_fd(struct loop_device *lo)
> +static void __loop_clr_fd(struct work_struct *work)
>   {
> +	struct loop_device *lo = container_of(work, struct loop_device, lo_clr_work);
> +	struct gendisk *disk = lo->lo_disk;
>   	struct queue_limits lim;
>   	struct file *filp;
>   	gfp_t gfp = lo->old_gfp_mask;
>   	int err;
>   
> +	/* Step 1: Flush all outstanding I/O, without open_mutex held. */
> +	/*
> +	 * Since loop_queue_rq() is called with RCU read lock, this synchronize_rcu()
> +	 * makes sure that no more queue_work() calls are made from loop_queue_work()
> +	 * from loop_queue_rq(). Subsequent loop_queue_rq() calls which are made after
> +	 * this synchronize_rcu() returned shall see lo->lo_state != Lo_bound and
> +	 * return with BLK_STS_IOERR.
> +	 */
> +	synchronize_rcu();
> +	/*
> +	 * This drain_workqueue() makes sure that no more loop_handle_cmd() calls are
> +	 * made from loop_process_work() from loop_workfn()/loop_rootcg_workfn().
> +	 */
> +	drain_workqueue(lo->workqueue);
> +	/*
> +	 * This blk_mq_freeze_queue() waits for completion of all outstanding I/O
> +	 * which has been scheduled via loop_queue_rq(), by waiting for q_usage_counter
> +	 * to reach 0. Since the lo->lo_state != Lo_bound check in loop_queue_rq()
> +	 * guarantees that no more new I/O requests are made, we can call
> +	 * blk_mq_unfreeze_queue() immediately after blk_mq_freeze_queue() returns.
> +	 */
> +	blk_mq_unfreeze_queue(lo->lo_queue, blk_mq_freeze_queue(lo->lo_queue));
> +
> +	/* Step 2: Perform remaining cleanup, with open_mutex held. */
> +	mutex_lock(&disk->open_mutex);
> +	WARN_ON_ONCE(lo->lo_state != Lo_rundown);
__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.

Thanks,

Bart.

  reply	other threads:[~2026-09-09 19:33 UTC|newest]

Thread overview: 14+ 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 [this message]
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-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

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=3883b05e-0a34-43f7-b2a9-a46d2b0c5ffc@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