From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77A99C11D0F for ; Thu, 20 Feb 2020 16:31:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 32A3F2465D for ; Thu, 20 Feb 2020 16:31:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PFl1Q3Rm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32A3F2465D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1352A6B0073; Thu, 20 Feb 2020 11:31:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 01DB66B0072; Thu, 20 Feb 2020 11:31:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB0EE6B0071; Thu, 20 Feb 2020 11:31:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id BF9B16B006E for ; Thu, 20 Feb 2020 11:31:41 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 695B4180AD80F for ; Thu, 20 Feb 2020 16:31:41 +0000 (UTC) X-FDA: 76511046402.24.wound78_2bc61566bbb1b X-HE-Tag: wound78_2bc61566bbb1b X-Filterd-Recvd-Size: 5861 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 16:31:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582216300; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/r8wEdgDQnJlRmRtuxFNLFh4SFG/CuhNC3WqWOl5Lwk=; b=PFl1Q3RmcI+1fzEGpPyM8XP+y/JHCKeKTJg7PIQF47V9nUGM4p5TjD4aMhP79HJa6lcv2x eLOX/5aFQszMcsOnvEZUhV6a9dD+G5tFEcF72vB6KDoYfzFBOb66CYOeKC1qnyc1FlSJXU MgNa/HYo8K9IDO2rRDxIrxQcktvcc7k= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-65-Y2A0Y6TAMayP7K7MuqjQfQ-1; Thu, 20 Feb 2020 11:31:30 -0500 X-MC-Unique: Y2A0Y6TAMayP7K7MuqjQfQ-1 Received: by mail-qk1-f197.google.com with SMTP id d134so3125010qkc.0 for ; Thu, 20 Feb 2020 08:31:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9p8DfFh4LDgRTv+VZI0mGqV/kjyY8x0K2QPT4Z6z4hI=; b=BpsSJGvywte6N7HaOC/wUrc2wwXXlwSPulNeCYqe0hjtjj0PkybK6d4iS/+78T9qoq umH9+ARiSl/h0fVHNvdyyfd0qvjB4/Y4DpnralubOLr7hxizwqjxOogq6TZ1P/9jbBe2 pRnv034aE+R+JBXcS8z8Cxb3En/nsUkoZQgWM59bwluEzkofy7OmZPq+puMymuurYxty 7UPVHKIZmNltGNv3m/Rg5wM8hb+yyoqbwqYL9p2JsLOPxuvzQbDtyU7opcr3IpeFR3PX b294m6a40/jMXiQ1CdStvD6LRJwdYidrz/X1jgb1oFkmzBINT2QiCV/dTT9y+uEoDboW J4Xw== X-Gm-Message-State: APjAAAWrZwbpMcollfoccMlGrRtv5p/ZO4cgspTss3gQMEM4ljCjFpB6 Wemk9RvqH2at5MS3B725UtB27LT8oZjUhMoBLPqCHYStBL3vc5t9thsHlVz2KdAL3ud6IEVEHme Nn7TnLWLlljw= X-Received: by 2002:ac8:6f09:: with SMTP id g9mr27612453qtv.275.1582216290040; Thu, 20 Feb 2020 08:31:30 -0800 (PST) X-Google-Smtp-Source: APXvYqwsnOU5LWdon8Q11QY9e4+1W5bENddKTz44hj+9UCZ2Yyh27gd4WB1LUA2w5xbsoq6RUPQx5Q== X-Received: by 2002:ac8:6f09:: with SMTP id g9mr27612422qtv.275.1582216289803; Thu, 20 Feb 2020 08:31:29 -0800 (PST) Received: from xz-x1.redhat.com ([104.156.64.75]) by smtp.gmail.com with ESMTPSA id l19sm42366qkl.3.2020.02.20.08.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 08:31:28 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Brian Geffon , Pavel Emelyanov , Mike Kravetz , David Hildenbrand , peterx@redhat.com, Martin Cracauer , Andrea Arcangeli , Mel Gorman , Bobby Powers , Mike Rapoport , "Kirill A . Shutemov" , Maya Gokhale , Johannes Weiner , Marty McFadden , Denis Plotnikov , Hugh Dickins , "Dr . David Alan Gilbert" , Jerome Glisse Subject: [PATCH v6 08/19] userfaultfd: wp: drop _PAGE_UFFD_WP properly when fork Date: Thu, 20 Feb 2020 11:31:01 -0500 Message-Id: <20200220163112.11409-9-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220163112.11409-1-peterx@redhat.com> References: <20200220163112.11409-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable 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: 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 c56a83e0a184..134bef68a1de 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1011,6 +1011,14 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct m= m_struct *src_mm, =09ret =3D -EAGAIN; =09pmd =3D *src_pmd; =20 +=09/* +=09 * Make sure the _PAGE_UFFD_WP bit is cleared if the new VMA +=09 * does not have the VM_UFFD_WP, which means that the uffd +=09 * fork event is not enabled. +=09 */ +=09if (!(vma->vm_flags & VM_UFFD_WP)) +=09=09pmd =3D pmd_clear_uffd_wp(pmd); + #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION =09if (unlikely(is_swap_pmd(pmd))) { =09=09swp_entry_t entry =3D pmd_to_swp_entry(pmd); diff --git a/mm/memory.c b/mm/memory.c index 21cd818dfede..557837ec29c3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -785,6 +785,14 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struc= t *src_mm, =09=09pte =3D pte_mkclean(pte); =09pte =3D pte_mkold(pte); =20 +=09/* +=09 * Make sure the _PAGE_UFFD_WP bit is cleared if the new VMA +=09 * does not have the VM_UFFD_WP, which means that the uffd +=09 * fork event is not enabled. +=09 */ +=09if (!(vm_flags & VM_UFFD_WP)) +=09=09pte =3D pte_clear_uffd_wp(pte); + =09page =3D vm_normal_page(vma, addr, pte); =09if (page) { =09=09get_page(page); --=20 2.24.1