Skip to contentSkip to conversation

Fix memory and firmware leaks

PATCH New Alex Deucher 1 participant 14 messages Jun 2, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Fix memory and firmware leaks

This patch set fixes several memory leaks and cases where we forgot to release the firmware.

Monk Liu (13):
drm/amdgpu: fix mem leak in smumgr
drm/amdgpu: fix mem leak in pplib/hwmgr
drm/amdgpu: fix mem leak in atombios
drm/amdgpu: fix memleak in pptable_init
drm/amdgpu: fix missing free wb for cond_exec
drm/amdgpu: fix gfx8 ucode mem leak
drm/amdgpu: fix gfx 7 ucode mem leak
drm/amdgpu: fix uvd fini mem leak
drm/amdgpu: fix sdma3 ucode mem leak
drm/amdgpu: fix sdma24 ucode mem leak
drm/amdgpu: fix cik sdma ucode memleak
drm/amdgpu: fix fiji smu fini mem leak
drm/amdgpu: fix tonga smu_fini mem leak

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c         |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c           |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c            | 19 ++++----
 drivers/gpu/drm/amd/amdgpu/cik_sdma.c              | 11 +++++
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c              | 17 +++++++
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c              | 22 ++++++++-
 drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c             | 10 ++++
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c             | 10 ++++
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c      |  8 +++-
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c        |  7 +++
 .../amd/powerplay/hwmgr/tonga_processpptables.c    | 54 ++++++++++------------
 drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c |  4 ++
 drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c      |  1 +
 .../gpu/drm/amd/powerplay/smumgr/tonga_smumgr.c    |  5 ++
 14 files changed, 132 insertions(+), 41 deletions(-)
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 1/13 drm/amdgpu: fix mem leak in smumgr

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/powerplay/smumgr/smumgr.c +1 -0
index c483baf..0728c1e3 100644
@@ -81,6 +81,7 @@ int smum_init(struct amd_pp_init *pp_init, struct pp_instance *handle)
 
 int smum_fini(struct pp_smumgr *smumgr)
 {
+	kfree(smumgr->device);
 	kfree(smumgr);
 	return 0;
 }
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH 2/13 drm/amdgpu: fix mem leak in pplib/hwmgr

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/powerplay/hwmgr/hwmgr.c +7 -0
index 1c48917..910d56d 100644
@@ -93,6 +93,13 @@ int hwmgr_fini(struct pp_hwmgr *hwmgr)
 	if (hwmgr == NULL || hwmgr->ps == NULL)
 		return -EINVAL;
 
+	/* do hwmgr finish*/
+	kfree(hwmgr->backend);
+
+	kfree(hwmgr->start_thermal_controller.function_list);
+
+	kfree(hwmgr->set_temperature_range.function_list);
+
 	kfree(hwmgr->ps);
 	kfree(hwmgr);
 	return 0;
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

PATCH 3/13 drm/amdgpu: fix mem leak in atombios

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -1
index 1727a4d..964f314 100644
@@ -827,8 +827,10 @@ static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg)
  */
 static void amdgpu_atombios_fini(struct amdgpu_device *adev)
 {
-	if (adev->mode_info.atom_context)
+	if (adev->mode_info.atom_context) {
 		kfree(adev->mode_info.atom_context->scratch);
+		kfree(adev->mode_info.atom_context->iio);
+	}
 	kfree(adev->mode_info.atom_context);
 	adev->mode_info.atom_context = NULL;
 	kfree(adev->mode_info.atom_card_info);
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

PATCH 4/13 drm/amdgpu: fix memleak in pptable_init

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c      |  8 +++-
 .../amd/powerplay/hwmgr/tonga_processpptables.c    | 54 ++++++++++------------
 2 files changed, 32 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/powerplay/amd_powerplay.c +7 -1
index 8e345bf..e629f8a 100644
@@ -73,11 +73,14 @@ static int pp_sw_init(void *handle)
 
 	ret = hwmgr->hwmgr_func->backend_init(hwmgr);
 	if (ret)
-		goto err;
+		goto err1;
 
 	pr_info("amdgpu: powerplay initialized\n");
 
 	return 0;
+err1:
+	if (hwmgr->pptable_func->pptable_fini)
+		hwmgr->pptable_func->pptable_fini(hwmgr);
 err:
 	pr_err("amdgpu: powerplay initialization failed\n");
 	return ret;
@@ -100,6 +103,9 @@ static int pp_sw_fini(void *handle)
 	if (hwmgr->hwmgr_func->backend_fini != NULL)
 		ret = hwmgr->hwmgr_func->backend_fini(hwmgr);
 
+	if (hwmgr->pptable_func->pptable_fini)
+		hwmgr->pptable_func->pptable_fini(hwmgr);
+
 	return ret;
 }
 
drivers/gpu/drm/amd/powerplay/hwmgr/tonga_processpptables.c +25 -29

73 lines not on this page · raw message

Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

