From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 796BFE552; Fri, 5 Sep 2025 22:47:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757112461; cv=none; b=sMt6JgTnILekSPflSFBcju7EnCgf2MYEVpAWKcSsMsUV9Z4fZI+Bxdn37Ri5Y08CZ4iULL5zFB8DR/s7cq1AOo9dEEpVkPNFyjKQmI610tq0lbQERJZS99GL5NCEuZoYsLsVG1bFKweBFvvKYBlcpp64Ern4/O+SiiMzBcgMhA8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757112461; c=relaxed/simple; bh=tGd46iQZ4DRbpvmkNmCnAZN6AsD9LicfdvyOISy1Mw4=; h=Mime-Version:Content-Type:Date:Message-Id:Subject:Cc:To:From: References:In-Reply-To; b=gn78l7j/Ox9nS2XAppEc2ymBfQGgqTMbzfFjTq5mfhlyFTHgeYTuNl/kylgJoAgbCRu0b2F5EfLvg93UcNLgl1ldACHR3fgHXOF2lAVZA/yCGyK1i41CA0Ldtme4M2c6BZDFTP/WutTQRr9ov6L6aBUGf+FJd3nkPM2f4vpxzyU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TcAR77h4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TcAR77h4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B005C4CEF1; Fri, 5 Sep 2025 22:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757112460; bh=tGd46iQZ4DRbpvmkNmCnAZN6AsD9LicfdvyOISy1Mw4=; h=Date:Subject:Cc:To:From:References:In-Reply-To:From; b=TcAR77h4nbsHt3U50oejIjGSj8BdrAIgFlSpDcx5NiYDyXpLea7shRMuTA609gocg u9S6lrMd3bUWK76TBOgERnUWkorsz9Wovc3lehCAtg2NSfDovhYa2Ho11Qn0o8MaHp wFkQz2NlQtk61Y7D+m7/8/VTDSZRK2y2z0Ewl62j/FwG45YPA5CdZD5bhSC5jWoo0l 1DCw1wM9dSSG+7SGCocKZr5yqhGbDh4lKYEUDQR8i/3c9aJ93B8aU9jRlWKXzuK8ku VsYKvmq4jL5s5CcsBNaJC64l/Ru45zCJ9NzYznJ8Z4W7QAbbfnuul28DgCUsapwhF6 zKGo7P4oLHQHQ== Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sat, 06 Sep 2025 00:47:36 +0200 Message-Id: Subject: Re: [PATCH 1/2] drm/gpuvm: add deferred vm_bo cleanup Cc: "Boris Brezillon" , "Matthew Brost" , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , "Maarten Lankhorst" , "Maxime Ripard" , "Thomas Zimmermann" , "David Airlie" , "Simona Vetter" , "Steven Price" , "Daniel Almeida" , "Liviu Dudau" , , , To: "Alice Ryhl" From: "Danilo Krummrich" References: <20250905-vmbo-defer-v1-0-7ae1a382b674@google.com> <20250905-vmbo-defer-v1-1-7ae1a382b674@google.com> <20250905152505.005a610d@fedora> In-Reply-To: On Fri Sep 5, 2025 at 8:18 PM CEST, Alice Ryhl wrote: > On Fri, Sep 5, 2025 at 3:25=E2=80=AFPM Boris Brezillon > wrote: >> On Fri, 05 Sep 2025 12:11:28 +0000 >> Alice Ryhl wrote: >> > +static bool >> > +drm_gpuvm_bo_is_dead(struct drm_gpuvm_bo *vm_bo) >> > +{ >> > + return !kref_read(&vm_bo->kref); >> >> I'm not too sure I like the idea of [ab]using vm_bo::kref to defer the >> vm_bo release. I get why it's done like that, but I'm wondering why we >> don't defer the release of drm_gpuva objects instead (which is really >> what's being released in va_unlink()). I can imagine drivers wanting to >> attach resources to the gpuva that can't be released in the >> dma-signalling path in the future, and if we're doing that at the gpuva >> level, we also get rid of this kref dance, since the va will hold a >> vm_bo ref until it's destroyed. >> >> Any particular reason you went for vm_bo destruction deferral instead >> of gpuva? > > All of the things that were unsafe to release in the signalling path > were tied to the vm_bo, so that is why I went for vm_bo cleanup. > Another advantage is that it lets us use the same deferred logic for > the vm_bo_put() call that drops the refcount from vm_bo_obtain(). > > Of course if gpuvas might have resources that need deferred cleanup, > that might change the situation somewhat. I think we want to track PT(E) allocations, or rather reference counts of p= age table structures carried by the drm_gpuva, but we don't need to release the= m on drm_gpuva_unlink(), which is where we drop the reference count of the vm_bo= . Deferring drm_gpuva_unlink() isn't really an option I think, the GEMs list = of VM_BOs and the VM_BOs list of VAs is usually used in ttm_device_funcs::move= to map or unmap all VAs associated with a GEM object. I think PT(E) reference counts etc. should be rather released when the drm_= gpuva is freed, i.e. page table allocations can be bound to the lifetime of a drm_gpuva. Given that, I think that eventually we'll need a cleanup list fo= r those as well, since once they're removed from the VM tree (in the fence signalling critical path), we loose access otherwise. >> > +static void >> > +drm_gpuvm_bo_defer_locked(struct kref *kref) >> > +{ >> > + struct drm_gpuvm_bo *vm_bo =3D container_of(kref, struct drm_gpu= vm_bo, >> > + kref); >> > + struct drm_gpuvm *gpuvm =3D vm_bo->vm; >> > + >> > + if (!drm_gpuvm_resv_protected(gpuvm)) { >> > + drm_gpuvm_bo_list_del(vm_bo, extobj, true); >> > + drm_gpuvm_bo_list_del(vm_bo, evict, true); >> > + } >> > + >> > + list_del(&vm_bo->list.entry.gem); >> > + mutex_unlock(&vm_bo->obj->gpuva.lock); >> >> I got tricked by this implicit unlock, and the conditional unlocks it >> creates in drm_gpuva_unlink_defer(). Honestly, I'd rather see this >> unlocked moved to drm_gpuva_unlink_defer() and a conditional unlock >> added to drm_gpuvm_bo_put_deferred(), because it's easier to reason >> about when the lock/unlock calls are in the same function >> (kref_put_mutex() being the equivalent of a conditional lock). > > Ok. I followed the docs of kref_put_mutex() that say to unlock it from > the function. Yes, please keep it the way it is, I don't want to deviate from what is documented and everyone else does. Besides that, I also think it's a little less error prone.