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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8AE7C433EF for ; Thu, 9 Dec 2021 13:56:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53B106B0072; Thu, 9 Dec 2021 08:56:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C2E26B0073; Thu, 9 Dec 2021 08:56:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 363F76B0074; Thu, 9 Dec 2021 08:56:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id 243F96B0072 for ; Thu, 9 Dec 2021 08:56:09 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DE85518579891 for ; Thu, 9 Dec 2021 13:55:58 +0000 (UTC) X-FDA: 78898404396.07.9AA696A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id E6FC220008 for ; Thu, 9 Dec 2021 13:55:57 +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=1+LEczdi59AY2/papldS92pldhESqdSy5rOO+LXFl/Y=; b=BN5zR4Fap4OgbbW6sVMj4jsSBW ilAnzN36cbHQO/TcIlS7AGgmaJEGWgjklvLL8UYTAqWAvaYX1k6e/+tlghjFURWAcOMIaNCIlTqrq EQxnogm7lkO6cKp4Xe7wWXN6kKowrwd8oLAmDfuxyre3ek1mvbUe7JaT/tgWY3JMhfx//48e82tMw NAfRHXggAMFolsWz/6cYamZIi/SxeNZ65Eg15PASz2d3U5Eor2e0S/cJPJFzZtdVrMiKFu1bmYjMQ aGaDxdoZ+l+UU86+SUjonqqsSlyV0/Gp6jHlCsc8Y9Vuxsq2sYFSP3CiFXaXqc0pkiGLzxGt/3vcy LcRiZktw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvJtf-009Oqj-PV; Thu, 09 Dec 2021 13:55:43 +0000 Date: Thu, 9 Dec 2021 13:55:43 +0000 From: Matthew Wilcox To: Hugh Dickins Cc: Andrew Morton , Vlastimil Babka , William Kucharski , Christoph Hellwig , "Kirill A. Shutemov" , Mike Rapoport , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm: delete unsafe BUG from page_cache_add_speculative() Message-ID: References: <8b98fc6f-3439-8614-c3f3-945c659a1aba@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8b98fc6f-3439-8614-c3f3-945c659a1aba@google.com> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E6FC220008 X-Stat-Signature: mhrfb5xhzsrhhuhcpxchek8wd8hstfyi Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=BN5zR4Fa; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1639058157-815664 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 Wed, Dec 08, 2021 at 11:19:18PM -0800, Hugh Dickins wrote: > It is not easily reproducible, but on 5.16-rc I have several times hit > the VM_BUG_ON_PAGE(PageTail(page), page) in page_cache_add_speculative(): > usually from filemap_get_read_batch() for an ext4 read, yesterday from > next_uptodate_page() from filemap_map_pages() for a shmem fault. > > That BUG used to be placed where page_ref_add_unless() had succeeded, > but now it is placed before folio_ref_add_unless() is attempted: that > is not safe, since it is only the acquired reference which makes the > page safe from racing THP collapse or split. > > We could keep the BUG, checking PageTail only when folio_ref_try_add_rcu() > has succeeded; but I don't think it adds much value - just delete it. Whoops, that was careless of me. I agree with your reasoning and patch. Reviewed-by: Matthew Wilcox (Oracle) > Fixes: 020853b6f5ea ("mm: Add folio_try_get_rcu()") > Signed-off-by: Hugh Dickins > --- > > include/linux/pagemap.h | 1 - > 1 file changed, 1 deletion(-) > > --- 5.16-rc4/include/linux/pagemap.h > +++ linux/include/linux/pagemap.h > @@ -285,7 +285,6 @@ static inline struct inode *folio_inode( > > static inline bool page_cache_add_speculative(struct page *page, int count) > { > - VM_BUG_ON_PAGE(PageTail(page), page); > return folio_ref_try_add_rcu((struct folio *)page, count); > } >