i386, rust changes for 2024-01-24
The following changes since commit d6430c17d7113d3c38480dc34e59d00b0504e2f7:
Merge tag 'pull-riscv-to-apply-20250119-1' of https://github.com/alistair23/qemu into staging (2025-01-19 08:55:46 -0500)
are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to 021d8e747907d4a2226557bf9885d4c0fa6abd8b:
rust: qemu-api: add sub-subclass to the integration tests (2025-01-28 12:22:54 +0100)
----------------------------------------------------------------
* target/i386: optimize string instructions
* target/i386: new Sierra Forest and Clearwater Forest models
* rust: type-safe vmstate implementation
* rust: use interior mutability for PL011
* rust: clean ups
* memtxattrs: remove usage of bitfields from MEMTXATTRS_UNSPECIFIED
----------------------------------------------------------------
Paolo Bonzini (37):
rust: pl011: fix repr(C) for PL011Class
target/i386: inline gen_jcc into sole caller
target/i386: remove trailing 1 from gen_{j, cmov, set}cc1 target/i386: unify REP and REPZ/REPNZ generation
target/i386: unify choice between single and repeated string instructions target/i386: reorganize ops emitted by do_gen_rep, drop repz_opt target/i386: tcg: move gen_set/reset_* earlier in the file target/i386: fix RF handling for string instructions
target/i386: make cc_op handling more explicit for repeated string instructions. target/i386: do not use gen_op_jz_ecx for repeated string operations target/i386: optimize CX handling in repeated string operations target/i386: execute multiple REP/REPZ iterations without leaving TB target/i386: pull computation of string update value out of loop target/i386: extract common bits of gen_repz/gen_repz_nz target/i386: avoid using s->tmp0 for add to implicit registers
rust: vmstate: add new type safe implementation
rust: vmstate: implement VMState for non-leaf types
rust: vmstate: add varray support to vmstate_of!
rust: vmstate: implement Zeroable for VMStateField
rust: vmstate: implement VMState for scalar types
rust: vmstate: add public utility macros to implement VMState
rust: qemu_api: add vmstate_struct
rust: pl011: switch vmstate to new-style macros
rust: vmstate: remove translation of C vmstate macros
rust: vmstate: make order of parameters consistent in vmstate_clock
rust: prefer NonNull::new to assertions
rust: pl011: remove unnecessary "extern crate"
rust: pl011: hide unnecessarily "pub" items from outside pl011::device
rust: pl011: extract conversion to RegisterOffset
rust: pl011: extract CharBackend receive logic into a separate function
rust: pl011: pull interrupt updates out of read/write ops
rust: pl011: extract PL011Registers
rust: pl011: wrap registers with BqlRefCell
rust: pl011: remove duplicate definitions
rust: pl011: pull device-specific code out of MemoryRegionOps callbacks
rust: pl011: drop use of ControlFlow
rust: qdev: make reset take a shared reference
Tao Su (4):
target/i386: Introduce SierraForest-v2 model target/i386: Export BHI_NO bit to guests target/i386: Add new CPU model ClearwaterForest
docs: Add GNR, SRF and CWF CPU models
Zhao Liu (7):
stub: Fix build failure with --enable-user --disable-system --enable-tools rust/qdev: Make REALIZE safe
rust/pl011: Avoid bindings::*
memattrs: Convert unspecified member to bool
memattrs: Check the size of MemTxAttrs
rust/zeroable: Implement Zeroable with const_zero macro
rust: qemu-api: add sub-subclass to the integration tests
docs/system/cpu-models-x86.rst.inc | 50 ++- include/exec/memattrs.h | 21 +- target/i386/cpu.h | 33 +- target/i386/cpu.c | 156 +++++++- target/i386/tcg/translate.c | 363 ++++++++++------- target/i386/tcg/emit.c.inc | 55 +-- rust/hw/char/pl011/src/device.rs | 509 +++++++++++++----------- rust/hw/char/pl011/src/device_class.rs | 73 ++-- rust/hw/char/pl011/src/lib.rs | 69 ++-- rust/hw/char/pl011/src/memory_ops.rs | 25 +- rust/qemu-api/src/prelude.rs | 2 + rust/qemu-api/src/qdev.rs | 16 +- rust/qemu-api/src/qom.rs | 21 +- rust/qemu-api/src/vmstate.rs | 700 +++++++++++++++++++++------------ rust/qemu-api/src/zeroable.rs | 118 +++--- rust/qemu-api/tests/tests.rs | 56 ++- stubs/meson.build | 4 +- 17 files changed, 1416 insertions(+), 855 deletions(-)
Signature · 1 line
2.48.1
[PULL 38/48] rust: pl011: extract conversion to RegisterOffset
As an added bonus, this also makes the new function return u32 instead of u64, thus factoring some casts into a single place.
--- rust/hw/char/pl011/src/device.rs | 137 ++++++++++++++++++------------- rust/hw/char/pl011/src/lib.rs | 2 +- 2 files changed, 79 insertions(+), 60 deletions(-)
rust/hw/char/pl011/src/device.rs +78 -59
@@ -5,6 +5,7 @@use core::ptr::{addr_of, addr_of_mut,NonNull };use std::{ ffi::CStr , + ops::ControlFlow , os::raw::{c_int, c_uint, c_void}, };
@@ -222,19 +223,11 @@ fn post_init(&self) { } } -pub fn read (&mut self, offset:hwaddr , _size:c_uint ) -> std::ops::ControlFlow <u64 ,u64 > { +fn regs_read (&mut self, offset:RegisterOffset ) ->ControlFlow <u32 ,u32 > {use RegisterOffset ::*; -let value =match RegisterOffset ::try_from (offset) { -Err (v)if (0x3f8 ..0x400 ).contains (&(v >>2 )) => { -let device_id = self.get_class ().device_id; - u32::from (device_id[(offset -0xfe0 ) >>2 ]) - } -Err (_) => { -// qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); -0 - } -Ok (DR ) => { +ControlFlow ::Break (match offset { +DR => { self.flags.set_receive_fifo_full (false );let c = self.read_fifo[self.read_pos];if self.read_count >0 {
@@ -251,69 +244,53 @@ pub fn read(&mut self, offset: hwaddr, _size: c_uint) -> std::ops::ControlFlow<u self.receive_status_error_clear.set_from_data (c); self.update ();// Must call qemu_chr_fe_accept_input, so return Continue: -let c = u32::from (c); -return std::ops::ControlFlow ::Continue (u64::from (c)); +return ControlFlow ::Continue (u32::from (c)); } - Ok(RSR) => u32::from(self.receive_status_error_clear), - Ok(FR) => u32::from(self.flags), - Ok(FBRD) => self.fbrd, - Ok(ILPR) => self.ilpr, - Ok(IBRD) => self.ibrd, - Ok(LCR_H) => u32::from(self.line_control), - Ok(CR) => u32::from(self.control), - Ok(FLS) => self.ifl, - Ok(IMSC) => self.int_enabled, - Ok(RIS) => self.int_level, - Ok(MIS) => self.int_level & self.int_enabled, - Ok(ICR) => { + RSR => u32::from(self.receive_status_error_clear), + FR => u32::from(self.flags), + FBRD => self.fbrd, + ILPR => self.ilpr, + IBRD => self.ibrd, + LCR_H => u32::from(self.line_control), + CR => u32::from(self.control), + FLS => self.ifl, + IMSC => self.int_enabled, + RIS => self.int_level, + MIS => self.int_level & self.int_enabled, + ICR => {// "The UARTICR Register is the interrupt clear register and is write-only" // Source: ARM DDI 0183G 3.3.13 Interrupt Clear Register, UARTICR 0 } - Ok(DMACR) => self.dmacr, - }; - std::ops::ControlFlow ::Break (value.into ()) + DMACR => self.dmacr, + }) } -pub fn write (&mut self, offset:hwaddr , value:u64 ) { +fn regs_write (&mut self, offset:RegisterOffset , value:u32 ) {// eprintln!("write offset {offset} value {value}"); use RegisterOffset ::*; -let value:u32 = valueas u32 ; -match RegisterOffset ::try_from (offset) { -Err (_bad_offset) => { -eprintln! ("write bad offset {offset} value {value}" ); - } -Ok (DR ) => { -// ??? Check if transmitter is enabled. -let ch:u8 = valueas u8 ; -// XXX this blocks entire thread. Rewrite to use -// qemu_chr_fe_write and background I/O callbacks - -// SAFETY: self.char_backend is a valid CharBackend instance after it's been -// initialized in realize(). -unsafe { -qemu_chr_fe_write_all (addr_of_mut! (self.char_backend), &ch,1 ); - } +match offset { +DR => { self.loopback_tx (value); self.int_level |= registers::INT_TX ; self.update (); } -Ok (RSR ) => { - self.receive_status_error_clear.reset (); +RSR => { + self.receive_status_error_clear =0 .into (); } -Ok (FR ) => { +FR => {// flag writes are ignored } -Ok (ILPR ) => { +ILPR => { self.ilpr = value; } -Ok (IBRD ) => { +IBRD => { self.ibrd = value; } -Ok (FBRD ) => { +FBRD => { self.fbrd = value; } -Ok (LCR_H ) => { +LCR_H => {let new_val: registers::LineControl = value.into ();// Reset the FIFO state on FIFO enable or disable if self.line_control.fifos_enabled () != new_val.fifos_enabled () {
@@ -336,26 +313,26 @@ pub fn write(&mut self, offset: hwaddr, value: u64) { self.line_control = new_val; self.set_read_trigger (); } - Ok(CR) => { + CR => {// ??? Need to implement the enable bit. self.control = value.into (); self.loopback_mdmctrl (); } - Ok(FLS) => { + FLS => { self.ifl = value; self.set_read_trigger (); } - Ok(IMSC) => { + IMSC => { self.int_enabled = value; self.update (); } - Ok(RIS) => {} - Ok(MIS) => {} - Ok(ICR) => { + RIS => {} + MIS => {} + ICR => { self.int_level &= !value; self.update(); } - Ok(DMACR) => { + DMACR => { self.dmacr = value; if value & 3 > 0 { // qemu_log_mask(LOG_UNIMP, "pl011: DMA not implemented\n");
@@ -570,6 +547,48 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> {Ok (()) } + +pub fn read (&mut self, offset:hwaddr , _size:u32 ) ->ControlFlow <u64 ,u64 > { +match RegisterOffset ::try_from (offset) { +Err (v)if (0x3f8 ..0x400 ).contains (&(v >>2 )) => { +let device_id = self.get_class ().device_id; +ControlFlow ::Break (u64::from (device_id[(offset -0xfe0 ) >>2 ])) + } +Err (_) => { +// qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); +ControlFlow ::Break (0 ) + } +Ok (field) => { +let result = self.regs_read (field); +match result { +ControlFlow ::Break (value) =>ControlFlow ::Break (value.into ()), +ControlFlow ::Continue (value) =>ControlFlow ::Continue (value.into ()), + } + } + } + } + +pub fn write (&mut self, offset:hwaddr , value:u64 ) { +if let Ok (field) =RegisterOffset ::try_from (offset) { +// qemu_chr_fe_write_all() calls into the can_receive +// callback, so handle writes before entering PL011Registers. +if field ==RegisterOffset ::DR { +// ??? Check if transmitter is enabled. +let ch:u8 = valueas u8 ; +// SAFETY: char_backend is a valid CharBackend instance after it's been +// initialized in realize(). +// XXX this blocks entire thread. Rewrite to use +// qemu_chr_fe_write and background I/O callbacks +unsafe { +qemu_chr_fe_write_all (&mut self.char_backend, &ch,1 ); + } + } + + self.regs_write (field, valueas u32 ); + }else { +eprintln! ("write bad offset {offset} value {value}" ); + } + } }/// Which bits in the interrupt status matter for each outbound IRQ line ?
rust/hw/char/pl011/src/lib.rs +1 -1
@@ -43,7 +43,7 @@#[doc(alias = "offset" )] #[allow(non_camel_case_types)] #[repr( u64 )] -#[derive( Debug , qemu_api_macros:: TryInto )] +#[derive( Debug , Eq , PartialEq , qemu_api_macros:: TryInto )] enum RegisterOffset {/// Data Register ///
Signature · 1 line
2.48.1
Quoted 5 lines · Paolo Bonzini
The following changes since commit
d6430c17d7113d3c38480dc34e59d00b0504e2f7:Merge tag 'pull-riscv-to-apply-20250119-1' of https://github.com/alistair23/qemu into staging (2025-01-19 08:55:46 -0500)
Quoted 7 lines
are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to
021d8e747907d4a2226557bf9885d4c0fa6abd8b:rust: qemu-api: add sub-subclass to the integration tests (2025-01-28 12:22:54 +0100)
CI is hitting the following failure (see default.log):
thread '<unnamed>' panicked at 'already borrowed', rust/qemu-api/libqemu_api.rlib.p/structured/cell.rs:450:5
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace fatal runtime error: failed to initiate panic, error 5
Do you want to include a patch that sets RUST_BACKTRACE=1 in the test environment so the backtrace is captured in the logs?
Thanks,
Stefan
Quoted 86 lines
----------------------------------------------------------------
* target/i386: optimize string instructions
* target/i386: new Sierra Forest and Clearwater Forest models
* rust: type-safe vmstate implementation
* rust: use interior mutability for PL011
* rust: clean ups
* memtxattrs: remove usage of bitfields fromMEMTXATTRS_UNSPECIFIED----------------------------------------------------------------
Paolo Bonzini (37):
rust: pl011: fix repr(C) for PL011Class
target/i386: inlinegen_jccinto sole caller
target/i386: remove trailing 1 from gen_{j, cmov, set}cc1 target/i386: unify REP and REPZ/REPNZ generation
target/i386: unify choice between single and repeated string instructions target/i386: reorganize ops emitted bydo_gen_rep, droprepz_opttarget/i386: tcg: move gen_set/reset_* earlier in the file target/i386: fix RF handling for string instructions
target/i386: makecc_ophandling more explicit for repeated string instructions. target/i386: do not usegen_op_jz_ecxfor repeated string operations target/i386: optimize CX handling in repeated string operations target/i386: execute multiple REP/REPZ iterations without leaving TB target/i386: pull computation of string update value out of loop target/i386: extract common bits of gen_repz/gen_repz_nz target/i386: avoid usings->tmp0for add to implicit registers
rust: vmstate: add new type safe implementation
rust: vmstate: implement VMState for non-leaf types
rust: vmstate: add varray support tovmstate_of!
rust: vmstate: implement Zeroable for VMStateField
rust: vmstate: implement VMState for scalar types
rust: vmstate: add public utility macros to implement VMState
rust:qemu_api: addvmstate_struct
rust: pl011: switch vmstate to new-style macros
rust: vmstate: remove translation of C vmstate macros
rust: vmstate: make order of parameters consistent invmstate_clock
rust: preferNonNull::newto assertions
rust: pl011: remove unnecessary "extern crate"
rust: pl011: hide unnecessarily "pub" items from outsidepl011::device
rust: pl011: extract conversion to RegisterOffset
rust: pl011: extract CharBackend receive logic into a separate function
rust: pl011: pull interrupt updates out of read/write ops
rust: pl011: extract PL011Registers
rust: pl011: wrap registers with BqlRefCell
rust: pl011: remove duplicate definitions
rust: pl011: pull device-specific code out of MemoryRegionOps callbacks
rust: pl011: drop use of ControlFlow
rust: qdev: make reset take a shared referenceTao Su (4):
target/i386: Introduce SierraForest-v2 model target/i386: ExportBHI_NObit to guests target/i386: Add new CPU model ClearwaterForest
docs: Add GNR, SRF and CWF CPU modelsZhao Liu (7):
stub: Fix build failure with --enable-user --disable-system --enable-toolsrust/qdev: Make REALIZE safe
rust/pl011: Avoid bindings::*
memattrs: Convert unspecified member to bool
memattrs: Check the size of MemTxAttrs
rust/zeroable: Implement Zeroable withconst_zeromacro
rust: qemu-api: add sub-subclass to the integration testsdocs/system/cpu-models-x86.rst.inc | 50 ++- include/exec/memattrs.h | 21 +- target/i386/cpu.h | 33 +- target/i386/cpu.c | 156 +++++++- target/i386/tcg/translate.c | 363 ++++++++++------- target/i386/tcg/emit.c.inc | 55 +-- rust/hw/char/pl011/src/device.rs | 509 +++++++++++++----------- rust/hw/char/pl011/src/device_class.rs | 73 ++-- rust/hw/char/pl011/src/lib.rs | 69 ++-- rust/hw/char/pl011/src/memory_ops.rs | 25 +- rust/qemu-api/src/prelude.rs | 2 + rust/qemu-api/src/qdev.rs | 16 +- rust/qemu-api/src/qom.rs | 21 +- rust/qemu-api/src/vmstate.rs | 700 +++++++++++++++++++++------------ rust/qemu-api/src/zeroable.rs | 118 +++--- rust/qemu-api/tests/tests.rs | 56 ++- stubs/meson.build | 4 +- 17 files changed, 1416 insertions(+), 855 deletions(-)--
2.48.1
Quoted 6 lines · Stefan Hajnoczi
thread '<unnamed>' panicked at 'already borrowed',
rust/qemu-api/libqemu_api.rlib.p/structured/cell.rs:450:5
note: run withRUST_BACKTRACE=1environment variable to display a backtrace fatal runtime error: failed to initiate panic, error 5
Hmm, this one does not reproduce locally. I've started a QEMU_CI_AVOCADO_TESTING run.
Quoted 2 lines
Do you want to include a patch that sets RUST_BACKTRACE=1 in the test environment so the backtrace is captured in the logs?
Yeah, I'll send one in the next version of the pull request. The BqlRefCell issues are easy to track (because you cannot drop the BQL while you have an outstanding borrow, unlike regular Rust RefCells), but you do need a backtrace...
Paolo