From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.95.84 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796231543; b=pFrARnlBzjuaquZG1H7I89NbTdlApaaXPRCoA/Z22HAFQT6EVthUm05Bz2FK7wGZhiQZ Lr/1JV/uUF53SFiGdo0OZK7cmwCV3NMkkqcetxukZIfVGh9VS+Y7GsNQDVlL2S6cTD2Az 1/07oMsSfMvx5Z0r6fbDGlEMGbRERQvIVfkwISz6+PuTYkI/UJdKDjd/q7rSZ4aUqI33K 7/FK8y2bCfVdUqHVrToZbkajykSCuK+i5T9wqIoIsp4coARRxm4nwLBnvXGr07FWBzI72 axiTy/4fsZ0FgYZy9YBEsyLLzEagoc4vCh4QkF7LIGqP9CEJqjLrwqKFI+CPq9+p1ng== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796231543; h=DMARC-Filter:DKIM-Signature:Received:Received: Content-Transfer-Encoding:Content-Type:Date:Message-Id:Cc:Subject: From:To:X-Mailer:References:In-Reply-To:X-ClientProxiedBy: MIME-Version:X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=kyKjQaE1fpMUccL15Z3cXIt4R77OSATlyAwNOUyP9zE=; b=TRO6pV75wF8TAwqRGi/K4nmdu/ILj+1cQmdFgNF4xWqNikgYLlXBKN21kJaGzqrB1huN bpZk3bsMqZ38apYGWARZc7n6LFwMWVrc8DcYySbRiLILvG8+uEUIZz1LDH1ztPeCcZA9i Nhm9Z+1F46lVukqQXbjcYZB8MGbZxDHzp2vQgoyuAoy/6siZrVOTKMP0waDt3yZS3j0R0 cxRBuCZSImO0gWGZA60sRpN6PnP1p5W4kBi/3Jhgt4Me9XCINLGi7C2bfU9gsddPJx8SN hoWDElcwrksHHc9WyTg4YrkGg7JmvaHM8p5ZAXNuGgkXc/zxsK+klk3OOrXI1l/hNFA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass header.d=garyguo.net header.i=@garyguo.net header.a=rsa-sha256 header.s=selector1 header.b=KU2PsLeB; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.95.84 Received: from LO2P265CU024.outbound.protection.outlook.com (mail-uksouthazon11021084.outbound.protection.outlook.com [52.101.95.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A930606A31A; Wed, 2 Dec 2026 17:12:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4A930606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=garyguo.net header.i=@garyguo.net header.a=rsa-sha256 header.s=selector1 header.b=KU2PsLeB ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bi6nvnp5FJQZaH8zrl2gNX31v59erNAvpAoLwvtTuZxG6W8yO9T+p/rgTz2KtUFo24f0Df4g56TqTUNvywFHXDoXh061urMiXYRYlnvVi6u7N0On8GLasGQa71etkaK/94TYQrwL22Cs+bE7xa+flNAxVmME4aZsG4EwG5ZqSNd9cyC2TCMFRt2dyv7V79J/k75c1jvYsTP5vDcm2M2A0bSAi+ztClhGCXn4rpyVsga67EJt80OaYzolbXR+sG8F+MzQ8tLl5jSocZ65tuM4WRkB8xyI7ipxoAEMbW+XHbP+5sPWCybkxU9CVMx17VdL2FBSRVmhAWLo/etw1sZirw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kyKjQaE1fpMUccL15Z3cXIt4R77OSATlyAwNOUyP9zE=; b=m5UMzhLoMlc72aFsv2sqtrgP5kIJQHxFGUyz9pxLrG/mrd/IqevzA530wNgTsfSo++A+sXwaeTX3ie8EhQpIDoP2Ca/GobFGInYXtNumOjGpfsrMFcHVg3fPGq7FEhWQzxYeltITXNmRJKqs/dyejI7GLonNG0gkdBMBqU8uPe3BS1yfyKGphVu0q0t5g8wQG3LZ4cHzUfH9JGMDWjfZ3NCJNCkTP04I9uNVfhX07nHT5JYWMlnNCRCIZQgAky91Ct52GOGUCdw2QE/RsLCjFierzfedTIYbAtBDtykPpQ/FGaxb+AM5T6BTwEAABu5Nws/cqzel3Z4gcqOz4fF8Qw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kyKjQaE1fpMUccL15Z3cXIt4R77OSATlyAwNOUyP9zE=; b=KU2PsLeBICTFnp9zCBhPxiz1IBK6nX/9R0pqNmYxUzM8W85lamckb8+JTy9bhAs0jo/2mgYARRLjyl4alkdQQxFq7J2n5aJPCf2oYrhRy/BD8ikGOPAeavBAyGjtyB6rt/LpA6FEr/oNnQNR5DHfvhSyVuvzODMk8GqyaW3MsiY= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LO0P265MB6054.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:289::10) by LO8P265MB793063.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:800::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.11; Wed, 2 Dec 2026 17:12:18 +0000 Received: from LO0P265MB6054.GBRP265.PROD.OUTLOOK.COM ([fe80::ebd6:df88:f3f2:ddb1]) by LO0P265MB6054.GBRP265.PROD.OUTLOOK.COM ([fe80::ebd6:df88:f3f2:ddb1%5]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 17:12:17 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 02 Dec 2026 17:12:16 +0000 Message-Id: Cc: , , , Subject: Re: [PATCH v3 5/9] rust: DmaFence: Replace call_rcu() with RcuState From: "Gary Guo" To: "Philipp Stanner" , "Miguel Ojeda" , "Boqun Feng" , "Gary Guo" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Benno Lossin" , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "Daniel Almeida" , "Tamir Duberstein" , "Alexandre Courbot" , =?utf-8?q?Onur_=C3=96zkan?= , "Sumit Semwal" , =?utf-8?q?Christian_K=C3=B6nig?= , "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" X-Mailer: aerc 0.22.0 References: <20261202113914.1660411-2-phasta@kernel.org> <20261202113914.1660411-7-phasta@kernel.org> In-Reply-To: <20261202113914.1660411-7-phasta@kernel.org> X-ClientProxiedBy: LO4P123CA0363.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18e::8) To LO0P265MB6054.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:289::10) X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LO0P265MB6054:EE_|LO8P265MB793063:EE_ X-MS-Office365-Filtering-Correlation-Id: 078692da-e904-42cd-200f-08df50976b19 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|7416014|1800799024|366016|23010399003|4143699003|6133799003|261009223027099003|22082099003|18002099003|3023799007|921020|56012099006|10067099003|261102123227099003|261021121427099003|261021123027099003|261022105027099003|261022075727099003|261021135927099003|261028144727099003|261026140227099003|261026121527099003; X-Microsoft-Antispam-Message-Info: FOZKvF6W6g5ytvcs5We8f0MSpxdEIIRFK163XuXfeWCw5BB+dTHymGgEfbHQgS+vE3sHyXj6ax37VkgHfX+rtLZoNXibxPPeNHP611ktCSDF2qXXG/jwq8QtchYiwSTax8NIlwmUvdgB5x44cWeK/odQybqg4d2j2mNyqB2meHPtoMZ5IHcYirED6Up7Ryh6q0kirgr+65keX/5arlyx8JbmWmC8HuN+/A8DDmlwM7oHurPqfBzaenV0XqmzKRMkvsDCqskiAjg4Mk6qjJjf9l6kshJMM97xV/q5vp+mI4PHuKpjJcHlNAHQsKPo+U4NrzZpNyhCslfAE5sg/MXOML/VqKqMmMYBcw9vYdbHQVwda/4EZ0xJAhdmxT2l6H29TH2ALDktICEdewK1F0h+lKBsZENZOx4C6ldmF7QUzsYpjfEVZ8QYVRqp6Ot757CmfS7Ab5UdKtMFHx21ioa+hKJbYezagmrvHbXKPLCIJXB3ylEEzQQHjbg3H/vCEx+nR17LZq8mAs1z4BIO4YztrbpX+M9VsfyltcRwxpnPoOWzzJs7Ughgeg2UVXTRBg3oKNTctO5C441MLO9aYbVI31SnYoO2+5xGOVZacOsEIiZvFkdEZqhAo8/E5Y1p9FZGMDwcebdUw5bWEg/f5r7KNoDsBoG9qM2zckf/Zi6DmFSBf7Vb+6sYsOPKyC+7wvyjzW0ltgnHexz9I7oG0PUOzA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LO0P265MB6054.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(376014)(7416014)(1800799024)(366016)(23010399003)(4143699003)(6133799003)(261009223027099003)(22082099003)(18002099003)(3023799007)(921020)(56012099006)(10067099003)(261102123227099003)(261021121427099003)(261021123027099003)(261022105027099003)(261022075727099003)(261021135927099003)(261028144727099003)(261026140227099003)(261026121527099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?dDU1bWgxVUF0allqOEp5Y0QvSmxXN01XMmpFU1dVelZLeGp1K1BwMjRxWjNS?= =?utf-8?B?RTZrdFkxRDNkcGFMQmhiTmJEYnpzVUF2RHBQaFhkdGJIRGRTVlFHOENZT2ds?= =?utf-8?B?NEd0aUZYaUNJNDljcG42MnF2VkN5OFg1N1NVaWsrT3h4NFFQT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XhPQzFxUzd0eG1zRlRWdlE5bzFlZVdtVWp3OXRLbHNlc1F0Uy82Ynp5VnAy?= =?utf-8?B?dnJ1SzFaRWQzSVJ6SkdNUUduYzdwaGhRN0U4TTlqV2JnR1lwdlJUZVVEelVB?= =?utf-8?B?VFgzTWtDK1oxdFZUa1BhSFhMQkY0bXNLc3RiSDlsbU1NZ0EwT21YSi9pM1RG?= =?utf-8?B?L1d0MVpLTmduQnA0cnpRZGNzQkFJVEVuVTQ5S3FDU204SmlJVTFrQ0docE1H?= =?utf-8?B?cS9Ta0ExbkNEYWcwNTZwTERQUkNhUndsSVNCRytGd3pKc1ZuRE40L3hTSEZ0?= =?utf-8?B?cGwwUUE4Q3ZZWUVQdklvTWpidzM5eFBkRXQ4ZFdFbVNuU2RUNDh3eDEvNGxQ?= =?utf-8?B?clpGaExNbFRmR3ZhMlV5UGdzZTdTcmN3UmxiSjZSd2pHYlNqODRYZz09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 078692da-e904-42cd-200f-08df50976b19 X-MS-Exchange-CrossTenant-AuthSource: LO0P265MB6054.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 17:12:17.8062 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4tgTSN4KEsHRVJWCRsEEwDHQh4TrwSEkiqv17mOVRE+z9XgyrzLjx6rVc8q2kOHMq/ixYxmVAoONtB3PqIOk8Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO8P265MB793063 On Wed Dec 2, 2026 at 11:39 AM GMT, Philipp Stanner wrote: > The C dma_fence contract demands that a fence's data disappears no > earlier than 1 RCU grace period after the DriverFence was signaled. So > far, we achieved this with dropping the DriverFence's data in a deferred > manner with a manual, raw binding call to call_rcu(). > > However, this call_rcu() does not solve one problem: It is conceivable > that some driver data must not drop in atomic context; but call_rcu()'s > payload *can* be executed in atomic context. > > Moreover, the current developments in drm::JobQueue, where a DriverFence > is always coupled 1:1 with a Job, allows for dropping job and fence > through a work item. > > We can satisfy the grace period requirement in a safe yet performant > manner through RcuState, which only waits for a grace period if the > specified grace period has not yet passed. > > We can exactly identify the right grace period by creating the RcuState > in DriverFence::signal(). > > Replace DriverFence::drop()'s call_rcu() with cond_synchronize_rcu(). > > An implication of this is that fences must for now drop in process > context until someone finds a more elegant solution. Document this > requirement. > > Adjust FenceContext's drop accordingly, replacing the rcu_barrier() with > a synchronize_rcu(). > > Suggested-by: Gary Guo > Signed-off-by: Philipp Stanner > --- > rust/kernel/dma_buf/dma_fence.rs | 132 +++++++++++++------------------ > 1 file changed, 54 insertions(+), 78 deletions(-) > > diff --git a/rust/kernel/dma_buf/dma_fence.rs b/rust/kernel/dma_buf/dma_f= ence.rs > index c04b68fe67fe..41233e9c3934 100644 > --- a/rust/kernel/dma_buf/dma_fence.rs > +++ b/rust/kernel/dma_buf/dma_fence.rs > @@ -21,6 +21,7 @@ > }; > =20 > use core::{ > + cell::UnsafeCell, > marker::PhantomData, > mem::ManuallyDrop, > ops::Deref, > @@ -42,7 +43,10 @@ > Atomic, > Relaxed, // > }, > - rcu::rcu_barrier, // > + rcu::{ > + synchronize_rcu, > + RcuState, // > + }, // > }, // > }; > =20 > @@ -58,6 +62,8 @@ pub trait FenceContextOps { > /// A dma-fence context. A fence context takes care of associating relat= ed fences > /// with each other, providing each with raising sequence numbers and a = common > /// identifier. > +/// > +/// A FenceContext must drop in non-atomic context. > #[pin_data(PinnedDrop)] > pub struct FenceContext { > /// The fence context number. > @@ -65,7 +71,7 @@ pub struct FenceContext { > /// The sequence number for the next fence created. > seqno: Atomic, > // The name parameters can be accessed by the dma_fence backend_ops.= UAF > - // errors are prevented by the `call_rcu()` in `drop_driver_fence_da= ta()`. > + // errors are prevented by `synchronize_rcu()`. > /// The name of the driver this FenceContext's fences belong to. > driver_name: CString, > /// The name of the timeline this FenceContext's fences belong to. > @@ -149,20 +155,17 @@ fn next_seqno(&self) -> u64 { > /// > /// This is needed because many times, creation of a [`DriverFence`]= must not > /// fail, and allocating might deadlock in some situations. > - /// > - /// The `data` you pass here must not perform any operations that ar= e illegal > - /// in atomic context in its [`Drop`] implementation. > pub fn new_fence_allocation( > &self, > data: T::FenceDataType, > ) -> Result> { > let fence_data =3D DriverFenceData { > - rcu_head: Default::default(), > // `inner` remains uninitialized until a `DriverFence` takes= over. > inner: Fence { > inner: Opaque::uninit(), > }, > fctx: self, > + synchronize_rcu_cookie: UnsafeCell::new(None), > data, > }; > =20 > @@ -243,15 +246,10 @@ fn drop(self: Pin<&mut Self>) { > panic!("Forgotten fences in FenceContext."); > } > =20 > - // Ensure that the driver cannot unload while there are still dm= a_fence > - // callbacks running. At the same time, the RCU barrier addresse= s the > - // problem inherited by the C backend, in which backend ops call= backs > - // might be accessing the fence while it is being signaled (or s= hortly > - // after). This could cause UAF access on the fence context's > - // `fctx.driver_name` and `fctx.timeline_name`. > - // > - // Wait for the RCU callbacks in `DriverFence::drop`. > - rcu_barrier(); > + // If a DriverFence signals without doing a synchronize_rcu(), a= nd a > + // fctx drops immediately afterwards, then backend_ops still acc= essing > + // the fctx might run into UAF if we don't wait for them here. > + synchronize_rcu(); This condition is only true for !needs_drop? I think this should be if !needs_drop::<...>() { synchronize_rcu(); } > } > } > =20 > @@ -615,12 +613,14 @@ struct DriverFenceData<'a, T: Send + Sync + FenceCo= ntextOps> { > // necessary so that the C backend can free the allocation (coming f= rom our > // Rust code) with kfree_rcu(). > inner: Fence, > - /// Callback head for dropping this in a deferred manner through RCU= . > - rcu_head: bindings::callback_head, > /// Reference to access the FenceContext. > fctx: &'a FenceContext, > - /// The API user's data. It is essential that the data only performs > - /// operations legal in atomic context in its [`Drop`] implementatio= n. > + /// A cookie that helps with reducing the number of costly calls to > + /// `synchronize_rcu()` in [`DriverFence::drop()`]. > + /// > + /// Gets set when a [`DriverFence`] signals, `None` otherwise. > + synchronize_rcu_cookie: UnsafeCell>, > + /// The API user's data. > #[pin] > data: T::FenceDataType, > } > @@ -659,6 +659,8 @@ struct DriverFenceData<'a, T: Send + Sync + FenceCont= extOps> { > /// > /// In the unlikely case of such violations, a panic is thrown. > /// > +/// A DriverFence must drop in non-atomic context. > +/// > /// # Examples > /// > /// ``` > @@ -831,7 +833,6 @@ pub fn signal(&self, res: Result) { > // must not have been signaled yet, which we check direc= tly above. > unsafe { bindings::dma_fence_set_error(fence.as_raw(), e= rr.to_errno()) }; > } > - > // SAFETY: `self.data` is valid because `self` is valid. > let fctx =3D unsafe { self.data.as_ref().fctx }; > let _ =3D fctx.nr_of_unsignaled_fences.fetch_sub(1, Relaxed)= ; > @@ -839,6 +840,11 @@ pub fn signal(&self, res: Result) { > // SAFETY: `fence` is valid because `self` is valid. The loc= k must > // be held, which we acquired above. > unsafe { bindings::dma_fence_signal_locked(fence.as_raw()) }= ; > + > + // SAFETY: `self.data` is valid because `self` is valid. > + // The lock guarantees exclusivity. > + let rcu_cookie =3D unsafe { &mut *self.data.as_ref().synchro= nize_rcu_cookie.get() }; > + *rcu_cookie =3D Some(RcuState::new()); > } > } > } > @@ -955,15 +961,15 @@ fn drop(&mut self) { > // dma_fence_is_signaled_locked() because the C backend wants to= get rid > // of the latter. > =20 > - // SAFETY: `guard` is valid until the `call_rcu()` below. > + // SAFETY: `guard` is valid. > let signaled: bool =3D unsafe { bindings::dma_fence_test_signale= d_flag(guard.as_raw()) }; > if !signaled { > pr_err!("DriverFence drops unsignaled. Danger of memory corr= uption!\n"); > - // SAFETY: `guard` is valid until the `call_rcu()` below. Th= e fence > - // must not have been signaled yet, which we check directly = above. > + // SAFETY: `guard` is valid. The fence must not have been si= gnaled > + // yet, which we check directly above. > unsafe { bindings::dma_fence_set_error(guard.as_raw(), ECANC= ELED.to_errno()) }; > - // SAFETY: `guard` is valid until the `call_rcu()` below. Th= e lock > - // must be held, which we acquired above. > + // SAFETY: `guard` is valid. The lock must be held, which we > + // acquired above. > unsafe { bindings::dma_fence_signal_locked(guard.as_raw()) }= ; > =20 > // SAFETY: `self.data` is valid because `self` is valid. > @@ -988,59 +994,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(); > + } > + > + // SAFETY: Valid because `self` is valid. RCU above ensures that= all > + // accessors are gone. > + unsafe { drop_in_place(&raw mut self.data) }; Sashiko's finding is valid here. Best, Gary > + > + // 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()) }; > } > }