From: Michail Tatas <michail.tatas@gmail.com>
To: alexander.deucher@amd.com, christian.koenig@amd.com,
airlied@gmail.com, simona@ffwll.ch
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2] drm/amdgpu: unmap GART dma pages before free
Date: Thu, 24 Sep 2026 18:36:05 +0300 [thread overview]
Message-ID: <arVDZbkfZbzfvKO4@michalis-linux> (raw)
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.
Signed-off-by: Michail Tatas <michail.tatas@gmail.com>
---
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(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
index c4c21dbbbdbf..116c646b86a8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
@@ -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);
--
2.43.0
reply other threads:[~2026-09-25 7:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=arVDZbkfZbzfvKO4@michalis-linux \
--to=michail.tatas@gmail.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.