From patchwork Tue Dec 19 07:55:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13497941 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 409BDC41535 for ; Tue, 19 Dec 2023 07:57:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BAA9B8D0009; Tue, 19 Dec 2023 02:57:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B32068D0005; Tue, 19 Dec 2023 02:57:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AD048D0009; Tue, 19 Dec 2023 02:57:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 812928D0005 for ; Tue, 19 Dec 2023 02:57:02 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6772C402A9 for ; Tue, 19 Dec 2023 07:57:02 +0000 (UTC) X-FDA: 81582811884.07.A96BE3C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id BD102180002 for ; Tue, 19 Dec 2023 07:57:00 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=I33wxrN3; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702972620; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cOaAbTjD+sxL1nd4c8n1i5s+aCyb/VfpADXT9rdcjmA=; b=bMSUMUvpKUwz8VFMpWaQS5MG/RVAc1VB7689o0Smd7d0AC29hJQ9OAJxHqALgoU3UycOs0 gD6RagFbpQcYbBOVceAb4eB5vNJ6ZHpSxQPosAxoOpv9daaaKMzLmfjetTwGVfY+W7KWap iau+ihYSNVfDcLNhbNFElA0mcLMoLDY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=I33wxrN3; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.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=1702972620; a=rsa-sha256; cv=none; b=d19daDnOV8ZphVfX6MX5WAJ4xrwPFHMz/z+29P9AXJ8Ac+oGYMx/kpSjqaspjG/zD8JP7q rGSyD5TftXNzgWs0peRbTAcqMdzqZB1eEXPzfjPT4cFa9FMDWt2/OnhL+wwsKiDr1iQD29 T5Lg7bZt0Gwuj6BmSUKmYr0xiOOMf1o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702972620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cOaAbTjD+sxL1nd4c8n1i5s+aCyb/VfpADXT9rdcjmA=; b=I33wxrN3O9vPCiFjlesq0j6PIBNMuraGIScTkbYbvD126LJOerl7Qbv7lyJXAobbriJ5b2 PJE1iXoe277NG5Ay6Jh2t0hOd/pApRLH1V9Tj4fRgUEdtP4kZ+fKXS2veBY3VgWWGbNjpD kfNn/JDYU/BfLh5ML/ltkLYD4M7hhs4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-DMz-Hx_eOQmrxyRviaVqjQ-1; Tue, 19 Dec 2023 02:56:54 -0500 X-MC-Unique: DMz-Hx_eOQmrxyRviaVqjQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 26A2183B8E7; Tue, 19 Dec 2023 07:56:53 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFE972026F95; Tue, 19 Dec 2023 07:56:40 +0000 (UTC) From: peterx@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Christophe Leroy , Lorenzo Stoakes , David Hildenbrand , Vlastimil Babka , Mike Kravetz , Mike Rapoport , Christoph Hellwig , John Hubbard , Andrew Jones , linux-arm-kernel@lists.infradead.org, Michael Ellerman , "Kirill A . Shutemov" , linuxppc-dev@lists.ozlabs.org, Rik van Riel , linux-riscv@lists.infradead.org, Yang Shi , James Houghton , "Aneesh Kumar K . V" , Andrew Morton , Jason Gunthorpe , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen Subject: [PATCH 05/13] mm: Introduce vma_pgtable_walk_{begin|end}() Date: Tue, 19 Dec 2023 15:55:30 +0800 Message-ID: <20231219075538.414708-6-peterx@redhat.com> In-Reply-To: <20231219075538.414708-1-peterx@redhat.com> References: <20231219075538.414708-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Rspamd-Queue-Id: BD102180002 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: sfzxbei6r9z57i1pwkt6mfu9f4zk77yi X-HE-Tag: 1702972620-984410 X-HE-Meta: U2FsdGVkX184+s+upSyYKD6if5KntpJtCJg3ZrnhDjI9ofqFB1oW+goQuCOR4j8r+O4reVxHgjBmzXo2c+uui2cy9kO2BnsKTzxzgCLlTXKdm5Eg5zFHLpzIGwy0k7cjDyCPGPTVFhwyj2NXbjDml2NSLtuMuGce3mg+t0gA/brKzGSeslNwmqDktwBmqHwvibDW4jUPyYxwLtYbkRHEVx19tOifvs3c5xdP0VFXWe9TaH3lBOv8cuvWxi0SHX2S1XdyHC52RG3Ea5brUYwWA8kGN4hbnPphGNdMkktaMbHnLlGTR5xDUhpMuGDecgpEc5tboNKLGVXjaHvpV5RLzBKW+J7lisg77tr5oQ00meZUTtGWuWHKR1jtdVcT/Zxz+r/2tU0i14E6CeJCkJ7GNxYsBQynWh+owFBggn8mnd0Hi6WATJeA4IglteoYp/ZhhK0hIIKCNLU5FoNLkTBo9vjKttmHYaUJppO7Ig8aUhArUs7nmECfBvF7/GLZK9kUDvd7cYddFhuIKbo/RavDdkYMxL7PESU7qTkqgFejnKbXxlPR43sbeWCJg9b/CZ2rtOv4OVLYvzSYhY0ZByqgpKZPmWnu8+58tvHPRu0RzmJlTqoLWNkM/dcvEaqMeB+8928ipdSZMvrVcAq+JFrgyWXx5e4c1lhMM6+L/toGRZLJPYSY48nBQKSnEU3Ftv8CZGdgQ1qkN1o+iLFZYnYPPjQfSg+qqaGPbSrN3CGbhA/C+II1P2PTZUGzyL85JLAmIt2XLTJszJT2LBIwYrW65dheok7qe6JJlZlxKfkfryJDAyok63+dE8kNnANrCLl5YDHmiQ1gOxWDi9B2j93UqJIQYdiOsci0qEarb4CWJZ7g9BC9G8w5aTYU+89P0Pf0+kH61Me4MfDVm1ObjqdzQcO8PPP4O2FeDch2exLKldK75Dh0u6c7VrjPoQ6nqQO+qxxUgXiimWfYP5E1ylV exdUuoIX A/JWxxGe7iSR+OrjAa10l9xKL41twycX2vms5ankbFSzJvjSWPnpUUnJfQRoszxhHa9pLl5btfWtzBb1Cb24ZE5cPnLX0Zppafew5Ey+xoGCygAHCV3zDbdzNvM3LP5Q/ebiwiMz8NpWCWyJdtTU3F/23rJJLPbox9mCXCrtQMs4hamIJPwwi7ZQE1CyZFUCyzyqW75w/jcHF1jBRSt+dU71eIfJ4ib6OnpeHDzrz9Cy5+QRZomvC7QH79Ttgf0gED/XvDbcE1rp7EHsT3KacZXyWQA== 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: List-Subscribe: List-Unsubscribe: From: Peter Xu Introduce per-vma begin()/end() helpers for pgtable walks. This is a preparation work to merge hugetlb pgtable walkers with generic mm. The helpers need to be called before and after a pgtable walk, will start to be needed if the pgtable walker code supports hugetlb pages. It's a hook point for any type of VMA, but for now only hugetlb uses it to stablize the pgtable pages from getting away (due to possible pmd unsharing). Reviewed-by: Christoph Hellwig Signed-off-by: Peter Xu Reviewed-by: Muchun Song --- include/linux/mm.h | 3 +++ mm/memory.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index b72bf25a45cf..85e43775824b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4181,4 +4181,7 @@ static inline bool pfn_is_unaccepted_memory(unsigned long pfn) return range_contains_unaccepted_memory(paddr, paddr + PAGE_SIZE); } +void vma_pgtable_walk_begin(struct vm_area_struct *vma); +void vma_pgtable_walk_end(struct vm_area_struct *vma); + #endif /* _LINUX_MM_H */ diff --git a/mm/memory.c b/mm/memory.c index 1795aba53cf5..9ac6a9db971e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6270,3 +6270,15 @@ void ptlock_free(struct ptdesc *ptdesc) kmem_cache_free(page_ptl_cachep, ptdesc->ptl); } #endif + +void vma_pgtable_walk_begin(struct vm_area_struct *vma) +{ + if (is_vm_hugetlb_page(vma)) + hugetlb_vma_lock_read(vma); +} + +void vma_pgtable_walk_end(struct vm_area_struct *vma) +{ + if (is_vm_hugetlb_page(vma)) + hugetlb_vma_unlock_read(vma); +}