From: Zhao Liu <zhao1.liu@intel.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>,
qemu-devel@nongnu.org, qemu-rust@nongnu.org,
Zhao Liu <zhao1.liu@intel.com>
Subject: [PATCH 00/22] rust/hpet: Move towards lockless IO, partly
Date: Thu, 13 Nov 2025 13:19:15 +0800 [thread overview]
Message-ID: <20251113051937.4017675-1-zhao1.liu@intel.com> (raw)
Hi,
This series tries to (partly) synchronize the lockless IO of the C HPET
to Rust HPET, and deploy Migratable<>/ToMigrationState to HPET.
It's "partly" because this series only uses Mutex<> to protect registers
and doesn't add SeqLock.
This series is based on master branch at the commit 9febfa94b69b ("Merge
tag 'for-upstream' of https://repo.or.cz/qemu/kevin into staging"). And
you can also find the code here:
https://gitlab.com/zhao.liu/qemu/-/tree/rust-hpet-refactor-v1-11-11-2025
Thanks for your review!
Overview
========
1. Replacing BqlRefCell<single register> with Mutex<HPETregisters>
------------------------------------------------------------------
In fact, the most part of this series is to convert
BqlCell<single register> to BqlRefCell<HPETRegisters>. The difference
between the two includes:
* BqlCell<> is used for quick access but BqlRefCell<> would involve
the reference with bigger scope.
* BqlRefCell<> doesn't allow multiple borrowing, which requires to take
care about lifetime management.
* Placing all registers in HPETRegisters makes it more complex to
justify reference lifetime.
However, once the conversion is complete, we only need to borrow
BqlRefCell<> once during MMIO read/write operations. This makes replacing
BqlRefCell<> with Mutex<> a straightforward way.
And to address BQL context issue during lockless IO (like commit
d99041a20328 ("hpet: guard IRQ handling with BQL")), this series
introduce BqlGuard to provide BQL context by hand.
But there's "difference": Rust HPET has stronger BQL guarantees and it
uses BqlCell<> and BqlRefCell<> for many fields of HPETState, so that
Rust HPET needs to provide BQL context for more cases that C HPET (which
just guards IRQ handling). More details, please review Patch 22.
2. Leverage Migartable<> and ToMigrationState
---------------------------------------------
This series uses Migratable<> twice:
* Patch 20 applies Migratable<> for BqlRefCell<>.
* Patch 21 applies Migratable<> for Mutex<>.
Migrable<> and ToMigrationState work well at the above cases.
But there's one thing still missing (I just remember this when I'm writng
this cover letter):
* ToMigrationState for Timer
The timer's ToMigrationState would be added in v2 or in a seperate
patch.
Open Question
=============
I'm still a bit unsure - can we provide a property option to control
whether ToMigrationState automatically generates VMState, for simple
case without version/subsection consideration?
In this series, I implemented VMState for HPETTimerRegistersMigration
and HPETRegistersMigration by hand. But doing such thing by hand for the
generated struts seems not natural enough.
Thanks and Best Regards,
Zhao
---
Zhao Liu (22):
rust/migration: Add Sync implementation for Migratable<>
rust/migration: Fix missing name in the VMSD of Migratable<>
rust/migration: Check name field in VMStateDescriptionBuilder
rust/bql: Add BqlGuard to provide BQL context
rust/bql: Ensure BQL locked early at BqlRefCell borrowing
rust/memory: Add enable_lockless_io binding
rust/hpet: Reduce unnecessary mutable self argument
rust/hpet: Rename HPETRegister to DecodedRegister
rust/hpet: Rename decoded "reg" enumeration to "target"
rust/hpet: Abstract HPETTimerRegisters struct
rust/hpet: Make timer register accessors as methods of
HPETTimerRegisters
rust/hpet: Abstract HPETRegisters struct
rust/hpet: Make global register accessors as methods of HPETRegisters
rust/hpet: Borrow HPETState.regs once in HPETState::post_load()
rust/hpet: Explicitly initialize complex fields in init()
rust/hpet: Pass &BqlRefCell<HPETRegisters> as argument during MMIO
access
rust/hpet: Maintain HPETTimerRegisters in HPETRegisters
rust/hpet: Borrow BqlRefCell<HPETRegisters> at top level
rust/hpet: Rename hpet_regs variables to regs
rust/hpet: Apply Migratable<> wrapper and ToMigrationState for
HPETRegisters
rust/hpet: Replace BqlRefCell<HPETRegisters> with Mutex<HPETRegisters>
rust/hpet: Enable lockless IO
include/qemu/main-loop.h | 22 +-
rust/bql/src/cell.rs | 16 +-
rust/bql/src/lib.rs | 101 ++++-
rust/hw/timer/hpet/src/device.rs | 638 +++++++++++++++++++------------
rust/migration/src/migratable.rs | 7 +
rust/migration/src/vmstate.rs | 15 +-
rust/system/src/memory.rs | 15 +-
stubs/iothread-lock.c | 11 +
system/cpus.c | 10 +
9 files changed, 583 insertions(+), 252 deletions(-)
--
2.34.1
next reply other threads:[~2025-11-13 5:03 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 5:19 Zhao Liu [this message]
2025-11-13 5:19 ` [PATCH 01/22] rust/migration: Add Sync implementation for Migratable<> Zhao Liu
2025-11-13 5:19 ` [PATCH 02/22] rust/migration: Fix missing name in the VMSD of Migratable<> Zhao Liu
2025-11-13 5:19 ` [PATCH 03/22] rust/migration: Check name field in VMStateDescriptionBuilder Zhao Liu
2025-11-13 5:19 ` [PATCH 04/22] rust/bql: Add BqlGuard to provide BQL context Zhao Liu
2025-11-13 5:19 ` [PATCH 05/22] rust/bql: Ensure BQL locked early at BqlRefCell borrowing Zhao Liu
2025-11-13 5:19 ` [PATCH 06/22] rust/memory: Add enable_lockless_io binding Zhao Liu
2025-11-13 5:19 ` [PATCH 07/22] rust/hpet: Reduce unnecessary mutable self argument Zhao Liu
2025-11-13 5:19 ` [PATCH 08/22] rust/hpet: Rename HPETRegister to DecodedRegister Zhao Liu
2025-11-13 5:19 ` [PATCH 09/22] rust/hpet: Rename decoded "reg" enumeration to "target" Zhao Liu
2025-11-13 5:19 ` [PATCH 10/22] rust/hpet: Abstract HPETTimerRegisters struct Zhao Liu
2025-11-13 11:24 ` Paolo Bonzini
2025-11-14 4:37 ` Zhao Liu
2025-11-15 7:54 ` Paolo Bonzini
2025-11-13 5:19 ` [PATCH 11/22] rust/hpet: Make timer register accessors as methods of HPETTimerRegisters Zhao Liu
2025-11-13 5:19 ` [PATCH 12/22] rust/hpet: Abstract HPETRegisters struct Zhao Liu
2025-11-13 5:19 ` [PATCH 13/22] rust/hpet: Make global register accessors as methods of HPETRegisters Zhao Liu
2025-11-13 5:19 ` [PATCH 14/22] rust/hpet: Borrow HPETState.regs once in HPETState::post_load() Zhao Liu
2025-11-13 5:19 ` [PATCH 15/22] rust/hpet: Explicitly initialize complex fields in init() Zhao Liu
2025-11-13 5:19 ` [PATCH 16/22] rust/hpet: Pass &BqlRefCell<HPETRegisters> as argument during MMIO access Zhao Liu
2025-11-13 5:19 ` [PATCH 17/22] rust/hpet: Maintain HPETTimerRegisters in HPETRegisters Zhao Liu
2025-11-13 5:19 ` [PATCH 18/22] rust/hpet: Borrow BqlRefCell<HPETRegisters> at top level Zhao Liu
2025-11-13 5:19 ` [PATCH 19/22] rust/hpet: Rename hpet_regs variables to regs Zhao Liu
2025-11-13 5:19 ` [PATCH 20/22] rust/hpet: Apply Migratable<> wrapper and ToMigrationState for HPETRegisters Zhao Liu
2025-11-13 5:19 ` [PATCH 21/22] rust/hpet: Replace BqlRefCell<HPETRegisters> with Mutex<HPETRegisters> Zhao Liu
2025-11-13 9:31 ` Zhao Liu
2025-11-13 11:36 ` Zhao Liu
2025-11-13 5:19 ` [PATCH 22/22] rust/hpet: Enable lockless IO Zhao Liu
2025-11-13 14:29 ` Paolo Bonzini
2025-11-14 6:39 ` 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=20251113051937.4017675-1-zhao1.liu@intel.com \
--to=zhao1.liu@intel.com \
--cc=imammedo@redhat.com \
--cc=manos.pitsidianakis@linaro.org \
--cc=marcandre.lureau@redhat.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).