lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6688a873-20d6-4e45-82c1-83a226f5bba4@proton.me>
Date: Mon, 29 Jul 2024 16:15:28 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Alex Mantel <alexmantel93@...lbox.org>, ojeda@...nel.org, alex.gaynor@...il.com, wedsonaf@...il.com, boqun.feng@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com, a.hindborg@...sung.com, aliceryhl@...gle.com, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3] rust: Implement the smart pointer `InPlaceInit` for `Arc`

On 27.07.24 06:24, Alex Mantel wrote:
> For pinned and unpinned initialization of structs, a trait named
> `InPlaceInit` exists for uniform access. `Arc` did not implement
> `InPlaceInit` yet, although the functions already existed. The main
> reason for that, was that the trait itself returned a `Pin<Self>`. The
> `Arc` implementation of the kernel is already implicitly pinned.
> 
> To enable `Arc` to implement `InPlaceInit` and to have uniform access,
> for in-place and pinned in-place initialization, an associated type is
> introduced for `InPlaceInit`. The new implementation of `InPlaceInit`
> for `Arc` sets `Arc` as the associated type. Older implementations use
> an explicit `Pin<T>` as the associated type. The implemented methods for
> `Arc` are mostly moved from a direct implementation on `Arc`. There
> should be no user impact. The implementation for `ListArc` is omitted,
> because it is not merged yet.
> 
> Link: https://github.com/Rust-for-Linux/linux/issues/1079
> Signed-off-by: Alex Mantel <alexmantel93@...lbox.org>

One documentation nit below, otherwise this LGTM:

Reviewed-by: Benno Lossin <benno.lossin@...ton.me>

> ---
> Hello again!
> 
> This is the 3rd version of my very first patch. I applied the
> suggestions on the 2nd submission. Thank you again for your feedback,
> looking for more!
> 
> v1:
>   * https://lore.kernel.org/rust-for-linux/20240717034801.262343-2-alexmantel93@mailbox.org/
> 
> v2:
>   * remove the `From:` from the patch.
>   * add the prefix `rust: ` to the subject.
>   * Remove the empty line between `Link` and `Signed-off-by`.
>   * https://lore.kernel.org/all/20240719192234.330341-1-alexmantel93@mailbox.org/
> 
> v3:
>   * Rename PinnedResult to PinnedSelf
>   * Adjust documentation for PinnedSelf
> 
>  rust/kernel/init.rs     | 39 +++++++++++++++++++++++++++++++++++----
>  rust/kernel/sync/arc.rs | 25 ++-----------------------
>  2 files changed, 37 insertions(+), 27 deletions(-)
> 
> diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
> index 68605b633..fa5f182fe 100644
> --- a/rust/kernel/init.rs
> +++ b/rust/kernel/init.rs
> @@ -213,6 +213,7 @@
>  use crate::{
>      alloc::{box_ext::BoxExt, AllocError, Flags},
>      error::{self, Error},
> +    sync::Arc,
>      sync::UniqueArc,
>      types::{Opaque, ScopeGuard},
>  };
> @@ -1112,11 +1113,17 @@ unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> {
> 
>  /// Smart pointer that can initialize memory in-place.
>  pub trait InPlaceInit<T>: Sized {
> +    /// Pinned version of Rusts `Self`.

I would not have mentioned "Rust" here, since that should be obvious.

---
Cheers,
Benno

> +    ///
> +    /// If a type already implicitly pins its pointee, `Pin<Self>` is unnecessary. In this case use
> +    /// `Self`, otherwise just use `Pin<Self>`.
> +    type PinnedSelf;
> +
>      /// Use the given pin-initializer to pin-initialize a `T` inside of a new smart pointer of this
>      /// type.
>      ///
>      /// If `T: !Unpin` it will not be able to move afterwards.
> -    fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Pin<Self>, E>
> +    fn try_pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> Result<Self::PinnedSelf, E>
>      where
>          E: From<AllocError>;
> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