From: "Adrián Larumbe" <adrian.larumbe@collabora.com>
To: Boris Brezillon <boris.brezillon@collabora.com>,
Rob Herring <robh@kernel.org>,
Steven Price <steven.price@arm.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Philipp Zabel <p.zabel@pengutronix.de>
Cc: kernel@collabora.com,
"Adrián Larumbe" <adrian.larumbe@collabora.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [PATCH 5/9] drm/panfrost: Handle page mapping failure
Date: Tue, 15 Oct 2024 00:31:40 +0100 [thread overview]
Message-ID: <20241014233758.994861-5-adrian.larumbe@collabora.com> (raw)
In-Reply-To: <20241014233758.994861-1-adrian.larumbe@collabora.com>
Right now Panfrost's GPU page fault IRQ assumes the architectural page
mapping function always suceeds. That might not always be the case, so we
haravest its return status and unmap whatever we had mapped so far.
Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
---
drivers/gpu/drm/panfrost/panfrost_mmu.c | 66 +++++++++++++++++--------
1 file changed, 46 insertions(+), 20 deletions(-)
diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c
index 8514a02d306d..03fbb12804ab 100644
--- a/drivers/gpu/drm/panfrost/panfrost_mmu.c
+++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c
@@ -291,13 +291,34 @@ static void panfrost_mmu_flush_range(struct panfrost_device *pfdev,
pm_runtime_put_autosuspend(pfdev->base.dev);
}
+static void mmu_unmap_range(size_t len, u64 iova, bool is_heap,
+ struct io_pgtable_ops *ops)
+{
+ size_t unmapped_len = 0;
+
+ while (unmapped_len < len) {
+ size_t unmapped_page, pgcount;
+ size_t pgsize = get_pgsize(iova, len - unmapped_len, &pgcount);
+
+ if (is_heap)
+ pgcount = 1;
+ if (!is_heap || ops->iova_to_phys(ops, iova)) {
+ unmapped_page = ops->unmap_pages(ops, iova, pgsize, pgcount, NULL);
+ WARN_ON(unmapped_page != pgsize * pgcount);
+ }
+ iova += pgsize * pgcount;
+ unmapped_len += pgsize * pgcount;
+ }
+}
+
static int mmu_map_sg(struct panfrost_device *pfdev, struct panfrost_mmu *mmu,
- u64 iova, int prot, struct sg_table *sgt)
+ u64 iova, int prot, struct sg_table *sgt, bool is_heap)
{
unsigned int count;
struct scatterlist *sgl;
struct io_pgtable_ops *ops = mmu->pgtbl_ops;
u64 start_iova = iova;
+ int ret;
for_each_sgtable_dma_sg(sgt, sgl, count) {
unsigned long paddr = sg_dma_address(sgl);
@@ -311,8 +332,13 @@ static int mmu_map_sg(struct panfrost_device *pfdev, struct panfrost_mmu *mmu,
size_t pgcount, mapped = 0;
size_t pgsize = get_pgsize(iova | paddr, len, &pgcount);
- ops->map_pages(ops, iova, paddr, pgsize, pgcount, prot,
+ ret = ops->map_pages(ops, iova, paddr, pgsize, pgcount, prot,
GFP_KERNEL, &mapped);
+ if (ret) {
+ /* Unmap everything we mapped and bail out */
+ mmu_unmap_range(mapped, start_iova, is_heap, ops);
+ return ret;
+ }
/* Don't get stuck if things have gone wrong */
mapped = max(mapped, pgsize);
iova += mapped;
@@ -334,6 +360,7 @@ int panfrost_mmu_map(struct panfrost_gem_mapping *mapping)
struct panfrost_device *pfdev = to_panfrost_device(obj->dev);
struct sg_table *sgt;
int prot = IOMMU_READ | IOMMU_WRITE;
+ int ret;
if (WARN_ON(mapping->active))
return 0;
@@ -345,8 +372,13 @@ int panfrost_mmu_map(struct panfrost_gem_mapping *mapping)
if (WARN_ON(IS_ERR(sgt)))
return PTR_ERR(sgt);
- mmu_map_sg(pfdev, mapping->mmu, mapping->mmnode.start << PAGE_SHIFT,
- prot, sgt);
+ ret = mmu_map_sg(pfdev, mapping->mmu, mapping->mmnode.start << PAGE_SHIFT,
+ prot, sgt, false);
+ if (ret) {
+ drm_gem_shmem_put_pages(shmem);
+ return ret;
+ }
+
mapping->active = true;
return 0;
@@ -360,7 +392,7 @@ void panfrost_mmu_unmap(struct panfrost_gem_mapping *mapping)
struct io_pgtable_ops *ops = mapping->mmu->pgtbl_ops;
u64 iova = mapping->mmnode.start << PAGE_SHIFT;
size_t len = mapping->mmnode.size << PAGE_SHIFT;
- size_t unmapped_len = 0;
+
if (WARN_ON(!mapping->active))
return;
@@ -368,19 +400,7 @@ void panfrost_mmu_unmap(struct panfrost_gem_mapping *mapping)
dev_dbg(pfdev->base.dev, "unmap: as=%d, iova=%llx, len=%zx",
mapping->mmu->as, iova, len);
- while (unmapped_len < len) {
- size_t unmapped_page, pgcount;
- size_t pgsize = get_pgsize(iova, len - unmapped_len, &pgcount);
-
- if (bo->is_heap)
- pgcount = 1;
- if (!bo->is_heap || ops->iova_to_phys(ops, iova)) {
- unmapped_page = ops->unmap_pages(ops, iova, pgsize, pgcount, NULL);
- WARN_ON(unmapped_page != pgsize * pgcount);
- }
- iova += pgsize * pgcount;
- unmapped_len += pgsize * pgcount;
- }
+ mmu_unmap_range(len, iova, bo->is_heap, ops);
panfrost_mmu_flush_range(pfdev, mapping->mmu,
mapping->mmnode.start << PAGE_SHIFT, len);
@@ -533,8 +553,11 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
if (ret)
goto err_map;
- mmu_map_sg(pfdev, bomapping->mmu, addr,
- IOMMU_WRITE | IOMMU_READ | IOMMU_NOEXEC, sgt);
+ ret = mmu_map_sg(pfdev, bomapping->mmu, addr,
+ IOMMU_WRITE | IOMMU_READ | IOMMU_NOEXEC,
+ sgt, true);
+ if (ret)
+ goto err_mmu_map_sg;
bomapping->active = true;
bo->heap_rss_size += SZ_2M;
@@ -548,6 +571,9 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
return 0;
+err_mmu_map_sg:
+ dma_unmap_sgtable(pfdev->base.dev, sgt,
+ DMA_BIDIRECTIONAL, 0);
err_map:
sg_free_table(sgt);
err_unlock:
--
2.46.2
next prev parent reply other threads:[~2024-10-14 23:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-14 23:31 [PATCH 1/9] drm/panfrost: Replace DRM driver allocation method with newer one Adrián Larumbe
2024-10-14 23:31 ` [PATCH 2/9] drm/panfrost: handle inexistent GPU during probe Adrián Larumbe
2024-10-21 14:06 ` Boris Brezillon
2024-10-24 14:55 ` Steven Price
2024-10-14 23:31 ` [PATCH 3/9] drm/panfrost: handle error when allocating AS number Adrián Larumbe
2024-10-21 14:07 ` Boris Brezillon
2024-10-14 23:31 ` [PATCH 4/9] drm/panfrost: handle job hw submit errors Adrián Larumbe
2024-10-21 14:14 ` Boris Brezillon
2024-10-14 23:31 ` Adrián Larumbe [this message]
2024-10-21 14:32 ` [PATCH 5/9] drm/panfrost: Handle page mapping failure Boris Brezillon
2024-10-14 23:31 ` [PATCH 6/9] drm/panfrost: Avoid re-enabling job interrupts in the reset path Adrián Larumbe
2024-10-21 14:52 ` Boris Brezillon
2024-10-14 23:31 ` [PATCH 7/9] drm/panfrost: Refactor job IRQ enabling sequence Adrián Larumbe
2024-10-14 23:31 ` [PATCH 8/9] drm/panfrost: Add forward declaration and types header Adrián Larumbe
2024-10-14 23:31 ` [PATCH 9/9] drm/panfrost: Explicitly clean up panfrost fence Adrián Larumbe
2024-10-16 13:12 ` Christian König
2024-10-16 16:43 ` Adrián Larumbe
2024-10-17 9:27 ` Christian König
2024-10-17 12:44 ` [PATCH 1/9] drm/panfrost: Replace DRM driver allocation method with newer one Boris Brezillon
2024-10-24 14:55 ` Steven Price
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=20241014233758.994861-5-adrian.larumbe@collabora.com \
--to=adrian.larumbe@collabora.com \
--cc=airlied@gmail.com \
--cc=boris.brezillon@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--cc=simona@ffwll.ch \
--cc=steven.price@arm.com \
--cc=tzimmermann@suse.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®