Patch "drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()" has been added to the 7.2-stable tree
Subsystems (2)
[email protected]
AppliedThis is a note to let you know that I've just added the patch titled
drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()
to the 7.2-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
drm-amdgpu-fix-init-ordering-in-amdgpu_vram_mgr_init.patch
and it can be found in the queue-7.2 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
From e773798e14ac0aea54ca9676083b91f445e5bc59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= <[email protected]>
Date: Sat, 25 Jul 2026 12:00:31 +0200
Subject: drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
From: Thomas Hellström <[email protected]>
commit e773798e14ac0aea54ca9676083b91f445e5bc59 upstream.
drmm_cgroup_register_region() is called before INIT_LIST_HEAD() and gpu_buddy_init() in amdgpu_vram_mgr_init(). If it fails, the function returns early and bypasses those initializations.
Since adev->mman.initialized is set to true before amdgpu_vram_mgr_init() is called, a failure triggers amdgpu_ttm_fini(), which calls amdgpu_vram_mgr_fini(), which then:
- Calls list_for_each_entry_safe() on reservations_pending and reserved_pages, whose list_head::next pointers are zero-initialized (NULL). The loop does not recognize them as empty and dereferences NULL.
- Calls gpu_buddy_fini(), which iterates free_trees[] unconditionally via for_each_free_tree(). Since mm->free_trees is NULL (never allocated), this dereferences NULL.
Both result in a kernel panic on the module load error path.
Fix by moving drmm_cgroup_register_region() to after the list and buddy allocator are fully initialized, so the teardown path is safe to run.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +4 -3
@@ -918,9 +918,6 @@ int amdgpu_vram_mgr_init(struct amdgpu_dstruct ttm_resource_manager *man = &mgr->manager;int err; - man->cg =drmm_cgroup_register_region (adev_to_drm (adev),"vram" , adev->gmc.real_vram_size); -if (IS_ERR (man->cg)) -return PTR_ERR (man->cg);ttm_resource_manager_init (man, &adev->mman.bdev, adev->gmc.real_vram_size);
@@ -935,6 +932,10 @@ int amdgpu_vram_mgr_init(struct amdgpu_dif (err)return err; + man->cg =drmm_cgroup_register_region (adev_to_drm (adev),"vram" , adev->gmc.real_vram_size); +if (IS_ERR (man->cg)) +return PTR_ERR (man->cg); +ttm_set_driver_manager (&adev->mman.bdev,TTM_PL_VRAM , &mgr->manager);ttm_resource_manager_set_used (man, true);return 0 ;
Patches currently in stable-queue which might be from [email protected] are
queue-7.2/drm-amdgpu-fix-init-ordering-in-amdgpu_vram_mgr_init.patch
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unfixed teardown kernel panic when gpu_buddy_init() fails --
commit 96e42e3ef488e9ad28452efe2bd6b23f7a53c47b
Author: Thomas Hellström <[email protected]>
drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()
The commit moves drmm_cgroup_register_region() to after the list and buddy allocator are fully initialized to fix a teardown kernel panic. When drmm_cgroup_register_region() fails, it triggers the teardown path which used to crash because the buddy allocator and lists weren't initialized.
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +0
-0
[ ... ]
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c int amdgpu_vram_mgr_init(struct amdgpu_device *adev) · line 933
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +0
-0@@ -935,6 +932,10 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)if (err)return err;
[Severity: High]
This is a pre-existing issue, but does this still lead to a kernel panic during teardown if gpu_buddy_init() fails?
Because adev->mman.initialized is set to true earlier in amdgpu_ttm_init(), a failure from gpu_buddy_init() triggers the teardown path in amdgpu_ttm_fini(), which calls amdgpu_vram_mgr_fini().
amdgpu_vram_mgr_fini() unconditionally calls gpu_buddy_fini():
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c:amdgpu_vram_mgr_fini() {
...
if (!adev->gmc.is_app_apu)
gpu_buddy_fini(&mgr->mm);
...
}However, if gpu_buddy_init() fails, it cleans up internally and leaves mm->free_trees as a NULL or dangling pointer:
drivers/gpu/buddy.c:gpu_buddy_init() {
...
out_free_tree:
while (i--)
kfree(mm->free_trees[i]);
kfree(mm->free_trees);
return -ENOMEM;
}Then gpu_buddy_fini() blindly iterates over these pointers:
drivers/gpu/buddy.c:gpu_buddy_fini() {
...
for_each_free_tree(i)
kfree(mm->free_trees[i]);
kfree(mm->free_trees);
kfree(mm->roots);
}Could this crash during module load under memory pressure when the allocation in gpu_buddy_init() fails?
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +4
-0+ man->cg =drmm_cgroup_register_region (adev_to_drm (adev),"vram" , adev->gmc.real_vram_size); +if (IS_ERR (man->cg)) +return PTR_ERR (man->cg); +ttm_set_driver_manager (&adev->mman.bdev,TTM_PL_VRAM , &mgr->manager);ttm_resource_manager_set_used (man, true);return 0 ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/2026090939-sarcasm-demeaning-4889@gregkh?part=1