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.

Signed-off-by: Mario Limonciello <[email protected]>
---
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,
--  
Mario Limonciello <[email protected]>

Reply via email to