From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9CC5C2D0E4 for ; Tue, 24 Nov 2020 18:34:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 654D820637 for ; Tue, 24 Nov 2020 18:34:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="GPn+9JAX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 654D820637 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A67756B006E; Tue, 24 Nov 2020 13:34:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F2576B0070; Tue, 24 Nov 2020 13:34:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E0A16B0071; Tue, 24 Nov 2020 13:34:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id 746366B006E for ; Tue, 24 Nov 2020 13:34:05 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3E4E11EE6 for ; Tue, 24 Nov 2020 18:34:05 +0000 (UTC) X-FDA: 77520161250.30.rifle57_240b43327370 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 04A8F180B3C85 for ; Tue, 24 Nov 2020 18:34:04 +0000 (UTC) X-HE-Tag: rifle57_240b43327370 X-Filterd-Recvd-Size: 5975 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Tue, 24 Nov 2020 18:34:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=tYzsIguZF1KzH8yF7YgXxi0wukPYn54G/R4/HvqYvBw=; b=GPn+9JAXTzYRQFP/tGUfh/zXs1 SAA3hxoM8fIrWUcQDhxDaR7HdvrLA1QTQMkytkLpbSOn3thdtvYU/U26jGgQqjzr2RDceiH4TUrkk eULgQxje5WTdX9D3PFAf7a7JPOkM1n2aQOVEs03eaUN+Mx2YcwPjfCC7vSsLWmfhjg2Hzi+6x44D2 +kB2uMNKqCgu2UGWp6LY5dQGkZ0tFFAFuk6VcQfNOcb/nGW1U+0IYtoNH8iNrhmkiAYt5ug4J+w6A 84v3dC6uGzTrWND1VPGDm2QxFnIbPdfwVsycpb0M/UyxFVDntLu3DpxE8YhF2/WOQxTdX9pVR6I3O IfC31lAA==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1khd8R-0003CI-Ad; Tue, 24 Nov 2020 18:33:51 +0000 Date: Tue, 24 Nov 2020 18:33:51 +0000 From: Matthew Wilcox To: Hugh Dickins Cc: Linus Torvalds , Jan Kara , syzbot , Andreas Dilger , Ext4 Developers List , Linux Kernel Mailing List , syzkaller-bugs , Theodore Ts'o , Linux-MM , Oleg Nesterov , Andrew Morton , "Kirill A. Shutemov" , Nicholas Piggin , Alex Shi , Qian Cai , Christoph Hellwig , "Darrick J. Wong" , William Kucharski , Jens Axboe , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: Re: kernel BUG at fs/ext4/inode.c:LINE! Message-ID: <20201124183351.GD4327@casper.infradead.org> References: <000000000000d3a33205add2f7b2@google.com> <20200828100755.GG7072@quack2.suse.cz> <20200831100340.GA26519@quack2.suse.cz> <20201124121912.GZ4327@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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/