From patchwork Fri Nov 18 01:11:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13047544 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 9A170C43219 for ; Fri, 18 Nov 2022 01:11:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 391C66B0071; Thu, 17 Nov 2022 20:11:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 342CB6B0072; Thu, 17 Nov 2022 20:11:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20AF16B0073; Thu, 17 Nov 2022 20:11:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 10A2A6B0071 for ; Thu, 17 Nov 2022 20:11:38 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E164DA0290 for ; Fri, 18 Nov 2022 01:11:37 +0000 (UTC) X-FDA: 80144785434.10.67F28F3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 832EC1C0008 for ; Fri, 18 Nov 2022 01:11:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668733897; 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=Xcizgw09qxh5kxz+rR5aBntzCJEVxf2HEif8HyYLI/s=; b=PqdIUPDEcyT8Kjc18rxTtRuMgUDPHSkdOKrG66FljHRPfP4BkiywRvvXo05onknEZujc8T gf62WEk4iFu5fX732wrSgL/tVw/gcQTjjw+YTHhGMUAusXNYolqPNNQqAJS4YeBobXSRK8 K184uYRl6ers5OWq+xSFhU9NG0C3Q4c= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-356-KC71_G_OMuuvQPKs-HZ5dA-1; Thu, 17 Nov 2022 20:11:35 -0500 X-MC-Unique: KC71_G_OMuuvQPKs-HZ5dA-1 Received: by mail-qv1-f69.google.com with SMTP id nk7-20020a056214350700b004c68c912c93so2425624qvb.16 for ; Thu, 17 Nov 2022 17:11:35 -0800 (PST) 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=Xcizgw09qxh5kxz+rR5aBntzCJEVxf2HEif8HyYLI/s=; b=EBvVLLP+WtATAdhCP09Pr3eE1vNbPyAFRo2XM0qZPi6lwE5w8VSlgTzIE0NE4v8bbv oxtZq6c/yvco7x6igZDNKND369M2SJncYIOrH3z2SaGEueG0wG/OZLyatZCzYHpx6iXV O65i5yG7cxgttfB9RK3tOUCCheLfcdEpQlipwcrouOmBt38TQtEhp9rXDiqNkCZN8v6f QN9agReBMDsVkewG6XL4DMi21rkKDojNZPCHVUNtTmnw27kp9h+XsRmTQxjKaLZtPUtT bap8DJVtL+gadMtRZhwMbJvYEZStEp+gq1rsha5ouOCJnR991lCmfmnWIWztp9+NAyPN sfNg== X-Gm-Message-State: ANoB5pl184V0pBC6JEbyvIzW2igGQIFWEvpYxinnPmv4PGPjtT8WjJGy wPhC9afCoi8PQuZya/oQAjxx/IbLy2hbIA4HG75AYIgiH+fcYZv4z+2HKPh4p0rxl0zBXMDdJ20 knCH4gWy5VSA= X-Received: by 2002:a0c:b3db:0:b0:4b3:e8bc:b06d with SMTP id b27-20020a0cb3db000000b004b3e8bcb06dmr4998972qvf.72.1668733895401; Thu, 17 Nov 2022 17:11:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5zY9gm/9Sq/rUG10fAy37Oz9ULSDk0Pq8azqj/JTmW8KGkcU5gXTaCvi5BCEs8EdrHiJsuRQ== X-Received: by 2002:a0c:b3db:0:b0:4b3:e8bc:b06d with SMTP id b27-20020a0cb3db000000b004b3e8bcb06dmr4998963qvf.72.1668733895220; Thu, 17 Nov 2022 17:11:35 -0800 (PST) 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 i5-20020a05620a404500b006fb11eee465sm1507162qko.64.2022.11.17.17.11.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 17:11:34 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Muchun Song , peterx@redhat.com, Nadav Amit , Miaohe Lin , James Houghton , David Hildenbrand , Andrew Morton , Rik van Riel , Andrea Arcangeli Subject: [PATCH RFC v2 11/12] mm/hugetlb: Use hugetlb walker lock in page_vma_mapped_walk() Date: Thu, 17 Nov 2022 20:11:33 -0500 Message-Id: <20221118011133.2179145-1-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221118011025.2178986-1-peterx@redhat.com> References: <20221118011025.2178986-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=1668733897; 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=Xcizgw09qxh5kxz+rR5aBntzCJEVxf2HEif8HyYLI/s=; b=KYCmGJlocewuyr5LhWLbUnxT4VPA/rxnnMa49Nz6/kYyEp0Gb4Voe0nktefM5APedpJMl7 OxVgFCloyDlQDeEWKeudGxp7Po7hWJx2wxDAJVptJ6npVNoLR8cojaaDVPnoCD4a561oYW YByBPDpoN1Dyot3nHgPZm4q/WpiGbno= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PqdIUPDE; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668733897; a=rsa-sha256; cv=none; b=YFBuR08GBcjvCU0Mwb27++OgOdSz3zUp310T1Bm84soZbOtw1Amo+FF/RuJIohFZSSi3VE mp1zOQ27P4nR01/fBTE100GNlyLoIFtfPIbByDy+y1E26UkSaP4N5F+tPK/SPVabbcaS4l nw2SxBoy14NE8NrFTl1LPnm0tEzpjjY= X-Rspam-User: X-Stat-Signature: 8ce3aq15h4gieo6g8i6a6hi8ec5npa1g X-Rspamd-Queue-Id: 832EC1C0008 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PqdIUPDE; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam07 X-HE-Tag: 1668733897-308305 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: Hugetlb walker lock makes sure the pte_t* won't go away from under us. Signed-off-by: Peter Xu --- include/linux/rmap.h | 4 ++++ mm/page_vma_mapped.c | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 011a7530dc76..94d25a67db2b 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -13,6 +13,7 @@ #include #include #include +#include /* * The anon_vma heads a list of private "related" vmas, to scan if @@ -408,6 +409,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); + /* This needs to be after unlock of the spinlock */ + if (is_vm_hugetlb_page(pvmw->vma)) + hugetlb_walker_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..5ac8a89130f6 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -169,10 +169,13 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) if (pvmw->pte) return not_found(pvmw); + hugetlb_walker_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) { + hugetlb_walker_unlock(); return false; + } pvmw->ptl = huge_pte_lock(hstate, mm, pvmw->pte); if (!check_pte(pvmw))