From: Zhao Liu <zhao1.liu@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org
Subject: Re: [PATCH 09/15] rust: irq: wrap IRQState with Opaque<>
Date: Tue, 25 Feb 2025 17:36:37 +0800 [thread overview]
Message-ID: <Z72PJVq+R0nsQSwR@intel.com> (raw)
In-Reply-To: <a776b84b-dd3c-4e17-b89a-a745c1f89a83@redhat.com>
On Tue, Feb 25, 2025 at 09:28:52AM +0100, Paolo Bonzini wrote:
> Date: Tue, 25 Feb 2025 09:28:52 +0100
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: Re: [PATCH 09/15] rust: irq: wrap IRQState with Opaque<>
>
> On 2/25/25 09:26, Zhao Liu wrote:
> > > +/// An opaque wrapper around [`bindings::IRQState`].
> > > +#[repr(transparent)]
> > > +#[derive(Debug, qemu_api_macros::Wrapper)]
> > > +pub struct IRQState(Opaque<bindings::IRQState>);
> > > +
> > > /// Interrupt sources are used by devices to pass changes to a value (typically
> > > /// a boolean). The interrupt sink is usually an interrupt controller or
> > > /// GPIO controller.
> > > @@ -22,8 +28,7 @@
> > > /// method sends a `true` value to the sink. If the guest has to see a
> > > /// different polarity, that change is performed by the board between the
> > > /// device and the interrupt controller.
> > > -pub type IRQState = bindings::IRQState;
> > > -
> > > +///
> > > /// Interrupts are implemented as a pointer to the interrupt "sink", which has
> > > /// type [`IRQState`]. A device exposes its source as a QOM link property using
> > > /// a function such as [`SysBusDeviceMethods::init_irq`], and
> > > @@ -41,7 +46,7 @@ pub struct InterruptSource<T = bool>
> > > where
> > > c_int: From<T>,
> > > {
> > > - cell: BqlCell<*mut IRQState>,
> > > + cell: BqlCell<*mut bindings::IRQState>,
> >
> > Once we've already wrapper IRQState in Opaque<>, should we still use
> > bindings::IRQState?
> >
> > Although InterruptSource just stores a pointer. However, I think we can
> > use wrapped IRQState here instead of the native binding type, since this
> > item is also crossing the FFI boundary. What do you think?
>
> Using the wrapped IRQState would be a bit more code because you have to cast
> the pointer all the time when calling C code. As far as correctness is
> concerned, it does not really matter because as you said it only stores a
> pointer.
Yes, it makes sense. This conversion doesn't block the current patch. The
correctness has been guaranteed.
> However, if needed, InterruptSource could have a function that converts from
> IRQState to Option<&Opaque<irq::IRQState>>. Since the accessor is needed
> anyway, that would be a good place to put the conversion.
Then I understand we still need `assert!(bql_locked())` in assessor as
the doc said: "it is possible to assert in the code that the right lock
is taken, to use it together with a custom lock guard type, or to let C
code take the lock, as appropriate."
next prev parent reply other threads:[~2025-02-25 9:18 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-21 17:03 [PATCH 00/15] rust: prepare for splitting crates Paolo Bonzini
2025-02-21 17:03 ` [PATCH 01/15] rust: add IsA bounds to QOM implementation traits Paolo Bonzini
2025-02-24 14:43 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 02/15] rust: add SysBusDeviceImpl Paolo Bonzini
2025-02-24 14:46 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 03/15] rust: qom: add ObjectImpl::CLASS_INIT Paolo Bonzini
2025-02-24 14:56 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 04/15] rust: pl011, qemu_api tests: do not use ClassInitImpl Paolo Bonzini
2025-02-24 15:14 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 05/15] rust: qom: get rid of ClassInitImpl Paolo Bonzini
2025-02-24 15:24 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 06/15] rust: cell: add wrapper for FFI types Paolo Bonzini
2025-02-25 6:46 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 07/15] rust: qemu_api_macros: add Wrapper derive macro Paolo Bonzini
2025-02-25 7:54 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 08/15] rust: timer: wrap QEMUTimer with Opaque<> Paolo Bonzini
2025-02-25 7:56 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 09/15] rust: irq: wrap IRQState " Paolo Bonzini
2025-02-25 8:26 ` Zhao Liu
2025-02-25 8:28 ` Paolo Bonzini
2025-02-25 9:36 ` Zhao Liu [this message]
2025-02-21 17:03 ` [PATCH 10/15] rust: qom: wrap Object " Paolo Bonzini
2025-02-25 8:47 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 11/15] rust: qdev: wrap Clock and DeviceState " Paolo Bonzini
2025-02-25 8:52 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 12/15] rust: sysbus: wrap SysBusDevice " Paolo Bonzini
2025-02-25 8:59 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 13/15] rust: memory: wrap MemoryRegion " Paolo Bonzini
2025-02-25 9:14 ` Zhao Liu
2025-02-25 9:47 ` Paolo Bonzini
2025-02-21 17:03 ` [PATCH 14/15] rust: chardev: wrap Chardev " Paolo Bonzini
2025-02-25 9:19 ` Zhao Liu
2025-02-21 17:03 ` [PATCH 15/15] rust: bindings: remove more unnecessary Send/Sync impls Paolo Bonzini
2025-02-25 9:20 ` Zhao Liu
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=Z72PJVq+R0nsQSwR@intel.com \
--to=zhao1.liu@intel.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@nongnu.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).