Skip to contentSkip to conversation

block: rust: fix `Send` bound for `GenDisk`

PATCH In review Yuan Tan 2 participants 2 messages Jun 11

Subsystems (3)
lore
Share & tools
lore

Yuan Tan

author
#0 lore raw

PATCH v3 1/1 block: rust: fix `Send` bound for `GenDisk`

From: Yuan Tan <[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.

Fixes 3253aba3408a ("rust: block: introduce `kernel::block::mq` module")

---

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.

The change in this v3 is adding the missing trailers. Andreas' v2 already addresses the TagSet issue from my v1, and his commit message is also more appropriate. Therefore this v3 has no changes other than the trailers.

I am not sure whether it is appropriate for me to take Andreas' patch and only adjust the trailers. Please correct me, and my apologies if this is not the right way to handle it.

 rust/kernel/block/mq/gen_disk.rs | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
rust/kernel/block/mq/gen_disk.rs +8 -2
index 912cb805caf5..b36d24382cc3 100644
@@ -199,8 +199,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
#1 lore raw
Quoted 4 lines · Yuan Tan

I am not sure whether it is appropriate for me to take Andreas' patch and only adjust the trailers. Please correct me, and my apologies if this is not the right way to handle it.

It is OK to re-send a patch from someone else, but you need to make sure you give the proper attribution etc.

In particular, you should keep the authorship from Andreas if he was the author of the actual fix (though it sounds like Andreas is OK with you as author due to v1 (?)), and you should also keep the existing Signed-off-by (again, assuming you were actually picking his patch, which I don't know if it is the case here), adding your own afterwards because you carried the patch. And if you make any changes to the patch, you are supposed to mention that too, inside square brackets, etc.

Furthermore, if you reported the issue but you are not the author, then you should use Reported-by for yourself too (even if you have a Signed-off-by because you are re-sending his patch). Either way, a Link tag to the original report would be nice if one is available.

In addition, the Fixes tag means there should likely be a Cc: stable tag too, given the hash covers other stable releases, unless it shouldn't be backported (in which case, it should be justified).

The document that explains these tags etc. is at:

https://docs.kernel.org/process/submitting-patches.html

I hope that helps!

Cheers,
Miguel