rust: add Ownable trait and Owned type - #1282
Open
blktests-ci-kpd[bot] wants to merge 9 commits into
Open
blktests-ci-kpd[bot] wants to merge 9 commits into
blktests-ci-kpd[bot] wants to merge 9 commits into
Conversation
Author
|
Upstream branch: 50d05c7 |
Author
|
Upstream branch: 50d05c7 |
blktests-ci-kpd
Bot
force-pushed
the
series/1150826=>linus-master
branch
from
September 11, 2026 09:22
9d3d2b3 to
84e8c0b
Compare
Author
|
Upstream branch: 50d05c7 |
blktests-ci-kpd
Bot
force-pushed
the
series/1150826=>linus-master
branch
from
September 11, 2026 14:05
84e8c0b to
0465bfc
Compare
blktests-ci-kpd
Bot
force-pushed
the
linus-master_base
branch
from
September 12, 2026 02:26
7efd8cd to
a0aeca9
Compare
Author
|
Upstream branch: 5225b8e |
blktests-ci-kpd
Bot
force-pushed
the
series/1150826=>linus-master
branch
from
September 12, 2026 02:31
0465bfc to
3e3dd6b
Compare
blktests-ci-kpd
Bot
force-pushed
the
linus-master_base
branch
from
September 13, 2026 08:50
a0aeca9 to
772381e
Compare
Author
|
Upstream branch: 2f0c1cf |
blktests-ci-kpd
Bot
force-pushed
the
series/1150826=>linus-master
branch
from
September 13, 2026 09:42
3e3dd6b to
820cce3
Compare
blktests-ci-kpd
Bot
force-pushed
the
linus-master_base
branch
from
September 13, 2026 22:56
772381e to
0224dee
Compare
Author
|
Upstream branch: 2f0c1cf |
blktests-ci-kpd
Bot
force-pushed
the
series/1150826=>linus-master
branch
from
September 13, 2026 23:02
820cce3 to
c152528
Compare
blktests-ci-kpd
Bot
force-pushed
the
linus-master_base
branch
from
September 15, 2026 09:28
0224dee to
f14340f
Compare
Add a method to consume a `Box<T, A>` and return a `NonNull<T>`. This is a convenience wrapper around `Self::into_raw` for callers that need a `NonNull` pointer rather than a raw pointer. Assisted-by: LLM Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Gary Guo <gary@garyguo.net>
By analogy to `AlwaysRefCounted` and `ARef`, an `Ownable` type is a (typically C FFI) type that *may* be owned by Rust, but need not be. Unlike `AlwaysRefCounted`, this mechanism expects the reference to be unique within Rust, and does not allow cloning. Conceptually, this is similar to a `KBox<T>`, except that it delegates resource management to the `T` instead of using a generic allocator. [ om: - Split code into separate file and `pub use` it from types.rs. - Make from_raw() and into_raw() public. - Remove OwnableMut, and make DerefMut dependent on Unpin instead. - Usage example/doctest for Ownable/Owned. - Fixes to documentation and commit message. ] Link: https://lore.kernel.org/all/20250202-rust-page-v1-1-e3170d7fe55e@asahilina.net/ Signed-off-by: Asahi Lina <lina+kernel@asahilina.net> Co-developed-by: Oliver Mangold <oliver.mangold@pm.me> Signed-off-by: Oliver Mangold <oliver.mangold@pm.me> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alice Ryhl <aliceryhl@google.com> [ Andreas: Updated documentation, examples, and formatting. Change safety requirements, safety comments. ] Assisted-by: LLM Co-developed-by: Andreas Hindborg <a.hindborg@kernel.org> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
Implement `ForeignOwnable` for `Owned<T>`. This allows use of `Owned<T>` in places such as the `XArray`. Note that `T` does not need to implement `ForeignOwnable` for `Owned<T>` to implement `ForeignOwnable`. Assisted-by: LLM Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
There are types where it may both be reference counted in some cases and owned in others. In such cases, obtaining `ARef<T>` from `&T` would be unsound as it allows creation of `ARef<T>` copy from `&Owned<T>`. Therefore, we split `AlwaysRefCounted` into `RefCounted` (which `ARef<T>` would require) and a marker trait to indicate that the type is always reference counted (and not `Ownable`) so the `&T` -> `ARef<T>` conversion is possible. - Rename `AlwaysRefCounted` to `RefCounted`. - Add a new unsafe trait `AlwaysRefCounted`. - Implement the new trait `AlwaysRefCounted` for the newly renamed `RefCounted` implementations. This leaves functionality of existing implementers of `AlwaysRefCounted` intact. Suggested-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Signed-off-by: Oliver Mangold <oliver.mangold@pm.me> [ Andreas: Updated commit message and rebase on rust-next (7.2) ] Acked-by: Igor Korotin <igor.korotin.linux@gmail.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Reviewed-by: Gary Guo <gary@garyguo.net> Assisted-by: LLM Co-developed-by: Andreas Hindborg <a.hindborg@kernel.org> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
SAFETY comment in rustdoc example was just 'TODO'. Fixed. Link: Rust-for-Linux/linux#351 Signed-off-by: Oliver Mangold <oliver.mangold@pm.me> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Assisted-by: LLM Co-developed-by: Andreas Hindborg <a.hindborg@kernel.org> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Types implementing one of these traits can safely convert between an `ARef<T>` and an `Owned<T>`. This is useful for types which generally are accessed through an `ARef` but have methods which can only safely be called when the reference is unique, like e.g. `block::mq::Request::end_ok()`. Signed-off-by: Oliver Mangold <oliver.mangold@pm.me> [ Andreas: Fix formatting, update documentation, fix error handling in examples. ] Assisted-by: LLM Co-developed-by: Andreas Hindborg <a.hindborg@kernel.org> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
`struct page` is managed by a native reference count, and kernel C code routinely takes its own references to pages, for example when a page is inserted into a VMA with `vm_insert_page()`. Thus, implement `RefCounted` for `Page`, backed by `get_page()` and `put_page()`, mark it `AlwaysRefCounted`, and return `ARef<Page>` from `Page::alloc_page()`. The page is freed when the last reference to it is dropped; for the order-0 pages allocated here, this is equivalent to `__free_pages()`. This also allows `Page` references to be returned as borrowed references without owning the `struct page`. Remove `BorrowedPage` and update users to use `&Page` and `ARef<Page>`. Assisted-by: LLM Suggested-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Add a method to `Page` that allows construction of an instance from `struct page` pointer. Assisted-by: LLM Signed-off-by: Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by: Onur Özkan <work@onurozkan.dev>
`ExclusivePage` wraps a regular page but adds an invariant that the page data area does not incur data races. This means `ExclusivePage` cannot be mapped to user space or shared with devices, and it becomes simpler to directly reference the contents of the page. Since `Page` implements `AlwaysRefCounted`, handing out a `&Page` from an `ExclusivePage` would allow safe code to obtain an `ARef<Page>` to the page and break the aliasing invariant of `ExclusivePage`. Thus, do not implement `Deref<Target = Page>` for `ExclusivePage`. Assisted-by: LLM Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
Author
|
Upstream branch: 5878583 |
blktests-ci-kpd
Bot
force-pushed
the
series/1150826=>linus-master
branch
from
September 15, 2026 09:36
c152528 to
5c7b4c1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request for series with
subject: rust: add
Ownabletrait andOwnedtypeversion: 21
url: https://patchwork.kernel.org/series/1161895/