Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp223088pxb; Thu, 25 Feb 2021 00:17:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbum0VFvA0nhe2Es2sD+f82OUZ0WxU03IVxS1ldU39u0UUCG1LXRmTLxDfd7FrRs5wYpjy X-Received: by 2002:a17:906:f18a:: with SMTP id gs10mr1565516ejb.341.1614241038791; Thu, 25 Feb 2021 00:17:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614241038; cv=none; d=google.com; s=arc-20160816; b=LPSqY0TzFvmUgUIP++l6wweL/0c9cC76ImO93jdcSx/WZQRqTcE5TfuVPIFOLQWwla YtiGwsqeZhAUzyRpqoImOcnPpizTWlZ3I4ToNEtLXKJtyMulVEYUKVr6nrXLILbFHyZv oBe32m2lpJLjCQmT3ZlwOxEavEQrtStrnROv7heN1VBBeis6rEg+BejONBTSy63ORZFm P9u/1J+LKIEePAHNkoeONLNcWsXZkR1n+Zuq/pAjl4MpmSs+5pO39E3QuSnPk9aAE1Dv JqrPlmUYDr54FmVEW7y1ZbQp9KpDJ58z9ZUBgqSUmMOr7xgwo9qyRsPtjS0JqSNwZTi5 zqew== 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=Gqbdv7dcKJ3HCSbhGAkcVMLKp5XjaZ2pyZBQ0WD1HYc=; b=QjwqFFBhhrH9HXDkXyP7gFUKoDusBpIRqcPBtzlqj3gCOxPLabIkprvFVKYgOY3S3F IEt4Hx+CU1FbU/OXLz+3WuGCCL5Z5kxAFwal/7DJ0eqX+/rFqRzeSPVwjaQHHr6iDtaV wjUcJYcg/kKERxGLi4iZzL7+Hbu3rnW0Y/aAnuxQk9IaKIU8p89VCEtaK0I1zwkOEhLc +OmicN6xuIvUjMf7ASbEu3dNfDz4g5wHZitACp9LrYQ439UoFImpo/lOAW01zg48vdo5 yapQgig+N4iqagwOAbsfsBItyN5m8SyUQPyaUCEQDl07zA4k+QmkOLyMEkbvwf3AhR6m FtWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=iQABgmB2; 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 m12si733889ejx.720.2021.02.25.00.16.54; Thu, 25 Feb 2021 00:17: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=iQABgmB2; 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 S236403AbhBYA2S (ORCPT + 99 others); Wed, 24 Feb 2021 19:28:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236376AbhBYA1w (ORCPT ); Wed, 24 Feb 2021 19:27:52 -0500 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7876EC061788 for ; Wed, 24 Feb 2021 16:27:12 -0800 (PST) Received: by mail-qk1-x74a.google.com with SMTP id x21so3141942qkm.19 for ; Wed, 24 Feb 2021 16:27:12 -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=Gqbdv7dcKJ3HCSbhGAkcVMLKp5XjaZ2pyZBQ0WD1HYc=; b=iQABgmB2nLQqaKFyd+0m8gvgul2Nt+XEMSupc3YU+qI9MdQ6eucQVi37eJUoliHxGc OCA3NnqnU0jVrAPr6wJdk3zwxFyRkq+GqYdIMH7GKD9BkNJKUAZdzcpJ/WYkwuIVfhHo MaUfU84qw3yu0dvwnEga90NViMOUtE5V3Qicxd5SqkolYKOv31XWFq6wa8zduh/NmSgY XY84n067XFrVpjAncfw/6qjH75qZVlt6Z+XyGvVZeJhdTxVXr8gGI+LIbtVIAJ2TWosG GNO1H5CyC1zMdrXCjCEpGj8ujleA4lr68NUOhYwhlhplb8jOusKFkKYl49EDsMiVJI9D kVng== 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=Gqbdv7dcKJ3HCSbhGAkcVMLKp5XjaZ2pyZBQ0WD1HYc=; b=JCKg1x3pEAkudl8+DuRfV6IK3zYUE0aRZ3oakmhKGMcfVcnGSg0zUEgJAnnOum44Hw a1I0V2QD+YyG2jS/qvb1BrHGy36A5QbKgx6Jv1pNwdINrvVE8bfjkAvhte5oqBdax786 FOqQBD70oUxbswJ9W2IYnCgyIsQLFBOIsX+x7Dp+A7jfoH/X5ApP05iz5yyuh3QwKTAw 3fX9FFlKkEnVNJpOLxCzyLDKjb+W+kttYqckCiqMjXdn8N9keyVViAZw5xoZX3sfp7gx 7SKWaO3AU4+gl7rXXn0IIdk0K9cHhC1/W3P1YzlZqnWRh4WlKmXaUZZmypxjkm/756P/ oa4A== X-Gm-Message-State: AOAM530ru9x/sz0syI2ly2LQJm8bcqeovITSz5eBzh5nf4ukOZuokokb QXiizQT1m7qS5160MS72kCYiCuTJ1QWUjAZtYTvl Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:a5fd:f848:2fdf:4651]) (user=axelrasmussen job=sendgmr) by 2002:a05:6214:941:: with SMTP id dn1mr237760qvb.61.1614212831623; Wed, 24 Feb 2021 16:27:11 -0800 (PST) Date: Wed, 24 Feb 2021 16:26:54 -0800 In-Reply-To: <20210225002658.2021807-1-axelrasmussen@google.com> Message-Id: <20210225002658.2021807-3-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210225002658.2021807-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.617.g56c4b15f3c-goog Subject: [PATCH v8 2/6] 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.617.g56c4b15f3c-goog