Re: [PATCH] drm/amdgpu: cap GTT size to physical RAM on APUs

"Francis, David" <[email protected]> Tue, 28 Jul 2026 14:12:14 +0000
Newsgroups org.freedesktop.lists.amd-gfx
Message-ID <SA1PR12MB81449D3F0A3ADCCC6D5FEAA5EFCB2@SA1PR12MB8144.namprd12.prod.outlook.com>
Looks good to me

Reviewed-by: David Francis <[email protected]>

________________________________________
From: amd-gfx <[email protected]> on behalf of Harkirat Gill <[email protected]>
Sent: Monday, July 27, 2026 3:42 PM
To: [email protected]
Cc: Koenig, Christian; Gill, Harkirat (Harry)
Subject: [PATCH] drm/amdgpu: cap GTT size to physical RAM on APUs

[Some people who received this message don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

On APUs, the GTT pool is backed by system RAM, but its size is not bound
to the non-carveout memory that actually backs it. A user can end up
with GTT + VRAM exceeding total physical memory through the following
sequence:

 - Have a large non-carveout memory space (~128GB) and accordingly set a
   large GTT (~100GB) via the ttm module parameter.
 - Lower the non-carveout memory space in BIOS by increasing the UMA
   Frame Buffer Size (VRAM) to 64GB.
 - The previously set GTT value (~100GB) persists, even though the new
   non-carveout space (64GB) can no longer back it.

This leads to a case where kernel reports GTT (100GB) + VRAM (64GB)
despite the sum being greater than total physical memory (128GB).

Cap the GTT size to totalram_pages() on APUs. totalram_pages() already
excludes the VRAM carveout, so the resulting GTT can never exceed the
system RAM that actually backs it.

Signed-off-by: Harkirat Gill <[email protected]>
Assisted-by: Claude:claude-opus-4
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 7920675af..da89d19dd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2173,6 +2173,18 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
                gtt_size = configured_size;
        }

+       /* Cap GTT so that it does not exceed total physical RAM. */
+       if (adev->flags & AMD_IS_APU) {
+               u64 phys_ram = (u64)totalram_pages() << PAGE_SHIFT;
+
+               if (gtt_size > phys_ram) {
+                       gtt_size = phys_ram;
+                       dev_info(adev->dev,
+                                "Capping GTT to %uM to not exceed available system memory\n",
+                                (unsigned int)(gtt_size / (1024 * 1024)));
+               }
+       }
+
        /* Initialize GTT memory pool */
        r = amdgpu_gtt_mgr_init(adev, gtt_size);
        if (r) {

base-commit: ea97ab2759506d9a818ffed1009bde01062b4091
--
2.43.0