From patchwork Thu Jul 12 00:48:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 10520755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 40901600CA for ; Thu, 12 Jul 2018 00:49:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BC6229868 for ; Thu, 12 Jul 2018 00:49:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 201A02989C; Thu, 12 Jul 2018 00:49:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A38C29868 for ; Thu, 12 Jul 2018 00:49:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1D926B0003; Wed, 11 Jul 2018 20:49:04 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CCD276B0006; Wed, 11 Jul 2018 20:49:04 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBCEE6B0007; Wed, 11 Jul 2018 20:49:04 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id 7795B6B0003 for ; Wed, 11 Jul 2018 20:49:04 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id t19-v6so16048911plo.9 for ; Wed, 11 Jul 2018 17:49:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:from:to:cc:subject :message-id:user-agent:mime-version; bh=kW4BM2WWRZgHzBJjvfunU+jFFOLoLG6zcw7MdzGSoY8=; b=ZWDuWISezFnDQz2MIFaItssd1YqY/nNJ38AnIFSDF+8XfqY0cZ63olNjMUD7LD1cxS l3c1E+0gAeMvY007mf5RnQYFSfZ3POQ9xZcAkc9Z+T3w7sHl0hadi85dNbAnxrdWCWOD sEkwn5eC5yRsw0CtbArHO97VAxqsuAANl+O7gdpDZ9DJqoVaCVJdpEg4tJKT1pjIjnKH rVUf7jPYWjvAWW4D2JgMFzXfdfC0EdaPlmNdAIA46aQsWNp7eYTbE0uTBBQGgU6wgpdK mSib9bxney5st3maehDgj3jOBbZOEoPJqUmFS8u48Vxa/B+dWQpXhRzHGAgu20OMYsR2 uNLg== X-Gm-Message-State: AOUpUlEKPG5B3NAiSfPr1q3lLL/czY0cIHyq0PHUAFf4n8bt86mPgdZn UnQPpsCGtoXEBuaNVL34laRqOXbiVtoaP6M5ioR5gE0s0DOBWSA+9CIPo4nKbqbKipj5ayyWKXE Jc55nGL5Phq7kWmgKQbxdlmB5SfkGG+CgsJxOiHyOiEs/C9CB6uNwbPaqyWTLa879YZwsMbuMhS reCLSx02rtEn9JrmtfCcfHSwLWRSSLna9xYjcKV+QvS99FP/PwgRS3pQBMjQsM0hp1prYhwJZiD pGAwLsdepq7o2uKriATJ9aA3DdXWIbSS/AguhAPcopVnC0tmmArBPp2K2L5FFPaIsjuFOortlWu h2aAEGhRTtA91u7jDNJjMMN0siC8K3Yd5XCpeYUgj5Pv1eMEwW2F7PeHkG/xSl865abdUd10mbk + X-Received: by 2002:a17:902:4a0c:: with SMTP id w12-v6mr76050pld.289.1531356544084; Wed, 11 Jul 2018 17:49:04 -0700 (PDT) X-Received: by 2002:a17:902:4a0c:: with SMTP id w12-v6mr76013pld.289.1531356543035; Wed, 11 Jul 2018 17:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531356543; cv=none; d=google.com; s=arc-20160816; b=AORtkNQC6AZuPFCCPEVH14fxVtHly2i5uDILzbFTJraTuTm0LHzuQeKaexQHbVCfqJ en12rpsJXI1SjZeaSX2Q4yiiudEFBH/XqDdfW2bH29KZyoVFagSeVBhOhBiGRO48gRYl eZkb2rpTvf9PHEcDvLPVFRS4cuIwUxDIWN65iANvHVp2qko16mHofEEiYlEJaHQ2pjzg ZGx7bwseGiYsVZE1yPm+OR47KtKVjbJwjTEdPaH/IY/w3TgbxEbQ/aN4UlwCyf4L49Pr a3ealTr/1tnhYv2FDF4YegRdr10E5iQsNmVSqSa7yIc6ib7N6msbJqZZ9GkbeJePogIz vJhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=kW4BM2WWRZgHzBJjvfunU+jFFOLoLG6zcw7MdzGSoY8=; b=eIBHTSWzooK8SfA6llGWPUf8q+dMg7BdLRo5DnfPjksM6AEPnv1i8n1FkXQb+ISuOR qCwsPMqSx6llgu44CEs0fvR//AaPKOVKPqf8aZHKaqBAM9rIB1kpj+tadHs4VwqRZY1Z VWoqnXhydaWdWEZzlQFGcumxlq5wHv6cx5w/j5bMXL55/j82D1XxpdTBEuulBNdn4rTI QvtCFo+3o6xt8gXPoqG3d5k910j5mAJB5SO/boM2y5vsYJGJCfWBomQRSCwhNimhYQ/6 vUtTmgWb7p9qp6rRQxFLVSPq4DTUqcLywLf70c1ffVazeGoHyoH8x1O7IY6A0dnVFTlF L/xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="hbk3IXL/"; spf=pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m24-v6sor5915877pgn.197.2018.07.11.17.49.02 for (Google Transport Security); Wed, 11 Jul 2018 17:49:03 -0700 (PDT) Received-SPF: pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="hbk3IXL/"; spf=pass (google.com: domain of hughd@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=kW4BM2WWRZgHzBJjvfunU+jFFOLoLG6zcw7MdzGSoY8=; b=hbk3IXL/J3lLHXjCpQ0wUvt/ZBhy/THLwHBhA/TCLhr3cB8NYU/OeqPaNAaUJYCxfq Va7HzMln8Z2FHz4/czpOZo5fF/v1jL5d+uNunGZetb7NFJMBbWsYefIdKkLKaqfFjwxv tK/7EKHVRIQYukvws6RDFHBBAE2V/EPI93DVgf9FyRRftvykthULCNjzfFfRAUu+fTm+ yZv6fcmgdggnNo1mEIOip8vrc3N3N7a67vp2EGBj5ooMjMDVDm9rY5R77GYg9ZoBzVfq L3Vx7KJrpIDWz6lE+W5HqvVfyy3do4bp1eAwXxkEoG3/PN7IIqfU8nHFSR1YlvWo1Wqs QrbA== X-Google-Smtp-Source: AAOMgpe1Jb5+rYyiTjNAJ5u+GyEF9eUmej8W1rcCrQKWsBb+B0MJPCrO9xYgCemHYrdeqmGN6LwBlg== X-Received: by 2002:a63:4f1a:: with SMTP id d26-v6mr87450pgb.121.1531356542232; Wed, 11 Jul 2018 17:49:02 -0700 (PDT) Received: from [100.112.75.225] ([104.133.8.97]) by smtp.gmail.com with ESMTPSA id t192-v6sm33362567pgc.74.2018.07.11.17.49.01 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jul 2018 17:49:01 -0700 (PDT) Date: Wed, 11 Jul 2018 17:48:54 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: Ashwin Chaugule , "Kirill A. Shutemov" , "Huang, Ying" , Yang Shi , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] thp: fix data loss when splitting a file pmd Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP __split_huge_pmd_locked() must check if the cleared huge pmd was dirty, and propagate that to PageDirty: otherwise, data may be lost when a huge tmpfs page is modified then split then reclaimed. How has this taken so long to be noticed? Because there was no problem when the huge page is written by a write system call (shmem_write_end() calls set_page_dirty()), nor when the page is allocated for a write fault (fault_dirty_shared_page() calls set_page_dirty()); but when allocated for a read fault (which MAP_POPULATE simulates), no set_page_dirty(). Fixes: d21b9e57c74c ("thp: handle file pages in split_huge_pmd()") Reported-by: Ashwin Chaugule Signed-off-by: Hugh Dickins Cc: "Kirill A. Shutemov" Cc: "Huang, Ying" Cc: Yang Shi Cc: # v4.8+ Reviewed-by: Kirill A. Shutemov --- mm/huge_memory.c | 2 ++ 1 file changed, 2 insertions(+) --- 4.18-rc4/mm/huge_memory.c 2018-06-16 18:48:22.029173363 -0700 +++ linux/mm/huge_memory.c 2018-07-10 20:11:29.991011603 -0700 @@ -2084,6 +2084,8 @@ static void __split_huge_pmd_locked(stru if (vma_is_dax(vma)) return; page = pmd_page(_pmd); + if (!PageDirty(page) && pmd_dirty(_pmd)) + set_page_dirty(page); if (!PageReferenced(page) && pmd_young(_pmd)) SetPageReferenced(page); page_remove_rmap(page, true);