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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 3E00CFCB61E for ; Fri, 6 Mar 2026 16:11:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F20B010ED7D; Fri, 6 Mar 2026 16:11:27 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="mTF0Gake"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0917910E0AC; Fri, 6 Mar 2026 16:11:26 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id BB78F401C6; Fri, 6 Mar 2026 16:11:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 133AAC4CEF7; Fri, 6 Mar 2026 16:11:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772813485; bh=giDNf5Uurfn7J3U1n15U/wA3Va2VYqmcI//1lmmKH8U=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=mTF0GakeaIpC4RT05s8KQlYVtcp9iPQeMAh7LhMmX6PqqJW5gvxQuVHNGKS/dwqAr lJuhmLkipTH46kV4owrtV6UV21IyyFx7KBJmmXFACQuSZAR9duYEBUlnhSWTaU+dN8 AEvDj7a7bcwDMJ1zPU6USQfFKTpQM8goxhWuoeMOERgdPpyLAWzva4xGwnPmC+5rh7 K1pcDuSLGQ0PvcZK9VXPdK9Wq1W2fuhXAH1q3F3jtQrQFW+mxolk2K8LC478yYCber 61qM96UpnGv7AFe3yjcbie0qlBFgrdAvPadCTGeZkxkhF5akJGW8QJQkq2Met1A4k8 kbDI855WQ0IzA== Message-ID: Date: Fri, 6 Mar 2026 17:11:13 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 13/13] mm: Remove device private pages from the physical address space To: Jordan Niethe , linux-mm@kvack.org Cc: balbirs@nvidia.com, matthew.brost@intel.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, ziy@nvidia.com, apopple@nvidia.com, lorenzo.stoakes@oracle.com, lyude@redhat.com, dakr@kernel.org, airlied@gmail.com, simona@ffwll.ch, rcampbell@nvidia.com, mpenttil@redhat.com, jgg@nvidia.com, willy@infradead.org, linuxppc-dev@lists.ozlabs.org, intel-xe@lists.freedesktop.org, jgg@ziepe.ca, Felix.Kuehling@amd.com, jhubbard@nvidia.com, maddy@linux.ibm.com, mpe@ellerman.id.au, ying.huang@linux.alibaba.com References: <20260202113642.59295-1-jniethe@nvidia.com> <20260202113642.59295-14-jniethe@nvidia.com> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU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xdzNQtLtgZzOV 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: <20260202113642.59295-14-jniethe@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" On 2/2/26 12:36, Jordan Niethe wrote: > The existing design of device private memory imposes limitations which > render it non functional for certain systems and configurations where > the physical address space is limited. > > Device private memory is implemented by first reserving a region of the > physical address space. This is a problem. The physical address space is > not a resource that is directly under the kernel's control. Availability > of suitable physical address space is constrained by the underlying > hardware and firmware and may not always be available. > > Device private memory assumes that it will be able to reserve a device > memory sized chunk of physical address space. However, there is nothing > guaranteeing that this will succeed, and there a number of factors that > increase the likelihood of failure. We need to consider what else may > exist in the physical address space. It is observed that certain VM > configurations place very large PCI windows immediately after RAM. Large > enough that there is no physical address space available at all for > device private memory. This is more likely to occur on 43 bit physical > width systems which have less physical address space. > > Instead of using the physical address space, introduce a device private > address space and allocate devices regions from there to represent the > device private pages. > > Introduce a new interface memremap_device_private_pagemap() that > allocates a requested amount of device private address space and creates > the necessary device private pages. > > To support this new interface, struct dev_pagemap needs some changes: > > - Add a new dev_pagemap::nr_pages field as an input parameter. > - Add a new dev_pagemap::pages array to store the device > private pages. > > When using memremap_device_private_pagemap(), rather then passing in > dev_pagemap::ranges[dev_pagemap::nr_ranges] of physical address space to > be remapped, dev_pagemap::nr_ranges will always be 1, and the device > private range that is reserved is returned in dev_pagemap::range. > > Forbid calling memremap_pages() with dev_pagemap::ranges::type = > MEMORY_DEVICE_PRIVATE. > > Represent this device private address space using a new > device_private_pgmap_tree maple tree. This tree maps a given device > private address to a struct dev_pagemap, where a specific device private > page may then be looked up in that dev_pagemap::pages array. > > Device private address space can be reclaimed and the assoicated device > private pages freed using the corresponding new > memunmap_device_private_pagemap() interface. > > Because the device private pages now live outside the physical address > space, they no longer have a normal PFN. This means that page_to_pfn(), > et al. are no longer meaningful. > > Introduce helpers: > > - device_private_page_to_offset() > - device_private_folio_to_offset() > > to take a given device private page / folio and return its offset within > the device private address space. > > Update the places where we previously converted a device private page to > a PFN to use these new helpers. When we encounter a device private > offset, instead of looking up its page within the pagemap use > device_private_offset_to_page() instead. > > Update the existing users: > > - lib/test_hmm.c > - ppc ultravisor > - drm/amd/amdkfd > - gpu/drm/xe > - gpu/drm/nouveau > > to use the new memremap_device_private_pagemap() interface. > > Acked-by: Felix Kuehling > Reviewed-by: Zi Yan # for MM changes > Signed-off-by: Jordan Niethe > Signed-off-by: Alistair Popple > > --- > v1: > - Include NUMA node paramater for memremap_device_private_pagemap() > - Add devm_memremap_device_private_pagemap() and friends > - Update existing users of memremap_pages(): > - ppc ultravisor > - drm/amd/amdkfd > - gpu/drm/xe > - gpu/drm/nouveau > - Update for HMM huge page support > - Guard device_private_offset_to_page and friends with CONFIG_ZONE_DEVICE > > v2: > - Make sure last member of struct dev_pagemap remains DECLARE_FLEX_ARRAY(struct range, ranges); > > v3: > - Use numa_mem_id() if memremap_device_private_pagemap is called with > NUMA_NO_NODE. This fixes a null pointer deref in > lruvec_stat_mod_folio(). > - drm/xe: Remove call to devm_release_mem_region() in xe_pagemap_destroy_work() > - s/VM_BUG/VM_WARN/ > > v4: > - Use devm_memunmap_device_private_pagemap() in > xe_pagemap_destroy_work() > - Replace ^ with != for PVMW_DEVICE_PRIVATE comparisions > - Minor style changes > - remove discussion of aarch64 from commit message - not relevant post > eeb8fdfcf090 ("arm64: Expose the end of the linear map in PHYSMEM_END") > > v6: > - Fix maybe unused in kgd2kfd_init_zone_device() > - Replace division by PAGE_SIZE with DIV_ROUND_UP() when setting > nr_pages. This mirrors the align up that previously happened in > get_free_mem_region() > --- There is just too much in this patch to review it reasonably. You should probably have a patch that just introduces the helpers and have them just do what we to today. E.g., device_private_page_to_offset() would just do a pfn_to_page(). Then you can convert individual core-mm pieces that I people can review them making their brain hurt. Afterwards, you can have a patch that does the real "mm: Remove device private pages from the physical address space" and doesn't have to touch too many core-mm pieces. [...] > diff --git a/mm/util.c b/mm/util.c > index 65e3f1a97d76..8482ebc5c394 100644 > --- a/mm/util.c > +++ b/mm/util.c > @@ -1244,7 +1244,10 @@ void snapshot_page(struct page_snapshot *ps, const struct page *page) > struct folio *foliop; > int loops = 5; > > - ps->pfn = page_to_pfn(page); > + if (is_device_private_page(page)) > + ps->pfn = device_private_page_to_offset(page); > + else > + ps->pfn = page_to_pfn(page); > ps->flags = PAGE_SNAPSHOT_FAITHFUL; Why is that not done by the caller? -- Cheers, David