From patchwork Sun Oct 30 21:29:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13055 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1972501wru; Sun, 30 Oct 2022 14:32:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7pNqjW9OV83e1ad6iCAOGrsj3GgSHtwEJTrKTOoPLGaA/pup2Lil805d1VO5gHWjD6gS27 X-Received: by 2002:a17:902:c643:b0:186:9efc:67a1 with SMTP id s3-20020a170902c64300b001869efc67a1mr11001192pls.30.1667165533816; Sun, 30 Oct 2022 14:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667165533; cv=none; d=google.com; s=arc-20160816; b=ymFxVqNqP35AJ1HSXdQtRmHCyp/wVst28PCOTl/PUiZ95piaM13jLrKdS1BJQp7hYv wQjqos/bW8mZ77duJFyGYKJr5AYCxPzMheKouLhGtUl1cP0PxgJKEIZszzKhLl2jX6DJ /QXkE8ccqaHd5oBhonCls8ol13GyjQho8prL7/g7QHDgX1p2WY+ZhkNHoRDFNTV/Dh7S qdjkp7B+ygZedd7/SRtrI2kqECgGaW4Crohj9Kv5h+9QBSzf2QzGwdRkbEy7qWq/X8/+ JgLta8KLu4pC2gl2+cHu5FDt2yuJf37JjRwRtsmrYssBU30/gvu9UYxbNdDvt/SZ01hC z4ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=agXgQWAuByPHwxJXo49Hx7hkR/BEQEXX5BlO+c7HbVA=; b=umv6745ciJ1PT+3GbUnTStaPl73ZQW+9i3dICpJXvyBVxi4kVYeYwu5ZOUlBjkPZ3K DaS/QaxOX8fzDE3tlY8D5OacJ+/Z6n7t9/lPIrqM65KeV0SuxlOE1vSiUs8JWdzORKSR /ZGrBqDp3xImVuA3xzS5vmc7l9lnlWCOKlnLPa3PgRPDCUQtcX8Q+Qw8vL102sYufIxT EJfqtZtllqS78kktEuCw6uxxo5hSqg9O0kxl0fbwpBq/ochDiEKUc6tOfPSTxqFaqmMv Jhegfo9wx+a5PifEA1jO9E2mfxmf1DwWjjv/nTHvt4X8r/AvnuKblLuXXc4+34Sts0T0 Cjrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eULKnbz0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a170902f68900b00186a3bc939esi6972583plg.211.2022.10.30.14.32.00; Sun, 30 Oct 2022 14:32:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eULKnbz0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229689AbiJ3Vaz (ORCPT + 99 others); Sun, 30 Oct 2022 17:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229767AbiJ3Van (ORCPT ); Sun, 30 Oct 2022 17:30:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7DC3A44D for ; Sun, 30 Oct 2022 14:29:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667165382; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=agXgQWAuByPHwxJXo49Hx7hkR/BEQEXX5BlO+c7HbVA=; b=eULKnbz0iRds+nPlupkJyRMKYcVP+cp5maTyzQDLF5wNoXctbhkLXZD9j0LTMMVj5TsfXd fR9mu1TxV1yDf1GtxdfgdkUv/AjHxoeNsHTdUcUehxHI9fAUO7TqMKB0YsbM6imdWHXonw 7qzTxx/IGWrnJcdxMEvS3aOEzhRmQCM= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-327-42NyM1FaOu-uVp8XgLv4dg-1; Sun, 30 Oct 2022 17:29:39 -0400 X-MC-Unique: 42NyM1FaOu-uVp8XgLv4dg-1 Received: by mail-qk1-f198.google.com with SMTP id de21-20020a05620a371500b006eed31abb72so7984366qkb.6 for ; Sun, 30 Oct 2022 14:29:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=agXgQWAuByPHwxJXo49Hx7hkR/BEQEXX5BlO+c7HbVA=; b=Gows9Re9yfGoUNgITLJKKq60Ec3WWjKhyE3fESjCRJ1M4s+i/aAQWIsKberUYj02m+ DOGeok46iH1gHOKw4v8adKiAu6DQfE0qsGNqg4r8CP6/5P+gBsHf7wYzFzpTUguXsvPD va6FSMEeILn2XkBa9+xcCR9D+vqqKt4qp6IRM/KG+ZUSr4J4aXmHqh8aw/799nf2oAnW h8pZYRPYObKXdjIgBnq41qnxfNq3Z1FfoMecFZUeMlMdsqLOiWqyeR9L9T96qlvEa/TQ /leSjIbXlIWSQ+/04O/YPu4pSNDDV9VN52ZtP5vLl9PksXy3YoT5P0U75xDn/UhZKqDQ wN1Q== X-Gm-Message-State: ACrzQf2zJgP/O9MmPQG4x7Yy6Lafr9zaGGFzL0DuWdcPPWQYp4RDjG8A q3lKNajO/mAu7alBdYdmQ4iZ1XGrQFfnB9SzST84JjRawaA+5Xz+0qD7m1IuZdEKc3l55dcCHUK RIavErLnjYVUesKn+fVQF2JvJRegX0+FNsPGCUNzvmaEbkGLskhCW/0mddEY+YNMN/9H54p94sw == X-Received: by 2002:a0c:f0d4:0:b0:4bb:6583:66e6 with SMTP id d20-20020a0cf0d4000000b004bb658366e6mr8560482qvl.123.1667165379140; Sun, 30 Oct 2022 14:29:39 -0700 (PDT) X-Received: by 2002:a0c:f0d4:0:b0:4bb:6583:66e6 with SMTP id d20-20020a0cf0d4000000b004bb658366e6mr8560462qvl.123.1667165378831; Sun, 30 Oct 2022 14:29:38 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id a1-20020ac81081000000b003a4b88b886esm2654781qtj.96.2022.10.30.14.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 14:29:38 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , James Houghton , Miaohe Lin , David Hildenbrand , Muchun Song , Andrea Arcangeli , Nadav Amit , Mike Kravetz , peterx@redhat.com, Rik van Riel Subject: [PATCH RFC 04/10] mm/hugetlb: Make userfaultfd_huge_must_wait() RCU-safe Date: Sun, 30 Oct 2022 17:29:23 -0400 Message-Id: <20221030212929.335473-5-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221030212929.335473-1-peterx@redhat.com> References: <20221030212929.335473-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748149767172885867?= X-GMAIL-MSGID: =?utf-8?q?1748149767172885867?= RCU makes sure the pte_t* won't go away from under us. Please refer to the comment above huge_pte_offset() for more information. Signed-off-by: Peter Xu --- fs/userfaultfd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 07c81ab3fd4d..4e813e68e4f8 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -243,6 +243,9 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, mmap_assert_locked(mm); + /* For huge_pte_offset() */ + rcu_read_lock(); + ptep = huge_pte_offset(mm, address, vma_mmu_pagesize(vma)); if (!ptep) @@ -261,6 +264,7 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, if (!huge_pte_write(pte) && (reason & VM_UFFD_WP)) ret = true; out: + rcu_read_unlock(); return ret; } #else