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 11873606A31A for ; Wed, 2 Dec 2026 11:49:26 +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=K6u/nvog Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 715BF10E347; Wed, 2 Dec 2026 11:49:20 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E81710E347 for ; Wed, 2 Dec 2026 11:49:14 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 3B27F60E0A; Wed, 2 Dec 2026 11:49:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B83431F000C1; Wed, 2 Dec 2026 11:49:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796212152; bh=vQKJ3mdr7IDimPrimmoTajXX/8er0QlmBsBvrm+YHeQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=K6u/nvog1oi6NiwaN/Atp7PKeKA3U9lcjQFSxUsRsz/LkwhwACD7eLP55vbKFkXLI mbZNtxNYYR+ZYDMgFEng7p4KlTBK597IQTiMCR4MDeAVSCe1IV5FJCkoSu381He1MS PkbRq4ywlebNc7O4rZkxIDKH5DqlISMpHXcYLxuxcPBbyYOUdaq0a765PYf84xpKB5 jSbGnqnWyfczxCeRxafu57k2RC4ckKoJJ7zL9rhMRI5dbXoH0lFc/Qkt29au6Y1m1m +JTLcvq76mdzWu8Q44IQy7o7+8D8V0ggerMCwxFjCGU4byNKujCDrSccUz5qdwJ/7I CmX3s7I/Xfn1A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 5/9] rust: DmaFence: Replace call_rcu() with RcuState To: "Philipp Stanner" Cc: dri-devel@lists.freedesktop.org, media-ci@linuxtv.org, ojeda@kernel.org, gary@garyguo.net In-Reply-To: <20261202113914.1660411-7-phasta@kernel.org> References: <20261202113914.1660411-2-phasta@kernel.org> <20261202113914.1660411-7-phasta@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 11:49:12 +0000 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: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 X-Archived-By: Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] rust: dma_fence: T::FenceDataType leak in DriverFence::drop() -- commit 531a4c5c61c9c35b5cea6f9028e63b8c4f574fa8 Author: Philipp Stanner rust: DmaFence: Replace call_rcu() with RcuState This commit replaces the deferred call_rcu() callback in DriverFence::drop() with RcuState::cond_synchronize() and synchronize_rcu() so that driver fence data is dropped synchronously in process context. > diff --git a/rust/kernel/dma_buf/dma_fence.rs b/rust/kernel/dma_buf/dma_f= ence.rs > index faeed63ffeab8..f3889994e69d3 100644 > --- a/rust/kernel/dma_buf/dma_fence.rs > +++ b/rust/kernel/dma_buf/dma_fence.rs [ ... ] > @@ -980,59 +986,29 @@ fn drop(&mut self) { > return; > } > =20 > - // SAFETY: Valid because `self` is valid. > - let rcu_head_ptr =3D unsafe { &raw mut (*self.data.as_ptr()).rcu= _head }; > + // SAFETY: `self` is valid. > + let data =3D unsafe { self.data.as_ref() }; > + // SAFETY: Access is exclusive because we are dropping. > + let rcu_cookie =3D unsafe { &mut *data.synchronize_rcu_cookie.ge= t() }; > =20 > - // SAFETY: `call_rcu()` is always safe to be called. `rcu_head_p= tr` was > - // created validly above. The module must perform a `synchronize= _rcu()` > - // or `rcu_barrier()` call to guard against module unload. > - unsafe { bindings::call_rcu(rcu_head_ptr, Some(drop_driver_fence= _data::)) }; > - } > -} > + // Make sure none of the fence backend_ops can access fence-data= anymore. > + // > + // TODO: > + // This would not be necessary if the C dma_fence backend were u= sing a > + // spinlock to properly synchronize its signaled state. Fix it i= n C and > + // then remove synchronize_rcu(). > + if let Some(cookie) =3D rcu_cookie { > + cookie.cond_synchronize(); > + } else { > + synchronize_rcu(); > + } > =20 > -// TODO: > -// The entire call_rcu() mechanism in the drop above and the code below = would be > -// unnecessary if C's dma_fence_signal() could be reworked in a way that= after it > -// ran, the caller knows that no fence_ops callbacks can be running anym= ore. > -// In other words, if the dma_fence backend would use its spinlock for f= ull > -// synchronization. > -// > -// Then we could move the drop_in_place() and dma_fence_put() upwards in= to the > -// drop() implementation and call it a day. > + // SAFETY: Valid because `self` is valid. RCU above ensures that= all > + // accessors are gone. > + unsafe { drop_in_place(&raw mut self.data) }; > =20 > -/// Finally really drop this `DriverFence` > -/// > -/// # Safety > -/// > -/// `head` references the `rcu_head` field of an `DriverFenceData`. A= ll > -/// accessors to that `DriverFenceData` must be gone by now. This mus= t be > -/// ensured by signalling the associated `DriverFence` and then waiti= ng > -/// for a grace period until calling this function here. > -unsafe extern "C" fn drop_driver_fence_data( > - head: *mut bindings::callback_head, > -) { > - // SAFETY: Caller provides a pointer to the `rcu_head` field of a `D= riverFenceData`. > - let fence_data =3D unsafe { container_of!(head, DriverFenceData<'_, = T>, rcu_head) }; > - > - // SAFETY: `fence_data` was created validly above. All the fence's d= ata will > - // only drop below, but the raw pointer to the raw C `dma_fence` rem= ains > - // valid because the reference count is only decremented at the end = of the > - // function. > - let fence =3D unsafe { (*fence_data).inner.inner.get() }; > - > - // SAFETY: `fence_data` was created validly above. The user has alre= ady > - // dropped the only conventional accessor to the user data, the `Dri= verFence`, > - // one grace period ago. All accessors are gone now. > - unsafe { drop_in_place(&raw mut (*fence_data).data) }; > - > - // The inner `Fence` explicitly does not get dropped because there m= ay be > - // many more users / consumers, each holding their own reference. > - > - // SAFETY: Once a `DriverFence` is initialized, the inner `fence` is= valid > - // and initialized. It is valid until the refcount drops to 0, which= can > - // earliest happen once we drop the `DriverFence`'s reference here. > - unsafe { bindings::dma_fence_put(fence) }; > - > - // The actual memory the data associated with a `DriverFence` lives = in > - // gets freed by the C dma_fence backend once the fence's refcount r= eaches 0. > + // SAFETY: Valid because `self` is valid. This is the initial re= ference > + // from when this `DriverFence` was created. > + unsafe { bindings::dma_fence_put(self.as_raw()) }; > + } > } [Severity: High] Does drop_in_place(&raw mut self.data) leak the inner T::FenceDataType payload? self.data on DriverFence is a NonNull>, which has no Drop implementation, so drop_in_place(&raw mut self.data) is a no-op and (*self.data.as_ptr()).data is never dropped before dma_fence_put() frees the allocation. Also, once drop_in_place(&raw mut (*self.data.as_ptr()).data) is used, self.as_raw() should be cached before dropping the payload so it does not create a shared reference &DriverFenceData<'a, T> after the data field has been dropped in place. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202113914.1660= 411-2-phasta@kernel.org?part=3D5