From: Danilo Krummrich Date: Mon, 24 Mar 2025 17:40:48 +0000 (+0100) Subject: rust: dma: add `Send` implementation for `CoherentAllocation` X-Git-Tag: v6.15-rc1~93^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=28bb48c4cb34f65a9aa602142e76e1426da31293;p=thirdparty%2Fkernel%2Flinux.git rust: dma: add `Send` implementation for `CoherentAllocation` Stephen found a future build failure in linux-next [1]: error[E0277]: `*mut MyStruct` cannot be sent between threads safely --> samples/rust/rust_dma.rs:47:22 | 47 | impl pci::Driver for DmaSampleDriver { | ^^^^^^^^^^^^^^^ `*mut MyStruct` cannot be sent between threads safely It is caused by the interaction between commit 935e1d90bf6f ("rust: pci: require Send for Driver trait implementers") from the driver-core tree, which fixes a missing concurrency requirement, and commit 9901addae63b ("samples: rust: add Rust dma test sample driver") which adds a sample that does not satisfy that requirement. Add a `Send` implementation to `CoherentAllocation`, which allows the sample (and other future users) to satisfy it. Reported-by: Stephen Rothwell Closes: https://lore.kernel.org/linux-next/20250324215702.1515ba92@canb.auug.org.au/ [1] Signed-off-by: Danilo Krummrich Reviewed-by: Boqun Feng Link: https://lore.kernel.org/r/20250324174048.1075597-1-ojeda@kernel.org [ Added number to Closes. Fix typo spotted by Boqun. - Miguel ] Signed-off-by: Miguel Ojeda --- diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs index 9d00f9c49f47e..8cdc76043ee77 100644 --- a/rust/kernel/dma.rs +++ b/rust/kernel/dma.rs @@ -301,6 +301,10 @@ impl Drop for CoherentAllocation { } } +// SAFETY: It is safe to send a `CoherentAllocation` to another thread if `T` +// can be sent to another thread. +unsafe impl Send for CoherentAllocation {} + /// Reads a field of an item from an allocated region of structs. /// /// # Examples