All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dm: core: put device mapper block device synchronously
@ 2024-04-16  0:56 Ming Lei
  2024-04-16 15:28 ` [PATCH v2] dm: restore synchronous close of device mapper block device Mike Snitzer
  0 siblings, 1 reply; 5+ messages in thread
From: Ming Lei @ 2024-04-16  0:56 UTC (permalink / raw)
  To: Mike Snitzer, dm-devel
  Cc: linux-block, linux-fsdevel, Ming Lei, Zhong Changhui,
	Christian Brauner, Jan Kara

'dmsetup remove_all' actually depends on sync bdev release since
dm_lock_for_deletion() may return -EBUSY if the open count is > 0, and the
open count is dropped in dm_blk_close().

So if dm_blk_close() is delayed because of fput(), this device mapper
device is skipped in remove_all, and cause regression.

Fix the issue by using __fput_sync().

Reported-by: Zhong Changhui <czhong@redhat.com>
Fixes: a28d893eb327 ("md: port block device access to file")
Suggested-by: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/md/dm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 56aa2a8b9d71..93f3d28b0f03 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -765,7 +765,7 @@ static struct table_device *open_table_device(struct mapped_device *md,
 	return td;
 
 out_blkdev_put:
-	fput(bdev_file);
+	__fput_sync(bdev_file);
 out_free_td:
 	kfree(td);
 	return ERR_PTR(r);
@@ -778,7 +778,7 @@ static void close_table_device(struct table_device *td, struct mapped_device *md
 {
 	if (md->disk->slave_dir)
 		bd_unlink_disk_holder(td->dm_dev.bdev, md->disk);
-	fput(td->dm_dev.bdev_file);
+	__fput_sync(td->dm_dev.bdev_file);
 	put_dax(td->dm_dev.dax_dev);
 	list_del(&td->list);
 	kfree(td);
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] dm: restore synchronous close of device mapper block device
  2024-04-16  0:56 [PATCH] dm: core: put device mapper block device synchronously Ming Lei
@ 2024-04-16 15:28 ` Mike Snitzer
  2024-04-17  1:32   ` Ming Lei
  2024-04-18  2:31   ` Changhui Zhong
  0 siblings, 2 replies; 5+ messages in thread
From: Mike Snitzer @ 2024-04-16 15:28 UTC (permalink / raw)
  To: ming.lei
  Cc: brauner, czhong, dm-devel, jack, linux-block, linux-fsdevel,
	Mike Snitzer

From: Ming Lei <ming.lei@redhat.com>

'dmsetup remove' and 'dmsetup remove_all' require synchronous bdev
release. Otherwise dm_lock_for_deletion() may return -EBUSY if the open
count is > 0, because the open count is dropped in dm_blk_close()
which occurs after fput() completes.

So if dm_blk_close() is delayed because of asynchronous fput(), this
device mapper device is skipped during remove, which is a regression.

Fix the issue by using __fput_sync().

Also: DM device removal has long supported being made asynchronous by
setting the DMF_DEFERRED_REMOVE flag on the DM device. So leverage
using async fput() in close_table_device() if DMF_DEFERRED_REMOVE flag
is set.

Reported-by: Zhong Changhui <czhong@redhat.com>
Fixes: a28d893eb327 ("md: port block device access to file")
Suggested-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
[snitzer: editted commit header, use fput() if DMF_DEFERRED_REMOVE set]
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
---
 drivers/md/dm.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 56aa2a8b9d71..7d0746b37c8e 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -765,7 +765,7 @@ static struct table_device *open_table_device(struct mapped_device *md,
 	return td;
 
 out_blkdev_put:
-	fput(bdev_file);
+	__fput_sync(bdev_file);
 out_free_td:
 	kfree(td);
 	return ERR_PTR(r);
@@ -778,7 +778,13 @@ static void close_table_device(struct table_device *td, struct mapped_device *md
 {
 	if (md->disk->slave_dir)
 		bd_unlink_disk_holder(td->dm_dev.bdev, md->disk);
-	fput(td->dm_dev.bdev_file);
+
+	/* Leverage async fput() if DMF_DEFERRED_REMOVE set */
+	if (unlikely(test_bit(DMF_DEFERRED_REMOVE, &md->flags)))
+		fput(td->dm_dev.bdev_file);
+	else
+		__fput_sync(td->dm_dev.bdev_file);
+
 	put_dax(td->dm_dev.dax_dev);
 	list_del(&td->list);
 	kfree(td);
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] dm: restore synchronous close of device mapper block device
  2024-04-16 15:28 ` [PATCH v2] dm: restore synchronous close of device mapper block device Mike Snitzer
@ 2024-04-17  1:32   ` Ming Lei
  2024-04-17  3:27     ` Mike Snitzer
  2024-04-18  2:31   ` Changhui Zhong
  1 sibling, 1 reply; 5+ messages in thread
From: Ming Lei @ 2024-04-17  1:32 UTC (permalink / raw)
  To: Mike Snitzer; +Cc: brauner, czhong, dm-devel, jack, linux-block, linux-fsdevel

On Tue, Apr 16, 2024 at 11:28:42AM -0400, Mike Snitzer wrote:
> From: Ming Lei <ming.lei@redhat.com>
> 
> 'dmsetup remove' and 'dmsetup remove_all' require synchronous bdev
> release. Otherwise dm_lock_for_deletion() may return -EBUSY if the open
> count is > 0, because the open count is dropped in dm_blk_close()
> which occurs after fput() completes.
> 
> So if dm_blk_close() is delayed because of asynchronous fput(), this
> device mapper device is skipped during remove, which is a regression.
> 
> Fix the issue by using __fput_sync().
> 
> Also: DM device removal has long supported being made asynchronous by
> setting the DMF_DEFERRED_REMOVE flag on the DM device. So leverage
> using async fput() in close_table_device() if DMF_DEFERRED_REMOVE flag
> is set.

IMO, this way isn't necessary, because the patch is one bug fix, and we are
supposed to recover into exact previous behavior before commit a28d893eb327
("md: port block device access to file") for minimizing regression risk.

But the extra change seems work.


thanks, 
Ming


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] dm: restore synchronous close of device mapper block device
  2024-04-17  1:32   ` Ming Lei
@ 2024-04-17  3:27     ` Mike Snitzer
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Snitzer @ 2024-04-17  3:27 UTC (permalink / raw)
  To: Ming Lei; +Cc: brauner, czhong, dm-devel, jack, linux-block, linux-fsdevel

On Wed, Apr 17, 2024 at 09:32:55AM +0800, Ming Lei wrote:
> On Tue, Apr 16, 2024 at 11:28:42AM -0400, Mike Snitzer wrote:
> > From: Ming Lei <ming.lei@redhat.com>
> > 
> > 'dmsetup remove' and 'dmsetup remove_all' require synchronous bdev
> > release. Otherwise dm_lock_for_deletion() may return -EBUSY if the open
> > count is > 0, because the open count is dropped in dm_blk_close()
> > which occurs after fput() completes.
> > 
> > So if dm_blk_close() is delayed because of asynchronous fput(), this
> > device mapper device is skipped during remove, which is a regression.
> > 
> > Fix the issue by using __fput_sync().
> > 
> > Also: DM device removal has long supported being made asynchronous by
> > setting the DMF_DEFERRED_REMOVE flag on the DM device. So leverage
> > using async fput() in close_table_device() if DMF_DEFERRED_REMOVE flag
> > is set.
> 
> IMO, this way isn't necessary, because the patch is one bug fix, and we are
> supposed to recover into exact previous behavior before commit a28d893eb327
> ("md: port block device access to file") for minimizing regression risk.
> 
> But the extra change seems work.

I normally would agree but I see no real reason to avoid leveraging
async fput() for the async DM device removal use-case ;)

