Skip to contentSkip to conversation

drm/amdgpu: unmap GART dma pages before free

PATCH New Michail Tatas 1 participant 1 message Sep 24

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

PATCH v2 1/1 drm/amdgpu: unmap GART dma pages before free

amdgpu_gart_table_ram_alloc() maps the GART dma pages and neither the error path nor amdgpu_gart_table_ram_free() unmaps those pages before freeing them, which could leave the device writing to freed memory.

Fix by unmapping the GART dma pages before freeing them.

---

Changes in v2:
- Fixed a null dereference possibility based on review from sashiko

Revisions:
- v1: https://lore.kernel.org/all/arKhDFCSoPDNYaxX@michalis-linux/

 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +4 -0
index c4c21dbbbdbf..116c646b86a8 100644
@@ -209,6 +209,8 @@ int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev)
 error_resv:
 	amdgpu_bo_unreserve(bo);
 error:
+	dma_unmap_page(&adev->pdev->dev, dma_addr, adev->gart.table_size,
+		       DMA_BIDIRECTIONAL);
 	amdgpu_bo_unref(&bo);
 	if (sg) {
 		sg_free_table(sg);
@@ -240,6 +242,8 @@ void amdgpu_gart_table_ram_free(struct amdgpu_device *adev)
 		amdgpu_bo_unreserve(adev->gart.bo);
 	}
 	amdgpu_bo_unref(&adev->gart.bo);
+	dma_unmap_page(&adev->pdev->dev, sg_dma_address(sg->sgl), adev->gart.table_size,
+		       DMA_BIDIRECTIONAL);
 	sg_free_table(sg);
 	kfree(sg);
 	p = virt_to_page(adev->gart.ptr);
Signature · 1 line
2.43.0