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 981BDEF48C9 for ; Mon, 16 Feb 2026 08:57:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 07E2310E1B6; Mon, 16 Feb 2026 08:57:22 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="V6VdsYkw"; dkim-atps=neutral Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id CAAA410E1F5 for ; Mon, 16 Feb 2026 08:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1771232239; bh=Q2wZ05+kkbpTiaWuLV2p79VJg8YBx8ve3kJWksjnV4U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=V6VdsYkwhO2T6ofbx21wM2gFf5qoFcJTfQu2YLrgp4JwL5Qe4iG/rNt0WQMSABc3i 0sd9LULh8XWr62useoiKP8w79SLaz+PY2Mobolg10WgBshYGqYIKRpDRldHYAq/pxd jxO2BaSyCWkh/lCGmlo7g5M0JHNDZ3A0Y/DqbwV7CWa0iZ//+Ix1j97AWn0Mxrejxq muy9ZkiLRRudTnUEaDtBrJmfGjXtl6RHWaqRY/d7TyKZKeiTJaNrS+5xY84l2E1a1l QiOLrxePMOr3iEMdg4177AZp6Z6BbT5FokpT4AgnkZWUYHKqZFTUCH9dteM/XQ0PZS jBUVswYnAikfA== 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 A5E8017E131F; Mon, 16 Feb 2026 09:57:18 +0100 (CET) Date: Mon, 16 Feb 2026 09:57:14 +0100 From: Boris Brezillon To: =?UTF-8?B?QWRyacOhbg==?= Larumbe Cc: Steven Price , Liviu Dudau , 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 v3 9/9] drm/panthor: Add a GEM shrinker Message-ID: <20260216095714.40a7e5ec@fedora> In-Reply-To: References: <20260211080343.1887134-1-boris.brezillon@collabora.com> <20260211080343.1887134-10-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=UTF-8 Content-Transfer-Encoding: quoted-printable 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, 13 Feb 2026 18:23:34 +0000 Adri=C3=A1n Larumbe wrote: > > +static int remap_evicted_vma(struct drm_gpuvm_bo *vm_bo, > > + struct panthor_vma *evicted_vma, > > + struct panthor_vm_op_ctx *op_ctx) > > +{ > > + struct panthor_vm *vm =3D container_of(vm_bo->vm, struct panthor_vm, = base); > > + struct panthor_gem_object *bo =3D to_panthor_bo(vm_bo->obj); > > + struct drm_gpuva *va; > > + bool found =3D false; > > + int ret; > > + > > + ret =3D panthor_vm_op_ctx_prealloc_pts(op_ctx); > > + if (ret) > > + goto out_cleanup; > > + > > + /* Take op_lock to protect against va insertion/removal. */ > > + mutex_lock(&vm->op_lock); > > + drm_gpuvm_bo_for_each_va(va, vm_bo) { > > + struct panthor_vma *vma =3D container_of(va, struct panthor_vma, bas= e); > > + > > + if (vma !=3D evicted_vma) > > + continue; > > + > > + /* We can't rely solely on pointer equality, because the VMA might h= ave been > > + * freed and a new one allocated at the same address. If the evicted= bit > > + * is still set, we're sure it's our VMA, because population/evictio= n is > > + * serialized with the BO resv lock. > > + */ =20 >=20 > At first I thought to avoid having VM_BIND operations change the VM's VMA= 's in the interval between > select_evicted_vma() and remap_evicted_vma(), maybe you could take the VM= 's operation lock around both of them > in panthor_vm_restore_vmas(). But because the same lock is taken in the d= ma signalling path and > panthor_vm_op_ctx_prealloc_pts() can sleep, then we cannot do that. Maybe= you could add a note clarifying this? Sure, how about index 78b875a59d1e..9ce4077bef8e 100644 --- a/drivers/gpu/drm/panthor/panthor_mmu.c +++ b/drivers/gpu/drm/panthor/panthor_mmu.c @@ -2395,7 +2395,11 @@ static int remap_evicted_vma(struct drm_gpuvm_bo *vm= _bo, if (ret) goto out_cleanup; =20 - /* Take op_lock to protect against va insertion/removal. */ + /* Take op_lock to protect against va insertion/removal. Note that = the + * evicted_vma selection was done with the same lock held, but we h= ad + * to release it so we can allocate PTs, because this very same lock + * is taken in a DMA-signalling path. + */ mutex_lock(&vm->op_lock); drm_gpuvm_bo_for_each_va(va, vm_bo) { struct panthor_vma *vma =3D container_of(va, struct panthor= _vma, base); @@ -2403,10 +2407,11 @@ static int remap_evicted_vma(struct drm_gpuvm_bo *v= m_bo, if (vma !=3D evicted_vma) continue; =20 - /* We can't rely solely on pointer equality, because the VM= A might have been - * freed and a new one allocated at the same address. If th= e evicted bit - * is still set, we're sure it's our VMA, because populatio= n/eviction is - * serialized with the BO resv lock. + /* Because we had to release the lock between the evicted_v= ma selection + * and its repopulation, we can't rely solely on pointer eq= uality (the + * VMA might have been freed and a new one allocated at the= same address). + * If the evicted bit is still set, we're sure it's our VMA= , because + * population/eviction is serialized with the BO resv lock. */ if (vma->evicted) found =3D true; ?