PATCH 5/13 drm/amdgpu: fix missing free wb for cond_exec

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1 -0
index a4b3f44..dc8a7bb 100644
@@ -346,6 +346,7 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)
 	ring->ring = NULL;
 	ring->ring_obj = NULL;
 
+	amdgpu_wb_free(ring->adev, ring->cond_exe_offs);
 	amdgpu_wb_free(ring->adev, ring->fence_offs);
 	amdgpu_wb_free(ring->adev, ring->rptr_offs);
 	amdgpu_wb_free(ring->adev, ring->wptr_offs);
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

PATCH 6/13 drm/amdgpu: fix gfx8 ucode mem leak

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +21 -1
index 4d747ba..9f6f866 100644
@@ -836,6 +836,26 @@ err1:
 	return r;
 }
 
+
+static void gfx_v8_0_free_microcode(struct amdgpu_device *adev) {
+	release_firmware(adev->gfx.pfp_fw);
+	adev->gfx.pfp_fw = NULL;
+	release_firmware(adev->gfx.me_fw);
+	adev->gfx.me_fw = NULL;
+	release_firmware(adev->gfx.ce_fw);
+	adev->gfx.ce_fw = NULL;
+	release_firmware(adev->gfx.rlc_fw);
+	adev->gfx.rlc_fw = NULL;
+	release_firmware(adev->gfx.mec_fw);
+	adev->gfx.mec_fw = NULL;
+	if ((adev->asic_type != CHIP_STONEY) &&
+	    (adev->asic_type != CHIP_TOPAZ))
+		release_firmware(adev->gfx.mec2_fw);
+	adev->gfx.mec2_fw = NULL;
+
+	kfree(adev->gfx.rlc.register_list_format);
+}
+
 static int gfx_v8_0_init_microcode(struct amdgpu_device *adev)
 {
 	const char *chip_name;
@@ -1983,7 +2003,7 @@ static int gfx_v8_0_sw_fini(void *handle)
 
 	gfx_v8_0_rlc_fini(adev);
 
-	kfree(adev->gfx.rlc.register_list_format);
+	gfx_v8_0_free_microcode(adev);
 
 	return 0;
 }
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

PATCH 7/13 drm/amdgpu: fix gfx 7 ucode mem leak

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +17 -0
index 7f18a53..8c6ad1e 100644
@@ -991,6 +991,22 @@ out:
 	return err;
 }
 
