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.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 7D831CA9EAF for ; Mon, 21 Oct 2019 18:03:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 74C7E20B7C for ; Mon, 21 Oct 2019 18:03:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="mvpvVaZF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 74C7E20B7C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EA9346B0003; Mon, 21 Oct 2019 14:03:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E318F6B0005; Mon, 21 Oct 2019 14:03:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF8976B0006; Mon, 21 Oct 2019 14:03:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id A6C0F6B0003 for ; Mon, 21 Oct 2019 14:03:17 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 4F5F6181AEF3E for ; Mon, 21 Oct 2019 18:03:17 +0000 (UTC) X-FDA: 76068563634.09.stove59_910d8a5c7ae24 X-HE-Tag: stove59_910d8a5c7ae24 X-Filterd-Recvd-Size: 5022 Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Mon, 21 Oct 2019 18:03:16 +0000 (UTC) Received: by mail-qt1-f193.google.com with SMTP id g50so8227848qtb.4 for ; Mon, 21 Oct 2019 11:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=wyEp1kOdaCYzrwvdEM/kPkFxBB0Sg4gRdGjRJK/qdGA=; b=mvpvVaZFNZtubTKfQHrkzk+N5tFEJzXkNyBqBIs3pZ3zkZK3mabIbyDflu013jujfB e5vctsPQHk3tuswyq/oOs+kWRhM2nWogmkJ61jp/QjY6kwuVK3ylBA8sIIL3uNUVSDCx HK4x0bfd8m9zAN5LrzGqHzcEHECkkVIH1KbUc6fCKfKaWaCtAqICaAK9Xen2TkIRNmq9 gEmYUJpCAZfaAP5kH1NIlJCW02OKZT8Jog5Mb7cSxUWKfNatckxZkVwXvsCNB3xE+e8d pZFKxvx7vuzVF8dHS49kJug9W1Wnb2i82nJ7jTiccu5BUcADyeJ59xd+d1KqbHVDwfU4 h8wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wyEp1kOdaCYzrwvdEM/kPkFxBB0Sg4gRdGjRJK/qdGA=; b=H0qC7g5ikdHg1HzClYP9jXwkPttAswlP/K6+5aDih+inaA+OhfqZcSEhArlcRMLepV Epm3pi7xGX0K2c+HUSkNHLwVe98tHfGMiu1tieISayoyzE46NDVr7omagaYuDpZ9oc7Z 3oh1Y/z5i1gt/wzfJoSvETpGMG7V2Nr+mz9c5HP/azdcVUU9VeyV9/fOkhlf3Av5AtWX FVHoEy3kcIRFKv2zOD1y49GlcN2lLIDaqd7Ib3BEWoMnEnBFn82XB+zaDYFMcTppWLWr uqJD4oxKYtgQZFV4qxolc1djvvddL590e30O3yQCFWvTwH3x+wESr6FWKizhhltxvAqh hoFw== X-Gm-Message-State: APjAAAWJST/tqxiV83q9C6FOf/O1p8QHRqiZ1sV18dDgBkvl5Jnk4p2o r0Wrz3H9UtmZaIx7j0iHyhZe7A== X-Google-Smtp-Source: APXvYqz68/kqjdmLF8f0rHCHXaVIR95FOdV8pEtEZdEGeJGVjChL9WqcBJ04eXbqarquvsAy3MC8cw== X-Received: by 2002:ac8:3a26:: with SMTP id w35mr25006063qte.211.1571680995603; Mon, 21 Oct 2019 11:03:15 -0700 (PDT) Received: from localhost ([2620:10d:c091:500::3:2d1]) by smtp.gmail.com with ESMTPSA id 131sm8838166qkg.1.2019.10.21.11.03.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 11:03:14 -0700 (PDT) Date: Mon, 21 Oct 2019 14:03:14 -0400 From: Johannes Weiner To: Song Liu Cc: Andrew Morton , open list , "linux-mm@kvack.org" , "matthew.wilcox@oracle.com" , Kernel Team , "william.kucharski@oracle.com" , "kirill.shutemov@linux.intel.com" , Hugh Dickins Subject: Re: [PATCH v3] mm,thp: recheck each page before collapsing file THP Message-ID: <20191021180314.GA185593@cmpxchg.org> References: <20191018180345.4188310-1-songliubraving@fb.com> <20191018181712.91dd9e9f9941642300e1b8d9@linux-foundation.org> <9DC29F5B-1DF5-408F-BEDF-FD1FBAAB1361@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9DC29F5B-1DF5-408F-BEDF-FD1FBAAB1361@fb.com> User-Agent: Mutt/1.12.2 (2019-09-21) 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, Oct 19, 2019 at 05:24:00AM +0000, 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. 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. > > Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS") > Cc: Kirill A. Shutemov > Cc: Johannes Weiner > Cc: Hugh Dickins > Cc: William Kucharski > Cc: Andrew Morton > Signed-off-by: Song Liu Acked-by: Johannes Weiner