From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7906438FFB; Wed, 8 Jul 2026 12:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783515011; cv=none; b=mYF0cgU1dCYkz9S6x3fgoOQBXRVrbuODdd28hCmLJ4+2wT4lKOrbGEjzlf5RrItz4SM1eEyF9gHxPxCViFIv6p9jphF/INqZj+rCmdYr5qj5fR0e9f3I2MtvuEc54jOxK0lCHnic3GlCllY5qViMStLqGcf7QTovv96HPK3oM6w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783515011; c=relaxed/simple; bh=IbwF4pMHfyhwOslYT5YnzmrvzgTa5uH5GBgU1nK9uiI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RNjmFQYyO1Jg6KkQGwSC8CVMXnKm6UPOZCdNq63h8S3FPArP8O8/qbI+dPplRV3suSHb5o5VwXEzSVzPkz8TX06+quh0REhCzpppy9nkYg1E2RY4PiM8Jc5F3M4368mpsrfn4mHbEsn6rXapPnH5XIiV0htv5HVE3w37LuOCyGM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jitZrOHB; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jitZrOHB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2693F1F000E9; Wed, 8 Jul 2026 12:50:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783515007; bh=IbwF4pMHfyhwOslYT5YnzmrvzgTa5uH5GBgU1nK9uiI=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=jitZrOHBE9XNJumMdXFVv18tUngtPLdb9x2l4MXb1a4a3audPmwI5ES1+E/p39+fH HMBtTttJu5WKPwMZpzl5XSMW8IWWsdWOQpWuuuOHUvCzW0Upi/fHIEHKy/XatkKhbs YIrgECVYDaOyOlaeXFov/nDhiba0x7J/yL1Q67FUZOmQNsefjzpkn/aCjEu0dJ6ZK9 nlap2Fjp+x+P5ahqGT40ffudUAfNKdE4tL3hjqRQjY1+Q8v+zswk6N6KyX0QPm3fqz Jak61XpK3z4GmnyZVFYWCCa1m5lbXTTe07OjSwKUXfEIRonD9IqEaS2TOTSr62FACC l7BKByWi/ic2A== Date: Wed, 8 Jul 2026 14:50:04 +0200 From: Thierry Reding To: Will Deacon Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Hunter , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Sowjanya Komatineni , Luca Ceresoli , Mikko Perttunen , Yury Norov , Rasmus Villemoes , Russell King , Alexander Gordeev , Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Marek Szyprowski , Robin Murphy , Sumit Semwal , Benjamin Gaignard , Brian Starkey , John Stultz , "T.J. Mercier" , Christian =?utf-8?B?S8O2bmln?= , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Catalin Marinas , Thierry Reding , devicetree@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux.dev, linaro-mm-sig@lists.linaro.org, linux-trace-kernel@vger.kernel.org, Thierry Reding , Chun Ng Subject: Re: [PATCH v3 04/11] arm64/mm: Add set_memory_device() and set_memory_normal() Message-ID: References: <20260701-tegra-vpr-v3-0-d80f7b871bb4@nvidia.com> <20260701-tegra-vpr-v3-4-d80f7b871bb4@nvidia.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="gs6kcdn3aiethnov" Content-Disposition: inline In-Reply-To: --gs6kcdn3aiethnov Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH v3 04/11] arm64/mm: Add set_memory_device() and set_memory_normal() MIME-Version: 1.0 On Tue, Jul 07, 2026 at 12:27:13PM +0100, Will Deacon wrote: > On Mon, Jul 06, 2026 at 03:49:24PM +0200, Thierry Reding wrote: > > On Fri, Jul 03, 2026 at 06:13:31PM +0100, Will Deacon wrote: > > > On Thu, Jul 02, 2026 at 06:41:23PM +0200, Thierry Reding wrote: > > > > On Thu, Jul 02, 2026 at 03:46:44PM +0200, Thierry Reding wrote: > > > > > On Thu, Jul 02, 2026 at 10:18:47AM +0100, Will Deacon wrote: > > > > > > On Wed, Jul 01, 2026 at 06:08:15PM +0200, Thierry Reding wrote: > > > > > > > From: Chun Ng > > > > > > >=20 > > > > > > > Add helpers to swap PROT_NORMAL and PROT_DEVICE_nGnRnE protec= tion bits > > > > > > > on a kernel-linear-map range. > > > > > >=20 > > > > > > That sounds like a really terrible idea. Why is this necessary = and how > > > > > > does it interact with things like load_unaligned_zeropad()? > > > > >=20 > > > > > This is necessary because once the memory controller has walled o= ff the > > > > > new memory region the CPU must not access it under any circumstan= ces or > > > > > it'll cause the CPU to lock up (I think technically it'll hit an = SError > > > > > but in practice that just means it'll freeze, as far as I can tel= l). > > > > >=20 > > > > > Probably doesn't interact well at all with load_unaligned_zeropad= (). > > > > >=20 > > > > > > I think you should unmap the memory from the linear map and mem= remap() > > > > > > it instead. > > > > >=20 > > > > > Given that the memory can never be accessed by the CPU after the = memory > > > > > controller locks it down, I don't think we'll even need memremap(= ). The > > > > > only thing we really need is the sg_table we hand out via the DMA= BUFs > > > > > so that they can be used by device drivers to program their DMA e= ngines > > > > > internally. > > > > >=20 > > > > > Looking through some of the architecture code around this, should= n't we > > > > > simply be using set_memory_encrypted() and set_memory_decrypted()= for > > > > > this? While they might've been created for slightly other use-cas= es, > > > > > they seem to be doing exactly what we want (i.e. remove the page = range > > > > > from the linear mapping and flushing it, or restoring the valid b= it and > > > > > standard permissions, respectively). > > > >=20 > > > > Ah... I guess we can't do it because we're not in a realm world and= so > > > > the early checks in __set_memory_enc_dec() would return early and t= urn > > > > it into a no-op. > > > >=20 > > > > How about if I extract a common helper and provide set_memory_p() a= nd > > > > set_memory_np() in terms of those. Those are available on x86 and > > > > PowerPC as well, so fairly standard. I suppose at that point we're > > > > closer to set_memory_valid(). > > >=20 > > > Why not just call set_direct_map_invalid_noflush() + > > > flush_tlb_kernel_range() for each page? We already have APIs for this. > >=20 > > Having a "standard" helper with a fixed and documented purposed seemed > > like a preferable approach for this particular case. We also may want to > > make the driver that uses this buildable as a module, in which case we'd > > need to export these rather low-level APIs. And then there's also the > > fact that we typically call this on a rather large region of memory > > (usually something like 512 MiB), so doing it page-by-page is rather > > suboptimal. > >=20 > > > The big challenge I see with any linear map manipulation, however, is > > > that it will rely on can_set_direct_map() which likely means you need= to > > > give up some performance and/or security to make this work. Does memo= ry > > > become inaccesible dynamically at runtime? If not, the best bet would > > > be to describe it as a carveout in the DT and mark it as "no-map" so > > > we avoid mapping it in the first place. > >=20 > > VPR exists in two modes: static and resizable. For static VPR we do > > exactly that: describe it as carveout in DT with no-map and deal with it > > accordingly in the driver. Resizable VPR is for device that have small > > amounts of RAM. Content-protected video playback will in the worst case > > consume around 1.8 GiB of RAM, so we want to be able to reuse for other > > purposes when VPR is unused on those devices. In that case, the memory > > is also described as a reserved-memory region in DT, but it is marked as > > reusable so that it can be managed by CMA. > >=20 > > The resize operation is fairly slow to begin with because we need to > > stall the GPU and put it into reset before the operation, then take it > > out of reset and resume it afterwards. > >=20 > > What kind of performance impact do you expect? >=20 > You'll need to measure it, but we've seen reports of double-digit > percentage regressions in performance and power. As I said, the problem > is that you need to split the linear map to 4k page at runtime to unmap > the dynamic carveout, but that isn't something that can be done on most > CPUs. Therefore you end up having to use page-granular mappings for the > entire thing, similarly to how 'rodata_full' drives can_set_direct_map() > and the perf/power hit affects everything. >=20 > It's hard to know what to suggest... I wonder if any of the memory > hotplug logic could help here? I've read up on memory hotplug a bit and it sounds like it could fit this really nicely. Given that we only use CMA (along with the extra patches to it) to make sure that any buffers are reclaimed for VPR use, we should be able to get rid of the CMA usage altogether and replace it with online_pages() and offline_pages() instead. Rather than using a fixed set of CMA areas like we currently do, each "chunk" in the VPR driver could represent a memory block instead (which looks like it will be 128 MiB for 4 KiB pages and 512 MiB for 64 KiB pages). We currently use 512 MiB as the chunk size, so it should be relatively similar and easy to adjust. One issue that we would absolutely need this memory to be ZONE_MOVABLE =66rom the start. Using no-map in DT and then online_pages() probably will not work because there's no struct page for the memory. So we're left with keeping the memory onlined by default, in which case we'd need some way for DT to instruct the memory to be put into ZONE_MOVABLE always. There's a "hotpluggable" property for "memory" nodes, maybe that can be extended to apply to reserved-memory nodes as well? Thierry --gs6kcdn3aiethnov Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEiOrDCAFJzPfAjcif3SOs138+s6EFAmpOR3kACgkQ3SOs138+ s6EbFg/9G04JpY5Cu3AX1K9vtQtrw3D5Gowsl1qT7PXe9AmN9PK2oggEDnsm6JPw hyDVKxzpLbktBMB5vNKmr4KGYrIEeW4fs+thwrdNjf5GhX7cTQyL78oHaEVTZAn7 cpiFfepSy6xW4ZDIpHzj6bUVg06S8VZmLOwKHuDbA4N6PZ95evD1ff3/TQs6Y1E6 WJhgBPjZbTLh6jiIM1y2hRK3GAChy9nC2g2R1LOySIK9NBCgfKV0p2/hv+vQCLSk e5ON2GcP06dR1XChOMnEPkUS4BzptxIzVkM7aRiGPJqxVREXJK4MvRTyjZ+W4FuX R/QDhwkxdI8+4pwfVPWB10dEWH5vfIrxU5VwO4Uujp4p14P1/nKkWXTe8S69Qitj GU8UxLk76btqwkVS43qOyHXH+yXuQBiaWBVTyo8vQx3zp5i8gq1h1xm04ryI0hWj BGqXiOxzDr6lEmXUj6h3gUTP+14whWOW8lTqIL0QTKwC4HDv5KTgfgBME2KkYAwp 1adJdmJ09vhkKAOK1mKHCJHmhOggmoDpIfH8yYSbHeTe4mZZHq9qKtFjvzA8TtMw 82H0EfyjYM8eNPNZU1/SfsTnhKpTmnLpDCmmdz6Oe4hWGxZVO16z9VujL/EPa0fa mY3dWpM8cSvKCP6jm8jguy5IhhLZkS4ljig1obSEvcH0/Tu1FJk= =zFs3 -----END PGP SIGNATURE----- --gs6kcdn3aiethnov--