From: Boris Brezillon <boris.brezillon@collabora.com>
To: Steven Price <steven.price@arm.com>
Cc: "Adrián Larumbe" <adrian.larumbe@collabora.com>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
kernel@collabora.com, "Liviu Dudau" <liviu.dudau@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>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Alice Ryhl" <aliceryhl@google.com>
Subject: Re: [PATCH v9 5/6] drm/panthor: Support sparse mappings
Date: Fri, 24 Apr 2026 12:31:03 +0200 [thread overview]
Message-ID: <20260424123103.28f6ada7@fedora> (raw)
In-Reply-To: <f0ec1b96-a6ff-49c6-b57d-740f97ac867f@arm.com>
On Fri, 24 Apr 2026 11:09:27 +0100
Steven Price <steven.price@arm.com> wrote:
> Hi Adrián,
>
> On 22/04/2026 13:25, Adrián Larumbe wrote:
> > Allow UM to bind sparsely populated memory regions by cyclically mapping
> > virtual ranges over a kernel-allocated dummy BO. This alternative is
> > preferable to the old method of handling sparseness in the UMD, because it
> > relied on the creation of a buffer object to the same end, despite the fact
> > Vulkan sparse resources don't need to be backed by a driver BO.
> >
> > The choice of backing sparsely-bound regions with a Panhtor BO was made so
> > as to profit from the existing shrinker reclaim code. That way no special
> > treatment must be given to the dummy sparse BOs when reclaiming memory, as
> > would be the case if we had chosen a raw kernel page implementation.
> >
> > A new dummy BO is allocated per open file context, because even though the
> > Vulkan spec mandates that writes into sparsely bound regions must be
> > discarded, our implementation is still a workaround over the fact Mali CSF
> > GPUs cannot support this behaviour on the hardware level, so writes still
> > make it into the backing BO. If we had a global one, then it could be a
> > venue for information leaks between file contexts, which should never
> > happen in DRM.
> >
> > Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
> > Signed-off-by: Adrián Larumbe <adrian.larumbe@collabora.com>
>
> Looks good, a few issues below.
>
> I'm worried about remap_evicted_vma() and how that interacts with sparse
> mappings. Does that need to be fixed up to handle sparse mappings? Or is
> there something to prevent the dummy BO being reclaimed? I might be
> missing something here.
Given the sparse mappings still have a vm_bo+gem object attached to them,
I think reclaim is fine, but I'll double check.
> > +static int
> > +panthor_vm_map_sparse(struct panthor_vm *vm, u64 iova, int prot,
> > + struct sg_table *sgt, u64 size)
> > +{
> > + u64 start_iova = iova;
> > + int ret;
> > +
> > + if (iova & (SZ_2M - 1)) {
> > + u64 unaligned_size = min(ALIGN(iova, SZ_2M) - iova, size);
> > +
> > + ret = panthor_vm_map_pages(vm, iova, prot, sgt,
> > + 0, unaligned_size);
> > + if (ret)
> > + return ret;
> > +
> > + size -= unaligned_size;
> > + iova += unaligned_size;
> > + }
> > +
> > + /* TODO: we should probably optimize this at the io_pgtable level. */
> > + while (size > 0) {
> > + u64 next_size = min(size, sg_dma_len(sgt->sgl));
>
> Here we're only using the first entry of the scatter list. So I think in
> the fragmented case we don't end up using the full 2MB.
It should just be
u32 chunk_size = min(size, SZ_2M);
really. The fact the BO is backed by physically contiguous memory
doesn't matter because panthor_vm_map_pages() can cope with that
already.
>
> > +
> > + ret = panthor_vm_map_pages(vm, iova, prot,
> > + sgt, 0, next_size);
> > + if (ret)
> > + goto err_unmap;
> > +
> > + size -= next_size;
> > + iova += next_size;
> > + }
To sum up, the whole thing can be simplified to something like:
static int
panthor_vm_map_sparse(struct panthor_vm *vm, u64 iova, int prot,
struct sg_table *sgt, u64 size)
u64 offset = 0;
while (offset < size) {
u32 chunk_size = min(size - offset, SZ_2M - (iova & (SZ_2M - 1)));
ret = panthor_vm_map_pages(vm, iova + offset, prot,
sgt, 0, chunk_size);
if (ret) {
panthor_vm_unmap_pages(vm, iova, offset);
return ret;
}
offset += chunk_size;
}
return 0;
}
next prev parent reply other threads:[~2026-04-24 10:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-22 12:25 [PATCH v9 0/6] Support sparse mappings in Panthor Adrián Larumbe
2026-04-22 12:25 ` [PATCH v9 1/6] drm/panthor: Expose GPU page sizes to UM Adrián Larumbe
2026-04-24 13:18 ` Steven Price
2026-04-27 14:29 ` Adrián Larumbe
2026-04-22 12:25 ` [PATCH v9 2/6] drm/panthor: Pass vm_bind_op to vm_prepare_map_op_ctx Adrián Larumbe
2026-04-22 12:25 ` [PATCH v9 3/6] drm/panthor: Delete spurious whitespace from uAPI header Adrián Larumbe
2026-04-22 12:25 ` [PATCH v9 4/6] drm/panthor: Remove unused operation context field Adrián Larumbe
2026-04-22 12:25 ` [PATCH v9 5/6] drm/panthor: Support sparse mappings Adrián Larumbe
2026-04-24 10:09 ` Steven Price
2026-04-24 10:31 ` Boris Brezillon [this message]
2026-04-24 12:06 ` Adrián Larumbe
2026-04-24 12:14 ` Boris Brezillon
2026-04-24 11:37 ` Adrián Larumbe
2026-04-22 12:25 ` [PATCH v9 6/6] drm/panthor: Bump the driver version to 1.9 Adrián Larumbe
2026-04-24 10:16 ` 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=20260424123103.28f6ada7@fedora \
--to=boris.brezillon@collabora.com \
--cc=adrian.larumbe@collabora.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel@collabora.com \
--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