From: Zhao Liu <zhao1.liu@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, philmd@linaro.org, qemu-rust@nongnu.org
Subject: Re: [PATCH 6/7] rust: pl011: fix migration stream
Date: Thu, 19 Dec 2024 15:52:45 +0800 [thread overview]
Message-ID: <Z2PQzYc3aoyElDSn@intel.com> (raw)
In-Reply-To: <20241212172209.533779-7-pbonzini@redhat.com>
On Thu, Dec 12, 2024 at 06:22:03PM +0100, Paolo Bonzini wrote:
> Date: Thu, 12 Dec 2024 18:22:03 +0100
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH 6/7] rust: pl011: fix migration stream
> X-Mailer: git-send-email 2.47.1
>
> The Rust vmstate macros lack the type-safety of their C equivalents (so
> safe, much abstraction), and therefore they were predictably wrong.
Yes, this makes Rust more unsafe than C code...
> The registers have already been changed to 32-bits in the previous patch,
> but read_pos/read_count/read_trigger also have to be u32 instead of usize.
> The easiest way to do so is to let the FIFO use u32 indices instead
> of usize.
>
> My plan for making VMStateField typesafe is to have a trait to retrieve
> a basic VMStateField; for example something like vmstate_uint32 would
> become an implementation of the VMState trait on u32. Then you'd write
> something like "vmstate_of!(Type, field).with_version_id(2)". That is,
> vmstate_of retrieves the basic VMStateField and fills in the offset,
> and then more changes can be applied on top.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> rust/hw/char/pl011/src/device.rs | 38 ++++++++++++++++++++++----
> rust/hw/char/pl011/src/device_class.rs | 8 +++---
> rust/qemu-api/src/vmstate.rs | 22 ---------------
> 3 files changed, 36 insertions(+), 32 deletions(-)
>
> @@ -64,9 +64,9 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int {
> vmstate_uint32!(ibrd, PL011State),
> vmstate_uint32!(fbrd, PL011State),
> vmstate_uint32!(ifl, PL011State),
> - vmstate_int32!(read_pos, PL011State),
> - vmstate_int32!(read_count, PL011State),
> - vmstate_int32!(read_trigger, PL011State),
> + vmstate_uint32!(read_pos, PL011State),
> + vmstate_uint32!(read_count, PL011State),
> + vmstate_uint32!(read_trigger, PL011State),
uint32 and int32 types both use `qemu_put_be32s` and `qemu_get_be32s`
to save and store vmstate, so I think it's safe to convert
vmstate_int32! to vmstate_uint32! here.
> },
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
next prev parent reply other threads:[~2024-12-19 7:34 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-12 17:21 [PATCH 0/7] rust: pl011: bug fixes Paolo Bonzini
2024-12-12 17:21 ` [PATCH 1/7] rust: pl011: fix declaration of LineControl bits Paolo Bonzini
2024-12-18 13:23 ` Philippe Mathieu-Daudé
2024-12-19 3:42 ` Zhao Liu
2024-12-12 17:21 ` [PATCH 2/7] rust: pl011: match break logic of C version Paolo Bonzini
2024-12-18 13:18 ` Philippe Mathieu-Daudé
2024-12-19 4:38 ` Zhao Liu
2024-12-19 6:31 ` Paolo Bonzini
2024-12-12 17:22 ` [PATCH 3/7] rust: pl011: always use reset() method on registers Paolo Bonzini
2024-12-18 13:28 ` Philippe Mathieu-Daudé
2024-12-19 6:55 ` Zhao Liu
2024-12-12 17:22 ` [PATCH 4/7] rust: pl011: fix break errors and definition of Data struct Paolo Bonzini
2024-12-18 14:49 ` Philippe Mathieu-Daudé
2024-12-19 7:17 ` Zhao Liu
2024-12-12 17:22 ` [PATCH 5/7] rust: pl011: extend registers to 32 bits Paolo Bonzini
2024-12-18 13:43 ` Philippe Mathieu-Daudé
2024-12-19 7:30 ` Zhao Liu
2024-12-12 17:22 ` [PATCH 6/7] rust: pl011: fix migration stream Paolo Bonzini
2024-12-18 14:50 ` Philippe Mathieu-Daudé
2024-12-19 7:52 ` Zhao Liu [this message]
2024-12-12 17:22 ` [PATCH 7/7] rust: pl011: simplify handling of the FIFO enabled bit in LCR Paolo Bonzini
2024-12-18 13:20 ` Philippe Mathieu-Daudé
2024-12-19 7:55 ` Zhao Liu
2024-12-18 11:17 ` [PATCH 0/7] rust: pl011: bug fixes Philippe Mathieu-Daudé
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=Z2PQzYc3aoyElDSn@intel.com \
--to=zhao1.liu@intel.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.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).