rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benno Lossin <benno.lossin@proton.me>
To: Andreas Hindborg <a.hindborg@kernel.org>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH 16/22] rust: pin-init: add `std` and `alloc` support from the user-space version
Date: Wed, 05 Mar 2025 13:55:03 +0000	[thread overview]
Message-ID: <D88DTO6ZIXMN.26SWTE440RP9K@proton.me> (raw)
In-Reply-To: <8734frd5v6.fsf@kernel.org>

On Wed Mar 5, 2025 at 1:22 PM CET, Andreas Hindborg wrote:
> "Benno Lossin" <benno.lossin@proton.me> writes:
>
>> To synchronize the kernel's version of pin-init with the user-space
>> version, introduce support for `std` and `alloc`. While the kernel uses
>> neither, the user-space version has to support both. Thus include the
>> required `#[cfg]`s and additional code.
>>
>> Signed-off-by: Benno Lossin <benno.lossin@proton.me>
>> ---
>>  rust/pin-init/src/__internal.rs |  27 ++++++
>>  rust/pin-init/src/alloc.rs      | 158 ++++++++++++++++++++++++++++++++
>>  rust/pin-init/src/lib.rs        |  17 ++--
>>  3 files changed, 196 insertions(+), 6 deletions(-)
>>  create mode 100644 rust/pin-init/src/alloc.rs
>>
>> diff --git a/rust/pin-init/src/__internal.rs b/rust/pin-init/src/__internal.rs
>> index 74086365a18a..27d4a8619c04 100644
>> --- a/rust/pin-init/src/__internal.rs
>> +++ b/rust/pin-init/src/__internal.rs
>> @@ -186,6 +186,33 @@ pub fn init<E>(self: Pin<&mut Self>, init: impl PinInit<T, E>) -> Result<Pin<&mu
>>      }
>>  }
>>
>> +#[test]
>
> I think the kunit support we have in the pipeline will pick this up?

Is that support also enabled for crates outside of the `kernel` crate?
I would argue it shouldn't and then this isn't a problem.

>> +fn stack_init_reuse() {
>> +    use ::std::{borrow::ToOwned, println, string::String};
>> +    use core::pin::pin;
>> +
>> +    #[derive(Debug)]
>> +    struct Foo {
>> +        a: usize,
>> +        b: String,
>> +    }
>> +    let mut slot: Pin<&mut StackInit<Foo>> = pin!(StackInit::uninit());
>> +    let value: Result<Pin<&mut Foo>, core::convert::Infallible> =
>> +        slot.as_mut().init(crate::init!(Foo {
>> +            a: 42,
>> +            b: "Hello".to_owned(),
>> +        }));
>> +    let value = value.unwrap();
>> +    println!("{value:?}");
>> +    let value: Result<Pin<&mut Foo>, core::convert::Infallible> =
>> +        slot.as_mut().init(crate::init!(Foo {
>> +            a: 24,
>> +            b: "world!".to_owned(),
>> +        }));
>> +    let value = value.unwrap();
>> +    println!("{value:?}");
>> +}
>> +
>
> [...]
>
>> diff --git a/rust/pin-init/src/lib.rs b/rust/pin-init/src/lib.rs
>> index 55d8953620f0..1fdca35906a0 100644
>> --- a/rust/pin-init/src/lib.rs
>> +++ b/rust/pin-init/src/lib.rs
>> @@ -204,8 +204,8 @@
>>  //! [structurally pinned fields]:
>>  //!     https://doc.rust-lang.org/std/pin/index.html#pinning-is-structural-for-field
>>  //! [stack]: crate::stack_pin_init
>> -//! [`Arc<T>`]: ../kernel/sync/struct.Arc.html
>> -//! [`Box<T>`]: ../kernel/alloc/struct.KBox.html
>> +//! [`Arc<T>`]: https://doc.rust-lang.org/stable/alloc/sync/struct.Arc.html
>> +//! [`Box<T>`]: https://doc.rust-lang.org/stable/alloc/boxed/struct.Box.html
>
> Now these will render incorrect in the kernel docs, right?

What do you mean by that? The link will resolve to the std versions of
`Arc` and `Box`. But that is also what this crate will support, as it
doesn't know about the kernel's own alloc.

