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 D8E26E7DF0A for ; Mon, 2 Feb 2026 16:52:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 412B310E500; Mon, 2 Feb 2026 16:52:45 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="lW+50llU"; dkim-atps=neutral Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id CFFB210E500 for ; Mon, 2 Feb 2026 16:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1770051162; bh=1C/eWXfz/8E8OiOMDyZd+lz0fF9dC1XLvsKZslpQO9k=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lW+50llUnzR626txg7aIRLHp/2RMuQspRgDqyt7liGLBF/Zk3PL1sZR1bIWzVX+RA 8Nbt8FYH6tJ165R6MVbwG7LMUzT/v7zG9UOIxDzMLRgWs4rkODRE8LvmQ+p0lvtjIZ 3zgaZrqGb2tvFP/usA71D21o7hQlS6tStAGhurAvGRFcWMzS8YGmG92eopetIZ7o+e KuVmASLwpk6vBuVpeMug8rP3zKWUnNc5KoijJUucCRWI6beUN3GviJbG6mfosdYjnQ ApQXre383u9+L3kcybEO4IwT+6hTM/IWulMFay0dIF5Iyu/US7lWMi1xSSJ9EwgzcM R0Kg2RkbIOTdA== Received: from fedora (unknown [IPv6:2a01:e0a:2c:6930:d919:a6e:5ea1:8a9f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by bali.collaboradmins.com (Postfix) with ESMTPSA id A55AF17E1203; Mon, 2 Feb 2026 17:52:41 +0100 (CET) Date: Mon, 2 Feb 2026 17:52:36 +0100 From: Boris Brezillon To: Steven Price Cc: Liviu Dudau , =?UTF-8?B?QWRyacOhbg==?= 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?B?SGVsbHN0csO2bQ==?= , Alice Ryhl , kernel@collabora.com Subject: Re: [PATCH v2 7/8] drm/panthor: Track the number of mmap on a BO Message-ID: <20260202175236.0e26e671@fedora> In-Reply-To: References: <20260202113607.1745667-1-boris.brezillon@collabora.com> <20260202113607.1745667-8-boris.brezillon@collabora.com> Organization: Collabora X-Mailer: Claws Mail 4.3.1 (GTK 3.24.51; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Mon, 2 Feb 2026 16:48:41 +0000 Steven Price wrote: > On 02/02/2026 11:36, Boris Brezillon wrote: > > This will be used to order things by reclaimability. > > > > v2: > > - Fix refcounting > > > > Signed-off-by: Boris Brezillon > > --- > > drivers/gpu/drm/panthor/panthor_gem.c | 44 +++++++++++++++++++++++++-- > > drivers/gpu/drm/panthor/panthor_gem.h | 3 ++ > > 2 files changed, 45 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c > > index 7e966fbe500f..26fe4be10a86 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) > > @@ -603,6 +604,12 @@ 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); > > + refcount_set(&bo->cmap.mmap_count, 1); > > I think you still need to recheck the refcount with the lock held. > Otherwise two threads could race: > > Thread 1 | Thread 2 > -------------------------------+-------------------------- > if (!refcount_inc_not_zero()) | > | > | if (!refcount_inc_not_zero()) > | dma_resv_lock() > | refcount_set(..., 1) > | dma_resv_unlock() > dma_resv_lock() | > refcount_set(..., 1) | > dma_resv_unlock() | > > Which leaves a refcount missing. Uh, right. I fixed that pattern in multiple places but somehow overlooked this one. Will fix in v3. Thanks!