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=-16.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 C94C5C433DB for ; Fri, 12 Feb 2021 21:54:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 67A9764DDF for ; Fri, 12 Feb 2021 21:54:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 67A9764DDF Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E7D4B8D009A; Fri, 12 Feb 2021 16:54:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DE9E38D0060; Fri, 12 Feb 2021 16:54:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7F198D009A; Fri, 12 Feb 2021 16:54:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id ABD078D0060 for ; Fri, 12 Feb 2021 16:54:24 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 777B418332C43 for ; Fri, 12 Feb 2021 21:54:24 +0000 (UTC) X-FDA: 77810970048.03.anger07_03010cc27624 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin03.hostedemail.com (Postfix) with ESMTP id 58D3128A4E9 for ; Fri, 12 Feb 2021 21:54:24 +0000 (UTC) X-HE-Tag: anger07_03010cc27624 X-Filterd-Recvd-Size: 6440 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Fri, 12 Feb 2021 21:54:23 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id t6so1005527pje.9 for ; Fri, 12 Feb 2021 13:54:23 -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=gu7tdY0Aew2YyZEezQ7c9umemvdMZgwicALrokdOWMenBC66LvRUBUZZwxH7BzxG/E ZpjnegJDQHkgGpUEMz/K98+htbrreMO9jYWmAZPxi/zHULzdO1n8um5+wjfMa8uOkwad h4mKPHvnxtUYQUruUEVPqJDxjWRv8+GysvahUQOtAzx1arLj1CKxKsO7GFy16VwdkDS7 aAsRKigLV1weoyoY3IUmtesZdUZ8jQYoIByWy8eUO1eYEso60JzPknBpRbWlOJLPKwgA 0Rpz02uzuwVDONqQvJ+OqiglsFW4KUmCKpRarLv50M1oXXinDZnnayMxioPnTNKfFfIU /lFw== X-Gm-Message-State: AOAM532oaoKrWFs2e0sTXSVx2T+HKjV88Q4KYmZIBuk+ErpNeXHcUFQE sP1NDLVoH/tXy3rAAWJ3h/EZo7JQYo6hvEixpW2V X-Google-Smtp-Source: ABdhPJwGFRdVdg0cd7jePQFHLBhd+X3gZzHYFwdheoONEE1KBWOaidn+Vm+YQFlcd9yaV231OScKlUtfWhrhA94tO2JM 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" 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: 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