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 A684FEE3698 for ; Thu, 12 Feb 2026 17:18:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C3BFE10E1C2; Thu, 12 Feb 2026 17:18:13 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E21B10E1C2 for ; Thu, 12 Feb 2026 17:18:13 +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 62504339 for ; Thu, 12 Feb 2026 09:18:06 -0800 (PST) Received: from [192.168.0.1] (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7F20C3F632 for ; Thu, 12 Feb 2026 09:18:12 -0800 (PST) Date: Thu, 12 Feb 2026 17:16:07 +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 v3 8/9] drm/panthor: Track the number of mmap on a BO Message-ID: References: <20260211080343.1887134-1-boris.brezillon@collabora.com> <20260211080343.1887134-9-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: <20260211080343.1887134-9-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 Wed, Feb 11, 2026 at 09:03:42AM +0100, Boris Brezillon wrote: > This will be used to order things by reclaimability. > > v2: > - Fix refcounting > > v3: > - Fix refcounting (again) > > Signed-off-by: Boris Brezillon Reviewed-by: Liviu Dudau Best regards, Liviu > --- > drivers/gpu/drm/panthor/panthor_gem.c | 45 +++++++++++++++++++++++++-- > drivers/gpu/drm/panthor/panthor_gem.h | 3 ++ > 2 files changed, 46 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c > index 8905042b856c..e46bfc4f2063 100644 > --- a/drivers/gpu/drm/panthor/panthor_gem.c > +++ b/drivers/gpu/drm/panthor/panthor_gem.c > @@ -491,6 +491,7 @@ static void panthor_gem_print_info(struct drm_printer *p, unsigned int indent, > drm_printf_indent(p, indent, "vmap_use_count=%u\n", > refcount_read(&bo->cmap.vaddr_use_count)); > drm_printf_indent(p, indent, "vaddr=%p\n", bo->cmap.vaddr); > + drm_printf_indent(p, indent, "mmap_count=%u\n", refcount_read(&bo->cmap.mmap_count)); > } > > static int panthor_gem_pin_locked(struct drm_gem_object *obj) > @@ -606,6 +607,13 @@ static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *v > if (is_cow_mapping(vma->vm_flags)) > return -EINVAL; > > + if (!refcount_inc_not_zero(&bo->cmap.mmap_count)) { > + dma_resv_lock(obj->resv, NULL); > + if (!refcount_inc_not_zero(&bo->cmap.mmap_count)) > + refcount_set(&bo->cmap.mmap_count, 1); > + dma_resv_unlock(obj->resv); > + } > + > vm_flags_set(vma, VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP); > vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); > if (should_map_wc(bo)) > @@ -732,10 +740,43 @@ static vm_fault_t panthor_gem_fault(struct vm_fault *vmf) > return blocking_page_setup(vmf, bo, page_offset, true); > } > > +static void panthor_gem_vm_open(struct vm_area_struct *vma) > +{ > + struct panthor_gem_object *bo = to_panthor_bo(vma->vm_private_data); > + > + /* mmap_count must have been incremented at mmap time, so it can't be > + * zero here. > + */ > + if (!drm_gem_is_imported(&bo->base)) > + drm_WARN_ON(bo->base.dev, !refcount_inc_not_zero(&bo->cmap.mmap_count)); > + > + drm_gem_vm_open(vma); > +} > + > +static void panthor_gem_vm_close(struct vm_area_struct *vma) > +{ > + struct panthor_gem_object *bo = to_panthor_bo(vma->vm_private_data); > + > + if (drm_gem_is_imported(&bo->base)) > + goto out; > + > + if (refcount_dec_not_one(&bo->cmap.mmap_count)) > + goto out; > + > + dma_resv_lock(bo->base.resv, NULL); > + if (refcount_dec_and_test(&bo->cmap.mmap_count)) { > + /* Nothing to do, pages are reclaimed lazily. */ > + } > + dma_resv_unlock(bo->base.resv); > + > +out: > + drm_gem_object_put(&bo->base); > +} > + > const struct vm_operations_struct panthor_gem_vm_ops = { > .fault = panthor_gem_fault, > - .open = drm_gem_vm_open, > - .close = drm_gem_vm_close, > + .open = panthor_gem_vm_open, > + .close = panthor_gem_vm_close, > }; > > static const struct drm_gem_object_funcs panthor_gem_funcs = { > diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h > index b66478c9590c..c0a18dca732c 100644 > --- a/drivers/gpu/drm/panthor/panthor_gem.h > +++ b/drivers/gpu/drm/panthor/panthor_gem.h > @@ -80,6 +80,9 @@ struct panthor_gem_cpu_map { > > /** @vaddr_use_count: Number of active vmap() requests on this GEM */ > refcount_t vaddr_use_count; > + > + /** @mmap_count: Number of active mmap() requests on this GEM */ > + refcount_t mmap_count; > }; > > /** > -- > 2.52.0 > -- ==================== | I would like to | | fix the world, | | but they're not | | giving me the | \ source code! / --------------- ¯\_(ツ)_/¯