[PATCH v13 2/4] rust: `AlwaysRefCounted` is renamed to `RefCounted`.

Gary Guo gary at garyguo.net
Mon Dec 1 16:00:30 UTC 2025


On Mon, 17 Nov 2025 10:07:57 +0000
Oliver Mangold <oliver.mangold at pm.me> wrote:

> `AlwaysRefCounted` will become a marker trait to indicate that it is
> allowed to obtain an `ARef<T>` from a `&T`, which cannot be allowed for
> types which are also Ownable.

The message needs a rationale for making the change rather than relying
on the reader to deduce so.

For example:

	There are types where it may both be referenced counted in some
	cases and owned in other. 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.

Best,
Gary

> 
> Signed-off-by: Oliver Mangold <oliver.mangold at pm.me>
> Co-developed-by: Andreas Hindborg <a.hindborg at kernel.org>
> Signed-off-by: Andreas Hindborg <a.hindborg at kernel.org>
> Suggested-by: Alice Ryhl <aliceryhl at google.com>
> ---
>  rust/kernel/auxiliary.rs        |  7 +++++-
>  rust/kernel/block/mq/request.rs | 15 +++++++------
>  rust/kernel/cred.rs             | 13 ++++++++++--
>  rust/kernel/device.rs           | 13 ++++++++----
>  rust/kernel/device/property.rs  |  7 +++++-
>  rust/kernel/drm/device.rs       | 10 ++++++---
>  rust/kernel/drm/gem/mod.rs      | 10 ++++++---
>  rust/kernel/fs/file.rs          | 16 ++++++++++----
>  rust/kernel/mm.rs               | 15 +++++++++----
>  rust/kernel/mm/mmput_async.rs   |  9 ++++++--
>  rust/kernel/opp.rs              | 10 ++++++---
>  rust/kernel/owned.rs            |  2 +-
>  rust/kernel/pci.rs              | 10 ++++++---
>  rust/kernel/pid_namespace.rs    | 12 +++++++++--
>  rust/kernel/platform.rs         |  7 +++++-
>  rust/kernel/sync/aref.rs        | 47 ++++++++++++++++++++++++++---------------
>  rust/kernel/task.rs             | 10 ++++++---
>  rust/kernel/types.rs            |  2 +-
>  18 files changed, 154 insertions(+), 61 deletions(-)



More information about the Linux-security-module-archive mailing list