From patchwork Mon Jan 21 07:57:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10772819 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 D254F1390 for ; Mon, 21 Jan 2019 07:59:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C4C8729CB1 for ; Mon, 21 Jan 2019 07:59:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B912929CBB; Mon, 21 Jan 2019 07:59:50 +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 5B12529CB1 for ; Mon, 21 Jan 2019 07:59:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CFE08E0008; Mon, 21 Jan 2019 02:59:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 67FCF8E0001; Mon, 21 Jan 2019 02:59:49 -0500 (EST) 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 5960B8E0008; Mon, 21 Jan 2019 02:59:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id 301958E0001 for ; Mon, 21 Jan 2019 02:59:49 -0500 (EST) Received: by mail-qk1-f197.google.com with SMTP id w28so18271338qkj.22 for ; Sun, 20 Jan 2019 23:59:49 -0800 (PST) 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:in-reply-to:references; bh=CMKcOJHBuk/LOB9JBPR9KTuaFj4SKYgIxDPbqbU3Psw=; b=KE6zGID785N470UBUw5y83wWamYY2chqhk5hQneov29UUBkOESH2KmcmpAfPnlTeKh xTJa3pbBy7nde0FCdKZv8ohVPEdiDdrjdz31NxRRQAX0FzROTBJCJjPXFEBmGaq/JdFB PSPUH0DPbQ+3epwYaRLF/iIYJpwFvoDhOxxnV0mYNH6mORxej20SryC/FfKY7LeQhAdj RObd8tdbHHZrKmW9hb2qW5BycZilhWUKmqa93pkIRFnmtptYH+L/W2G5RFuXBpOKbG9f O/E45d3McphOFyQpbDejzwSH9v8iD9Y/MTlsx/2jPufD45BUkw3/mzLT2p+I7Brdm2Ro A+Lw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AJcUukfzsgx5CPLmXnzDsU6UmVz1eJSWZjtHRzQRIwSSIw12Om2Tu/TL U+V0gKrpaurZBLmOc6hxuYVF4TwnUIZRg4k4cGmdJAIWH5KUUS4RC+O63QJVALMaNX3pz9YPOQB OAHkve08dwPMnaQWys4xT3BlgtlnKEQWtL3XJQqtbTD9f1tzGBakw7n2Zg+nCs3AZKQ== X-Received: by 2002:a0c:95b5:: with SMTP id s50mr24804266qvs.64.1548057588985; Sun, 20 Jan 2019 23:59:48 -0800 (PST) X-Google-Smtp-Source: ALg8bN5YqqNao6b4Hw9DWhKdTuCXwg594EUi6dQS0mavo7DNHR5csiuDsUVRBYKz4tcwg4mpkRKc X-Received: by 2002:a0c:95b5:: with SMTP id s50mr24804245qvs.64.1548057588505; Sun, 20 Jan 2019 23:59:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548057588; cv=none; d=google.com; s=arc-20160816; b=Xy10TYmQ89iaPvsWsudLU1IK1h8KZ/Qtl24OWucALmsQqOQgv3VgqDL6DceA6Sa84f NqbhjVSx8SHhqyvuv0SWQkY23YoT9iUo1IVyUUk+WME6tD/94jP+os6fb7Qs5egdpwaa bEjKW6sozGBqioyKpPE1CzvHKg7MuKkazjLrf7Ga29SGEaKwFOIld7x/aiSHvXZJbWpC m7h0uIZYk7LXsHoar6+EdLHLExo2p/Du2cRaHhk8hClNWFd66m43SSleFSZKpC1FqwXW a07ZUNo03NWwMy4X555Nlbmi+LN3fIMCSkIZNOV/23iUUn1A1X67yvfDtqFaag7rj1P8 Oqtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=CMKcOJHBuk/LOB9JBPR9KTuaFj4SKYgIxDPbqbU3Psw=; b=L3HjYoSvlE2SPlLgAXOOPBUPIJDeL8FkJZUwFoAoUkeNJhfif/nVD8GHupFuB2BVlO wMR/UqjRStWW3MdIzzKoyBwY7/lt9DC1Atb27H5znMfkmaYMWZUMuXUssfveJUxSTpnM 6oiAAsWdz9+DFdsz25gZFPcOC5k0WAk/F1lENtaDKL/9o3HUNguEJwykxbOm3/zsmRXl HWHEYmG+4n4WHjyR2RicoGe0AeGSVJuDbQIdrT2+8/9yoToMJtIEeOSCxMUJuXAQnNsQ g4OSIesBA3R0arl+oj13L8dn7zy3oyVR+ag+aheeBuG+WaO92KP1+fvHcNdYqnuxO+XY ia1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 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 (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id b16si11661148qtp.115.2019.01.20.23.59.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jan 2019 23:59:48 -0800 (PST) Received-SPF: pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 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-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AE09806B6; Mon, 21 Jan 2019 07:59:47 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-116.nay.redhat.com [10.66.14.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B9F5608F3; Mon, 21 Jan 2019 07:59:39 +0000 (UTC) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , Maya Gokhale , Jerome Glisse , Johannes Weiner , peterx@redhat.com, Martin Cracauer , Denis Plotnikov , Shaohua Li , Andrea Arcangeli , Pavel Emelyanov , Mike Kravetz , Marty McFadden , Mike Rapoport , Mel Gorman , "Kirill A . Shutemov" , "Dr . David Alan Gilbert" Subject: [PATCH RFC 17/24] userfaultfd: wp: drop _PAGE_UFFD_WP properly when fork Date: Mon, 21 Jan 2019 15:57:15 +0800 Message-Id: <20190121075722.7945-18-peterx@redhat.com> In-Reply-To: <20190121075722.7945-1-peterx@redhat.com> References: <20190121075722.7945-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 21 Jan 2019 07:59:47 +0000 (UTC) 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 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. 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 169795c8e56c..2a3ec62e83b6 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -928,6 +928,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 a3de13b728f4..f5497752d2a3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -788,6 +788,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);