From: Zhao Liu <zhao1.liu@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org, junjie.mao@hotmail.com
Subject: Re: [RFC PATCH 5/9] rust: vmstate: implement VMState for scalar types
Date: Thu, 16 Jan 2025 14:59:43 +0800 [thread overview]
Message-ID: <Z4iuX5oTr2r5B569@intel.com> (raw)
In-Reply-To: <f1e17aac-543a-4d9b-906b-8ee98d1ff55e@redhat.com>
> > > +impl_vmstate_scalar!(vmstate_info_uint64, u64);
> >
> > What about applying this to "usize" with vmstate_info_uint64?
>
> There's 32-bit hosts too... So one would have to add vmstate_info_ulong
> which is serialized as 64-bit.
>
> We can add it later, but perhaps we could also create a derive(Index,
> IndexMut) macro that makes it possible to specify the type of the index.
> While Rust uses usize instead of uNN for array indices, that does not have
> to be universal; using uNN is a lot better if it means you can get rid of
> casts from register values to array indices and back. See for example
> commit 6b4f7b0705b ("rust: pl011: fix migration stream", 2024-12-19).
Yes, I agree!
> That is indeed also an issue for HPET, but in that case it can be isolated
> to a couple lines,
>
> let timer_id: usize = ((addr - 0x100) / 0x20) as usize;
>
> and it could even be wrapped further
>
> fn timer_and_addr(&self, addr: hwaddr) -> Option<&BqlRefCell<HPETTimer>,
> hwaddr> {
> let timer_id: usize = ((addr - 0x100) / 0x20) as usize;
> if timer_id > self.num_timers.get() {
> // TODO: Add trace point -
> trace_hpet_timer_id_out_of_range(timer_id)
> None
> } else {
> Some((self.get_timer(timer_id), addr & 0x18))
> }
> }
>
> ...
>
> match self.timer_and_addr(addr) {
> None => 0 // Reserved,
> Some(timer, addr) => timer.borrow_mut().read(addr, size)
> }
>
>
> So for HPET you didn't reach the threshold of having to create "pub struct
> HPETTimers([BqlRefCell<HPETTimer>; MAX_HPET_TIMERS])" and implement Index<>.
>
Thank you Paolo! Will apply your wrapping suggestion!
Regards,
Zhao
next prev parent reply other threads:[~2025-01-16 6:41 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-31 0:23 [RFC PATCH 0/9] rust: (mostly) type safe VMState Paolo Bonzini
2024-12-31 0:23 ` [RFC PATCH 1/9] rust: vmstate: add new type safe implementation Paolo Bonzini
2025-01-07 8:58 ` Zhao Liu
2025-01-07 12:23 ` Paolo Bonzini
2025-01-07 14:01 ` Zhao Liu
2024-12-31 0:23 ` [RFC PATCH 2/9] rust: vmstate: implement VMState for non-leaf types Paolo Bonzini
2025-01-07 15:43 ` Zhao Liu
2024-12-31 0:23 ` [RFC PATCH 3/9] rust: vmstate: add varray support to vmstate_of! Paolo Bonzini
2025-01-08 3:28 ` Zhao Liu
2025-01-15 10:14 ` Paolo Bonzini
2024-12-31 0:23 ` [RFC PATCH 4/9] rust: vmstate: implement Zeroable for VMStateField Paolo Bonzini
2025-01-06 14:31 ` Zhao Liu
2024-12-31 0:23 ` [RFC PATCH 5/9] rust: vmstate: implement VMState for scalar types Paolo Bonzini
2025-01-08 6:45 ` Zhao Liu
2025-01-15 13:08 ` Paolo Bonzini
2025-01-16 6:59 ` Zhao Liu [this message]
2024-12-31 0:23 ` [RFC PATCH 6/9] rust: vmstate: add public utility macros to implement VMState Paolo Bonzini
2025-01-08 8:15 ` Zhao Liu
2024-12-31 0:23 ` [RFC PATCH 7/9] rust: qemu_api: add vmstate_struct and vmstate_cell Paolo Bonzini
2025-01-07 16:49 ` Paolo Bonzini
2024-12-31 0:23 ` [RFC PATCH 8/9] rust: pl011: switch vmstate to new-style macros Paolo Bonzini
2025-01-08 8:27 ` Zhao Liu
2024-12-31 0:23 ` [RFC PATCH 9/9] rust: vmstate: remove translation of C vmstate macros Paolo Bonzini
2025-01-08 8:40 ` 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=Z4iuX5oTr2r5B569@intel.com \
--to=zhao1.liu@intel.com \
--cc=junjie.mao@hotmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.