rust: block: implement `Send` and `Sync` for `TagSet`
Subsystems (3)
Andreas Hindborg
maintainerPATCH 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
@@ -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]>
Quoted 13 lines · Andreas Hindborg
TagSetnever implementedSendorSync. This did not matter until commit "rust: block: fixSendbound forGenDisk" madeGenDisk: Senddepend onArc<TagSet<T>>: Send, which in turn requiresTagSet<T>: Send + Sync. With that bound unsatisfiable,GenDiskis neverSend, and the rnull driver fails to build once configfs requires `GroupOperations::Child:
Send`.
TagSetowns no data typed byT. It only wraps the Cstruct blk_mq_tag_set, which can be dropped from any thread by callingblk_mq_free_tag_set. Thus, implementSendandSyncforTagSetunconditionally.
Quoted 4 lines
Reported-by Thorsten Leemhuis <[email protected]>Suggested-by Gary Guo <[email protected]>Signed-off-by Andreas Hindborg <[email protected]>
Quoted 7 lines · Andreas Hindborg
TagSetnever implementedSendorSync. This did not matter until commit "rust: block: fixSendbound forGenDisk" madeGenDisk: Senddepend onArc<TagSet<T>>: Send, which in turn requiresTagSet<T>: Send + Sync. With that bound unsatisfiable,GenDiskis neverSend, and the rnull driver fails to build once configfs requires `GroupOperations::Child:
Send`.
Quoted 7 lines
TagSetowns no data typed byT. It only wraps the Cstruct blk_mq_tag_set, which can be dropped from any thread by callingblk_mq_free_tag_set. Thus, implementSendandSyncforTagSetunconditionally.
Thx, this fixes is for me! Just in case anyone cares:
Ciao, Thorsten
Quoted 8 lines · Andreas Hindborg
TagSetnever implementedSendorSync. This did not matter until commit "rust: block: fixSendbound forGenDisk" madeGenDisk: Senddepend onArc<TagSet<T>>: Send, which in turn requiresTagSet<T>: Send + Sync. With that bound unsatisfiable,GenDiskis neverSend, 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