diff options
author | Jan Kara <jack@suse.cz> | 2017-03-23 01:37:00 +0100 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2017-03-22 20:11:33 -0600 |
commit | f759741d9d913eb57784a94b9bca78b376fc26a9 (patch) | |
tree | 19832434e2c4c1db34bceee048f422b910300686 /fs/block_dev.c | |
parent | b1c51afc00f164457e126dcfc946fdd563948d26 (diff) | |
download | linux-f759741d9d913eb57784a94b9bca78b376fc26a9.tar.gz linux-f759741d9d913eb57784a94b9bca78b376fc26a9.tar.bz2 linux-f759741d9d913eb57784a94b9bca78b376fc26a9.zip |
block: Fix oops in locked_inode_to_wb_and_lock_list()
When block device is closed, we call inode_detach_wb() in __blkdev_put()
which sets inode->i_wb to NULL. That is contrary to expectations that
inode->i_wb stays valid once set during the whole inode's lifetime and
leads to oops in wb_get() in locked_inode_to_wb_and_lock_list() because
inode_to_wb() returned NULL.
The reason why we called inode_detach_wb() is not valid anymore though.
BDI is guaranteed to stay along until we call bdi_put() from
bdev_evict_inode() so we can postpone calling inode_detach_wb() to that
moment.
Also add a warning to catch if someone uses inode_detach_wb() in a
dangerous way.
Reported-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'fs/block_dev.c')
-rw-r--r-- | fs/block_dev.c | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c index 53e2389ae4d4..f2d59f143ef4 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -885,6 +885,8 @@ static void bdev_evict_inode(struct inode *inode) spin_lock(&bdev_lock); list_del_init(&bdev->bd_list); spin_unlock(&bdev_lock); + /* Detach inode from wb early as bdi_put() may free bdi->wb */ + inode_detach_wb(inode); if (bdev->bd_bdi != &noop_backing_dev_info) { bdi_put(bdev->bd_bdi); bdev->bd_bdi = &noop_backing_dev_info; @@ -1875,12 +1877,6 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) kill_bdev(bdev); bdev_write_inode(bdev); - /* - * Detaching bdev inode from its wb in __destroy_inode() - * is too late: the queue which embeds its bdi (along with - * root wb) can be gone as soon as we put_disk() below. - */ - inode_detach_wb(bdev->bd_inode); } if (bdev->bd_contains == bdev) { if (disk->fops->release) |