qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Zhao Liu <zhao1.liu@intel.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-rust@nongnu.org,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 2/3] hw/char/pl011: Pad PL011State struct to same size as Rust impl
Date: Thu, 20 Mar 2025 23:28:16 +0800	[thread overview]
Message-ID: <Z9w0EIgD6A3oBL33@intel.com> (raw)
In-Reply-To: <20250320133248.1679485-3-peter.maydell@linaro.org>

On Thu, Mar 20, 2025 at 01:32:47PM +0000, Peter Maydell wrote:
> Date: Thu, 20 Mar 2025 13:32:47 +0000
> From: Peter Maydell <peter.maydell@linaro.org>
> Subject: [PATCH 2/3] hw/char/pl011: Pad PL011State struct to same size as
>  Rust impl
> X-Mailer: git-send-email 2.43.0
> 
> We have some users of the PL011 struct which embed it directly into
> their own state structs. This means that the Rust version of the
> device must have a state struct that is the same size or smaller
> than the C struct.
> 
> In commit 9b642097d6b7 ("rust: pl011: switch to safe chardev operation")
> the Rust PL011 state struct changed from having a bindings::CharBackend
> to a chardev::CharBackend, which made it grow larger than the C
> version. This results in an assertion at startup when QEMU was
> built with Rust enabled:
> 
>  $ qemu-system-arm -M raspi2b -display none
>  ERROR:../../qom/object.c:562:object_initialize_with_type: assertion
>  failed: (size >= type->instance_size)
> 
> The long-term better approach to this problem would be to move
> our C device code patterns away from "embed a struct" and (back)
> to "have a pointer to the device", so we can make the C PL011State
> struct a private implementation detail rather than exposed to
> its users.
> 
> For the short term, add a padding field at the end of the C struct
> so it's big enough that the Rust state struct can fit.
> 
> Fixes: 9b642097d6b7 ("rust: pl011: switch to safe chardev operation")
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  include/hw/char/pl011.h | 5 +++++
>  1 file changed, 5 insertions(+)

LGTM, BqlRefCell<> has extra fields to make BqlRefCell<T> bigger than T,

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>



  reply	other threads:[~2025-03-20 15:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-20 13:32 [PATCH 0/3] rust: Fix PL011State size mismatch assert Peter Maydell
2025-03-20 13:32 ` [PATCH 1/3] rust: assertions: add static_assert Peter Maydell
2025-03-20 14:03   ` Philippe Mathieu-Daudé
2025-03-20 15:20   ` Zhao Liu
2025-03-20 13:32 ` [PATCH 2/3] hw/char/pl011: Pad PL011State struct to same size as Rust impl Peter Maydell
2025-03-20 15:28   ` Zhao Liu [this message]
2025-03-20 13:32 ` [PATCH 3/3] rust: pl011: Check size of state struct at compile time Peter Maydell
2025-03-20 15:45   ` Zhao Liu
2025-03-20 16:02     ` Peter Maydell
2025-03-21  4:31       ` 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=Z9w0EIgD6A3oBL33@intel.com \
    --to=zhao1.liu@intel.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --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).