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: 13509767 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 47F4DC3DA6E for ; Wed, 3 Jan 2024 09:16:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC77E8D0052; Wed, 3 Jan 2024 04:16:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C317A8D0053; Wed, 3 Jan 2024 04:16:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A78868D0052; Wed, 3 Jan 2024 04:16:05 -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 95EEC8D0035 for ; Wed, 3 Jan 2024 04:16:05 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E50E71A08D9 for ; Wed, 3 Jan 2024 09:15:47 +0000 (UTC) X-FDA: 81637442334.24.4F88E19 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 3BFF9A001B for ; Wed, 3 Jan 2024 09:15:46 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y51juoeg; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf25.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.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=1704273346; 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=GERLJEPmXyjsod6a3w+H+MRPlzFy0pZTus1RG/9onmU=; b=S6lRJVIO0RBWL6LZ2HWlKKMoZW7egD7csWfDJGoP9bRJjAEQn5wDRf/FSlmHi6tEAzl5hU QbT2f2FBfzarW9e5kdX5sFCyFdlDUyFqNl7TzNWIdgNve7/mXWkxGkhueDr80psphHgcZE Q+D+OkZE6bGb5JVV+jmuOe4loCAfMxo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y51juoeg; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf25.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704273346; a=rsa-sha256; cv=none; b=KpfqH1CZ6Ef+4HNoskWr6jjGk7CI7GAy83dW4KxR1MwzV5lvBelxKYiI/kONS6QfzYpOLn yuvf2xG5E2EpbiiWwGry2KqY8EifI65QDkaRlPjxQmsqzLEsjNiT+fG+dqUScFD6fJlP+I g0ktycqZPyRLGhP+xzktvgRPQgj++v0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704273345; 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=Y51juoegElrXveh17ucgztUNWyc3Djgsb94Z70aj+Q2TaY+Wx4OPNnN18eliZTEZ206aUd jxMVPkHNlHBttdb6R1cgJpz4h3Xp3Yxg4kIgFWiekOb9fqdSOXSsLUpj1zboSDO9ha20TE O/Rx5tZw5lIFN/tTPABM1UKOVlXPEB0= 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> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspamd-Queue-Id: 3BFF9A001B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 8njg5qekez6pfbzgjh7676jk67rp9e5k X-HE-Tag: 1704273346-813892 X-HE-Meta: U2FsdGVkX19Q2Z2qsD3DehuDYPaTEFajZntriADbVZr1U6PX+scy7GGEUxc+q1QDhZj+j5M094fGx4PlwgGVGGPU5VBjMpXX9u6qk4vHR46F1x7mlh5VBcTVfcuLJv0X2vb1knJBCRWkUVYvBjo0JUV9dWz0jnFVteI8+vX+rSfu45hEq406cFRL80eFYEX6jEbZXTMPHL5DeeGrV7704JflBdfRiu3ZQ44Db6b3caiKNhQk1gwaCST5jGe5Gw/igLhvAXy2+vZKBONmP+RuO9t+cTJeQdgEcU0qfE1bS+Jdy4HBzJZzE7qpOFpwHsTEAykr083eo+HwbGY87AtJMKDEQ5nai2Bl1MsmVm06cuklg8Y4IhaGfWuYfoL24UdZ+FbS/oWVHXPS+2Lq0/DYxDZPM/B94uIWz5tONjPBncVtOAa+R8Ytsx7B5NBAMqcGUoIStibKs2DSQonVUELw6YMtCDTupG+m5ziYXgpQ92ki5QhtdKWjNwqM8WLP91drFstNoxR+oJFtYP8fdhbCYP0+BrZT6tioyPoK64UEmjRuJxXDs0RQWngFtVL7xynPPCkko2NSCVHosaACBNdwOgfiVLB+jhMXKGQRhdrf3wfrU/3aRtTVddzGrLsbZsXFnmg9K67tl+P87wIZgBceJRPec2V8FqlS1g5JI5pV637zFo+2aiginVDrWljeISQhwI0YWxMDIK4lH7L0GqDoYYCWjMmAry1ZDULl6GcCNkYW2M0EsoBX8yGBVOI0oKboYvSDR7BSm5s1dzfspOmf4ExK7PbDDVsEqWum9Jk8K1WV86yTm5v9Dx/KYtLJX+mm0RHVPKPHPM+B1J9xMU/XYOYOYI39OBzrnLnzPOszprY+zcsY0wgYJMaVqz8KtKnyo1eB6Cm9EyQTXapLn9hwkG1+HqHGkTRhB0aiNQY/J7cvKQX9O8/fFtYxdI7zA6dwWuUqgbDBD35xgDVIW2s Cn9qp3At 18Qu4SDf9fwwcv1veuM0HIkKlmXsVvZz9FA4o/epLlYV/xfYAFDPFRfZIxcYzGEl8GjCpj57ymi+KUd2n9MxwQi7ypgs91GrMFaM2aquRPb8bqfsChGodWXJx4CzJForUitAxN9vOowRR1RqR0+UVDOS/2yodGrdG1Dk0tzdxuWteMaMW7t+RyJrQkb35dFfXx7AiyGwwot/EmBqwwXyYZRVz1s97bWjrXuLZBS5zNAPuePe/paK1O8XiNHESp84ygdX47zB0GAkZP6K0+//oAfpzLg== 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 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); +}