Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1367129ybi; Wed, 19 Jun 2019 19:24:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVq6vDBs40WfARnhEzWNRuA0829Jfkck2SL7N5kbFAO4W6YqbTFPx1GHhZ5I0FCWJlYRD+ X-Received: by 2002:a17:902:29e6:: with SMTP id h93mr116368548plb.297.1560997482680; Wed, 19 Jun 2019 19:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560997482; cv=none; d=google.com; s=arc-20160816; b=Cb9aEMOJDSUjj9vXP7tPnhz4CQuZt1UpHinXnXROOoBlcawG5YjUX3tT9u9933OJdY x7zBZTyEi1jFM/Ho7a2ZIPOIdBs0+lgcjmevnlyY9JduoaUrXhDEQ5vB7T9csKWFFw8z UEqBIkB/cnjeaIIG4Wa5qJ/Q8KzcGlmUxlQiiy+G4J3pr+nXEgbahINHwLJaIW63g1QY G1Wi2jwF0DEACuGjfP2t/SHFdrRk4kzEwwncJylakp6HR0+yWnBJKn2R0o2mtrWx5L34 MUZBcQyfalcgzTvrFdDfDFM3L3c6g3lrQkdv1WBHVvxctqZGCGqHLnvsAJu/6WgzeAjB aYkw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0B6K/1qpxz5QZNrjR0a/hvrU0mQd0LSbp6v1C3+Zb7A=; b=Za0i4C3oTluPviZ5+VPJCtxi9wueKiOtALvSqm6TV+98XEnaMd0OaODKVX6BnEM1L2 Zc2p978QsTEUMEjHAfzPrI0o0epdBO0ma/evwfY841uksuo+9GsqQsuypnH3QYBaL+mk NXM1HfaraAPq7QrrxoSMfctd3nvZjNsWtghbyYZgCfmn3b5h363OEfEpvG9ZrsdCTiJF Qxb4FCeS6UXssg53FNWxtXlt6FrV6sZddHioQjXUHt+9f+U5y/VY7NOUeHFP8lml+jt9 K6ybk6Th6UfOeeU8apQWHqnT6S9gRYoHPhmgWJrDqEqM09pHthO5i0E2OGFF/Dmepj71 81hQ== 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 x7si4356061pgr.427.2019.06.19.19.24.27; Wed, 19 Jun 2019 19:24:42 -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 S1731508AbfFTCXE (ORCPT + 99 others); Wed, 19 Jun 2019 22:23:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35108 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726370AbfFTCXE (ORCPT ); Wed, 19 Jun 2019 22:23:04 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0A5E308FBAC; Thu, 20 Jun 2019 02:23:03 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-78.pek2.redhat.com [10.72.12.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5886D1001E79; Thu, 20 Jun 2019 02:22:56 +0000 (UTC) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Hugh Dickins , Maya Gokhale , Jerome Glisse , Pavel Emelyanov , Johannes Weiner , peterx@redhat.com, Martin Cracauer , Denis Plotnikov , Shaohua Li , Andrea Arcangeli , Mike Kravetz , Marty McFadden , Mike Rapoport , Mel Gorman , "Kirill A . Shutemov" , "Dr . David Alan Gilbert" Subject: [PATCH v5 13/25] userfaultfd: wp: drop _PAGE_UFFD_WP properly when fork Date: Thu, 20 Jun 2019 10:19:56 +0800 Message-Id: <20190620022008.19172-14-peterx@redhat.com> In-Reply-To: <20190620022008.19172-1-peterx@redhat.com> References: <20190620022008.19172-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 20 Jun 2019 02:23:04 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org UFFD_EVENT_FORK support for uffd-wp should be already there, except that we should clean the uffd-wp bit if uffd fork event is not enabled. Detect that to avoid _PAGE_UFFD_WP being set even if the VMA is not being tracked by VM_UFFD_WP. Do this for both small PTEs and huge PMDs. Reviewed-by: Jerome Glisse Reviewed-by: Mike Rapoport Signed-off-by: Peter Xu --- mm/huge_memory.c | 8 ++++++++ mm/memory.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 3fda79f6746b..757975920df8 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -980,6 +980,14 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, ret = -EAGAIN; pmd = *src_pmd; + /* + * Make sure the _PAGE_UFFD_WP bit is cleared if the new VMA + * does not have the VM_UFFD_WP, which means that the uffd + * fork event is not enabled. + */ + if (!(vma->vm_flags & VM_UFFD_WP)) + pmd = pmd_clear_uffd_wp(pmd); + #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION if (unlikely(is_swap_pmd(pmd))) { swp_entry_t entry = pmd_to_swp_entry(pmd); diff --git a/mm/memory.c b/mm/memory.c index d79e6d1f8c62..8c69257d6ef1 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -790,6 +790,14 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, pte = pte_mkclean(pte); pte = pte_mkold(pte); + /* + * Make sure the _PAGE_UFFD_WP bit is cleared if the new VMA + * does not have the VM_UFFD_WP, which means that the uffd + * fork event is not enabled. + */ + if (!(vm_flags & VM_UFFD_WP)) + pte = pte_clear_uffd_wp(pte); + page = vm_normal_page(vma, addr, pte); if (page) { get_page(page); -- 2.21.0