rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/22] make pin-init into a standalone crate
@ 2025-03-08 11:03 Benno Lossin
  2025-03-08 11:03 ` [PATCH v2 01/22] rust: init: disable doctests Benno Lossin
                   ` (22 more replies)
  0 siblings, 23 replies; 34+ messages in thread
From: Benno Lossin @ 2025-03-08 11:03 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross
  Cc: rust-for-linux

This patch series extracts the pin-init API from the kernel crate and
turns it into a standalone crate used by the kernel crate. The reasoning
for this change is that the maintenance burden for me is too great
maintaining two (more and more) diverging versions of the same library.
At [1] you can find the user-space version of the pin-init library as a
Rust crate.

The reason for the difference between the two versions is that the
kernel does not use the `std` and `alloc` standard libraries as almost
every other user-space Rust crate does. This not only prevents the
kernel version from implementing features for the `Arc` type from
`alloc`, but also from any `std` types appearing in the documentation.
Additionally, the documentation text is different in several places as
it explicitly mentions the kernel's `Opaque<T>` type.

There are also minor changes in code that occurred due to the same
reason as the documentation changes or due to the non-optimal setup for
synchronizing changes between the two versions (the process it fully
manual, as no diffs can be ported between the two). For example, the
`try_[pin_]init!` macros in the kernel default to the kernel's own
`Error` type. The user-space version does not have such defaulting
behavior.

Since there are other projects outside of the kernel that have begun
using pin-init, the only sensible solution to this problem is to
synchronize both versions and then develop them simultaneously, ensuring
perpetual diff-compatibility. I have even had people contribute code on
github.

Additionally, I want to do some big changes to the pin-init library
internals. For example, porting the proc-macros over to `syn`. We will
probably get support for this later this year in the kernel and I want
to be ready to be able to make that switch as soon as possible. This is
because non-syn proc-macros are just pure hell and the current
implementation is a frankenstein-monster of a mix of declarative macros
and proc-macros that I'd rather replace by using `syn`. I already wrote
the code for that transition and will be submitting an RFC based on this
series shortly.

For these reasons, this patch series extracts all code of the pin-init
API and moves it into a new directory, making it its own crate. Since
the user-space version has some functional differences, these are also
introduced by this series. But in situations where the kernel has
special requirements, extensions to the pin-init crate are reintroduced
in/moved back into the kernel crate. To allow the dream of
diff-compatibility to be true, this series also introduces code files
from the user-space version.

`pin-init` is licensed under APACHE 2.0 OR MIT and almost all code that
is moved already was present with that license. There is a small license
change in patch #2, you can find the explanation in the commit message.

With this change also comes an entry in the MAINTAINERS file, since I
have to synchronize all changes with the user-space version and vice
versa.

For this series I would really appreciate some Tested-by's, by users of
the pin-init library within the kernel in order to ensure that I have
not broken anything.

Special thanks to Miguel for helping me a lot with getting the series
ready!

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

---
Cheers,
Benno

Changelog:
* v1 -> v2:
Link to v1: https://lore.kernel.org/rust-for-linux/20250304225245.2033120-1-benno.lossin@proton.me/
  - reword commit messages
  - change all occurrences of `Mutex` to `CMutex` in patch #5
  - avoid churn in patch #7 by removing changed lines that will be
    changed in #15 anyways
  - change documentation based on the `kernel` cfg, pointing to the
    kernel's `Arc` and `Box` (the user-space version continues to point
    to the std lib versions)
  - explain the reason for using `fn(*mut T) -> *mut T` in `Invariant`
  - fix typo in `README.md`

