Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7660457pxb; Thu, 18 Feb 2021 16:52:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMamvHaRDj9YgKm92RshCBNb2d8M2Fh/GRC0AmWxoYbdLZNyDNpstkDT/K4dtJOF5QGunF X-Received: by 2002:a17:906:d196:: with SMTP id c22mr6506017ejz.104.1613695921242; Thu, 18 Feb 2021 16:52:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613695921; cv=none; d=google.com; s=arc-20160816; b=eedFgivkimu9R0I8wSI+7B1rED196nruF5FPU7DjaJXXei9XfUPjnmzm8B49QxAvIR SdFnapmp2rqVkscxNsnfmyQm8/tboMmOFdj0QXV9LHSoXH9WDtOTGkuufGFQZ9Z9nhtS 288es9gxtverhCXKxjy+r1ZHAIDl0tHUmPlXpoVCbufDfpawqZO/3yD+r8V16iR7AEkP /4YZVLgJ8dOXS1dOj53NAhELlRt/546GjPBijod1/QaoAwjrlgPRxSeVy53g4M7V5xDP c/tYhHjoAgPLkkmfyQMZSL6yhNU1A93jhWQ3J1mK0ryyWitAizTizEXOdU3ArDWNhlQn xePA== 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=zTA0HqnWPWBrswb659GU/gCm981HmO13IUaVA54oeatjyCi6Ar8fOHvP5P4xeg7PSR 2q1ljhv2gwRtZbhpLDNXokkCkqN73zKHOwBFhOXbzyHwRV4ClHk8nuMaHEZ6/vK9SzU6 eZP4CamqGmw5Bb+vaLzE/zrhDsfvkBZHldBcURqSD1Z7NAJwUQnRzQ9Ut/Y9Fk5FWG8q lnnl2l4lpquTMcFyi2h6aSJ6Ib6o2QUmQlM1EU7zU81Dh6ZhZ3Y69tRAeIFkSOTHZbxS LtOJ3lYezJ07DZPD/s8/W8J9y2XM1GDbnQjIimPClFal7K6ZIkNK/lCtCsfNljgF+W4H KQ9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Ik5mLa+w; 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 f17si4476948ejd.597.2021.02.18.16.51.38; Thu, 18 Feb 2021 16:52:01 -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=Ik5mLa+w; 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 S229879AbhBSAtz (ORCPT + 99 others); Thu, 18 Feb 2021 19:49:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbhBSAtx (ORCPT ); Thu, 18 Feb 2021 19:49:53 -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 A4C78C06178A for ; Thu, 18 Feb 2021 16:48:36 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id c12so4817283ybf.1 for ; Thu, 18 Feb 2021 16:48:36 -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=Ik5mLa+wIzQ9zfYIXzCW8txps5b0LOtlw5SCrz0oCUlrnn7+7YcukDUOv592BKXIqA XyMpq/lVfamEDV77jRUDPpYomIaSg3srYMmwkz4alfwvoOPbJWqLB0s4hfvKyGQmNSjh SAvyLDI68vF48r++B4/5iUJqMpniXnHnA186xd0b+LGQigqd7YehpirHSvL8pzcClIdG tblMLXy0TyMR+kiVbvV74wD5F6ko1FL2kimeYxojeJbkG5WBJJal+0ySZ9HVCMhuGoNK B87mVtEI4pnGDDEI82to7662ighQZ673OxM1jDpoBdoODkD66MnmLr0kYQrwJHg+9Oej KYJg== 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=qYlUv5kHWBChn4cvt356Az5CWpMavp9DJFom1uo6h4KmaCA5aYowc5GFYSZPRX6A0m gg0vb/k7L8neFa6D+HLJKjomKOHdxfgp+NZI9Q1+mYsvJB6DPMfj7WGVlMI1lkGTL93U 4x4Z6wX3TvWFivpShVUJnCRXZuS8wTkIbmgF0k7zlCcrwh0MJSCO+/CCD0oPlWdIs9WJ +OqqJTzOFWPCmc2W18f+AIi+OOXvl4fFmDOF0dyr2xugi6PFIp2SP4Z0/AQmLLxS2fMz IUz/J8ocFol/aAEDuxt6ZEUlAdcFvJoXLVTiIBLJi4hAhcI8klAZvx90bGB4zpjat4Co q9FA== X-Gm-Message-State: AOAM533NElQ1F9ffNa0Vu2hO6w7GtLM3Zz9Ka9/1AOWi4YiJENqzfIZP 2T74CHJQOS6Se8iLkY1F8t4EYs0gK0f2PEus5ogO Sender: "axelrasmussen via sendgmr" X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:e939:4cce:117:5af3]) (user=axelrasmussen job=sendgmr) by 2002:a25:c090:: with SMTP id c138mr6712073ybf.279.1613695715827; Thu, 18 Feb 2021 16:48:35 -0800 (PST) Date: Thu, 18 Feb 2021 16:48:20 -0800 In-Reply-To: <20210219004824.2899045-1-axelrasmussen@google.com> Message-Id: <20210219004824.2899045-3-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210219004824.2899045-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.30.0.617.g56c4b15f3c-goog Subject: [PATCH v7 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