mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Almeida <daniel.almeida@collabora.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"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: Wed, 15 Jan 2025 12:37:33 -0300	[thread overview]
Message-ID: <F8AB1160-F8CF-412F-8B88-4C79D65B53A1@collabora.com> (raw)
In-Reply-To: <Z4fIi_Gr0XZog4Ye@boqun-archlinux>



> On 15 Jan 2025, at 11:39, Boqun Feng <boqun.feng@gmail.com> wrote:
> 
> On Wed, Jan 15, 2025 at 09:27:39AM +0100, Alice Ryhl wrote:
>> On Wed, Jan 15, 2025 at 1:47 AM Boqun Feng <boqun.feng@gmail.com> wrote:
>>> 
>>> On Tue, Jan 14, 2025 at 03:57:57PM -0300, Daniel Almeida 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?
>>>> 
>>> 
>>> Because `Opaque` implies the value may not be initialized, it's similar
>>> to `MaybeUninit`.
>>> 
>>> Do you really need the `Opaque` here? C code won't touch `handler` if
>>> I'm not missing anything.
>> 
>> The irq callback is given access to handler, so it could touch it at any time.
>> 
> 
> You're right it could, but would it? C code doesn't know the concrete
> type of the handler, so what it usually does is just passing the
> pointers to the Rust code (again).
> 
> A similar case the `func` field in `ClosureWork`: it doesn't need to be
> `Opaque`, although workqueue callback may access it.
> 
> Am I missing something here? Daniel, why this has to be `Opaque`? Could
> you explain?
> 
> Regards,
> Boqun
> 
>> Alice

As Alice said, !Unpin is the main requirement. Although it’s not clear whether this can’t be
achieved through a PhantomPinned<T> instead.

Again, Opaque<T> needs to have its docs updated to more thoroughly explain when it should
be used. My understanding relies on what is written, i.e.: a transparent wrapper providing
!Unpin, UnsafeCell and a *mut T API for an owned T.

One could very well think this is the default thing to reach for to build anything wrapping a bindgen type.

Note that “blob of bytes that shouldn’t be touched” is not explicitly written down in the docs. What is in the docs
is a vague  “objects that are never interpreted by the Rust side”.


— Daniel



  parent reply	other threads:[~2025-01-15 15:38 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-24 14:20 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 [this message]
2025-01-15 11:38         ` Gary Guo
2025-01-15 12:31           ` Daniel Almeida
2025-01-16  8:29             ` Alice Ryhl
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=F8AB1160-F8CF-412F-8B88-4C79D65B53A1@collabora.com \
    --to=daniel.almeida@collabora.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --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 \
    --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

all inboxes | Powered by JetHome®