fix TTM device_list use-after-free on failed probe
Subsystems (2)
v2 cover fix TTM device_list use-after-free on failed probe
When amdgpu probe fails after ttm_device_init() has succeeded, the freed amdgpu_device stays linked on ttm_glob.device_list. The next ttm_device_init() or ttm_global_swapout() then touches freed memory (list_add corruption on the following bind).
Failure points are any error return in amdgpu_ttm_init() after ttm_device_init(), and gmc_v*_sw_init() failing after amdgpu_bo_init(). In the latter case GMC's status.sw stays false, so amdgpu_device_ip_fini() skips its sw_fini, which is the only path to amdgpu_bo_fini() -> amdgpu_ttm_fini() -> ttm_device_fini(). The leaked MMIO_REMAP BO also shows up as "Memory manager not clean" on the next bind.
Patch 1 unwinds amdgpu_ttm_init() through amdgpu_ttm_fini() and makes that function safe on a partially initialized device. Patch 2 unwinds amdgpu_bo_init() in the GMC sw_init paths (v6-v12), including freeing the pinned GART table and pdb0 BOs first. Patch 3 releases the WC memtype and MTRR when amdgpu_bo_init() fails after reserving them.
---
Changes in v2:
- Patch 2: free the pinned GART table BO (and pdb0_bo on v9/v12) before amdgpu_bo_fini() on the error paths, as sw_fini does; use the RAM
variant on v9 without VRAM (reported by Sashiko)
- Link to v1: https://patch.msgid.link/[email protected]
To: Alex Deucher <[email protected]>
Cc: [email protected]
---
Mario Limonciello (3):
drm/amdgpu: unwind TTM on amdgpu_ttm_init() failure drm/amdgpu: unwind bo_init on GMC sw_init failure drm/amdgpu: release WC memtype and MTRR when amdgpu_bo_init() fails
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 20 +++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 43 ++++++++++++++++++------------ drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 11 ++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 11 ++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 12 +++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 7 ++++- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 15 ++++++++--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 15 ++++++++--- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 ++++++++++-- 9 files changed, 116 insertions(+), 35 deletions(-)
---
base-commit: bd703c23ae1dea86795e99d510fb9196566baa01
change-id: 20261118-superm1-amdgpu-memory-leak-f22abeab3189
Best regards,
Signature · 1 line
Mario Limonciello <[email protected]>
PATCH v2 1/3 drm/amdgpu: unwind TTM on amdgpu_ttm_init() failure
If amdgpu_ttm_init() fails after ttm_device_init() succeeded, the error paths just return. Nothing later calls ttm_device_fini() because the GMC IP block never reaches sw_fini, so the freed amdgpu_device stays linked on ttm_glob.device_list. The next ttm_device_init() or ttm_global_swapout() then walks freed memory. The MMIO_REMAP BO created in amdgpu_ttm_init() is also leaked, which shows up as "Memory manager not clean" on the following bind.
Route every error after ttm_device_init() through amdgpu_ttm_fini(), and mark the manager initialized as soon as ttm_device_init() succeeds so the unwind also covers a pool init failure. Make amdgpu_ttm_fini() skip the VRAM, GTT and PREEMPT managers when they were never registered, as it can now run on a partially initialized device.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 43 ++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +26 -17
@@ -2153,20 +2153,21 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) "failed initializing buffer object driver(%d).\n", r);return r; } +/* from here on amdgpu_ttm_fini() is responsible for unwinding */ + adev->mman.initialized = true; r =amdgpu_ttm_pools_init (adev);if (r) {dev_err (adev->dev,"failed to init ttm pools(%d).\n" , r); -return r; + goto err_fini; } - adev->mman.initialized = true;if (!adev->gmc.is_app_apu) {/* Initialize VRAM pool with all of VRAM divided into pages */ r =amdgpu_vram_mgr_init (adev);if (r) {dev_err (adev->dev,"Failed initializing VRAM heap.\n" ); -return r; + goto err_fini; } }
@@ -2190,7 +2191,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) r =amdgpu_ttm_alloc_vram_resv_regions (adev);if (r) -return r; + goto err_fini;/* RAS loads and reserves bad pages */ amdgpu_ras_mgr_early_init_service (adev);
@@ -2239,7 +2240,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) r =amdgpu_gtt_mgr_init (adev, gtt_size);if (r) {dev_err (adev->dev,"Failed initializing GTT heap.\n" ); -return r; + goto err_fini; }dev_info (adev->dev," %uM of GTT memory ready.\n" , (unsigned int )(gtt_size / (1024 *1024 )));
@@ -2253,52 +2254,52 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) r =amdgpu_ttm_init_on_chip (adev,AMDGPU_PL_DOORBELL , adev->doorbell.size /PAGE_SIZE );if (r) {dev_err (adev->dev,"Failed initializing doorbell heap.\n" ); -return r; + goto err_fini; }/* Create a doorbell page for kernel usages */ r =amdgpu_doorbell_create_kernel_doorbells (adev);if (r) {dev_err (adev->dev,"Failed to initialize kernel doorbells.\n" ); -return r; + goto err_fini; }/* Initialize MMIO-remap pool (single page 4K) */ r =amdgpu_ttm_init_on_chip (adev,AMDGPU_PL_MMIO_REMAP ,1 );if (r) {dev_err (adev->dev,"Failed initializing MMIO-remap heap.\n" ); -return r; + goto err_fini; }/* Allocate the singleton MMIO_REMAP BO if supported */ r =amdgpu_ttm_alloc_mmio_remap_bo (adev);if (r) -return r; + goto err_fini;/* Initialize preemptible memory pool */ r =amdgpu_preempt_mgr_init (adev);if (r) {dev_err (adev->dev,"Failed initializing PREEMPT heap.\n" ); -return r; + goto err_fini; }/* Initialize various on-chip memory pools */ r =amdgpu_ttm_init_on_chip (adev,AMDGPU_PL_GDS , adev->gds.gds_size);if (r) {dev_err (adev->dev,"Failed initializing GDS heap.\n" ); -return r; + goto err_fini; } r =amdgpu_ttm_init_on_chip (adev,AMDGPU_PL_GWS , adev->gds.gws_size);if (r) {dev_err (adev->dev,"Failed initializing gws heap.\n" ); -return r; + goto err_fini; } r =amdgpu_ttm_init_on_chip (adev,AMDGPU_PL_OA , adev->gds.oa_size);if (r) {dev_err (adev->dev,"Failed initializing oa heap.\n" ); -return r; + goto err_fini; }if (adev->ualink.npa_size) {
@@ -2306,7 +2307,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) adev->ualink.npa_size);if (r) {dev_err (adev->dev,"Failed initializing NPA heap.\n" ); -return r; + goto err_fini; } }
@@ -2318,6 +2319,10 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) "Debug VRAM access will use slowpath MM access\n");return 0 ; + +err_fini: +amdgpu_ttm_fini (adev); +return r; }/*
@@ -2352,10 +2357,14 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev) adev->mman.aper_base_kaddr =NULL ; } -if (!adev->gmc.is_app_apu) +/* may be called on a partially initialized TTM, skip unregistered managers */ +if (!adev->gmc.is_app_apu && +ttm_manager_type (&adev->mman.bdev,TTM_PL_VRAM ))amdgpu_vram_mgr_fini (adev); -amdgpu_gtt_mgr_fini (adev); -amdgpu_preempt_mgr_fini (adev); +if (ttm_manager_type (&adev->mman.bdev,TTM_PL_TT )) +amdgpu_gtt_mgr_fini (adev); +if (ttm_manager_type (&adev->mman.bdev,AMDGPU_PL_PREEMPT )) +amdgpu_preempt_mgr_fini (adev);amdgpu_doorbell_fini (adev);ttm_range_man_fini (&adev->mman.bdev,AMDGPU_PL_GDS );
Signature · 1 line
2.43.0
PATCH v2 2/3 drm/amdgpu: unwind bo_init on GMC sw_init failure
In reply to Mario LimoncielloWhen gmc_v*_sw_init() fails after amdgpu_bo_init(), the GMC block's status.sw stays false, so amdgpu_device_ip_fini() skips its sw_fini and amdgpu_bo_fini() (and thus ttm_device_fini()) is never called. The freed device is left on ttm_glob.device_list.
Unwind on the failure paths after amdgpu_bo_init(): GART init failures call amdgpu_bo_fini(); later failures (RAS sw init on v9-v12, vm_fault_info allocation on v7/v8) also call amdgpu_vm_manager_fini().
The GART table BO (and pdb0_bo on v9/v12) is pinned in VRAM by gmc_v*_gart_init(), and pinned BOs can't be evicted during TTM teardown. Free them before amdgpu_bo_fini(), as gmc_v*_sw_fini() does, otherwise ttm_device_fini() warns and leaks the BOs and their backing allocations. On v9 the GART table lives in system memory when there is no VRAM, so use the matching RAM free helper there, guarded against gart_init() failing before the BO was created.
--- drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 11 +++++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 11 +++++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 12 ++++++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 7 ++++++- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 15 ++++++++++++--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 15 ++++++++++++--- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 +++++++++++++++-- 7 files changed, 73 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +9 -2
@@ -861,7 +861,7 @@ static int gmc_v10_0_sw_init(struct amdgpu_ip_block *ip_block) r =gmc_v10_0_gart_init (adev);if (r) -return r; + goto err_bo_fini;/* * number of VMs
@@ -880,9 +880,16 @@ static int gmc_v10_0_sw_init(struct amdgpu_ip_block *ip_block) r =amdgpu_gmc_ras_sw_init (adev);if (r) -return r; + goto err_vm_fini;return 0 ; + +err_vm_fini: +amdgpu_vm_manager_fini (adev); +err_bo_fini: +amdgpu_gart_table_vram_free (adev); +amdgpu_bo_fini (adev); +return r; }/**
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +9 -2
@@ -859,7 +859,7 @@ static int gmc_v11_0_sw_init(struct amdgpu_ip_block *ip_block) r =gmc_v11_0_gart_init (adev);if (r) -return r; + goto err_bo_fini;/* * number of VMs
@@ -879,9 +879,16 @@ static int gmc_v11_0_sw_init(struct amdgpu_ip_block *ip_block) r =amdgpu_gmc_ras_sw_init (adev);if (r) -return r; + goto err_vm_fini;return 0 ; + +err_vm_fini: +amdgpu_vm_manager_fini (adev); +err_bo_fini: +amdgpu_gart_table_vram_free (adev); +amdgpu_bo_fini (adev); +return r; }/**
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +10 -2
@@ -987,7 +987,7 @@ static int gmc_v12_0_sw_init(struct amdgpu_ip_block *ip_block) r =gmc_v12_0_gart_init (adev);if (r) -return r; + goto err_bo_fini;if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (12 ,1 ,0 ))gmc_v12_1_init_nps_details (adev);
@@ -1021,12 +1021,20 @@ static int gmc_v12_0_sw_init(struct amdgpu_ip_block *ip_block) r =amdgpu_gmc_ras_sw_init (adev);if (r) -return r; + goto err_vm_fini;if (amdgpu_ip_version (adev,GC_HWIP ,0 ) ==IP_VERSION (12 ,1 ,0 ))amdgpu_gmc_sysfs_init (adev);return 0 ; + +err_vm_fini: +amdgpu_vm_manager_fini (adev); +err_bo_fini: +amdgpu_gart_table_vram_free (adev); +amdgpu_bo_free_kernel (&adev->gmc.pdb0_bo,NULL , &adev->gmc.ptr_pdb0); +amdgpu_bo_fini (adev); +return r; }/**
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +6 -1
@@ -817,7 +817,7 @@ static int gmc_v6_0_sw_init(struct amdgpu_ip_block *ip_block) r =gmc_v6_0_gart_init (adev);if (r) -return r; + goto err_bo_fini;/* * number of VMs
@@ -840,6 +840,11 @@ static int gmc_v6_0_sw_init(struct amdgpu_ip_block *ip_block) }return 0 ; + +err_bo_fini: +amdgpu_gart_table_vram_free (adev); +amdgpu_bo_fini (adev); +return r; }static int gmc_v6_0_sw_fini (struct amdgpu_ip_block *ip_block)
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +12 -3
@@ -999,7 +999,7 @@ static int gmc_v7_0_sw_init(struct amdgpu_ip_block *ip_block) r =gmc_v7_0_gart_init (adev);if (r) -return r; + goto err_bo_fini;/* * number of VMs
@@ -1026,11 +1026,20 @@ static int gmc_v7_0_sw_init(struct amdgpu_ip_block *ip_block) } adev->gmc.vm_fault_info = kmalloc_obj(struct kfd_vm_fault_info); -if (!adev->gmc.vm_fault_info) -return -ENOMEM ; +if (!adev->gmc.vm_fault_info) { + r = -ENOMEM ; + goto err_vm_fini; + }atomic_set_release (&adev->gmc.vm_fault_info_updated,0 );return 0 ; + +err_vm_fini: +amdgpu_vm_manager_fini (adev); +err_bo_fini: +amdgpu_gart_table_vram_free (adev); +amdgpu_bo_fini (adev); +return r; }static int gmc_v7_0_sw_fini (struct amdgpu_ip_block *ip_block)
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +12 -3
@@ -1114,7 +1114,7 @@ static int gmc_v8_0_sw_init(struct amdgpu_ip_block *ip_block) r =gmc_v8_0_gart_init (adev);if (r) -return r; + goto err_bo_fini;/* * number of VMs
@@ -1141,11 +1141,20 @@ static int gmc_v8_0_sw_init(struct amdgpu_ip_block *ip_block) } adev->gmc.vm_fault_info = kmalloc_obj(struct kfd_vm_fault_info); -if (!adev->gmc.vm_fault_info) -return -ENOMEM ; +if (!adev->gmc.vm_fault_info) { + r = -ENOMEM ; + goto err_vm_fini; + }atomic_set_release (&adev->gmc.vm_fault_info_updated,0 );return 0 ; + +err_vm_fini: +amdgpu_vm_manager_fini (adev); +err_bo_fini: +amdgpu_gart_table_vram_free (adev); +amdgpu_bo_fini (adev); +return r; }static int gmc_v8_0_sw_fini (struct amdgpu_ip_block *ip_block)
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +15 -2
@@ -2026,7 +2026,7 @@ static int gmc_v9_0_sw_init(struct amdgpu_ip_block *ip_block) r =gmc_v9_0_gart_init (adev);if (r) -return r; + goto err_bo_fini;gmc_v9_0_init_nps_details (adev);/*
@@ -2066,12 +2066,25 @@ static int gmc_v9_0_sw_init(struct amdgpu_ip_block *ip_block) r =amdgpu_gmc_ras_sw_init (adev);if (r) -return r; + goto err_vm_fini;if (amdgpu_is_multi_aid (adev))amdgpu_gmc_sysfs_init (adev);return 0 ; + +err_vm_fini: +amdgpu_vm_manager_fini (adev); +err_bo_fini: +if (!adev->gmc.real_vram_size) { +/* GART bo may not exist if gart_init failed early */ +if (adev->gart.bo) +amdgpu_gart_table_ram_free (adev); + }else +amdgpu_gart_table_vram_free (adev); +amdgpu_bo_free_kernel (&adev->gmc.pdb0_bo,NULL , &adev->gmc.ptr_pdb0); +amdgpu_bo_fini (adev); +return r; }static int gmc_v9_0_sw_fini (struct amdgpu_ip_block *ip_block)
Signature · 1 line
2.43.0
PATCH v2 3/3 drm/amdgpu: release WC memtype and MTRR when amdgpu_bo_init() fails
In reply to Mario Limoncielloamdgpu_bo_init() reserves the WC memtype for the VRAM aperture and adds an MTRR before calling amdgpu_ttm_init(). If amdgpu_ttm_init() fails, the GMC sw_init callers just return the error and GMC's sw_fini is never run, so amdgpu_bo_fini(), the only place that drops the memtype and MTRR, is never called. A later rebind then reserves the same aperture again with the old reservation still held.
Undo the memtype reservation and the MTRR in amdgpu_bo_init() itself when amdgpu_ttm_init() fails.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +17 -3
@@ -1130,11 +1130,13 @@ static const char * const amdgpu_vram_names[] = {*/ int amdgpu_bo_init (struct amdgpu_device *adev) { +int r; +/* On A+A platform, VRAM can be mapped as WB */ if (!adev->gmc.xgmi.connected_to_cpu && !adev->gmc.is_app_apu) {/* reserve PAT memory space to WC for VRAM */ -int r =arch_io_reserve_memtype_wc (adev->gmc.aper_base, - adev->gmc.aper_size); + r =arch_io_reserve_memtype_wc (adev->gmc.aper_base, + adev->gmc.aper_size);if (r) {DRM_ERROR ("Unable to set WC memtype for the aperture base\n" );
@@ -1151,7 +1153,19 @@ int amdgpu_bo_init(struct amdgpu_device *adev) (unsigned long long)adev->gmc.aper_size >> 20);drm_info (adev_to_drm (adev),"RAM width %dbits %s\n" , adev->gmc.vram_width, amdgpu_vram_names[adev->gmc.vram_type]); -return amdgpu_ttm_init (adev); + + r =amdgpu_ttm_init (adev); +if (r) { +/* the caller does not call amdgpu_bo_fini() when we fail */ +if (!adev->gmc.xgmi.connected_to_cpu && !adev->gmc.is_app_apu) { +arch_phys_wc_del (adev->gmc.vram_mtrr); +arch_io_free_memtype_wc (adev->gmc.aper_base, + adev->gmc.aper_size); + } +return r; + } + +return 0 ; }/**
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 3/3] drm/amdgpu: release WC memtype and MTRR when amdgpu_bo_init() fails
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/amdgpu: missing Fixes trailer for amdgpu_bo_init() leak fix --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/amdgpu: missing Fixes trailer for amdgpu_bo_init() leak fix --
commit b39bca7df25d1f904ab6219bf84105076d42ff05
Author: Mario Limonciello <[email protected]>
Quoted 9 lines
drm/amdgpu: release WC memtype and MTRR when
amdgpu_bo_init()fails
amdgpu_bo_init()reserves the WC memtype for the VRAM aperture and adds an MTRR before callingamdgpu_ttm_init(). Ifamdgpu_ttm_init()fails, the GMCsw_initcallers just return the error and GMC'ssw_finiis never run, soamdgpu_bo_fini(), the only place that drops the memtype and MTRR, is never called. A later rebind then reserves the same aperture again with the old reservation still held.
Quoted 4 lines
Undo the memtype reservation and the MTRR in
amdgpu_bo_init()itself whenamdgpu_ttm_init()fails.Signed-off-by Mario Limonciello <[email protected]>
[Severity: Low]
Should this bug fix include Fixes tags for the commits that introduced the MTRR and WC memtype reservations in amdgpu_bo_init() without unwinding them on failure?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Quoted 46 lines · Mario Limonciello
When amdgpu probe fails after
ttm_device_init()has succeeded, the freedamdgpu_devicestays linked on ttm_glob.device_list. The nextttm_device_init()orttm_global_swapout()then touches freed memory (list_addcorruption on the following bind).Failure points are any error return in
amdgpu_ttm_init()afterttm_device_init(), and gmc_v*_sw_init() failing afteramdgpu_bo_init(). In the latter case GMC's status.sw stays false, soamdgpu_device_ip_fini()skips itssw_fini, which is the only path toamdgpu_bo_fini()->amdgpu_ttm_fini()->ttm_device_fini(). The leakedMMIO_REMAPBO also shows up as "Memory manager not clean" on the next bind.Patch 1 unwinds
amdgpu_ttm_init()throughamdgpu_ttm_fini()and makes that function safe on a partially initialized device. Patch 2 unwindsamdgpu_bo_init()in the GMCsw_initpaths (v6-v12), including freeing the pinned GART table and pdb0 BOs first. Patch 3 releases the WC memtype and MTRR whenamdgpu_bo_init()fails after reserving them.Signed-off-by Mario Limonciello <[email protected]>---
Changes in v2:
- Patch 2: free the pinned GART table BO (andpdb0_boon v9/v12) beforeamdgpu_bo_fini()on the error paths, assw_finidoes; use the RAM
variant on v9 without VRAM (reported by Sashiko)
- Link to v1: https://patch.msgid.link/[email protected]To: Alex Deucher <[email protected]>
Cc: [email protected]---
Mario Limonciello (3):
drm/amdgpu: unwind TTM onamdgpu_ttm_init()failure drm/amdgpu: unwindbo_initon GMCsw_initfailure drm/amdgpu: release WC memtype and MTRR whenamdgpu_bo_init()failsdrivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 20 +++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 43 ++++++++++++++++++------------ drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 11 ++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 11 ++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 12 +++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 7 ++++- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 15 ++++++++--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 15 ++++++++--- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 ++++++++++-- 9 files changed, 116 insertions(+), 35 deletions(-)
Quoted 7 lines
---
base-commit:bd703c23ae1dea86795e99d510fb9196566baa01
change-id: 20261118-superm1-amdgpu-memory-leak-f22abeab3189Best regards,
--
Mario Limonciello <[email protected]>
Ping?
Quoted 13 lines · Mario Limonciello
When amdgpu probe fails after
ttm_device_init()has succeeded, the freedamdgpu_devicestays linked on ttm_glob.device_list. The nextttm_device_init()orttm_global_swapout()then touches freed memory (list_addcorruption on the following bind).Failure points are any error return in
amdgpu_ttm_init()afterttm_device_init(), and gmc_v*_sw_init() failing afteramdgpu_bo_init(). In the latter case GMC's status.sw stays false, soamdgpu_device_ip_fini()skips itssw_fini, which is the only path toamdgpu_bo_fini()->amdgpu_ttm_fini()->ttm_device_fini(). The leakedMMIO_REMAPBO also shows up as "Memory manager not clean" on the next bind.
Quoted 8 lines
Patch 1 unwinds
amdgpu_ttm_init()throughamdgpu_ttm_fini()and makes that function safe on a partially initialized device. Patch 2 unwindsamdgpu_bo_init()in the GMCsw_initpaths (v6-v12), including freeing the pinned GART table and pdb0 BOs first. Patch 3 releases the WC memtype and MTRR whenamdgpu_bo_init()fails after reserving them.Signed-off-by Mario Limonciello <[email protected]>
Series is:
Quoted 34 lines
---
Changes in v2:
- Patch 2: free the pinned GART table BO (andpdb0_boon v9/v12) beforeamdgpu_bo_fini()on the error paths, assw_finidoes; use the RAM
variant on v9 without VRAM (reported by Sashiko)
- Link to v1: https://patch.msgid.link/[email protected]To: Alex Deucher <[email protected]>
Cc: [email protected]---
Mario Limonciello (3):
drm/amdgpu: unwind TTM onamdgpu_ttm_init()failure drm/amdgpu: unwindbo_initon GMCsw_initfailure drm/amdgpu: release WC memtype and MTRR whenamdgpu_bo_init()failsdrivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 20 +++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 43 ++++++++++++++++++------------ drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 11 ++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 11 ++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 12 +++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 7 ++++- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 15 ++++++++--- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 15 ++++++++--- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 17 ++++++++++-- 9 files changed, 116 insertions(+), 35 deletions(-)---
base-commit:bd703c23ae1dea86795e99d510fb9196566baa01
change-id: 20261118-superm1-amdgpu-memory-leak-f22abeab3189Best regards,
--
Mario Limonciello <[email protected]>