From: Alice Ryhl <aliceryhl@google.com>
To: Daniel Almeida <daniel.almeida@collabora.com>
Cc: "Gary Guo" <gary@garyguo.net>, "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] rust: irq: add support for request_irq()
Date: Thu, 16 Jan 2025 09:29:44 +0100 [thread overview]
Message-ID: <CAH5fLgiOASgjoYKFz6kWwzLaH07DqP2ph+3YyCDh2+gYqGpABA@mail.gmail.com> (raw)
In-Reply-To: <71A92388-A636-47F4-9B1C-0154D9AA9839@collabora.com>
On Wed, Jan 15, 2025 at 1:31 PM Daniel Almeida
<daniel.almeida@collabora.com> wrote:
>
>
>
> > On 15 Jan 2025, at 08:38, Gary Guo <gary@garyguo.net> wrote:
> >
> > On Tue, 14 Jan 2025 15:57:57 -0300
> > Daniel Almeida <daniel.almeida@collabora.com> wrote:
> >
> >>>
> >>> It's not the pin_init! stuff, but the Opaque stuff. If it fails, then
> >>> it runs the destructor of Opaque<T>, which does *not* run the
> >>> destructor of T.
> >>>
> >>> Alice
> >>
> >> This is pretty unintuitive if you take into account trivial examples like
> >>
> >> ```
> >> struct Foo(T)
> >> ```
> >>
> >> Where dropping Foo drops T.
> >>
> >> Is there any reason why dropping Opaque<T> doesn’t behave similarly?
> >>
> >> — Daniel
> >
> > `Opaque` means that "this is a blob of bytes and don't touch it". It
> > can be uninitialized, so no meaningful action can be performed when
> > it's dropped.
> >
> > Best,
> > Gary
> >
>
> I really think that the documentation for this type has to be improved somehow.
>
> How is this a blob of bytes that can’t be touched, if it gives out a *mut T?
>
> I think I’ve consistently seen code that either accesses or mutates the inner T through
> the pointer.
It's not a problem to give out a *mut T. A Opaque is a blob of bytes
that *might* or *might not* contain a valid `T`. When you dereference
a raw pointer to the inner value, you are unsafely asserting that
*right now*, it does in fact contain a valid T.
The problem we're running into here is that Opaque is intended for
wrapping C types, but you're using it to wrap a Rust type instead. I
think we should have a new container type called `Aliased<T>` defined
like Opaque but without the MaybeUninit.
#[repr(transparent)]
pub struct Aliased<T> {
value: UnsafeCell<T>,
_pin: PhantomPinned,
}
This type can then serve the purpose of a Rust type that might be
accessed in weird ways, but *is* guaranteed to hold a valid Rust type.
It's destructor will run the destructor of T.
Alice
next prev parent reply other threads:[~2025-01-16 8:29 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-24 14:20 [PATCH] rust: irq: add support for request_irq() Daniel Almeida
2024-10-24 15:05 ` Miguel Ojeda
2024-10-24 15:08 ` Daniel Almeida
2024-10-27 5:30 ` kernel test robot
2024-10-28 15:29 ` Alice Ryhl
2024-11-04 20:10 ` Daniel Almeida
2024-11-06 11:17 ` Alice Ryhl
2024-10-29 11:59 ` Alice Ryhl
2024-11-04 19:19 ` Daniel Almeida
2025-01-13 14:42 ` Alice Ryhl
2025-01-14 18:34 ` Daniel Almeida
2025-01-14 18:36 ` Alice Ryhl
2025-01-14 18:57 ` Daniel Almeida
2025-01-15 0:45 ` Boqun Feng
2025-01-15 8:27 ` Alice Ryhl
2025-01-15 14:39 ` Boqun Feng
2025-01-15 14:42 ` Alice Ryhl
2025-01-15 16:00 ` Boqun Feng
2025-01-15 15:37 ` Daniel Almeida
2025-01-15 11:38 ` Gary Guo
2025-01-15 12:31 ` Daniel Almeida
2025-01-16 8:29 ` Alice Ryhl [this message]
2025-01-19 17:50 ` Boqun Feng
2025-01-15 11:42 ` Gary Guo
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=CAH5fLgiOASgjoYKFz6kWwzLaH07DqP2ph+3YyCDh2+gYqGpABA@mail.gmail.com \
--to=aliceryhl@google.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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).