[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f397640b-23ed-412a-a1ac-59b7c56e5110@de.bosch.com>
Date: Fri, 31 May 2024 10:35:35 +0200
From: Dirk Behme <dirk.behme@...bosch.com>
To: Danilo Krummrich <dakr@...hat.com>, <gregkh@...uxfoundation.org>,
<rafael@...nel.org>, <bhelgaas@...gle.com>, <ojeda@...nel.org>,
<alex.gaynor@...il.com>, <wedsonaf@...il.com>, <boqun.feng@...il.com>,
<gary@...yguo.net>, <bjorn3_gh@...tonmail.com>, <benno.lossin@...ton.me>,
<a.hindborg@...sung.com>, <aliceryhl@...gle.com>, <airlied@...il.com>,
<fujita.tomonori@...il.com>, <lina@...hilina.net>, <pstanner@...hat.com>,
<ajanulgu@...hat.com>, <lyude@...hat.com>
CC: <rust-for-linux@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-pci@...r.kernel.org>
Subject: Re: [RFC PATCH 05/11] rust: add revocable objects
On 20.05.2024 19:25, Danilo Krummrich wrote:
> From: Wedson Almeida Filho <wedsonaf@...il.com>
>
> This implements the Revocable and AsyncRevocable types.
>
> Revocable allows access to objects to be safely revoked at run time.
>
> This is useful, for example, for resources allocated during device probe;
> when the device is removed, the driver should stop accessing the device
> resources even if other state is kept in memory due to existing
> references (i.e., device context data is ref-counted and has a non-zero
> refcount after removal of the device).
>
> AsyncRevocable allows access to objects to be revoked without having to
> wait for existing users to complete. This will be used to drop futures
> in tasks when executors are being torn down.
>
> Co-developed-by: Andreas Hindborg <a.hindborg@...sung.com>
> Signed-off-by: Andreas Hindborg <a.hindborg@...sung.com>
> Signed-off-by: Wedson Almeida Filho <wedsonaf@...il.com>
> Signed-off-by: Danilo Krummrich <dakr@...hat.com>
> ---
> rust/kernel/lib.rs | 1 +
> rust/kernel/revocable.rs | 441 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 442 insertions(+)
> create mode 100644 rust/kernel/revocable.rs
>
> diff --git a/rust/kernel/lib.rs b/rust/kernel/lib.rs
> index 698121c925f3..d7d415429517 100644
> --- a/rust/kernel/lib.rs
> +++ b/rust/kernel/lib.rs
> @@ -40,6 +40,7 @@
> pub mod net;
> pub mod prelude;
> pub mod print;
> +pub mod revocable;
> mod static_assert;
> #[doc(hidden)]
> pub mod std_vendor;
> diff --git a/rust/kernel/revocable.rs b/rust/kernel/revocable.rs
> new file mode 100644
> index 000000000000..71408039a117
> --- /dev/null
> +++ b/rust/kernel/revocable.rs
> @@ -0,0 +1,441 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +//! Revocable objects.
> +//!
> +//! The [`Revocable`] type wraps other types and allows access to them to be revoked. The existence
> +//! of a [`RevocableGuard`] ensures that objects remain valid.
> +
> +use crate::{
> + bindings,
> + init::{self},
> + prelude::*,
> + sync::rcu,
> +};
> +use core::{
> + cell::UnsafeCell,
> + marker::PhantomData,
> + mem::MaybeUninit,
> + ops::Deref,
> + ptr::drop_in_place,
> + sync::atomic::{fence, AtomicBool, AtomicU32, Ordering},
> +};
> +
> +/// An object that can become inaccessible at runtime.
> +///
> +/// Once access is revoked and all concurrent users complete (i.e., all existing instances of
> +/// [`RevocableGuard`] are dropped), the wrapped object is also dropped.
> +///
> +/// # Examples
You might want to enable the doctest and check if the Examples are at
least compiling ;) Here and in devres as well.
Best regards
Dirk
Powered by blists - more mailing lists