>>  //! [`impl PinInit<Foo>`]: PinInit
>>  //! [`impl PinInit<T, E>`]: PinInit
>>  //! [`impl Init<T, E>`]: Init
>> @@ -239,6 +239,11 @@
>>  #[doc(hidden)]
>>  pub mod macros;
>>
>> +#[cfg(any(feature = "std", feature = "alloc"))]
>> +mod alloc;
>> +#[cfg(any(feature = "std", feature = "alloc"))]
>> +pub use alloc::InPlaceInit;
>
> Do we really need to have this entire file sitting dead in the kernel
> tree? If you are not building the user space version from the kernel
> sources, I don't think we need it here. Even when you want to sync
> between the two repositories, it should be easy to handle an entire file
> being not present on one side.

I do have a script that does the commit porting, you can find it at [1].
So I could easily add that file there. However, I think it also is
important that it's easy to remember which files are synchronized and
which files aren't. At the moment it's very simple, the synchronized
files are:
- README.md
- CONTRIBUTING.md
- src/*
- internal/src/*
- examples/*

If I introduce special cases for files in src, I fear that I might get
confused at some point, making a change that shouldn't be done etc.

I understand your worry about the dead file, but at the same time, I
think it's vital to keep the pattern of synchronized files as simple as
possible.

[1]: https://github.com/Rust-for-Linux/pin-init/commit/7eda8fda7cb48883511db4b5f4fff8d574eef25a

---
Cheers,
Benno


  reply	other threads:[~2025-03-05 13:55 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <xn5HRPkxO91lsoIUAwMnnAvQRCAgmw6nzTZX2DsODS0viAvz_g6B8l3dpYNtcL2jBXySi0DQrVi04b6MY8GbMw==@protonmail.internalid>
2025-03-04 22:52 ` [PATCH 00/22] make pin-init into a standalone crate Benno Lossin
2025-03-04 22:53   ` [PATCH 01/22] rust: init: disable doctests Benno Lossin
2025-03-05  8:51     ` Andreas Hindborg
2025-03-05 12:53       ` Benno Lossin
2025-03-05 13:00         ` Miguel Ojeda
2025-03-05 14:09         ` Andreas Hindborg
2025-03-05 14:31           ` Benno Lossin
2025-03-05  9:17     ` Fiona Behrens
2025-03-04 22:53   ` [PATCH 02/22] rust: move pin-init API into its own directory Benno Lossin
2025-03-05  9:03     ` Andreas Hindborg
2025-03-05  9:17     ` Fiona Behrens
2025-03-04 22:53   ` [PATCH 03/22] rust: add extensions to the pin-init crate and move relevant documentation there Benno Lossin
2025-03-05  9:11     ` Andreas Hindborg
2025-03-05 11:03       ` Benno Lossin
2025-03-05  9:17     ` Fiona Behrens
2025-03-04 22:53   ` [PATCH 04/22] rust: pin-init: move proc-macro documentation into pin-init crate Benno Lossin
2025-03-05  9:18     ` Fiona Behrens
2025-03-05  9:34     ` Andreas Hindborg
2025-03-05 11:05       ` Benno Lossin
2025-03-04 22:53   ` [PATCH 05/22] rust: pin-init: change examples to the user-space version Benno Lossin
2025-03-05  9:19     ` Fiona Behrens
2025-03-05 10:06     ` Andreas Hindborg
2025-03-04 22:53   ` [PATCH 06/22] rust: pin-init: call `try_[pin_]init!` from `[pin_]init!` instead of `__init_internal!` Benno Lossin
2025-03-05  9:19     ` Fiona Behrens
2025-03-05 10:12     ` Andreas Hindborg
2025-03-04 22:54   ` [PATCH 07/22] rust: pin-init: move the default error behavior of `try_[pin_]init` Benno Lossin
2025-03-05  9:21     ` Fiona Behrens
2025-03-05 10:29     ` Andreas Hindborg
2025-03-05 10:47       ` Benno Lossin
2025-03-04 22:54   ` [PATCH 08/22] rust: pin-init: move `InPlaceInit` and impls of `InPlaceWrite` into the kernel crate Benno Lossin
2025-03-05  9:23     ` Fiona Behrens
2025-03-05 11:18     ` Andreas Hindborg
2025-03-05 12:06       ` Benno Lossin
2025-03-05 12:28         ` Andreas Hindborg
2025-03-05 12:37           ` Benno Lossin
2025-03-04 22:54   ` [PATCH 09/22] rust: pin-init: move impl `Zeroable` for `Opaque` and `Option<KBox<T>>` " Benno Lossin
2025-03-05  9:24     ` Fiona Behrens
2025-03-05 11:26     ` Andreas Hindborg
2025-03-05 12:05       ` Benno Lossin
2025-03-05 12:11         ` Alice Ryhl
2025-03-05 12:17           ` Benno Lossin
2025-03-05 12:49             ` Alice Ryhl
2025-03-05 12:51               ` Benno Lossin
2025-03-04 22:54   ` [PATCH 10/22] rust: add `ZeroableOption` and implement it instead of `Zeroable` for `Option<Box<T, A>>` Benno Lossin
2025-03-05  9:25     ` Fiona Behrens
2025-03-05 11:30     ` Andreas Hindborg
2025-03-04 22:54   ` [PATCH 11/22] rust: pin-init: fix documentation links Benno Lossin
2025-03-05  9:26     ` Fiona Behrens
2025-03-05 11:37     ` Andreas Hindborg
2025-03-05 11:49       ` Benno Lossin
2025-03-04 22:54   ` [PATCH 12/22] rust: pin-init: remove kernel-crate dependency Benno Lossin
2025-03-05  9:27     ` Fiona Behrens
2025-03-05 11:49     ` Andreas Hindborg
2025-03-05 12:00       ` Benno Lossin
2025-03-05 12:27         ` Andreas Hindborg
2025-03-04 22:55   ` [PATCH 13/22] rust: pin-init: change the way the `paste!` macro is called Benno Lossin
2025-03-05  9:28     ` Fiona Behrens
2025-03-05 11:52     ` Andreas Hindborg
2025-03-04 22:55   ` [PATCH 14/22] rust: add pin-init crate build infrastructure Benno Lossin
2025-03-05 11:59     ` Andreas Hindborg
2025-03-05 12:10       ` Benno Lossin
2025-03-05 12:31         ` Andreas Hindborg
2025-03-05 12:50           ` Miguel Ojeda
2025-03-05 13:00             ` Benno Lossin
2025-03-05 14:19             ` Andreas Hindborg
2025-03-05 14:34               ` Benno Lossin
2025-03-05 12:47       ` Miguel Ojeda
2025-03-04 22:55   ` [PATCH 15/22] rust: make pin-init its own crate Benno Lossin
2025-03-05  9:29     ` Fiona Behrens
2025-03-05 12:12     ` Andreas Hindborg
2025-03-05 13:40       ` Benno Lossin
2025-03-05 14:20         ` Andreas Hindborg
2025-03-04 22:55   ` [PATCH 16/22] rust: pin-init: add `std` and `alloc` support from the user-space version Benno Lossin
2025-03-05  9:32     ` Fiona Behrens
2025-03-05 12:22     ` Andreas Hindborg
2025-03-05 13:55       ` Benno Lossin [this message]
2025-03-05 14:29         ` Andreas Hindborg
2025-03-05 15:05           ` Benno Lossin
2025-03-05 17:27             ` Andreas Hindborg
2025-03-04 22:55   ` [PATCH 17/22] rust: pin-init: synchronize documentation with " Benno Lossin
2025-03-05  9:33     ` Fiona Behrens
2025-03-05 12:52     ` Andreas Hindborg
2025-03-04 22:55   ` [PATCH 18/22] rust: pin-init: internal: synchronize with " Benno Lossin
2025-03-05 12:56     ` Andreas Hindborg
2025-03-04 22:56   ` [PATCH 19/22] rust: pin-init: miscellaneous synchronization with the " Benno Lossin
2025-03-05 12:57     ` Andreas Hindborg
2025-03-04 22:56   ` [PATCH 20/22] rust: pin-init: add miscellaneous files from " Benno Lossin
2025-03-05  9:35     ` Fiona Behrens
2025-03-05 13:04     ` Andreas Hindborg
2025-03-05 13:37       ` Miguel Ojeda
2025-03-05 13:58         ` Benno Lossin
2025-03-04 22:56   ` [PATCH 21/22] rust: pin-init: re-enable doctests Benno Lossin
2025-03-05  9:35     ` Fiona Behrens
2025-03-05 13:05     ` Andreas Hindborg
2025-03-04 22:56   ` [PATCH 22/22] MAINTAINERS: add entry for the `pin-init` crate Benno Lossin
2025-03-05  0:17     ` Jarkko Sakkinen
2025-03-05  0:43       ` Benno Lossin
2025-03-05  5:14         ` Jarkko Sakkinen
2025-03-04 23:12   ` [PATCH 00/22] make pin-init into a standalone crate Benno Lossin
2025-03-05 13:56   ` Andreas Hindborg
2025-03-05 14:03     ` Benno Lossin
2025-03-05 14:36       ` Andreas Hindborg
2025-03-05 14:47         ` Benno Lossin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D88DTO6ZIXMN.26SWTE440RP9K@proton.me \
    --to=benno.lossin@proton.me \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).