public inbox for linux-next@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: dma: add `Send` implementation for `CoherentAllocation`
@ 2025-03-24 17:40 Miguel Ojeda
  2025-03-24 17:43 ` Miguel Ojeda
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Miguel Ojeda @ 2025-03-24 17:40 UTC (permalink / raw)
  To: Abdiel Janulgue, Danilo Krummrich, Miguel Ojeda, Alex Gaynor,
	Greg Kroah-Hartman, Stephen Rothwell
  Cc: Daniel Almeida, Robin Murphy, Andreas Hindborg, rust-for-linux,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Alice Ryhl, Trevor Gross, Rafael J. Wysocki, linux-next,
	linux-kernel, patches

From: Danilo Krummrich <dakr@kernel.org>

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 <sfr@canb.auug.org.au>
Closes: https://lore.kernel.org/linux-next/20250324215702.1515ba92@canb.auug.org.au/
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
 rust/kernel/dma.rs | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
index 9d00f9c49f47..18de693c4924 100644
--- a/rust/kernel/dma.rs
+++ b/rust/kernel/dma.rs
@@ -301,6 +301,10 @@ fn drop(&mut self) {
     }
 }
 
+// SAFETY: It is safe to send a `CoherentAllocation` to another thread if `T`
+// can be send to another thread.
+unsafe impl<T: AsBytes + FromBytes + Send> Send for CoherentAllocation<T> {}
+
 /// Reads a field of an item from an allocated region of structs.
 ///
 /// # Examples
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-03-24 22:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-24 17:40 [PATCH] rust: dma: add `Send` implementation for `CoherentAllocation` Miguel Ojeda
2025-03-24 17:43 ` Miguel Ojeda
2025-03-24 18:00 ` Boqun Feng
2025-03-24 22:36 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox