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: 13025217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53227ECAAA1 for ; Sun, 30 Oct 2022 21:29:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB3228E0001; Sun, 30 Oct 2022 17:29:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E63E180007; Sun, 30 Oct 2022 17:29:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D03CC8E0005; Sun, 30 Oct 2022 17:29:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C21658E0001 for ; Sun, 30 Oct 2022 17:29:41 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A07511A049F for ; Sun, 30 Oct 2022 21:29:41 +0000 (UTC) X-FDA: 80078907762.22.8C29327 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 40B8380005 for ; Sun, 30 Oct 2022 21:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667165380; 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=F9KeaadkZ5/1tjX8ytmHlhgPASL52gPiqVxikdUdfib+N/gdKEEUM9RstAwKlcib1Wc4N4 Qk3+Ke7NxqSTrjoRtr7okfuy3MhtEuI/IGE0AJqjna8c8JfXvwBaEj5bWX/HytBzLe1rwW bH5/jzqnA0iDMzo8JRtEJzYatRgg56Q= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-286-yUbR5LoGPoq_1As3pPPGtA-1; Sun, 30 Oct 2022 17:29:39 -0400 X-MC-Unique: yUbR5LoGPoq_1As3pPPGtA-1 Received: by mail-qk1-f197.google.com with SMTP id h8-20020a05620a284800b006b5c98f09fbso8156963qkp.21 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=htyn0rjOaVMUMkBIRLxtL+Z4jfZTh6Hey1MHiuKZaJt7gvUDdjWf6Sq6e0mjCvj4y/ jDEIXeqpEHMIujZECmryiRKM2Ep32vyDJyZF8jo6VrGXtEDRiCYvhVDn/1XNxrr/C+le DuKyZAe9xXiQ3UOIX7q6bUsJm6OhwBRdfIcehnRTd+3RRdeip4RNwct8l95DJQHn0/Ip 8LD4yOxA4ee9ko0ElZdwu//GKmemntPMYo6RI30Ao9XYfEcKduW7jQTkY96pucJKGzfW J/lyAjaIzGLqtsxQf2hcgPRMXOSHyS1kC62kL96NMIc3M7WhtGKjSw70TNLosMbjMff3 EjiQ== X-Gm-Message-State: ACrzQf38L4n1QagRV7WWiijFyf81SyzJeldVF6AWHfmZTmV0j3PsCVZd hfQVSdM5mcPCUYr99vG0GNfSj8UYg0ht23wq71HOHCZqeIPFC1u4cDC0qxSbXPBs7eUg070YzZU 4roITKOUpd3U= X-Received: by 2002:a0c:f0d4:0:b0:4bb:6583:66e6 with SMTP id d20-20020a0cf0d4000000b004bb658366e6mr8560478qvl.123.1667165379075; Sun, 30 Oct 2022 14:29:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7sce2XU7RtWq2xdMTQLA/Y2bdKWFb6WfMYU+Rxg+ddv0M5GF24IJZTzMXfQ4BlQlC1JXATQQ== 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667165381; h=from:from:sender: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:dkim-signature; bh=agXgQWAuByPHwxJXo49Hx7hkR/BEQEXX5BlO+c7HbVA=; b=NMnwYa/yHkUtGQKR7UKHq8a65vVXbvhV6tK1nXpD6j4jtxxbuWxMvWYTOMY+aMoKigNNX5 ml+UaH0zptVI7oMZJCUgrPZotlZphxv7ESvADTkHe/CPwCcHlFBn+o1mNmuZx8SkJj052V Wg3vr0mvjeUAUgiH/FGEFvtqZJyLkpo= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=F9Keaadk; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667165381; a=rsa-sha256; cv=none; b=kcyBQYBHqa/o2ONvs8acnWvZ/d9rgTi8LPFwPHTVLMe9sLPIGXZbu3WECN4jXTeOp1uVbz XXFQ737k4d8uKc0T3Bc8ikU/3E53/Ij/Kh4WgdcKfGx5/l3lEpebr/yCD96+FYwRyBv5wU j4xTzS+mlG9Vuc6fZMOPjB85P7L2qxQ= X-Stat-Signature: 4fqn4jk1bj838bx58ajkeursmazpn9sj X-Rspamd-Queue-Id: 40B8380005 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=F9Keaadk; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1667165381-94907 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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