All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
	Josef Bacik <josef@toxicpanda.com>,
	Minchan Kim <minchan@kernel.org>, Nitin Gupta <ngupta@vflare.org>,
	Jan Kara <jack@suse.cz>, "Darrick J . Wong" <djwong@kernel.org>,
	Ming Lei <ming.lei@redhat.com>,
	Matteo Croce <mcroce@microsoft.com>,
	linux-block@vger.kernel.org, nbd@other.debian.org
Subject: Re: [PATCH 13/14] loop: remove lo_refcount and avoid lo_mutex in ->open / ->release
Date: Tue, 29 Mar 2022 16:49:13 +0200	[thread overview]
Message-ID: <20220329144913.GA3666@lst.de> (raw)
In-Reply-To: <6a383515-e2c0-9200-85b0-067238934b10@I-love.SAKURA.ne.jp>

On Tue, Mar 29, 2022 at 11:02:15PM +0900, Tetsuo Handa wrote:
> It seems that the loop driver was added in Linux 1.3.68, and
> 
>   if (lo->lo_refcnt > 1)
>     return -EBUSY;
> 
> check in loop_clr_fd() was there from the beginning. The intent of this
> check was unclear.

Yes.

> But now I think that current
> 
>   disk_openers(lo->lo_disk) > 1
> 
> form is there for three reasons.
> 
> (1) Avoid I/O errors when some process which opens and reads from this
>     loop device in response to uevent notification (e.g. systemd-udevd),
>     as described in commit a1ecac3b0656a682 ("loop: Make explicit loop
>     device destruction lazy"). This opener is short-lived because it is
>     likely that the file descriptor used by that process is closed soon.

Well.  With the the uevent supression in the current series there won't
be uevents until the capacity has been set to 0.  More importantly
anything that listens to theses kinds of uevents needs to be able to
deal with I/O errors like this.

> (2) Avoid I/O errors caused by underlying layer of stacked loop devices
>     (i.e. ioctl(some_loop_fd, LOOP_SET_FD, other_loop_fd)) being suddenly
>     disappeared. This opener is long-lived because this reference is
>     associated with not a file descriptor but lo->lo_backing_file.

Again, if you clear the FD expecting I/O errors is the logical consequence.
This is like saying we should work around seeing I/O errors when hot
removing a physical device.

> (3) Avoid I/O errors caused by underlying layer of mounted loop device
>     (i.e. mount(some_loop_device, some_mount_point)) being suddenly
>     disappeared. This opener is long-lived because this reference is
>     associated with not a file descriptor but mount.

Same I/O error story.  If you hot remove a nvme SSD you do expect
error in the file system.  This is a pretty clear action -> consequence
relation.

> While race in (1) might be acceptable, (2) and (3) should be checked
> racelessly. That is, make sure that __loop_clr_fd() will not run if
> loop_validate_file() succeeds, by doing refcount check with global lock
> held when explicit loop device destruction is requested.
> 
> As a result of no longer waiting for lo->lo_mutex after setting Lo_rundown,
> we can remove pointless BUG_ON(lo->lo_state != Lo_rundown) check.

I really do like this patch.  And I think based on your description that
we both agree that the disk_openers check is not needed for functional
correctness as a malicious userspace can do concurrent operations even
without the openers check.  You want a protection against "I/O errors"
when the FD is cleared on a live device, and with your patch we get
that with the disk_openers check.  I'm perfectly fine with that state
for this series as it keeps the status quo.  I just think this check
that goes all the way back is actually a really bad idea that just
provides some false security.  But that isn't something we need to
discuss here and now.

  reply	other threads:[~2022-03-29 14:49 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25  6:39 yet another approach to fix the loop lock order inversions v5 Christoph Hellwig
2022-03-25  6:39 ` [PATCH 01/14] nbd: use the correct block_device in nbd_bdev_reset Christoph Hellwig
2022-03-25  9:48   ` Jan Kara
2022-03-25  6:39 ` [PATCH 02/14] zram: cleanup reset_store Christoph Hellwig
2022-03-25  6:39 ` [PATCH 03/14] zram: cleanup zram_remove Christoph Hellwig
2022-03-25  6:39 ` [PATCH 04/14] block: add a disk_openers helper Christoph Hellwig
2022-03-25  6:39 ` [PATCH 05/14] block: turn bdev->bd_openers into an atomic_t Christoph Hellwig
2022-03-25  6:39 ` [PATCH 06/14] loop: de-duplicate the idle worker freeing code Christoph Hellwig
2022-03-25  6:39 ` [PATCH 07/14] loop: initialize the worker tracking fields once Christoph Hellwig
2022-03-25  6:39 ` [PATCH 08/14] loop: remove the racy bd_inode->i_mapping->nrpages asserts Christoph Hellwig
2022-03-25  6:39 ` [PATCH 09/14] loop: don't freeze the queue in lo_release Christoph Hellwig
2022-03-25  6:39 ` [PATCH 10/14] loop: only freeze the queue in __loop_clr_fd when needed Christoph Hellwig
2022-03-25  6:39 ` [PATCH 11/14] loop: implement ->free_disk Christoph Hellwig
2022-03-25 10:42   ` Tetsuo Handa
2022-03-25 15:10     ` Tetsuo Handa
2022-03-25  6:39 ` [PATCH 12/14] loop: suppress uevents while reconfiguring the device Christoph Hellwig
2022-03-25  9:49   ` Jan Kara
2022-03-25  6:39 ` [PATCH 13/14] loop: remove lo_refcount and avoid lo_mutex in ->open / ->release Christoph Hellwig
2022-03-26  2:52   ` Tetsuo Handa
2022-03-29  6:52     ` Christoph Hellwig
2022-03-29 13:25       ` Christoph Hellwig
2022-03-29 14:02         ` Tetsuo Handa
2022-03-29 14:49           ` Christoph Hellwig [this message]
2022-03-25  6:39 ` [PATCH 14/14] loop: don't destroy lo->workqueue in __loop_clr_fd Christoph Hellwig
2022-03-29 15:36 ` [PATCH 15/14] loop: avoid loop_validate_mutex/lo_mutex in ->release Tetsuo Handa
2022-03-30  8:14   ` Jan Kara

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=20220329144913.GA3666@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=djwong@kernel.org \
    --cc=jack@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=mcroce@microsoft.com \
    --cc=minchan@kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=nbd@other.debian.org \
    --cc=ngupta@vflare.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.