From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80FDA43E484 for ; Tue, 16 Jun 2026 11:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781610877; cv=none; b=F1dToxE1xnTlIeQbjterYma7wTICKlRIeVU8tYvHt19aD8Sf157t0+iiVB9iVRoKhTzR166ZJxnE1+O87QE3MHsAGZQRNqFl4dRGN5JjBvBta6uHi/hT9xhPYnnD3yLwiVuxjUbWdjOcknljRXVckJRA9AI/28EV/QqytO03KQg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781610877; c=relaxed/simple; bh=/5GyqFufVnT0ephA4mcW12nnDGKZodyXuu8OjccvjII=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OhLZyF7PsOUJkLl9PhkqNATVHuY5mWphRyPHxo4CDGTymvUXvgUwxfUZDENNblp3tKT6pwmPgcCUgO9+VjnPJL7jiMdFwXmYhb7c6EEdr9hFL80xHMYhn5ZP1rCad9RbHK8tLl8wO+G0k5py1B6cR4XJ7RvoO56lS0BpYazU4fU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=d5An8ztK; arc=none smtp.client-ip=209.85.208.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="d5An8ztK" Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-68cdfbad902so4716512a12.0 for ; Tue, 16 Jun 2026 04:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781610873; x=1782215673; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Fkz/8WHSlc5z8mgSFYgivmaJvolb4fXApnGq7F/IsFs=; b=d5An8ztK8te3TbjRv3dNRhwXyfIjPc2YktyqBrbqUtK1jNVuy7x5TAmHHYc+AN4u+N lFxB7laTr7E3rQcNcdQUsyvdp3jdPaUmwQZkmcigC220Cc2L19XkYkERVnFS9E1XMzi5 1X+EwXKYTpA42ohxCtFTBtGZdn6Uw3adiPaNc/GPZxz5vWK4FK2RHUGmawga9oR/qwMe ZawVZ8VQjwBEL4xQNuuaJRylRPnzTpL0vt8zX3vhj0bPfI+Ac2CPUvMWhQPGmZwbtNBQ T7rlCWj4Mr1VuxXT8IS8Fg8FOa6rg1BWHYtx92GHoTVdItxt+868JLLi6ILB+BINszQJ aLmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781610873; x=1782215673; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Fkz/8WHSlc5z8mgSFYgivmaJvolb4fXApnGq7F/IsFs=; b=Topck96eA3crvgqi9EAa0B9qnB8qk1rVKMWy+FxKNPwBU4tnorA1k9fi2UBWvslZ4r ws4cekO4ctHxs0mEumUJuXipsVmuv73qSzGT+fItaiVrOAchSpLyoVEe5JQZa38E/Pft eOOCKzX+rC8TiAPXXtct/631/Tddq1hwf4SkB+/emDJnz5UnRcET4C/b7XxTGLVxbGln lBPdEQB5SMvPhVz+69l83g1yo9mKUVcSrgJ7h6e4cypXlplhzD2QI0xKOLbWGsseA8SJ DxBNTjyKpJ1kbF79B3xJFxZcPiw+FF6CMBqopDAbjNyxkQJULXaYVGKFc/Y/Q7RGLv1d 7fKg== X-Forwarded-Encrypted: i=1; AFNElJ8A3pB8Qiea/9vMqYNgAAOMtko4FQ+a2nvnScqe8q9js3iCJM5Zct6gwQ6aKP4l1wE+I+TBlLzseM4=@vger.kernel.org X-Gm-Message-State: AOJu0YyE5EqitjMGrMPMU6EAv7FG6mppPYPFYjj+ykOW41PMCl1NRtnw 5Y3vrvH0USQR5obTXlAFM4KHB2QmY3slrRTDWwPVa8AFgbjcayxz+RWtHdk+ykGNUtzyuU+7aAd V9PkFpnryza0Y3JfigA== X-Received: from edrc26.prod.google.com ([2002:aa7:d61a:0:b0:68d:205:9a90]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:35c5:b0:695:865:47cd with SMTP id 4fb4d7f45d1cf-695086ebec3mr1540972a12.7.1781610868582; Tue, 16 Jun 2026 04:54:28 -0700 (PDT) Date: Tue, 16 Jun 2026 11:54:27 +0000 In-Reply-To: <20260604-unique-ref-v17-2-7b4c3d2930b9@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260604-unique-ref-v17-0-7b4c3d2930b9@kernel.org> <20260604-unique-ref-v17-2-7b4c3d2930b9@kernel.org> Message-ID: Subject: Re: [PATCH v17 02/10] rust: types: Add Ownable/Owned types From: Alice Ryhl To: Andreas Hindborg Cc: Miguel Ojeda , Gary Guo , "=?utf-8?B?QmrDtnJu?= Roy Baron" , Benno Lossin , Trevor Gross , Danilo Krummrich , Greg Kroah-Hartman , Dave Ertman , Ira Weiny , Leon Romanovsky , Paul Moore , Serge Hallyn , "Rafael J. Wysocki" , David Airlie , Simona Vetter , Alexander Viro , Christian Brauner , Jan Kara , Daniel Almeida , Viresh Kumar , Nishanth Menon , Stephen Boyd , Bjorn Helgaas , "Krzysztof =?utf-8?Q?Wilczy=C5=84ski?=" , Boqun Feng , Uladzislau Rezki , Lorenzo Stoakes , Vlastimil Babka , "Liam R. Howlett" , Igor Korotin , Pavel Tikhomirov , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-block@vger.kernel.org, linux-security-module@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-pm@vger.kernel.org, linux-pci@vger.kernel.org, driver-core@lists.linux.dev, Asahi Lina , Oliver Mangold Content-Type: text/plain; charset="utf-8" On Thu, Jun 04, 2026 at 10:11:14PM +0200, Andreas Hindborg wrote: > From: Asahi Lina > > 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`, 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 > Co-developed-by: Oliver Mangold > Signed-off-by: Oliver Mangold > Reviewed-by: Boqun Feng > Reviewed-by: Daniel Almeida > [ Andreas: Updated documentation, examples, and formatting. Change safety > requirements, safety comments. Use a reference for `release`. ] > Reviewed-by: Gary Guo > Co-developed-by: Andreas Hindborg > Signed-off-by: Andreas Hindborg Overall looks good to me, but two nits below. With them fixed: Reviewed-by: Alice Ryhl > +pub trait Ownable { > + /// Tear down this `Ownable`. > + /// > + /// Implementers of `Ownable` can use this function to clean up the use of `Self`. This can > + /// include freeing the underlying object. > + /// > + /// # Safety > + /// > + /// Callers must ensure that the caller has exclusive ownership of `T`, and this ownership can > + /// be transferred to the `release` method. > + unsafe fn release(&mut self); I'd make this take a raw pointer because the pointer can be freed during the execution of release(), which references don't allow. > diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs > index 4329d3c2c2e5..4aec7b699269 100644 > --- a/rust/kernel/types.rs > +++ b/rust/kernel/types.rs > @@ -11,6 +11,17 @@ > }; > use pin_init::{PinInit, Wrapper, Zeroable}; > > +pub use crate::{ > + owned::{ > + Ownable, > + Owned, // > + }, > + sync::aref::{ > + ARef, > + AlwaysRefCounted, // > + }, // > +}; We removed the types::ARef re-export, so you shouldn't add it back. Alice