block: rust: fix `Send` bound for `GenDisk`
Subsystems (3)
PATCH 1/1 block: rust: fix `Send` bound for `GenDisk`
From: Andreas Hindborg <[email protected]>
The Send implementation for GenDisk<T> was conditioned on T: Send. This constrains the wrong type. T is the Operations implementation, which is typically a zero-sized marker type that carries no data, so `T:
Send says nothing about whether the data a GenDisk` actually owns can be moved to another thread.
A GenDisk<T> owns the queue data T::QueueData (stored as the gendisk's queuedata and dropped when the GenDisk is dropped) and an Arc<TagSet<T>>. These are the values transferred when a GenDisk is sent across a thread boundary, so the Send bound must constrain exactly them. Bound T::QueueData: Send and Arc<TagSet<T>>: Send instead.
Links: https://lore.kernel.org/all/[email protected]
---
Changes in v4:
Following Miguel’s suggestion, I am resending Andreas’ v2 patch, but with Priya’s and Dylan’s Reported-by tags added.
I noticed that this patch has not been merged yet, and I am not sure what its current status is.
Link to v3:
- https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Add Priya and Dylan's names to the Reported-by tags
Link to v2:
- https://lore.kernel.org/all/[email protected]/
Link to v1:
- https://lore.kernel.org/all/[email protected]/
I am a bit unsure how to handle this v3.
rust/kernel/block/mq/gen_disk.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
rust/kernel/block/mq/gen_disk.rs +8 -2
@@ -212,8 +212,14 @@ pub struct GenDisk<T: Operations> { }// SAFETY: `GenDisk` is an owned pointer to a `struct gendisk` and an `Arc` to a -// `TagSet` It is safe to send this to other threads as long as T is Send. -unsafe impl <T :Operations +Send >Send for GenDisk <T > {} +// `TagSet`. It is safe to send this to other threads as long as these two are `Send`. +unsafe impl <T >Send for GenDisk <T > +where +T :Operations , +T ::QueueData :Send , +Arc <TagSet <T >>:Send , +{ +}impl <T :Operations >Drop for GenDisk <T > {fn drop (&mut self) {
Signature · 1 line
2.43.2
Quoted 3 lines · Yuan Tan
I noticed that this patch has not been merged yet, and I am not sure what its current status is.
Nit: this patch wasn't tagged as v4, so that may be confusing.
Cheers,
Miguel