<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/rust/kernel/sync/arc.rs, branch v6.4</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v6.4</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v6.4'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2023-04-12T16:41:05Z</updated>
<entry>
<title>rust: sync: add functions for initializing `UniqueArc&lt;MaybeUninit&lt;T&gt;&gt;`</title>
<updated>2023-04-12T16:41:05Z</updated>
<author>
<name>Benno Lossin</name>
<email>benno.lossin@proton.me</email>
</author>
<published>2023-04-08T12:26:33Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=1944caa8e8dcb2d93d99d8364719ad8d07aa163f'/>
<id>urn:sha1:1944caa8e8dcb2d93d99d8364719ad8d07aa163f</id>
<content type='text'>
Add two functions `init_with` and `pin_init_with` to
`UniqueArc&lt;MaybeUninit&lt;T&gt;&gt;` to initialize the memory of already allocated
`UniqueArc`s. This is useful when you want to allocate memory check some
condition inside of a context where allocation is forbidden and then
conditionally initialize an object.

Signed-off-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@samsung.com&gt;
Link: https://lore.kernel.org/r/20230408122429.1103522-16-y86-dev@protonmail.com
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: sync: reduce stack usage of `UniqueArc::try_new_uninit`</title>
<updated>2023-04-12T16:41:05Z</updated>
<author>
<name>Benno Lossin</name>
<email>benno.lossin@proton.me</email>
</author>
<published>2023-04-08T12:26:27Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=701608bd030a888f654862295a49c5d0f42f864c'/>
<id>urn:sha1:701608bd030a888f654862295a49c5d0f42f864c</id>
<content type='text'>
`UniqueArc::try_new_uninit` calls `Arc::try_new(MaybeUninit::uninit())`.
This results in the uninitialized memory being placed on the stack,
which may be arbitrarily large due to the generic `T` and thus could
cause a stack overflow for large types.

Change the implementation to use the pin-init API which enables in-place
initialization. In particular it avoids having to first construct and
then move the uninitialized memory from the stack into the final location.

Signed-off-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@samsung.com&gt;
Link: https://lore.kernel.org/r/20230408122429.1103522-15-y86-dev@protonmail.com
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: init/sync: add `InPlaceInit` trait to pin-initialize smart pointers</title>
<updated>2023-04-12T16:41:05Z</updated>
<author>
<name>Benno Lossin</name>
<email>benno.lossin@proton.me</email>
</author>
<published>2023-04-08T12:25:56Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=92c4a1e7e81cc775b2ad6bedb348098230f7ed87'/>
<id>urn:sha1:92c4a1e7e81cc775b2ad6bedb348098230f7ed87</id>
<content type='text'>
The `InPlaceInit` trait that provides two functions, for initializing
using `PinInit&lt;T, E&gt;` and `Init&lt;T&gt;`. It is implemented by `Arc&lt;T&gt;`,
`UniqueArc&lt;T&gt;` and `Box&lt;T&gt;`.

Signed-off-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@samsung.com&gt;
Link: https://lore.kernel.org/r/20230408122429.1103522-9-y86-dev@protonmail.com
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: sync: change error type of constructor functions</title>
<updated>2023-04-12T16:41:05Z</updated>
<author>
<name>Benno Lossin</name>
<email>benno.lossin@proton.me</email>
</author>
<published>2023-04-08T12:25:29Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d6dbca3592209d29c10e171224c34803805e88ca'/>
<id>urn:sha1:d6dbca3592209d29c10e171224c34803805e88ca</id>
<content type='text'>
Change the error type of the constructors of `Arc` and `UniqueArc` to be
`AllocError` instead of `Error`. This makes the API more clear as to
what can go wrong when calling `try_new` or its variants.

Signed-off-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@samsung.com&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Link: https://lore.kernel.org/r/20230408122429.1103522-4-y86-dev@protonmail.com
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: sync: arc: Add UniqueArc&lt;MaybeUninit&lt;T&gt;::assume_init()</title>
<updated>2023-04-12T16:41:04Z</updated>
<author>
<name>Asahi Lina</name>
<email>lina@asahilina.net</email>
</author>
<published>2023-04-03T10:01:12Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=31d95c2f99bf16e59b996cf6a227e198a64e835c'/>
<id>urn:sha1:31d95c2f99bf16e59b996cf6a227e198a64e835c</id>
<content type='text'>
We can already create `UniqueArc&lt;MaybeUninit&lt;T&gt;&gt;` instances with
`UniqueArc::try_new_uninit()` and write to them with `write()`. Add
the missing unsafe `assume_init()` function to promote it to
`UniqueArc&lt;T&gt;`, so users can do piece-wise initialization of the
contents instead of doing it all at once as long as they keep the
invariants (the same requirements as `MaybeUninit::assume_init()`).

This mirrors the std `Arc::assume_init()` function. In the kernel,
since we have `UniqueArc`, arguably this only belongs there since most
use cases will initialize it immediately after creating it, before
demoting it to `Arc` to share it.

[ Miguel: The "Rust pin-init API for pinned initialization of structs"
  patch series [1] from Benno Lossin contains a very similar patch:

    rust: sync: add `assume_init` to `UniqueArc`

    Adds the `assume_init` function to `UniqueArc&lt;MaybeUninit&lt;T&gt;&gt;` that
    unsafely assumes the value to be initialized and yields a value of type
    `UniqueArc&lt;T&gt;`. This function is used when manually initializing the
    pointee of an `UniqueArc`.

  To make that patch a noop and thus drop it, I adjusted the `SAFETY`
  comment here to be the same as in the current latest version of
  that series (v7).

  I have also brought the `Reviewed-by`s there into here, and reworded
  the `Co-authored-by` into `Co-developed-by`. ]