Benno Lossin (21):
  rust: init: disable doctests
  rust: move pin-init API into its own directory
  rust: add extensions to the pin-init crate and move relevant
    documentation there
  rust: pin-init: move proc-macro documentation into pin-init crate
  rust: pin-init: change examples to the user-space version
  rust: pin-init: call `try_[pin_]init!` from `[pin_]init!` instead of
    `__init_internal!`
  rust: pin-init: move the default error behavior of `try_[pin_]init`
  rust: pin-init: move `InPlaceInit` and impls of `InPlaceWrite` into
    the kernel crate
  rust: pin-init: move impl `Zeroable` for `Opaque` and
    `Option<KBox<T>>` into the kernel crate
  rust: add `ZeroableOption` and implement it instead of `Zeroable` for
    `Option<Box<T, A>>`
  rust: pin-init: fix documentation links
  rust: pin-init: remove kernel-crate dependency
  rust: pin-init: change the way the `paste!` macro is called
  rust: make pin-init its own crate
  rust: pin-init: add `std` and `alloc` support from the user-space
    version
  rust: pin-init: synchronize documentation with the user-space version
  rust: pin-init: internal: synchronize with user-space version
  rust: pin-init: miscellaneous synchronization with the user-space
    version
  rust: pin-init: add miscellaneous files from the user-space version
  rust: pin-init: re-enable doctests
  MAINTAINERS: add entry for the `pin-init` crate

Miguel Ojeda (1):
  rust: add pin-init crate build infrastructure

 MAINTAINERS                                   |   13 +
 rust/Makefile                                 |   75 +-
 rust/kernel/alloc/kbox.rs                     |    9 +-
 rust/kernel/block/mq/tag_set.rs               |    5 +-
 rust/kernel/driver.rs                         |    6 +-
 rust/kernel/init.rs                           | 1450 ++--------------
 rust/kernel/lib.rs                            |    6 +-
 rust/kernel/list.rs                           |    2 +-
 rust/kernel/prelude.rs                        |    8 +-
 rust/kernel/sync/arc.rs                       |   68 +-
 rust/kernel/sync/condvar.rs                   |    6 +-
 rust/kernel/sync/lock.rs                      |    4 +-
 rust/kernel/sync/lock/mutex.rs                |    2 +-
 rust/kernel/sync/lock/spinlock.rs             |    2 +-
 rust/kernel/types.rs                          |   13 +-
 rust/macros/helpers.rs                        |  148 +-
 rust/macros/lib.rs                            |  127 +-
 rust/macros/module.rs                         |    2 +-
 rust/macros/quote.rs                          |    1 +
 rust/pin-init/CONTRIBUTING.md                 |   72 +
 rust/pin-init/README.md                       |  228 +++
 rust/pin-init/examples/big_struct_in_place.rs |   39 +
 rust/pin-init/examples/error.rs               |   27 +
 rust/pin-init/examples/linked_list.rs         |  161 ++
 rust/pin-init/examples/mutex.rs               |  209 +++
 rust/pin-init/examples/pthread_mutex.rs       |  178 ++
 rust/pin-init/examples/static_init.rs         |  122 ++
 rust/pin-init/internal/src/helpers.rs         |  152 ++
 rust/pin-init/internal/src/lib.rs             |   48 +
 .../internal/src}/pin_data.rs                 |    7 +-
 .../internal/src}/pinned_drop.rs              |    7 +-
 .../internal/src}/zeroable.rs                 |   11 +-
 .../init => pin-init/src}/__internal.rs       |   46 +-
 rust/pin-init/src/alloc.rs                    |  158 ++
 rust/pin-init/src/lib.rs                      | 1486 +++++++++++++++++
 rust/{kernel/init => pin-init/src}/macros.rs  |  129 +-
 scripts/Makefile.build                        |    2 +-
 scripts/generate_rust_analyzer.py             |   17 +-
 38 files changed, 3343 insertions(+), 1703 deletions(-)
 create mode 100644 rust/pin-init/CONTRIBUTING.md
 create mode 100644 rust/pin-init/README.md
 create mode 100644 rust/pin-init/examples/big_struct_in_place.rs
 create mode 100644 rust/pin-init/examples/error.rs
 create mode 100644 rust/pin-init/examples/linked_list.rs
 create mode 100644 rust/pin-init/examples/mutex.rs
 create mode 100644 rust/pin-init/examples/pthread_mutex.rs
 create mode 100644 rust/pin-init/examples/static_init.rs
 create mode 100644 rust/pin-init/internal/src/helpers.rs
 create mode 100644 rust/pin-init/internal/src/lib.rs
 rename rust/{macros => pin-init/internal/src}/pin_data.rs (97%)
 rename rust/{macros => pin-init/internal/src}/pinned_drop.rs (92%)
 rename rust/{macros => pin-init/internal/src}/zeroable.rs (88%)
 rename rust/{kernel/init => pin-init/src}/__internal.rs (84%)
 create mode 100644 rust/pin-init/src/alloc.rs
 create mode 100644 rust/pin-init/src/lib.rs
 rename rust/{kernel/init => pin-init/src}/macros.rs (92%)


