Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1655630pxb; Wed, 10 Feb 2021 13:27:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxft6nS/ehBNYUUG+gY4M7M/91PRduIUZARhvWtbG2Y0O7mGkKvteiXPdAiXI8ByxpoDAdx X-Received: by 2002:a17:907:3e06:: with SMTP id hp6mr4981618ejc.254.1612992475457; Wed, 10 Feb 2021 13:27:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612992475; cv=none; d=google.com; s=arc-20160816; b=wDXNdbJaR1jTZxKgkfcaS01vRrRlo+aHee86r/vwxNFxZKf7dpgiaXaEY6954mRy1p ihixJef6xi3CA/eWQOSmxBNowLL3dXzpEAdRl/NjMVCcfaZZnnf+wTHU8lvbtzyFa80q PANA9JZSFYZ7ceZXQLhay1asID5J9RxKQe9HfRNvURbfagbWZJqnfNsMsLkelrNtWuit yBddDmCmRVjqa7gLdyOEDTEDlCOu++gnXsYwNZhQbVYx7LxJZk6jxXRD/afeEPyHqK+t svafwSf4IJP9uYBzIC2dPy8uVjQDACb6SbBkgEn+c0ODGohe5fAJzgjQFEuNoZnzBf93 0cAQ== 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=C7eX4+NVGX5He9yBXKDzK09THiAFk9zxs8Mq4BgC9+k=; b=xdLSrKqqiosWVUao5gtaAeiXuczOtqwX9lvtpUqn7kMvSMD3yoxnCcaAE1AROoHHWK J6jBV0MwUfJw+eyjPYd7GGSAfN72rHlQsBwHqMehOarITVFWVIoliSqCqQgolUe8cRO9 e19QpNQLI5evN6qI/xJqzPlukJ7J4O1py+aAH9gcJPBYQK6a/ZsNA3HE8eV3J2eVWUuc UD3Ttl/EzSJx0UxC8a75rHIHjT1/8kwbruVhUk05RUO2UrO1U4m05FOP/gVD1Xa9zfiI fLSqi+ZfzwMWC3uVstknqTksB2DbOsyDZi6kP2B/890pHU3LhOevL0beV6yN04XdlJMl 5D7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=X4O2XnKe; 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 dc19si2048936edb.348.2021.02.10.13.27.31; Wed, 10 Feb 2021 13:27:55 -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=X4O2XnKe; 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 S233450AbhBJV0B (ORCPT + 99 others); Wed, 10 Feb 2021 16:26:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233454AbhBJVXB (ORCPT ); Wed, 10 Feb 2021 16:23:01 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 047C5C06121C for ; Wed, 10 Feb 2021 13:22:18 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id w11so3922559ybq.8 for ; Wed, 10 Feb 2021 13:22:18 -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=C7eX4+NVGX5He9yBXKDzK09THiAFk9zxs8Mq4BgC9+k=; b=X4O2XnKeTyP1mrCdcCUv43l+RzH7IHrvPnQey/wsi4M+B7W6hzZlGZRvvKHgHPwxwy /WvTVU9Ez2URRDEtOOJilnHqyhVt6olC/GaNJXdnpvVpPBeGB4gNunb7ZQQAvUfzsdxe edZieAb5VYpDFXolL8aMA/zf1+cab8/dJJYDrbwRG+GaG11wlghI8k3l4/uai0ppkIOY VRGXu6go8MCoW4HFmNHNxwfTbMwbVHMUk2ma8RoEvXxXQ4B5PVnkOj5fjrgRZZ2y3LAP 0DBfUQeu/ImT99KF9thtVNcUbahpM0amXl0cGg6p/tFca2fEUDbwL7TN4RyPqcPqmPCr FDgQ== 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=C7eX4+NVGX5He9yBXKDzK09THiAFk9zxs8Mq4BgC9+k=; b=Xu+q8qmI4s6DKF8rQ/2FgMl7tLFEWrwvFOD4fcaH49G5iv1SG1zfcxMROnLgdDXT9L Ouft0cK8l+rYxawu0vF6PRJwEk/3NEZY4ehuyn4H/bBMiQpCfbS8M6nRAuBPyte+mMor JE3a4SKRv5GVr4Al9m3+KqsB9yDBg2hlqrUuUo46Zab14iQZdIhFKe9QWlDSaO/QfK4l dcr4BSRnd+Bq/AxSZ1QioF45jSaCK6h9B6LUuSC4ATE4iIc1/xiwbGxCQLlPQzafm+Nj B1RhPK9bImJWvLvpTb4JpHGOI5fM8KTPYBOfTxbbRE7U9J6p+2tJAY9pPj+4rmMi9Gto FY5w== X-Gm-Message-State: AOAM533wk/D/mDBzTF12e0hqyFVZk8s4OnN2WccVLM9nfOA4rDgrAtfm sAyiIJscybZNGKMDtOFHDK4caUTm9kahQRD4y3LD Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:94ee:de01:168:9f20]) (user=axelrasmussen job=sendgmr) by 2002:a25:cc46:: with SMTP id l67mr7659356ybf.16.1612992138150; Wed, 10 Feb 2021 13:22:18 -0800 (PST) Date: Wed, 10 Feb 2021 13:21:56 -0800 In-Reply-To: <20210210212200.1097784-1-axelrasmussen@google.com> Message-Id: <20210210212200.1097784-7-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210210212200.1097784-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH v5 06/10] 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 , 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. Reviewed-by: Peter Xu Signed-off-by: Axel Rasmussen --- include/linux/userfaultfd_k.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index 0390e5ac63b3..e060d5f77cc5 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -56,12 +56,19 @@ 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 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 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.478.g8a0d178c01-goog