Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1368639pxb; Thu, 28 Jan 2021 14:55:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaC87lgeOLQVIOhiMMy3XfNcCatA0irtjp90rXOHxoSTU+y82Lvj4D5l1OWNPg3vSzQQtP X-Received: by 2002:a05:6402:c87:: with SMTP id cm7mr2094591edb.69.1611874522929; Thu, 28 Jan 2021 14:55:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611874522; cv=none; d=google.com; s=arc-20160816; b=nU11BmHeuFLJ0B0Xdqrf8exZ5kargi7zho8ILTFnlYIX3J0Ih5GeY/xkUyNuaCHluy 0yJEYQhLPnuZsD4A3r2VLjcNl9A1M6Wty378OfCFVIEzxLsjdkDZHvqFwuwFqK9OSkJh 6LN7zT1NAghMk6y5ngwongWOkanWglXgL7NK+czRuxtCrKx15w1PV+rF2PAhvzCX3dwn lhOl3ABkgQ3JR76cSevLW2o7j+4+2WV5osLeOZ1eXoRcHt+sHkTdF6I+VbpvJQbGFBJE wuS4hOmfKstqwxXUvQx0zI5vPz3/HybCWFd2YhN1qVmCujz+gHrpR5gE93IHVYMwdSi0 hUMw== 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=ZyNXN+vY7+byGEzXckl2cjsPvL1+MihL3e0jf1aRuY0=; b=Uufo1xFLDx4Hv9qX7uL05MPOzhLsqzXEHff8TLWoxLDOYcNmck2SPHKqlRQLqKjsjG pre92nDbOF2biTKt+G9jrBeEanvpoy26r+/n5ge3jAN2ZqjBIwMSoSNOXMl3TuaTdmx3 ohXGEo4zCGB0BYXb0SKnDTHQzwrdCKj16L1mwReocKPJ9Jy+TknnI0kGqEsrzm9XwQNX S9tJEKCDb0nYdZKns36viSShoFyCe4n0NtPVOhiAoFwZmpYvC8osZCehE1Fet9a+2UdL P6hklG2CxBMrX0cmopfPdx3985tqkAn4ehgEybVLAl7sqQHkVUhM/luF/kS/iCGTjHat 5OEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hInQaWuh; 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 kd11si3502621ejc.330.2021.01.28.14.54.58; Thu, 28 Jan 2021 14:55:22 -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=hInQaWuh; 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 S231609AbhA1Ww7 (ORCPT + 99 others); Thu, 28 Jan 2021 17:52:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231664AbhA1Wv0 (ORCPT ); Thu, 28 Jan 2021 17:51:26 -0500 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 930A8C0617A9 for ; Thu, 28 Jan 2021 14:48:38 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id z19so4591600qtv.20 for ; Thu, 28 Jan 2021 14:48:38 -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=ZyNXN+vY7+byGEzXckl2cjsPvL1+MihL3e0jf1aRuY0=; b=hInQaWuhlmhVzsJQOOP66wxpBpJkZz0jp3JdPNaTamPFbqY2Iw7tYezAFSsj/X/h0l T//j35IRMXVjHvbnrOMRm67QMdJNZC4EVEFLwXjxKbG2ItZIlriMw4yPfN8SL0+axm10 nB3lG6H5halTcOohKo2Bunr1Mhiv0S6uvccIRFE2yavExj+oydg1TXJPsp2+5JIPJEUI iLlqvTWsvE5vTvctddRV6sDEkokg+J+axchFI7fLCP3v0fRC7iBag6zrKuQHOaIQoC6f C8HmrO04qOrB5OSzTgypkr0jqRAv7jVcvbkbd+9FxJRfviJoAvrCOhjbuY7/dlG/jqqn HHCQ== 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=ZyNXN+vY7+byGEzXckl2cjsPvL1+MihL3e0jf1aRuY0=; b=R/9cJHbJA6lrGCT9u8L2VCRn23+pDOU8W5xQEDhHJez1+3rzGjqIk1+nTArejpZHW9 BeIfNbiNbOGzc4fgUh00AxX6aULStzApOlBWxK5Q292MRz+Gbv1m6/tVVKjVdsg7as/4 G6y9DhXLAcXoxw4mU35ezgs0bSfEWbtteS65fsqcjbcn6CPK67Wo5IvfWf4hk3Mln7RB XQYUv4H7aqI8rd/jYfy1dP4r587X0XLeEqEcsoDtoDVrbmhIuepU/3Hnt/bdInIC6t3e zKDCzIuubjNCtnJMB2FkasW8CZTh0hDOlBoad6NGFoG4gxlBKefrpGpQLPxXvPMaMybv A9tA== X-Gm-Message-State: AOAM532ENJf2MzHqjKjcGfYMUQ8WrkPRy3xrHSsHNb0ypBvS9Joki5eg w6PJD7Q5DB595ZJcerLCIO3rGclAY6soSyq093Up Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:f693:9fff:feef:c8f8]) (user=axelrasmussen job=sendgmr) by 2002:ad4:544b:: with SMTP id h11mr1850894qvt.24.1611874117664; Thu, 28 Jan 2021 14:48:37 -0800 (PST) Date: Thu, 28 Jan 2021 14:48:16 -0800 In-Reply-To: <20210128224819.2651899-1-axelrasmussen@google.com> Message-Id: <20210128224819.2651899-7-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210128224819.2651899-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog Subject: [PATCH v3 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" 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 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.365.g02bc693789-goog