From: Matthew Wilcox <willy@infradead.org>
To: Hugh Dickins <hughd@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Jan Kara <jack@suse.cz>,
syzbot <syzbot+3622cea378100f45d59f@syzkaller.appspotmail.com>,
Andreas Dilger <adilger.kernel@dilger.ca>,
Ext4 Developers List <linux-ext4@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
syzkaller-bugs <syzkaller-bugs@googlegroups.com>,
Theodore Ts'o <tytso@mit.edu>, Linux-MM <linux-mm@kvack.org>,
Oleg Nesterov <oleg@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
"Kirill A. Shutemov" <kirill@shutemov.name>,
Nicholas Piggin <npiggin@gmail.com>,
Alex Shi <alex.shi@linux.alibaba.com>, Qian Cai <cai@lca.pw>,
Christoph Hellwig <hch@infradead.org>,
"Darrick J. Wong" <darrick.wong@oracle.com>,
William Kucharski <william.kucharski@oracle.com>,
Jens Axboe <axboe@kernel.dk>,
linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org
Subject: Re: kernel BUG at fs/ext4/inode.c:LINE!
Date: Tue, 24 Nov 2020 18:33:51 +0000 [thread overview]
Message-ID: <20201124183351.GD4327@casper.infradead.org> (raw)
In-Reply-To: <alpine.LSU.2.11.2011240810470.1029@eggly.anvils>
On Tue, Nov 24, 2020 at 08:28:16AM -0800, Hugh Dickins wrote:
> On Tue, 24 Nov 2020, Matthew Wilcox wrote:
> > On Mon, Nov 23, 2020 at 08:07:24PM -0800, Hugh Dickins wrote:
> > >
> > > Then on crashing a second time, realized there's a stronger reason against
> > > that approach. If my testing just occasionally crashes on that check,
> > > when the page is reused for part of a compound page, wouldn't it be much
> > > more common for the page to get reused as an order-0 page before reaching
> > > wake_up_page()? And on rare occasions, might that reused page already be
> > > marked PageWriteback by its new user, and already be waited upon? What
> > > would that look like?
> > >
> > > It would look like BUG_ON(PageWriteback) after wait_on_page_writeback()
> > > in write_cache_pages() (though I have never seen that crash myself).
> >
> > I don't think this is it. write_cache_pages() holds a reference to the
> > page -- indeed, it holds the page lock! So this particular race cannot
> > cause the page to get recycled. I still have no good ideas what this
> > is :-(
>
> It is confusing. I tried to explain that in the final paragraph:
>
> > > Was there a chance of missed wakeups before, since a page freed before
> > > reaching wake_up_page() would have PageWaiters cleared? I think not,
> > > because each waiter does hold a reference on the page: this bug comes
> > > not from real waiters, but from when PageWaiters is a false positive.
>
> but got lost in between the original end_page_writeback() and the patched
> version when writing that last part - false positive PageWaiters are not
> relevant. I'll try rewording that in the simpler version, following.
>
> The BUG_ON(PageWriteback) would occur when the old use of the page, the
> one we do TestClearPageWriteback on, had *no* waiters, so no additional
> page reference beyond the page cache (and whoever racily frees it). The
> reuse of the page definitely has a waiter holding a reference, as you
> point out, and PageWriteback still set; but our belated wake_up_page()
> has woken it to hit the BUG_ON.
I ... think I see. Let me try to write it out:
page is allocated, added to page cache, dirtied, writeback starts,
--- thread A ---
filesystem calls end_page_writeback()
test_clear_page_writeback()
--- context switch to thread B ---
truncate_inode_pages_range() finds the page, it doesn't have writeback set,
we delete it from the page cache. Page gets reallocated, dirtied, writeback
starts again. Then we call write_cache_pages(), see
PageWriteback() set, call wait_on_page_writeback()
--- context switch back to thread A ---
wake_up_page(page, PG_writeback);
... thread B is woken, but because the wakeup was for the old use of
the page, PageWriteback is still set.
Devious.
We could fix this by turning that 'if' into a 'while' in
write_cache_pages(). Just accept that spurious wakeups can happen
and they're harmless. We do need to remove that check of PageWaiters
in wake_up_page() -- as you say, we shouldn't be checking that after
dropping the reference. I had patches to do that ..
https://lore.kernel.org/linux-mm/20200416220130.13343-1-willy@infradead.org/
specifically:
https://lore.kernel.org/linux-mm/20200416220130.13343-11-willy@infradead.org/
next prev parent reply other threads:[~2020-11-24 18:34 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-27 2:48 kernel BUG at fs/ext4/inode.c:LINE! syzbot
2020-08-28 10:07 ` Jan Kara
2020-08-31 10:03 ` Jan Kara
2020-08-31 18:21 ` Linus Torvalds
2020-11-24 4:07 ` Hugh Dickins
2020-11-24 4:26 ` Linus Torvalds
2020-11-24 4:53 ` Linus Torvalds
2020-11-24 6:34 ` Hugh Dickins
2020-11-24 16:46 ` Hugh Dickins
2020-11-24 12:19 ` Matthew Wilcox
2020-11-24 16:28 ` Hugh Dickins
2020-11-24 18:33 ` Matthew Wilcox [this message]
2020-11-24 19:00 ` Linus Torvalds
2020-11-24 20:15 ` Matthew Wilcox
2020-11-24 20:34 ` Linus Torvalds
2020-11-24 21:46 ` Hugh Dickins
2020-11-24 23:24 ` Linus Torvalds
2020-11-25 21:30 ` Linus Torvalds
2020-11-25 22:01 ` Linus Torvalds
2020-11-25 9:20 ` 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=20201124183351.GD4327@casper.infradead.org \
--to=willy@infradead.org \
--cc=adilger.kernel@dilger.ca \
--cc=akpm@linux-foundation.org \
--cc=alex.shi@linux.alibaba.com \
--cc=axboe@kernel.dk \
--cc=cai@lca.pw \
--cc=darrick.wong@oracle.com \
--cc=hch@infradead.org \
--cc=hughd@google.com \
--cc=jack@suse.cz \
--cc=kirill@shutemov.name \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=npiggin@gmail.com \
--cc=oleg@redhat.com \
--cc=syzbot+3622cea378100f45d59f@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=william.kucharski@oracle.com \
/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).