d701e061 | 31-May-2023 |
Alice Ryhl <aliceryhl@google.com> |
rust: sync: reword the `Arc` safety comment for `Sync`
The safety comment on `impl Sync for Arc` references the Send safety comment. This commit avoids that in case the two comments drift apart in t
rust: sync: reword the `Arc` safety comment for `Sync`
The safety comment on `impl Sync for Arc` references the Send safety comment. This commit avoids that in case the two comments drift apart in the future.
Suggested-by: Andreas Hindborg <a.hindborg@samsung.com> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20230531145939.3714886-3-aliceryhl@google.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
f8110cd1 | 31-May-2023 |
Alice Ryhl <aliceryhl@google.com> |
rust: sync: reword the `Arc` safety comment for `Send`
The safety comment on `impl Send for Arc` talks about "directly" accessing the value, when it really means "accessing the value with a mutable
rust: sync: reword the `Arc` safety comment for `Send`
The safety comment on `impl Send for Arc` talks about "directly" accessing the value, when it really means "accessing the value with a mutable reference". This commit clarifies that.
Suggested-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Link: https://lore.kernel.org/r/20230531145939.3714886-2-aliceryhl@google.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
47329ba1 | 17-May-2023 |
Alice Ryhl <aliceryhl@google.com> |
rust: sync: implement `AsRef<T>` for `Arc<T>`
This trait lets you use `Arc<T>` in code that is generic over smart pointer types.
The `AsRef` trait should be implemented on all smart pointers. The s
rust: sync: implement `AsRef<T>` for `Arc<T>`
This trait lets you use `Arc<T>` in code that is generic over smart pointer types.
The `AsRef` trait should be implemented on all smart pointers. The standard library also implements it on the ordinary `Arc`.
Co-developed-by: Wedson Almeida Filho <walmeida@microsoft.com> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Link: https://lore.kernel.org/r/20230517200814.3157916-2-aliceryhl@google.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
bd780aea | 17-May-2023 |
Alice Ryhl <aliceryhl@google.com> |
rust: sync: add `Arc::ptr_eq`
Add a method for comparing whether two `Arc` pointers reference the same underlying object.
This comparison can already be done by getting a reference to the inner val
rust: sync: add `Arc::ptr_eq`
Add a method for comparing whether two `Arc` pointers reference the same underlying object.
This comparison can already be done by getting a reference to the inner values and comparing whether the references have the same address. However, writing `Arc::ptr_eq(a, b)` is generally less error-prone than doing the same check on the references, since you might otherwise accidentally compare the two `&Arc<T>` references instead, which wont work because those are pointers to pointers to the inner value, when you just want to compare the pointers to the inner value.
Also, this method might optimize better because getting a reference to the inner value involves offsetting the pointer, which this method does not need to do.
Co-developed-by: Wedson Almeida Filho <walmeida@microsoft.com> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Link: https://lore.kernel.org/r/20230517200814.3157916-1-aliceryhl@google.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
19096bce | 25-Mar-2023 |
Wedson Almeida Filho <walmeida@microsoft.com> |
rust: sync: introduce `CondVar`
This is the traditional condition variable or monitor synchronisation primitive. It is implemented with C's `wait_queue_head_t`.
It allows users to release a lock an
rust: sync: introduce `CondVar`
This is the traditional condition variable or monitor synchronisation primitive. It is implemented with C's `wait_queue_head_t`.
It allows users to release a lock and go to sleep while guaranteeing that notifications won't be missed. This is achieved by enqueuing a wait entry before releasing the lock.
Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Will Deacon <will@kernel.org> Cc: Waiman Long <longman@redhat.com> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20230411054543.21278-12-wedsonaf@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
e32cca32 | 27-Mar-2023 |
Wedson Almeida Filho <walmeida@microsoft.com> |
rust: lock: add `Guard::do_unlocked`
It releases the lock, executes some function provided by the caller, then reacquires the lock. This is preparation for the implementation of condvars, which will
rust: lock: add `Guard::do_unlocked`
It releases the lock, executes some function provided by the caller, then reacquires the lock. This is preparation for the implementation of condvars, which will sleep after between unlocking and relocking.
We need an explicit `relock` method for primitives like `SpinLock` that have an irqsave variant: we use the guard state to determine if the lock was originally acquired with the regular `lock` function or `lock_irqsave`.
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com> Link: https://lore.kernel.org/rust-for-linux/20230412121431.41627-1-wedsonaf@gmail.com/ [ Removed the irqsave bits as discussed. ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
c6d917a4 | 19-Apr-2023 |
Wedson Almeida Filho <walmeida@microsoft.com> |
rust: lock: introduce `SpinLock`
This is the `spinlock_t` lock backend and allows Rust code to use the kernel spinlock idiomatically.
Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <ming
rust: lock: introduce `SpinLock`
This is the `spinlock_t` lock backend and allows Rust code to use the kernel spinlock idiomatically.
Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Will Deacon <will@kernel.org> Cc: Waiman Long <longman@redhat.com> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com> Link: https://lore.kernel.org/r/20230419174426.132207-1-wedsonaf@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
6d20d629 | 11-Apr-2023 |
Wedson Almeida Filho <walmeida@microsoft.com> |
rust: lock: introduce `Mutex`
This is the `struct mutex` lock backend and allows Rust code to use the kernel mutex idiomatically.
Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@re
rust: lock: introduce `Mutex`
This is the `struct mutex` lock backend and allows Rust code to use the kernel mutex idiomatically.
Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Will Deacon <will@kernel.org> Cc: Waiman Long <longman@redhat.com> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com> Link: https://lore.kernel.org/r/20230411054543.21278-3-wedsonaf@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
76d4bd59 | 11-Apr-2023 |
Wedson Almeida Filho <walmeida@microsoft.com> |
rust: sync: introduce `Lock` and `Guard`
They are generic Rust implementations of a lock and a lock guard that contain code that is common to all locks. Different backends will be introduced in subs
rust: sync: introduce `Lock` and `Guard`
They are generic Rust implementations of a lock and a lock guard that contain code that is common to all locks. Different backends will be introduced in subsequent commits.
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Suggested-by: Gary Guo <gary@garyguo.net> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com> Link: https://lore.kernel.org/r/20230411054543.21278-2-wedsonaf@gmail.com [ Fixed typo. ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
1944caa8 | 08-Apr-2023 |
Benno Lossin <benno.lossin@proton.me> |
rust: sync: add functions for initializing `UniqueArc<MaybeUninit<T>>`
Add two functions `init_with` and `pin_init_with` to `UniqueArc<MaybeUninit<T>>` to initialize the memory of already allocated
rust: sync: add functions for initializing `UniqueArc<MaybeUninit<T>>`
Add two functions `init_with` and `pin_init_with` to `UniqueArc<MaybeUninit<T>>` 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 <benno.lossin@proton.me> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Link: https://lore.kernel.org/r/20230408122429.1103522-16-y86-dev@protonmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
701608bd | 08-Apr-2023 |
Benno Lossin <benno.lossin@proton.me> |
rust: sync: reduce stack usage of `UniqueArc::try_new_uninit`
`UniqueArc::try_new_uninit` calls `Arc::try_new(MaybeUninit::uninit())`. This results in the uninitialized memory being placed on the st
rust: sync: reduce stack usage of `UniqueArc::try_new_uninit`
`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 <benno.lossin@proton.me> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Link: https://lore.kernel.org/r/20230408122429.1103522-15-y86-dev@protonmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
92c4a1e7 | 08-Apr-2023 |
Benno Lossin <benno.lossin@proton.me> |
rust: init/sync: add `InPlaceInit` trait to pin-initialize smart pointers
The `InPlaceInit` trait that provides two functions, for initializing using `PinInit<T, E>` and `Init<T>`. It is implemented
rust: init/sync: add `InPlaceInit` trait to pin-initialize smart pointers
The `InPlaceInit` trait that provides two functions, for initializing using `PinInit<T, E>` and `Init<T>`. It is implemented by `Arc<T>`, `UniqueArc<T>` and `Box<T>`.
Signed-off-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Link: https://lore.kernel.org/r/20230408122429.1103522-9-y86-dev@protonmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
31d95c2f | 03-Apr-2023 |
Asahi Lina <lina@asahilina.net> |
rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init()
We can already create `UniqueArc<MaybeUninit<T>>` instances with `UniqueArc::try_new_uninit()` and write to them with `write()`. Add the
rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init()
We can already create `UniqueArc<MaybeUninit<T>>` instances with `UniqueArc::try_new_uninit()` and write to them with `write()`. Add the missing unsafe `assume_init()` function to promote it to `UniqueArc<T>`, 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<MaybeUninit<T>>` that unsafely assumes the value to be initialized and yields a value of type `UniqueArc<T>`. 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 <benno.lossin@proton.me> Signed-off-by: Benno Lossin <benno.lossin@proton.me> Signed-off-by: Asahi Lina <lina@asahilina.net> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Wedson Almeida Filho <walmeida@microsoft.com> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20230224-rust-arc-v2-2-5c97a865b276@asahilina.net Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
1edd0337 | 03-Apr-2023 |
Asahi Lina <lina@asahilina.net> |
rust: sync: arc: Implement Arc<dyn Any + Send + Sync>::downcast()
This mirrors the standard library's alloc::sync::Arc::downcast().
Based on the Rust standard library implementation, ver 1.62.0, li
rust: sync: arc: Implement Arc<dyn Any + Send + Sync>::downcast()
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 <yakoyoku@gmail.com> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Asahi Lina <lina@asahilina.net> Link: https://lore.kernel.org/r/20230224-rust-arc-v2-1-5c97a865b276@asahilina.net [ Moved `mod std_vendor;` up. ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
0c7ae432 | 30-Jan-2023 |
Wedson Almeida Filho <wedsonaf@gmail.com> |
rust: types: implement `ForeignOwnable` for `Arc<T>`
This allows us to hand ownership of Rust ref-counted objects to the C side of the kernel.
Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.co
rust: types: implement `ForeignOwnable` for `Arc<T>`
This allows us to hand ownership of Rust ref-counted objects to the C side of the kernel.
Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Reviewed-by: Alice Ferrazzi <alice.ferrazzi@miraclelinux.com> Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|
0748424a | 28-Dec-2022 |
Wedson Almeida Filho <wedsonaf@gmail.com> |
rust: sync: add support for dispatching on Arc and ArcBorrow.
Trait objects (`dyn T`) require trait `T` to be "object safe". One of the requirements for "object safety" is that the receiver have one
rust: sync: add support for dispatching on Arc and ArcBorrow.
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<T>` and `ArcBorrow<'_, T>` to the list of allowed types.
Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Acked-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
show more ...
|