From patchwork Wed Jan 3 09:14:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 184674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4911429dyb; Wed, 3 Jan 2024 01:17:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjLFA9EbQU+mhBtGtgPa42y3P1jCbSG/XmRmyyEYhHy6BuyjWcZ5G7JN8KzwLQtPULpuwj X-Received: by 2002:a50:a699:0:b0:554:50d7:4b49 with SMTP id e25-20020a50a699000000b0055450d74b49mr7270697edc.89.1704273421875; Wed, 03 Jan 2024 01:17:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704273421; cv=none; d=google.com; s=arc-20160816; b=OR/b4R+BwDNJCG08VJoCA1RygHD+ryKIq97pgInGCZW7H3q1HuihIpPP2SRDEeTluz 0LHFCa+MmepLD/oM4N8y2tHgjdm1srJrxsz2LQL8kwlNRW1iFyKfLlkIqCofVpyDXVwV wQFbqFAVr6dI4xyKCs9OIqO9ELWJSH5tkYPVUHQbjd+UdccPlhtSkiGwudNE/hJ2S6w7 jCipOyMrTbTZCn48wUldRgLtAUJB5uGh9BgjPPs0PagWQbmC5DUD0K30GtOMuvzzKuPz Jvdg2JzeUHS8glMvyK3M2trKnt0ThxL4ntFm/NJiJfFt40dJcy7KedDZDGznVKaGrKKl J3UQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15320-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c7-20020a50d647000000b005565057cf23si2532809edj.435.2024.01.03.01.17.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 01:17:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15320-ouuuleilei=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=ao+pTYbt; spf=pass (google.com: domain of linux-kernel+bounces-15320-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15320-ouuuleilei=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 6872A1F23F03 for ; Wed, 3 Jan 2024 09:17:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4286F19458; Wed, 3 Jan 2024 09:15:52 +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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787060207843243276 X-GMAIL-MSGID: 1787060207843243276 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); +}