* [Devel] [PATCH hci-8.1 0/1] drm/amdgpu: fix init ordering in amdgpu_vram_mgr_init()
@ 2026-11-06 14:55 Mirian Shilakadze
2026-11-06 14:55 ` [Devel] [PATCH hci-8.1 1/1] ms/drm/amdgpu: Fix " Mirian Shilakadze
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Mirian Shilakadze @ 2026-11-06 14:55 UTC (permalink / raw)
To: khorenko; +Cc: devel
Backport of the upstream stable fix e773798e14ac ("drm/amdgpu: Fix
init ordering in amdgpu_vram_mgr_init()"). It registers the dmem
region after the VRAM manager lists and buddy allocator are set up, so
a failed registration leaves a manager that can be torn down safely.
It is a clean cherry-pick, the changed lines are the same as upstream,
and it only moves the registration down, nothing else changes.
Not run: we have no node with an AMD GPU. Build-tested only,
amdgpu_vram_mgr.o compiles with the 211.52.1.22.19 config.
As far as I can tell from reading the code, the crash described
upstream cannot be triggered in our kernel. amdgpu_ttm_fini() is only
reached from the GMC block sw_fini, and amdgpu_device_ip_fini() skips
a block whose sw_init failed, so a failed registration just fails
the probe.
https://virtuozzo.atlassian.net/browse/VSTOR-153702
Thomas Hellström (1):
ms/drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
--
2.43.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Devel] [PATCH hci-8.1 1/1] ms/drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()
2026-11-06 14:55 [Devel] [PATCH hci-8.1 0/1] drm/amdgpu: fix init ordering in amdgpu_vram_mgr_init() Mirian Shilakadze
@ 2026-11-06 14:55 ` Mirian Shilakadze
2026-11-06 15:00 ` no-reply
2026-11-12 13:31 ` Konstantin Khorenko
2026-11-12 13:31 ` [Devel] [PATCH hci-8.1 0/1] drm/amdgpu: fix " Konstantin Khorenko
2026-11-12 13:32 ` Konstantin Khorenko
2 siblings, 2 replies; 6+ messages in thread
From: Mirian Shilakadze @ 2026-11-06 14:55 UTC (permalink / raw)
To: khorenko; +Cc: devel
From: Thomas Hellström <thomas.hellstrom@linux.intel.com>
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.
Reported-by: Sashiko-bot <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260428073116.15687-1-thomas.hellstrom@linux.intel.com?part=4
Fixes: 2b624a2c1865 ("drm/ttm: Handle cgroup based eviction in TTM")
Cc: Friedrich Vock <friedrich.vock@gmx.de>
Cc: Maarten Lankhorst <dev@lankhorst.se>
Cc: Tejun Heo <tj@kernel.org>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: amd-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Cc: stable@vger.kernel.org # v6.14+
Assisted-by: GitHub_Copilot:claude-sonnet-4.6
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Reviewed-By: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Tested-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Link: https://patch.msgid.link/20260725100036.2372-2-thomas.hellstrom@linux.intel.com
Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
(cherry picked from commit e773798e14ac0aea54ca9676083b91f445e5bc59)
https://virtuozzo.atlassian.net/browse/VSTOR-153702
Feature: fix ms/drm
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 9d934c07fa6b..2e457a0388a3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -917,9 +917,6 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
struct 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);
@@ -934,6 +931,10 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
if (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;
--
2.43.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Devel] [PATCH hci-8.1 1/1] ms/drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()
2026-11-06 14:55 ` [Devel] [PATCH hci-8.1 1/1] ms/drm/amdgpu: Fix " Mirian Shilakadze
@ 2026-11-06 15:00 ` no-reply
2026-11-12 13:31 ` Konstantin Khorenko
1 sibling, 0 replies; 6+ messages in thread
From: no-reply @ 2026-11-06 15:00 UTC (permalink / raw)
To: Mirian Shilakadze, khorenko; +Cc: devel
> From: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>
> 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
> [ ... ]
>
> https://virtuozzo.atlassian.net/browse/VSTOR-153702
> Feature: fix ms/drm
>
> Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261106145524.96305-1-mirian.shilakadze@virtuozzo.com?part=1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Devel] [PATCH hci-8.1 0/1] drm/amdgpu: fix init ordering in amdgpu_vram_mgr_init()
2026-11-06 14:55 [Devel] [PATCH hci-8.1 0/1] drm/amdgpu: fix init ordering in amdgpu_vram_mgr_init() Mirian Shilakadze
2026-11-06 14:55 ` [Devel] [PATCH hci-8.1 1/1] ms/drm/amdgpu: Fix " Mirian Shilakadze
@ 2026-11-12 13:31 ` Konstantin Khorenko
2026-11-12 13:32 ` Konstantin Khorenko
2 siblings, 0 replies; 6+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 13:31 UTC (permalink / raw)
To: Mirian Shilakadze; +Cc: devel
Applying as is.
On Fri, 06 Nov 2026 18:55:18 +0400, Mirian Shilakadze wrote:
> Thomas Hellström (1):
> ms/drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()
Thanks. Your reading of the probe path is right: a failed GMC sw_init
never reaches amdgpu_ttm_fini(), so the crash cannot happen here.
Separate patches, not needed for this one; I created a task for
each:
1. amdgpu_vram_mgr_init(): free the buddy allocator when
drmm_cgroup_register_region() fails, call drm_buddy_fini(&mgr->mm)
before "return PTR_ERR(man->cg);".
Why: the registration now runs after drm_buddy_init(), and with no
teardown on that path an -ENOMEM at probe leaks the buddy memory.
Upstream added the same call in bd4f284df04d ("drm/amdgpu: Wire up
dmem cgroup reclaim for VRAM manager"), the reclaim wiring we did
not take.
https://virtuozzo.atlassian.net/browse/VSTOR-154845
2. Backport 7d0507772406 ("drm/buddy: release free_trees array on buddy
mm teardown").
Why: our drm_buddy_fini() frees each free tree but not the
free_trees array itself, so every amdgpu or xe unload leaks it.
https://virtuozzo.atlassian.net/browse/VSTOR-154850
3. amdgpu_ttm_init() and gmc_v*_sw_init(): undo ttm_device_init() on
the error paths after it. Fix it upstream first (amd-gfx), then
backport.
Why: a probe that fails after ttm_device_init() (a VRAM or GTT heap
error, gart_init, -ENOMEM) never reaches ttm_device_fini(), because
sw_fini is skipped for a block whose sw_init failed. The bdev stays
on the TTM global device list while adev is freed with the failed
probe, and the next TTM swapout or ttm_device_init() of another GPU
walks into freed memory. Mainline has the same code.
https://virtuozzo.atlassian.net/browse/VSTOR-154875
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Devel] [PATCH hci-8.1 1/1] ms/drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()
2026-11-06 14:55 ` [Devel] [PATCH hci-8.1 1/1] ms/drm/amdgpu: Fix " Mirian Shilakadze
2026-11-06 15:00 ` no-reply
@ 2026-11-12 13:31 ` Konstantin Khorenko
1 sibling, 0 replies; 6+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 13:31 UTC (permalink / raw)
To: Mirian Shilakadze; +Cc: devel
Applying as is.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Devel] [PATCH hci-8.1 0/1] drm/amdgpu: fix init ordering in amdgpu_vram_mgr_init()
2026-11-06 14:55 [Devel] [PATCH hci-8.1 0/1] drm/amdgpu: fix init ordering in amdgpu_vram_mgr_init() Mirian Shilakadze
2026-11-06 14:55 ` [Devel] [PATCH hci-8.1 1/1] ms/drm/amdgpu: Fix " Mirian Shilakadze
2026-11-12 13:31 ` [Devel] [PATCH hci-8.1 0/1] drm/amdgpu: fix " Konstantin Khorenko
@ 2026-11-12 13:32 ` Konstantin Khorenko
2 siblings, 0 replies; 6+ messages in thread
From: Konstantin Khorenko @ 2026-11-12 13:32 UTC (permalink / raw)
To: Mirian Shilakadze; +Cc: devel
On Fri, 06 Nov 2026 18:55:18 +0400, Mirian Shilakadze wrote:
> drm/amdgpu: fix init ordering in amdgpu_vram_mgr_init()
>
> Backport of the upstream stable fix e773798e14ac ("drm/amdgpu: Fix
> init ordering in amdgpu_vram_mgr_init()"). It registers the dmem
> region after the VRAM manager lists and buddy allocator are set up, so
> a failed registration leaves a manager that can be torn down safely.
> It is a clean cherry-pick, the changed lines are the same as upstream,
> and it only moves the registration down, nothing else changes.
>
> [...]
Applied to branch-rh10-6.12.0-211.52.1.22.x.vz10-ovz, will be released in rh10-6.12.0-211.52.1.22.21.vz10, thanks!
[1/1] ms/drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/ffbc4c6f4d0b
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-12 13:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06 14:55 [Devel] [PATCH hci-8.1 0/1] drm/amdgpu: fix init ordering in amdgpu_vram_mgr_init() Mirian Shilakadze
2026-11-06 14:55 ` [Devel] [PATCH hci-8.1 1/1] ms/drm/amdgpu: Fix " Mirian Shilakadze
2026-11-06 15:00 ` no-reply
2026-11-12 13:31 ` Konstantin Khorenko
2026-11-12 13:31 ` [Devel] [PATCH hci-8.1 0/1] drm/amdgpu: fix " Konstantin Khorenko
2026-11-12 13:32 ` Konstantin Khorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox