Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2256921imm; Tue, 4 Sep 2018 00:56:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbsPpUk+CDD19/oFCUYFOPoMrvL6CglVP961pmb5+CVkP4lm4pDNyORwKXC/8rgVnW5Abqa X-Received: by 2002:a63:b207:: with SMTP id x7-v6mr4881677pge.401.1536047812586; Tue, 04 Sep 2018 00:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536047812; cv=none; d=google.com; s=arc-20160816; b=g+1QuZ+wfIi9eSX1G1hwdKZPqT1iHzfz486DPpUoxDy4yVy6nvAU2almXeXnGxhyG4 J33CVLAqM2a1sHgEkapDaBjmHExhw15hI6qElUsw+M4KJDlvWjL2sHMV/WI9SzJnWuUg SOfzZOIK1tHwynKu5AgHDgqdj8GS0fGukBbNPveqDhEGptQWBN9MHspEkh1iQTr7J+x5 BX0mOfc1XJT+7tVi8Z+ldn30AcHUyLXOCPTSlHeEiPqcPK+vDoudSupMgaV9LocEJPSB ESFyT2hKx3XneeavHBHJ+KP7bSW98mIMm6j6kfe0NkzDSyvMGO8qTxNpJuplOAt+gTMP ZLEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:arc-authentication-results; bh=+p4aonBKJLPIdtJn3nq/vbdKIAjl/WUw/+l3fuTE220=; b=s/BPNHb59K+Da5G34MbcONb8fk0BswC1EtslX4rrcNmovQTeOfVgXqYXtZ6tKySzOy 77pR30dQ4iXM+UTZEZ71iSE0lA3bwallEToQNJ+KHcqnvOLgQOw5qn33V39smgowEQJE 42KavX/A9n0O132NvP8uK/xnAr74+Do83EaG39dgllpMvZNC/xpM3wLjiu42rhcpJeok 918BHnzOT7RMkB8BicZXI6CV94qeCHO6og0hN1uAh6Lgdh/zhkId2qZntd3SvjYphtVP 2TRmABuEHCrKtVesfM3xMwRn6dzV/Es3sZU1O0CJBsf2MF+9AZ1DN40lTPgyrRY0LjIm Pw+Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l12-v6si19393767plt.440.2018.09.04.00.56.36; Tue, 04 Sep 2018 00:56:52 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726284AbeIDMTS (ORCPT + 99 others); Tue, 4 Sep 2018 08:19:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38770 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725992AbeIDMTS (ORCPT ); Tue, 4 Sep 2018 08:19:18 -0400 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?q?J=C3=A9r=C3=B4me=20Glisse?= , "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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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)); -- 2.17.1