Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1553935
| Path | csiph.com!weretis.net!feeder4.news.weretis.net!newsfeed.CARNet.hr!news.spin.it!bofh.it!news.nic.it!robomod |
|---|---|
| From | Dan Williams <dan.j.williams@intel.com> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] block: fix blk_get_backing_dev_info() crash, use bdev->bd_queue |
| Date | Sun, 08 Jan 2017 22:00:02 +0100 |
| Message-ID | <sXsJk-32d-5@gated-at.bofh.it> (permalink) |
| References | <sWrFE-2MO-9@gated-at.bofh.it> <sWzWy-nl-19@gated-at.bofh.it> <sWGOl-5dK-15@gated-at.bofh.it> <sXrDz-2kN-5@gated-at.bofh.it> |
| X-Original-To | Jan Kara <jack@suse.cz> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=qTazStoVdIGsjjds0uj5+/k1nqONCVdu3yp6XgObqrQ=; b=CX5Df+YfnKiFvJLBLuEBRjOMJFaXVl/ya/csawUydwwfvSADPVe/qJioKOZSmixNYz T/TED9rnglPVB+rhKuLViG3VFuoHpACFjgGdX8Vj92OmxZM8W9jul1rRiVKBlEfnbNgv 50BxRnEnUNWEOfnspOCFSEhX0+IJz0tni4tpESUtXZMKvzg981QeqMSyaj/XxykZv4zb 5WH2vPeuYITc8mhT6NhhdWAAFuDEgah1hjzIaigMBQ4c1qFVeHSfcSu9fLjxQDgV3KZX yGkZIbHbCm/cimrXoeAg0zlijnfeOdUj1Kp9yMF3p5qzcaXjcLHfUPY4F1FC3pz1I5g+ K2Gg== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=qTazStoVdIGsjjds0uj5+/k1nqONCVdu3yp6XgObqrQ=; b=IMwyBEe2v1TspkHnSJwKa+yhMGnr/3cYmjDoK9GC7OvBYoJ+Bt2dlwg+55xFe7gO/W P2nhH/nYO+bLrRgBdq7P9kR+iL3fT9BmvJyosfv2Np2ZhcBnK4MXY4QQYC2UJ17wALHI v2c7E+0iMe3ZK2Tce/4Gdh6m1UtYZ4J/0c0dYhIwX8KD8yyLfJrYn/w+3WfPxz5uV9ix QrxZVHsivxCn3ej1lyR+0sGL92NmO3Q2eTdAgg2m2+c1AhwaHmj9H81iCVyNXhcIT41C jqwC+CWhyWL1ZdweDizn9TSBvb7tm/8HkYIiekU1ooY04pLVlA7d9BseGZK6h5BrWmfU wVxA== |
| X-Gm-Message-State | AIkVDXJuSTmmSmpqCcMGBaMrKdABWPYDS1ulLh1xwaBF9acHmDfv5zv8TKZeK4C0xfb0d2OYWdi57c0PnZ0b159v |
| X-Received | by 10.157.1.210 with SMTP id e76mr5220273ote.211.1483908618179; Sun, 08 Jan 2017 12:50:18 -0800 (PST) |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 90 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Jens Axboe <axboe@fb.com>, Andi Kleen <ak@linux.intel.com>, Rabin Vincent <rabinv@axis.com>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, "stable@vger.kernel.org" <stable@vger.kernel.org>, linux-block@vger.kernel.org, Jeff Moyer <jmoyer@redhat.com>, Wei Fang <fangwei1@huawei.com>, Christoph Hellwig <hch@lst.de> |
| X-Original-Date | Sun, 8 Jan 2017 12:50:17 -0800 |
| X-Original-Message-ID | <CAPcyv4hvdtJ9v9XLARAY+Es8pPYEVP76ht6TLyWC=T_vqGwxWA@mail.gmail.com> |
| X-Original-References | <148366547505.38941.646379357860772670.stgit@dwillia2-desk3.amr.corp.intel.com> <20170106102330.GB3533@quack2.suse.cz> <CAPcyv4gmvGkAbse619WOBsEd8DDn8Fe4kVJ7r+iYug8DEg+cEg@mail.gmail.com> <20170108194614.GA18227@quack2.suse.cz> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1553935 |
Show key headers only | View raw
On Sun, Jan 8, 2017 at 11:46 AM, Jan Kara <jack@suse.cz> wrote:
> On Fri 06-01-17 09:45:45, Dan Williams wrote:
>> On Fri, Jan 6, 2017 at 2:23 AM, Jan Kara <jack@suse.cz> wrote:
>> > On Thu 05-01-17 17:17:55, Dan Williams wrote:
>> >> The ->bd_queue member of struct block_device was added in commit
>> >> 87192a2a49c4 ("vfs: cache request_queue in struct block_device") in
>> >> v3.3. However, blk_get_backing_dev_info() has been using
>> >> bdev_get_queue() and grabbing the request_queue through the gendisk
>> >> since before the git era.
>> >>
>> >> At final __blkdev_put() time ->bd_disk is cleared while ->bd_queue is
>> >> not. The queue remains valid until the final put of the parent disk.
>> >>
>> >> The following crash signature results from blk_get_backing_dev_info()
>> >> trying to lookup the queue through ->bd_disk after the final put of the
>> >> block device. Simply switch bdev_get_queue() to use ->bd_queue directly
>> >> which is guaranteed to still be valid at invalidate_partition() time.
>> >>
>> >> BUG: unable to handle kernel NULL pointer dereference at 0000000000000568
>> >> IP: blk_get_backing_dev_info+0x10/0x20
>> >> [..]
>> >> Call Trace:
>> >> __inode_attach_wb+0x3a7/0x5d0
>> >> __filemap_fdatawrite_range+0xf8/0x100
>> >> filemap_write_and_wait+0x40/0x90
>> >> fsync_bdev+0x54/0x60
>> >> ? bdget_disk+0x30/0x40
>> >> invalidate_partition+0x24/0x50
>> >> del_gendisk+0xfa/0x230
>> >
>> > So we have a similar reports of the same problem. E.g.:
>> >
>> > http://www.spinics.net/lists/linux-fsdevel/msg105153.html
>> >
>> > However I kind of miss how your patch would fix all those cases. The
>> > principial problem is that inode_to_bdi() called on block device inode
>> > wants to get the backing_dev_info however on last close of a block device
>> > we do put_disk() and thus the request queue containing backing_dev_info
>> > does not have to be around at that time. In your case you are lucky enough
>> > to have the containing disk still around but that's not the case for all
>> > inode_to_bdi() users (see e.g. the report I referenced) and your patch
>> > would change relatively straightforward NULL pointer dereference to rather
>> > subtle use-after-free issue
>>
>> True. If there are other cases that don't hold their own queue
>> reference this patch makes things worse.
>>
>> > so I disagree with going down this path.
>>
>> I still think this patch is the right thing to do, but it needs to
>> come after the wider guarantee that having an active bdev reference
>> guarantees that the queue and backing_dev_info are still allocated.
>>
>> > So what I think needs to be done is that we make backing_dev_info
>> > independently allocated structure with different lifetime rules to gendisk
>> > or request_queue - definitely I want it to live as long as block device
>> > inode exists. However it needs more thought what the exact lifetime rules
>> > will be.
>>
>> Hmm, why does it need to be separately allocated?
>>
>> Something like this, passes the libnvdimm unit tests: (non-whitespace
>> damaged version attached)
>
> So the problem with this approach is that request queue will be pinned while
> bdev inode exists. And how long that is is impossible to predict or influence
> from userspace so e.g. you cannot remove device driver from memory and even
> unplugging USB after it has been unmounted would suddently go via a path of
> "device removed while it is used" which can have unexpected consequences. I
> guess Jens or Christoph will know more about the details...
We do have the "block, fs: reliably communicate bdev end-of-life"
effort that I need to revisit:
http://www.spinics.net/lists/linux-fsdevel/msg93312.html
...but I don't immediately see how keeping the request_queue around
longer makes the situation worse?
> I have prototyped patches which split backing_dev_info from request_queue
> and it was not even that difficult in the end. I'll give those patches some
> testing and post them for comments...
As long as the crashes are addressed I don't much care which solution
goes upstream.
That said I think it is unfortunate that we introduced ->bd_queue in
v3.3, but most users are still pointer chasing through
->bd_disk->queue. I'll see if the 0day robot can find any performance
benefit to this change outside of trying to fix a bdev-unplug crash.
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] block: fix blk_get_backing_dev_info() crash, use bdev->bd_queue Dan Williams <dan.j.williams@intel.com> - 2017-01-06 02:40 +0100
Re: [PATCH] block: fix blk_get_backing_dev_info() crash, use bdev->bd_queue Jan Kara <jack@suse.cz> - 2017-01-06 11:30 +0100
Re: [PATCH] block: fix blk_get_backing_dev_info() crash, use bdev->bd_queue Dan Williams <dan.j.williams@intel.com> - 2017-01-06 18:50 +0100
Re: [PATCH] block: fix blk_get_backing_dev_info() crash, use bdev->bd_queue Jan Kara <jack@suse.cz> - 2017-01-08 20:50 +0100
Re: [PATCH] block: fix blk_get_backing_dev_info() crash, use bdev->bd_queue Dan Williams <dan.j.williams@intel.com> - 2017-01-08 22:00 +0100
Re: [PATCH] block: fix blk_get_backing_dev_info() crash, use bdev->bd_queue Dan Williams <dan.j.williams@intel.com> - 2017-01-10 03:10 +0100
Re: [PATCH] block: fix blk_get_backing_dev_info() crash, use bdev->bd_queue Christoph Hellwig <hch@lst.de> - 2017-01-10 17:00 +0100
csiph-web