From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B9C4274FF2 for ; Tue, 15 Apr 2025 06:01:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.22 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744696870; cv=none; b=LIFO6pMZBWQSdGXftpu34iT17TpZGCZzEshJTkgPARPDrZGbwwGL4xXcgQi1uJD19gOFoWqgaoPsPhXNToa7HgiuQWMSVzKrAgFNH8SLtJQdqdyVkCjtZ8GgoHWBAyr0Z+BAOOasYJI5RsP+IhWr3HKqdF4NAtp7aLkRePFCV4I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744696870; c=relaxed/simple; bh=cykvFx/xC2kpSzHqvr0f2oMiL42N47IdnmcTJIwr6Wk=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Rg8pobwC8hGQXzPN5ITLJxVQJHA/6Qb2UYjst9nLnugU76LuxngqC92abYB3p1rCgr0hhsR0GIwpzlnEHEx1kJQvhV1mzSQa5V3I+Yl2Cc6LysRUXvF5tt3V40KQUIeRq8Mfd/ys8NzVnuVg8GReQm5j1kqMG3XeKQB4zQzbrBY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=BDUQnEXy; arc=none smtp.client-ip=185.70.43.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="BDUQnEXy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1744696865; x=1744956065; bh=rB8xDnp69TZWlNpoP1ytFmrKVrG4ZdU0O7ge3EeWJ+E=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=BDUQnEXy5Z5yGNZQWDFPWOqeVbe/b69KK+BjNDsTTnGN/did2vlN9wFMid3yAgzH0 HcFowrPa/jCHEnfaREiYoz96yZ9xzQpAagxR+6Ob143mjTuyiS6bS0e4DvVl8spyr+ hoPPjEkJ4dmLag5osT+vnysKi7CVOfem/ypVwzsJJKIcxTPS2PfjOExBA4XxMF6Ixk BY9t3aQm1N1ixePrTrzRjpzWumtWhs6pudrzSEAHIa6+0A8+oqAcT0far3rHzmdFHJ aEGysbJ6TDhyrMyVUs6OqUVVB5cMtPagtlM5uvENjhcSdNHaNJ0FEC0jOgojSAaQ0T vEgbXdRp26LEw== Date: Tue, 15 Apr 2025 06:01:02 +0000 To: Andreas Hindborg From: Oliver Mangold Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Trevor Gross , Asahi Lina , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v9 1/5] rust: types: Add Ownable/Owned types Message-ID: In-Reply-To: <87o6x5d97m.fsf@kernel.org> References: <20250325-unique-ref-v9-0-e91618c1de26@pm.me> <20250325-unique-ref-v9-1-e91618c1de26@pm.me> <87o6x5d97m.fsf@kernel.org> Feedback-ID: 31808448:user:proton X-Pm-Message-ID: a0c63a9ef1b1faf8c484cedeee18243a606dd78c Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 250409 1034, Andreas Hindborg wrote: > Hi Oliver, >=20 Hi Andreas, > "Oliver Mangold" writes: >=20 > > From: Asahi Lina > > > > By analogy to AlwaysRefCounted and ARef, an Ownable type is a (typicall= y > > 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, 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@= asahilina.net/ > > Signed-off-by: Asahi Lina > > [ 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 > > Reviewed-by: Boqun Feng > > --- > > rust/kernel/lib.rs | 1 + > > rust/kernel/ownable.rs | 117 +++++++++++++++++++++++++++++++++++++++++= ++++++++ > > rust/kernel/types.rs | 2 + > > 3 files changed, 120 insertions(+) >=20 > 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= : >=20 > Callers must ensure that *ownership of* the underlying object is acquir= ed. Agree. I will fix these. Best, Oliver