Link: https://lore.kernel.org/r/20230408122429.1103522-5-y86-dev@protonmail.com [1]
Co-developed-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Signed-off-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Signed-off-by: Asahi Lina &lt;lina@asahilina.net&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Wedson Almeida Filho &lt;walmeida@microsoft.com&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@samsung.com&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Link: https://lore.kernel.org/r/20230224-rust-arc-v2-2-5c97a865b276@asahilina.net
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: sync: arc: Implement Arc&lt;dyn Any + Send + Sync&gt;::downcast()</title>
<updated>2023-04-10T21:55:43Z</updated>
<author>
<name>Asahi Lina</name>
<email>lina@asahilina.net</email>
</author>
<published>2023-04-03T10:01:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=1edd03378e50ff1071004c80cb878e4bad73a68f'/>
<id>urn:sha1:1edd03378e50ff1071004c80cb878e4bad73a68f</id>
<content type='text'>
This mirrors the standard library's alloc::sync::Arc::downcast().

Based on the Rust standard library implementation, ver 1.62.0,
licensed under "Apache-2.0 OR MIT", from:

    https://github.com/rust-lang/rust/tree/1.62.0/library/alloc/src

For copyright details, please see:

    https://github.com/rust-lang/rust/blob/1.62.0/COPYRIGHT

Reviewed-by: Martin Rodriguez Reboredo &lt;yakoyoku@gmail.com&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@samsung.com&gt;
Reviewed-by: Vincenzo Palazzo &lt;vincenzopalazzodev@gmail.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Signed-off-by: Asahi Lina &lt;lina@asahilina.net&gt;
Link: https://lore.kernel.org/r/20230224-rust-arc-v2-1-5c97a865b276@asahilina.net
[ Moved `mod std_vendor;` up. ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: sync: impl {Debug,Display} for {Unique,}Arc</title>
<updated>2023-04-10T03:05:39Z</updated>
<author>
<name>Boqun Feng</name>
<email>boqun.feng@gmail.com</email>
</author>
<published>2023-02-07T18:52:15Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=00140a8308367208d56e93cf08fa1636202a0dc7'/>
<id>urn:sha1:00140a8308367208d56e93cf08fa1636202a0dc7</id>
<content type='text'>
This allows printing the inner data of `Arc` and its friends if the
inner data implements `Display` or `Debug`. It's useful for logging and
debugging purpose.

Signed-off-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Reviewed-by: Vincenzo Palazzo &lt;vincenzopalazzodev@gmail.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@samsung.com&gt;
Reviewed-by: Björn Roy Baron &lt;bjorn3_gh@protonmail.com&gt;
Link: https://lore.kernel.org/r/20230207185216.1314638-2-boqun.feng@gmail.com
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: types: implement `ForeignOwnable` for `Arc&lt;T&gt;`</title>
<updated>2023-02-07T10:24:24Z</updated>
<author>
<name>Wedson Almeida Filho</name>
<email>wedsonaf@gmail.com</email>
</author>
<published>2023-01-30T06:44:04Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=0c7ae432576100ce3609bca0508b9fbcb686a5fe'/>
<id>urn:sha1:0c7ae432576100ce3609bca0508b9fbcb686a5fe</id>
<content type='text'>
This allows us to hand ownership of Rust ref-counted objects to
the C side of the kernel.

Signed-off-by: Wedson Almeida Filho &lt;wedsonaf@gmail.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Vincenzo Palazzo &lt;vincenzopalazzodev@gmail.com&gt;
Reviewed-by: Alice Ferrazzi &lt;alice.ferrazzi@miraclelinux.com&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@samsung.com&gt;
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: sync: add support for dispatching on Arc and ArcBorrow.</title>
<updated>2023-01-16T22:48:06Z</updated>
<author>
<name>Wedson Almeida Filho</name>
<email>wedsonaf@gmail.com</email>
</author>
<published>2022-12-28T06:03:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=0748424aba89811b85e6e0f958b8ccd47f5af47e'/>
<id>urn:sha1:0748424aba89811b85e6e0f958b8ccd47f5af47e</id>
<content type='text'>
Trait objects (`dyn T`) require trait `T` to be "object safe". One of
the requirements for "object safety" is that the receiver have one of
the allowed types. This commit adds `Arc&lt;T&gt;` and `ArcBorrow&lt;'_, T&gt;` to
the list of allowed types.

Signed-off-by: Wedson Almeida Filho &lt;wedsonaf@gmail.com&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Vincenzo Palazzo &lt;vincenzopalazzodev@gmail.com&gt;
Acked-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: sync: introduce `UniqueArc`</title>
<updated>2023-01-16T22:48:06Z</updated>
<author>
<name>Wedson Almeida Filho</name>
<email>wedsonaf@gmail.com</email>
</author>
<published>2022-12-28T06:03:45Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=70e42ebbf6416e8005d8e08ae521b7d5cc5a8b3a'/>
<id>urn:sha1:70e42ebbf6416e8005d8e08ae521b7d5cc5a8b3a</id>
<content type='text'>
Since `Arc&lt;T&gt;` does not allow mutating `T` directly (i.e., without inner
mutability), it is currently not possible to do some initialisation of
`T` post construction but before being shared.

`UniqueArc&lt;T&gt;` addresses this problem essentially being an `Arc&lt;T&gt;` that
has a refcount of 1 and is therefore writable. Once initialisation is
completed, it can be transitioned (without failure paths) into an
`Arc&lt;T&gt;`.

Suggested-by: Gary Guo &lt;gary@garyguo.net&gt;
Signed-off-by: Wedson Almeida Filho &lt;wedsonaf@gmail.com&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Vincenzo Palazzo &lt;vincenzopalazzodev@gmail.com&gt;
Acked-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
</feed>
