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.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 D76F1C43141 for ; Fri, 15 Nov 2019 00:11:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8168620727 for ; Fri, 15 Nov 2019 00:11:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z2BH+HyV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8168620727 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 087806B0005; Thu, 14 Nov 2019 19:11:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 03BAB6B0006; Thu, 14 Nov 2019 19:11:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E689C6B0007; Thu, 14 Nov 2019 19:11:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id CF9376B0005 for ; Thu, 14 Nov 2019 19:11:02 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 8447A181AC212 for ; Fri, 15 Nov 2019 00:11:02 +0000 (UTC) X-FDA: 76156581564.21.iron84_605bc632ea151 X-HE-Tag: iron84_605bc632ea151 X-Filterd-Recvd-Size: 3925 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 Nov 2019 00:11:02 +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 BC916206B6; Fri, 15 Nov 2019 00:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573776661; bh=DAQm9GR3gvG9lmdRo4b+3ThCEzBJHxVOj3bJdvsKmUo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Z2BH+HyV6PzsdDums/qePKJ3B+BF0HrQS+1JcaUkD7oQrCeuFEbXYAxJFklnVh1sB FcltzugMbIC4Ehov24ga9fH6W+ocw0Sr8XWlf4uhyEEICK/JfMe4ILtZgwUhpaYxvY bey+zemAuH2Gab0bXTkIYqz+BB/xyUPskwOOZ/gA= Date: Thu, 14 Nov 2019 16:10:58 -0800 From: Andrew Morton To: Song Liu Cc: open list , Linux MM , "matthew.wilcox@oracle.com" , Kernel Team , "william.kucharski@oracle.com" , "kirill.shutemov@linux.intel.com" , Johannes Weiner , "Hugh Dickins" Subject: Re: [PATCH v5 1/2] mm,thp: recheck each page before collapsing file THP Message-Id: <20191114161058.e61d7b86c516da7a45259f21@linux-foundation.org> In-Reply-To: <60961DFB-32CB-4E56-8921-B2945E8BCB88@fb.com> References: <20191106060930.2571389-1-songliubraving@fb.com> <20191106060930.2571389-2-songliubraving@fb.com> <60961DFB-32CB-4E56-8921-B2945E8BCB88@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 Wed, 13 Nov 2019 23:47:06 +0000 Song Liu wrote: > > > On Nov 5, 2019, at 10:09 PM, Song Liu wrote: > > > > 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. The only case we hit a dirty page here is > > when the page hasn't been written since write. Bail out and retry when > > this happens. > > > > syzbot reported bug on previous version of this patch. > > > > Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS") > > Reported-by: syzbot+efb9e48b9fbdc49bb34a@syzkaller.appspotmail.com > > Cc: Johannes Weiner > > Cc: Kirill A. Shutemov > > Cc: Hugh Dickins > > Cc: William Kucharski > > Cc: Andrew Morton > > Signed-off-by: Song Liu > > I think we need this in 5.4 official, but I haven't seen it in Linus' > master branch. > > Hi Andrew, > > Could you please send patch/pull-request for it? Yep, today or tomorrow...