Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1207931imm; Wed, 11 Jul 2018 20:10:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeyamVeF+Vmg7wC/Ul65/r5S5w5Nzsua67A2bpzepcyD1GaWfNVubcdlOpK9JWRvyAlj/2M X-Received: by 2002:a63:2043:: with SMTP id r3-v6mr463379pgm.105.1531365033124; Wed, 11 Jul 2018 20:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531365033; cv=none; d=google.com; s=arc-20160816; b=h4PYdFDuZ+Ff6YCmZ/1uxjsQjlNb/CvzhCGo0zuzMU8LW9kGd9+4oeqntW41mODfBw VohRWt8pOGeq8FlyR8DBqtjNiwMibkI/YzaguxIY0afDo/+fO8Pney014oLuQBY61pI7 VmrdeRWrMe2A9rLMdWYE30dtBZ9d7eIIAn1pfrnkFN/Hkr0zqJyj/SgW/Cj3pZlZMAmB aGrXgzZ1Dq5oKw4eXLzmhq5h69YNWSlrG0ZmBms3PSTIH9qGdbQYtKz6zXaB7Td0KFt+ g578yi+fUOK4rs9otwMsL5m98OyTV/vzl6cY16K1nqG7p/AMHA8oxP8I6VgqqyVbe8A7 Nf0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:arc-authentication-results; bh=kW4BM2WWRZgHzBJjvfunU+jFFOLoLG6zcw7MdzGSoY8=; b=PiwBz8Gm46kJeYbE+/gCyo2+1u4EdorQki+E4ikNZLvVWLON17VStt275P9G0jxcxJ tM+heu19/fs3ai4T8x+lH3dH4aKGfKT9PMovifcPt3K//oPIAixTyOR/DaNT5ArB/+ci s6NchBjKRgU5UgXhnXL96VHIopbRNbJxVKqiXSXuvW5qOMadRfCAeStjMMnv1j6ISFgm so/nd29TyTgXojv70YVHsmNWiuFOX6CeEe8K/OR5gpYNd/nm3DDNEOz71PMfxcwAmSWL LsMKZLheTQLW/lmt7pOxnYq4lDkX0KaHTq2xFC2F+du/Cbgoy4oi3zf5YZxZLsbk8n4+ AnbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="hbk3IXL/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f21-v6si19489535pgl.235.2018.07.11.20.10.17; Wed, 11 Jul 2018 20:10:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="hbk3IXL/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390118AbeGLA4A (ORCPT + 99 others); Wed, 11 Jul 2018 20:56:00 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46818 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733280AbeGLAz6 (ORCPT ); Wed, 11 Jul 2018 20:55:58 -0400 Received: by mail-pg1-f195.google.com with SMTP id p23-v6so3225491pgv.13 for ; Wed, 11 Jul 2018 17:49:03 -0700 (PDT) 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-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:user-agent :mime-version; bh=kW4BM2WWRZgHzBJjvfunU+jFFOLoLG6zcw7MdzGSoY8=; b=sJJCtKME924Oh1lhnzOHMoZa0aDIbybYDFzBjHy4KPua2ZcrOUwQXs8sGkcvAi09/s r0IA01JXhQSSt9XVBbmmkQH1hYn1kOu7wsKpcmOiqdJHuXoGaoiFdGiqPkY/DKaMEn4a hqJs0+Gn8g6zNQ7cB+lH6Y/PRMsiFODUk6QSRccGK8XHfmConYWOACFZY5YQ9pAAXQIR +BKgVRJqZtVAnUvf0fgKTUJODsKCZ4FSrK7JhLX6/Lp601vxes/e5u17Df3me7xwtBa+ dwJzkj66nr3iZGw8AdBeTT6zqi7VBwlQAyNIP85N3R5PyjzZb9lPD5H8xP3ZAhC5Ewl5 gaaw== X-Gm-Message-State: AOUpUlHX8spvrhcODSLO5e0tPaaazsu0SWkiMmlK8wsHaS5B4q1RIIfI 76q/4RIODm3mI5Yv3Jcp/lWa5Q== 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 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __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+ --- 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);