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 03CD9C5DF60 for ; Fri, 8 Nov 2019 03:53:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BC9E321882 for ; Fri, 8 Nov 2019 03:53:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="fz48zrPs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC9E321882 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 4D6966B0005; Thu, 7 Nov 2019 22:53:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 45F726B0006; Thu, 7 Nov 2019 22:53:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34E216B0007; Thu, 7 Nov 2019 22:53:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id 1A4376B0005 for ; Thu, 7 Nov 2019 22:53:31 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id CC813485A for ; Fri, 8 Nov 2019 03:53:30 +0000 (UTC) X-FDA: 76131740580.29.dad69_1ea16a77c361d X-HE-Tag: dad69_1ea16a77c361d X-Filterd-Recvd-Size: 3052 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Fri, 8 Nov 2019 03:53:30 +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 2C19B20869; Fri, 8 Nov 2019 03:53:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573185209; bh=slR4qIidQmC7We2wOTVqSVRCCiFEmzZiKJg8hXTu6+c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fz48zrPsaivstCfk3Bajpbs66Pr9WE+lxf22D/Z2W9p3Jnc+V88OWfLd95xOP0jDA DXDwYq0jgcWD48TWMeKktHUK9iqUbBCXOB/M/drzvzAjgt/rIqD7+vepaMiPm4HgoF BRUbRHYJATIvI86WEfgk3bT30Sft/JCKAFycLvIs= Date: Thu, 7 Nov 2019 19:53:28 -0800 From: Andrew Morton To: Song Liu Cc: , , , , , , Johannes Weiner , Hugh Dickins Subject: Re: [PATCH v5 1/2] mm,thp: recheck each page before collapsing file THP Message-Id: <20191107195328.600f302bbde69cf9c1089500@linux-foundation.org> In-Reply-To: <20191106060930.2571389-2-songliubraving@fb.com> References: <20191106060930.2571389-1-songliubraving@fb.com> <20191106060930.2571389-2-songliubraving@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 Tue, 5 Nov 2019 22:09:29 -0800 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. Incorrect data is pretty serious. Should we backport this into -stable kernels? (I suspect I already asked this in response to earier versions, sorry ;))