Linux cgroups development
 help / color / mirror / Atom feed
From: Arunpravin Paneer Selvam <arunpravin.paneerselvam@amd.com>
To: "Christian König" <christian.koenig@amd.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	intel-xe@lists.freedesktop.org
Cc: Sashiko-bot <sashiko-bot@kernel.org>,
	"Friedrich Vock" <friedrich.vock@gmx.de>,
	"Maarten Lankhorst" <dev@lankhorst.se>,
	"Tejun Heo" <tj@kernel.org>, "Maxime Ripard" <mripard@kernel.org>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	stable@vger.kernel.org, "Natalie Vock" <natalie.vock@gmx.de>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	cgroups@vger.kernel.org, "Huang Rui" <ray.huang@amd.com>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Matthew Auld" <matthew.auld@intel.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Simona Vetter" <simona@ffwll.ch>,
	"David Airlie" <airlied@gmail.com>,
	"Thadeu Lima de Souza Cascardo" <cascardo@igalia.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 1/6] drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()
Date: Tue, 7 Jul 2026 23:35:49 +0530	[thread overview]
Message-ID: <9c8b4367-c029-4731-8ea8-b8263e11ada1@amd.com> (raw)
In-Reply-To: <9eae1a5c-d2ef-4d75-a581-58299ca37a1f@amd.com>



On 7/3/2026 6:38 PM, Christian König wrote:
> Arun please take a look at this.
Sure Christian. This fix looks correct to me.
Reviewed-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>

Thanks,
Arun.
>
> Thanks,
> Christian.
>
> On 7/3/26 15:05, Thomas Hellström wrote:
>> 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>
>> ---
>>   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 2a241a5b12c4..ac3f71d77140 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
>> @@ -918,9 +918,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);
>>   
>> @@ -935,6 +932,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;


  parent reply	other threads:[~2026-07-07 18:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03 13:05 [PATCH v7 0/6] Add reclaim to the dmem cgroup controller Thomas Hellström
2026-07-03 13:05 ` [PATCH v7 1/6] drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init() Thomas Hellström
2026-07-03 13:08   ` Christian König
2026-07-03 13:11     ` Thomas Hellström
2026-07-07 18:05     ` Arunpravin Paneer Selvam [this message]
2026-07-03 13:05 ` [PATCH v7 2/6] cgroup/dmem: Introduce struct dmem_cgroup_init for region initialization Thomas Hellström
2026-07-03 13:05 ` [PATCH v7 3/6] cgroup/dmem: Add reclaim callback for lowering max below current usage Thomas Hellström
2026-07-06 19:25   ` Tejun Heo
2026-07-07  7:20     ` Thomas Hellström
2026-07-07 10:01     ` Maarten Lankhorst
2026-07-03 13:05 ` [PATCH v7 4/6] drm/ttm: Hook up a cgroup-aware reclaim callback for the dmem controller Thomas Hellström
2026-07-03 13:05 ` [PATCH v7 5/6] drm/xe: Wire up dmem cgroup reclaim for VRAM manager Thomas Hellström
2026-07-03 13:05 ` [PATCH v7 6/6] drm/amdgpu: " Thomas Hellström
2026-07-03 14:37 ` [PATCH v7 0/6] Add reclaim to the dmem cgroup controller Thadeu Lima de Souza Cascardo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9c8b4367-c029-4731-8ea8-b8263e11ada1@amd.com \
    --to=arunpravin.paneerselvam@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=cascardo@igalia.com \
    --cc=cgroups@vger.kernel.org \
    --cc=christian.koenig@amd.com \
    --cc=dev@lankhorst.se \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=friedrich.vock@gmx.de \
    --cc=hannes@cmpxchg.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matthew.auld@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=mkoutny@suse.com \
    --cc=mripard@kernel.org \
    --cc=natalie.vock@gmx.de \
    --cc=ray.huang@amd.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=sashiko-bot@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.kernel.org \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tj@kernel.org \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox