From: Andreas Hindborg <a.hindborg@kernel.org>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] rust: add global lock support
Date: Thu, 10 Oct 2024 16:08:50 +0200 [thread overview]
Message-ID: <87frp4kq31.fsf@kernel.org> (raw)
In-Reply-To: <CAH5fLghvZsU-rF+6hkOoiAOWhpiLJV1WJNPYCRWTq7cEW8UM1w@mail.gmail.com> (Alice Ryhl's message of "Thu, 10 Oct 2024 16:01:29 +0200")
Alice Ryhl <aliceryhl@google.com> writes:
> On Thu, Oct 10, 2024 at 3:57 PM Andreas Hindborg <a.hindborg@kernel.org> wrote:
>>
>> Hi Alice,
>>
>> Alice Ryhl <aliceryhl@google.com> writes:
>>
>> > Add support for creating global variables that are wrapped in a mutex or
>> > spinlock. Optionally, the macro can generate a special LockedBy type
>> > that does not require a runtime check.
>> >
>> > The implementation here is intended to replace the global mutex
>> > workaround found in the Rust Binder RFC [1]. In both cases, the global
>> > lock must be initialized before first use. The macro is unsafe to use
>> > for the same reason.
>> >
>> > The separate initialization step is required because it is tricky to
>> > access the value of __ARCH_SPIN_LOCK_UNLOCKED from Rust. Doing so will
>> > require changes to the C side. That change will happen as a follow-up to
>> > this patch.
>>
>> Why is this a challenge? It seems to work with locks that are not
>> global.
>
> Because normal locks are not initialized in a const expression.
>
>> > diff --git a/rust/kernel/sync/lock/global.rs b/rust/kernel/sync/lock/global.rs
>> > new file mode 100644
>> > index 000000000000..fc02fac864f6
>> > --- /dev/null
>> > +++ b/rust/kernel/sync/lock/global.rs
>> > @@ -0,0 +1,260 @@
>> > +// SPDX-License-Identifier: GPL-2.0
>> > +
>> > +// Copyright (C) 2024 Google LLC.
>> > +
>> > +//! Support for defining statics containing locks.
>> > +
>> > +/// Defines a global lock.
>> > +///
>> > +/// Supports the following options:
>> > +///
>> > +/// * `value` specifies the initial value in the global lock.
>> > +/// * `wrapper` specifies the name of the wrapper struct.
>>
>> Could you add an example to demonstrate when using `wrapper` option
>> would be useful?
>
> Probably only guard and locked_by are useful, but I think you need to
> give the wrapper a name to reasonably use guard/locked_by.
Could you expand the example to show this, or would it become too
long?
BR Andreas
prev parent reply other threads:[~2024-10-10 14:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-30 13:11 [PATCH v4] rust: add global lock support Alice Ryhl
2024-10-10 10:39 ` Benno Lossin
2024-10-10 10:53 ` Alice Ryhl
2024-10-10 13:55 ` Boqun Feng
2024-10-10 13:58 ` Alice Ryhl
2024-10-10 14:29 ` Boqun Feng
2024-10-10 16:33 ` Boqun Feng
2024-10-10 22:21 ` Benno Lossin
2024-10-10 23:06 ` Boqun Feng
2024-10-11 7:01 ` Benno Lossin
2024-10-11 22:43 ` Boqun Feng
2024-10-10 22:13 ` Benno Lossin
2024-10-10 14:01 ` Andreas Hindborg
2024-10-10 22:14 ` Benno Lossin
2024-10-11 14:57 ` Andreas Hindborg
2024-10-10 13:57 ` Andreas Hindborg
2024-10-10 14:01 ` Alice Ryhl
2024-10-10 14:08 ` Andreas Hindborg [this message]
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=87frp4kq31.fsf@kernel.org \
--to=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--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 \
/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).