From patchwork Tue Sep 4 07:55:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10586917 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA5D11669 for ; Tue, 4 Sep 2018 07:55:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC8D628ED5 for ; Tue, 4 Sep 2018 07:55:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B00C228EF9; Tue, 4 Sep 2018 07:55:24 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE 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 1602D28ED5 for ; Tue, 4 Sep 2018 07:55:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 000FF6B6C6A; Tue, 4 Sep 2018 03:55:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EEF966B6C6B; Tue, 4 Sep 2018 03:55:22 -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 DDF946B6C6C; Tue, 4 Sep 2018 03:55:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f197.google.com (mail-qt0-f197.google.com [209.85.216.197]) by kanga.kvack.org (Postfix) with ESMTP id B11DE6B6C6A for ; Tue, 4 Sep 2018 03:55:22 -0400 (EDT) Received: by mail-qt0-f197.google.com with SMTP id e88-v6so3212318qtb.1 for ; Tue, 04 Sep 2018 00:55:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:mime-version:content-transfer-encoding; bh=+p4aonBKJLPIdtJn3nq/vbdKIAjl/WUw/+l3fuTE220=; b=L8vNpjXOWZy9BZByWJ409qP7ctzVS3tf3C5nNBr2yimfmKwAMR0XbFIBTyHQVWuVqm HFnA1e0KayRmKkxlAxAIjQ4C7MuLvjck/JgbL7O+HvwsFkfRJP7cCVOLtDUD+CEBaJXE gkxUzA8e+Vn5plWBuAnwKYUxsMruwwn5pldrQlRHOlggHLrMbRqyFtXfPqOLYwrJtCOU CX2qOLGxI4CO44jp2BkQ0kJQp5f243ViJtNw8jMhNDGh2PgMHGDF6PPrW1ttm4cOSl3y oxUak37v1JTWRbx5tuTzzIhG8HaOppD4odDSc7OenpIQ0h9hkscujCkRa2dnkVfwhiP2 9yBQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APzg51AWEm28TVIpaHOHTMR7ssr+Bh5cwz8+7dbllPYYprBQpb0Aaezb maxsVo3xxQNdf0RJ6yvR7Dc6F1J7REN+xUFwS+ccXpYjznVPa3qtk2NKKtq0GiTwGwpjg+FEqRl atz7tDV0mXFYrmHCUdeyceGWhE4TOo3e6QH688z4QhclGO2927yAUBdWahsRjj0rcPw== X-Received: by 2002:a37:b842:: with SMTP id i63-v6mr1944868qkf.187.1536047722443; Tue, 04 Sep 2018 00:55:22 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda2QaNN3H9SXRRX7B8P91pnfHqVw3dCMjNyCAQSffVbszVzDVXd5Safsp4F0a8Qa+fcd2Br X-Received: by 2002:a37:b842:: with SMTP id i63-v6mr1944857qkf.187.1536047721937; Tue, 04 Sep 2018 00:55:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047721; cv=none; d=google.com; s=arc-20160816; b=IPt2VPuQ0b/192oiOHDR+ZWU90jOSgtcQeLAVvTvQGpnVZoFm0RFf8Ln95fp0BWLHe DuS1rZKz/OPf3O2jO0kzz3sHXjjTbcYIGI1Ce+iP6GVfF2WijlbdGbiaGtALLbfyyunF S9mZiTzRdVovgQqFg5BEC0SdyztuzmlXdv1eHpp4ewT3BMKkbLchI/od4lqBcftG0cnz 82H7x4LwPn3HxSPcVq2xfu7KbTMelf6m8AiL2vYiNOOwfBUCpB8ufSZqSb7VOBrrTuBc YuVd5Xpf7NJlUCq9v9ApFIyH5LzKs6a0puq46WYl1K1Yai13qwk6gk2yH4ETTQgic8zZ Mdbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=+p4aonBKJLPIdtJn3nq/vbdKIAjl/WUw/+l3fuTE220=; b=kOM1lnPdGywhrxXnHPL+ia+u0iNtFD/K+gQqQHtmTNNF2gbfrBtIvH0Lxw3mJoxRRa o6hvwBkc8i1M8ywpgaGVEWW+gIccmFX3smxc0fWmEZCPdmfExaPej6GLiPmRs+Ph3E5o wWVjBIIZeMvvecoY4UJe57oEV1jrNwk8GlZ6TNSJTUBr1/sB+rypJlHREQ3l6695d+T8 6oAdxvU4k7MNGoymAVSIjFsCyplC3yuv9atgLXsdIDv/Q1KjS5aSGUj+1zEtPBsdEMtf 4Se5yEmkcxYwFOG3axz7RUkcmc3LK4cXCwyRTcMjE8MAyLnr3yLq0D62yNfPk/gFxF26 9a0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id a5-v6si3029807qtp.320.2018.09.04.00.55.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:55:21 -0700 (PDT) Received-SPF: pass (google.com: domain of peterx@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54CBD87927; Tue, 4 Sep 2018 07:55:21 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B109202704B; Tue, 4 Sep 2018 07:55:11 +0000 (UTC) From: Peter Xu To: linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Andrea Arcangeli , Andrew Morton , "Kirill A. Shutemov" , Michal Hocko , Zi Yan , Huang Ying , Dan Williams , Naoya Horiguchi , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , "Aneesh Kumar K.V" , Konstantin Khlebnikov , Souptick Joarder , linux-mm@kvack.org Subject: [PATCH] mm: hugepage: mark splitted page dirty when needed Date: Tue, 4 Sep 2018 15:55:10 +0800 Message-Id: <20180904075510.22338-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 04 Sep 2018 07:55:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 04 Sep 2018 07:55:21 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'peterx@redhat.com' RCPT:'' 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 When splitting a huge page, we should set all small pages as dirty if the original huge page has the dirty bit set before. Otherwise we'll lose the original dirty bit. CC: Andrea Arcangeli CC: Andrew Morton CC: "Kirill A. Shutemov" CC: Michal Hocko CC: Zi Yan CC: Huang Ying CC: Dan Williams CC: Naoya Horiguchi CC: "Jérôme Glisse" CC: "Aneesh Kumar K.V" CC: Konstantin Khlebnikov CC: Souptick Joarder CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org Signed-off-by: Peter Xu --- To the reviewers: I'm new to the mm world so sorry if this patch is making silly mistakes, however it did solve a problem for me when testing with a customized Linux tree mostly based on Andrea's userfault write-protect work. Without the change, my customized QEMU/tcg tree will not be able to do correct UFFDIO_WRITEPROTECT and then QEMU will get a SIGBUS when faulting multiple times. With the change (or of course disabling THP) then UFFDIO_WRITEPROTECT will be able to correctly resolve the write protections then it runs well. Any comment would be welcomed. TIA. --- mm/huge_memory.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c3bc7e9c9a2a..0754a16923d5 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2176,6 +2176,8 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, entry = pte_mkold(entry); if (soft_dirty) entry = pte_mksoft_dirty(entry); + if (dirty) + entry = pte_mkdirty(entry); } pte = pte_offset_map(&_pmd, addr); BUG_ON(!pte_none(*pte));