rust: block: convert `block::mq` to use `Refcount`
authorGary Guo <gary@garyguo.net>
Fri, 5 Sep 2025 04:41:40 +0000 (21:41 -0700)
committerPeter Zijlstra <peterz@infradead.org>
Mon, 15 Sep 2025 07:38:36 +0000 (09:38 +0200)
commita307bf1db5448eccd72a1d7857f7661c6330d5ad
tree13ad271e34c14d904a78cc0f425c54dff934fec9
parent076acb647c1f448177d8b3b0e4f33de959713d7d
rust: block: convert `block::mq` to use `Refcount`

Currently there's a custom reference counting in `block::mq`, which uses
`AtomicU64` Rust atomics, and this type doesn't exist on some 32-bit
architectures. We cannot just change it to use 32-bit atomics, because
doing so will make it vulnerable to refcount overflow. So switch it to
use the kernel refcount `kernel::sync::Refcount` instead.

There is an operation needed by `block::mq`, atomically decreasing
refcount from 2 to 0, which is not available through refcount.h, so
I exposed `Refcount::as_atomic` which allows accessing the refcount
directly.

[boqun: Adopt the LKMM atomic API]
Signed-off-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev>
Acked-by: Andreas Hindborg <a.hindborg@kernel.org>
Tested-by: David Gow <davidgow@google.com>
Link: https://lore.kernel.org/r/20250723233312.3304339-5-gary@kernel.org
rust/kernel/block/mq/operations.rs
rust/kernel/block/mq/request.rs
rust/kernel/sync/refcount.rs