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=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,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 4E4DEC47E49 for ; Wed, 6 Nov 2019 04:58:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D7985214D8 for ; Wed, 6 Nov 2019 04:58:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="TBhoVGJQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D7985214D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 749206B000D; Tue, 5 Nov 2019 23:58:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F9B16B000E; Tue, 5 Nov 2019 23:58:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E9176B0010; Tue, 5 Nov 2019 23:58:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id 48DC16B000D for ; Tue, 5 Nov 2019 23:58:37 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 01FF0181AEF15 for ; Wed, 6 Nov 2019 04:58:37 +0000 (UTC) X-FDA: 76124647032.07.boot05_2e11e0635020c X-HE-Tag: boot05_2e11e0635020c X-Filterd-Recvd-Size: 4070 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Nov 2019 04:58:36 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C6CF8214D8; Wed, 6 Nov 2019 04:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573016315; bh=OYGZe4Y6kWI8ux52zLIbquW9cR6zY7hfuBXqrqwr1wc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=TBhoVGJQTZ+E9SIiFJuABeDLvEI/E0N9x+RZWx/Z58ToEhwc4O/fkSZjjtCsQoPNS jnzyWCyPc3f6sracKxKYaehf4aAMtvZW2LISMAi9wwZCHqvWVhQ8NvahdN0QLN4igo Mpaax3WS3XRmlGZo0wqSvu4ccQPNeHIUMgHb7bhw= Date: Tue, 5 Nov 2019 20:58:34 -0800 From: Andrew Morton To: Song Liu Cc: open list , "linux-mm@kvack.org" , "matthew.wilcox@oracle.com" , Kernel Team , "william.kucharski@oracle.com" , "kirill.shutemov@linux.intel.com" , "Johannes Weiner" , Hugh Dickins Subject: Re: [PATCH v3] mm,thp: recheck each page before collapsing file THP Message-Id: <20191105205834.aaebbbfead54637d17a84775@linux-foundation.org> In-Reply-To: <9DC29F5B-1DF5-408F-BEDF-FD1FBAAB1361@fb.com> References: <20191018180345.4188310-1-songliubraving@fb.com> <20191018181712.91dd9e9f9941642300e1b8d9@linux-foundation.org> <9DC29F5B-1DF5-408F-BEDF-FD1FBAAB1361@fb.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Sat, 19 Oct 2019 05:24:00 +0000 Song Liu wrote: > > We don't have a ref on that page. After we've released the xarray lock > > we have no business playing with *page at all, correct? > > Yeah, this piece is not just redundant, but also buggy. I am also > including some information about it. > > Updated commit log: > > ============================= 8< ============================= > > In collapse_file(), for !is_shmem case, current check cannot guarantee > the locked page is up-to-date. Specifically, xas_unlock_irq() should not > be called before lock_page() and get_page(); and it is necessary to > recheck PageUptodate() after locking the page. > > With this bug and CONFIG_READ_ONLY_THP_FOR_FS=y, madvise(HUGE)'ed .text > may contain corrupted data. This is because khugepaged mistakenly > collapses some not up-to-date sub pages into a huge page, and assumes the > huge page is up-to-date. This will NOT corrupt data in the disk, because > the page is read-only and never written back. Fix this by properly > checking PageUptodate() after locking the page. This check replaces > "VM_BUG_ON_PAGE(!PageUptodate(page), page);". > > Also, move PageDirty() check after locking the page. Current khugepaged > should not try to collapse dirty file THP, because it is limited to > read-only .text. Add a warning with the PageDirty() check as it should > not happen. This warning is added after page_mapping() check, because > if the page is truncated, it might be dirty. I've lost the plot on this patch. I have the v3 patch plus these fixes: http://lkml.kernel.org/r/20191028221414.3685035-1-songliubraving@fb.com http://lkml.kernel.org/r/20191022191006.411277-1-songliubraving@fb.com http://lkml.kernel.org/r/20191030200736.3455046-1-songliubraving@fb.com and there's a v4 which I can't correlate with the above. And there has been discussion about deferring some of the filemap_flush() changes until later. So I think it's best if we just start again. Can you please prepare and send out a v5 (which might be a 2-patch series)?