Re: [PATCH v9 1/5] rust: types: Add Ownable/Owned types
From: Oliver Mangold
Date: Tue Apr 15 2025 - 02:01:21 EST
On 250409 1034, Andreas Hindborg wrote:
> Hi Oliver,
>
Hi Andreas,
> "Oliver Mangold" <oliver.mangold@xxxxx> writes:
>
> > From: Asahi Lina <lina@xxxxxxxxxxxxx>
> >
> > 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.
> >
> > Link: https://lore.kernel.org/all/20250202-rust-page-v1-1-e3170d7fe55e@xxxxxxxxxxxxx/
> > Signed-off-by: Asahi Lina <lina@xxxxxxxxxxxxx>
> > [ om:
> > - split code into separate file and `pub use` it from types.rs
> > - make from_raw() and into_raw() public
> > - fixes to documentation
> > ]
> > Signed-off-by: Oliver Mangold <oliver.mangold@xxxxx>
> > Reviewed-by: Boqun Feng <boqun.feng@xxxxxxxxx>
> > ---
> > rust/kernel/lib.rs | 1 +
> > rust/kernel/ownable.rs | 117 +++++++++++++++++++++++++++++++++++++++++++++++++
> > rust/kernel/types.rs | 2 +
> > 3 files changed, 120 insertions(+)
>
> I would suggest moving ownable.rs to rust/kernel/types/ownable.rs and
> then moving `pub mod ownable` to types.rs.
Yes, that makes more sense.
> I am not sure we need the non-null invariant here, since it is an
> invariant of `NonNull`. The rest is fine.
> I would drop 'pointer' in 'a unique `&mut T` ~pointer~' here. '`&mut T`'
> is sufficient alone.
> Like here, I think this is correct (without the pointer wording).
> This part "the underlying object is acquired" is unclear to me. How about:
>
> Callers must ensure that *ownership of* the underlying object is acquired.
Agree. I will fix these.
Best,
Oliver