base-commit: 7eb172143d5508b4da468ed59ee857c6e5e01da6
-- 
2.47.2



^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2025-03-19 13:14 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-08 11:03 [PATCH v2 00/22] make pin-init into a standalone crate Benno Lossin
2025-03-08 11:03 ` [PATCH v2 01/22] rust: init: disable doctests Benno Lossin
2025-03-08 11:04 ` [PATCH v2 02/22] rust: move pin-init API into its own directory Benno Lossin
2025-03-08 11:04 ` [PATCH v2 03/22] rust: add extensions to the pin-init crate and move relevant documentation there Benno Lossin
2025-03-18 11:32   ` Andreas Hindborg
2025-03-08 11:04 ` [PATCH v2 04/22] rust: pin-init: move proc-macro documentation into pin-init crate Benno Lossin
2025-03-18 11:33   ` Andreas Hindborg
2025-03-19 13:14     ` Miguel Ojeda
2025-03-08 11:04 ` [PATCH v2 05/22] rust: pin-init: change examples to the user-space version Benno Lossin
2025-03-08 11:04 ` [PATCH v2 06/22] rust: pin-init: call `try_[pin_]init!` from `[pin_]init!` instead of `__init_internal!` Benno Lossin
2025-03-08 11:04 ` [PATCH v2 07/22] rust: pin-init: move the default error behavior of `try_[pin_]init` Benno Lossin
2025-03-08 11:04 ` [PATCH v2 08/22] rust: pin-init: move `InPlaceInit` and impls of `InPlaceWrite` into the kernel crate Benno Lossin
2025-03-18 11:37   ` Andreas Hindborg
2025-03-08 11:04 ` [PATCH v2 09/22] rust: pin-init: move impl `Zeroable` for `Opaque` and `Option<KBox<T>>` " Benno Lossin
2025-03-13 11:16   ` Fiona Behrens
2025-03-08 11:04 ` [PATCH v2 10/22] rust: add `ZeroableOption` and implement it instead of `Zeroable` for `Option<Box<T, A>>` Benno Lossin
2025-03-08 11:04 ` [PATCH v2 11/22] rust: pin-init: fix documentation links Benno Lossin
2025-03-18 11:38   ` Andreas Hindborg
2025-03-08 11:04 ` [PATCH v2 12/22] rust: pin-init: remove kernel-crate dependency Benno Lossin
2025-03-08 11:04 ` [PATCH v2 13/22] rust: pin-init: change the way the `paste!` macro is called Benno Lossin
2025-03-08 11:05 ` [PATCH v2 14/22] rust: add pin-init crate build infrastructure Benno Lossin
2025-03-08 11:05 ` [PATCH v2 15/22] rust: make pin-init its own crate Benno Lossin
2025-03-18 11:40   ` Andreas Hindborg
2025-03-08 11:05 ` [PATCH v2 16/22] rust: pin-init: add `std` and `alloc` support from the user-space version Benno Lossin
2025-03-08 11:05 ` [PATCH v2 17/22] rust: pin-init: synchronize documentation with " Benno Lossin
2025-03-08 11:05 ` [PATCH v2 18/22] rust: pin-init: internal: synchronize with " Benno Lossin
2025-03-13 11:22   ` Fiona Behrens
2025-03-08 11:05 ` [PATCH v2 19/22] rust: pin-init: miscellaneous synchronization with the " Benno Lossin
2025-03-13 11:24   ` Fiona Behrens
2025-03-08 11:05 ` [PATCH v2 20/22] rust: pin-init: add miscellaneous files from " Benno Lossin
2025-03-08 11:05 ` [PATCH v2 21/22] rust: pin-init: re-enable doctests Benno Lossin
2025-03-08 11:05 ` [PATCH v2 22/22] MAINTAINERS: add entry for the `pin-init` crate Benno Lossin
2025-03-16 21:07 ` [PATCH v2 00/22] make pin-init into a standalone crate Miguel Ojeda
2025-03-17 10:45   ` Benno Lossin

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).