Mike

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] dm: restore synchronous close of device mapper block device
  2024-04-16 15:28 ` [PATCH v2] dm: restore synchronous close of device mapper block device Mike Snitzer
  2024-04-17  1:32   ` Ming Lei
@ 2024-04-18  2:31   ` Changhui Zhong
  1 sibling, 0 replies; 5+ messages in thread
From: Changhui Zhong @ 2024-04-18  2:31 UTC (permalink / raw)
  To: Mike Snitzer
  Cc: ming.lei, brauner, dm-devel, jack, linux-block, linux-fsdevel

On Tue, Apr 16, 2024 at 11:29 PM Mike Snitzer <snitzer@kernel.org> wrote:
>
> From: Ming Lei <ming.lei@redhat.com>
>
> 'dmsetup remove' and 'dmsetup remove_all' require synchronous bdev
> release. Otherwise dm_lock_for_deletion() may return -EBUSY if the open
> count is > 0, because the open count is dropped in dm_blk_close()
> which occurs after fput() completes.
>
> So if dm_blk_close() is delayed because of asynchronous fput(), this
> device mapper device is skipped during remove, which is a regression.
>
> Fix the issue by using __fput_sync().
>
> Also: DM device removal has long supported being made asynchronous by
> setting the DMF_DEFERRED_REMOVE flag on the DM device. So leverage
> using async fput() in close_table_device() if DMF_DEFERRED_REMOVE flag
> is set.
>
> Reported-by: Zhong Changhui <czhong@redhat.com>
> Fixes: a28d893eb327 ("md: port block device access to file")
> Suggested-by: Christian Brauner <brauner@kernel.org>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> [snitzer: editted commit header, use fput() if DMF_DEFERRED_REMOVE set]
> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
> ---
>  drivers/md/dm.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/md/dm.c b/drivers/md/dm.c
> index 56aa2a8b9d71..7d0746b37c8e 100644
> --- a/drivers/md/dm.c
> +++ b/drivers/md/dm.c
> @@ -765,7 +765,7 @@ static struct table_device *open_table_device(struct mapped_device *md,
>         return td;
>
>  out_blkdev_put:
> -       fput(bdev_file);
> +       __fput_sync(bdev_file);
>  out_free_td:
>         kfree(td);
>         return ERR_PTR(r);
> @@ -778,7 +778,13 @@ static void close_table_device(struct table_device *td, struct mapped_device *md
>  {
>         if (md->disk->slave_dir)
>                 bd_unlink_disk_holder(td->dm_dev.bdev, md->disk);
> -       fput(td->dm_dev.bdev_file);
> +
> +       /* Leverage async fput() if DMF_DEFERRED_REMOVE set */
> +       if (unlikely(test_bit(DMF_DEFERRED_REMOVE, &md->flags)))
> +               fput(td->dm_dev.bdev_file);
> +       else
> +               __fput_sync(td->dm_dev.bdev_file);
> +
>         put_dax(td->dm_dev.dax_dev);
>         list_del(&td->list);
>         kfree(td);
> --
> 2.40.0
>

I tried to apply this patch and looks this issue has solved by this patch


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-18  2:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-16  0:56 [PATCH] dm: core: put device mapper block device synchronously Ming Lei
2024-04-16 15:28 ` [PATCH v2] dm: restore synchronous close of device mapper block device Mike Snitzer
2024-04-17  1:32   ` Ming Lei
2024-04-17  3:27     ` Mike Snitzer
2024-04-18  2:31   ` Changhui Zhong

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.