From: Benno Lossin <benno.lossin@proton.me>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Andreas Hindborg" <a.hindborg@samsung.com>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] rust: add global lock support
Date: Tue, 10 Sep 2024 07:10:46 +0000 [thread overview]
Message-ID: <3c471d06-d8c4-47a2-b29b-4faa5d61d25d@proton.me> (raw)
In-Reply-To: <CAH5fLgh9kHm4XbcH2X4y6nwZ9VLYuUeu3hNmQBcdZ+Vx1H1L9w@mail.gmail.com>
On 04.09.24 12:32, Alice Ryhl wrote:
> On Tue, Sep 3, 2024 at 12:17 AM Benno Lossin <benno.lossin@proton.me> wrote:
>>
>> On 02.09.24 13:42, Alice Ryhl wrote:
>>> On Mon, Sep 2, 2024 at 1:37 PM Alice Ryhl <aliceryhl@google.com> wrote:
>>>>
>>>> On Fri, Aug 30, 2024 at 3:22 PM Benno Lossin <benno.lossin@proton.me> wrote:
>>>>>
>>>>> On 30.08.24 07:34, Alice Ryhl wrote:
>>>>>> On Thu, Aug 29, 2024 at 8:17 PM Benno Lossin <benno.lossin@proton.me> wrote:
>>>>>>>
>>>>>>> On 27.08.24 10:41, Alice Ryhl wrote:
>>>>>>>> For architectures that don't use all-zeros for the unlocked case, we
>>>>>>>> will most likely have to hard-code the correct representation on the
>>>>>>>> Rust side.
>>>>>>>
>>>>>>> You mean in `unsafe_const_init`?
>>>>>>
>>>>>> No, I mean we would have `unsafe_const_new` directly set `state` to
>>>>>> the right value and let `unsafe_const_init` be a no-op.
>>>>>
>>>>> But how do you set the right value of a list_head? The value will be
>>>>> moved.
>>>>
>>>> Right ... we probably can't get around needing a macro. Can statics
>>>> even reference themselves?
>>>
>>> Looks like they can:
>>>
>>> use std::ptr::addr_of;
>>>
>>> struct MyStruct {
>>> ptr: *const MyStruct,
>>> }
>>>
>>> static mut MY_STRUCT: MyStruct = MyStruct {
>>> ptr: addr_of!(MY_STRUCT),
>>> };
>>
>> That's useful to know...
>> But I don't see a way to get pinned-init to work with this. I would need
>> a lot of currently experimental features (const closures, const traits)
>> and a way to initialize a static without providing a direct value, since
>> I can't just do
>>
>> static mut MY_STRUCT: MyStruct = {
>> unsafe { __pinned_init(addr_of_mut!(MY_STRUCT), /* initializer */) };
>> unsafe { addr_of!(MY_STRUCT).read() }
>> };
>>
>> It (rightfully) complains that I am initializing the static with itself.
>>
>> We /might/ be able to do something special for `Mutex`/ other locks, but
>> I haven't tried yet. So the unsafe approach seems the best at the moment.
>
> It sounds like we'll just want a macro that generates a global wrapped
> in a Mutex/SpinLock for now ...
Yeah.
> If we're going to do that, we could take the extra step and have it
> generate special Guard and LockedBy types so that you can have a
> LockedBy that doesn't need to make any runtime checks.
Oh that is a good idea!
---
Cheers,
Benno
next prev parent reply other threads:[~2024-09-10 7:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-27 8:41 [PATCH v2] rust: add global lock support Alice Ryhl
2024-08-29 18:16 ` Benno Lossin
2024-08-30 5:34 ` Alice Ryhl
2024-08-30 13:21 ` Benno Lossin
2024-09-02 11:37 ` Alice Ryhl
2024-09-02 11:42 ` Alice Ryhl
2024-09-02 14:18 ` Boqun Feng
2024-09-02 14:19 ` Alice Ryhl
2024-09-02 22:16 ` Benno Lossin
2024-09-04 10:32 ` Alice Ryhl
2024-09-10 7:10 ` Benno Lossin [this message]
2024-09-02 21:37 ` Benno Lossin
2024-08-30 15:09 ` Gary Guo
2024-09-02 10:46 ` Alice Ryhl
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=3c471d06-d8c4-47a2-b29b-4faa5d61d25d@proton.me \
--to=benno.lossin@proton.me \
--cc=a.hindborg@samsung.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
/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).