From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D9233AA1A5 for ; Thu, 5 Mar 2026 14:51:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772722281; cv=none; b=Xxz7xT9YXXxriPMQXMRF81OBec21iXBgtONz6fyR+JETryN7Z8sXHI/P91k9tcI+Zy/bRHEnmde9ArlGnvFUWaXhclYIxfeH0ipu69wNRM2XlrgHzVc1rEJA0RMp5es0Z3NyqjjlvAGyNrQp6oxpZ6G3MtRxv2pGwNvMiK19FA0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772722281; c=relaxed/simple; bh=/w8TcpKcTnsFexEJat+yvEFtYbwnKnSmrwKbNj1qvfE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Kdodzwa86QsMoTRF25sVUjctMxZaf+G4Uwwc3SSfwC52LrbXUwJxxy/RwWviE1aVhdzeZcGcRXONeGuRRhDyLK/0K1nlrAsCxpJqPGohvAtvf8y1q2+xmXtxCgGJKUBUBZX+8G0aiCtMBacdCC3Df7d2Ai6yrpbne7oFLtq9Jxk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2C8BB339; Thu, 5 Mar 2026 06:51:11 -0800 (PST) Received: from [10.43.18.28] (e126510-lin.lund.arm.com [10.43.18.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8559A3F694; Thu, 5 Mar 2026 06:51:09 -0800 (PST) Message-ID: Date: Thu, 5 Mar 2026 15:51:05 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH RFC 00/19] mm: Add __GFP_UNMAPPED To: Brendan Jackman , Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Vlastimil Babka , Wei Xu , Johannes Weiner , Zi Yan Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, rppt@kernel.org, Sumit Garg , derkling@google.com, reijiw@google.com, Will Deacon , rientjes@google.com, "Kalyazin, Nikita" , patrick.roy@linux.dev, "Itazuri, Takahiro" , Andy Lutomirski , David Kaplan , Thomas Gleixner , Yosry Ahmed , Ryan Roberts , Rick Edgecombe References: <20260225-page_alloc-unmapped-v1-0-e8808a03cd66@google.com> Content-Language: en-GB From: Kevin Brodsky In-Reply-To: <20260225-page_alloc-unmapped-v1-0-e8808a03cd66@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 25/02/2026 17:34, Brendan Jackman wrote: > .:::: Design: Introducing "freetypes" > > The biggest challenge for efficiently getting stuff out of the direct > map is TLB flushing. Pushing this problem into the page allocator turns > out to enable amortising that flush cost into almost nothing. The core > idea is to have pools of already-unmapped pages. We'd like those pages > to be physically contiguous so they don't unduly fragment the pagetables > around them, and we'd like to be able to efficiently look up these > already-unmapped pages during allocation. The page allocator already has > deeply-ingrained functionality for physically grouping pages by a > certain attribute, and then indexing free pages by that attribute, this > mechanism is: migratetypes. > > So basically, this series extends the concepts of migratetypes in the > allocator so that as well as just representing mobility, they can > represent other properties of the page too. (Actually, migratetypes are > already sort of overloaded, but the main extension is to be able to > represent _orthogonal_ properties). In order to avoid further > overloading the concept of a migratetype, this extension is done by > adding a new concept on top of migratetype: the _freetype_. A freetype > is basically just a migratetype plus some flags, and it replaces > migratetypes wherever the latter is currently used as to index free > pages. > > The first freetype flag is then added, which marks the pages it indexes > as being absent from the direct map. This is then used to implement the > new __GFP_UNMAPPED flag, which allocates pages from pageblocks that have > the new flag, or unmaps pages if no existing ones are already available. This approach seems very interesting to me, and I wonder if it could be applied to another use-case. I am working on a security feature to protect page table pages (PTPs) using pkeys [1]. This relies on all PTPs being mapped with a specific pkey (in the direct map). That requires changing a mapping attribute rather than making it invalid, but AFAICT this is essentially the same problem as the one you're trying to solve. There are however extra challenges with mapping PTPs with special attributes. The main one, which you mention in patch 17, is that splitting the direct map may require allocating PTPs, which may lead to recursion. [1] introduces a dedicated page table allocator on top of the buddy allocator, which attempts to cache PMD-sized blocks if possible. It ensures that no recursion occurs by using a special flag when allocating PTPs while splitting the direct map, and keeping a reserve of pages specifically for that situation (patch 15 and 24). There is also special handling for early page tables (essentially keeping track of them and setting their pkey once we can split the direct map). Do you think that this freetype infrastructure could be used for that purpose, instead of introducing a layer on top of the buddy allocator? I expect that much of the special handling for allocating PTPs can be kept separate. Ensuring that protected pages are always available to split the direct map may be difficult though... This is deeply embedded in the allocator I proposed. - Kevin [1] https://lore.kernel.org/linux-hardening/20260227175518.3728055-1-kevin.brodsky@arm.com/