From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EA1E606A31A for ; Wed, 2 Dec 2026 11:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IucIR8MW Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B176E11213D; Wed, 2 Dec 2026 11:41:02 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id A7E9411213D for ; Wed, 2 Dec 2026 11:40:56 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 8F6EB446FC; Wed, 2 Dec 2026 11:40:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9DBA1F00893; Wed, 2 Dec 2026 11:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796211656; bh=ZldvPlPDVQTirtjyzc/1IZBg2pruGMjbV1cEuOiJq8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IucIR8MWqS/0YLOPWx4do5h67OFfGzGbODKg56R/ypo/WvSaDkrRuMTNZoUuvqk7q pSRYv+/udV2UtBM3C0cYydS/o09NqpXRL3XPjVOCYBfjWY9kyEdBlqdIzKi1qrQ1N6 REdPI222KqDUgQVeNzISUIsXVkJOK7qoFlDvE9Z+KWwQdADqfRX1UQKrBaThthmOlv 4JV9kqbqQj6dMwtL52zKmM2dIBat5z/nkuTq+7c6TXEOfKc9goMw3D1/eIYwUZ2vo0 wrO2xMjEK67hD+gAyV1NBq8M8M97TMrwR9IO+ANJQOOZoPNIoj+7n1qomXHyhgubpy brp8CUxn/Dagw== From: Philipp Stanner To: Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?UTF-8?q?Onur=20=C3=96zkan?= , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Philipp Stanner , Matthew Brost , David Airlie , Simona Vetter , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Lyude Paul , "Joel Fernandes (NVIDIA)" , Boris Brezillon , Yuvan Shen Cc: rust-for-linux@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, rcu@vger.kernel.org Subject: [PATCH v3 7/9] rust: DmaFence: Pass result in callbacks Date: Wed, 2 Dec 2026 12:39:13 +0100 Message-ID: <20261202113914.1660411-9-phasta@kernel.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261202113914.1660411-2-phasta@kernel.org> References: <20261202113914.1660411-2-phasta@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "dri-devel" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 A FenceCallbackRegistration invokes the on_signal() trait functions specified by the user. These callbacks always get executed, even if the fence was signaled with an error. The user must then be able to react accordingly. Memory ordering is ensured by the C backend. Change the on_signal() trait function so that the implementor always receives the fence's actual state. Signed-off-by: Philipp Stanner --- rust/kernel/dma_buf/dma_fence.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/rust/kernel/dma_buf/dma_fence.rs b/rust/kernel/dma_buf/dma_fence.rs index 71e202e1f7cf..6141089335b3 100644 --- a/rust/kernel/dma_buf/dma_fence.rs +++ b/rust/kernel/dma_buf/dma_fence.rs @@ -299,9 +299,12 @@ fn from(e: AllocError) -> Self { /// } /// /// impl FenceCallback for MyCallback { -/// fn on_signal(&mut self) { -/// pr_info!("Fence signaled!\n"); -/// // Handle fence completion +/// fn on_signal(&mut self, status: Result) { +/// if status.is_ok() { +/// pr_info!("Fence signaled!\n"); +/// } else { +/// pr_err!("Fence signaled with an error!\n"); +/// } /// } /// } /// ``` @@ -316,7 +319,7 @@ pub trait FenceCallback: Send { /// An implementation likely wants to inform itself (e.g., through a work item) /// within this callback that the associated [`FenceCallbackRegistration`] /// can now be dropped. - fn on_signal(&mut self); + fn on_signal(&mut self, status: Result); } /// A callback registration on a fence. @@ -403,11 +406,17 @@ pub unsafe fn new<'a>( // embedded into a `FenceCallbackRegistration`. let reg: *mut Self = unsafe { container_of!(ptr, Self, callback_foreign) }; + // SAFETY: `reg` is a valid `Self` pointer. This here is literally an + // executing fence callback, hence the fence is signaled. Its signaled + // bit has been set with a strongly ordered atomic instruction on the + // same CPU. + let fence_result = unsafe { (*reg).fence.__status() }; + // SAFETY: `reg` is a valid `Self` pointer. // // The backend ensures synchronisation so whoever holds the registration object cannot drop // it while this code is running. See `FenceCallbackRegistration::drop`. - unsafe { (*reg).callback.on_signal() }; + unsafe { (*reg).callback.on_signal(fence_result) }; } /// Returns a reference to the fence this callback is registered on. @@ -676,8 +685,12 @@ struct DriverFenceData<'a, T: Send + Sync + FenceContextOps> { /// struct CallbackData { } /// /// impl FenceCallback for CallbackData { -/// fn on_signal(&mut self) { -/// pr_info!("DmaFence callback executed.\n"); +/// fn on_signal(&mut self, status: Result) { +/// if status.is_ok() { +/// pr_info!("DmaFence callback executed.\n"); +/// } else { +/// pr_err!("DmaFence callback executed, but fence has an error.\n"); +/// } /// } /// } /// -- 2.56.0