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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 2A7DEC64E7C for ; Tue, 24 Nov 2020 12:19:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C478F2168B for ; Tue, 24 Nov 2020 12:19:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="AoYEmNwS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387524AbgKXMTS (ORCPT ); Tue, 24 Nov 2020 07:19:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729172AbgKXMTR (ORCPT ); Tue, 24 Nov 2020 07:19:17 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 826ACC0613D6; Tue, 24 Nov 2020 04:19:17 -0800 (PST) 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=uvDfFcTJVIdXBGR+joN6zXz154p6r479ClVsKuidpag=; b=AoYEmNwScc3ZhYqB9VycOafUC5 2v8rbvnu68twnK4hQ1ICV3Qzd3tbpCIgVcqUSI2A3/4FgAKbdGgoPE3j691S9i44M+3BMOp+ucZpe WYTpbzzzuC8m5I6rqbpj7uJxVy2iPPq4BbrJt3tnjp156mNc79iiEIPR+k4akIFcqQYYTWMEGNmOn GTS+ei+v5ogGFPnIWlWKqtnu9wWzezGV6iDyvZWWbfaK41ZVxjD7qnMAJMwYOli6+LnTRhtDS8F/J ATpzt8UTjj6e/hWbcAEtZdqToH0AwcokShCJbDWUIV5xBWmnCgjfTQnUGBa3qUsMVttttRPptukAc Xc1lNbWw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1khXHs-0002FJ-2w; Tue, 24 Nov 2020 12:19:12 +0000 Date: Tue, 24 Nov 2020 12:19:12 +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: <20201124121912.GZ4327@casper.infradead.org> References: <000000000000d3a33205add2f7b2@google.com> <20200828100755.GG7072@quack2.suse.cz> <20200831100340.GA26519@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Mon, Nov 23, 2020 at 08:07:24PM -0800, Hugh Dickins wrote: > Twice now, when exercising ext4 looped on shmem huge pages, I have crashed > on the PF_ONLY_HEAD check inside PageWaiters(): ext4_finish_bio() calling > end_page_writeback() calling wake_up_page() on tail of a shmem huge page, > no longer an ext4 page at all. > > The problem is that PageWriteback is not accompanied by a page reference > (as the NOTE at the end of test_clear_page_writeback() acknowledges): as > soon as TestClearPageWriteback has been done, that page could be removed > from page cache, freed, and reused for something else by the time that > wake_up_page() is reached. > > https://lore.kernel.org/linux-mm/20200827122019.GC14765@casper.infradead.org/ > Matthew Wilcox suggested avoiding or weakening the PageWaiters() tail > check; but I'm paranoid about even looking at an unreferenced struct page, > lest its memory might itself have already been reused or hotremoved (and > wake_up_page_bit() may modify that memory with its ClearPageWaiters()). > > 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 :-(