All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org,
	Christoph Hellwig <hch@infradead.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>,
	Lekshmi Pillai <lekshmicpillai@in.ibm.com>,
	Tejun Heo <tj@kernel.org>, NeilBrown <neilb@suse.de>,
	Omar Sandoval <osandov@osandov.com>, Jan Kara <jack@suse.cz>
Subject: [PATCH 04/13] block: Move bdi_unregister() to del_gendisk()
Date: Tue, 21 Feb 2017 18:09:49 +0100	[thread overview]
Message-ID: <20170221170958.21845-5-jack@suse.cz> (raw)
In-Reply-To: <20170221170958.21845-1-jack@suse.cz>

Commit 6cd18e711dd8 "block: destroy bdi before blockdev is
unregistered." moved bdi unregistration (at that time through
bdi_destroy()) from blk_release_queue() to blk_cleanup_queue() because
it needs to happen before blk_unregister_region() call in del_gendisk()
for MD. As much as it is fine for device registration / unregistration
purposes, it does not fit our needs wrt writeback code. For those we
will need bdi_unregister() to happen after bdev_unhash_inode() so that
we are sure bdev inode is destroyed or soon to be destroyed (as soon as
last inode reference is dropped and nobody should be holding bdev inode
reference for long at this point) because bdi_unregister() may block
waiting for bdev's inode i_wb reference to be dropped and that happens
only once bdev inode gets destroyed.

Also SCSI will free up the device number from sd_remove() called through
a maze of callbacks from device_del() in __scsi_remove_device() before
blk_cleanup_queue() and thus similar races as described in 6cd18e711dd8
can happen for SCSI as well as reported by Omar [1]. Moving
bdi_unregister() to del_gendisk() fixes these problems as well since
del_gendisk() gets called from sd_remove() before freeing the device
number.

This also makes device_add_disk() (calling bdi_register_owner()) more
symmetric with del_gendisk().

[1] http://marc.info/?l=linux-block&m=148554717109098&w=2

Tested-by: Lekshmi Pillai <lekshmicpillai@in.ibm.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 block/blk-core.c | 2 --
 block/genhd.c    | 7 +++++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 47104f6a398b..9a901dcfdd5c 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -580,8 +580,6 @@ void blk_cleanup_queue(struct request_queue *q)
 		q->queue_lock = &q->__queue_lock;
 	spin_unlock_irq(lock);
 
-	bdi_unregister(q->backing_dev_info);
-
 	/* @q is and will stay empty, shutdown and put */
 	blk_put_queue(q);
 }
diff --git a/block/genhd.c b/block/genhd.c
index f6c4d4400759..68c613edb93a 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -660,6 +660,13 @@ void del_gendisk(struct gendisk *disk)
 	disk->flags &= ~GENHD_FL_UP;
 
 	sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi");
+	/*
+	 * Unregister bdi before releasing device numbers (as they can get
+	 * reused and we'd get clashes in sysfs) but after bdev inodes are
+	 * unhashed and thus will be soon destroyed as bdev inode's reference
+	 * to wb_writeback can block bdi_unregister().
+	 */
+	bdi_unregister(disk->queue->backing_dev_info);
 	blk_unregister_queue(disk);
 	blk_unregister_region(disk_devt(disk), disk->minors);
 
-- 
2.10.2

  parent reply	other threads:[~2017-02-21 17:09 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-21 17:09 [PATCH 0/13 v2] block: Fix block device shutdown related races Jan Kara
2017-02-21 17:09 ` [PATCH 01/13] block: Move bdev_unhash_inode() after invalidate_partition() Jan Kara
2017-02-21 17:09 ` [PATCH 02/13] block: Unhash also block device inode for the whole device Jan Kara
2017-02-21 17:09 ` [PATCH 03/13] block: Revalidate i_bdev reference in bd_aquire() Jan Kara
2017-02-21 17:09 ` Jan Kara [this message]
2017-02-21 19:53   ` [PATCH 04/13] block: Move bdi_unregister() to del_gendisk() Bart Van Assche
2017-02-22  8:51     ` Jan Kara
2017-02-22 17:42       ` Bart Van Assche
2017-02-21 17:09 ` [PATCH 05/13] bdi: Mark congested->bdi as internal Jan Kara
2017-02-28 16:06   ` Tejun Heo
2017-02-21 17:09 ` [PATCH 06/13] bdi: Make wb->bdi a proper reference Jan Kara
2017-02-28 16:07   ` Tejun Heo
2017-02-21 17:09 ` [PATCH 07/13] bdi: Move removal from bdi->wb_list into wb_shutdown() Jan Kara
2017-02-28 16:14   ` Tejun Heo
2017-02-21 17:09 ` [PATCH 08/13] bdi: Shutdown writeback on all cgwbs in cgwb_bdi_destroy() Jan Kara
2017-02-28 16:44   ` Tejun Heo
2017-02-21 17:09 ` [PATCH 09/13] bdi: Do not wait for cgwbs release in bdi_unregister() Jan Kara
2017-02-28 16:51   ` Tejun Heo
2017-02-21 17:09 ` [PATCH 10/13] bdi: Rename cgwb_bdi_destroy() to cgwb_bdi_unregister() Jan Kara
2017-02-28 16:51   ` Tejun Heo
2017-02-21 17:09 ` [PATCH 11/13] block: Fix oops in locked_inode_to_wb_and_lock_list() Jan Kara
2017-02-28 16:52   ` Tejun Heo
2017-02-21 17:09 ` [PATCH 12/13] kobject: Export kobject_get_unless_zero() Jan Kara
2017-02-21 19:39   ` Bart Van Assche
2017-02-21 17:09 ` [PATCH 13/13] block: Fix oops scsi_disk_get() Jan Kara
2017-02-21 19:33   ` Bart Van Assche
2017-02-21 17:19 ` [PATCH 0/13 v2] block: Fix block device shutdown related races Jan Kara
2017-02-21 18:55   ` Dan Williams
2017-02-21 17:19 ` Jens Axboe
2017-02-22 10:24   ` Jan Kara
2017-03-01  7:25     ` Omar Sandoval
2017-03-01  7:26       ` Omar Sandoval
2017-03-01 15:11         ` Jan Kara
2017-03-06 20:38           ` Omar Sandoval
2017-03-07 13:57             ` Jan Kara
2017-03-07 16:28               ` Omar Sandoval
2017-03-08 13:21                 ` Jan Kara
2017-02-28 16:54 ` Tejun Heo
2017-03-01 15:37   ` Jan Kara
2017-03-01 16:26     ` Tejun Heo

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=20170221170958.21845-5-jack@suse.cz \
    --to=jack@suse.cz \
    --cc=axboe@kernel.dk \
    --cc=bauerman@linux.vnet.ibm.com \
    --cc=dan.j.williams@intel.com \
    --cc=hch@infradead.org \
    --cc=lekshmicpillai@in.ibm.com \
    --cc=linux-block@vger.kernel.org \
    --cc=neilb@suse.de \
    --cc=osandov@osandov.com \
    --cc=tj@kernel.org \
    /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.