From patchwork Mon Jan 21 07:57:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10772805 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 C44A51390 for ; Mon, 21 Jan 2019 07:59:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6A1C29C15 for ; Mon, 21 Jan 2019 07:59:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA29C29C18; Mon, 21 Jan 2019 07:59:08 +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 4676D29C15 for ; Mon, 21 Jan 2019 07:59:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 59A448E0005; Mon, 21 Jan 2019 02:59:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 548148E0001; Mon, 21 Jan 2019 02:59:07 -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 460828E0005; Mon, 21 Jan 2019 02:59:07 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 1F1E28E0001 for ; Mon, 21 Jan 2019 02:59:07 -0500 (EST) Received: by mail-qt1-f199.google.com with SMTP id d35so20293551qtd.20 for ; Sun, 20 Jan 2019 23:59:07 -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=NbmjnZLLq16I7ddzT2uJLYevedAg3DqF8/tVlLBRIBA=; b=bmCOXtSx9lnYursZLngSP+/HwTDlYAhD7YkCYGVtIsV2rFT8ypnM224ybvLIl1/BfG o3R09K1RkSl1Qn/4Gscp2Qnyude6kqIhz3fDmr8nyASJL+cUFgTa+oz+1SDJLFMyQiOf 4f1MxrJFNCIlZlbbQ1oPVo66K91vGglpoJPYCgCW03CMBJ92B7JWT6sUSJCvORweh4NT p+7T5q+B6FK51o9vhBG5UaOfdhxhc2yVgrkPFuVoCCbcn/zuW+NDjWnE1cE4361z1P4n IvKUzFTcq45O/8yNcLD59ZKG4RyryOveDKbz4vrTM7zHZDKL4EjJN2oHhpuXG1GuDO1w 9FkQ== 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: AJcUukcdg1zxDIQ2rJtVofLGQ12tice/LU6ZR3zwcJyxZFUPPP1RUjoZ MDYcNeXMZpxo8VcUXA9nhWp6a/2V4sJYQ0dXSWk8M9zwhp0eeWgZvV1YwQPDjbgFfIVS01yPq25 H2xmHC1OateE1l/7nYMhfAKDcRkDdqs7Eh+HjlL13RhZIWeymN6k2jAmwmDnR16/ZcQ== X-Received: by 2002:a0c:e40a:: with SMTP id o10mr24179821qvl.197.1548057546919; Sun, 20 Jan 2019 23:59:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN6tz+ez7S2Iyl7tRWYNs3UQLh6lM3fYZD2wjss72/AXFqe4x712ZsJFg7Q4GHdl72Fq/Ioo X-Received: by 2002:a0c:e40a:: with SMTP id o10mr24179806qvl.197.1548057546480; Sun, 20 Jan 2019 23:59:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548057546; cv=none; d=google.com; s=arc-20160816; b=rB++37co68pMO3K+4fR8aHFsH0rp3hnmYu2XNgKQlNd1LMUlu54jsGrArnUuN2zlA8 mozRRKc+yo6LWD1OqucBsYcOIkKUcC3kgK1RZqtajm7u1JcIYCNyKQUiz3YByYei1F2G 789aCSb4BZIFUU3EQTaFdNNk+muHIjOvzLEWzwwekgDVvrq+1BcIQD1G4/0xpKuIDRQQ oLhEpYeGRcAs8iXZbIzWNL9ctbkJRyMPFOOLkI8jed2R9NcJr2WyQGz+eDaz3j/KHSfx Z0JpNb9+1k1uczvgHaJcjmvgyeVf3MSPm9GvH9MGAjsgvgCz/vx1vXrrjV4XDTCMGlz3 9B6Q== 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=NbmjnZLLq16I7ddzT2uJLYevedAg3DqF8/tVlLBRIBA=; b=VScPny8zGXtWdRtpJoQNxOin/ZAIwMBV79/xeL+LQy2O8m0cxXFjwR2ALVi6piVMZ0 3sMAPr91TQL8QIc3CiuuVXynfg7L016rUAPcNxNSfX8TAGbDm/+xZKEd8+OIWAG6SHT/ YIdNEf8PsFz/BFan8+ODgfjfcq+cDBe3rD+omk9ZGonKzyjx4UwQ05JBDOVn7VpSdyJE mnadvkL6/7U7DIcIiMtXxv2PEbgptSQ4QMBpnSKSjZXbEZR77TK6KxLDiuYaCAQgo+9b IMKRDHMxuZoRj6dOf7px4806Fk7aWn/nTUC1WxA+M33rvy8NLX+0DhY0D/BbZ3UbgMmU 1ptg== 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 y36si5656021qtd.218.2019.01.20.23.59.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jan 2019 23:59:06 -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 9A1EB9FDD4; Mon, 21 Jan 2019 07:59:05 +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 62EC9608C2; Mon, 21 Jan 2019 07:58:57 +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 11/24] userfaultfd: wp: userfaultfd_pte/huge_pmd_wp() helpers Date: Mon, 21 Jan 2019 15:57:09 +0800 Message-Id: <20190121075722.7945-12-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.39]); Mon, 21 Jan 2019 07:59:05 +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 From: Andrea Arcangeli Implement helpers methods to invoke userfaultfd wp faults more selectively: not only when a wp fault triggers on a vma with vma->vm_flags VM_UFFD_WP set, but only if the _PAGE_UFFD_WP bit is set in the pagetable too. Signed-off-by: Andrea Arcangeli Signed-off-by: Peter Xu --- include/linux/userfaultfd_k.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index e82f3156f4e9..0d3b32b54e2a 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -14,6 +14,8 @@ #include /* linux/include/uapi/linux/userfaultfd.h */ #include +#include +#include /* * CAREFUL: Check include/uapi/asm-generic/fcntl.h when defining @@ -57,6 +59,18 @@ static inline bool userfaultfd_wp(struct vm_area_struct *vma) return vma->vm_flags & VM_UFFD_WP; } +static inline bool userfaultfd_pte_wp(struct vm_area_struct *vma, + pte_t pte) +{ + return userfaultfd_wp(vma) && pte_uffd_wp(pte); +} + +static inline bool userfaultfd_huge_pmd_wp(struct vm_area_struct *vma, + pmd_t pmd) +{ + return userfaultfd_wp(vma) && pmd_uffd_wp(pmd); +} + static inline bool userfaultfd_armed(struct vm_area_struct *vma) { return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP); @@ -106,6 +120,19 @@ static inline bool userfaultfd_wp(struct vm_area_struct *vma) return false; } +static inline bool userfaultfd_pte_wp(struct vm_area_struct *vma, + pte_t pte) +{ + return false; +} + +static inline bool userfaultfd_huge_pmd_wp(struct vm_area_struct *vma, + pmd_t pmd) +{ + return false; +} + + static inline bool userfaultfd_armed(struct vm_area_struct *vma) { return false;