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 BB877CD6E57 for ; Wed, 3 Jun 2026 17:14:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 11EF7112174; Wed, 3 Jun 2026 17:14:13 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="axVI2v1o"; dkim-atps=neutral Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 060B1112174 for ; Wed, 3 Jun 2026 17:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1780506850; bh=TLmekHM3EmmxpFvVf0s2ub+Xb1oU8p/GBNRtuqGNaWI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=axVI2v1oU/IIMKtn8X01EBEvuFuOLnOM54apTBHtHP2lQNaDvDltdf3Mde3xDboLu 5PF0kH4s8L9VjNDKIawb74LfJJWXmGaOzeF1zLQf4paiY1MU9Fg48onr55L+Ak3C8G mLbg4vgV0L5ufHjNtLWU3GzDo6UkwI9PvIt+0xKtW27/6moaWiv9Qo5SkzMTQHK52Y O32VNGIJ/wbtBBB+ckEX1eAnQHOFLsSxhilyZSaDEAE2C/GvXsM7p35rQDSGVxOI57 xFXL5sgkzS5K99/iAAf5x62loT1VeTEz8pFwcAjtBNpiPOAnYassMd6yX+qgWAQAwS Vnti14waWdv6w== Received: from fedora-2.home (unknown [100.64.0.11]) (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 57F2317E05FC; Wed, 3 Jun 2026 19:14:09 +0200 (CEST) Date: Wed, 3 Jun 2026 19:14:05 +0200 From: Boris Brezillon To: Daniel Almeida Cc: Philipp Stanner , Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?B?QmrDtnJu?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Sumit Semwal , Christian =?UTF-8?B?S8O2bmln?= , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Greg Kroah-Hartman , Igor Korotin , Lorenzo Stoakes , Alexandre Courbot , FUJITA Tomonori , Krishna Ketan Rai , Shankari Anand , manos@pitsidianak.is, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, rcu@vger.kernel.org Subject: Re: [PATCH 3/4] rust: Add dma_fence abstractions Message-ID: <20260603191405.4c75badb@fedora-2.home> In-Reply-To: <4F8E8E04-5AB5-4E6B-9194-5FC467E2313F@collabora.com> References: <20260530143541.229628-2-phasta@kernel.org> <20260530143541.229628-5-phasta@kernel.org> <4F8E8E04-5AB5-4E6B-9194-5FC467E2313F@collabora.com> Organization: Collabora X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; 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 Wed, 3 Jun 2026 13:41:02 -0300 Daniel Almeida wrote: > > + /// Called when the fence is signaled. > > + /// > > + /// This is called from the fence signaling path, which may be in interrupt > > + /// context or with locks held, which is why `self` is only borrowed, so that > > + /// it cannot drop. Implementations must not sleep or perform > > + /// long-running operations. > > + /// > > + /// An implementation likely wants to inform itself (e.g., through a work item) > > + /// within this callback that the associated [`FenceCbRegistration`] can now be > > + /// dropped. > > + fn called(&mut self); > > This is a central point. We ideally would want this to consume self, because we > may want to move things out of the callback. This one comes from me. The rationale being that ::called() is called from an atomic context, and the resources attached to the callback data might require acquiring other sleeping locks to be released, and sometimes you don't even notice immediately because said resources are refcounted, and the lock is only acquired when you happen to be the last owner. Yes, those can be caught at runtime if the C side is properly annotated with might_sleep(), but that's not always the case. If we defer the drop of the data only when the FenceCb is dropped/recycled, we're at least not constrained by this "runs in atomic context" thing. > > Consider a fence design where signal() consumes self. Now consider this: > > ``` > impl FenceCb for MyCallback { > fn called(&mut self) { > // Can't move the fence out, so we have to put an Option just to be able > // to move. > if let Some(f) = self.some_fence.take() { > f.signal(); > } > } > ``` > > This used to be the case when our version of the job queue used the "proxy > fence" design: > > > ``` > // Callback on the hw fence > impl FenceCb for MyCallback { > fn called(&mut self) { > if let Some(f) = self.submit_fence.take() { > f.signal(); > } I'm pretty sure lockdep won't like it anyway, because this is nested locking of the same lock class. For such proxies, we'll need to teach lockdep about the nesting like has been recently done on dma_fence_array & co. But I'm digressing. > } > ``` > > Although this is not the case anymore, since we phased out this design given > Christian's recent work. Still, we should ideally not require Option here in > general just to make resource transfer possible. I see. OTOH, don't we need to make this inner data movable if we want to cancel the FenceCb before the fence is signaled anyway? And that's most certainly a case we have in the teardown path.