From patchwork Sun Oct 30 21:29:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13025219 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 D1964ECAAA1 for ; Sun, 30 Oct 2022 21:29:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA0D980009; Sun, 30 Oct 2022 17:29:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D52DF80007; Sun, 30 Oct 2022 17:29:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7DF180009; Sun, 30 Oct 2022 17:29:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id ABA3E80007 for ; Sun, 30 Oct 2022 17:29:44 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 948551A049F for ; Sun, 30 Oct 2022 21:29:44 +0000 (UTC) X-FDA: 80078907888.12.C743A76 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 3D2D510000D for ; Sun, 30 Oct 2022 21:29:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667165383; 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=WBN8D9wCQW9wV7A+8u6L08Ik6RBdolsM1Jhl7A7rc8s=; b=RpUxgBd+F+W93cmG3fir1GF0Now2WPJzntfgvGt82ReTjvuGTREKd39RUXsXTjmRnH94b8 yzy3KbaLKfHSrA5NieLPIuQXaWR7R+Jx6qTX82uFn5z2LRvxomFmTdzTB2NyDnBBDMndyH T+5cxUrgRIOS0C60DKtrhR6+nyuNCxc= 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-413-hz1K7Eg_P5aYFga1E-Ming-1; Sun, 30 Oct 2022 17:29:42 -0400 X-MC-Unique: hz1K7Eg_P5aYFga1E-Ming-1 Received: by mail-qk1-f198.google.com with SMTP id i11-20020a05620a404b00b006eeb0791c1aso8075240qko.10 for ; Sun, 30 Oct 2022 14:29:42 -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=WBN8D9wCQW9wV7A+8u6L08Ik6RBdolsM1Jhl7A7rc8s=; b=MKtbzNySE1V4ROU3itS7i3VieqAFQgB90eOBF2ej8995RMM9YiHJqg8BxLUjcQMYD2 rz9hyRcKKK4n8z9QHNKjE24fPCtgK5LVrdvTpkZwVSpoF6tyAL8rSnq5GmtZBvsZK/FO krV0Dz2QNXQwDIgvlCReke2K40cebOyM5Re2FY/qLtkXWFxzhyUexTJkkZgAUTAH+ShX +3Mld4ZV0Xti0MOMM9JWY2IRj7vN0B0fPP1gplU2rvE2op0pQVnCNxIbAVF2d37609Es rfJ90BUP87lfnx2qB7ol6pbB0o9ZJMo+W35fVh0L5zOHht+HOQdJXXNKHs0Cke1iQLNl kgfA== X-Gm-Message-State: ACrzQf1wGFT5EbzzCMpjGPGTVLRI7BXm7UqI1dwkJcp5d9toFywvgO3Q M++RBvXUdBvWTzEWvO6mwuK5YcN5mWNsonb5jqkdnEtajkvCOFmIDvz2ebcXtGScwd8rhDLtKMO nObxcfZteP8c= X-Received: by 2002:a05:620a:404d:b0:6da:4b51:2a8f with SMTP id i13-20020a05620a404d00b006da4b512a8fmr6987354qko.421.1667165381926; Sun, 30 Oct 2022 14:29:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM42RXOVz0QArfSJMlSE1Zpcejb5AA8L6KVh4LIIheRuXu9MXkBezCcPcA+vujWAM+SNNHsPqw== X-Received: by 2002:a05:620a:404d:b0:6da:4b51:2a8f with SMTP id i13-20020a05620a404d00b006da4b512a8fmr6987344qko.421.1667165381708; Sun, 30 Oct 2022 14:29:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 14:29:41 -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 06/10] mm/hugetlb: Make page_vma_mapped_walk() RCU-safe Date: Sun, 30 Oct 2022 17:29:25 -0400 Message-Id: <20221030212929.335473-7-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=1667165384; 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=WBN8D9wCQW9wV7A+8u6L08Ik6RBdolsM1Jhl7A7rc8s=; b=445lPIUBXS+DARawlFyUSbJCNhbGNGmwa3yX3p0sv229yFoG+mV/pmsT1E6b5sryhzavil Y+OZqRtNb+XWqPNeao3RSEOYx2O7WeJcxaamYRSxbEjstXyxuQkO62bJDnyg275wpT7qd8 QTy97RUyVyInn+IXf4hpZdNcoP1amCw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RpUxgBd+; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.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=1667165384; a=rsa-sha256; cv=none; b=QwjXad9CVF07AlU1XORYDMzlKHeZH6tQ2Y3adxzDDWETpN0Tij0SYfBxv3NUsDkUCAS8Vp +6td7KSjR0W3TlJUYQPwKcnFBINJqTpYRmJach6dzh0s9n/EUWnuBuitFWf1AkF7kPr4ME ZEldIvN4r05RtI/uNtrhPFrQX1kq0ts= X-Stat-Signature: 74zf91dfg79b8941ppq1ttytd7amfoix X-Rspamd-Queue-Id: 3D2D510000D Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RpUxgBd+; spf=pass (imf05.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.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: 1667165384-717227 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 --- include/linux/rmap.h | 3 +++ mm/page_vma_mapped.c | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index bd3504d11b15..d2c5e69a56f2 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -408,6 +408,9 @@ static inline void page_vma_mapped_walk_done(struct page_vma_mapped_walk *pvmw) pte_unmap(pvmw->pte); if (pvmw->ptl) spin_unlock(pvmw->ptl); + /* Hugetlb uses RCU lock for safe access of huge_pte_offset() */ + if (is_vm_hugetlb_page(pvmw->vma)) + rcu_read_unlock(); } bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw); diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index 93e13fc17d3c..513210a59d7b 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -169,10 +169,15 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) if (pvmw->pte) return not_found(pvmw); + /* For huge_pte_offset() */ + rcu_read_lock(); + /* when pud is not present, pte will be NULL */ pvmw->pte = huge_pte_offset(mm, pvmw->address, size); - if (!pvmw->pte) + if (!pvmw->pte) { + rcu_read_unlock(); return false; + } pvmw->ptl = huge_pte_lock(hstate, mm, pvmw->pte); if (!check_pte(pvmw))