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).
Patch 3 releases the WC memtype and MTRR when amdgpu_bo_init() fails
after reserving them.

Signed-off-by: Mario Limonciello <[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     | 10 +++++--
 drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c     | 10 +++++--
 drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c     | 10 +++++--
 drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c      |  6 ++++-
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c      | 14 +++++++---
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c      | 14 +++++++---
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c      | 10 +++++--
 9 files changed, 102 insertions(+), 35 deletions(-)
---
base-commit: 71830abced88ee7665010e79b51f0789b033cc3a
change-id: 20261113-superm1-amdgpu-memory-leak-a2a6b2a93efb

Best regards,
--  
Mario Limonciello <[email protected]>

Reply via email to