linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Vyukov <dvyukov@google.com>
To: Tejun Heo <tj@kernel.org>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	syzkaller <syzkaller@googlegroups.com>,
	Kostya Serebryany <kcc@google.com>,
	Alexander Potapenko <glider@google.com>,
	Ilya Dryomov <idryomov@gmail.com>, Jens Axboe <axboe@fb.com>,
	Jan Kara <jack@suse.com>
Subject: Re: fs: GPF in locked_inode_to_wb_and_lock_list
Date: Fri, 22 Apr 2016 20:55:27 +0200	[thread overview]
Message-ID: <CACT4Y+bHst2Cq1zk6RMVh78mDM2J2fQN4Q0ULROtb04-EamK7Q@mail.gmail.com> (raw)
In-Reply-To: <20160421170635.GO7822@mtj.duckdns.org>

On Thu, Apr 21, 2016 at 7:06 PM, Tejun Heo <tj@kernel.org> wrote:
> Hello,
>
> (cc'ing Ilya, Jan and Jens)
>
> On Thu, Apr 21, 2016 at 12:00:38PM +0200, Dmitry Vyukov wrote:
>> On Thu, Apr 21, 2016 at 11:45 AM, Andrey Ryabinin
>> <ryabinin.a.a@gmail.com> wrote:
>> > 2016-04-21 11:35 GMT+03:00 Dmitry Vyukov <dvyukov@google.com>:
>> >>
>> >> ffffffff818884dd:       48 8b 03                mov    (%rbx),%rax
>> >>
>> >> So whatever load "&wb->bdi->wb" produces is a NULL deref. (is it wb
>> >> that is NULL?)
>> >
>> > Yes it's NULL wb, because there is only one load:
>> >     mov    (%rbx),%rax        =>       rax = wb->bdi
>> >     add    $0x50,%rax         =>       rax = &bdi->wb
>>
>>
>> I bet that wb becomes NULL on the second iteration of the loop. The
>> loop loops in case of a race with another thread, so it would also
>> explain why it is difficult to reproduce.
>>
>> Tejun, does it make any sense to you?
>
> Yeah, that makes sense.  I think the culprit is 43d1c0eb7e11 ("block:
> detach bdev inode from its wb in __blkdev_put()") which allows inode
> to wb association to be broken while other operations including
> writeback are in progress.  I thought it should be okay as the inode
> must be clean at that point but that obviously doesn't mean that there
> can be no writeback operations in flight.
>
> I hope we could eventually move away from the current model where we
> try to swap out an underlying data structure while upper layers may
> still be referring to it in the future but for now we can make sure
> the writeback operation is finished before detaching wb.
>
> Dmitry, I understand that the bug is difficult to reproduce but can
> you please give the following patch a try?


I've merged it into my tree and will restart the fuzzer and leave it
running for the weekend.
Though, yeah, it is difficult to reproduce...


> Thanks.
>
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 20a2c02..209ea33 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -1530,12 +1530,7 @@ 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);
> +               inode_detach_blkdev_wb(bdev);
>         }
>         if (bdev->bd_contains == bdev) {
>                 if (disk->fops->release)
> diff --git a/include/linux/writeback.h b/include/linux/writeback.h
> index d0b5ca5..ec1f530 100644
> --- a/include/linux/writeback.h
> +++ b/include/linux/writeback.h
> @@ -230,6 +230,25 @@ static inline void inode_detach_wb(struct inode *inode)
>  }
>
>  /**
> + * inode_detach_blkdev_wb - disassociate a bd_inode from its wb
> + * @bdev: block_device of interest
> + *
> + * @bdev is being put for the last time.  Detaching bdev inode in
> + * __destroy_inode() is too late: the queue which embeds its bdi (along
> + * with root wb) can be gone as soon as the containing disk is put.
> + *
> + * This function dissociates @bdev->bd_inode from its wb.  The inode must
> + * be clean and no further operations should be started on it.
> + */
> +static inline void inode_detach_blkdev_wb(struct block_device *bdev)
> +{
> +       if (bdev->bd_inode->i_wb) {
> +               flush_delayed_work(&bdev->bd_inode->i_wb->dwork);
> +               inode_detach_wb(bdev->bd_inode);
> +       }
> +}
> +
> +/**
>   * wbc_attach_fdatawrite_inode - associate wbc and inode for fdatawrite
>   * @wbc: writeback_control of interest
>   * @inode: target inode
> @@ -277,6 +296,10 @@ static inline void inode_detach_wb(struct inode *inode)
>  {
>  }
>
> +static inline void inode_detach_blkdev_wb(struct block_device *bdev)
> +{
> +}
> +
>  static inline void wbc_attach_and_unlock_inode(struct writeback_control *wbc,
>                                                struct inode *inode)
>         __releases(&inode->i_lock)

  reply	other threads:[~2016-04-22 18:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-18  9:44 fs: GPF in locked_inode_to_wb_and_lock_list Dmitry Vyukov
2016-04-20 21:14 ` Tejun Heo
2016-04-21  8:25   ` Dmitry Vyukov
2016-04-21  9:10     ` Andrey Ryabinin
2016-04-21  9:29       ` Dmitry Vyukov
2016-04-21 16:14     ` Tejun Heo
2016-04-21  8:35   ` Dmitry Vyukov
2016-04-21  9:45     ` Andrey Ryabinin
2016-04-21 10:00       ` Dmitry Vyukov
2016-04-21 17:06         ` Tejun Heo
2016-04-22 18:55           ` Dmitry Vyukov [this message]
2016-06-06 17:46             ` Dmitry Vyukov
2016-06-17 16:04               ` [PATCH] block: flush writeback dwork before detaching a bdev inode from it Tejun Heo
2016-06-20 13:31                 ` Jan Kara
2016-06-20 13:38                   ` Dmitry Vyukov
2016-06-20 17:40                     ` Tejun Heo
2016-06-21 12:58                       ` Dmitry Vyukov

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=CACT4Y+bHst2Cq1zk6RMVh78mDM2J2fQN4Q0ULROtb04-EamK7Q@mail.gmail.com \
    --to=dvyukov@google.com \
    --cc=axboe@fb.com \
    --cc=glider@google.com \
    --cc=idryomov@gmail.com \
    --cc=jack@suse.com \
    --cc=kcc@google.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ryabinin.a.a@gmail.com \
    --cc=syzkaller@googlegroups.com \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).