All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Tetsuo Handa" <penguin-kernel@I-love.SAKURA.ne.jp>,
	"Bart Van Assche" <bvanassche@acm.org>,
	"Jens Axboe" <axboe@kernel.dk>, "Christoph Hellwig" <hch@lst.de>,
	"Jan Kara" <jack@suse.cz>,
	"linux-block" <linux-block@vger.kernel.org>
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>,
	<rust-for-linux@vger.kernel.org>,
	"Linus Torvalds" <torvalds@linux-foundation.org>,
	"Nilay Shroff" <nilay@linux.ibm.com>
Subject: Re: [PATCH v5 1/2] block: Add post_release() operation
Date: Wed, 23 Sep 2026 19:38:09 +0100	[thread overview]
Message-ID: <DLMWXEJS130L.2WSB0G2YD3LY7@garyguo.net> (raw)
In-Reply-To: <69960302-1535-441a-be4e-d652766d65c2@I-love.SAKURA.ne.jp>

On Wed Sep 23, 2026 at 6:09 AM BST, Tetsuo Handa wrote:
> Add post_release() block device operation which provides a hook for
> performing synchronous cleanup without disk->open_mutex held, which is
> needed by the loop devices.
>
> Real-world container engines, test suites, and system utilities rely on
> fput() from __loop_clr_fd() being completed when lo_release() returns.
> But changes which went to the v7.1 merge window broke an assumption that
> there is no outstanding I/O when __loop_clr_fd() is called, causing NULL
> pointer dereference problem in lo_rw_aio().
>
> In order to fix this regression, we want to allow __loop_clr_fd() to flush
> outstanding I/O. But calling drain_workqueue() from __loop_clr_fd() with
> disk->open_mutex held causes lockdep warnings. We need a mechanism which
> can flush outstanding I/O without disk->open_mutex held.
>
> But deferring __loop_clr_fd() to WQ context has a problem that there is no
> way to wait for completion of __loop_clr_fd() before the calling thread
> returns to the userspace, for there is no hook for calling flush_work().
> Despite what LO_FLAGS_AUTOCLEAR can guarantee is to clear backing device
> "eventually" after the last thread called lo_release(), abovementioned
> programs are expecting "synchronously" when a thread who is going to call
> umount() or open() as soon as returning from close() called close().
> That is an unsatisfiable expectation because the former is an objective
> behavior and the latter is a subjective dependency. Nonetheless, we need
> to try to wait for completion of __loop_clr_fd() at best-effort basis.
>
> Also, since __loop_clr_fd() calls module_put(THIS_MODULE) and there is no
> API for waiting for completion of remote thread's task work context,
> deferring __loop_clr_fd() to task work context has a problem (aside from
> task_work_add() being not exported to loadable modules) that module unload
> operation can unmap code/data segment before __loop_clr_fd() completes.
>
> Therefore, allow the loop driver to safely know completion of
> __loop_clr_fd(), by adding a hook which is called after disk->open_mutex
> is released.
>
> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
> ---
> Changes in v5:
>   Since Bart Van Assche commented that post_release() is more clear
>   and more descriptive than run_todo(), renamed run_todo() back to
>   post_release(), and make it be called only if release() was called.
>
>  block/bdev.c                     | 28 +++++++++++++++++++---------
>  include/linux/blkdev.h           | 10 ++++++++++
>  rust/kernel/block/mq/gen_disk.rs |  1 +
>  3 files changed, 30 insertions(+), 9 deletions(-)
>
> diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs
> index fc97dd873974..2ff77ef49781 100644
> --- a/rust/kernel/block/mq/gen_disk.rs
> +++ b/rust/kernel/block/mq/gen_disk.rs
> @@ -129,6 +129,7 @@ pub fn build<T: Operations>(
>              submit_bio: None,
>              open: None,
>              release: None,
> +            post_release: None,
>              ioctl: None,
>              compat_ioctl: None,
>              check_events: None,

Ideally we'd use

    ..pin_init::zeroed()

At the end of the struct expression to zero out all other fields instead of
manually zeroing each single field.

This is pre-existing issue though, so leaving as is is also fine.

Best,
Gary

  parent reply	other threads:[~2026-09-23 18:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23  5:09 [PATCH v5 1/2] block: Add post_release() operation Tetsuo Handa
2026-09-23  5:10 ` [PATCH v5 2/2] loop: Perform __loop_clr_fd() from post_release callback Tetsuo Handa
2026-09-23 17:16   ` Bart Van Assche
2026-09-23 17:14 ` [PATCH v5 1/2] block: Add post_release() operation Bart Van Assche
2026-09-23 18:38 ` Gary Guo [this message]
2026-09-24 13:46   ` Tetsuo Handa
2026-09-28 17:29 ` Bart Van Assche
2026-10-05  8:45   ` Christoph Hellwig
2026-10-05 14:23     ` Tetsuo Handa
2026-10-05 21:07     ` 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=DLMWXEJS130L.2WSB0G2YD3LY7@garyguo.net \
    --to=gary@garyguo.net \
    --cc=Markus.Elfring@web.de \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=bfoster@redhat.com \
    --cc=bvanassche@acm.org \
    --cc=cui.tao@linux.dev \
    --cc=dlemoal@kernel.org \
    --cc=hch@lst.de \
    --cc=hdanton@sina.com \
    --cc=jack@suse.cz \
    --cc=linux-block@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=nilay@linux.ibm.com \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tom.leiming@gmail.com \
    --cc=torvalds@linux-foundation.org \
    --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 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.