Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp346735rdh; Tue, 19 Dec 2023 00:07:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGm0eAQuCKk6HpZe/Av/GC8cezc2R1XLGm4SwHq8uFchnLVO7qUIQy9UMRXXZN56XBjmN6L X-Received: by 2002:a50:d088:0:b0:553:a544:f1de with SMTP id v8-20020a50d088000000b00553a544f1demr132172edd.12.1702973234296; Tue, 19 Dec 2023 00:07:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702973234; cv=none; d=google.com; s=arc-20160816; b=hXGCg+VX/YZj+b+fznaU7dUMs7tW4M2cGGV2REWDaiojroN5KItREYf4M01vLCj31B o+DM0lu92FTPF3Mev1kr6gH8Sj2/jygb7zt3yReLKoL3yt86IVrXhrlxv2KwJ82u995I 8ufQILyFy9N7VKx8ZUTPEjfzuUHiAHIp12uk6l79e1k+OTsSpUQGFlbkYPgsPURL3OO3 wkZMptm7QCXu2h6SPiqvmPSfjJ2t81LHvmWuwwArlC2lGr0pmyAe+VCdD0W6eRrImn4e +JERWoXNdSS77s7y+CcZR4kSyGCejMOxA3T+cJta0uqeKoNhWf+/SEIcdBmEfiPZLdKf ZMNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cOaAbTjD+sxL1nd4c8n1i5s+aCyb/VfpADXT9rdcjmA=; fh=3mpu6Yyr5hMzDKtkQvzcApl7ZSQGU4G8QyIY2BAU7VY=; b=yZhhaXGZ0S7BjSqYobtufL+hAQqv9KGtaRe3zj/CHvwm5SOvEA27RotQBmXSbDJ7ck hGRXWI2KbMDseevI9yni/qiWQri+5gc+tCRe/ZQttDDnZbgVnRtxi96ELKof44rhDrQ9 3Q0FkG1/VxbffbVkNFJJ4tkZG2w1aOuhZoAqiFJvXsNuq3Q+vFaJPfvL92avnhqDd37l 3VV0DgHsTpIsimd0mj0JY2TzJH98wi0Q6ywaLEBYfEy9ODymWsMCk94H/mhiRA1HSPET 0MGEXe82n7d0yaF1PjsfGXtJ0lIIA9odTpAu1UkyB9syQ4h5YxAznTwVl1wQrRE3jyLD mUQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=I33wxrN3; spf=pass (google.com: domain of linux-kernel+bounces-4839-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4839-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cw14-20020a056402228e00b005539b12827dsi294892edb.144.2023.12.19.00.07.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 00:07:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4839-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=I33wxrN3; spf=pass (google.com: domain of linux-kernel+bounces-4839-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4839-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4740F1F26617 for ; Tue, 19 Dec 2023 07:57:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 605CA182A0; Tue, 19 Dec 2023 07:57:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="I33wxrN3" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 216EB168CB for ; Tue, 19 Dec 2023 07:57:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 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 --- 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); +} -- 2.41.0