Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1366880ybi; Wed, 19 Jun 2019 19:24:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxsWmNViOX4BdpGJ/WBjDNjOeVAS2OocXePhFzm0ypKmuz+T7jTnWQ/y6Ur7G2lpdxdG01r X-Received: by 2002:a17:90a:d14a:: with SMTP id t10mr409162pjw.85.1560997464504; Wed, 19 Jun 2019 19:24:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560997464; cv=none; d=google.com; s=arc-20160816; b=qVrCL3ejQPwx82Z9czsfHMTq5mYJGwpKd0+aYAEjfW57Fy1knerlTb40O4/axLawqH lKbt4VkJn0l3phJo/PEUgVMNQsUG/7KwlfzAjPWF/r7YvvF84USO1ltAGw727nBWCWcK BYCeH1F/0Bvc4rkiB0tmbSC4bCLhxMCX5hkWIjwdUg1tTp6f/yvZ5lB6SlMlxZXN8KUi q8AY4dgZpJgONah0u7vXDqkGz23K0Qbn64ChZ9use/pbG9eNFRDS46+AvgF0qEzAHsNe 0lTGbjRw6K9moIIwSAtwPG+EQH246/GAbSjAg4UZP0sWmLzxXFpiePNcXktVk8kCI0h9 bePw== 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=jN8gpQC/k7eZtjFNJDwsdS9nBmHNvi88dujJcJMSTFw=; b=P9TlsBf0/+h9drKQoTJG5KWvlapIGyEamzUzD3YeU1f3+oPftSPIkqHmnrR5hqCw1c 0JaSjejJar8OiLCvATkCUDEk0fqxaedXgmrOVHkvyocVvr8F7QoK7Sl3CBo+h6caGD35 miv/z6ZEQVGarJ00RjRDTuDnKQ4AqQb44gfM8BVhpe1Eq7U2De9ibMSfQ2p/+6I1Zo4e J8fYYzT95RU8KPL6OIKvNaP6ScyTIQTwl/zmPC+ziN3yrD6Pe2CqvOXUu5RbW1MHmgGH EgaKJNzVpQX2Bujo4VkKxN3/uv52ZhS+OHozjs0qsFyXLT1MbpqVpVTydDv+A4W0R07I Mbwg== 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 g12si2748487pjs.35.2019.06.19.19.24.09; Wed, 19 Jun 2019 19:24:24 -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 S1731459AbfFTCWO (ORCPT + 99 others); Wed, 19 Jun 2019 22:22:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35976 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726480AbfFTCWO (ORCPT ); Wed, 19 Jun 2019 22:22:14 -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 D444F1796; Thu, 20 Jun 2019 02:22:13 +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 6663E1001E69; Thu, 20 Jun 2019 02:22:07 +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 09/25] userfaultfd: wp: userfaultfd_pte/huge_pmd_wp() helpers Date: Thu, 20 Jun 2019 10:19:52 +0800 Message-Id: <20190620022008.19172-10-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.29]); Thu, 20 Jun 2019 02:22:14 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Jerome Glisse Reviewed-by: Mike Rapoport 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 5dc247af0f2e..7b91b76aac58 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; -- 2.21.0