From patchwork Thu Nov 16 01:29:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13457479 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 067FBC5ACB2 for ; Thu, 16 Nov 2023 01:29:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C810B6B03E3; Wed, 15 Nov 2023 20:29:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C07896B03E5; Wed, 15 Nov 2023 20:29:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A08BA6B03E6; Wed, 15 Nov 2023 20:29:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8C6B86B03E3 for ; Wed, 15 Nov 2023 20:29:22 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6CD761A017D for ; Thu, 16 Nov 2023 01:29:22 +0000 (UTC) X-FDA: 81462084564.30.F8B2ACD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 63C564000A for ; Thu, 16 Nov 2023 01:29:20 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MDL2fyfx; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.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=1700098160; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=i0M65PApL8h6gQcrG6fLgH2zAjMUA+gwn5/0n3MZLTE=; b=BqpJpTps627EHhu7lbwneQkv+KhWqDV9tIUbibeV/WWDcUOjncKnabkJMx8pxNS68JmQvS HJ2nxoXCEfg1pyul7uAEcMTnQuprCMcCm8jGlmfEHO4VvISJS/LJZ2HFi+zBtfK76LTgMD RG+yrWf53B3hX//Qa1hLWgxKGxjaWO0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MDL2fyfx; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.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=1700098160; a=rsa-sha256; cv=none; b=rEzHautrM5CP0DTKd+F13+259gonkk9OQSGrMI9k8MpdUyWqlBkQaPBo2+eIhrYZ18AXXZ +yECySpq64ZVX+omfMmJ5K7agFDbHfyta7K87RvCwCIboYkC2cEsdJDs3oyzf84klHuC3P GatyGT6quf93v/SQxrWxPdNA6neSPTw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700098159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i0M65PApL8h6gQcrG6fLgH2zAjMUA+gwn5/0n3MZLTE=; b=MDL2fyfxPG+pvu3smhKh3tlxnwBFbIlET5vr7Ll3chZiQr2rkIalilgHiD8C8gDdMKke+8 rrhQRYnr/gTUqAg9jU60u7CEcreI6JnwI0TUgj5Tc2bXJ7k8Mh+I/jkcZ+uBu4bGhlnplp YUx+bljIOIpXytFecX+Q3ceyl1xE7ng= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-UhXfdOTROVO4J-3itagVxA-1; Wed, 15 Nov 2023 20:29:18 -0500 X-MC-Unique: UhXfdOTROVO4J-3itagVxA-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-421be23b19aso883431cf.1 for ; Wed, 15 Nov 2023 17:29:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700098158; x=1700702958; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i0M65PApL8h6gQcrG6fLgH2zAjMUA+gwn5/0n3MZLTE=; b=G9yKD+r2GfczKxRNQG2qYnrOVqVbzFma4cC+f3m4pftS+RgaJ5vYCcR+pPcjb28j9v WcdR65ZiZwRAsmXYc4zZTHnhf7DE9bX9YLmnZGxVhnK5tp6xpbgPBEzX37Y+/NGQtr1L xD/3+2AvNN/iL4GkCiDYuU9bDb9npdxuo/6Zky9U3n1MT+dqpTjTckOA5rx2Sjnbwq3+ gkPqayNPz53YPY9Ea6RHH4Y/8P9P4u2XccWqDhKXGz/g4LkJIlixu9F7EWs3aKDZNYfa cj6ZoB4guFibztS8C9D6K90hhWbEI4ffhukVGMDQM9d/DKrVFW9jc+d5cQ0nq1fYHo4p 5AFA== X-Gm-Message-State: AOJu0YxtDrGnU8Mk4crq7en8CnDukMP1OOcChd8TLhUvxKT1oU3oLp/q 2RqMlcc4CB/CcHcme4lfHSta7nxBntk9OxiadDGYteNus4aPHn9xFm8cfiqjMQJWR3z6Xxd/wvq kFTUadkY/gWw= X-Received: by 2002:ac8:4716:0:b0:421:abb7:1eac with SMTP id f22-20020ac84716000000b00421abb71eacmr7303882qtp.0.1700098157802; Wed, 15 Nov 2023 17:29:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+ZhOFntlbofY44x0fylWHFWXMzqejypTQt/uP49OXaw97pBVx5pY9jGkMxKB+HQGuvx0qxQ== X-Received: by 2002:ac8:4716:0:b0:421:abb7:1eac with SMTP id f22-20020ac84716000000b00421abb71eacmr7303852qtp.0.1700098157463; Wed, 15 Nov 2023 17:29:17 -0800 (PST) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id c24-20020ac85198000000b0041e383d527esm3922598qtn.66.2023.11.15.17.29.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 17:29:16 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , "Kirill A . Shutemov" , Lorenzo Stoakes , Axel Rasmussen , Matthew Wilcox , John Hubbard , Mike Rapoport , peterx@redhat.com, Hugh Dickins , David Hildenbrand , Andrea Arcangeli , Rik van Riel , James Houghton , Yang Shi , Jason Gunthorpe , Vlastimil Babka , Andrew Morton Subject: [PATCH RFC 04/12] mm: Introduce vma_pgtable_walk_{begin|end}() Date: Wed, 15 Nov 2023 20:29:00 -0500 Message-ID: <20231116012908.392077-5-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231116012908.392077-1-peterx@redhat.com> References: <20231116012908.392077-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 63C564000A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: gn9d1id5w6kxcs7cgtfkepfe8ywbsxfn X-HE-Tag: 1700098160-315803 X-HE-Meta: U2FsdGVkX19N+3VgBtlWU2tRGiDEm1y5L4uSqJ4MNeW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IInp0TRxdXMb3z22nnXFlIQE+xLeRSluarChnyD55whl0h8p0leP2n2pLQno//vFvqMM6+r1L+JHi5sxiuZSuWFD4D0LMmGdhlM1a0hswY4vUcS3tTtLXjp0JGJgW1yCY4oXWHbDx1e4hdd/m4rN6zrELan+6RVuuGAG1X5hU0j4NUyhgfw0m1DPzmy4Zs13+EozxvU6ztEJgcYH8ikmqt+JS8/PrQE8BwOs6agnHtv4H7+XUYYV8SqH5NbxoROBrboFpFOjnCICabrAncr3YV21yolQSEPopfWUD3wdglrsAhNH9nZ0DiLTjwJZgwBrlhErYcGKj7fQ== 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: 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). Signed-off-by: Peter Xu Reviewed-by: Christoph Hellwig --- 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 64cd1ee4aacc..349232dd20fb 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4154,4 +4154,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 e27e2e5beb3f..3a6434b40d87 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6180,3 +6180,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); +}