Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3C10D0EE1C for ; Sat, 12 Oct 2024 00:42:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6908E10E0DA; Sat, 12 Oct 2024 00:42:03 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by gabe.freedesktop.org (Postfix) with ESMTP id E17B110E0DA for ; Sat, 12 Oct 2024 00:42:02 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0DCE8DA7 for ; Fri, 11 Oct 2024 17:42:32 -0700 (PDT) Received: from e110455-lin.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 30B173F5A1 for ; Fri, 11 Oct 2024 17:42:02 -0700 (PDT) Date: Sat, 12 Oct 2024 01:41:58 +0100 From: Liviu Dudau To: =?utf-8?Q?Adri=C3=A1n?= Larumbe Cc: Steven Price , Boris Brezillon , dri-devel@lists.freedesktop.org, kernel@collabora.com Subject: Re: [PATCH] drm/panthor: Fix firmware initialization on systems with a page size > 4k Message-ID: References: <20241008084744.82688-1-boris.brezillon@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Fri, Oct 11, 2024 at 06:58:45PM +0100, Adrián Larumbe 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 > > > > Reviewed-by: Steven Price Reviewed-by: Liviu Dudau > > > > > --- > > > 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? There are probably not that many DRM drivers that need specific alignment, but I think it's not a bad idea to add a function like that in a separate patch. > > > > + 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? Until future comes in and the firmware page size changes :) But yeah, it could help in the future to search for firmware's page size when we will need to update it. Best regards, Liviu > > Cheers, > Adrian > > Reviewed-by: Adrian Larumbe > > > > ret = panthor_vm_alloc_va(vm, gpu_va, size, &kbo->va_node); > > > if (ret) > > > goto err_put_obj; > > > diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c > > > index 3cd2bce59edc..e53d131c53cc 100644 > > > --- a/drivers/gpu/drm/panthor/panthor_mmu.c > > > +++ b/drivers/gpu/drm/panthor/panthor_mmu.c > > > @@ -1027,10 +1027,10 @@ panthor_vm_alloc_va(struct panthor_vm *vm, u64 va, u64 size, > > > { > > > int ret; > > > > > > - if (!size || (size & ~PAGE_MASK)) > > > + if (!size || !IS_ALIGNED(size, SZ_4K)) > > > return -EINVAL; > > > > > > - if (va != PANTHOR_VM_KERNEL_AUTO_VA && (va & ~PAGE_MASK)) > > > + if (va != PANTHOR_VM_KERNEL_AUTO_VA && !IS_ALIGNED(va, SZ_4K)) > > > return -EINVAL; > > > > > > mutex_lock(&vm->mm_lock); > > > @@ -2370,7 +2370,7 @@ panthor_vm_bind_prepare_op_ctx(struct drm_file *file, > > > int ret; > > > > > > /* Aligned on page size. */ > > > - if ((op->va | op->size) & ~PAGE_MASK) > > > + if (!IS_ALIGNED(op->va | op->size, SZ_4K)) > > > return -EINVAL; > > > > > > switch (op->flags & DRM_PANTHOR_VM_BIND_OP_TYPE_MASK) { > -- ==================== | I would like to | | fix the world, | | but they're not | | giving me the | \ source code! / --------------- ¯\_(ツ)_/¯