From mboxrd@z Thu Jan 1 00:00:00 1970 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 E83E5D46605 for ; Thu, 15 Jan 2026 17:41:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3E79B10E7B5; Thu, 15 Jan 2026 17:41:06 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by gabe.freedesktop.org (Postfix) with ESMTP id 4033310E7B5 for ; Thu, 15 Jan 2026 17:41:04 +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 3D1D51515 for ; Thu, 15 Jan 2026 09:40:57 -0800 (PST) Received: from e142607.local (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id AD06B3F59E for ; Thu, 15 Jan 2026 09:41:03 -0800 (PST) Date: Thu, 15 Jan 2026 17:40:08 +0000 From: Liviu Dudau To: Boris Brezillon Cc: Steven Price , =?utf-8?Q?Adri=C3=A1n?= Larumbe , dri-devel@lists.freedesktop.org, David Airlie , Simona Vetter , Akash Goel , Rob Clark , Sean Paul , Konrad Dybcio , Akhil P Oommen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Dmitry Osipenko , Chris Diamand , Danilo Krummrich , Matthew Brost , Thomas =?utf-8?Q?Hellstr=C3=B6m?= , Alice Ryhl , kernel@collabora.com Subject: Re: [PATCH v1 7/9] drm/panthor: Split panthor_vm_prepare_map_op_ctx() to prepare for reclaim Message-ID: References: <20260109130801.1239558-1-boris.brezillon@collabora.com> <20260109130801.1239558-8-boris.brezillon@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20260109130801.1239558-8-boris.brezillon@collabora.com> 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, Jan 09, 2026 at 02:07:59PM +0100, Boris Brezillon wrote: > We're gonna need just the page table reservation logic when we restore > evicted BO mappings, so let's prepare for that by extracting the > op_ctx init and page table pre-allocation into separate helpers. > > Signed-off-by: Boris Brezillon Reviewed-by: Liviu Dudau Best regards, Liviu > --- > drivers/gpu/drm/panthor/panthor_mmu.c | 70 ++++++++++++++++----------- > 1 file changed, 42 insertions(+), 28 deletions(-) > > diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c > index c323b7123713..3290e0b5facb 100644 > --- a/drivers/gpu/drm/panthor/panthor_mmu.c > +++ b/drivers/gpu/drm/panthor/panthor_mmu.c > @@ -1170,6 +1170,45 @@ panthor_vm_op_ctx_prealloc_vmas(struct panthor_vm_op_ctx *op_ctx) > return 0; > } > > +static void panthor_vm_init_op_ctx(struct panthor_vm_op_ctx *op_ctx, > + u64 size, u64 va, u32 flags) > +{ > + memset(op_ctx, 0, sizeof(*op_ctx)); > + op_ctx->flags = flags; > + op_ctx->va.range = size; > + op_ctx->va.addr = va; > +} > + > +static int panthor_vm_op_ctx_prealloc_pts(struct panthor_vm_op_ctx *op_ctx) > +{ > + u64 size = op_ctx->va.range; > + u64 va = op_ctx->va.addr; > + int ret; > + > + /* L1, L2 and L3 page tables. > + * We could optimize L3 allocation by iterating over the sgt and merging > + * 2M contiguous blocks, but it's simpler to over-provision and return > + * the pages if they're not used. > + */ > + u64 pt_count = ((ALIGN(va + size, 1ull << 39) - ALIGN_DOWN(va, 1ull << 39)) >> 39) + > + ((ALIGN(va + size, 1ull << 30) - ALIGN_DOWN(va, 1ull << 30)) >> 30) + > + ((ALIGN(va + size, 1ull << 21) - ALIGN_DOWN(va, 1ull << 21)) >> 21); > + > + op_ctx->rsvd_page_tables.pages = kcalloc(pt_count, > + sizeof(*op_ctx->rsvd_page_tables.pages), > + GFP_KERNEL); > + if (!op_ctx->rsvd_page_tables.pages) > + return -ENOMEM; > + > + ret = kmem_cache_alloc_bulk(pt_cache, GFP_KERNEL, pt_count, > + op_ctx->rsvd_page_tables.pages); > + op_ctx->rsvd_page_tables.count = ret; > + if (ret != pt_count) > + return -ENOMEM; > + > + return 0; > +} > + > #define PANTHOR_VM_BIND_OP_MAP_FLAGS \ > (DRM_PANTHOR_VM_BIND_OP_MAP_READONLY | \ > DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC | \ > @@ -1185,7 +1224,6 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx, > { > struct drm_gpuvm_bo *preallocated_vm_bo; > struct sg_table *sgt = NULL; > - u64 pt_count; > int ret; > > if (!bo) > @@ -1204,10 +1242,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx, > bo->exclusive_vm_root_gem != panthor_vm_root_gem(vm)) > return -EINVAL; > > - memset(op_ctx, 0, sizeof(*op_ctx)); > - op_ctx->flags = flags; > - op_ctx->va.range = size; > - op_ctx->va.addr = va; > + panthor_vm_init_op_ctx(op_ctx, size, va, flags); > > ret = panthor_vm_op_ctx_prealloc_vmas(op_ctx); > if (ret) > @@ -1250,30 +1285,9 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx, > > op_ctx->map.bo_offset = offset; > > - /* L1, L2 and L3 page tables. > - * We could optimize L3 allocation by iterating over the sgt and merging > - * 2M contiguous blocks, but it's simpler to over-provision and return > - * the pages if they're not used. > - */ > - pt_count = ((ALIGN(va + size, 1ull << 39) - ALIGN_DOWN(va, 1ull << 39)) >> 39) + > - ((ALIGN(va + size, 1ull << 30) - ALIGN_DOWN(va, 1ull << 30)) >> 30) + > - ((ALIGN(va + size, 1ull << 21) - ALIGN_DOWN(va, 1ull << 21)) >> 21); > - > - op_ctx->rsvd_page_tables.pages = kcalloc(pt_count, > - sizeof(*op_ctx->rsvd_page_tables.pages), > - GFP_KERNEL); > - if (!op_ctx->rsvd_page_tables.pages) { > - ret = -ENOMEM; > + ret = panthor_vm_op_ctx_prealloc_pts(op_ctx); > + if (ret) > goto err_cleanup; > - } > - > - ret = kmem_cache_alloc_bulk(pt_cache, GFP_KERNEL, pt_count, > - op_ctx->rsvd_page_tables.pages); > - op_ctx->rsvd_page_tables.count = ret; > - if (ret != pt_count) { > - ret = -ENOMEM; > - goto err_cleanup; > - } > > /* Insert BO into the extobj list last, when we know nothing can fail. */ > dma_resv_lock(panthor_vm_resv(vm), NULL); > -- > 2.52.0 >