Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7014140rdb; Wed, 3 Jan 2024 01:18:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+hdqI4UC+JYI+ShUf3LkJNE771K1QncM6lvwcdZnE8T7LVzJuRxRDxq33uDmjAvfcm2Br X-Received: by 2002:a92:ca0b:0:b0:35d:53ae:a702 with SMTP id j11-20020a92ca0b000000b0035d53aea702mr25801216ils.31.1704273490965; Wed, 03 Jan 2024 01:18:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704273490; cv=none; d=google.com; s=arc-20160816; b=Gz+L+NEPG2cLud1ifVeycOAXt2a1qdGEYGB8ZIupNuz7VQh/qIelIJMMb4cyrBRkjy ErZEdgh1+3emF3ZDvTGlvG1u0F0Njc7i/rZ5VMtVq/6FY8OO/qmg6J1UZMoNmMKQ1d4L +EHbirg/zVLib87n2kYipIZt+9eBwLsG7AesZzC0LW6Ds0oo5fVzAgdR001+f3u0aTXM SyUgHTADSf6d/62zAa/utsFz5X6htX91sKWEqWi8bBknN0WJ5dIcuwzjinqJuInj/saN 9rDMKQHuCzbGt24AyG+QtcCswEL++g9h/1yh+LnLMQFR8b9AzF0kqiI51vtsZ7361HdO 0z/Q== 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=GERLJEPmXyjsod6a3w+H+MRPlzFy0pZTus1RG/9onmU=; fh=JvQ3nGflNTIwPBfhSW2OJAIjHOHR+R1SiFkwzYoQoWY=; b=V9DQJBYToWGu62fUX2mbLVpQLO2d6DDcPyH68bOcs1s+x4wg2RU2A6j6khd2On3w9+ kLt5vYK0zBq8G1AKSd5AOA7kyDcMCk8Oeg+tQYoXilWbBgWLSnmnX73KfFcKbNmKgGZN fE70UudHXkGFKp/r7j81FsfYp1/RtI9/87JIbERRNFEMtTp50JwAB5JnbbkYbquuYefN cGGi1zWSSsFzQUajeXG219A6L+yKeDlngXfxEqseUBeTlKL6M3e6OHIlWuCe3NrDVEHb VvHZUcdBh1T40QHu3E8gaebkihl/E7uKZpCRD4o9up4tQd/0RVTsPUlQBGEGUvNGSYAV CPsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ao+pTYbt; spf=pass (google.com: domain of linux-kernel+bounces-15320-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15320-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id o13-20020a635d4d000000b005cdaf95abefsi21326064pgm.506.2024.01.03.01.18.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 01:18:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15320-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ao+pTYbt; spf=pass (google.com: domain of linux-kernel+bounces-15320-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15320-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 72575B23425 for ; Wed, 3 Jan 2024 09:16:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 767F419443; Wed, 3 Jan 2024 09:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ao+pTYbt" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 57E1918EA7 for ; Wed, 3 Jan 2024 09:15:48 +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=1704273347; 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=GERLJEPmXyjsod6a3w+H+MRPlzFy0pZTus1RG/9onmU=; b=ao+pTYbtE0fbLyIB+2qmtoEWSaBaQ3sLSoSNR+BVhku9i1x+CH1qe7tsTGKfH8S2BwOxkR vEeQHl4FAbmRunxWm9rMQY0kUpvh6E+/a5IEpy+t4o/B+mZ8hDewsMuprGR0uGtKyi3OvR P8AlyS3ttMAfIeIlyb3ziq4c2FWY6y4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-AvRlxFvDMHWmUtn2K9LV5Q-1; Wed, 03 Jan 2024 04:15:42 -0500 X-MC-Unique: AvRlxFvDMHWmUtn2K9LV5Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 1957D29AA38F; Wed, 3 Jan 2024 09:15:41 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.69]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C3DE492BE6; Wed, 3 Jan 2024 09:15:29 +0000 (UTC) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: James Houghton , David Hildenbrand , "Kirill A . Shutemov" , Yang Shi , peterx@redhat.com, linux-riscv@lists.infradead.org, Andrew Morton , "Aneesh Kumar K . V" , Rik van Riel , Andrea Arcangeli , Axel Rasmussen , Mike Rapoport , John Hubbard , Vlastimil Babka , Michael Ellerman , Christophe Leroy , Andrew Jones , linuxppc-dev@lists.ozlabs.org, Mike Kravetz , Muchun Song , linux-arm-kernel@lists.infradead.org, Jason Gunthorpe , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox Subject: [PATCH v2 05/13] mm: Introduce vma_pgtable_walk_{begin|end}() Date: Wed, 3 Jan 2024 17:14:15 +0800 Message-ID: <20240103091423.400294-6-peterx@redhat.com> In-Reply-To: <20240103091423.400294-1-peterx@redhat.com> References: <20240103091423.400294-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.10 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 Reviewed-by: Muchun Song 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 896c0079f64f..6836da00671a 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 7e1f4849463a..89f3caac2ec8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6279,3 +6279,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