From: Boris Brezillon <boris.brezillon@collabora.com>
To: "Steven Price" <steven.price@arm.com>,
"Liviu Dudau" <liviu.dudau@arm.com>,
"Adrián Larumbe" <adrian.larumbe@collabora.com>,
"Akash Goel" <akash.goel@arm.com>
Cc: 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>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
Boris Brezillon <boris.brezillon@collabora.com>
Subject: [PATCH 1/4] drm/panthor: Avoid false positives in iova_mapped_as_huge_page()
Date: Thu, 17 Sep 2026 14:33:43 +0200 [thread overview]
Message-ID: <20260917-panthor-fix-partial-unmap-v1-1-c7008f15fea3@collabora.com> (raw)
In-Reply-To: <20260917-panthor-fix-partial-unmap-v1-0-c7008f15fea3@collabora.com>
The check on the folio size is actually moot if the BO offset matching
the VA we're checking huge-mapping for is not 2M aligned as well.
This means that we are sometimes returning true when we shouldn't, which
forces an extra unmap+map to deal with block-mapping splits. It's not
a functional bug per-se, because the unmap+map sequence will restore
things in the state we expect them to be, but it's better to properly
optimize those cases.
Note that we now align the VA on 2M address below it otherwise we can't
check the bo_offset alignment (both physical and virtual address need
to be aligned, in addition to the physically contiguous size being 2M,
which the folio size check ensures).
These changes force us to pass the drm_gpuva that's being unmapped
instead of the new mappings that will be created to cover the left/right
sections we remap. This changes makes the logic a lot easier to reason
about, because it doesn't make sense to how things were mapped by
passing the new mappings that are not yet in place.
Fixes: 8e7460eac786 ("drm/panthor: Support partial unmaps of huge pages")
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_mmu.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index 9f63a048df61..b0a7033480e6 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -2295,15 +2295,29 @@ static int panthor_gpuva_sm_step_map(struct drm_gpuva_op *op, void *priv)
}
static bool
-iova_mapped_as_huge_page(struct drm_gpuva_op_map *op, u64 addr)
+iova_mapped_as_huge_page(struct drm_gpuva *mapping, u64 va)
{
- struct panthor_gem_object *bo = to_panthor_bo(op->gem.obj);
+ struct panthor_gem_object *bo = to_panthor_bo(mapping->gem.obj);
+ u64 aligned_va = ALIGN_DOWN(va, SZ_2M);
const struct page *pg;
pgoff_t bo_offset;
- bo_offset = addr - op->va.addr + op->gem.offset;
+ /* If the 2M-aligned VA is outside the mapping being tested, we know
+ * it's not a huge map.
+ */
+ if (aligned_va < mapping->va.addr)
+ return false;
+
+ bo_offset = aligned_va - mapping->va.addr + mapping->gem.offset;
pg = bo->backing.pages[bo_offset >> PAGE_SHIFT];
+ /* In case of shmem backing, we know we can only have a huge mapping
+ * if the bo_offset is 2M aligned, meaning we can skip the folio size
+ * check if it's not the case.
+ */
+ if (!IS_ALIGNED(bo_offset, SZ_2M))
+ return false;
+
return folio_size(page_folio(pg)) >= SZ_2M;
}
@@ -2328,7 +2342,7 @@ unmap_hugepage_align(const struct drm_gpuva_op_remap *op,
*/
if (op->prev && aligned_unmap_start < *unmap_start &&
op->prev->va.addr <= aligned_unmap_start &&
- (is_sparse || iova_mapped_as_huge_page(op->prev, *unmap_start))) {
+ (is_sparse || iova_mapped_as_huge_page(op->unmap->va, *unmap_start))) {
*unmap_range += *unmap_start - aligned_unmap_start;
*unmap_start = aligned_unmap_start;
}
@@ -2338,7 +2352,7 @@ unmap_hugepage_align(const struct drm_gpuva_op_remap *op,
*/
if (op->next && aligned_unmap_end > unmap_end &&
op->next->va.addr + op->next->va.range >= aligned_unmap_end &&
- (is_sparse || iova_mapped_as_huge_page(op->next, unmap_end - 1))) {
+ (is_sparse || iova_mapped_as_huge_page(op->unmap->va, unmap_end - 1))) {
*unmap_range += aligned_unmap_end - unmap_end;
}
}
--
2.55.0
next prev parent reply other threads:[~2026-09-17 12:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 12:33 [PATCH 0/4] drm/panthor: Fix partial unmaps, again Boris Brezillon
2026-09-17 12:33 ` Boris Brezillon [this message]
2026-09-18 16:34 ` [PATCH 1/4] drm/panthor: Avoid false positives in iova_mapped_as_huge_page() Akash Goel
2026-09-17 12:33 ` [PATCH 2/4] drm/panthor: Fix iova_mapped_as_huge_page() for imported BOs Boris Brezillon
2026-09-18 16:35 ` Akash Goel
2026-09-17 12:33 ` [PATCH 3/4] drm/panthor: Consolidate the is-huge-page-mapping test Boris Brezillon
2026-09-18 16:39 ` Akash Goel
2026-09-17 12:33 ` [PATCH 4/4] drm/panthor: Actually check huge-page mapping on sparse regions Boris Brezillon
2026-09-18 16:48 ` Akash Goel
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=20260917-panthor-fix-partial-unmap-v1-1-c7008f15fea3@collabora.com \
--to=boris.brezillon@collabora.com \
--cc=adrian.larumbe@collabora.com \
--cc=airlied@gmail.com \
--cc=akash.goel@arm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liviu.dudau@arm.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@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®