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 1701CCAC5B8 for ; Mon, 6 Oct 2025 11:41:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6301E10E357; Mon, 6 Oct 2025 11:41:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="my/QQ51+"; dkim-atps=neutral Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0C5EB10E357 for ; Mon, 6 Oct 2025 11:41:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1759750873; bh=hUUotr5MYYM9aMcAKjEfjPvHV8s0XExBA23OlR2mXR8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=my/QQ51+SkDZGZdItelA0xu/CEBqSp22WzT1IV5M1OPTHxOkMK8+apad66Cjsxg+W T4xtxfXbS+xvPvoYGT/tTH0nnaG5f52Mp5aOlYynlMTFNPxOi2qzmryOc9In4dZJsZ 4RM7bu6U69cW0f8mLkXssfSUorbb3qsrAyMssRdQg4ivFXBdTyIzMdJpe2OCHK4Q9H tGopfrl/BgQTfH9NrdnjyOzo6ZROCiOAepaJy592ls/mDmMBFpYWsbi9K/45JvyDvD k673KzmXvbXjihnvpeJHcuqDTC7AozU6SVeEhNpeteAVsvdtwB1cwmm4We9dZyfJbY 0V5PQ8GrXQOzw== 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 X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by bali.collaboradmins.com (Postfix) with ESMTPSA id 143C917E0AC3; Mon, 6 Oct 2025 13:41:13 +0200 (CEST) Date: Mon, 6 Oct 2025 13:41:08 +0200 From: Boris Brezillon To: Alice Ryhl Cc: Danilo Krummrich , Matthew Brost , Thomas =?UTF-8?B?SGVsbHN0csO2bQ==?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Steven Price , Daniel Almeida , Liviu Dudau , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: Re: [PATCH v3 1/2] drm/gpuvm: add deferred vm_bo cleanup Message-ID: <20251006134108.6a5cdcb7@fedora> In-Reply-To: References: <20251001-vmbo-defer-v3-0-a3fe6b6ae185@google.com> <20251001-vmbo-defer-v3-1-a3fe6b6ae185@google.com> <20251001171346.482142eb@fedora> Organization: Collabora X-Mailer: Claws Mail 4.3.1 (GTK 3.24.49; 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 Mon, 6 Oct 2025 13:31:51 +0200 Alice Ryhl wrote: > On Wed, Oct 1, 2025 at 5:13=E2=80=AFPM Boris Brezillon > wrote: > > > > On Wed, 1 Oct 2025 16:42:35 +0200 > > Alice Ryhl wrote: > > =20 > > > On Wed, Oct 1, 2025 at 4:01=E2=80=AFPM Danilo Krummrich wrote: =20 > > > > > > > > On Wed Oct 1, 2025 at 12:41 PM CEST, Alice Ryhl wrote: =20 > > > > > +/* > > > > > + * Must be called with GEM mutex held. After releasing GEM mutex, > > > > > + * drm_gpuvm_bo_defer_free_unlocked() must be called. > > > > > + */ > > > > > +static void > > > > > +drm_gpuvm_bo_defer_free_locked(struct kref *kref) > > > > > +{ > > > > > + struct drm_gpuvm_bo *vm_bo =3D container_of(kref, struct dr= m_gpuvm_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); > > > > > +} > > > > > + > > > > > +/* > > > > > + * GEM mutex must not be held. Called after drm_gpuvm_bo_defer_f= ree_locked(). > > > > > + */ > > > > > +static void > > > > > +drm_gpuvm_bo_defer_free_unlocked(struct drm_gpuvm_bo *vm_bo) > > > > > +{ > > > > > + struct drm_gpuvm *gpuvm =3D vm_bo->vm; > > > > > + > > > > > + llist_add(&vm_bo->list.entry.bo_defer, &gpuvm->bo_defer); > > > > > +} > > > > > + > > > > > +static void > > > > > +drm_gpuvm_bo_defer_free(struct kref *kref) > > > > > +{ > > > > > + struct drm_gpuvm_bo *vm_bo =3D container_of(kref, struct dr= m_gpuvm_bo, > > > > > + kref); > > > > > + > > > > > + mutex_lock(&vm_bo->obj->gpuva.lock); > > > > > + drm_gpuvm_bo_defer_free_locked(kref); > > > > > + mutex_unlock(&vm_bo->obj->gpuva.lock); > > > > > + > > > > > + /* > > > > > + * It's important that the GEM stays alive for the duration= in which we > > > > > + * hold the mutex, but the instant we add the vm_bo to bo_d= efer, > > > > > + * another thread might call drm_gpuvm_bo_deferred_cleanup(= ) and put > > > > > + * the GEM. Therefore, to avoid kfreeing a mutex we are hol= ding, we add > > > > > + * the vm_bo to bo_defer *after* releasing the GEM's mutex. > > > > > + */ > > > > > + drm_gpuvm_bo_defer_free_unlocked(vm_bo); > > > > > +} =20 > > > > > > > > So, you're splitting drm_gpuvm_bo_defer_free() into two functions, = one doing the > > > > work that is required to be called with the gpuva lock held and one= that does > > > > the work that does not require a lock, which makes perfect sense. > > > > > > > > However, the naming chosen for the two functions, i.e. > > > > drm_gpuvm_bo_defer_free_unlocked() and drm_gpuvm_bo_defer_free_lock= ed() is > > > > confusing: > > > > > > > > What you mean semantically mean is "do part 1 with lock held" and "= do part 2 > > > > without lock held", but the the chosen names suggest that both func= tions are > > > > identical, with the only difference that one takes the lock interna= lly and the > > > > other one requires the caller to take the lock. > > > > > > > > It's probably better to name them after what they do and not what t= hey're part > > > > of. If you prefer the latter, that's fine with me too, but please c= hoose a name > > > > that makes this circumstance obvious. =20 > > > > > > Fair point. Do you have naming suggestions? Otherwise I can name them > > > drm_gpuvm_bo_defer_free_part1() and drm_gpuvm_bo_defer_free_part2(). > > > :) =20 > > > > drm_gpuvm_bo_free_deferral_extract_locked() and > > drm_gpuvm_bo_free_deferral_enqueue()? Definitely not short names though= . =20 >=20 > With those names I have to do some additional line breaks. How about: >=20 > drm_gpuvm_bo_into_zombie() > drm_gpuvm_bo_defer_zombie() Sounds good. I think I'd prefer if the second one was called drm_gpuvm_bo_defer_zombie_cleanup() to make clear what the deferral is about, but feel free to ignore this if you think it's too long.