From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E784C982EE for ; Mon, 21 Sep 2026 18:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jCW5MFUb1YtOsNpow2W/cS4g5/gZUIBKPxi3st6wwFI=; b=I8HxSs1DO/tUvs 4/yISqP8cSa3tuw9ZxuTTqUhObwc+nJ1Amw+IaKmXfQbyiL85ur8TCjjiLMK+2G/kjfb2Do982dIy i3jGz9EFliIAVSTv7QinV0EVXpiyJb9sw3YW6XR94Rx5T22yswvYVcqPffv697zP3Tjk9RbRhDzOi Xwg5a5ZHNxHuH2y4QUKvAv+2uUuuvCh3xvX3p9ZpkUFWehKdFMcnsNRRTaaDbkOjJNIZN80zlaO/y 5qANXDLuFyMsGYPreCYxMEXGXTkHPiJNAWys2FIP6AcT9ub6/sDHTlA5N7Ps2ydNp5Rsmvc37AV1N 5yd6pK1T3O63p56TM7YQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x8ion-000000038AP-1RhA; Mon, 21 Sep 2026 18:32:45 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x8iod-0000000387b-49zu; Mon, 21 Sep 2026 18:32:37 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 463336021E; Mon, 21 Sep 2026 18:32:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFB3C1F000FF; Mon, 21 Sep 2026 18:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790015554; bh=+pyw6OIqYdaAAArC1eiLPCVl5i4GbNp6LlCIy/JNTw8=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=WFpE9f55RKK1JMKZpFnzyVz8Dh1+RNUasf0LCrtkPk8+9726+cpRXF54sbuypEfBf 5LTBlAiInfG29CTPfkcQOP346jxknb4mbDB15wEdh54KIXQ6mAMIdM9WzPIyQQREBd SV47M1UTSYsyEzBI3js629pZI7JGj/fNujG5663D0CZbNIqkew03Eq589y7pmvK65k g/gXwVIivnPr/fkXhNnIjoo0v1e3lIKcXrEecSJnYiwZz7cRmfx/0s6haCgCO/ee8U As9PU/MVIoPu3tNUquzVZgN3iP/ywgFtdx1I5eKaNyQaELj5BTpGbJujngYk30c3LQ dgqwwYKmpuvew== Message-ID: Date: Mon, 21 Sep 2026 19:13:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 01/12] mm/huge_memory: zap deposited page tables after an RCU grace period To: "Lorenzo Stoakes (ARM)" Cc: Andrew Morton , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Kiryl Shutsemau , Guo Ren , Brian Cain , Geert Uytterhoeven , Dinh Nguyen , Simon Schuster , Jonas Bonn , Stefan Kristiansson , Stafford Horne , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Russell King , Vineet Gupta , Michal Simek , Chris Zankel , Max Filippov , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , "David S. Miller" , Andreas Larsson , Richard Henderson , Matt Turner , Magnus Lindholm , Catalin Marinas , Mark Rutland , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Madhavan Srinivasan , Michael Ellerman , "Christophe Leroy (CS GROUP)" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Richard Weinberger , Anton Ivanov , Johannes Berg , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Arnd Bergmann , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jason Gunthorpe , John Hubbard , Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-openrisc@vger.kernel.org, linux-sh@vger.kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-snps-arc@lists.infradead.org, linux-arch@vger.kernel.org, sparclinux@vger.kernel.org, linux-alpha@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-um@lists.infradead.org, Hugh Dickins , Qi Zheng References: <20260911-rcu-pagetable-freeing-v3-0-7b8c86103821@kernel.org> <20260911-rcu-pagetable-freeing-v3-1-7b8c86103821@kernel.org> <467b6599-b73a-4f58-a29a-b6c6d1ffc3a5@kernel.org> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2Ah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o3t6inu6H7pt7OL6u6BQj7DoMAEQEAAcLBfAQYAQgAJgIbDBYhBBvZyq1zXEw6Rg38yk3e EPcA/4NaBQJonNqrBQkmWAihAAoJEE3eEPcA/4NaKtMQALAJ8PzprBEXbXcEXwDKQu+P/vts IfUb1UNMfMV76BicGa5NCZnJNQASDP/+bFg6O3gx5NbhHHPeaWz/VxlOmYHokHodOvtL0WCC 8A5PEP8tOk6029Z+J+xUcMrJClNVFpzVvOpb1lCbhjwAV465Hy+NUSbbUiRxdzNQtLtgZzOV Zw7jxUCs4UUZLQTCuBpFgb15bBxYZ/BL9MbzxPxvfUQIPbnzQMcqtpUs21CMK2PdfCh5c4gS sDci6D5/ZIBw94UQWmGpM/O1ilGXde2ZzzGYl64glmccD8e87OnEgKnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On 9/16/26 18:59, Lorenzo Stoakes (ARM) wrote: > On Wed, Sep 16, 2026 at 04:42:04PM +0200, David Hildenbrand (Arm) wrote: >> On 9/11/26 21:36, Lorenzo Stoakes (ARM) wrote: >>> When an anonymous mapping is collapsed for THP, a PTE page table is >>> 'deposited' with the installed PMD entry. >> >> Right. Or when we allocate an anon THP. > > That case doesn't interact with page walking though, as they're > just-allocated right? I was surprised to read that page tables deposited during collapse should behave differently than page tables deposited during allocation :) That's the semantic change you are adding (and that I didn't quite understand from reading your description): a deposited page table could now get reused and modified for another page table due to a PMD split, while there might still be an RCU page table walker walking it. And PMD comparisons (+ proper memory ordering) have to make sure that we didn't just walk something that doesn't belong to us. [...] >> >> Wait, but wouldn't it be really problematic to punch a page table that is still > > Punch? You mean deposit? Yes! > >> being walked into the deposited list where it can just be allocated from another >> PMD->PTE split? > > In general, RCU-only page table walkers are _only_ guaranteed that the page > tables are not freed from underneath them, as per the cover letter: > > "As a result, page table walks can now be performed safely under RCU without > any risk of page tables being freed underneath a walker. > > However, this is the only guarantee that this work provides - page table > walkers must still ensure that page table entries are as expected > throughout." So far page table walkers never walk deposited page tables. Just like they never walk freed page tables. For *current* lockless page table walkers (IRQs disabled), tlb_remove_table_sync_one() takes care of that. So there is no such thing as "walking a page table that was reused in different context (as a page table) in the meantime". > > So this series doesn't actually have to answer that :) > > But a PTE PTL -> pmd_same() check will flag anything like that, > a.k.a. pte_offset_map_lock(). > > The RCU lock replaces stablisation on stuff other than VMA/mmap or rmap > lock. > > If the walker needs to be sure the PTE is actually valid and belongs to the > expected walk then further is required. > > Alternatively (like GUP-fast) if you wanted to avoid locking at all, IRQs > off would be required paired with the tlb_remove_table_sync_one() in > collapse_huge_page(). Doing an RCU sync in tlb_remove_table_sync_one() would be the big hammer (I thought that was discussed with Lance recently). There is also this option: just allocate a new page table and deposit it, and free the existing page table through RCU. Long story short: allowing empty page tables to be freed by RCU is simple. Allowing empty page tables to be reused while they are still getting walked is obviously more complicated conceptually. Likely it can be made working, but I'd hope that we can keep it simpler. > > Another strategy could be used I guess with looped checks but it gets a bit > sketchy with timing etc. > > But actually maybe we can avoid all that... > >> >> Note that pgtable_trans_huge_withdraw() just dequeues *some* PTE page table in >> the list attached to the PMD table. >> >> Something is odd here. > > ...Since this code path already allocates (the huge folio), so allocation > here isn't an issue (as long as done outside of lcosk), why not have it > also allocate a new PTE to deposit and RCU-free the existing PTE instead? > > That eliminates the one place in the kernel (afaik) where a > page-table-walker-visible table can just get yoinked over somewhere else. > > Then a lockless PMD check works. > > E.g. something like the below? Hah! Great minds think alike. -- Cheers, David _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv