From: Boris Brezillon <boris.brezillon@collabora.com>
To: "Adrián Larumbe" <adrian.larumbe@collabora.com>
Cc: Steven Price <steven.price@arm.com>,
Liviu Dudau <liviu.dudau@arm.com>,
dri-devel@lists.freedesktop.org, kernel@collabora.com
Subject: Re: [PATCH] drm/panthor: Fix firmware initialization on systems with a page size > 4k
Date: Mon, 14 Oct 2024 08:49:53 +0200 [thread overview]
Message-ID: <20241014084953.37a417fd@collabora.com> (raw)
In-Reply-To: <ynenorrf3kf3a5hmxfocjge3ytbydx42dmat53ywqaphjuc56k@lcgbdggi63ve>
On Fri, 11 Oct 2024 18:58:45 +0100
Adrián Larumbe <adrian.larumbe@collabora.com> wrote:
> Hi Boris,
>
> On 09.10.2024 09:10, Steven Price wrote:
> > On 08/10/2024 09:47, Boris Brezillon wrote:
> > > The system and GPU MMU page size might differ, which becomes a
> > > problem for FW sections that need to be mapped at explicit address
> > > since our PAGE_SIZE alignment might cover a VA range that's
> > > expected to be used for another section.
> > >
> > > Make sure we never map more than we need.
> > >
> > > Fixes: 2718d91816ee ("drm/panthor: Add the FW logical block")
> > > Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> >
> > Reviewed-by: Steven Price <steven.price@arm.com>
> >
> > > ---
> > > drivers/gpu/drm/panthor/panthor_fw.c | 3 +--
> > > drivers/gpu/drm/panthor/panthor_gem.c | 11 ++++++++---
> > > drivers/gpu/drm/panthor/panthor_mmu.c | 6 +++---
> > > 3 files changed, 12 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
> > > index ef232c0c2049..293846400296 100644
> > > --- a/drivers/gpu/drm/panthor/panthor_fw.c
> > > +++ b/drivers/gpu/drm/panthor/panthor_fw.c
> > > @@ -515,8 +515,7 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
> > > return -EINVAL;
> > > }
> > >
> > > - if ((hdr.va.start & ~PAGE_MASK) != 0 ||
> > > - (hdr.va.end & ~PAGE_MASK) != 0) {
> > > + if (!IS_ALIGNED(hdr.va.start, SZ_4K) || !IS_ALIGNED(hdr.va.end, SZ_4K)) {
> > > drm_err(&ptdev->base, "Firmware corrupted, virtual addresses not page aligned: 0x%x-0x%x\n",
> > > hdr.va.start, hdr.va.end);
> > > return -EINVAL;
> > > diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
> > > index c60b599665d8..2c8d6e2c7232 100644
> > > --- a/drivers/gpu/drm/panthor/panthor_gem.c
> > > +++ b/drivers/gpu/drm/panthor/panthor_gem.c
> > > @@ -44,8 +44,7 @@ void panthor_kernel_bo_destroy(struct panthor_kernel_bo *bo)
> > > to_panthor_bo(bo->obj)->exclusive_vm_root_gem != panthor_vm_root_gem(vm)))
> > > goto out_free_bo;
> > >
> > > - ret = panthor_vm_unmap_range(vm, bo->va_node.start,
> > > - panthor_kernel_bo_size(bo));
> > > + ret = panthor_vm_unmap_range(vm, bo->va_node.start, bo->va_node.size);
> > > if (ret)
> > > goto out_free_bo;
> > >
> > > @@ -95,10 +94,16 @@ panthor_kernel_bo_create(struct panthor_device *ptdev, struct panthor_vm *vm,
> > > }
> > > bo = to_panthor_bo(&obj->base);
> > > - size = obj->base.size;
> > > kbo->obj = &obj->base;
> > > bo->flags = bo_flags;
> > >
> > > + /* The system and GPU MMU page size might differ, which becomes a
> > > + * problem for FW sections that need to be mapped at explicit address
> > > + * since our PAGE_SIZE alignment might cover a VA range that's
> > > + * expected to be used for another section.
> > > + * Make sure we never map more than we need.
> > > + */
>
> I was wondering, this must be a relatively common situation for other DRM
> drivers, so maybe the DRM shmem core should have a BO creation function that
> lets you specify an exact page alignment?
So, there's a difference between the MMU page granularity and the system
page size. The BO allocation granularity will always be the system page
size, because gem_shmem can't allocate partial pages.
>
> > > + size = ALIGN(size, SZ_4K);
>
> I was thinking, if we know that the FW's page size is always 4KiB, maybe we could do
>
> #define CSF_FW_PAGESIZE SZ_4K
>
> somewhere in panthor_fw.h to make things clearer?
That I can do. If we want it to be fully dynamic, we can even make it a
panthor_mmu_get_page_size() helper which queries the pgsize_bitmap of
the io_pgtable to get the minimum granularity.
prev parent reply other threads:[~2024-10-14 6:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-08 8:47 [PATCH] drm/panthor: Fix firmware initialization on systems with a page size > 4k Boris Brezillon
2024-10-09 8:10 ` Steven Price
2024-10-11 17:58 ` Adrián Larumbe
2024-10-12 0:41 ` Liviu Dudau
2024-10-14 6:49 ` Boris Brezillon [this message]
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=20241014084953.37a417fd@collabora.com \
--to=boris.brezillon@collabora.com \
--cc=adrian.larumbe@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel@collabora.com \
--cc=liviu.dudau@arm.com \
--cc=steven.price@arm.com \
/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.