Skip to content

implement `kernel::sync::Refcount` and convert users

Gary Guo linux-block lkml rust-for-linux 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest5 patches 13 repliesIn review
  2. v45 patches 4 repliesSuperseded

Changes in v5 from the cover letter

- Forbid using Refcount::new() with already-saturated initial value. (Refcount::set can still set value to the saturated range, as
users may want to set it to a runtime value that the compiler cannot
easily determine to be non-negative).
- Moved a documentation comment from one commit to another following
Benno's suggestion
- Link to v4: https://lore.kernel.org/rust-for-linux/[email protected]/

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5rust: implement `kernel::sync::Refcount`rust/helpers/refcount.c rust/kernel/sync.rs rust/kernel/sync/refcount.rs+110 -04 replies
2/5rust: make `Arc::into_unique_or_drop` associated functionrust/kernel/sync/arc.rs+6 -61 reply
3/5rust: convert `Arc` to use `Refcount`rust/kernel/sync/arc.rs+14 -312 replies
4/5rust: block: convert `block::mq` to use `Refcount`rust/kernel/block/mq/operations.rs rust/kernel/block/mq/request.rs rust/kernel/sync/refcount.rs+34 -506 replies
5/5MAINTAINERS: update atomic infrastructure entry to include RustMAINTAINERS+2 -00 replies

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by.

PatchAlice RyhlBoqun FengFiona BehrensBenno LossinDavid GowAndreas HindborgAlexandre Courbot
1/5R-b R-b R-b R-b
2/5R-b R-b
3/5R-b R-b
4/5R-b T-b A-b
5/5A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 7 reviewers.

Read the v5 thread

Cover letter [PATCH v5 0/5] implement `kernel::sync::Refcount` and convert users

From: Gary Guo <[email protected]>

Currently there're two refcount usage in rust/, Arc and block::mq. Arc uses refcount_t with FFI calls directly, and block::mq use Rust atomics and custom refcounting.

This series consolidate them to have a single Refcount which wraps refcount_t and have it used by both.

With the removal of Rust AtomicU64 this would also make the code work for 32-bit systems. See [1] as a previous attempt to fix this issue.

Changes in v5:
- Forbid using Refcount::new() with already-saturated initial value. (Refcount::set can still set value to the saturated range, as
users may want to set it to a runtime value that the compiler cannot
easily determine to be non-negative).
- Moved a documentation comment from one commit to another following
Benno's suggestion
- Link to v4: https://lore.kernel.org/rust-for-linux/[email protected]/

Changes in v4:
- Move justification on why &Refcount is okay when used for reference
coutning into the Refcount::dec_and_test documentation comment.
- Split Arc::into_unique_or_drop signature change into another patch.
- Wording/comment changes
- Link to v3: https://lore.kernel.org/rust-for-linux/[email protected]/

Changes in v3:
- Drop dec_not_one and revert to dec_and_test/set as the former
lacks acquire semantics.
- Move a use statement from patch 1 to correct place (patch 3).
- Update maintainer entry to include refcount.rs and add myself as a
reviewer, as suggested by Boqun.
- Link to v2: https://lore.kernel.org/rust-for-linux/[email protected]

Changes in v2:
- Refcount::read method is dropped
- Refcount::dec_not_one method is added and Arc::into_unique_or_drop
is converted to use it.
- Link to v1: https://lore.kernel.org/rust-for-linux/[email protected]

Gary Guo (5):
rust: implement kernel::sync::Refcount
rust: make Arc::into_unique_or_drop associated function
rust: convert Arc to use Refcount
rust: block: convert block::mq to use Refcount
MAINTAINERS: update atomic infrastructure entry to include Rust

 MAINTAINERS                        |   2 +
 rust/helpers/refcount.c            |  10 +++
 rust/kernel/block/mq/operations.rs |   7 +-
 rust/kernel/block/mq/request.rs    |  63 +++++-----------
 rust/kernel/sync.rs                |   2 +
 rust/kernel/sync/arc.rs            |  55 +++++---------
 rust/kernel/sync/refcount.rs       | 112 +++++++++++++++++++++++++++++
 7 files changed, 165 insertions(+), 86 deletions(-)
 create mode 100644 rust/kernel/sync/refcount.rs

base-commit: cc84ef3b88f407e8bd5a5f7b6906d1e69851c856

Signature · 1 line
2.49.0