i386, rust changes for 2024-01-24
Subsystems (2)
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 9feb68638e504c91b59e745b94423e8536abfd03:
rust: qemu-api: add sub-subclass to the integration tests (2025-01-23 19:07:39 +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 (39):
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
rust/zeroable: Implement Zeroable with const_zero macro
rust: qemu-api: add sub-subclass to the integration tests
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 (5):
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
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 | 489 +++++++++++++---------- rust/hw/char/pl011/src/device_class.rs | 73 ++-- rust/hw/char/pl011/src/lib.rs | 67 ++-- 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, 1403 insertions(+), 846 deletions(-)
Signature · 1 line
2.48.1
[PULL 01/48] rust: pl011: fix repr(C) for PL011Class
--- rust/hw/char/pl011/src/device.rs | 1 + 1 file changed, 1 insertion(+)
rust/hw/char/pl011/src/device.rs +1 -0
@@ -123,6 +123,7 @@ pub struct PL011State {qom_isa! (PL011State :SysBusDevice ,DeviceState ,Object ); +#[repr( C )] pub struct PL011Class { parent_class: <SysBusDevice as ObjectType >::Class ,/// The byte string that identifies the device.
Signature · 1 line
2.48.1
[PULL 04/48] target/i386: unify REP and REPZ/REPNZ generation
In reply to Paolo BonziniIt only differs in a single call to gen_jcc, so use a "bool" argument to distinguish the two cases; do not duplicate code.
--- target/i386/tcg/translate.c | 39 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-)
target/i386/tcg/translate.c +20 -19
@@ -1310,14 +1310,18 @@ static void gen_outs(DisasContext *s, MemOp ot)gen_bpt_io (s, s->tmp2_i32, ot); } -/* Generate jumps to current or next instruction */ -static void gen_repz (DisasContext *s,MemOp ot, -void (*fn)(DisasContext *s,MemOp ot)) +static void do_gen_rep (DisasContext *s,MemOp ot, +void (*fn)(DisasContext *s,MemOp ot), +bool is_repz_nz) {TCGLabel *l2; l2 =gen_jz_ecx_string (s);fn (s, ot);gen_op_add_reg_im (s, s->aflag,R_ECX ,-1 ); +if (is_repz_nz) { +int nz = (s->prefix &PREFIX_REPNZ ) ?1 :0 ; +gen_jcc (s, (JCC_Z <<1 ) | (nz ^1 ), l2); + }/* * A loop would cause two single step exceptions if ECX = 1 * before rep string_insn
@@ -1325,28 +1329,25 @@ static void gen_repz(DisasContext *s, MemOp ot,if (s->repz_opt) {gen_op_jz_ecx (s, l2); } +/* +* For CMPS/SCAS there is no need to set CC_OP_DYNAMIC: only one iteration +* is done at a time, so the translation block ends unconditionally after +* this instruction and there is no control flow junction. +*/ gen_jmp_rel_csize (s, -cur_insn_len (s),0 ); } +static void gen_repz (DisasContext *s,MemOp ot, +void (*fn)(DisasContext *s,MemOp ot)) + +{ +do_gen_rep (s, ot, fn, false); +} +static void gen_repz_nz (DisasContext *s,MemOp ot,void (*fn)(DisasContext *s,MemOp ot)) { -TCGLabel *l2; -int nz = (s->prefix &PREFIX_REPNZ ) ?1 :0 ; - - l2 =gen_jz_ecx_string (s); -fn (s, ot); -gen_op_add_reg_im (s, s->aflag,R_ECX ,-1 ); -gen_jcc (s, (JCC_Z <<1 ) | (nz ^1 ), l2); -if (s->repz_opt) { -gen_op_jz_ecx (s, l2); - } -/* -* Only one iteration is done at a time, so the translation -* block ends unconditionally after this instruction and there -* is no control flow junction - no need to set CC_OP_DYNAMIC. -*/ -gen_jmp_rel_csize (s, -cur_insn_len (s),0 ); +do_gen_rep (s, ot, fn, true); }static void gen_helper_fp_arith_ST0_FT0 (int op)
Signature · 1 line
2.48.1
[PULL 03/48] target/i386: remove trailing 1 from gen_{j, cmov, set}cc1
In reply to Paolo BonziniThis is not needed anymore now that gen_jcc has been eliminated (merged into the similarly-named gen_Jcc, where the uppercase letter gives away that it is an emission function).
--- target/i386/tcg/translate.c | 14 +++++++------- target/i386/tcg/emit.c.inc | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-)
target/i386/tcg/translate.c +7 -7
@@ -1148,7 +1148,7 @@ static CCPrepare gen_prepare_cc(DisasContext *s, int b, TCGv reg)return cc; } -static void gen_setcc1 (DisasContext *s,int b,TCGv reg) +static void gen_setcc (DisasContext *s,int b,TCGv reg) {CCPrepare cc =gen_prepare_cc (s, b, reg);
@@ -1170,12 +1170,12 @@ static void gen_setcc1(DisasContext *s, int b, TCGv reg)static inline void gen_compute_eflags_c (DisasContext *s,TCGv reg) { -gen_setcc1 (s,JCC_B <<1 , reg); +gen_setcc (s,JCC_B <<1 , reg); }/* generate a conditional jump to label 'l1' according to jump opcode value 'b'. In the fast case, T0 is guaranteed not to be used. */ -static inline void gen_jcc1_noeob (DisasContext *s,int b,TCGLabel *l1) +static inline void gen_jcc_noeob (DisasContext *s,int b,TCGLabel *l1) {CCPrepare cc =gen_prepare_cc (s, b,NULL );
@@ -1190,7 +1190,7 @@ static inline void gen_jcc1_noeob(DisasContext *s, int b, TCGLabel *l1)value 'b'. In the fast case, T0 is guaranteed not to be used. One or both of the branches will call gen_jmp_rel, so ensure cc_op is clean. */ -static inline void gen_jcc1 (DisasContext *s,int b,TCGLabel *l1) +static inline void gen_jcc (DisasContext *s,int b,TCGLabel *l1) {CCPrepare cc =gen_prepare_cc (s, b,NULL );
@@ -1337,7 +1337,7 @@ static void gen_repz_nz(DisasContext *s, MemOp ot, l2 =gen_jz_ecx_string (s);fn (s, ot);gen_op_add_reg_im (s, s->aflag,R_ECX ,-1 ); -gen_jcc1 (s, (JCC_Z <<1 ) | (nz ^1 ), l2); +gen_jcc (s, (JCC_Z <<1 ) | (nz ^1 ), l2);if (s->repz_opt) {gen_op_jz_ecx (s, l2); }
@@ -1847,7 +1847,7 @@ static void gen_conditional_jump_labels(DisasContext *s, target_long diff,gen_jmp_rel (s, s->dflag, diff,0 ); } -static void gen_cmovcc1 (DisasContext *s,int b,TCGv dest,TCGv src) +static void gen_cmovcc (DisasContext *s,int b,TCGv dest,TCGv src) {CCPrepare cc =gen_prepare_cc (s, b,NULL );
@@ -2856,7 +2856,7 @@ static void gen_x87(DisasContext *s, X86DecodedInsn *decode) } op1 = fcmov_cc[op &3 ] | (((op >>3 ) &1 ) ^1 ); l1 =gen_new_label (); -gen_jcc1_noeob (s, op1, l1); +gen_jcc_noeob (s, op1, l1);gen_helper_fmov_ST0_STN (tcg_env,tcg_constant_i32 (opreg));gen_set_label (l1);
target/i386/tcg/emit.c.inc +5 -5
@@ -1634,7 +1634,7 @@ static void gen_CMC(DisasContext *s, X86DecodedInsn *decode) static void gen_CMOVcc(DisasContext *s, X86DecodedInsn *decode) { - gen_cmovcc1(s, decode->b & 0xf, s->T0, s->T1); + gen_cmovcc(s, decode->b & 0xf, s->T0, s->T1); } static void gen_CMPccXADD(DisasContext *s, X86DecodedInsn *decode)
@@ -2300,7 +2300,7 @@ static void gen_Jcc(DisasContext *s, X86DecodedInsn *decode) TCGLabel *taken = gen_new_label(); gen_bnd_jmp(s); - gen_jcc1(s, decode->b & 0xf, taken); + gen_jcc(s, decode->b & 0xf, taken); gen_conditional_jump_labels(s, decode->immediate, NULL, taken); }
@@ -2451,7 +2451,7 @@ static void gen_LOOPE(DisasContext *s, X86DecodedInsn *decode) gen_update_cc_op(s); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); gen_op_jz_ecx(s, not_taken); - gen_jcc1(s, (JCC_Z << 1), taken); /* jz taken */ + gen_jcc(s, (JCC_Z << 1), taken); /* jz taken */ gen_conditional_jump_labels(s, decode->immediate, not_taken, taken); }
@@ -2463,7 +2463,7 @@ static void gen_LOOPNE(DisasContext *s, X86DecodedInsn *decode) gen_update_cc_op(s); gen_op_add_reg_im(s, s->aflag, R_ECX, -1); gen_op_jz_ecx(s, not_taken); - gen_jcc1(s, (JCC_Z << 1) | 1, taken); /* jnz taken */ + gen_jcc(s, (JCC_Z << 1) | 1, taken); /* jnz taken */ gen_conditional_jump_labels(s, decode->immediate, not_taken, taken); }
@@ -3888,7 +3888,7 @@ static void gen_SCAS(DisasContext *s, X86DecodedInsn *decode) static void gen_SETcc(DisasContext *s, X86DecodedInsn *decode) { - gen_setcc1(s, decode->b & 0xf, s->T0); + gen_setcc(s, decode->b & 0xf, s->T0); } static void gen_SFENCE(DisasContext *s, X86DecodedInsn *decode)
Signature · 1 line
2.48.1
[PULL 02/48] target/i386: inline gen_jcc into sole caller
In reply to Paolo BonziniThe code of gen_Jcc is very similar to gen_LOOP* and gen_JCXZ, but this is hidden by gen_jcc.
--- target/i386/tcg/translate.c | 8 -------- target/i386/tcg/emit.c.inc | 5 ++++- 2 files changed, 4 insertions(+), 9 deletions(-)
target/i386/tcg/translate.c +0 -8
@@ -1847,14 +1847,6 @@ static void gen_conditional_jump_labels(DisasContext *s, target_long diff,gen_jmp_rel (s, s->dflag, diff,0 ); } -static void gen_jcc (DisasContext *s,int b,int diff) -{ -TCGLabel *l1 =gen_new_label (); - -gen_jcc1 (s, b, l1); -gen_conditional_jump_labels (s, diff,NULL , l1); -} -static void gen_cmovcc1 (DisasContext *s,int b,TCGv dest,TCGv src) {CCPrepare cc =gen_prepare_cc (s, b,NULL );
target/i386/tcg/emit.c.inc +4 -1
@@ -2297,8 +2297,11 @@ static void gen_IRET(DisasContext *s, X86DecodedInsn *decode) static void gen_Jcc(DisasContext *s, X86DecodedInsn *decode) { + TCGLabel *taken = gen_new_label(); + gen_bnd_jmp(s); - gen_jcc(s, decode->b & 0xf, decode->immediate); + gen_jcc1(s, decode->b & 0xf, taken); + gen_conditional_jump_labels(s, decode->immediate, NULL, taken); } static void gen_JCXZ(DisasContext *s, X86DecodedInsn *decode)
Signature · 1 line
2.48.1
[PULL 18/48] target/i386: Add new CPU model ClearwaterForest
In reply to Paolo BonziniFrom: Tao Su <[email protected]>
According to table 1-2 in Intel Architecture Instruction Set Extensions and Future Features (rev 056) [1], ClearwaterForest has the following new features which have already been virtualized:
- AVX-VNNI-INT16 CPUID.(EAX=7,ECX=1):EDX[bit 10]
- SHA512 CPUID.(EAX=7,ECX=1):EAX[bit 0]
- SM3 CPUID.(EAX=7,ECX=1):EAX[bit 1]
- SM4 CPUID.(EAX=7,ECX=1):EAX[bit 2]
Add above features to new CPU model ClearwaterForest. Comparing with SierraForest, ClearwaterForest bare-metal contains all features of SierraForest-v2 CPU model and adds:
- PREFETCHI CPUID.(EAX=7,ECX=1):EDX[bit 14]
- DDPD_U CPUID.(EAX=7,ECX=2):EDX[bit 3]
- BHI_NO IA32_ARCH_CAPABILITIES[bit 20]
Add above and all features of SierraForest-v2 CPU model to new CPU model ClearwaterForest.
[1] https://cdrdv2.intel.com/v1/dl/getContent/671368
--- target/i386/cpu.h | 33 +++++++++--- target/i386/cpu.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 6 deletions(-)
target/i386/cpu.h +27 -6
@@ -951,6 +951,12 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);/* Speculative Store Bypass Disable */ #define CPUID_7_0_EDX_SPEC_CTRL_SSBD (1U << 31) +/* SHA512 Instruction */ +#define CPUID_7_1_EAX_SHA512 (1U << 0) +/* SM3 Instruction */ +#define CPUID_7_1_EAX_SM3 (1U << 1) +/* SM4 Instruction */ +#define CPUID_7_1_EAX_SM4 (1U << 2)/* AVX VNNI Instruction */ #define CPUID_7_1_EAX_AVX_VNNI (1U << 4)/* AVX512 BFloat16 Instruction */
@@ -963,6 +969,12 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);#define CPUID_7_1_EAX_FSRS (1U << 11)/* Fast Short REP CMPS/SCAS */ #define CPUID_7_1_EAX_FSRC (1U << 12) +/* Flexible return and event delivery (FRED) */ +#define CPUID_7_1_EAX_FRED (1U << 17) +/* Load into IA32_KERNEL_GS_BASE (LKGS) */ +#define CPUID_7_1_EAX_LKGS (1U << 18) +/* Non-Serializing Write to Model Specific Register (WRMSRNS) */ +#define CPUID_7_1_EAX_WRMSRNS (1U << 19)/* Support Tile Computational Operations on FP16 Numbers */ #define CPUID_7_1_EAX_AMX_FP16 (1U << 21)/* Support for VPMADD52[H,L]UQ */
@@ -976,17 +988,23 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);#define CPUID_7_1_EDX_AVX_NE_CONVERT (1U << 5)/* AMX COMPLEX Instructions */ #define CPUID_7_1_EDX_AMX_COMPLEX (1U << 8) +/* AVX-VNNI-INT16 Instructions */ +#define CPUID_7_1_EDX_AVX_VNNI_INT16 (1U << 10)/* PREFETCHIT0/1 Instructions */ #define CPUID_7_1_EDX_PREFETCHITI (1U << 14)/* Support for Advanced Vector Extensions 10 */ #define CPUID_7_1_EDX_AVX10 (1U << 19) -/* Flexible return and event delivery (FRED) */ -#define CPUID_7_1_EAX_FRED (1U << 17) -/* Load into IA32_KERNEL_GS_BASE (LKGS) */ -#define CPUID_7_1_EAX_LKGS (1U << 18) -/* Non-Serializing Write to Model Specific Register (WRMSRNS) */ -#define CPUID_7_1_EAX_WRMSRNS (1U << 19) +/* Indicate bit 7 of the IA32_SPEC_CTRL MSR is supported */ +#define CPUID_7_2_EDX_PSFD (1U << 0) +/* Indicate bits 3 and 4 of the IA32_SPEC_CTRL MSR are supported */ +#define CPUID_7_2_EDX_IPRED_CTRL (1U << 1) +/* Indicate bits 5 and 6 of the IA32_SPEC_CTRL MSR are supported */ +#define CPUID_7_2_EDX_RRSBA_CTRL (1U << 2) +/* Indicate bit 8 of the IA32_SPEC_CTRL MSR is supported */ +#define CPUID_7_2_EDX_DDPD_U (1U << 3) +/* Indicate bit 10 of the IA32_SPEC_CTRL MSR is supported */ +#define CPUID_7_2_EDX_BHI_CTRL (1U << 4)/* Do not exhibit MXCSR Configuration Dependent Timing (MCDT) behavior */ #define CPUID_7_2_EDX_MCDT_NO (1U << 5)
@@ -1144,7 +1162,10 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w);#define MSR_ARCH_CAP_FBSDP_NO (1U << 14)#define MSR_ARCH_CAP_PSDP_NO (1U << 15)#define MSR_ARCH_CAP_FB_CLEAR (1U << 17) +#define MSR_ARCH_CAP_BHI_NO (1U << 20)#define MSR_ARCH_CAP_PBRSB_NO (1U << 24) +#define MSR_ARCH_CAP_GDS_NO (1U << 26) +#define MSR_ARCH_CAP_RFDS_NO (1U << 27)#define MSR_CORE_CAP_SPLIT_LOCK_DETECT (1U << 5)
target/i386/cpu.c +135 -0
141 lines not on this page · raw message
Signature · 1 line
2.48.1
[PULL 22/48] rust/pl011: Avoid bindings::*
In reply to Paolo BonziniFrom: Zhao Liu <[email protected]>
List all the necessary bindings to better identify gaps in rust/qapi. And include the bindings wrapped by rust/qapi instead mapping the raw bindings directly.
--- rust/hw/char/pl011/src/device.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
rust/hw/char/pl011/src/device.rs +10 -3
@@ -9,12 +9,19 @@ };use qemu_api::{ - bindings::{self, *}, + bindings::{ + error_fatal, hwaddr, memory_region_init_io, qdev_init_clock_in, qdev_new, + qdev_prop_set_chr, qemu_chr_fe_ioctl, qemu_chr_fe_set_handlers, qemu_chr_fe_write_all, + qemu_irq, sysbus_connect_irq, sysbus_mmio_map, sysbus_realize_and_unref,CharBackend , +Chardev ,Clock ,ClockEvent ,MemoryRegion ,QEMUChrEvent ,CHR_IOCTL_SERIAL_SET_BREAK , + }, c_str, irq::InterruptSource , prelude::*, - qdev::DeviceImpl , + qdev::{DeviceImpl ,DeviceState ,Property }, qom::{ClassInitImpl ,ObjectImpl ,ParentField }, + sysbus::{SysBusDevice ,SysBusDeviceClass }, + vmstate::VMStateDescription , };use crate ::{
@@ -494,7 +501,7 @@ pub fn can_receive(&self) -> bool { }pub fn event (&mut self, event:QEMUChrEvent ) { -if event == bindings::QEMUChrEvent ::CHR_EVENT_BREAK && !self.loopback_enabled () { +if event ==QEMUChrEvent ::CHR_EVENT_BREAK && !self.loopback_enabled () { self.put_fifo (registers::Data ::BREAK .into ()); } }
Signature · 1 line
2.48.1
[PULL 09/48] target/i386: make cc_op handling more explicit for repeated string instructions.
In reply to Paolo BonziniSince the cost of gen_update_cc_op() must be paid anyway, it's easier to place them manually and not rely on spilling that is buried under multiple levels of function calls. While at it, clarify the circumstances in which the gen_update_cc_op() is needed, and why it is not for REPxx SCAS and REPxx CMPS.
And since cc_op will have been spilled at the point of a fault, just make the whole insn CC_OP_DYNAMIC. Once repz_opt is reintroduced, a fault could happen either before or after the first execution of CMPS/SCAS, and CC_OP_DYNAMIC sidesteps the complicated matter of what x86_restore_state_to_opc would do.
--- target/i386/tcg/translate.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
target/i386/tcg/translate.c +21 -3
@@ -1234,8 +1234,9 @@ static inline void gen_jcc(DisasContext *s, int b, TCGLabel *l1)CCPrepare cc =gen_prepare_cc (s, b,NULL );/* -* Note that this must be _after_ gen_prepare_cc, because it -* can change the cc_op from CC_OP_DYNAMIC to CC_OP_EFLAGS! +* Note that this must be _after_ gen_prepare_cc, because it can change +* the cc_op to CC_OP_EFLAGS (because it's CC_OP_DYNAMIC or because +* it's cheaper to just compute the flags)! */ gen_update_cc_op (s);if (cc.use_reg2) {
@@ -1346,14 +1347,31 @@ static void do_gen_rep(DisasContext *s, MemOp ot,*/ s->flags &= ~HF_RF_MASK ; +/* +* For CMPS/SCAS, the CC_OP after a memory fault could come from either +* the previous instruction or the string instruction; but because we +* arrange to keep CC_OP up to date all the time, just mark the whole +* insn as CC_OP_DYNAMIC. +* +* It's not a problem to do this even for instructions that do not +* modify the flags, so do it unconditionally. +*/ gen_update_cc_op (s); +tcg_set_insn_start_param (s->base.insn_start,1 ,CC_OP_DYNAMIC ); + +/* Any iteration at all? */ gen_op_jz_ecx (s, done);fn (s, ot);gen_op_add_reg_im (s, s->aflag,R_ECX ,-1 ); +gen_update_cc_op (s); + +/* Leave if REP condition fails. */ if (is_repz_nz) {int nz = (s->prefix &PREFIX_REPNZ ) ?1 :0 ; -gen_jcc (s, (JCC_Z <<1 ) | (nz ^1 ), done); +gen_jcc_noeob (s, (JCC_Z <<1 ) | (nz ^1 ), done); +/* gen_prepare_eflags_z never changes cc_op. */ +assert (!s->cc_op_dirty); }/*
Signature · 1 line
2.48.1
[PULL 08/48] target/i386: fix RF handling for string instructions
In reply to Paolo BonziniRF must be set on traps and interrupts from a string instruction, except if they occur after the last iteration. Ensure it is set before giving the main loop a chance to execute.
--- target/i386/tcg/translate.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
target/i386/tcg/translate.c +21 -1
@@ -1337,6 +1337,14 @@ static void do_gen_rep(DisasContext *s, MemOp ot, bool is_repz_nz) {TCGLabel *done =gen_new_label (); +bool had_rf = s->flags &HF_RF_MASK ; + +/* +* Even if EFLAGS.RF was set on entry (such as if we're on the second or +* later iteration and an exception or interrupt happened), force gen_eob() +* not to clear the flag. We do that ourselves after the last iteration. +*/ + s->flags &= ~HF_RF_MASK ;gen_update_cc_op (s);gen_op_jz_ecx (s, done);
@@ -1348,12 +1356,24 @@ static void do_gen_rep(DisasContext *s, MemOp ot,gen_jcc (s, (JCC_Z <<1 ) | (nz ^1 ), done); } +/* +* Traps or interrupts set RF_MASK if they happen after any iteration +* but the last. Set it here before giving the main loop a chance to +* execute. (For faults, seg_helper.c sets the flag as usual). +*/ +if (!had_rf) { +gen_set_eflags (s,RF_MASK ); + } +/* Go to the main loop but reenter the same instruction. */ gen_jmp_rel_csize (s, -cur_insn_len (s),0 );/* CX/ECX/RCX is zero, or REPZ/REPNZ broke the repetition. */ gen_set_label (done);set_cc_op (s,CC_OP_DYNAMIC ); +if (had_rf) { +gen_reset_eflags (s,RF_MASK ); + }gen_jmp_rel_csize (s,0 ,1 ); }
@@ -2158,7 +2178,7 @@ gen_eob(DisasContext *s, int mode)gen_set_hflag (s,HF_INHIBIT_IRQ_MASK ); } -if (s->base.tb->flags &HF_RF_MASK ) { +if (s->flags &HF_RF_MASK ) {gen_reset_eflags (s,RF_MASK ); }if (mode ==DISAS_EOB_RECHECK_TF ) {
Signature · 1 line
2.48.1
[PULL 26/48] rust: vmstate: implement VMState for non-leaf types
In reply to Paolo BonziniArrays, pointers and cells use a VMStateField that is based on that for the inner type. The implementation therefore delegates to the VMState implementation of the inner type.
--- rust/qemu-api/src/vmstate.rs | 79 +++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-)
rust/qemu-api/src/vmstate.rs +78 -1
@@ -19,8 +19,9 @@//! `include/migration/vmstate.h`. These are not type-safe and should not be //! used if the equivalent functionality is available with `vmstate_of!`. -use core::marker::PhantomData ; +use core::{marker::PhantomData , mem, ptr::NonNull }; +use crate ::bindings::VMStateFlags ;pub use crate ::bindings::{VMStateDescription ,VMStateField };/// This macro is used to call a function with a generic argument bound
@@ -102,6 +103,15 @@ macro_rules! vmstate_of { }; } +impl VMStateFlags { +const VMS_VARRAY_FLAGS :VMStateFlags =VMStateFlags ( +VMStateFlags ::VMS_VARRAY_INT32 .0 + |VMStateFlags ::VMS_VARRAY_UINT8 .0 + |VMStateFlags ::VMS_VARRAY_UINT16 .0 + |VMStateFlags ::VMS_VARRAY_UINT32 .0 , + ); +} +// Add a couple builder-style methods to VMStateField, allowing // easy derivation of VMStateField constants from other types. impl VMStateField {
@@ -111,6 +121,73 @@ pub const fn with_version_id(mut self, version_id: i32) -> Self { self.version_id = version_id; self } + +#[must_use] +pub const fn with_array_flag (mut self, num:usize ) ->Self { +assert! (num <=0x7FFF_FFFFusize ); +assert! ((self.flags.0 &VMStateFlags ::VMS_ARRAY .0 ) ==0 ); +assert! ((self.flags.0 &VMStateFlags ::VMS_VARRAY_FLAGS .0 ) ==0 ); +if (self.flags.0 &VMStateFlags ::VMS_POINTER .0 ) !=0 { + self.flags =VMStateFlags (self.flags.0 & !VMStateFlags ::VMS_POINTER .0 ); + self.flags =VMStateFlags (self.flags.0 |VMStateFlags ::VMS_ARRAY_OF_POINTER .0 ); + } + self.flags =VMStateFlags (self.flags.0 & !VMStateFlags ::VMS_SINGLE .0 ); + self.flags =VMStateFlags (self.flags.0 |VMStateFlags ::VMS_ARRAY .0 ); + self.num = numas i32 ; + self + } + +#[must_use] +pub const fn with_pointer_flag (mut self) ->Self { +assert! ((self.flags.0 &VMStateFlags ::VMS_POINTER .0 ) ==0 ); + self.flags =VMStateFlags (self.flags.0 |VMStateFlags ::VMS_POINTER .0 ); + self + } +} + +// Transparent wrappers: just use the internal type + +macro_rules! impl_vmstate_transparent { + ($type:tywhere $base:tt:VMState $($where:tt)*) => { +unsafe impl <$base>VMState for $typewhere $base:VMState $($where)* { +const BASE :VMStateField =VMStateField { + size: mem::size_of::<$type>(), + ..<$baseas VMState >::BASE + }; + } + }; +} + +impl_vmstate_transparent! (std::cell::Cell <T >where T :VMState ); +impl_vmstate_transparent! (std::cell::UnsafeCell <T >where T :VMState ); +impl_vmstate_transparent! (crate ::cell::BqlCell <T >where T :VMState ); +impl_vmstate_transparent! (crate ::cell::BqlRefCell <T >where T :VMState ); + +// Pointer types using the underlying type's VMState plus VMS_POINTER +// Note that references are not supported, though references to cells +// could be allowed. + +macro_rules! impl_vmstate_pointer { + ($type:tywhere $base:tt:VMState $($where:tt)*) => { +unsafe impl <$base>VMState for $typewhere $base:VMState $($where)* { +const BASE :VMStateField = <$baseas VMState >::BASE .with_pointer_flag (); + } + }; +} + +impl_vmstate_pointer! (*const T where T :VMState ); +impl_vmstate_pointer! (*mut T where T :VMState ); +impl_vmstate_pointer! (NonNull <T >where T :VMState ); + +// Unlike C pointers, Box is always non-null therefore there is no need +// to specify VMS_ALLOC. +impl_vmstate_pointer! (Box <T >where T :VMState ); + +// Arrays using the underlying type's VMState plus +// VMS_ARRAY/VMS_ARRAY_OF_POINTER + +unsafe impl <T :VMState ,const N :usize >VMState for [T ;N ] { +const BASE :VMStateField = <T as VMState >::BASE .with_array_flag (N ); }#[doc(alias = "VMSTATE_UNUSED_BUFFER" )]
Signature · 1 line
2.48.1
[PULL 05/48] target/i386: unify choice between single and repeated string instructions
In reply to Paolo BonziniThe same "if" is present in all generator functions for string instructions. Push it inside gen_repz() and gen_repz_nz() instead.
--- target/i386/tcg/translate.c | 12 +++++++++-- target/i386/tcg/emit.c.inc | 42 +++++++------------------------------ 2 files changed, 17 insertions(+), 37 deletions(-)
target/i386/tcg/translate.c +10 -2
@@ -1341,13 +1341,21 @@ static void gen_repz(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot)) { -do_gen_rep (s, ot, fn, false); +if (s->prefix & (PREFIX_REPZ |PREFIX_REPNZ )) { +do_gen_rep (s, ot, fn, false); + }else { +fn (s, ot); + } }static void gen_repz_nz (DisasContext *s,MemOp ot,void (*fn)(DisasContext *s,MemOp ot)) { -do_gen_rep (s, ot, fn, true); +if (s->prefix & (PREFIX_REPZ |PREFIX_REPNZ )) { +do_gen_rep (s, ot, fn, true); + }else { +fn (s, ot); + } }static void gen_helper_fp_arith_ST0_FT0 (int op)
target/i386/tcg/emit.c.inc +7 -35
84 lines not on this page · raw message
Signature · 1 line
2.48.1
[PULL 12/48] target/i386: execute multiple REP/REPZ iterations without leaving TB
In reply to Paolo BonziniUse a TCG loop so that it is not necessary to go through the setup steps of REP and through the I/O check on every iteration. Interestingly, this is not a particularly effective optimization on its own, though it avoids the cost of correct RF emulation that was added in the previous patch. The main benefit lies in allowing the hoisting of loop invariants outside the loop, which will happen separately.
The loop exits when the low 16 bits of CX/ECX/RCX are zero (so generally speaking the string operation runs in 65536 iteration batches) to give the main loop an opportunity to pick up interrupts.
--- target/i386/tcg/translate.c | 55 +++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-)
target/i386/tcg/translate.c +49 -6
@@ -1333,13 +1333,28 @@ static void gen_outs(DisasContext *s, MemOp ot)gen_bpt_io (s, s->tmp2_i32, ot); } +#define REP_MAX 65535 +static void do_gen_rep (DisasContext *s,MemOp ot,void (*fn)(DisasContext *s,MemOp ot),bool is_repz_nz) { +TCGLabel *last =gen_new_label (); +TCGLabel *loop =gen_new_label ();TCGLabel *done =gen_new_label (); +target_ulong cx_mask =MAKE_64BIT_MASK (0 ,8 << s->aflag);TCGv cx_next =tcg_temp_new (); + +/* +* Check if we must translate a single iteration only. Normally, HF_RF_MASK +* would also limit translation blocks to one instruction, so that gen_eob +* can reset the flag; here however RF is set throughout the repetition, so +* we can plow through until CX/ECX/RCX is zero. +*/ +bool can_loop = + (!(tb_cflags (s->base.tb) & (CF_USE_ICOUNT |CF_SINGLE_STEP )) + && !(s->flags & (HF_TF_MASK |HF_INHIBIT_IRQ_MASK )));bool had_rf = s->flags &HF_RF_MASK ;/*
@@ -1364,19 +1379,29 @@ static void do_gen_rep(DisasContext *s, MemOp ot,/* Any iteration at all? */ tcg_gen_brcondi_tl (TCG_COND_TSTEQ , cpu_regs[R_ECX ], cx_mask, done); -fn (s, ot); - -tcg_gen_subi_tl (cx_next, cpu_regs[R_ECX ],1 ); -/* -* Write back cx_next to CX/ECX/RCX. There can be no carry, so zero -* extend if needed but do not do expensive deposit operations. +* From now on we operate on the value of CX/ECX/RCX that will be written +* back, which is stored in cx_next. There can be no carry, so we can zero +* extend here if needed and not do any expensive deposit operations later. */ +tcg_gen_subi_tl (cx_next, cpu_regs[R_ECX ],1 );#ifdef TARGET_X86_64 if (s->aflag ==MO_32 ) {tcg_gen_ext32u_tl (cx_next, cx_next); + cx_mask = ~0 ; }#endif + +/* +* The last iteration is handled outside the loop, so that cx_next +* can never underflow. +*/ +if (can_loop) { +tcg_gen_brcondi_tl (TCG_COND_TSTEQ , cx_next, cx_mask, last); + } + +gen_set_label (loop); +fn (s, ot);tcg_gen_mov_tl (cpu_regs[R_ECX ], cx_next);gen_update_cc_op (s);
@@ -1388,6 +1413,12 @@ static void do_gen_rep(DisasContext *s, MemOp ot,assert (!s->cc_op_dirty); } +if (can_loop) { +tcg_gen_subi_tl (cx_next, cx_next,1 ); +tcg_gen_brcondi_tl (TCG_COND_TSTNE , cx_next,REP_MAX , loop); +tcg_gen_brcondi_tl (TCG_COND_TSTEQ , cx_next, cx_mask, last); + } +/* * Traps or interrupts set RF_MASK if they happen after any iteration * but the last. Set it here before giving the main loop a chance to
@@ -1400,6 +1431,18 @@ static void do_gen_rep(DisasContext *s, MemOp ot,/* Go to the main loop but reenter the same instruction. */ gen_jmp_rel_csize (s, -cur_insn_len (s),0 ); +if (can_loop) { +/* +* The last iteration needs no conditional jump, even if is_repz_nz, +* because the repeats are ending anyway. +*/ +gen_set_label (last); +set_cc_op (s,CC_OP_DYNAMIC ); +fn (s, ot); +tcg_gen_mov_tl (cpu_regs[R_ECX ], cx_next); +gen_update_cc_op (s); + } +/* CX/ECX/RCX is zero, or REPZ/REPNZ broke the repetition. */ gen_set_label (done);set_cc_op (s,CC_OP_DYNAMIC );
Signature · 1 line
2.48.1
[PULL 19/48] docs: Add GNR, SRF and CWF CPU models
In reply to Paolo BonziniFrom: Tao Su <[email protected]>
Update GraniteRapids, SierraForest and ClearwaterForest CPU models in section "Preferred CPU models for Intel x86 hosts".
Also introduce bhi-no, gds-no and rfds-no in doc.
--- docs/system/cpu-models-x86.rst.inc | 50 +++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-)
docs/system/cpu-models-x86.rst.inc +46 -4
@@ -71,6 +71,16 @@ mixture of host CPU models between machines, if live migration compatibility is required, use the newest CPU model that is compatible across all desired hosts. +``ClearwaterForest`` + Intel Xeon Processor (ClearwaterForest, 2025) + +``SierraForest``, ``SierraForest-v2`` + Intel Xeon Processor (SierraForest, 2024), SierraForest-v2 mitigates + the GDS and RFDS vulnerabilities with stepping 3. + +``GraniteRapids``, ``GraniteRapids-v2`` + Intel Xeon Processor (GraniteRapids, 2024) + ``Cascadelake-Server``, ``Cascadelake-Server-noTSX`` Intel Xeon Processor (Cascade Lake, 2019), with "stepping" levels 6 or 7 only. (The Cascade Lake Xeon processor with *stepping 5 is
@@ -181,7 +191,7 @@ features are included if using "Host passthrough" or "Host model". CVE-2018-12127, [MSBDS] CVE-2018-12126). This is an MSR (Model-Specific Register) feature rather than a CPUID feature, - so it will not appear in the Linux ``/proc/cpuinfo`` in the host or + therefore it will not appear in the Linux ``/proc/cpuinfo`` in the host or guest. Instead, the host kernel uses it to populate the MDS vulnerability file in ``sysfs``.
@@ -189,10 +199,10 @@ features are included if using "Host passthrough" or "Host model". affected} in the ``/sys/devices/system/cpu/vulnerabilities/mds`` file. ``taa-no`` - Recommended to inform that the guest that the host is ``not`` + Recommended to inform the guest that the host is ``not`` vulnerable to CVE-2019-11135, TSX Asynchronous Abort (TAA). - This too is an MSR feature, so it does not show up in the Linux + This is also an MSR feature, therefore it does not show up in the Linux ``/proc/cpuinfo`` in the host or guest. It should only be enabled for VMs if the host reports ``Not affected``
@@ -214,7 +224,7 @@ features are included if using "Host passthrough" or "Host model". By disabling TSX, KVM-based guests can avoid paying the price of mitigating TSX-based attacks. - Note that ``tsx-ctrl`` too is an MSR feature, so it does not show + Note that ``tsx-ctrl`` is also an MSR feature, therefore it does not show up in the Linux ``/proc/cpuinfo`` in the host or guest. To validate that Intel TSX is indeed disabled for the guest, there are
@@ -223,6 +233,38 @@ features are included if using "Host passthrough" or "Host model". ``/sys/devices/system/cpu/vulnerabilities/tsx_async_abort`` file in the guest should report ``Mitigation: TSX disabled``. +``bhi-no`` + Recommended to inform the guest that the host is ``not`` + vulnerable to CVE-2022-0001, Branch History Injection (BHI). + + This is also an MSR feature, therefore it does not show up in the Linux + ``/proc/cpuinfo`` in the host or guest. + + It should only be enabled for VMs if the host reports + ``BHI: Not affected`` in the + ``/sys/devices/system/cpu/vulnerabilities/spectre_v2`` file. + +``gds-no`` + Recommended to inform the guest that the host is ``not`` + vulnerable to CVE-2022-40982, Gather Data Sampling (GDS). + + This is also an MSR feature, therefore it does not show up in the Linux + ``/proc/cpuinfo`` in the host or guest. + + It should only be enabled for VMs if the host reports ``Not affected`` + in the ``/sys/devices/system/cpu/vulnerabilities/gather_data_sampling`` + file. + +``rfds-no`` + Recommended to inform the guest that the host is ``not`` + vulnerable to CVE-2023-28746, Register File Data Sampling (RFDS). + + This is also an MSR feature, therefore it does not show up in the Linux + ``/proc/cpuinfo`` in the host or guest. + + It should only be enabled for VMs if the host reports ``Not affected`` + in the ``/sys/devices/system/cpu/vulnerabilities/reg_file_data_sampling`` + file. Preferred CPU models for AMD x86 hosts ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Signature · 1 line
2.48.1
[PULL 11/48] target/i386: optimize CX handling in repeated string operations
In reply to Paolo BonziniIn a repeated string operation, CX/ECX will be decremented until it is 0 but never underflow. Use this observation to avoid a deposit or zero-extend operation if the address size of the operation is smaller than MO_TL.
As in the previous patch, the patch is structured to include some preparatory work for subsequent changes. In particular, introducing cx_next prepares for when ECX will be decremented *before* calling fn(s, ot), and therefore cannot yet be written back to cpu_regs.
--- target/i386/tcg/translate.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
target/i386/tcg/translate.c +14 -1
@@ -1339,6 +1339,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, {TCGLabel *done =gen_new_label ();target_ulong cx_mask =MAKE_64BIT_MASK (0 ,8 << s->aflag); +TCGv cx_next =tcg_temp_new ();bool had_rf = s->flags &HF_RF_MASK ;/*
@@ -1364,7 +1365,19 @@ static void do_gen_rep(DisasContext *s, MemOp ot,tcg_gen_brcondi_tl (TCG_COND_TSTEQ , cpu_regs[R_ECX ], cx_mask, done);fn (s, ot); -gen_op_add_reg_im (s, s->aflag,R_ECX ,-1 ); + +tcg_gen_subi_tl (cx_next, cpu_regs[R_ECX ],1 ); + +/* +* Write back cx_next to CX/ECX/RCX. There can be no carry, so zero +* extend if needed but do not do expensive deposit operations. +*/ +#ifdef TARGET_X86_64 +if (s->aflag ==MO_32 ) { +tcg_gen_ext32u_tl (cx_next, cx_next); + } +#endif +tcg_gen_mov_tl (cpu_regs[R_ECX ], cx_next);gen_update_cc_op (s);/* Leave if REP condition fails. */
Signature · 1 line
2.48.1
[PULL 23/48] memattrs: Convert unspecified member to bool
In reply to Paolo BonziniFrom: Zhao Liu <[email protected]>
Convert unspecified member of MemTxAttrs from bit field to bool, so that bindgen could generate more ergonomic Rust binding with bool type.
As a result, MemTxAttrs needs to be expanded from 4 bytes to 8 bytes.
Therefore, move unspecified to after the bit fields and add reserved members to ensure that the whole structure is packed into 8 bytes.
--- include/exec/memattrs.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
include/exec/memattrs.h +12 -7
@@ -23,12 +23,6 @@* different semantics. */ typedef struct MemTxAttrs { - /* Bus masters which don't specify any attributes will get this - * (via the MEMTXATTRS_UNSPECIFIED constant), so that we can - * distinguish "all attributes deliberately clear" from - * "didn't specify" if necessary. - */ - unsigned int unspecified:1; /* * ARM/AMBA: TrustZone Secure access * x86: System Management Mode access
@@ -57,6 +51,17 @@ typedef struct MemTxAttrs {* PID (PCI PASID) support: Limited to 8 bits process identifier. */ unsigned int pid:8; + +/* +* Bus masters which don't specify any attributes will get this +* (via the MEMTXATTRS_UNSPECIFIED constant), so that we can +* distinguish "all attributes deliberately clear" from +* "didn't specify" if necessary. +*/ +bool unspecified; + +uint8_t _reserved1; +uint16_t _reserved2; } MemTxAttrs;/* Bus masters which don't specify any attributes will get this,
@@ -64,7 +69,7 @@ typedef struct MemTxAttrs {* (so that we can distinguish "all attributes deliberately clear" * from "didn't specify" if necessary). */ -#define MEMTXATTRS_UNSPECIFIED ((MemTxAttrs) { .unspecified = 1 }) +#define MEMTXATTRS_UNSPECIFIED ((MemTxAttrs) { .unspecified = true })/* New-style MMIO accessors can indicate that the transaction failed. * A zero (MEMTX_OK) response means success; anything else is a failure
Signature · 1 line
2.48.1
[PULL 43/48] rust: pl011: remove duplicate definitions
In reply to Paolo BonziniUnify the "Interrupt" enum and the "INT_*" constants with a struct that contains the bits. The "int_level" and "int_enabled" fields could use a crate such as "bitflags".
--- rust/hw/char/pl011/src/device.rs | 32 ++++++++++------------ rust/hw/char/pl011/src/lib.rs | 46 +++++++++++--------------------- 2 files changed, 29 insertions(+), 49 deletions(-)
rust/hw/char/pl011/src/device.rs +14 -18
@@ -191,7 +191,7 @@ pub(self) fn read(&mut self, offset: RegisterOffset) -> ControlFlow<u32, u32> { self.flags.set_receive_fifo_empty (true ); }if self.read_count +1 == self.read_trigger { - self.int_level &= !registers::INT_RX ; + self.int_level &= !Interrupt ::RX .0 ; }// Update error bits. self.receive_status_error_clear.set_from_data (c);
@@ -240,7 +240,7 @@ pub(self) fn write( }// interrupts always checked let _ = self.loopback_tx (value); - self.int_level |= registers::INT_TX ; + self.int_level |=Interrupt ::TX .0 ;return true ; } RSR => {
@@ -364,19 +364,19 @@ fn loopback_mdmctrl(&mut self) -> bool {// Change interrupts based on updated FR let mut il = self.int_level; - il &= !Interrupt ::MS ; + il &= !Interrupt ::MS .0 ;if self.flags.data_set_ready () { - il |=Interrupt ::DSR as u32 ; + il |=Interrupt ::DSR .0 ; }if self.flags.data_carrier_detect () { - il |=Interrupt ::DCD as u32 ; + il |=Interrupt ::DCD .0 ; }if self.flags.clear_to_send () { - il |=Interrupt ::CTS as u32 ; + il |=Interrupt ::CTS .0 ; }if self.flags.ring_indicator () { - il |=Interrupt ::RI as u32 ; + il |=Interrupt ::RI .0 ; } self.int_level = il;true
@@ -454,7 +454,7 @@ pub fn put_fifo(&mut self, value: u32) -> bool { }if self.read_count == self.read_trigger { - self.int_level |= registers::INT_RX ; + self.int_level |=Interrupt ::RX .0 ;return true ; }false
@@ -641,16 +641,12 @@ pub fn post_load(&self, _version_id: u32) -> Result<(), ()> {/// Which bits in the interrupt status matter for each outbound IRQ line ? const IRQMASK : [u32 ;6 ] = [/* combined IRQ */ -Interrupt ::E - |Interrupt ::MS - |Interrupt ::RT as u32 - |Interrupt ::TX as u32 - |Interrupt ::RX as u32 , -Interrupt ::RX as u32 , -Interrupt ::TX as u32 , -Interrupt ::RT as u32 , -Interrupt ::MS , -Interrupt ::E , +Interrupt ::E .0 |Interrupt ::MS .0 |Interrupt ::RT .0 |Interrupt ::TX .0 |Interrupt ::RX .0 , +Interrupt ::RX .0 , +Interrupt ::TX .0 , +Interrupt ::RT .0 , +Interrupt ::MS .0 , +Interrupt ::E .0 , ];/// # Safety
rust/hw/char/pl011/src/lib.rs +15 -31
60 lines not on this page · raw message
Signature · 1 line
2.48.1
[PULL 10/48] target/i386: do not use gen_op_jz_ecx for repeated string operations
In reply to Paolo BonziniExplicitly generate a TSTEQ branch (which is optimized to NE x,0 if possible). This does not make much sense yet, but later we will add more checks and some will use a temporary to check on the decremented value of CX/ECX/RCX; it will be clearer for all checks to share the same logic using TSTEQ(reg, cx_mask).
--- target/i386/tcg/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/tcg/translate.c +2 -1
@@ -1338,6 +1338,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, bool is_repz_nz) {TCGLabel *done =gen_new_label (); +target_ulong cx_mask =MAKE_64BIT_MASK (0 ,8 << s->aflag);bool had_rf = s->flags &HF_RF_MASK ;/*
@@ -1360,7 +1361,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot,tcg_set_insn_start_param (s->base.insn_start,1 ,CC_OP_DYNAMIC );/* Any iteration at all? */ -gen_op_jz_ecx (s, done); +tcg_gen_brcondi_tl (TCG_COND_TSTEQ , cpu_regs[R_ECX ], cx_mask, done);fn (s, ot);gen_op_add_reg_im (s, s->aflag,R_ECX ,-1 );
Signature · 1 line
2.48.1
[PULL 47/48] rust/zeroable: Implement Zeroable with const_zero macro
In reply to Paolo BonziniThe const_zero crate provides a nice macro to zero type-specific constants, which doesn't need to enumerates the fields one by one.
Introduce the const_zero macro to QEMU (along with its documentation), and use it to simplify the implementation of Zeroable trait.
--- rust/qemu-api/src/zeroable.rs | 137 +++++++++++++++------------------- 1 file changed, 61 insertions(+), 76 deletions(-)
rust/qemu-api/src/zeroable.rs +61 -76
@@ -1,13 +1,11 @@// SPDX-License-Identifier: GPL-2.0-or-later -use std::ptr; -/// Encapsulates the requirement that /// `MaybeUninit::<Self>::zeroed().assume_init()` does not cause undefined /// behavior. This trait in principle could be implemented as just: /// /// ``` -/// pub unsafe trait Zeroable: Default { +/// pub unsafe trait Zeroable { /// const ZERO: Self = unsafe { ::core::mem::MaybeUninit::<Self>::zeroed().assume_init() }; /// } /// ```
@@ -29,23 +27,61 @@ pub unsafe trait Zeroable: Default {const ZERO :Self ; } -unsafe impl Zeroable for crate ::bindings::Property__bindgen_ty_1 { -const ZERO :Self =Self { i:0 }; +/// A macro that acts similarly to [`core::mem::zeroed()`], only is const +/// +/// ## Safety +/// +/// Similar to `core::mem::zeroed()`, except this zeroes padding bits. Zeroed +/// padding usually isn't relevant to safety, but might be if a C union is used. +/// +/// Just like for `core::mem::zeroed()`, an all zero byte pattern might not +/// be a valid value for a type, as is the case for references `&T` and `&mut +/// T`. Reference types trigger a (denied by default) lint and cause immediate +/// undefined behavior if the lint is ignored +/// +/// ```rust compile_fail +/// use const_zero::const_zero; +/// // error: any use of this value will cause an error +/// // note: `#[deny(const_err)]` on by default +/// const STR: &str = unsafe{const_zero!(&'static str)}; +/// ``` +/// +/// `const_zero` does not work on unsized types: +/// +/// ```rust compile_fail +/// use const_zero::const_zero; +/// // error[E0277]: the size for values of type `[u8]` cannot be known at compilation time +/// const BYTES: [u8] = unsafe{const_zero!([u8])}; +/// ``` +/// ## Differences with `core::mem::zeroed` +/// +/// `const_zero` zeroes padding bits, while `core::mem::zeroed` doesn't +macro_rules! const_zero { +// This macro to produce a type-generic zero constant is taken from the +// const_zero crate (v0.1.1): +// +// https://docs.rs/const-zero/latest/src/const_zero/lib.rs.html +// +// and used under MIT license + ($type_:ty) => {{ +const TYPE_SIZE : ::core::primitive::usize = ::core::mem::size_of ::<$type_>(); +union TypeAsBytes { + bytes: [::core::primitive::u8 ;TYPE_SIZE ], + inner: ::core::mem::ManuallyDrop <$type_>, + } +const ZERO_BYTES :TypeAsBytes =TypeAsBytes { + bytes: [0 ;TYPE_SIZE ], + }; + ::core::mem::ManuallyDrop ::<$type_>::into_inner (ZERO_BYTES .inner) + }}; } -unsafe impl Zeroable for crate ::bindings::Property { -const ZERO :Self =Self { - name: ptr::null (), - info: ptr::null (), - offset:0 , - bitnr:0 , - bitmask:0 , - set_default:false , - defval:Zeroable ::ZERO , - arrayoffset:0 , - arrayinfo: ptr::null (), - arrayfieldsize:0 , - link_type: ptr::null (), +/// A wrapper to implement the `Zeroable` trait through the `const_zero` macro. +macro_rules! impl_zeroable { + ($type:ty) => { +unsafe impl Zeroable for $type { +const ZERO :Self =unsafe {const_zero! ($type ) }; + } }; }
@@ -57,61 +93,10 @@ fn default() -> Self { } } -unsafe impl Zeroable for crate ::bindings::VMStateFlags { -const ZERO :Self =Self (0 ); -} - -unsafe impl Zeroable for crate ::bindings::VMStateField { -const ZERO :Self =Self { - name: ptr::null (), - err_hint: ptr::null (), - offset:0 , - size:0 , - start:0 , - num:0 , - num_offset:0 , - size_offset:0 , - info: ptr::null (), - flags:Zeroable ::ZERO , - vmsd: ptr::null (), - version_id:0 , - struct_version_id:0 , - field_exists:None , - }; -} - -unsafe impl Zeroable for crate ::bindings::VMStateDescription { -const ZERO :Self =Self { - name: ptr::null (), - unmigratable:false , - early_setup:false , - version_id:0 , - minimum_version_id:0 , - priority:crate ::bindings::MigrationPriority ::MIG_PRI_DEFAULT , - pre_load:None , - post_load:None , - pre_save:None , - post_save:None , - needed:None , - dev_unplug_pending:None , - fields: ptr::null (), - subsections: ptr::null (), - }; -} - -unsafe impl Zeroable for crate ::bindings::MemoryRegionOps__bindgen_ty_1 { -const ZERO :Self =Self { - min_access_size:0 , - max_access_size:0 , - unaligned:false , - accepts:None , - }; -} - -unsafe impl Zeroable for crate ::bindings::MemoryRegionOps__bindgen_ty_2 { -const ZERO :Self =Self { - min_access_size:0 , - max_access_size:0 , - unaligned:false , - }; -} +impl_zeroable! (crate ::bindings::Property__bindgen_ty_1 ); +impl_zeroable! (crate ::bindings::Property ); +impl_zeroable! (crate ::bindings::VMStateFlags ); +impl_zeroable! (crate ::bindings::VMStateField ); +impl_zeroable! (crate ::bindings::VMStateDescription ); +impl_zeroable! (crate ::bindings::MemoryRegionOps__bindgen_ty_1 ); +impl_zeroable! (crate ::bindings::MemoryRegionOps__bindgen_ty_2 );
Signature · 1 line
2.48.1
[PULL 40/48] rust: pl011: pull interrupt updates out of read/write ops
In reply to Paolo Bonziniqemu_irqs are not part of the vmstate, therefore they will remain in PL011State. Update them if needed after regs_read()/regs_write().
Apply #[must_use] to functions that return whether the interrupt state could have changed, so that it's harder to forget the call to update().
--- rust/hw/char/pl011/src/device.rs | 84 ++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 36 deletions(-)
rust/hw/char/pl011/src/device.rs +48 -36
@@ -242,7 +242,6 @@ fn regs_read(&mut self, offset: RegisterOffset) -> ControlFlow<u32, u32> { }// Update error bits. self.receive_status_error_clear.set_from_data (c); - self.update ();// Must call qemu_chr_fe_accept_input, so return Continue: return ControlFlow ::Continue (u32::from (c)); }
@@ -266,7 +265,7 @@ fn regs_read(&mut self, offset: RegisterOffset) -> ControlFlow<u32, u32> { }) } -fn regs_write (&mut self, offset:RegisterOffset , value:u32 ) { +fn regs_write (&mut self, offset:RegisterOffset , value:u32 ) ->bool {// eprintln!("write offset {offset} value {value}"); use RegisterOffset ::*;match offset {
@@ -281,9 +280,10 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) {unsafe {qemu_chr_fe_write_all (addr_of_mut! (self.char_backend), &ch,1 ); } - self.loopback_tx (value); +// interrupts always checked +let _ = self.loopback_tx (value); self.int_level |= registers::INT_TX ; - self.update (); +return true ; } RSR => { self.receive_status_error_clear =0 .into ();
@@ -307,7 +307,7 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) { self.reset_rx_fifo (); self.reset_tx_fifo (); } -if self.line_control.send_break () ^ new_val.send_break () { +let update = (self.line_control.send_break () != new_val.send_break ()) && {let mut break_enable:c_int = new_val.send_break ().into ();// SAFETY: self.char_backend is a valid CharBackend instance after it's been // initialized in realize().
@@ -318,15 +318,16 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) { addr_of_mut!(break_enable).cast::<c_void>(), ); } - self.loopback_break (break_enable >0 ); - } + self.loopback_break (break_enable >0 ) + }; self.line_control = new_val; self.set_read_trigger (); +return update; } CR => {// ??? Need to implement the enable bit. self.control = value.into (); - self.loopback_mdmctrl (); +return self.loopback_mdmctrl (); } FLS => { self.ifl = value;
@@ -334,13 +335,13 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) { } IMSC => { self.int_enabled = value; - self.update (); +return true ; } RIS => {} MIS => {} ICR => { self.int_level &= !value; - self.update(); + return true; } DMACR => { self.dmacr = value;
@@ -350,14 +351,12 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) { } } } +false }#[inline] -fn loopback_tx (&mut self, value:u32 ) { -if !self.loopback_enabled () { -return ; - } - +#[must_use] +fn loopback_tx (&mut self, value:u32 ) ->bool {// Caveat: // // In real hardware, TX loopback happens at the serial-bit level
@@ -375,12 +374,13 @@ fn loopback_tx(&mut self, value: u32) {// hardware flow-control is enabled. // // For simplicity, the above described is not emulated. - self.put_fifo (value); + self.loopback_enabled () && self.put_fifo (value) } -fn loopback_mdmctrl (&mut self) { +#[must_use] +fn loopback_mdmctrl (&mut self) ->bool {if !self.loopback_enabled () { -return ; +return false ; }/*
@@ -421,13 +421,11 @@ fn loopback_mdmctrl(&mut self) { il |=Interrupt ::RI as u32 ; } self.int_level = il; - self.update (); +true } -fn loopback_break (&mut self, enable:bool ) { -if enable { - self.loopback_tx (registers::Data ::BREAK .into ()); - } +fn loopback_break (&mut self, enable:bool ) ->bool { + enable && self.loopback_tx (registers::Data ::BREAK .into ()) }fn set_read_trigger (&mut self) {
@@ -489,14 +487,17 @@ pub fn can_receive(&self) -> bool { }pub fn receive (&mut self, ch:u32 ) { -if !self.loopback_enabled () { - self.put_fifo (ch) +if !self.loopback_enabled () && self.put_fifo (ch) { + self.update (); } }pub fn event (&mut self, event:QEMUChrEvent ) {if event ==QEMUChrEvent ::CHR_EVENT_BREAK && !self.loopback_enabled () { - self.put_fifo (registers::Data ::BREAK .into ()); +let update = self.put_fifo (registers::Data ::BREAK .into ()); +if update { + self.update (); + } } }
@@ -519,7 +520,8 @@ pub fn fifo_depth(&self) -> u32 {1 } -pub fn put_fifo (&mut self, value:u32 ) { +#[must_use] +pub fn put_fifo (&mut self, value:u32 ) ->bool {let depth = self.fifo_depth ();assert! (depth >0 );let slot = (self.read_pos + self.read_count) & (depth -1 );
@@ -532,8 +534,9 @@ pub fn put_fifo(&mut self, value: u32) {if self.read_count == self.read_trigger { self.int_level |= registers::INT_RX ; - self.update (); +return true ; } +false }pub fn update (&self) {
@@ -565,7 +568,8 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { }pub fn read (&mut self, offset:hwaddr , _size:u32 ) ->ControlFlow <u64 ,u64 > { -match RegisterOffset ::try_from (offset) { +let mut update_irq =false ; +let result =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 ]))
@@ -574,22 +578,30 @@ pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow<u64, u64> {// 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 ()), + Ok(field) => match self.regs_read(field) { +ControlFlow ::Break (value) =>ControlFlow ::Break (value.into ()), +ControlFlow ::Continue (value) => { + update_irq =true ; +ControlFlow ::Continue (value.into ()) } - } + }, + }; +if update_irq { + self.update (); } + result }pub fn write (&mut self, offset:hwaddr , value:u64 ) { +let mut update_irq =false ;if let Ok (field) =RegisterOffset ::try_from (offset) { - self.regs_write (field, valueas u32 ); + update_irq = self.regs_write (field, valueas u32 ); }else {eprintln! ("write bad offset {offset} value {value}" ); } +if update_irq { + self.update (); + } } }
Signature · 1 line
2.48.1
[PULL 31/48] rust: qemu_api: add vmstate_struct
In reply to Paolo BonziniIt is not type safe, but it's the best that can be done without const_refs_static. It can also be used with BqlCell and BqlRefCell.
--- rust/qemu-api/src/vmstate.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
rust/qemu-api/src/vmstate.rs +33 -0
@@ -628,6 +628,39 @@ macro_rules! vmstate_array_of_pointer_to_struct { }}; } +// FIXME: including the `vmsd` field in a `const` is not possible without +// the const_refs_static feature (stabilized in Rust 1.83.0). Without it, +// it is not possible to use VMS_STRUCT in a transparent manner using +// `vmstate_of!`. While VMSTATE_CLOCK can at least try to be type-safe, +// VMSTATE_STRUCT includes $type only for documentation purposes; it +// is checked against $field_name and $struct_name, but not against $vmsd +// which is what really would matter. +#[doc(alias = "VMSTATE_STRUCT" )] +#[macro_export] +macro_rules! vmstate_struct { + ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:expr)?])?, $vmsd:expr, $type:ty $(,)?) => { + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name),"\0" ) + .as_bytes () + .as_ptr ()as *const ::std::os::raw::c_char , + $(.num_offset: $crate::offset_of!($struct_name, $num),)? + offset: { + $crate::assert_field_type!($struct_name, $field_name, $type ); + $crate::offset_of!($struct_name, $field_name) + }, + size: ::core::mem::size_of ::<$type>(), + flags: $crate::bindings::VMStateFlags ::VMS_STRUCT , + vmsd:unsafe { $vmsd }, + ..$crate::zeroable::Zeroable ::ZERO $( + .with_varray_flag ($crate::call_func_with_field!( + $crate ::vmstate::vmstate_varray_flag, + $struct_name, + $num)) + $(.with_varray_multiply ($factor))?)? + } + }; +} +#[doc(alias = "VMSTATE_CLOCK_V" )] #[macro_export] macro_rules! vmstate_clock_v {
Signature · 1 line
2.48.1
[PULL 35/48] rust: prefer NonNull::new to assertions
In reply to Paolo BonziniDo not use new_unchecked; the effect is the same, but the code is easier to read and unsafe regions become smaller. Likewise, NonNull::new can be used instead of assertion and followed by as_ref() or as_mut() instead of dereferencing the pointer.
--- rust/hw/char/pl011/src/device.rs | 17 +++++------------ rust/hw/char/pl011/src/device_class.rs | 23 +++++++++-------------- rust/hw/char/pl011/src/memory_ops.rs | 9 +++------ rust/qemu-api/src/qdev.rs | 12 +++++------- rust/qemu-api/src/qom.rs | 21 +++++++++++++-------- 5 files changed, 35 insertions(+), 47 deletions(-)
rust/hw/char/pl011/src/device.rs +5 -12
@@ -593,11 +593,8 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> {/// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. pub unsafe extern "C" fn pl011_can_receive (opaque: *mut c_void ) ->c_int { -unsafe { -debug_assert! (!opaque.is_null ()); -let state =NonNull ::new_unchecked (opaque.cast ::<PL011State >()); - state.as_ref ().can_receive ().into () - } +let state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); +unsafe { state.as_ref ().can_receive ().into () } }/// # Safety
@@ -608,9 +605,8 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> {/// /// The buffer and size arguments must also be valid. pub unsafe extern "C" fn pl011_receive (opaque: *mut c_void , buf: *const u8 , size:c_int ) { +let mut state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >();unsafe { -debug_assert! (!opaque.is_null ()); -let mut state =NonNull ::new_unchecked (opaque.cast ::<PL011State >());if state.as_ref ().loopback_enabled () {return ; }
@@ -627,11 +623,8 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> {/// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. pub unsafe extern "C" fn pl011_event (opaque: *mut c_void , event:QEMUChrEvent ) { -unsafe { -debug_assert! (!opaque.is_null ()); -let mut state =NonNull ::new_unchecked (opaque.cast ::<PL011State >()); - state.as_mut ().event (event) - } +let mut state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); +unsafe { state.as_mut ().event (event) } }/// # Safety
rust/hw/char/pl011/src/device_class.rs +9 -14
@@ -12,12 +12,10 @@use crate ::device::PL011State ; +#[allow(clippy::missing_const_for_fn)] extern "C" fn pl011_clock_needed (opaque: *mut c_void ) ->bool { -unsafe { -debug_assert! (!opaque.is_null ()); -let state =NonNull ::new_unchecked (opaque.cast ::<PL011State >()); - state.as_ref ().migrate_clock - } +let state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); +unsafe { state.as_ref ().migrate_clock } }/// Migration subsection for [`PL011State`] clock.
@@ -33,15 +31,12 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { };extern "C" fn pl011_post_load (opaque: *mut c_void , version_id:c_int ) ->c_int { -unsafe { -debug_assert! (!opaque.is_null ()); -let mut state =NonNull ::new_unchecked (opaque.cast ::<PL011State >()); -let result = state.as_mut ().post_load (version_idas u32 ); -if result.is_err () { - -1 - }else { -0 - } +let mut state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); +let result =unsafe { state.as_mut ().post_load (version_idas u32 ) }; +if result.is_err () { + -1 + }else { +0 } }
rust/hw/char/pl011/src/memory_ops.rs +3 -6
@@ -25,7 +25,7 @@unsafe extern "C" fn pl011_read (opaque: *mut c_void , addr:hwaddr , size:c_uint ) ->u64 {assert! (!opaque.is_null ()); -let mut state =unsafe {NonNull ::new_unchecked (opaque.cast ::<PL011State >()) }; +let mut state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >();let val =unsafe { state.as_mut ().read (addr, size) };match val { std::ops::ControlFlow ::Break (val) => val,
@@ -43,9 +43,6 @@ }unsafe extern "C" fn pl011_write (opaque: *mut c_void , addr:hwaddr , data:u64 , _size:c_uint ) { -unsafe { -assert! (!opaque.is_null ()); -let mut state =NonNull ::new_unchecked (opaque.cast ::<PL011State >()); - state.as_mut ().write (addr, data) - } +let mut state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); +unsafe { state.as_mut ().write (addr, data) } }
rust/qemu-api/src/qdev.rs +5 -7
@@ -4,7 +4,7 @@//! Bindings to create devices and access device functionality from Rust. -use std::ffi::CStr ; +use std::{ffi::CStr , ptr::NonNull };pub use bindings::{DeviceClass ,DeviceState ,Property };
@@ -55,9 +55,8 @@ fn vmsd() -> Option<&'static VMStateDescription> {/// can be downcasted to type `T`. We also expect the device is /// readable/writeable from one thread at any time. unsafe extern "C" fn rust_realize_fn <T :DeviceImpl >(dev: *mut DeviceState , _errp: *mut *mut Error ) { -assert! (!dev.is_null ()); -let state = dev.cast ::<T >(); -T ::REALIZE .unwrap ()(unsafe { &mut *state }); +let state =NonNull ::new (dev).unwrap ().cast ::<T >(); +T ::REALIZE .unwrap ()(unsafe { state.as_ref () }); }/// # Safety
@@ -66,9 +65,8 @@ fn vmsd() -> Option<&'static VMStateDescription> {/// can be downcasted to type `T`. We also expect the device is /// readable/writeable from one thread at any time. unsafe extern "C" fn rust_reset_fn <T :DeviceImpl >(dev: *mut DeviceState ) { -assert! (!dev.is_null ()); -let state = dev.cast ::<T >(); -T ::RESET .unwrap ()(unsafe { &mut *state }); +let mut state =NonNull ::new (dev).unwrap ().cast ::<T >(); +T ::RESET .unwrap ()(unsafe { state.as_mut () }); }impl <T >ClassInitImpl <DeviceClass >for T
rust/qemu-api/src/qom.rs +13 -8
@@ -58,6 +58,7 @@ fmt, ops::{Deref, DerefMut}, os::raw::c_void, + ptr::NonNull, };pub use bindings::{Object ,ObjectClass };
@@ -153,27 +154,34 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { }unsafe extern "C" fn rust_instance_init <T :ObjectImpl >(obj: *mut Object ) { +let mut state =NonNull ::new (obj).unwrap ().cast ::<T >();// SAFETY: obj is an instance of T, since rust_instance_init<T> // is called from QOM core as the instance_init function // for class T -unsafe {T ::INSTANCE_INIT .unwrap ()(&mut *obj.cast ::<T >()) } +unsafe { +T ::INSTANCE_INIT .unwrap ()(state.as_mut ()); + } }unsafe extern "C" fn rust_instance_post_init <T :ObjectImpl >(obj: *mut Object ) { +let state =NonNull ::new (obj).unwrap ().cast ::<T >();// SAFETY: obj is an instance of T, since rust_instance_post_init<T> // is called from QOM core as the instance_post_init function // for class T -T ::INSTANCE_POST_INIT .unwrap ()(unsafe { &*obj.cast ::<T >() }) +T ::INSTANCE_POST_INIT .unwrap ()(unsafe { state.as_ref () }); }unsafe extern "C" fn rust_class_init <T :ObjectType +ClassInitImpl <T ::Class >>( klass: *mut ObjectClass , _data: *mut c_void , ) { +let mut klass =NonNull ::new (klass) + .unwrap () + .cast ::<<T as ObjectType >::Class >();// SAFETY: klass is a T::Class, since rust_class_init<T> // is called from QOM core as the class_init function // for class T -T ::class_init (unsafe { &mut *klass.cast ::<T ::Class >() }) +T ::class_init (unsafe { klass.as_mut () }) }unsafe extern "C" fn drop_object <T :ObjectImpl >(obj: *mut Object ) {
@@ -581,11 +589,8 @@ pub trait ClassInitImpl<T> {/// can be downcasted to type `T`. We also expect the device is /// readable/writeable from one thread at any time. unsafe extern "C" fn rust_unparent_fn <T :ObjectImpl >(dev: *mut Object ) { -unsafe { -assert! (!dev.is_null ()); -let state = core::ptr::NonNull ::new_unchecked (dev.cast ::<T >()); -T ::UNPARENT .unwrap ()(state.as_ref ()); - } +let state =NonNull ::new (dev).unwrap ().cast ::<T >(); +T ::UNPARENT .unwrap ()(unsafe { state.as_ref () }); }impl <T >ClassInitImpl <ObjectClass >for T
Signature · 1 line
2.48.1
[PULL 38/48] rust: pl011: extract conversion to RegisterOffset
In reply to Paolo BonziniAs 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 | 113 +++++++++++++++++-------------- 1 file changed, 64 insertions(+), 49 deletions(-)
rust/hw/char/pl011/src/device.rs +64 -49
@@ -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,39 +244,33 @@ 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 ) => { +match offset { +DR => {// ??? Check if transmitter is enabled. let ch:u8 = valueas u8 ;// XXX this blocks entire thread. Rewrite to use
@@ -298,22 +285,22 @@ pub fn write(&mut self, offset: hwaddr, value: u64) { 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 +323,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 +557,34 @@ 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) { + 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 ?
Signature · 1 line
2.48.1
[PULL 48/48] rust: qemu-api: add sub-subclass to the integration tests
In reply to Paolo Bonzini--- rust/qemu-api/tests/tests.rs | 56 ++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-)
rust/qemu-api/tests/tests.rs +53 -3
@@ -14,8 +14,8 @@ cell::{self, BqlCell}, declare_properties, define_property, prelude::*, - qdev::{DeviceImpl, DeviceState, Property}, - qom::{ObjectImpl, ParentField}, + qdev::{DeviceClass, DeviceImpl, DeviceState, Property}, + qom::{ClassInitImpl, ObjectImpl, ParentField}, vmstate::VMStateDescription, zeroable::Zeroable, };
@@ -37,6 +37,10 @@ pub struct DummyState {qom_isa! (DummyState :Object ,DeviceState ); +pub struct DummyClass { + parent_class: <DeviceState as ObjectType >::Class , +} +declare_properties! {DUMMY_PROPERTIES ,define_property! (
@@ -49,7 +53,7 @@ pub struct DummyState { }unsafe impl ObjectType for DummyState { -type Class = <DeviceState as ObjectType >::Class ; +type Class =DummyClass ;const TYPE_NAME : &'staticCStr =c_str! ("dummy" ); }
@@ -67,6 +71,51 @@ fn vmsd() -> Option<&'static VMStateDescription> { } } +// `impl<T> ClassInitImpl<DummyClass> for T` doesn't work since it violates +// orphan rule. +impl ClassInitImpl <DummyClass >for DummyState { +fn class_init (klass: &mut DummyClass ) { + <Self as ClassInitImpl <DeviceClass >>::class_init (&mut klass.parent_class); + } +} + +#[derive(qemu_api_macros::offsets)] +#[repr( C )] +#[derive(qemu_api_macros:: Object )] +pub struct DummyChildState { + parent:ParentField <DummyState >, +} + +qom_isa! (DummyChildState :Object ,DeviceState ,DummyState ); + +pub struct DummyChildClass { + parent_class: <DummyState as ObjectType >::Class , +} + +unsafe impl ObjectType for DummyChildState { +type Class =DummyChildClass ; +const TYPE_NAME : &'staticCStr =c_str! ("dummy_child" ); +} + +impl ObjectImpl for DummyChildState { +type ParentType =DummyState ; +const ABSTRACT :bool =false ; +} + +impl DeviceImpl for DummyChildState {} + +impl ClassInitImpl <DummyClass >for DummyChildState { +fn class_init (klass: &mut DummyClass ) { + <Self as ClassInitImpl <DeviceClass >>::class_init (&mut klass.parent_class); + } +} + +impl ClassInitImpl <DummyChildClass >for DummyChildState { +fn class_init (klass: &mut DummyChildClass ) { + <Self as ClassInitImpl <DummyClass >>::class_init (&mut klass.parent_class); + } +} +fn init_qom () {static ONCE :BqlCell <bool > =BqlCell ::new (false );
@@ -85,6 +134,7 @@ fn test_object_new() {init_qom ();unsafe {object_unref (object_new (DummyState ::TYPE_NAME .as_ptr ()).cast ()); +object_unref (object_new (DummyChildState ::TYPE_NAME .as_ptr ()).cast ()); } }
Signature · 1 line
2.48.1
[PULL 37/48] rust: pl011: hide unnecessarily "pub" items from outside pl011::device
In reply to Paolo BonziniThe only public interfaces for pl011 are TYPE_PL011 and pl011_create. Remove pub from everything else.
Note: the "allow(dead_code)" is removed later.
--- rust/hw/char/pl011/src/device.rs | 2 +- rust/hw/char/pl011/src/device_class.rs | 2 +- rust/hw/char/pl011/src/lib.rs | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-)
rust/hw/char/pl011/src/device.rs +1 -1
@@ -573,7 +573,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { }/// Which bits in the interrupt status matter for each outbound IRQ line ? -pub const IRQMASK: [u32; 6] = [ +const IRQMASK: [u32; 6] = [ /* combined IRQ */ Interrupt::E | Interrupt::MS
rust/hw/char/pl011/src/device_class.rs +1 -1
@@ -19,7 +19,7 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { }/// Migration subsection for [`PL011State`] clock. -pub static VMSTATE_PL011_CLOCK :VMStateDescription =VMStateDescription { +static VMSTATE_PL011_CLOCK :VMStateDescription =VMStateDescription { name:c_str! ("pl011/clock" ).as_ptr (), version_id:1 , minimum_version_id:1 ,
rust/hw/char/pl011/src/lib.rs +8 -5
@@ -27,9 +27,11 @@use qemu_api::c_str; -pub mod device; -pub mod device_class; -pub mod memory_ops; +mod device; +mod device_class; +mod memory_ops; + +pub use device::pl011_create;pub const TYPE_PL011 : &::std::ffi::CStr =c_str! ("pl011" );pub const TYPE_PL011_LUMINARY : &::std::ffi::CStr =c_str! ("pl011_luminary" );
@@ -42,7 +44,7 @@#[allow(non_camel_case_types)] #[repr( u64 )] #[derive( Debug , qemu_api_macros:: TryInto )] -pub enum RegisterOffset { +enum RegisterOffset {/// Data Register /// /// A write to this register initiates the actual data transmission
@@ -98,7 +100,8 @@ pub enum RegisterOffset {//Reserved = 0x04C, } -pub mod registers { +#[allow(dead_code)] +mod registers {//! Device registers exposed as typed structs which are backed by arbitrary //! integer bitmaps. [`Data`], [`Control`], [`LineControl`], etc. use bilge::prelude::*;
Signature · 1 line
2.48.1
[PULL 06/48] target/i386: reorganize ops emitted by do_gen_rep, drop repz_opt
In reply to Paolo BonziniThe condition for optimizing repeat instruction is more or less the opposite of what you imagine: almost always the string instruction was _not_ optimized and optimizing the loop relied on goto_tb. This is obviously not great for performance, due to the cost of the exit-to-main-loop check, but also wrong. In fact, after expanding dc->jmp_opt and simplifying "!!x" to "x", the condition for looping used to be:
((cflags & CF_NO_GOTO_TB) ||
(flags & (HF_RF_MASK | HF_TF_MASK | HF_INHIBIT_IRQ_MASK))) && !(cflags & CF_USE_ICOUNT)In other words, setting aside RF (it requires special handling for REP instructions and it was completely missing), repeat instruction were being optimized if TF or inhibit IRQ flags were set. This is certainly wrong for TF, because string instructions trap after every execution, and probably for interrupt shadow too.
Get rid of repz_opt completely. The next patches will reintroduce the optimization, applying it in the common case instead of the unlikely and wrong one.
While at it, place the CX/ECX/RCX=0 case is at the end of the function, which saves a label and is clearer when reading the generated ops. For clarity, mark the cc_op explicitly as DYNAMIC even if at the end of the translation block; the cc_op can come from either the previous instruction or the string instruction, and currently we rely on a gen_update_cc_op() that is hidden in the bowels of gen_jcc() to spill cc_op and mark it clean.
--- target/i386/tcg/translate.c | 60 ++++++++----------------------------- 1 file changed, 13 insertions(+), 47 deletions(-)
target/i386/tcg/translate.c +13 -47
@@ -113,7 +113,6 @@ typedef struct DisasContext {#endif bool vex_w;/* used by AVX even on 32-bit processors */ bool jmp_opt;/* use direct block chaining for direct jumps */ -bool repz_opt;/* optimize jumps within repz instructions */ bool cc_op_dirty;CCOp cc_op;/* current CC operation */
@@ -1206,23 +1205,6 @@ static inline void gen_jcc(DisasContext *s, int b, TCGLabel *l1) } } -/* XXX: does not work with gdbstub "ice" single step - not a -serious problem. The caller can jump to the returned label -to stop the REP but, if the flags have changed, it has to call -gen_update_cc_op before doing so. */ -static TCGLabel *gen_jz_ecx_string (DisasContext *s) -{ -TCGLabel *l1 =gen_new_label (); -TCGLabel *l2 =gen_new_label (); - -gen_update_cc_op (s); -gen_op_jnz_ecx (s, l1); -gen_set_label (l2); -gen_jmp_rel_csize (s,0 ,1 ); -gen_set_label (l1); -return l2; -} -static void gen_stos (DisasContext *s,MemOp ot) {gen_string_movl_A0_EDI (s);
@@ -1314,27 +1296,25 @@ static void do_gen_rep(DisasContext *s, MemOp ot, void (*fn)(DisasContext *s, MemOp ot), bool is_repz_nz) { -TCGLabel *l2; - l2 =gen_jz_ecx_string (s); +TCGLabel *done =gen_new_label (); + +gen_update_cc_op (s); +gen_op_jz_ecx (s, done); +fn (s, ot);gen_op_add_reg_im (s, s->aflag,R_ECX ,-1 );if (is_repz_nz) {int nz = (s->prefix &PREFIX_REPNZ ) ?1 :0 ; -gen_jcc (s, (JCC_Z <<1 ) | (nz ^1 ), l2); +gen_jcc (s, (JCC_Z <<1 ) | (nz ^1 ), done); } -/* -* A loop would cause two single step exceptions if ECX = 1 -* before rep string_insn -*/ -if (s->repz_opt) { -gen_op_jz_ecx (s, l2); - } -/* -* For CMPS/SCAS there is no need to set CC_OP_DYNAMIC: only one iteration -* is done at a time, so the translation block ends unconditionally after -* this instruction and there is no control flow junction. -*/ + +/* Go to the main loop but reenter the same instruction. */ gen_jmp_rel_csize (s, -cur_insn_len (s),0 ); + +/* CX/ECX/RCX is zero, or REPZ/REPNZ broke the repetition. */ +gen_set_label (done); +set_cc_op (s,CC_OP_DYNAMIC ); +gen_jmp_rel_csize (s,0 ,1 ); } static void gen_repz(DisasContext *s, MemOp ot,
@@ -3665,20 +3645,6 @@ static void i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu) dc->cpuid_xsave_features = env->features[FEAT_XSAVE ]; dc->jmp_opt = !((cflags &CF_NO_GOTO_TB ) || (flags & (HF_RF_MASK |HF_TF_MASK |HF_INHIBIT_IRQ_MASK ))); -/* -* If jmp_opt, we want to handle each string instruction individually. -* For icount also disable repz optimization so that each iteration -* is accounted separately. -* -* FIXME: this is messy; it makes REP string instructions a lot less -* efficient than they should be and it gets in the way of correct -* handling of RF (interrupts or traps arriving after any iteration -* of a repeated string instruction but the last should set RF to 1). -* Perhaps it would be more efficient if REP string instructions were -* always at the beginning of the TB, or even their own TB? That -* would even allow accounting up to 64k iterations at once for icount. -*/ - dc->repz_opt = !dc->jmp_opt && !(cflags &CF_USE_ICOUNT ); dc->T0 =tcg_temp_new (); dc->T1 =tcg_temp_new ();
Signature · 1 line
2.48.1
[PULL 16/48] target/i386: Introduce SierraForest-v2 model
In reply to Paolo BonziniFrom: Tao Su <[email protected]>
Update SierraForest CPU model to add LAM, 4 bits indicating certain bits of IA32_SPEC_CTR are supported(intel-psfd, ipred-ctrl, rrsba-ctrl, bhi-ctrl) and the missing features(ss, tsc-adjust, cldemote, movdiri, movdir64b)
Also add GDS-NO and RFDS-NO to indicate the related vulnerabilities are mitigated in stepping 3.
--- target/i386/cpu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
target/i386/cpu.c +19 -0
@@ -4549,6 +4549,25 @@ static const X86CPUDefinition builtin_x86_defs[] = { .model_id = "Intel Xeon Processor (SierraForest)", .versions = (X86CPUVersionDefinition []) { { .version =1 }, + { + .version =2 , + .props = (PropValue []) { + {"ss" ,"on" }, + {"tsc-adjust" ,"on" }, + {"cldemote" ,"on" }, + {"movdiri" ,"on" }, + {"movdir64b" ,"on" }, + {"gds-no" ,"on" }, + {"rfds-no" ,"on" }, + {"lam" ,"on" }, + {"intel-psfd" ,"on" }, + {"ipred-ctrl" ,"on" }, + {"rrsba-ctrl" ,"on" }, + {"bhi-ctrl" ,"on" }, + {"stepping" ,"3" }, + {/* end of list */ } + } + }, {/* end of list */ }, }, },
Signature · 1 line
2.48.1
[PULL 14/48] target/i386: extract common bits of gen_repz/gen_repz_nz
In reply to Paolo BonziniNow that everything has been cleaned up, look at DF and prefixes in a single function, and call that one from gen_repz and gen_repz_nz.
--- target/i386/tcg/translate.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)
target/i386/tcg/translate.c +14 -20
@@ -688,14 +688,6 @@ static inline void gen_string_movl_A0_EDI(DisasContext *s)gen_lea_v_seg (s, cpu_regs[R_EDI ],R_ES ,-1 ); } -static inline TCGv gen_compute_Dshift (DisasContext *s,MemOp ot) -{ -TCGv dshift =tcg_temp_new (); -tcg_gen_ld32s_tl (dshift, tcg_env, offsetof(CPUX86State , df)); -tcg_gen_shli_tl (dshift, dshift, ot); -return dshift; -}; -static TCGv gen_ext_tl (TCGv dst,TCGv src,MemOp size,bool sign) {if (size ==MO_TL ) {
@@ -1446,29 +1438,31 @@ static void do_gen_rep(DisasContext *s, MemOp ot, TCGv dshift,gen_jmp_rel_csize (s,0 ,1 ); } -static void gen_repz (DisasContext *s,MemOp ot, -void (*fn)(DisasContext *s,MemOp ot,TCGv dshift)) - +static void do_gen_string (DisasContext *s,MemOp ot, +void (*fn)(DisasContext *s,MemOp ot,TCGv dshift), +bool is_repz_nz) { -TCGv dshift =gen_compute_Dshift (s, ot); +TCGv dshift =tcg_temp_new (); +tcg_gen_ld32s_tl (dshift, tcg_env, offsetof(CPUX86State , df)); +tcg_gen_shli_tl (dshift, dshift, ot);if (s->prefix & (PREFIX_REPZ |PREFIX_REPNZ )) { -do_gen_rep (s, ot, dshift, fn, false); +do_gen_rep (s, ot, dshift, fn, is_repz_nz); }else {fn (s, ot, dshift); } } +static void gen_repz (DisasContext *s,MemOp ot, +void (*fn)(DisasContext *s,MemOp ot,TCGv dshift)) +{ +do_gen_string (s, ot, fn, false); +} +static void gen_repz_nz (DisasContext *s,MemOp ot,void (*fn)(DisasContext *s,MemOp ot,TCGv dshift)) { -TCGv dshift =gen_compute_Dshift (s, ot); - -if (s->prefix & (PREFIX_REPZ |PREFIX_REPNZ )) { -do_gen_rep (s, ot, dshift, fn, true); - }else { -fn (s, ot, dshift); - } +do_gen_string (s, ot, fn, true); }static void gen_helper_fp_arith_ST0_FT0 (int op)
Signature · 1 line
2.48.1
[PULL 30/48] rust: vmstate: add public utility macros to implement VMState
In reply to Paolo Bonzini--- rust/qemu-api/src/vmstate.rs | 61 ++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-)
rust/qemu-api/src/vmstate.rs +58 -3
@@ -4,13 +4,18 @@//! Helper macros to declare migration state for device models. //! -//! This module includes three families of macros: +//! This module includes four families of macros: //! //! * [`vmstate_unused!`](crate::vmstate_unused) and //! [`vmstate_of!`](crate::vmstate_of), which are used to express the //! migration format for a struct. This is based on the [`VMState`] trait, //! which is defined by all migrateable types. //! +//! * [`impl_vmstate_forward`](crate::impl_vmstate_forward) and +//! [`impl_vmstate_bitsized`](crate::impl_vmstate_bitsized), which help with +//! the definition of the [`VMState`] trait (respectively for transparent +//! structs and for `bilge`-defined types) +//! //! * helper macros to declare a device model state struct, in particular //! [`vmstate_subsections`](crate::vmstate_subsections) and //! [`vmstate_fields`](crate::vmstate_fields).
@@ -134,7 +139,9 @@ macro_rules! info_enum_to_ref {/// # Safety /// /// The contents of this trait go straight into structs that are parsed by C -/// code and used to introspect into other structs. Be careful. +/// code and used to introspect into other structs. Generally, you don't need +/// to implement it except via macros that do it for you, such as +/// `impl_vmstate_bitsized!`. pub unsafe trait VMState {/// The `info` member of a `VMStateField` is a pointer and as such cannot /// yet be included in the [`BASE`](VMState::BASE) associated constant;
@@ -188,7 +195,9 @@ pub const fn vmstate_varray_flag<T: VMState>(_: PhantomData<T>) -> VMStateFlags/// * an array of any of the above /// /// In order to support other types, the trait `VMState` must be implemented -/// for them. +/// for them. The macros +/// [`impl_vmstate_bitsized!`](crate::impl_vmstate_bitsized) +/// and [`impl_vmstate_forward!`](crate::impl_vmstate_forward) help with this. #[macro_export] macro_rules! vmstate_of { ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:expr)?])? $(,)?) => {
@@ -276,6 +285,32 @@ pub const fn with_varray_multiply(mut self, num: u32) -> VMStateField { } } +/// This macro can be used (by just passing it a type) to forward the `VMState` +/// trait to the first field of a tuple. This is a workaround for lack of +/// support of nested [`offset_of`](core::mem::offset_of) until Rust 1.82.0. +/// +/// # Examples +/// +/// ``` +/// # use qemu_api::vmstate::impl_vmstate_forward; +/// pub struct Fifo([u8; 16]); +/// impl_vmstate_forward!(Fifo); +/// ``` +#[macro_export] +macro_rules! impl_vmstate_forward { +// This is similar to impl_vmstate_transparent below, but it +// uses the same trick as vmstate_of! to obtain the type of +// the first field of the tuple + ($tuple:ty) => { +unsafe impl $crate::vmstate::VMState for $tuple { +const SCALAR_TYPE : $crate::vmstate::VMStateFieldType = + $crate::call_func_with_field!($crate ::vmstate::vmstate_scalar_type, $tuple,0 ); +const BASE : $crate::bindings::VMStateField = + $crate::call_func_with_field!($crate ::vmstate::vmstate_base, $tuple,0 ); + } + }; +} +// Transparent wrappers: just use the internal type macro_rules! impl_vmstate_transparent {
@@ -296,6 +331,26 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* {impl_vmstate_transparent! (crate ::cell::BqlCell <T >where T :VMState );impl_vmstate_transparent! (crate ::cell::BqlRefCell <T >where T :VMState ); +#[macro_export] +macro_rules! impl_vmstate_bitsized { + ($type:ty) => { +unsafe impl $crate::vmstate::VMState for $type { +const SCALAR_TYPE : $crate::vmstate::VMStateFieldType = + <<<$typeas ::bilge::prelude::Bitsized >::ArbitraryInt +as ::bilge::prelude::Number >::UnderlyingType +as $crate::vmstate::VMState >::SCALAR_TYPE ; +const BASE : $crate::bindings::VMStateField = + <<<$typeas ::bilge::prelude::Bitsized >::ArbitraryInt +as ::bilge::prelude::Number >::UnderlyingType +as $crate::vmstate::VMState >::BASE ; +const VARRAY_FLAG : $crate::bindings::VMStateFlags = + <<<$typeas ::bilge::prelude::Bitsized >::ArbitraryInt +as ::bilge::prelude::Number >::UnderlyingType +as $crate::vmstate::VMState >::VARRAY_FLAG ; + } + }; +} +// Scalar types using predefined VMStateInfos macro_rules! impl_vmstate_scalar {
Signature · 1 line
2.48.1
[PULL 07/48] target/i386: tcg: move gen_set/reset_* earlier in the file
In reply to Paolo BonziniAllow using them in the code that translates REP/REPZ, without forward declarations.
--- target/i386/tcg/translate.c | 80 ++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 40 deletions(-)
target/i386/tcg/translate.c +40 -40
@@ -725,6 +725,46 @@ static inline void gen_op_jnz_ecx(DisasContext *s, TCGLabel *label1)gen_op_j_ecx (s,TCG_COND_NE , label1); } +static void gen_set_hflag (DisasContext *s,uint32_t mask) +{ +if ((s->flags & mask) ==0 ) { +TCGv_i32 t =tcg_temp_new_i32 (); +tcg_gen_ld_i32 (t, tcg_env, offsetof(CPUX86State , hflags)); +tcg_gen_ori_i32 (t, t, mask); +tcg_gen_st_i32 (t, tcg_env, offsetof(CPUX86State , hflags)); + s->flags |= mask; + } +} + +static void gen_reset_hflag (DisasContext *s,uint32_t mask) +{ +if (s->flags & mask) { +TCGv_i32 t =tcg_temp_new_i32 (); +tcg_gen_ld_i32 (t, tcg_env, offsetof(CPUX86State , hflags)); +tcg_gen_andi_i32 (t, t, ~mask); +tcg_gen_st_i32 (t, tcg_env, offsetof(CPUX86State , hflags)); + s->flags &= ~mask; + } +} + +static void gen_set_eflags (DisasContext *s,target_ulong mask) +{ +TCGv t =tcg_temp_new (); + +tcg_gen_ld_tl (t, tcg_env, offsetof(CPUX86State , eflags)); +tcg_gen_ori_tl (t, t, mask); +tcg_gen_st_tl (t, tcg_env, offsetof(CPUX86State , eflags)); +} + +static void gen_reset_eflags (DisasContext *s,target_ulong mask) +{ +TCGv t =tcg_temp_new (); + +tcg_gen_ld_tl (t, tcg_env, offsetof(CPUX86State , eflags)); +tcg_gen_andi_tl (t, t, ~mask); +tcg_gen_st_tl (t, tcg_env, offsetof(CPUX86State , eflags)); +} +static void gen_helper_in_func (MemOp ot,TCGv v,TCGv_i32 n) {switch (ot) {
@@ -2084,46 +2124,6 @@ static void gen_interrupt(DisasContext *s, uint8_t intno) s->base.is_jmp =DISAS_NORETURN ; } -static void gen_set_hflag (DisasContext *s,uint32_t mask) -{ -if ((s->flags & mask) ==0 ) { -TCGv_i32 t =tcg_temp_new_i32 (); -tcg_gen_ld_i32 (t, tcg_env, offsetof(CPUX86State , hflags)); -tcg_gen_ori_i32 (t, t, mask); -tcg_gen_st_i32 (t, tcg_env, offsetof(CPUX86State , hflags)); - s->flags |= mask; - } -} - -static void gen_reset_hflag (DisasContext *s,uint32_t mask) -{ -if (s->flags & mask) { -TCGv_i32 t =tcg_temp_new_i32 (); -tcg_gen_ld_i32 (t, tcg_env, offsetof(CPUX86State , hflags)); -tcg_gen_andi_i32 (t, t, ~mask); -tcg_gen_st_i32 (t, tcg_env, offsetof(CPUX86State , hflags)); - s->flags &= ~mask; - } -} - -static void gen_set_eflags (DisasContext *s,target_ulong mask) -{ -TCGv t =tcg_temp_new (); - -tcg_gen_ld_tl (t, tcg_env, offsetof(CPUX86State , eflags)); -tcg_gen_ori_tl (t, t, mask); -tcg_gen_st_tl (t, tcg_env, offsetof(CPUX86State , eflags)); -} - -static void gen_reset_eflags (DisasContext *s,target_ulong mask) -{ -TCGv t =tcg_temp_new (); - -tcg_gen_ld_tl (t, tcg_env, offsetof(CPUX86State , eflags)); -tcg_gen_andi_tl (t, t, ~mask); -tcg_gen_st_tl (t, tcg_env, offsetof(CPUX86State , eflags)); -} -/* Clear BND registers during legacy branches. */ static void gen_bnd_jmp (DisasContext *s) {
Signature · 1 line
2.48.1
[PULL 29/48] rust: vmstate: implement VMState for scalar types
In reply to Paolo BonziniScalar types are those that have their own VMStateInfo. This poses a problem in that references to VMStateInfo can only be included in associated consts starting with Rust 1.83.0, when the const_refs_static was stabilized. Removing the requirement is done by placing a limited list of VMStateInfos in an enum, and going from enum to &VMStateInfo only when building the VMStateField.
The same thing cannot be done with VMS_STRUCT because the set of VMStateDescriptions extends to structs defined by the devices. Therefore, structs and cells cannot yet use vmstate_of!.
--- rust/qemu-api/src/vmstate.rs | 128 ++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 2 deletions(-)
rust/qemu-api/src/vmstate.rs +126 -2
@@ -22,7 +22,10 @@use core::{marker::PhantomData , mem, ptr::NonNull };pub use crate ::bindings::{VMStateDescription ,VMStateField }; -use crate ::bindings::VMStateFlags ; +use crate ::{ + bindings::{self,VMStateFlags }, + zeroable::Zeroable , +};/// This macro is used to call a function with a generic argument bound /// to the type of a field. The function must take a
@@ -61,6 +64,70 @@ const fn phantom__<T>(_: &T) -> ::core::marker::PhantomData<T> { ::core::marker: }; } +/// Workaround for lack of `const_refs_static`: references to global variables +/// can be included in a `static`, but not in a `const`; unfortunately, this +/// is exactly what would go in the `VMStateField`'s `info` member. +/// +/// This enum contains the contents of the `VMStateField`'s `info` member, +/// but as an `enum` instead of a pointer. +#[allow(non_camel_case_types)] +pub enum VMStateFieldType { + null, + vmstate_info_bool, + vmstate_info_int8, + vmstate_info_int16, + vmstate_info_int32, + vmstate_info_int64, + vmstate_info_uint8, + vmstate_info_uint16, + vmstate_info_uint32, + vmstate_info_uint64, + vmstate_info_timer, +} + +/// Workaround for lack of `const_refs_static`. Converts a `VMStateFieldType` +/// to a `*const VMStateInfo`, for inclusion in a `VMStateField`. +#[macro_export] +macro_rules! info_enum_to_ref { + ($e:expr) => { +unsafe { +match $e { + $crate::vmstate::VMStateFieldType ::null => ::core::ptr::null (), + $crate::vmstate::VMStateFieldType ::vmstate_info_bool => { + ::core::ptr::addr_of!($crate ::bindings::vmstate_info_bool) + } + $crate::vmstate::VMStateFieldType ::vmstate_info_int8 => { + ::core::ptr::addr_of!($crate ::bindings::vmstate_info_int8) + } + $crate::vmstate::VMStateFieldType ::vmstate_info_int16 => { + ::core::ptr::addr_of!($crate ::bindings::vmstate_info_int16) + } + $crate::vmstate::VMStateFieldType ::vmstate_info_int32 => { + ::core::ptr::addr_of!($crate ::bindings::vmstate_info_int32) + } + $crate::vmstate::VMStateFieldType ::vmstate_info_int64 => { + ::core::ptr::addr_of!($crate ::bindings::vmstate_info_int64) + } + $crate::vmstate::VMStateFieldType ::vmstate_info_uint8 => { + ::core::ptr::addr_of!($crate ::bindings::vmstate_info_uint8) + } + $crate::vmstate::VMStateFieldType ::vmstate_info_uint16 => { + ::core::ptr::addr_of!($crate ::bindings::vmstate_info_uint16) + } + $crate::vmstate::VMStateFieldType ::vmstate_info_uint32 => { + ::core::ptr::addr_of!($crate ::bindings::vmstate_info_uint32) + } + $crate::vmstate::VMStateFieldType ::vmstate_info_uint64 => { + ::core::ptr::addr_of!($crate ::bindings::vmstate_info_uint64) + } + $crate::vmstate::VMStateFieldType ::vmstate_info_timer => { + ::core::ptr::addr_of!($crate ::bindings::vmstate_info_timer) + } + } + } + }; +} +/// A trait for types that can be included in a device's migration stream. It /// provides the base contents of a `VMStateField` (minus the name and offset). ///
@@ -69,6 +136,12 @@ const fn phantom__<T>(_: &T) -> ::core::marker::PhantomData<T> { ::core::marker:/// The contents of this trait go straight into structs that are parsed by C /// code and used to introspect into other structs. Be careful. pub unsafe trait VMState { +/// The `info` member of a `VMStateField` is a pointer and as such cannot +/// yet be included in the [`BASE`](VMState::BASE) associated constant; +/// this is only allowed by Rust 1.83.0 and newer. For now, include the +/// member as an enum which is stored in a separate constant. +const SCALAR_TYPE :VMStateFieldType =VMStateFieldType ::null; +/// The base contents of a `VMStateField` (minus the name and offset) for /// the type that is implementing the trait. const BASE :VMStateField ;
@@ -83,6 +156,12 @@ pub unsafe trait VMState { }; } +/// Internal utility function to retrieve a type's `VMStateFieldType`; +/// used by [`vmstate_of!`](crate::vmstate_of). +pub const fn vmstate_scalar_type <T :VMState >(_:PhantomData <T >) ->VMStateFieldType { +T ::SCALAR_TYPE +} +/// Internal utility function to retrieve a type's `VMStateField`; /// used by [`vmstate_of!`](crate::vmstate_of). pub const fn vmstate_base <T :VMState >(_:PhantomData <T >) ->VMStateField {
@@ -99,6 +178,15 @@ pub const fn vmstate_varray_flag<T: VMState>(_: PhantomData<T>) -> VMStateFlags/// Return the `VMStateField` for a field of a struct. The field must be /// visible in the current scope. /// +/// Only a limited set of types is supported out of the box: +/// * scalar types (integer and `bool`) +/// * the C struct `QEMUTimer` +/// * a transparent wrapper for any of the above (`Cell`, `UnsafeCell`, +/// [`BqlCell`](crate::cell::BqlCell), [`BqlRefCell`](crate::cell::BqlRefCell) +/// * a raw pointer to any of the above +/// * a `NonNull` pointer or a `Box` for any of the above +/// * an array of any of the above +/// /// In order to support other types, the trait `VMState` must be implemented /// for them. #[macro_export]
@@ -109,8 +197,14 @@ macro_rules! vmstate_of { .as_bytes() .as_ptr() as *const ::std::os::raw::c_char, offset: $crate::offset_of!($struct_name, $field_name), - // Compute most of the VMStateField from the type of the field. $(.num_offset: $crate::offset_of!($struct_name, $num),)? + // The calls to `call_func_with_field!` are the magic that + // computes most of the VMStateField from the type of the field. + info: $crate::info_enum_to_ref!($crate::call_func_with_field!( + $crate::vmstate::vmstate_scalar_type, + $struct_name, + $field_name + )), ..$crate::call_func_with_field!( $crate::vmstate::vmstate_base, $struct_name,
@@ -187,6 +281,7 @@ pub const fn with_varray_multiply(mut self, num: u32) -> VMStateField {macro_rules! impl_vmstate_transparent { ($type:tywhere $base:tt:VMState $($where:tt)*) => {unsafe impl <$base>VMState for $typewhere $base:VMState $($where)* { +const SCALAR_TYPE :VMStateFieldType = <$baseas VMState >::SCALAR_TYPE ;const BASE :VMStateField =VMStateField { size: mem::size_of ::<$type>(), ..<$baseas VMState >::BASE
@@ -201,6 +296,33 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* {impl_vmstate_transparent! (crate ::cell::BqlCell <T >where T :VMState );impl_vmstate_transparent! (crate ::cell::BqlRefCell <T >where T :VMState ); +// Scalar types using predefined VMStateInfos + +macro_rules! impl_vmstate_scalar { + ($info:ident, $type:ty$(, $varray_flag:ident)?) => { +unsafe impl VMState for $type { +const SCALAR_TYPE :VMStateFieldType =VMStateFieldType ::$info; +const BASE :VMStateField =VMStateField { + size: mem::size_of ::<$type>(), + flags:VMStateFlags ::VMS_SINGLE , + ..Zeroable ::ZERO + }; + $(const VARRAY_FLAG :VMStateFlags =VMStateFlags ::$varray_flag;)? + } + }; +} + +impl_vmstate_scalar! (vmstate_info_bool,bool ); +impl_vmstate_scalar! (vmstate_info_int8,i8 ); +impl_vmstate_scalar! (vmstate_info_int16,i16 ); +impl_vmstate_scalar! (vmstate_info_int32,i32 ); +impl_vmstate_scalar! (vmstate_info_int64,i64 ); +impl_vmstate_scalar! (vmstate_info_uint8,u8 ,VMS_VARRAY_UINT8 ); +impl_vmstate_scalar! (vmstate_info_uint16,u16 ,VMS_VARRAY_UINT16 ); +impl_vmstate_scalar! (vmstate_info_uint32,u32 ,VMS_VARRAY_UINT32 ); +impl_vmstate_scalar! (vmstate_info_uint64,u64 ); +impl_vmstate_scalar! (vmstate_info_timer, bindings::QEMUTimer ); +// Pointer types using the underlying type's VMState plus VMS_POINTER // Note that references are not supported, though references to cells // could be allowed.
@@ -208,6 +330,7 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* {macro_rules! impl_vmstate_pointer { ($type:tywhere $base:tt:VMState $($where:tt)*) => {unsafe impl <$base>VMState for $typewhere $base:VMState $($where)* { +const SCALAR_TYPE :VMStateFieldType = <T as VMState >::SCALAR_TYPE ;const BASE :VMStateField = <$baseas VMState >::BASE .with_pointer_flag (); } };
@@ -225,6 +348,7 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* {// VMS_ARRAY/VMS_ARRAY_OF_POINTER unsafe impl <T :VMState ,const N :usize >VMState for [T ;N ] { +const SCALAR_TYPE :VMStateFieldType = <T as VMState >::SCALAR_TYPE ;const BASE :VMStateField = <T as VMState >::BASE .with_array_flag (N ); }
Signature · 1 line
2.48.1
[PULL 36/48] rust: pl011: remove unnecessary "extern crate"
In reply to Paolo Bonzini--- rust/hw/char/pl011/src/lib.rs | 4 ---- 1 file changed, 4 deletions(-)
rust/hw/char/pl011/src/lib.rs +0 -4
@@ -25,10 +25,6 @@#![allow(clippy::upper_case_acronyms)] #![allow(clippy::result_unit_err)] -extern crate bilge; -extern crate bilge_impl; -extern crate qemu_api; -use qemu_api::c_str;pub mod device;
Signature · 1 line
2.48.1
[PULL 13/48] target/i386: pull computation of string update value out of loop
In reply to Paolo BonziniThis is a common operation that is executed many times in rep movs or rep stos loops. It can improve performance by several percentage points.
--- target/i386/tcg/translate.c | 54 ++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 28 deletions(-)
target/i386/tcg/translate.c +26 -28
@@ -832,16 +832,13 @@ static bool gen_check_io(DisasContext *s, MemOp ot, TCGv_i32 port,#endif } -static void gen_movs (DisasContext *s,MemOp ot) +static void gen_movs (DisasContext *s,MemOp ot,TCGv dshift) { -TCGv dshift; -gen_string_movl_A0_ESI (s);gen_op_ld_v (s, ot, s->T0, s->A0);gen_string_movl_A0_EDI (s);gen_op_st_v (s, ot, s->T0, s->A0); - dshift =gen_compute_Dshift (s, ot);gen_op_add_reg (s, s->aflag,R_ESI , dshift);gen_op_add_reg (s, s->aflag,R_EDI , dshift); }
@@ -1246,22 +1243,22 @@ static inline void gen_jcc(DisasContext *s, int b, TCGLabel *l1) } } -static void gen_stos (DisasContext *s,MemOp ot) +static void gen_stos (DisasContext *s,MemOp ot,TCGv dshift) {gen_string_movl_A0_EDI (s);gen_op_st_v (s, ot, s->T0, s->A0); -gen_op_add_reg (s, s->aflag,R_EDI ,gen_compute_Dshift (s, ot)); +gen_op_add_reg (s, s->aflag,R_EDI , dshift); } -static void gen_lods (DisasContext *s,MemOp ot) +static void gen_lods (DisasContext *s,MemOp ot,TCGv dshift) {gen_string_movl_A0_ESI (s);gen_op_ld_v (s, ot, s->T0, s->A0);gen_op_mov_reg_v (s, ot,R_EAX , s->T0); -gen_op_add_reg (s, s->aflag,R_ESI ,gen_compute_Dshift (s, ot)); +gen_op_add_reg (s, s->aflag,R_ESI , dshift); } -static void gen_scas (DisasContext *s,MemOp ot) +static void gen_scas (DisasContext *s,MemOp ot,TCGv dshift) {gen_string_movl_A0_EDI (s);gen_op_ld_v (s, ot, s->T1, s->A0);
@@ -1270,13 +1267,11 @@ static void gen_scas(DisasContext *s, MemOp ot)tcg_gen_sub_tl (cpu_cc_dst, s->T0, s->T1);set_cc_op (s,CC_OP_SUBB + ot); -gen_op_add_reg (s, s->aflag,R_EDI ,gen_compute_Dshift (s, ot)); +gen_op_add_reg (s, s->aflag,R_EDI , dshift); } -static void gen_cmps (DisasContext *s,MemOp ot) +static void gen_cmps (DisasContext *s,MemOp ot,TCGv dshift) { -TCGv dshift; -gen_string_movl_A0_EDI (s);gen_op_ld_v (s, ot, s->T1, s->A0);gen_string_movl_A0_ESI (s);
@@ -1286,7 +1281,6 @@ static void gen_cmps(DisasContext *s, MemOp ot)tcg_gen_sub_tl (cpu_cc_dst, s->T0, s->T1);set_cc_op (s,CC_OP_SUBB + ot); - dshift =gen_compute_Dshift (s, ot);gen_op_add_reg (s, s->aflag,R_ESI , dshift);gen_op_add_reg (s, s->aflag,R_EDI , dshift); }
@@ -1305,7 +1299,7 @@ static void gen_bpt_io(DisasContext *s, TCGv_i32 t_port, int ot) } } -static void gen_ins (DisasContext *s,MemOp ot) +static void gen_ins (DisasContext *s,MemOp ot,TCGv dshift) {gen_string_movl_A0_EDI (s);/* Note: we must do this dummy write first to be restartable in
@@ -1316,11 +1310,11 @@ static void gen_ins(DisasContext *s, MemOp ot)tcg_gen_andi_i32 (s->tmp2_i32, s->tmp2_i32,0xffff );gen_helper_in_func (ot, s->T0, s->tmp2_i32);gen_op_st_v (s, ot, s->T0, s->A0); -gen_op_add_reg (s, s->aflag,R_EDI ,gen_compute_Dshift (s, ot)); +gen_op_add_reg (s, s->aflag,R_EDI , dshift);gen_bpt_io (s, s->tmp2_i32, ot); } -static void gen_outs (DisasContext *s,MemOp ot) +static void gen_outs (DisasContext *s,MemOp ot,TCGv dshift) {gen_string_movl_A0_ESI (s);gen_op_ld_v (s, ot, s->T0, s->A0);
@@ -1329,14 +1323,14 @@ static void gen_outs(DisasContext *s, MemOp ot)tcg_gen_andi_i32 (s->tmp2_i32, s->tmp2_i32,0xffff );tcg_gen_trunc_tl_i32 (s->tmp3_i32, s->T0);gen_helper_out_func (ot, s->tmp2_i32, s->tmp3_i32); -gen_op_add_reg (s, s->aflag,R_ESI ,gen_compute_Dshift (s, ot)); +gen_op_add_reg (s, s->aflag,R_ESI , dshift);gen_bpt_io (s, s->tmp2_i32, ot); }#define REP_MAX 65535 -static void do_gen_rep (DisasContext *s,MemOp ot, -void (*fn)(DisasContext *s,MemOp ot), +static void do_gen_rep (DisasContext *s,MemOp ot,TCGv dshift, +void (*fn)(DisasContext *s,MemOp ot,TCGv dshift),bool is_repz_nz) {TCGLabel *last =gen_new_label ();
@@ -1401,7 +1395,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot, }gen_set_label (loop); -fn (s, ot); +fn (s, ot, dshift);tcg_gen_mov_tl (cpu_regs[R_ECX ], cx_next);gen_update_cc_op (s);
@@ -1438,7 +1432,7 @@ static void do_gen_rep(DisasContext *s, MemOp ot,*/ gen_set_label (last);set_cc_op (s,CC_OP_DYNAMIC ); -fn (s, ot); +fn (s, ot, dshift);tcg_gen_mov_tl (cpu_regs[R_ECX ], cx_next);gen_update_cc_op (s); }
@@ -1453,23 +1447,27 @@ static void do_gen_rep(DisasContext *s, MemOp ot, }static void gen_repz (DisasContext *s,MemOp ot, -void (*fn)(DisasContext *s,MemOp ot)) +void (*fn)(DisasContext *s,MemOp ot,TCGv dshift)) { +TCGv dshift =gen_compute_Dshift (s, ot); +if (s->prefix & (PREFIX_REPZ |PREFIX_REPNZ )) { -do_gen_rep (s, ot, fn, false); +do_gen_rep (s, ot, dshift, fn, false); }else { -fn (s, ot); +fn (s, ot, dshift); } }static void gen_repz_nz (DisasContext *s,MemOp ot, -void (*fn)(DisasContext *s,MemOp ot)) +void (*fn)(DisasContext *s,MemOp ot,TCGv dshift)) { +TCGv dshift =gen_compute_Dshift (s, ot); +if (s->prefix & (PREFIX_REPZ |PREFIX_REPNZ )) { -do_gen_rep (s, ot, fn, true); +do_gen_rep (s, ot, dshift, fn, true); }else { -fn (s, ot); +fn (s, ot, dshift); } }
Signature · 1 line
2.48.1
[PULL 44/48] rust: pl011: pull device-specific code out of MemoryRegionOps callbacks
In reply to Paolo Bonziniread() can now return a simple u64.
--- rust/hw/char/pl011/src/device.rs | 23 +++++++++++++---------- rust/hw/char/pl011/src/memory_ops.rs | 18 ++---------------- 2 files changed, 15 insertions(+), 26 deletions(-)
rust/hw/char/pl011/src/device.rs +13 -10
@@ -12,9 +12,10 @@use qemu_api::{ bindings::{ error_fatal, hwaddr, memory_region_init_io, qdev_init_clock_in, qdev_new, - qdev_prop_set_chr, qemu_chr_fe_ioctl, qemu_chr_fe_set_handlers, qemu_chr_fe_write_all, - qemu_irq, sysbus_connect_irq, sysbus_mmio_map, sysbus_realize_and_unref,CharBackend , -Chardev ,Clock ,ClockEvent ,MemoryRegion ,QEMUChrEvent ,CHR_IOCTL_SERIAL_SET_BREAK , + qdev_prop_set_chr, qemu_chr_fe_accept_input, qemu_chr_fe_ioctl, qemu_chr_fe_set_handlers, + qemu_chr_fe_write_all, qemu_irq, sysbus_connect_irq, sysbus_mmio_map, + sysbus_realize_and_unref,CharBackend ,Chardev ,Clock ,ClockEvent ,MemoryRegion , +QEMUChrEvent ,CHR_IOCTL_SERIAL_SET_BREAK , }, c_str, impl_vmstate_forward, irq::InterruptSource ,
@@ -538,30 +539,32 @@ fn post_init(&self) { } } -#[allow(clippy::needless_pass_by_ref_mut)] -pub fn read (&mut self, offset:hwaddr , _size:u32 ) ->ControlFlow <u64 ,u64 > { +pub fn read (&mut self, offset:hwaddr , _size:u32 ) ->u64 {let mut update_irq =false ;let result =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 ])) + u32::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 ) +0 }Ok (field) =>match self.regs.borrow_mut ().read (field) { -ControlFlow ::Break (value) =>ControlFlow ::Break (value.into ()), +ControlFlow ::Break (value) => value,ControlFlow ::Continue (value) => { update_irq =true ; -ControlFlow ::Continue (value.into ()) + value } }, };if update_irq { self.update (); +unsafe { +qemu_chr_fe_accept_input (&mut self.char_backend); + } } - result + result.into () }pub fn write (&mut self, offset:hwaddr , value:u64 ) {
rust/hw/char/pl011/src/memory_ops.rs +2 -16
@@ -24,25 +24,11 @@ };unsafe extern "C" fn pl011_read (opaque: *mut c_void , addr:hwaddr , size:c_uint ) ->u64 { -assert! (!opaque.is_null ());let mut state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); -let val =unsafe { state.as_mut ().read (addr, size) }; -match val { - std::ops::ControlFlow ::Break (val) => val, - std::ops::ControlFlow ::Continue (val) => { -// SAFETY: self.char_backend is a valid CharBackend instance after it's been -// initialized in realize(). -let cb_ptr =unsafe { core::ptr::addr_of_mut!(state.as_mut ().char_backend) }; -unsafe { -qemu_chr_fe_accept_input (cb_ptr); - } - - val - } - } +unsafe { state.as_mut () }.read (addr, size) }unsafe extern "C" fn pl011_write (opaque: *mut c_void , addr:hwaddr , data:u64 , _size:c_uint ) {let mut state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); -unsafe { state.as_mut ().write (addr, data) } +unsafe { state.as_mut () }.write (addr, data); }
Signature · 1 line
2.48.1
[PULL 45/48] rust: pl011: drop use of ControlFlow
In reply to Paolo BonziniIt is a poor match for what the code is doing, anyway.
--- rust/hw/char/pl011/src/device.rs | 39 +++++++++++++++----------------- 1 file changed, 18 insertions(+), 21 deletions(-)
rust/hw/char/pl011/src/device.rs +18 -21
@@ -5,7 +5,6 @@use core::ptr::{addr_of, addr_of_mut,NonNull };use std::{ ffi::CStr , - ops::ControlFlow , os::raw::{c_int, c_void}, };
@@ -177,10 +176,11 @@ fn vmsd() -> Option<&'static VMStateDescription> { }impl PL011Registers { -pub (self)fn read (&mut self, offset:RegisterOffset ) ->ControlFlow <u32 ,u32 > { +pub (self)fn read (&mut self, offset:RegisterOffset ) -> (bool ,u32 ) {use RegisterOffset ::*; -ControlFlow ::Break (match offset { +let mut update =false ; +let result =match offset {DR => { self.flags.set_receive_fifo_full (false );let c = self.read_fifo[self.read_pos];
@@ -196,8 +196,9 @@ pub(self) fn read(&mut self, offset: RegisterOffset) -> ControlFlow<u32, u32> { }// Update error bits. self.receive_status_error_clear.set_from_data (c); -// Must call qemu_chr_fe_accept_input, so return Continue: -return ControlFlow ::Continue (u32::from (c)); +// Must call qemu_chr_fe_accept_input + update =true ; + u32::from (c) } RSR => u32::from(self.receive_status_error_clear), FR => u32::from(self.flags),
@@ -216,7 +217,8 @@ pub(self) fn read(&mut self, offset: RegisterOffset) -> ControlFlow<u32, u32> {0 } DMACR => self.dmacr, - }) + }; + (update, result) } pub(self) fn write(
@@ -540,31 +542,26 @@ fn post_init(&self) { }pub fn read (&mut self, offset:hwaddr , _size:u32 ) ->u64 { -let mut update_irq =false ; -let result =match RegisterOffset ::try_from (offset) { +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 ]) + u64::from (device_id[(offset -0xfe0 ) >>2 ]) }Err (_) => {// qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); 0 } -Ok (field) =>match self.regs.borrow_mut ().read (field) { -ControlFlow ::Break (value) => value, -ControlFlow ::Continue (value) => { - update_irq =true ; - value +Ok (field) => { +let (update_irq, result) = self.regs.borrow_mut ().read (field); +if update_irq { + self.update (); +unsafe { +qemu_chr_fe_accept_input (&mut self.char_backend); + } } - }, - }; -if update_irq { - self.update (); -unsafe { -qemu_chr_fe_accept_input (&mut self.char_backend); + result.into () } } - result.into () }pub fn write (&mut self, offset:hwaddr , value:u64 ) {
Signature · 1 line
2.48.1
[PULL 15/48] target/i386: avoid using s->tmp0 for add to implicit registers
In reply to Paolo BonziniFor updates to implicit registers (RCX in LOOP instructions, RSI or RDI in string instructions, or the stack pointer) do the add directly using the registers (with no temporary) if 32-bit or 64-bit, or use a temporary created for the occasion if 16-bit. This is more efficient and removes move instructions for the MO_TL case.
--- target/i386/tcg/translate.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
target/i386/tcg/translate.c +15 -8
@@ -505,17 +505,24 @@ static inline void gen_op_jmp_v(DisasContext *s, TCGv dest) s->pc_save =-1 ; } +static inline void gen_op_add_reg (DisasContext *s,MemOp size,int reg,TCGv val) +{ +/* Using cpu_regs[reg] does not work for xH registers. */ +assert (size >=MO_16 ); +if (size ==MO_16 ) { +TCGv temp =tcg_temp_new (); +tcg_gen_add_tl (temp, cpu_regs[reg], val); +gen_op_mov_reg_v (s, size, reg, temp); + }else { +tcg_gen_add_tl (cpu_regs[reg], cpu_regs[reg], val); +tcg_gen_ext_tl (cpu_regs[reg], cpu_regs[reg], size); + } +} +static inline void gen_op_add_reg_im (DisasContext *s,MemOp size,int reg,int32_t val) { -tcg_gen_addi_tl (s->tmp0, cpu_regs[reg], val); -gen_op_mov_reg_v (s, size, reg, s->tmp0); -} - -static inline void gen_op_add_reg (DisasContext *s,MemOp size,int reg,TCGv val) -{ -tcg_gen_add_tl (s->tmp0, cpu_regs[reg], val); -gen_op_mov_reg_v (s, size, reg, s->tmp0); +gen_op_add_reg (s, size, reg,tcg_constant_tl (val)); }static inline void gen_op_ld_v (DisasContext *s,int idx,TCGv t0,TCGv a0)
Signature · 1 line
2.48.1
[PULL 39/48] rust: pl011: extract CharBackend receive logic into a separate function
In reply to Paolo BonziniPrepare for moving all references to the registers and the FIFO into a separate struct.
--- rust/hw/char/pl011/src/device.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
rust/hw/char/pl011/src/device.rs +9 -6
@@ -6,7 +6,7 @@use std::{ ffi::CStr , ops::ControlFlow , - os::raw::{c_int, c_uint, c_void}, + os::raw::{c_int, c_void}, };use qemu_api::{
@@ -488,6 +488,12 @@ pub fn can_receive(&self) -> bool { self.read_count < self.fifo_depth () } +pub fn receive (&mut self, ch:u32 ) { +if !self.loopback_enabled () { + self.put_fifo (ch) + } + } +pub fn event (&mut self, event:QEMUChrEvent ) {if event ==QEMUChrEvent ::CHR_EVENT_BREAK && !self.loopback_enabled () { self.put_fifo (registers::Data ::BREAK .into ());
@@ -513,7 +519,7 @@ pub fn fifo_depth(&self) -> u32 {1 } -pub fn put_fifo (&mut self, value:c_uint ) { +pub fn put_fifo (&mut self, value:u32 ) {let depth = self.fifo_depth ();assert! (depth >0 );let slot = (self.read_pos + self.read_count) & (depth -1 );
@@ -622,12 +628,9 @@ pub fn write(&mut self, offset: hwaddr, value: u64) {pub unsafe extern "C" fn pl011_receive (opaque: *mut c_void , buf: *const u8 , size:c_int ) {let mut state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >();unsafe { -if state.as_ref ().loopback_enabled () { -return ; - }if size >0 {debug_assert! (!buf.is_null ()); - state.as_mut ().put_fifo (c_uint::from (buf.read_volatile ())) + state.as_mut ().receive (u32::from (buf.read_volatile ())); } } }
Signature · 1 line
2.48.1
[PULL 20/48] stub: Fix build failure with --enable-user --disable-system --enable-tools
In reply to Paolo BonziniFrom: Zhao Liu <[email protected]>
Configuring "--enable-user --disable-system --enable-tools" causes the build failure with the following information:
/usr/bin/ld: libhwcore.a.p/hw_core_qdev.c.o: in function `device_finalize':
/qemu/build/../hw/core/qdev.c:688: undefined reference to `qapi_event_send_device_deleted'
collect2: error: ld returned 1 exit status
To fix the above issue, add qdev.c stub when build with have_tools.
With this fix, QEMU could be successfully built in the following cases:
--enable-user --disable-system --enable-tools
--enable-user --disable-system --disable-tools --enable-user --disable-system
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2766
--- stubs/meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
stubs/meson.build +2 -2
@@ -57,8 +57,8 @@ if have_user stub_ss.add(files('cpu-synchronize-state.c')) # Stubs for QAPI events. Those can always be included in the build, but - # they are not built at all for --disable-system --disable-tools builds. - if not (have_system or have_tools) + # they are not built at all for --disable-system builds. + if not have_system stub_ss.add(files('qdev.c')) endif endif
Signature · 1 line
2.48.1
[PULL 46/48] rust: qdev: make reset take a shared reference
In reply to Paolo BonziniBecause register reset is within a borrow_mut() call, reset does not need anymore a mut reference to the PL011State.
--- rust/hw/char/pl011/src/device.rs | 4 ++-- rust/qemu-api/src/qdev.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
rust/hw/char/pl011/src/device.rs +2 -2
@@ -172,7 +172,7 @@ fn vmsd() -> Option<&'static VMStateDescription> {Some (&device_class::VMSTATE_PL011 ) }const REALIZE :Option <fn (&Self )> =Some (Self ::realize); -const RESET :Option <fn (&mut Self )> =Some (Self ::reset); +const RESET :Option <fn (&Self )> =Some (Self ::reset); }impl PL011Registers {
@@ -621,7 +621,7 @@ pub fn realize(&self) { } } -pub fn reset (&mut self) { +pub fn reset (&self) { self.regs.borrow_mut ().reset (); }
rust/qemu-api/src/qdev.rs +1 -1
@@ -30,7 +30,7 @@ pub trait DeviceImpl {/// /// Rust does not yet support the three-phase reset protocol; this is /// usually okay for leaf classes. -const RESET :Option <fn (&mut Self )> =None ; +const RESET :Option <fn (&Self )> =None ;/// An array providing the properties that the user can set on the /// device. Not a `const` because referencing statics in constants
Signature · 1 line
2.48.1
[PULL 41/48] rust: pl011: extract PL011Registers
In reply to Paolo BonziniPull all the mutable fields of PL011State into a separate struct.
--- rust/hw/char/pl011/src/device.rs | 251 ++++++++++++++----------- rust/hw/char/pl011/src/device_class.rs | 46 +++-- 2 files changed, 168 insertions(+), 129 deletions(-)
rust/hw/char/pl011/src/device.rs +140 -111
@@ -85,11 +85,8 @@ fn index(&self, idx: u32) -> &Self::Output { }#[repr( C )] -#[derive( Debug , qemu_api_macros:: Object , qemu_api_macros::offsets)] -/// PL011 Device Model in QEMU -pub struct PL011State { -pub parent_obj:ParentField <SysBusDevice >, -pub iomem:MemoryRegion , +#[derive( Debug , Default , qemu_api_macros::offsets)] +pub struct PL011Registers {#[doc(alias = "fr" )] pub flags: registers::Flags , #[doc(alias = "lcr")]
@@ -109,8 +106,17 @@ pub struct PL011State { pub read_pos: u32, pub read_count: u32, pub read_trigger: u32, +} + +#[repr( C )] +#[derive( Debug , qemu_api_macros:: Object , qemu_api_macros::offsets)] +/// PL011 Device Model in QEMU +pub struct PL011State { +pub parent_obj:ParentField <SysBusDevice >, +pub iomem:MemoryRegion ,#[doc(alias = "chr" )] pub char_backend:CharBackend , +pub regs:PL011Registers ,/// QEMU interrupts /// /// ```text
@@ -169,61 +175,8 @@ fn vmsd() -> Option<&'static VMStateDescription> {const RESET :Option <fn (&mut Self )> =Some (Self ::reset); } -impl PL011State { -/// Initializes a pre-allocated, unitialized instance of `PL011State`. -/// -/// # Safety -/// -/// `self` must point to a correctly sized and aligned location for the -/// `PL011State` type. It must not be called more than once on the same -/// location/instance. All its fields are expected to hold unitialized -/// values with the sole exception of `parent_obj`. -unsafe fn init (&mut self) { -const CLK_NAME : &CStr =c_str! ("clk" ); - -// SAFETY: -// -// self and self.iomem are guaranteed to be valid at this point since callers -// must make sure the `self` reference is valid. -unsafe { -memory_region_init_io ( -addr_of_mut! (self.iomem), -addr_of_mut! (*self).cast ::<Object >(), - &PL011_OPS , -addr_of_mut! (*self).cast ::<c_void >(), -Self ::TYPE_NAME .as_ptr (), -0x1000 , - ); - } - -// SAFETY: -// -// self.clock is not initialized at this point; but since `NonNull<_>` is Copy, -// we can overwrite the undefined value without side effects. This is -// safe since all PL011State instances are created by QOM code which -// calls this function to initialize the fields; therefore no code is -// able to access an invalid self.clock value. -unsafe { -let dev: &mut DeviceState = self.upcast_mut (); - self.clock =NonNull ::new (qdev_init_clock_in ( - dev, -CLK_NAME .as_ptr (), -None ,/* pl011_clock_update */ -addr_of_mut! (*self).cast ::<c_void >(), -ClockEvent ::ClockUpdate .0 , - )) - .unwrap (); - } - } - -fn post_init (&self) { - self.init_mmio (&self.iomem); -for irqin self.interrupts.iter () { - self.init_irq (irq); - } - } - -fn regs_read (&mut self, offset:RegisterOffset ) ->ControlFlow <u32 ,u32 > { +impl PL011Registers { +pub (self)fn read (&mut self, offset:RegisterOffset ) ->ControlFlow <u32 ,u32 > {use RegisterOffset ::*; ControlFlow::Break(match offset {
@@ -265,7 +218,12 @@ fn regs_read(&mut self, offset: RegisterOffset) -> ControlFlow<u32, u32> { }) } -fn regs_write (&mut self, offset:RegisterOffset , value:u32 ) ->bool { +pub (self)fn write ( + &mut self, + offset:RegisterOffset , + value:u32 , + char_backend: *mut CharBackend , + ) ->bool {// eprintln!("write offset {offset} value {value}"); use RegisterOffset ::*;match offset {
@@ -275,10 +233,10 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) -> bool {// 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 +// SAFETY: 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 ); +qemu_chr_fe_write_all (char_backend, &ch,1 ); }// interrupts always checked let _ = self.loopback_tx (value);
@@ -313,7 +271,7 @@ fn regs_write(&mut self, offset: RegisterOffset, value: u32) -> bool {// initialized in realize(). unsafe {qemu_chr_fe_ioctl ( -addr_of_mut! (self.char_backend), + char_backend,CHR_IOCTL_SERIAL_SET_BREAK as i32 ,addr_of_mut! (break_enable).cast ::<c_void >(), );
@@ -432,23 +390,6 @@ fn set_read_trigger(&mut self) { self.read_trigger =1 ; } -pub fn realize (&self) { -// SAFETY: self.char_backend has the correct size and alignment for a -// CharBackend object, and its callbacks are of the correct types. -unsafe { -qemu_chr_fe_set_handlers ( -addr_of! (self.char_backend)as *mut CharBackend , -Some (pl011_can_receive), -Some (pl011_receive), -Some (pl011_event), -None , -addr_of! (*self).cast ::<c_void >()as *mut c_void , - core::ptr::null_mut (), -true , - ); - } - } -pub fn reset (&mut self) { self.line_control.reset (); self.receive_status_error_clear.reset ();
@@ -481,26 +422,6 @@ pub fn reset_tx_fifo(&mut self) { self.flags.set_transmit_fifo_empty (true ); } -pub fn can_receive (&self) ->bool { -// trace_pl011_can_receive(s->lcr, s->read_count, r); - self.read_count < self.fifo_depth () - } - -pub fn receive (&mut self, ch:u32 ) { -if !self.loopback_enabled () && self.put_fifo (ch) { - self.update (); - } - } - -pub fn event (&mut self, event:QEMUChrEvent ) { -if event ==QEMUChrEvent ::CHR_EVENT_BREAK && !self.loopback_enabled () { -let update = self.put_fifo (registers::Data ::BREAK .into ()); -if update { - self.update (); - } - } - } -#[inline] pub fn fifo_enabled (&self) ->bool { self.line_control.fifos_enabled () == registers::Mode ::FIFO
@@ -539,14 +460,7 @@ pub fn put_fifo(&mut self, value: u32) -> bool {false } -pub fn update (&self) { -let flags = self.int_level & self.int_enabled; -for (irq, i)in self.interrupts.iter ().zip (IRQMASK ) { - irq.set (flags & i !=0 ); - } - } - -pub fn post_load (&mut self, _version_id:u32 ) ->Result <(), ()> { +pub fn post_load (&mut self) ->Result <(), ()> {/* Sanity-check input state */ if self.read_pos >= self.read_fifo.len () || self.read_count > self.read_fifo.len () {return Err (());
@@ -566,6 +480,63 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> {Ok (()) } +} + +impl PL011State { +/// Initializes a pre-allocated, unitialized instance of `PL011State`. +/// +/// # Safety +/// +/// `self` must point to a correctly sized and aligned location for the +/// `PL011State` type. It must not be called more than once on the same +/// location/instance. All its fields are expected to hold unitialized +/// values with the sole exception of `parent_obj`. +unsafe fn init (&mut self) { +const CLK_NAME : &CStr =c_str! ("clk" ); + +// SAFETY: +// +// self and self.iomem are guaranteed to be valid at this point since callers +// must make sure the `self` reference is valid. +unsafe { +memory_region_init_io ( +addr_of_mut! (self.iomem), +addr_of_mut! (*self).cast ::<Object >(), + &PL011_OPS , +addr_of_mut! (*self).cast ::<c_void >(), +Self ::TYPE_NAME .as_ptr (), +0x1000 , + ); + } + + self.regs =Default ::default (); + +// SAFETY: +// +// self.clock is not initialized at this point; but since `NonNull<_>` is Copy, +// we can overwrite the undefined value without side effects. This is +// safe since all PL011State instances are created by QOM code which +// calls this function to initialize the fields; therefore no code is +// able to access an invalid self.clock value. +unsafe { +let dev: &mut DeviceState = self.upcast_mut (); + self.clock =NonNull ::new (qdev_init_clock_in ( + dev, +CLK_NAME .as_ptr (), +None ,/* pl011_clock_update */ +addr_of_mut! (*self).cast ::<c_void >(), +ClockEvent ::ClockUpdate .0 , + )) + .unwrap (); + } + } + +fn post_init (&self) { + self.init_mmio (&self.iomem); +for irqin self.interrupts.iter () { + self.init_irq (irq); + } + }pub fn read (&mut self, offset:hwaddr , _size:u32 ) ->ControlFlow <u64 ,u64 > {let mut update_irq =false ;
@@ -578,7 +549,7 @@ pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow<u64, u64> {// qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); ControlFlow ::Break (0 ) } - Ok(field) => match self.regs_read(field) { + Ok(field) => match self.regs.read(field) {ControlFlow ::Break (value) =>ControlFlow ::Break (value.into ()),ControlFlow ::Continue (value) => { update_irq =true ;
@@ -595,7 +566,7 @@ pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow<u64, u64> {pub fn write (&mut self, offset:hwaddr , value:u64 ) {let mut update_irq =false ;if let Ok (field) =RegisterOffset ::try_from (offset) { - update_irq = self.regs_write (field, valueas u32 ); + update_irq = self.regs.write (field, valueas u32 , &mut self.char_backend); }else {eprintln! ("write bad offset {offset} value {value}" ); }
@@ -603,6 +574,64 @@ pub fn write(&mut self, offset: hwaddr, value: u64) { self.update (); } } + +pub fn can_receive (&self) ->bool { +// trace_pl011_can_receive(s->lcr, s->read_count, r); +let regs = &self.regs; + regs.read_count < regs.fifo_depth () + } + +pub fn receive (&mut self, ch:u32 ) { +let regs = &mut self.regs; +let update_irq = !regs.loopback_enabled () && regs.put_fifo (ch); +if update_irq { + self.update (); + } + } + +pub fn event (&mut self, event:QEMUChrEvent ) { +let mut update_irq =false ; +let regs = &mut self.regs; +if event ==QEMUChrEvent ::CHR_EVENT_BREAK && !regs.loopback_enabled () { + update_irq = regs.put_fifo (registers::Data ::BREAK .into ()); + } +if update_irq { + self.update () + } + } + +pub fn realize (&self) { +// SAFETY: self.char_backend has the correct size and alignment for a +// CharBackend object, and its callbacks are of the correct types. +unsafe { +qemu_chr_fe_set_handlers ( +addr_of! (self.char_backend)as *mut CharBackend , +Some (pl011_can_receive), +Some (pl011_receive), +Some (pl011_event), +None , +addr_of! (*self).cast ::<c_void >()as *mut c_void , + core::ptr::null_mut (), +true , + ); + } + } + +pub fn reset (&mut self) { + self.regs.reset (); + } + +pub fn update (&self) { +let regs = &self.regs; +let flags = regs.int_level & regs.int_enabled; +for (irq, i)in self.interrupts.iter ().zip (IRQMASK ) { + irq.set (flags & i !=0 ); + } + } + +pub fn post_load (&mut self, _version_id:u32 ) ->Result <(), ()> { + self.regs.post_load () + } }/// Which bits in the interrupt status matter for each outbound IRQ line ?
rust/hw/char/pl011/src/device_class.rs +28 -18
66 lines not on this page · raw message
Signature · 1 line
2.48.1
[PULL 25/48] rust: vmstate: add new type safe implementation
In reply to Paolo BonziniThe existing translation of the C macros for vmstate does not make any attempt to type-check vmstate declarations against the struct, so introduce a new system that computes VMStateField based on the actual struct declaration.
Macros do not have full access to the type system, therefore a full implementation of this scheme requires a helper trait to analyze the type and produce a VMStateField from it; a macro "vmstate_of!" accepts arguments similar to "offset_of!" and tricks the compiler into looking up the trait for the right type.
The patch introduces not just vmstate_of!, but also the slightly too clever enabling macro call_func_with_field!. The particular trick used here was proposed on the users.rust-lang.org forum, so I take no merit and all the blame.
Introduce the trait and some functions to access it; the actual implementation comes later.
--- rust/qemu-api/src/prelude.rs | 2 + rust/qemu-api/src/vmstate.rs | 113 +++++++++++++++++++++++++++++++++-- 2 files changed, 109 insertions(+), 6 deletions(-)
rust/qemu-api/src/prelude.rs +2 -0
@@ -18,3 +18,5 @@pub use crate ::qom_isa;pub use crate ::sysbus::SysBusDeviceMethods ; + +pub use crate ::vmstate::VMState ;
rust/qemu-api/src/vmstate.rs +107 -6
120 lines not on this page · raw message
Signature · 1 line
2.48.1
[PULL 34/48] rust: vmstate: make order of parameters consistent in vmstate_clock
In reply to Paolo BonziniPlace struct_name before field_name, similar to offset_of.
--- rust/hw/char/pl011/src/device_class.rs | 2 +- rust/qemu-api/src/vmstate.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
rust/hw/char/pl011/src/device_class.rs +1 -1
@@ -27,7 +27,7 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { minimum_version_id: 1, needed: Some(pl011_clock_needed), fields: vmstate_fields! { -vmstate_clock! (clock,PL011State ), +vmstate_clock! (PL011State , clock), }, ..Zeroable ::ZERO };
rust/qemu-api/src/vmstate.rs +1 -1
@@ -457,7 +457,7 @@ macro_rules! vmstate_struct {#[doc(alias = "VMSTATE_CLOCK" )] #[macro_export] macro_rules! vmstate_clock { - ($field_name:ident, $struct_name:ty) => {{ + ($struct_name:ty, $field_name:ident) => {{ $crate::bindings::VMStateField { name: ::core::concat!(::core::stringify!($field_name),"\0" ) .as_bytes ()
Signature · 1 line
2.48.1
[PULL 33/48] rust: vmstate: remove translation of C vmstate macros
In reply to Paolo BonziniKeep vmstate_clock!; because it uses a field of type VMStateDescription, it cannot be converted to the VMState trait without access to the const_refs_static feature.
--- rust/qemu-api/src/vmstate.rs | 274 +++-------------------------------- 1 file changed, 23 insertions(+), 251 deletions(-)
rust/qemu-api/src/vmstate.rs +23 -251
@@ -21,8 +21,8 @@//! [`vmstate_fields`](crate::vmstate_fields). //! //! * direct equivalents to the C macros declared in -//! `include/migration/vmstate.h`. These are not type-safe and should not be -//! used if the equivalent functionality is available with `vmstate_of!`. +//! `include/migration/vmstate.h`. These are not type-safe and only provide +//! functionality that is missing from `vmstate_of!`. use core::{marker::PhantomData , mem, ptr::NonNull };
@@ -407,223 +407,16 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* {const BASE :VMStateField = <T as VMState >::BASE .with_array_flag (N ); } -#[doc(alias = "VMSTATE_UNUSED_BUFFER" )] -#[macro_export] -macro_rules! vmstate_unused_buffer { - ($field_exists_fn:expr, $version_id:expr, $size:expr) => {{ - $crate::bindings::VMStateField { - name:c_str! ("unused" ).as_ptr (), - err_hint: ::core::ptr::null (), - offset:0 , - size: $size, - start:0 , - num:0 , - num_offset:0 , - size_offset:0 , - info:unsafe { ::core::ptr::addr_of!($crate ::bindings::vmstate_info_unused_buffer) }, - flags:VMStateFlags ::VMS_BUFFER , - vmsd: ::core::ptr::null (), - version_id: $version_id, - struct_version_id:0 , - field_exists: $field_exists_fn, - } - }}; -} - -#[doc(alias = "VMSTATE_UNUSED_V" )] -#[macro_export] -macro_rules! vmstate_unused_v { - ($version_id:expr, $size:expr) => {{ - $crate::vmstate_unused_buffer!(None , $version_id, $size) - }}; -} -#[doc(alias = "VMSTATE_UNUSED" )] #[macro_export] macro_rules! vmstate_unused { ($size:expr) => {{ - $crate::vmstate_unused_v!(0 , $size) - }}; -} - -#[doc(alias = "VMSTATE_SINGLE_TEST" )] -#[macro_export] -macro_rules! vmstate_single_test { - ($field_name:ident, $struct_name:ty, $field_exists_fn:expr, $version_id:expr, $info:expr, $size:expr) => {{ $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name),0 ) - .as_bytes () - .as_ptr ()as *const ::std::os::raw::c_char , - err_hint: ::core::ptr::null (), - offset: $crate::offset_of!($struct_name, $field_name), + name: $crate::c_str!("unused" ).as_ptr (), size: $size, - start:0 , - num:0 , - num_offset:0 , - size_offset:0 , - info:unsafe { $info }, - flags:VMStateFlags ::VMS_SINGLE , - vmsd: ::core::ptr::null (), - version_id: $version_id, - struct_version_id:0 , - field_exists: $field_exists_fn, - } - }}; -} - -#[doc(alias = "VMSTATE_SINGLE" )] -#[macro_export] -macro_rules! vmstate_single { - ($field_name:ident, $struct_name:ty, $version_id:expr, $info:expr, $size:expr) => {{ - $crate::vmstate_single_test!($field_name, $struct_name,None , $version_id, $info, $size) - }}; -} - -#[doc(alias = "VMSTATE_UINT32_V" )] -#[macro_export] -macro_rules! vmstate_uint32_v { - ($field_name:ident, $struct_name:ty, $version_id:expr) => {{ - $crate::vmstate_single!( - $field_name, - $struct_name, - $version_id, - ::core::ptr::addr_of!($crate ::bindings::vmstate_info_uint32), - ::core::mem::size_of ::<u32 >() - ) - }}; -} - -#[doc(alias = "VMSTATE_UINT32" )] -#[macro_export] -macro_rules! vmstate_uint32 { - ($field_name:ident, $struct_name:ty) => {{ - $crate::vmstate_uint32_v!($field_name, $struct_name,0 ) - }}; -} - -#[doc(alias = "VMSTATE_ARRAY" )] -#[macro_export] -macro_rules! vmstate_array { - ($field_name:ident, $struct_name:ty, $length:expr, $version_id:expr, $info:expr, $size:expr) => {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name),0 ) - .as_bytes () - .as_ptr ()as *const ::std::os::raw::c_char , - err_hint: ::core::ptr::null (), - offset: $crate::offset_of!($struct_name, $field_name), - size: $size, - start:0 , - num: $lengthas _ , - num_offset:0 , - size_offset:0 , - info:unsafe { $info }, - flags:VMStateFlags ::VMS_ARRAY , - vmsd: ::core::ptr::null (), - version_id: $version_id, - struct_version_id:0 , - field_exists:None , - } - }}; -} - -#[doc(alias = "VMSTATE_UINT32_ARRAY_V" )] -#[macro_export] -macro_rules! vmstate_uint32_array_v { - ($field_name:ident, $struct_name:ty, $length:expr, $version_id:expr) => {{ - $crate::vmstate_array!( - $field_name, - $struct_name, - $length, - $version_id, - ::core::ptr::addr_of!($crate ::bindings::vmstate_info_uint32), - ::core::mem::size_of ::<u32 >() - ) - }}; -} - -#[doc(alias = "VMSTATE_UINT32_ARRAY" )] -#[macro_export] -macro_rules! vmstate_uint32_array { - ($field_name:ident, $struct_name:ty, $length:expr) => {{ - $crate::vmstate_uint32_array_v!($field_name, $struct_name, $length,0 ) - }}; -} - -#[doc(alias = "VMSTATE_STRUCT_POINTER_V" )] -#[macro_export] -macro_rules! vmstate_struct_pointer_v { - ($field_name:ident, $struct_name:ty, $version_id:expr, $vmsd:expr, $type:ty) => {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name),0 ) - .as_bytes () - .as_ptr ()as *const ::std::os::raw::c_char , - err_hint: ::core::ptr::null (), - offset: $crate::offset_of!($struct_name, $field_name), - size: ::core::mem::size_of ::<*const $type>(), - start:0 , - num:0 , - num_offset:0 , - size_offset:0 , - info: ::core::ptr::null (), - flags:VMStateFlags (VMStateFlags ::VMS_STRUCT .0 |VMStateFlags ::VMS_POINTER .0 ), - vmsd:unsafe { $vmsd }, - version_id: $version_id, - struct_version_id:0 , - field_exists:None , - } - }}; -} - -#[doc(alias = "VMSTATE_ARRAY_OF_POINTER" )] -#[macro_export] -macro_rules! vmstate_array_of_pointer { - ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr, $info:expr, $type:ty) => {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name),0 ) - .as_bytes () - .as_ptr ()as *const ::std::os::raw::c_char , - version_id: $version_id, - num: $numas _ , - info:unsafe { $info }, - size: ::core::mem::size_of ::<*const $type>(), - flags:VMStateFlags (VMStateFlags ::VMS_ARRAY .0 |VMStateFlags ::VMS_ARRAY_OF_POINTER .0 ), - offset: $crate::offset_of!($struct_name, $field_name), - err_hint: ::core::ptr::null (), - start:0 , - num_offset:0 , - size_offset:0 , - vmsd: ::core::ptr::null (), - struct_version_id:0 , - field_exists:None , - } - }}; -} - -#[doc(alias = "VMSTATE_ARRAY_OF_POINTER_TO_STRUCT" )] -#[macro_export] -macro_rules! vmstate_array_of_pointer_to_struct { - ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr, $vmsd:expr, $type:ty) => {{ - $crate::bindings::VMStateField { - name: ::core::concat!(::core::stringify!($field_name),0 ) - .as_bytes () - .as_ptr ()as *const ::std::os::raw::c_char , - version_id: $version_id, - num: $numas _ , - vmsd:unsafe { $vmsd }, - size: ::core::mem::size_of ::<*const $type>(), - flags:VMStateFlags ( -VMStateFlags ::VMS_ARRAY .0 - |VMStateFlags ::VMS_STRUCT .0 - |VMStateFlags ::VMS_ARRAY_OF_POINTER .0 , - ), - offset: $crate::offset_of!($struct_name, $field_name), - err_hint: ::core::ptr::null (), - start:0 , - num_offset:0 , - size_offset:0 , - vmsd: ::core::ptr::null (), - struct_version_id:0 , - field_exists:None , + info:unsafe { ::core::ptr::addr_of!($crate ::bindings::vmstate_info_unused_buffer) }, + flags: $crate::bindings::VMStateFlags ::VMS_BUFFER , + ..$crate::zeroable::Zeroable ::ZERO } }}; }
@@ -661,48 +454,27 @@ macro_rules! vmstate_struct { }; } -#[doc(alias = "VMSTATE_CLOCK_V" )] -#[macro_export] -macro_rules! vmstate_clock_v { - ($field_name:ident, $struct_name:ty, $version_id:expr) => {{ - $crate::vmstate_struct_pointer_v!( - $field_name, - $struct_name, - $version_id, - ::core::ptr::addr_of!($crate ::bindings::vmstate_clock), - $crate ::bindings::Clock - ) - }}; -} -#[doc(alias = "VMSTATE_CLOCK" )] #[macro_export] macro_rules! vmstate_clock { ($field_name:ident, $struct_name:ty) => {{ - $crate::vmstate_clock_v!($field_name, $struct_name,0 ) - }}; -} - -#[doc(alias = "VMSTATE_ARRAY_CLOCK_V" )] -#[macro_export] -macro_rules! vmstate_array_clock_v { - ($field_name:ident, $struct_name:ty, $num:expr, $version_id:expr) => {{ - $crate::vmstate_array_of_pointer_to_struct!( - $field_name, - $struct_name, - $num, - $version_id, - ::core::ptr::addr_of!($crate ::bindings::vmstate_clock), - $crate ::bindings::Clock - ) - }}; -} - -#[doc(alias = "VMSTATE_ARRAY_CLOCK" )] -#[macro_export] -macro_rules! vmstate_array_clock { - ($field_name:ident, $struct_name:ty, $num:expr) => {{ - $crate::vmstate_array_clock_v!($field_name, $struct_name, $name,0 ) + $crate::bindings::VMStateField { + name: ::core::concat!(::core::stringify!($field_name),"\0" ) + .as_bytes () + .as_ptr ()as *const ::std::os::raw::c_char , + offset: { + $crate::assert_field_type!( + $struct_name, + $field_name, + core::ptr::NonNull <$crate ::bindings::Clock > + ); + $crate::offset_of!($struct_name, $field_name) + }, + size: ::core::mem::size_of ::<*const $crate::bindings::Clock >(), + flags:VMStateFlags (VMStateFlags ::VMS_STRUCT .0 |VMStateFlags ::VMS_POINTER .0 ), + vmsd:unsafe { ::core::ptr::addr_of!($crate ::bindings::vmstate_clock) }, + ..$crate::zeroable::Zeroable ::ZERO + } }}; }
Signature · 1 line
2.48.1
[PULL 17/48] target/i386: Export BHI_NO bit to guests
In reply to Paolo BonziniFrom: Tao Su <[email protected]>
Branch History Injection (BHI) is a CPU side-channel vulnerability, where an attacker may manipulate branch history before transitioning from user to supervisor mode or from VMX non-root/guest to root mode. CPUs that set BHI_NO bit in MSR IA32_ARCH_CAPABILITIES to indicate no additional mitigation is required to prevent BHI.
Make BHI_NO bit available to guests.
--- target/i386/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/cpu.c +1 -1
@@ -1364,7 +1364,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {"taa-no" ,NULL ,NULL ,NULL ,NULL ,"sbdr-ssdp-no" ,"fbsdp-no" ,"psdp-no" ,NULL ,"fb-clear" ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , +"bhi-no" ,NULL ,NULL ,NULL ,"pbrsb-no" ,NULL ,"gds-no" ,"rfds-no" , "rfds-clear", NULL, NULL, NULL, },
Signature · 1 line
2.48.1
[PULL 42/48] rust: pl011: wrap registers with BqlRefCell
In reply to Paolo BonziniThis is a step towards making memory ops use a shared reference to the device type; it's not yet possible due to the calls to character device functions.
--- rust/hw/char/pl011/src/device.rs | 40 ++++++++++++++------------ rust/hw/char/pl011/src/device_class.rs | 8 +++--- 2 files changed, 26 insertions(+), 22 deletions(-)
rust/hw/char/pl011/src/device.rs +22 -18
@@ -109,14 +109,14 @@ pub struct PL011Registers { }#[repr( C )] -#[derive( Debug , qemu_api_macros:: Object , qemu_api_macros::offsets)] +#[derive(qemu_api_macros:: Object , qemu_api_macros::offsets)] /// PL011 Device Model in QEMU pub struct PL011State {pub parent_obj:ParentField <SysBusDevice >,pub iomem:MemoryRegion ,#[doc(alias = "chr" )] pub char_backend:CharBackend , -pub regs:PL011Registers , +pub regs:BqlRefCell <PL011Registers >,/// QEMU interrupts /// /// ```text
@@ -538,6 +538,7 @@ fn post_init(&self) { } } +#[allow(clippy::needless_pass_by_ref_mut)] pub fn read (&mut self, offset:hwaddr , _size:u32 ) ->ControlFlow <u64 ,u64 > {let mut update_irq =false ;let result =match RegisterOffset ::try_from (offset) {
@@ -549,7 +550,7 @@ pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow<u64, u64> {// qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); ControlFlow ::Break (0 ) } - Ok(field) => match self.regs.read(field) { + Ok(field) => match self.regs.borrow_mut().read(field) {ControlFlow ::Break (value) =>ControlFlow ::Break (value.into ()),ControlFlow ::Continue (value) => { update_irq =true ;
@@ -566,7 +567,10 @@ pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow<u64, u64> {pub fn write (&mut self, offset:hwaddr , value:u64 ) {let mut update_irq =false ;if let Ok (field) =RegisterOffset ::try_from (offset) { - update_irq = self.regs.write (field, valueas u32 , &mut self.char_backend); + update_irq = self + .regs + .borrow_mut () + .write (field, valueas u32 , &mut self.char_backend); }else {eprintln! ("write bad offset {offset} value {value}" ); }
@@ -577,21 +581,21 @@ pub fn write(&mut self, offset: hwaddr, value: u64) {pub fn can_receive (&self) ->bool {// trace_pl011_can_receive(s->lcr, s->read_count, r); -let regs = &self.regs; +let regs = self.regs.borrow (); regs.read_count < regs.fifo_depth () } -pub fn receive (&mut self, ch:u32 ) { -let regs = &mut self.regs; +pub fn receive (&self, ch:u32 ) { +let mut regs = self.regs.borrow_mut ();let update_irq = !regs.loopback_enabled () && regs.put_fifo (ch);if update_irq { self.update (); } } -pub fn event (&mut self, event:QEMUChrEvent ) { +pub fn event (&self, event:QEMUChrEvent ) {let mut update_irq =false ; -let regs = &mut self.regs; +let mut regs = self.regs.borrow_mut ();if event ==QEMUChrEvent ::CHR_EVENT_BREAK && !regs.loopback_enabled () { update_irq = regs.put_fifo (registers::Data ::BREAK .into ()); }
@@ -618,19 +622,19 @@ pub fn realize(&self) { }pub fn reset (&mut self) { - self.regs.reset (); + self.regs.borrow_mut ().reset (); }pub fn update (&self) { -let regs = &self.regs; +let regs = self.regs.borrow ();let flags = regs.int_level & regs.int_enabled;for (irq, i)in self.interrupts.iter ().zip (IRQMASK ) { irq.set (flags & i !=0 ); } } -pub fn post_load (&mut self, _version_id:u32 ) ->Result <(), ()> { - self.regs.post_load () +pub fn post_load (&self, _version_id:u32 ) ->Result <(), ()> { + self.regs.borrow_mut ().post_load () } }
@@ -667,11 +671,11 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> {/// /// The buffer and size arguments must also be valid. pub unsafe extern "C" fn pl011_receive (opaque: *mut c_void , buf: *const u8 , size:c_int ) { -let mut state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); +let state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >();unsafe {if size >0 {debug_assert! (!buf.is_null ()); - state.as_mut ().receive (u32::from (buf.read_volatile ())); + state.as_ref ().receive (u32::from (buf.read_volatile ())); } } }
@@ -682,8 +686,8 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> {/// the same size as [`PL011State`]. We also expect the device is /// readable/writeable from one thread at any time. pub unsafe extern "C" fn pl011_event (opaque: *mut c_void , event:QEMUChrEvent ) { -let mut state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); -unsafe { state.as_mut ().event (event) } +let state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); +unsafe { state.as_ref ().event (event) } }/// # Safety
@@ -708,7 +712,7 @@ pub fn post_load(&mut self, _version_id: u32) -> Result<(), ()> { }#[repr( C )] -#[derive( Debug , qemu_api_macros:: Object )] +#[derive(qemu_api_macros:: Object )] /// PL011 Luminary device model. pub struct PL011Luminary { parent_obj:ParentField <PL011State >,
rust/hw/char/pl011/src/device_class.rs +4 -4
@@ -6,7 +6,7 @@use std::os::raw::{c_int, c_void};use qemu_api::{ - bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_of, vmstate_struct, + bindings::*, c_str, prelude::*, vmstate_clock, vmstate_fields, vmstate_of, vmstate_struct, vmstate_subsections, vmstate_unused, zeroable::Zeroable , };
@@ -31,8 +31,8 @@ extern "C" fn pl011_clock_needed(opaque: *mut c_void) -> bool { };extern "C" fn pl011_post_load (opaque: *mut c_void , version_id:c_int ) ->c_int { -let mut state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); -let result =unsafe { state.as_mut ().post_load (version_idas u32 ) }; +let state =NonNull ::new (opaque).unwrap ().cast ::<PL011State >(); +let result =unsafe { state.as_ref ().post_load (version_idas u32 ) };if result.is_err () { -1 }else {
@@ -71,7 +71,7 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int { post_load: Some(pl011_post_load), fields: vmstate_fields! {vmstate_unused! (core::mem::size_of ::<u32 >()), -vmstate_struct! (PL011State , regs, &VMSTATE_PL011_REGS ,PL011Registers ), +vmstate_struct! (PL011State , regs, &VMSTATE_PL011_REGS ,BqlRefCell <PL011Registers >), }, subsections:vmstate_subsections! {VMSTATE_PL011_CLOCK
Signature · 1 line
2.48.1
[PULL 27/48] rust: vmstate: add varray support to vmstate_of!
In reply to Paolo Bonzini--- rust/qemu-api/src/vmstate.rs | 42 ++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-)
rust/qemu-api/src/vmstate.rs +40 -2
@@ -72,6 +72,15 @@ pub unsafe trait VMState {/// The base contents of a `VMStateField` (minus the name and offset) for /// the type that is implementing the trait. const BASE :VMStateField ; + +/// A flag that is added to another field's `VMStateField` to specify the +/// length's type in a variable-sized array. If this is not a supported +/// type for the length (i.e. if it is not `u8`, `u16`, `u32`), using it +/// in a call to [`vmstate_of!`](crate::vmstate_of) will cause a +/// compile-time error. +const VARRAY_FLAG :VMStateFlags = { +panic! ("invalid type for variable-sized array" ); + }; }/// Internal utility function to retrieve a type's `VMStateField`;
@@ -80,6 +89,13 @@ pub const fn vmstate_base<T: VMState>(_: PhantomData<T>) -> VMStateField {T ::BASE } +/// Internal utility function to retrieve a type's `VMStateFlags` when it +/// is used as the element count of a `VMSTATE_VARRAY`; used by +/// [`vmstate_of!`](crate::vmstate_of). +pub const fn vmstate_varray_flag <T :VMState >(_:PhantomData <T >) ->VMStateFlags { +T ::VARRAY_FLAG +} +/// Return the `VMStateField` for a field of a struct. The field must be /// visible in the current scope. ///
@@ -87,18 +103,23 @@ pub const fn vmstate_base<T: VMState>(_: PhantomData<T>) -> VMStateField {/// for them. #[macro_export] macro_rules! vmstate_of { - ($struct_name:ty, $field_name:ident $(,)?) => { + ($struct_name:ty, $field_name:ident $([0 .. $num:ident $(* $factor:expr)?])? $(,)?) => { $crate::bindings::VMStateField { name: ::core::concat!(::core::stringify!($field_name),"\0" ) .as_bytes () .as_ptr ()as *const ::std::os::raw::c_char , offset: $crate::offset_of!($struct_name, $field_name),// Compute most of the VMStateField from the type of the field. + $(.num_offset: $crate::offset_of!($struct_name, $num),)? ..$crate::call_func_with_field!( $crate ::vmstate::vmstate_base, $struct_name, $field_name - ) + )$(.with_varray_flag ($crate ::call_func_with_field!( + $crate ::vmstate::vmstate_varray_flag, + $struct_name, + $num)) + $(.with_varray_multiply ($factor))?)? } }; }
@@ -143,6 +164,22 @@ pub const fn with_pointer_flag(mut self) -> Self { self.flags =VMStateFlags (self.flags.0 |VMStateFlags ::VMS_POINTER .0 ); self } + +#[must_use] +pub const fn with_varray_flag <T :VMState >(mut self, flag:VMStateFlags ) ->VMStateField { +assert! ((self.flags.0 &VMStateFlags ::VMS_ARRAY .0 ) !=0 ); + self.flags =VMStateFlags (self.flags.0 & !VMStateFlags ::VMS_ARRAY .0 ); + self.flags =VMStateFlags (self.flags.0 | flag.0 ); + self + } + +#[must_use] +pub const fn with_varray_multiply (mut self, num:u32 ) ->VMStateField { +assert! (num <=0x7FFF_FFFFu32 ); + self.flags =VMStateFlags (self.flags.0 |VMStateFlags ::VMS_MULTIPLY_ELEMENTS .0 ); + self.num = numas i32 ; + self + } }// Transparent wrappers: just use the internal type
@@ -154,6 +191,7 @@ unsafe impl<$base> VMState for $type where $base: VMState $($where)* { size: mem::size_of::<$type>(), ..<$baseas VMState >::BASE }; +const VARRAY_FLAG :VMStateFlags = <$baseas VMState >::VARRAY_FLAG ; } }; }
Signature · 1 line
2.48.1
[PULL 28/48] rust: vmstate: implement Zeroable for VMStateField
In reply to Paolo BonziniThis shortens a bit the constants. Do not bother using it in the vmstate macros since most of them will go away soon.
--- rust/qemu-api/src/vmstate.rs | 18 +++--------------- rust/qemu-api/src/zeroable.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 15 deletions(-)
rust/qemu-api/src/vmstate.rs +3 -15
@@ -21,8 +21,8 @@use core::{marker::PhantomData , mem, ptr::NonNull }; -use crate ::bindings::VMStateFlags ;pub use crate ::bindings::{VMStateDescription ,VMStateField }; +use crate ::bindings::VMStateFlags ;/// This macro is used to call a function with a generic argument bound /// to the type of a field. The function must take a
@@ -503,20 +503,8 @@ macro_rules! vmstate_fields {static _FIELDS: &[$crate::bindings::VMStateField ] = &[ $($field),*, $crate::bindings::VMStateField { - name: ::core::ptr::null (), - err_hint: ::core::ptr::null (), - offset:0 , - size:0 , - start:0 , - num:0 , - num_offset:0 , - size_offset:0 , - info: ::core::ptr::null (), - flags:VMStateFlags ::VMS_END , - vmsd: ::core::ptr::null (), - version_id:0 , - struct_version_id:0 , - field_exists:None , + flags: $crate::bindings::VMStateFlags ::VMS_END , + ..$crate::zeroable::Zeroable ::ZERO } ]; _FIELDS.as_ptr ()
rust/qemu-api/src/zeroable.rs +31 -0
@@ -49,6 +49,37 @@ unsafe impl Zeroable for crate::bindings::Property { }; } +// bindgen does not derive Default here +#[allow(clippy::derivable_impls)] +impl Default for crate ::bindings::VMStateFlags { +fn default () ->Self { +Self (0 ) + } +} + +unsafe impl Zeroable for crate ::bindings::VMStateFlags { +const ZERO :Self =Self (0 ); +} + +unsafe impl Zeroable for crate ::bindings::VMStateField { +const ZERO :Self =Self { + name: ptr::null (), + err_hint: ptr::null (), + offset:0 , + size:0 , + start:0 , + num:0 , + num_offset:0 , + size_offset:0 , + info: ptr::null (), + flags:Zeroable ::ZERO , + vmsd: ptr::null (), + version_id:0 , + struct_version_id:0 , + field_exists:None , + }; +} +unsafe impl Zeroable for crate ::bindings::VMStateDescription {const ZERO :Self =Self { name: ptr::null (),
Signature · 1 line
2.48.1
[PULL 32/48] rust: pl011: switch vmstate to new-style macros
In reply to Paolo Bonzini--- rust/hw/char/pl011/src/device.rs | 3 ++- rust/hw/char/pl011/src/device_class.rs | 36 +++++++++++++------------- rust/hw/char/pl011/src/lib.rs | 6 +++++ 3 files changed, 26 insertions(+), 19 deletions(-)
rust/hw/char/pl011/src/device.rs +2 -1
@@ -15,7 +15,7 @@ qemu_irq, sysbus_connect_irq, sysbus_mmio_map, sysbus_realize_and_unref, CharBackend, Chardev, Clock, ClockEvent, MemoryRegion, QEMUChrEvent, CHR_IOCTL_SERIAL_SET_BREAK, }, - c_str, + c_str, impl_vmstate_forward, irq::InterruptSource, prelude::*, qdev::{DeviceImpl, DeviceState, Property},
@@ -61,6 +61,7 @@ impl DeviceId {#[repr(transparent)] #[derive( Debug , Default )] pub struct Fifo ([registers::Data ;PL011_FIFO_DEPTH as usize ]); +impl_vmstate_forward! (Fifo );impl Fifo {const fn len (&self) ->u32 {
rust/hw/char/pl011/src/device_class.rs +18 -18
@@ -6,11 +6,11 @@use std::os::raw::{c_int, c_void};use qemu_api::{ - bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_subsections, vmstate_uint32, - vmstate_uint32_array, vmstate_unused, zeroable::Zeroable , + bindings::*, c_str, vmstate_clock, vmstate_fields, vmstate_of, vmstate_subsections, + vmstate_unused, zeroable::Zeroable , }; -use crate ::device::{PL011State ,PL011_FIFO_DEPTH }; +use crate ::device::PL011State ;extern "C" fn pl011_clock_needed (opaque: *mut c_void ) ->bool {unsafe {
@@ -52,21 +52,21 @@ extern "C" fn pl011_post_load(opaque: *mut c_void, version_id: c_int) -> c_int { post_load: Some(pl011_post_load), fields: vmstate_fields! {vmstate_unused! (core::mem::size_of ::<u32 >()), -vmstate_uint32! (flags,PL011State ), -vmstate_uint32! (line_control,PL011State ), -vmstate_uint32! (receive_status_error_clear,PL011State ), -vmstate_uint32! (control,PL011State ), -vmstate_uint32! (dmacr,PL011State ), -vmstate_uint32! (int_enabled,PL011State ), -vmstate_uint32! (int_level,PL011State ), -vmstate_uint32_array! (read_fifo,PL011State ,PL011_FIFO_DEPTH ), -vmstate_uint32! (ilpr,PL011State ), -vmstate_uint32! (ibrd,PL011State ), -vmstate_uint32! (fbrd,PL011State ), -vmstate_uint32! (ifl,PL011State ), -vmstate_uint32! (read_pos,PL011State ), -vmstate_uint32! (read_count,PL011State ), -vmstate_uint32! (read_trigger,PL011State ), +vmstate_of! (PL011State , flags), +vmstate_of! (PL011State , line_control), +vmstate_of! (PL011State , receive_status_error_clear), +vmstate_of! (PL011State , control), +vmstate_of! (PL011State , dmacr), +vmstate_of! (PL011State , int_enabled), +vmstate_of! (PL011State , int_level), +vmstate_of! (PL011State , read_fifo), +vmstate_of! (PL011State , ilpr), +vmstate_of! (PL011State , ibrd), +vmstate_of! (PL011State , fbrd), +vmstate_of! (PL011State , ifl), +vmstate_of! (PL011State , read_pos), +vmstate_of! (PL011State , read_count), +vmstate_of! (PL011State , read_trigger), }, subsections:vmstate_subsections! {VMSTATE_PL011_CLOCK
rust/hw/char/pl011/src/lib.rs +6 -0
@@ -106,6 +106,7 @@ pub mod registers {//! Device registers exposed as typed structs which are backed by arbitrary //! integer bitmaps. [`Data`], [`Control`], [`LineControl`], etc. use bilge::prelude::*; +use qemu_api::impl_vmstate_bitsized;/// Receive Status Register / Data Register common error bits ///
@@ -172,6 +173,7 @@ pub struct Data { pub errors: Errors, _reserved: u16, } +impl_vmstate_bitsized! (Data );impl Data {// bilge is not very const-friendly, unfortunately
@@ -208,6 +210,7 @@ pub struct ReceiveStatusErrorClear { pub errors: Errors, _reserved_unpredictable: u24, } +impl_vmstate_bitsized! (ReceiveStatusErrorClear );impl ReceiveStatusErrorClear {pub fn set_from_data (&mut self, data:Data ) {
@@ -280,6 +283,7 @@ pub struct Flags { pub ring_indicator: bool, _reserved_zero_no_modify: u23, } +impl_vmstate_bitsized! (Flags );impl Flags {pub fn reset (&mut self) {
@@ -354,6 +358,7 @@ pub struct LineControl {/// 31:8 - Reserved, do not modify, read as zero. _reserved_zero_no_modify: u24, } +impl_vmstate_bitsized! (LineControl );impl LineControl {pub fn reset (&mut self) {
@@ -498,6 +503,7 @@ pub struct Control {/// 31:16 - Reserved, do not modify, read as zero. _reserved_zero_no_modify2: u16, } +impl_vmstate_bitsized! (Control );impl Control {pub fn reset (&mut self) {
Signature · 1 line
2.48.1
[PULL 21/48] rust/qdev: Make REALIZE safe
In reply to Paolo BonziniFrom: Zhao Liu <[email protected]>
A safe REALIZE accepts immutable reference.
Since current PL011's realize() only calls a char binding function ( qemu_chr_fe_set_handlers), it is possible to convert mutable reference (&mut self) to immutable reference (&self), which only needs to convert the pointers passed to C to mutable pointers.
Thus, make REALIZE accept immutable reference.
--- rust/hw/char/pl011/src/device.rs | 10 +++++----- rust/qemu-api/src/qdev.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-)
rust/hw/char/pl011/src/device.rs +5 -5
@@ -2,7 +2,7 @@// Author(s): Manos Pitsidianakis <[email protected]> // SPDX-License-Identifier: GPL-2.0-or-later -use core::ptr::{addr_of_mut,NonNull }; +use core::ptr::{addr_of, addr_of_mut,NonNull };use std::{ ffi::CStr , os::raw::{c_int, c_uint, c_void},
@@ -156,7 +156,7 @@ fn properties() -> &'static [Property] {fn vmsd () ->Option <&'staticVMStateDescription > {Some (&device_class::VMSTATE_PL011 ) } -const REALIZE :Option <fn (&mut Self )> =Some (Self ::realize); +const REALIZE :Option <fn (&Self )> =Some (Self ::realize);const RESET :Option <fn (&mut Self )> =Some (Self ::reset); }
@@ -439,17 +439,17 @@ fn set_read_trigger(&mut self) { self.read_trigger =1 ; } -pub fn realize (&mut self) { +pub fn realize (&self) {// SAFETY: self.char_backend has the correct size and alignment for a // CharBackend object, and its callbacks are of the correct types. unsafe {qemu_chr_fe_set_handlers ( -addr_of_mut! (self.char_backend), +addr_of! (self.char_backend)as *mut CharBackend ,Some (pl011_can_receive),Some (pl011_receive),Some (pl011_event),None , -addr_of_mut! (*self).cast ::<c_void >(), +addr_of! (*self).cast ::<c_void >()as *mut c_void , core::ptr::null_mut (),true , );
rust/qemu-api/src/qdev.rs +1 -1
@@ -23,7 +23,7 @@ pub trait DeviceImpl {/// /// If not `None`, the parent class's `realize` method is overridden /// with the function pointed to by `REALIZE`. -const REALIZE :Option <fn (&mut Self )> =None ; +const REALIZE :Option <fn (&Self )> =None ;/// If not `None`, the parent class's `reset` method is overridden /// with the function pointed to by `RESET`.
Signature · 1 line
2.48.1
[PULL 24/48] memattrs: Check the size of MemTxAttrs
In reply to Paolo BonziniFrom: Zhao Liu <[email protected]>
Make sure MemTxAttrs is packed into 8 bytes and does not exceed 8 bytes.
--- include/exec/memattrs.h | 2 ++ 1 file changed, 2 insertions(+)
include/exec/memattrs.h +2 -0
@@ -64,6 +64,8 @@ typedef struct MemTxAttrs {uint16_t _reserved2; } MemTxAttrs; +QEMU_BUILD_BUG_ON (sizeof (MemTxAttrs) >8 ); +/* Bus masters which don't specify any attributes will get this, * which has all attribute bits clear except the topmost one * (so that we can distinguish "all attributes deliberately clear"
Signature · 1 line
2.48.1
Quoted 13 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)
are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to
9feb68638e504c91b59e745b94423e8536abfd03:rust: qemu-api: add sub-subclass to the integration tests (2025-01-23 19:07:39 +0100)
Quoted 7 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
Hi Paolo,
Please take a look at this failure and send a v2 pull request, if necessary:
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
https://gitlab.com/qemu-project/qemu/-/jobs/8946857796
Thanks,
Stefan
Quoted 78 lines
----------------------------------------------------------------
Paolo Bonzini (39):
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 reference
rust/zeroable: Implement Zeroable withconst_zeromacro
rust: qemu-api: add sub-subclass to the integration testsTao 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 (5):
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 MemTxAttrsdocs/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 | 489 +++++++++++++---------- rust/hw/char/pl011/src/device_class.rs | 73 ++-- rust/hw/char/pl011/src/lib.rs | 67 ++-- 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, 1403 insertions(+), 846 deletions(-)--
2.48.1
Il ven 24 gen 2025, 20:05 Stefan Hajnoczi <[email protected]> ha scritto:
Quoted 11 lines
Hi Paolo,
Please take a look at this failure and send a v2 pull request, if necessary: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
Yes, it's a real bug.
Paolo
Quoted 93 lines
Thanks,
StefanQuoted 8 lines
----------------------------------------------------------------
Paolo Bonzini (39):
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 stringinstructions
Quoted 4 lines
target/i386: reorganize ops emitted by
do_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 stringinstructions.
Quoted 1 line
target/i386: do not use
gen_op_jz_ecxfor repeated stringoperations
Quoted 2 lines
target/i386: optimize CX handling in repeated string operations target/i386: execute multiple REP/REPZ iterations without leaving
TB
Quoted 8 lines
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->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 typesQuoted 8 lines
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 outside
pl011::deviceQuoted 2 lines
rust: pl011: extract conversion to RegisterOffset
rust: pl011: extract CharBackend receive logic into a separatefunction
Quoted 5 lines
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 MemoryRegionOpscallbacks
Quoted 5 lines
rust: pl011: drop use of ControlFlow
rust: qdev: make reset take a shared referencerust/zeroable: Implement Zeroable withconst_zeromacro
rust: qemu-api: add sub-subclass to the integration testsQuoted 8 lines
Tao 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 (5):
stub: Fix build failure with --enable-user --disable-system--enable-tools
Quoted 5 lines
rust/qdev: Make REALIZE saferust/pl011: Avoid bindings::*
memattrs: Convert unspecified member to bool
memattrs: Check the size of MemTxAttrsQuoted 14 lines
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 | 489 +++++++++++++---------- rust/hw/char/pl011/src/device_class.rs | 73 ++-- rust/hw/char/pl011/src/lib.rs | 67 ++-- 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+++++++++++++++++++++------------
Quoted 8 lines
rust/qemu-api/src/zeroable.rs | 118 +++--- rust/qemu-api/tests/tests.rs | 56 ++- stubs/meson.build | 4 +- 17 files changed, 1403 insertions(+), 846 deletions(-)--
2.48.1