Skip to contentSkip to conversation

rust: block: implement `Send` and `Sync` for `TagSet`

PATCH Applied Andreas Hindborg 4 participants 4 messages Sep 30 – Oct 1

Subsystems (3)
lore
Share & tools
lore

Andreas Hindborg

author maintainer
#0 lore raw

PATCH 1/1 rust: block: implement `Send` and `Sync` for `TagSet`

TagSet never implemented Send or Sync. This did not matter until commit "rust: block: fix Send bound for GenDisk" made GenDisk: Send depend on Arc<TagSet<T>>: Send, which in turn requires TagSet<T>: Send + Sync. With that bound unsatisfiable, GenDisk is never Send, and the rnull driver fails to build once configfs requires `GroupOperations::Child:
Send`.

TagSet owns no data typed by T. It only wraps the C struct blk_mq_tag_set, which can be dropped from any thread by calling blk_mq_free_tag_set. Thus, implement Send and Sync for TagSet unconditionally.

---
Hi Jens,

Please pick this patch to resolve a problematic rust configfs/block interaction in linux-next [1].

Best regards,
Andreas Hindborg

[1] https://lore.kernel.org/r/[email protected]

---
 rust/kernel/block/mq/tag_set.rs | 7 +++++++
 1 file changed, 7 insertions(+)
rust/kernel/block/mq/tag_set.rs +7 -0
index dae9df408a86..00d29688f920 100644
@@ -83,3 +83,10 @@ fn drop(self: Pin<&mut Self>) {
         unsafe { bindings::blk_mq_free_tag_set(self.inner.get()) };
     }
 }
+
+// SAFETY: It is safe to transfer ownership of `TagSet` between threads.
+unsafe impl<T: Operations> Send for TagSet<T> {}
+
+// SAFETY: It is safe to share `&TagSet` across threads. `TagSet` exposes no
+// `&self` methods that mutate the contained `blk_mq_tag_set`.
+unsafe impl<T: Operations> Sync for TagSet<T> {}

---
base-commit: df2908090cda368b01ff43709f51890076c56157
change-id: 20260930-tag-set-send-sync-c4d64515e1e0

Best regards,

Signature · 1 line
Andreas Hindborg <[email protected]>
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Andreas Hindborg

TagSet never implemented Send or Sync. This did not matter until commit "rust: block: fix Send bound for GenDisk" made GenDisk: Send depend on Arc<TagSet<T>>: Send, which in turn requires TagSet<T>: Send + Sync. With that bound unsatisfiable, GenDisk is never Send, and the rnull driver fails to build once configfs requires `GroupOperations::Child:
Send`.

TagSet owns no data typed by T. It only wraps the C struct blk_mq_tag_set, which can be dropped from any thread by calling blk_mq_free_tag_set. Thus, implement Send and Sync for TagSet unconditionally.

Quoted 4 lines
Tested-by on v1 1/1
#2 lore raw
In reply to Andreas Hindborg
Quoted 7 lines · Andreas Hindborg

TagSet never implemented Send or Sync. This did not matter until commit "rust: block: fix Send bound for GenDisk" made GenDisk: Send depend on Arc<TagSet<T>>: Send, which in turn requires TagSet<T>: Send + Sync. With that bound unsatisfiable, GenDisk is never Send, and the rnull driver fails to build once configfs requires `GroupOperations::Child:
Send`.

Quoted 7 lines

TagSet owns no data typed by T. It only wraps the C struct blk_mq_tag_set, which can be dropped from any thread by calling blk_mq_free_tag_set. Thus, implement Send and Sync for TagSet unconditionally.

Thx, this fixes is for me! Just in case anyone cares:

Ciao, Thorsten

maintainer Applied
#3 lore raw
In reply to Andreas Hindborg
Quoted 8 lines · Andreas Hindborg

TagSet never implemented Send or Sync. This did not matter until commit "rust: block: fix Send bound for GenDisk" made GenDisk: Send depend on Arc<TagSet<T>>: Send, which in turn requires TagSet<T>: Send + Sync. With that bound unsatisfiable, GenDisk is never Send, and the rnull driver fails to build once configfs requires `GroupOperations::Child:
Send`.

[...]

Applied, thanks!

[1/1] rust: block: implement Send and Sync for TagSet

      commit: 06dad60393f20985cc5f24eeed63f965d366c4a0

Best regards,

Signature · 1 line
Jens Axboe