From patchwork Sun Oct 30 21:29:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13025220 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 A99B3ECAAA1 for ; Sun, 30 Oct 2022 21:30:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A0868000A; Sun, 30 Oct 2022 17:30:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4508580007; Sun, 30 Oct 2022 17:30:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 318138000A; Sun, 30 Oct 2022 17:30:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2449B80007 for ; Sun, 30 Oct 2022 17:30:04 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 01B881A049F for ; Sun, 30 Oct 2022 21:30:03 +0000 (UTC) X-FDA: 80078908728.02.3A408B2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id A45C9140004 for ; Sun, 30 Oct 2022 21:30:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667165403; 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=6JldXIZ0VovVxqs2u1isjA5hu6yU0tGljewUccwkM0U=; b=fOYu3G/uyD2A3tFz0cgpBU19KDPlscNqr1Xhf8qDroqBBsTT7RZ7tnuaqr/Sw5FbD1zPXC mXfK5nDJ65dgQJ+k1NssEcFO/GafMj6JPTK/rT/vPUDLXyEL4xZTzHQZfhUEOGRbi47Gvw O0Ij1C3eH040LYvbko8GO5oXZDvphnA= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-416-ET2fLviFPGKsc3VPkTGn5w-1; Sun, 30 Oct 2022 17:29:44 -0400 X-MC-Unique: ET2fLviFPGKsc3VPkTGn5w-1 Received: by mail-qt1-f199.google.com with SMTP id i4-20020ac813c4000000b003a5044a818cso4847020qtj.11 for ; Sun, 30 Oct 2022 14:29:44 -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=6JldXIZ0VovVxqs2u1isjA5hu6yU0tGljewUccwkM0U=; b=XeRdvxz1yupoUAbGA95jGy63sttTBw7md26FpQMYSzgEiB46jaDa3UiEIHdC4pMfwn //9aDOVs2jy7yPdbp7IA1ze1iMVrPb4ZpfeK1BDFXXKvYOlHFPHA5aSbVqDg65KD9GEI udmwDi2GLMblEYCZQ1oGQnP4P2gx7CBGof6ezQTDDSaTZNYC7bNv24i1cM9V++WVvBrR eOfVJNK90lYGSJUGmxGXWSowQ6SLofeuv+L7VlK29Xzl/yYv7liePRvGhm6e9n0/sQZo e2RbdSnohzgK0zV/iYL8UP7g+VoDC6J1IMUFdkmQ95lf6ht8wtccQqjxIprubVaN4B3L GdyQ== X-Gm-Message-State: ACrzQf07X5BQ6xHslc5dztcDkSQD9LRs3qUPOUKS5TYK4vLM2+97CKdn oj71JUWfsjtRi9fHHtxbWcuOgTx+ddnXUdEcjiq6aJckhJNL/uBp/XkpP5tG+pDkUuZSCSKzrJ2 8O0nsCnJsi70= X-Received: by 2002:a05:6214:1c09:b0:4b7:f9f6:7d17 with SMTP id u9-20020a0562141c0900b004b7f9f67d17mr8720819qvc.22.1667165383321; Sun, 30 Oct 2022 14:29:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5VT0YcB2KUeD0RxKSYpx27URr0maKrp8Ghgz9I1abNoV5z97NF2ZhVFfbknBYsc6tbah94rA== X-Received: by 2002:a05:6214:1c09:b0:4b7:f9f6:7d17 with SMTP id u9-20020a0562141c0900b004b7f9f67d17mr8720803qvc.22.1667165383128; Sun, 30 Oct 2022 14:29:43 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 14:29:42 -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 07/10] mm/hugetlb: Make hugetlb_follow_page_mask() RCU-safe Date: Sun, 30 Oct 2022 17:29:26 -0400 Message-Id: <20221030212929.335473-8-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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667165403; a=rsa-sha256; cv=none; b=qM2c6TbeILWS4rakMQdFg6qg1OnwqI8a7yLCGGENUCAJBUWlbUFARYQicc8524F/pvzAFJ F9neH9l1owU2unwe69glOW9puIcriA96H+5WXc9J98Srj6X8yeuN7SmdhPxytRVByD1tV8 4E8F9htZLfKgDNpS210GgHXN5iB8hjI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="fOYu3G/u"; spf=pass (imf09.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667165403; 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=6JldXIZ0VovVxqs2u1isjA5hu6yU0tGljewUccwkM0U=; b=2s4fYF5twWgOfIUaK/bB8q2w2ZozYRnQou/Pnz8+66Vb8BFZejdsDYcdM1QEdhw9XCqiuF UZuHMo2o3AjPnGW9cZ3jMEXHXVIRL+8RClHkFCYMs/vLiILZigHeXGty+XCgJaF2FAvF3l 0cwwDy0O0HjG/C98DASYI11UeOguuC8= Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="fOYu3G/u"; spf=pass (imf09.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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A45C9140004 X-Stat-Signature: f1m9we67psnbt8nkzt7ozaf1fpasdb5h X-Rspam-User: X-HE-Tag: 1667165403-692618 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 --- mm/hugetlb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9869c12e6460..85214095fb85 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6229,10 +6229,12 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, if (WARN_ON_ONCE(flags & FOLL_PIN)) return NULL; + /* For huge_pte_offset() */ + rcu_read_lock(); retry: pte = huge_pte_offset(mm, haddr, huge_page_size(h)); if (!pte) - return NULL; + goto out_rcu; ptl = huge_pte_lock(h, mm, pte); entry = huge_ptep_get(pte); @@ -6266,6 +6268,8 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, } out: spin_unlock(ptl); +out_rcu: + rcu_read_unlock(); return page; }