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.6 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 97C6CC433E6 for ; Fri, 22 Jan 2021 21:29:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3C37623AF8 for ; Fri, 22 Jan 2021 21:29:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C37623AF8 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 3DBF46B0029; Fri, 22 Jan 2021 16:29:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 33E1E6B002B; Fri, 22 Jan 2021 16:29:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16A946B002C; Fri, 22 Jan 2021 16:29:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id E827F6B0029 for ; Fri, 22 Jan 2021 16:29:42 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B45689888 for ; Fri, 22 Jan 2021 21:29:42 +0000 (UTC) X-FDA: 77734703004.13.head93_4b0d4982756f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 97E1E181DF767 for ; Fri, 22 Jan 2021 21:29:42 +0000 (UTC) X-HE-Tag: head93_4b0d4982756f X-Filterd-Recvd-Size: 5885 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Jan 2021 21:29:41 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id s64so1904888yba.20 for ; Fri, 22 Jan 2021 13:29:41 -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=MPwAJ6+DP3gIY4R9V98gU/QUOgUfEvMZgCw03h5dW3o=; b=WYQGdSXW9Dowjq/tEtiJqYSTEnelLtZWHHwZiMQ94JhsG1GVc6oXRQMkpKu7eDAnHv NKg5GF6ig1ZApuH4agXonVwcgSdI+18UP1rEYDJjiagiX3nla69C6i534XagdKIa5rE/ stPFS97wq9OkZoeiz1rFi1x1kJZsS2k9umbO6YttlIBN6TmYynWgLi/QmC+NEZMItDTO 9ysUFg8CGvemV55rGYVD9R4kBsLZU/1kcscl/p0tmtk7bRUTGBNMM7r2jE3Eu/jv59Vv SJiRApl3UATIW3JdL0kjcsHrNtMWZkb94lqg3baFBxmKgHWZhyt+UWO78Fr7MO3m0ey5 ztKw== 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=MPwAJ6+DP3gIY4R9V98gU/QUOgUfEvMZgCw03h5dW3o=; b=cWQ30cHDj9zgc8GEHRTb7HUUvN9YTa0pWKv/fySPETLJ2qnPGeaYKzthUKBYy3xhVj 40/+9/EDOhkvfq+ZlVn1/oVD8VApaYmbiqbHUFBPGrPpJQMBaqmtall8wq/Nj7iN8dr1 Fvy/hog+qTJ0sfaN6zM6RjPTTOOt4R2g9C28Tzww/TYGR3ymVYIwOWUtxLMFCOEws+uo IBxBO2iCn7Yiam0JibJuO1dD8v4HH9555qG0EtybDgabDQn3Vq3o7/0we5i2FKYlmETy +PfY1fEiHvLhgBSSWJphwkb8zOvyc5zzTepgvRm4imoYnol3rPybFsCPYgEnmSm3xjXX HvqQ== X-Gm-Message-State: AOAM530mTvEdxa0fUwgf4GjF9N58kWp2jQNdHtNJCxUnrbBhOrDyQgEu ztJo692I1TPAHJ9M3+x4LpvmcuCOvx5uP4fzzqQd X-Google-Smtp-Source: ABdhPJyHx4pF16cMtKv8VUHxhdr6uUrqdN7OvpRpZ9uoUtGCjEIg5DdoSNeVrersXyA8X3p5MBqwn7u8giCGUi5oMp4a X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:f693:9fff:feef:c8f8]) (user=axelrasmussen job=sendgmr) by 2002:a25:c6d3:: with SMTP id k202mr9150649ybf.284.1611350981237; Fri, 22 Jan 2021 13:29:41 -0800 (PST) Date: Fri, 22 Jan 2021 13:29:23 -0800 In-Reply-To: <20210122212926.3457593-1-axelrasmussen@google.com> Message-Id: <20210122212926.3457593-7-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210122212926.3457593-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH v2 6/9] userfaultfd: disable huge PMD sharing for MINOR 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 , 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 shared 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. Reviewed-by: Peter Xu Signed-off-by: Axel Rasmussen --- include/linux/userfaultfd_k.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index 0390e5ac63b3..fb9abaeb4194 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -56,12 +56,18 @@ static inline bool is_mergeable_vm_userfaultfd_ctx(struct vm_area_struct *vma, } /* - * Never enable huge pmd sharing on uffd-wp registered vmas, because uffd-wp - * protect information is per pgtable entry. + * Never enable huge pmd sharing on some uffd registered vmas: + * + * - VM_UFFD_WP VMAs, because write protect information is per pgtable entry. + * + * - VM_UFFD_MINOR VMAs, because we explicitly want minor faults to occur even + * when the other half of a shared mapping is populated (even though the page + * is there, in our use case it may be out of date, so userspace needs to + * check for this and possibly update it). */ static inline bool uffd_disable_huge_pmd_share(struct vm_area_struct *vma) { - return vma->vm_flags & VM_UFFD_WP; + return vma->vm_flags & (VM_UFFD_WP | VM_UFFD_MINOR); } static inline bool userfaultfd_missing(struct vm_area_struct *vma) -- 2.30.0.280.ga3ce27912f-goog