On Mon, 2 Feb 2026 16:48:41 +0000 Steven Price <[email protected]> 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 <[email protected]> > > --- > > 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()) | > <pre-empted> | > | 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!