+static void gfx_v7_0_free_microcode(struct amdgpu_device *adev)
+{
+	release_firmware(adev->gfx.pfp_fw);
+	adev->gfx.pfp_fw = NULL;
+	release_firmware(adev->gfx.me_fw);
+	adev->gfx.me_fw = NULL;
+	release_firmware(adev->gfx.ce_fw);
+	adev->gfx.ce_fw = NULL;
+	release_firmware(adev->gfx.mec_fw);
+	adev->gfx.mec_fw = NULL;
+	release_firmware(adev->gfx.mec2_fw);
+	adev->gfx.mec2_fw = NULL;
+	release_firmware(adev->gfx.rlc_fw);
+	adev->gfx.rlc_fw = NULL;
+}
+
 /**
  * gfx_v7_0_tiling_mode_table_init - init the hw tiling table
  *
@@ -4489,6 +4505,7 @@ static int gfx_v7_0_sw_fini(void *handle)
 	gfx_v7_0_cp_compute_fini(adev);
 	gfx_v7_0_rlc_fini(adev);
 	gfx_v7_0_mec_fini(adev);
+	gfx_v7_0_free_microcode(adev);
 
 	return 0;
 }
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw

PATCH 8/13 drm/amdgpu: fix uvd fini mem leak

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +10 -9
index 01abfc2..e19520c 100644
@@ -253,19 +253,20 @@ int amdgpu_uvd_sw_fini(struct amdgpu_device *adev)
 {
 	int r;
 
-	if (adev->uvd.vcpu_bo == NULL)
-		return 0;
+	kfree(adev->uvd.saved_bo);
 
 	amd_sched_entity_fini(&adev->uvd.ring.sched, &adev->uvd.entity);
 
-	r = amdgpu_bo_reserve(adev->uvd.vcpu_bo, false);
-	if (!r) {
-		amdgpu_bo_kunmap(adev->uvd.vcpu_bo);
-		amdgpu_bo_unpin(adev->uvd.vcpu_bo);
-		amdgpu_bo_unreserve(adev->uvd.vcpu_bo);
-	}
+	if (adev->uvd.vcpu_bo) {
+		r = amdgpu_bo_reserve(adev->uvd.vcpu_bo, false);
+		if (!r) {
+			amdgpu_bo_kunmap(adev->uvd.vcpu_bo);
+			amdgpu_bo_unpin(adev->uvd.vcpu_bo);
+			amdgpu_bo_unreserve(adev->uvd.vcpu_bo);
+		}
 
-	amdgpu_bo_unref(&adev->uvd.vcpu_bo);
+		amdgpu_bo_unref(&adev->uvd.vcpu_bo);
+	}
 
 	amdgpu_ring_fini(&adev->uvd.ring);
 
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw

PATCH 9/13 drm/amdgpu: fix sdma3 ucode mem leak

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +10 -0
index 33605d4..532ea88 100644
@@ -236,6 +236,15 @@ static void sdma_v3_0_init_golden_registers(struct amdgpu_device *adev)
 	}
 }
 
+static void sdma_v3_0_free_microcode(struct amdgpu_device *adev)
+{
+	int i;
+	for (i = 0; i < adev->sdma.num_instances; i++) {
+		release_firmware(adev->sdma.instance[i].fw);
+		adev->sdma.instance[i].fw = NULL;
+	}
+}
+
 /**
  * sdma_v3_0_init_microcode - load ucode images from disk
  *
@@ -1256,6 +1265,7 @@ static int sdma_v3_0_sw_fini(void *handle)
 	for (i = 0; i < adev->sdma.num_instances; i++)
 		amdgpu_ring_fini(&adev->sdma.instance[i].ring);
 
+	sdma_v3_0_free_microcode(adev);
 	return 0;
 }
 
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw

PATCH 10/13 drm/amdgpu: fix sdma24 ucode mem leak

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +10 -0
index f6014b0..b556bd0 100644
@@ -105,6 +105,15 @@ static void sdma_v2_4_init_golden_registers(struct amdgpu_device *adev)
 	}
 }
 
+static void sdma_v2_4_free_microcode(struct amdgpu_device *adev)
+{
+	int i;
+	for (i = 0; i < adev->sdma.num_instances; i++) {
+		release_firmware(adev->sdma.instance[i].fw);
+		adev->sdma.instance[i].fw = NULL;
+	}
+}
+
 /**
  * sdma_v2_4_init_microcode - load ucode images from disk
  *
@@ -1018,6 +1027,7 @@ static int sdma_v2_4_sw_fini(void *handle)
 	for (i = 0; i < adev->sdma.num_instances; i++)
 		amdgpu_ring_fini(&adev->sdma.instance[i].ring);
 
+	sdma_v2_4_free_microcode(adev);
 	return 0;
 }
 
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#11 lore raw

PATCH 11/13 drm/amdgpu: fix cik sdma ucode memleak

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +11 -0
index 0079916..9dc4e24 100644
@@ -66,6 +66,16 @@ MODULE_FIRMWARE("radeon/mullins_sdma1.bin");
 
 u32 amdgpu_cik_gpu_check_soft_reset(struct amdgpu_device *adev);
 
+
+static void cik_sdma_free_microcode(struct amdgpu_device *adev)
+{
+	int i;
+	for (i = 0; i < adev->sdma.num_instances; i++) {
+			release_firmware(adev->sdma.instance[i].fw);
+			adev->sdma.instance[i].fw = NULL;
+	}
+}
+
 /*
  * sDMA - System DMA
  * Starting with CIK, the GPU has new asynchronous
@@ -1005,6 +1015,7 @@ static int cik_sdma_sw_fini(void *handle)
 	for (i = 0; i < adev->sdma.num_instances; i++)
 		amdgpu_ring_fini(&adev->sdma.instance[i].ring);
 
+	cik_sdma_free_microcode(adev);
 	return 0;
 }
 
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#12 lore raw

PATCH 12/13 drm/amdgpu: fix fiji smu fini mem leak

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c +4 -0
index 673a75c..0ac8642 100644
@@ -1006,6 +1006,10 @@ static int fiji_smu_init(struct pp_smumgr *smumgr)
 
 static int fiji_smu_fini(struct pp_smumgr *smumgr)
 {
+	struct fiji_smumgr *priv = (struct fiji_smumgr *)(smumgr->backend);
+
+	smu_free_memory(smumgr->device, (void *)priv->header_buffer.handle);
+
 	if (smumgr->backend) {
 		kfree(smumgr->backend);
 		smumgr->backend = NULL;
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#13 lore raw

PATCH 13/13 drm/amdgpu: fix tonga smu_fini mem leak

In reply to Alex Deucher

From: Monk Liu <[email protected]>

---
 drivers/gpu/drm/amd/powerplay/smumgr/tonga_smumgr.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/powerplay/smumgr/tonga_smumgr.c +5 -0
index 32820b6..70d3ecf 100644
@@ -328,6 +328,11 @@ int tonga_write_smc_sram_dword(struct pp_smumgr *smumgr,
 
 static int tonga_smu_fini(struct pp_smumgr *smumgr)
 {
+	struct tonga_smumgr *priv = (struct tonga_smumgr *)(smumgr->backend);
+
+	smu_free_memory(smumgr->device, (void *)priv->smu_buffer.handle);
+	smu_free_memory(smumgr->device, (void *)priv->header_buffer.handle);
+
 	if (smumgr->backend != NULL) {
 		kfree(smumgr->backend);
 		smumgr->backend = NULL;
Signature · 6 lines
2.5.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel