Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3271961pxb; Fri, 12 Feb 2021 13:59:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGkTyNSPy0yHAw+GenFSS5fxJxbPSg3njZgu80fQ9z0pVav224fJ83+vUOyTapjUdD0d5R X-Received: by 2002:a17:906:3006:: with SMTP id 6mr4991655ejz.448.1613167158621; Fri, 12 Feb 2021 13:59:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613167158; cv=none; d=google.com; s=arc-20160816; b=krmViK8P8QbcrGKKHFqGk/qPsaiQHXpAnLFVXoBhNgdxe6ts3RMXoAJpJ6Gh5yrnx6 WmEth9kyYedd3tLxbtZ+IhlW+p53SWwbkhzjWGiPvOHZv5EFUTcqrXeicrTUCK8Jz/v0 t6G9bXeTW85x7iwYg9IMWdYZIW5mv3d5c4KE9MLjwDno4TvWpY6ii+Dmh2ZSE+um+MtP nwvdNTogCquBn+AeFRD/r72X6AS2ESU6Dgt8jEw0x8JFpmaVWFtN3ZUSQ3FwF5HURXBy VjLNM8BIy+quj5U2aqba9+kwIjocVPuk0h2iSM+4VgDqI1DGrwHCKTmq0ohOgt1THnMv BApQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=YlfIormFBY/rysSGqj+ed5treI/R2/QqIMyWcQNPNXw=; b=CO3F8tfOQwaLQaU50e3AnQ5qmAueRN3VD4pWV7TOs+KswoqBr0wJZ/hrZTnphAi/fd B3WYg7c7HV6mMEh6POIHGnhiC0lXnMHSLj/Dx82B80O7R0Tot2mlp53T13UWs2BWZWAH ZpPNe6IoWl+F0WQRXFpZgzksybkScYf231+xdAs8UhN4Jq2l+LiugFCsZaGS8xRL8VIv YJxtbqUyCM32njzKpbCzgzq1MOvmCek4Girpt8alElCpyS1WjJvghFmg1YCOVHhugNwe 13We95Pdpl8AvNGNHW28kRg4U/LmLS/cuDgTp0mKCtPPMULW0r9zj8o/GqypGXZx01Hv 9Krg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CTA6VBPT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h7si6958920ejx.623.2021.02.12.13.58.55; Fri, 12 Feb 2021 13:59:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CTA6VBPT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230263AbhBLV4u (ORCPT + 99 others); Fri, 12 Feb 2021 16:56:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230494AbhBLVzk (ORCPT ); Fri, 12 Feb 2021 16:55:40 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFB53C061794 for ; Fri, 12 Feb 2021 13:54:26 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id e11so905852pjj.8 for ; Fri, 12 Feb 2021 13:54:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=YlfIormFBY/rysSGqj+ed5treI/R2/QqIMyWcQNPNXw=; b=CTA6VBPTeFoAytyEos3lFWsVfDnGleeYtmq/FweYdKvW2QZB2YOJ2iA5510aDYkwwm f1M4M0HXg164r7mCCQYA8E96Khx3lIUmOQCYKUU6G88yAzBKEo21KmMcQvRZeWO37DMT GuCm3Juq29cIL78PNFnwnb1evyu9ZvJY7rMy4EV+45WqOfBr00LinEOZ0kn4BPWi1s/v IsevNgCw4AzhAORs6F1A/oWmx8boULq3Uhrrc269HT0dzBi5x3fTSVlMO+xQ5ZMxjK7L E70c3DKqkObmpcmJsSksnqXlyE/pVf++EDEpmdEg0e2ecnMT9pcJVoet4SwErpYyG2sZ zHzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=YlfIormFBY/rysSGqj+ed5treI/R2/QqIMyWcQNPNXw=; b=sF/MsZW3wJC57wkZfwb5GQl+95w8jMc3qYGWLwRWVRsTYubMWbDfxTNtGZk82c5oqS kg5ScvHCoPwgWWc2xjtKShR5FaceF+3FXpdTB0VHWsj7LQSh4cWhKrwuBvVF1IlFDI3C uAKbmvTJbdC61IW4x2CjY63kAhXlt7gbrmq6vEXh43VHKGmzkTgdsku2UVNDQtRpoMVY K3R7ipNnt1QvDySiEUaa0d5DxdggWf8QLcHQwbaDt8WBJaIxeHFiOQMOi4FDId1yOm7E fEgyRF5lcz5/DAE0d3nzss0SyLWmoOWYKjqA33iA6AdwFtH24egfXVLdz4zTndSXdP/P HSbA== X-Gm-Message-State: AOAM530MVLO2QcMtvoJNEgv1xgBbwMNDDb3nVqC6MtDYsY9tF6TJaUig +pN1Np+4kOzwmOOLbJCuBPuKnGYF4z7hvCQZ+jSX Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:d2f:99bb:c1e0:34ba]) (user=axelrasmussen job=sendgmr) by 2002:a63:da4a:: with SMTP id l10mr5133633pgj.222.1613166862664; Fri, 12 Feb 2021 13:54:22 -0800 (PST) Date: Fri, 12 Feb 2021 13:53:59 -0800 In-Reply-To: <20210212215403.3457686-1-axelrasmussen@google.com> Message-Id: <20210212215403.3457686-4-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210212215403.3457686-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH v6 3/7] userfaultfd: disable huge PMD sharing for minor fault registered VMAs From: Axel Rasmussen To: Alexander Viro , Alexey Dobriyan , Andrea Arcangeli , Andrew Morton , Anshuman Khandual , Catalin Marinas , Chinwen Chang , Huang Ying , Ingo Molnar , Jann Horn , Jerome Glisse , Lokesh Gidra , "Matthew Wilcox (Oracle)" , Michael Ellerman , "=?UTF-8?q?Michal=20Koutn=C3=BD?=" , Michel Lespinasse , Mike Kravetz , Mike Rapoport , Nicholas Piggin , Peter Xu , Shaohua Li , Shawn Anastasio , Steven Rostedt , Steven Price , Vlastimil Babka Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Adam Ruprecht , Axel Rasmussen , Cannon Matthews , "Dr . David Alan Gilbert" , David Rientjes , Mina Almasry , Oliver Upton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As the comment says: for the minor fault use case, although the page might be present and populated in the other (non-UFFD-registered) half of the mapping, it may be out of date, and we explicitly want userspace to get a minor fault so it can check and potentially update the page's contents. Huge PMD sharing would prevent these faults from occurring for suitably aligned areas, so disable it upon UFFD registration. Signed-off-by: Axel Rasmussen --- include/linux/userfaultfd_k.h | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index 4e03268c65ec..98cb6260b4b4 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -62,15 +62,6 @@ static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma, return vma->vm_userfaultfd_ctx.ctx == vm_ctx.ctx; } -/* - * Never enable huge pmd sharing on uffd-wp registered vmas, because uffd-wp - * protect information is per pgtable entry. - */ -static inline bool uffd_disable_huge_pmd_share(struct vm_area_struct *vma) -{ - return vma->vm_flags & VM_UFFD_WP; -} - static inline bool userfaultfd_missing(struct vm_area_struct *vma) { return vma->vm_flags & VM_UFFD_MISSING; @@ -83,6 +74,23 @@ static inline bool userfaultfd_wp(struct vm_area_struct *vma) bool userfaultfd_minor(struct vm_area_struct *vma); +/* + * Never enable huge pmd sharing on some uffd registered vmas: + * + * - VM_UFFD_WP VMAs, because write protect information is per pgtable entry. + * + * - VM_UFFD_MISSING VMAs with UFFD_FEATURE_MINOR_HUGETLBFS, because otherwise + * we would never get minor faults for VMAs which share huge pmds. (If you + * have two mappings to the same underlying pages, and fault in the + * non-UFFD-registered one with a write, with huge pmd sharing this would + * *also* setup the second UFFD-registered mapping, and we'd not get minor + * faults.) + */ +static inline bool uffd_disable_huge_pmd_share(struct vm_area_struct *vma) +{ + return userfaultfd_wp(vma) || userfaultfd_minor(vma); +} + static inline bool userfaultfd_pte_wp(struct vm_area_struct *vma, pte_t pte) { -- 2.30.0.478.g8a0d178c01-goog