4 Commits
Author SHA1 Message Date
Gary Guo 8d49d90fb9 rust: make build_assert module the home of related macros
Given the macro scoping rules, all macros are rendered twice, in the
module and in the top-level of kernel crate.

Add `#[doc(hidden)]` to the macro definition and `#[doc(inline)]` to the
re-export inside `build_assert` module so the top-level items are hidden.

[ Sadly, because the definition is hidden, `rustdoc` decides to not list
  them as re-exports in the `prelude` page anymore, even if we refer to
  the not-actually-hidden item.

    - Miguel ]

Acked-by: Danilo Krummrich <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Acked-by: Alexandre Courbot <[email protected]>
Acked-by: FUJITA Tomonori <[email protected]>
Acked-by: Boqun Feng <[email protected]>
Signed-off-by: Gary Guo <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Kept a single declaration in the prelude, and reworded since they
  already had `no_inline`. Removed other imports from `predefine` since
  we now use the prelude. - Miguel ]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-06-10 09:07:13 +02:00
Alexandre Courbot d6ff6e8700 rust: sync: refcount: always inline functions using build_assert with arguments
`build_assert` relies on the compiler to optimize out its error path.
Functions using it with its arguments must thus always be inlined,
otherwise the error path of `build_assert` might not be optimized out,
triggering a build error.

Cc: [email protected]
Fixes: bb38f35b35 ("rust: implement `kernel::sync::Refcount`")
Reviewed-by: Daniel Almeida <[email protected]>
Signed-off-by: Alexandre Courbot <[email protected]>
Acked-by: Boqun Feng <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Miguel Ojeda <[email protected]>
2026-01-18 20:40:12 +01:00
Gary Guo a307bf1db5 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 <[email protected]>
Signed-off-by: Boqun Feng <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Benno Lossin <[email protected]>
Reviewed-by: Elle Rhumsaa <[email protected]>
Acked-by: Andreas Hindborg <[email protected]>
Tested-by: David Gow <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
2025-09-15 09:38:36 +02:00
Gary Guo bb38f35b35 rust: implement kernel::sync::Refcount
This is a wrapping layer of `include/linux/refcount.h`. Currently the
kernel refcount has already been used in `Arc`, however it calls into
FFI directly.

[boqun: Add the missing <> for the link in comment]
Signed-off-by: Gary Guo <[email protected]>
Signed-off-by: Boqun Feng <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Boqun Feng <[email protected]>
Reviewed-by: Fiona Behrens <[email protected]>
Reviewed-by: Benno Lossin <[email protected]>
Reviewed-by: Elle Rhumsaa <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
2025-09-15 09:38:35 +02:00