Skip to content

Commit 1843a0c

Browse files
committed
Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging
* scripts: dump stdin on meson-buildoptions error * rust: introduce qemu_api::cell::Opaque<> * rust: express pinning requirements for timers * rust: hpet: decode HPET registers into enums * rust: cell: add full example of declaring a SysBusDevice * rust: qom: remove operations on &mut # -----BEGIN PGP SIGNATURE----- # # iQFIBAABCAAyFiEE8TM4V0tmI4mGbHaCv/vSX3jHroMFAmfNbXwUHHBib256aW5p # QHJlZGhhdC5jb20ACgkQv/vSX3jHroNjpwf+ODnG0XzHt7LSag695zs5fVLK353m # vLAHJ0bsmHoR4V+jEc+eaY7esDx5TLB9SRX/NvDsumJ9xnGYxXVn8Ti5GNHpa/xd # qSReB6X3E8fqG5e3AffUJGJnxrD8dHJ733RsyJBZqJc9sWkUnSiEBb5lGu7br6oC # fFyfiGweYboQ4AsiQUDtEN+tQsTWNkdThYEzq+dpnZrDJHNnw5e/rRwmqCUnEsLU # PfwhrOGJ3OkIUtdgHStuNfiN9sqjXV5DXmZVa9L2We8FEQdkhBzg3TC0ez0gFG/1 # W0P6JwfWk9Z+y/ERxkaycSXmabM0zUiFF1UJNgKEXp5iuPnRFC82OtRSUg== # =de1b # -----END PGP SIGNATURE----- # gpg: Signature made Sun 09 Mar 2025 18:29:16 HKT # gpg: using RSA key F13338574B662389866C7682BFFBD25F78C7AE83 # gpg: issuer "[email protected]" # gpg: Good signature from "Paolo Bonzini <[email protected]>" [full] # gpg: aka "Paolo Bonzini <[email protected]>" [full] # Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4 E2F7 7E15 100C CD36 69B1 # Subkey fingerprint: F133 3857 4B66 2389 866C 7682 BFFB D25F 78C7 AE83 * tag 'for-upstream' of https://gitlab.com/bonzini/qemu: (25 commits) rust: pl011: Allow NULL chardev argument to pl011_create() meson.build: default to -gsplit-dwarf for debug info rust: qom: remove operations on &mut rust: cell: add full example of declaring a SysBusDevice rust: hpet: decode HPET registers into enums rust: pl011: pass around registers::Data rust: pl011: switch to safe chardev operation rust: pl011: clean up visibilities of callbacks rust: pl011: move register definitions out of lib.rs rust: chardev: provide basic bindings to character devices rust: bindings: remove more unnecessary Send/Sync impls rust: chardev: wrap Chardev with Opaque<> rust: memory: wrap MemoryRegion with Opaque<> rust: sysbus: wrap SysBusDevice with Opaque<> rust: hpet: do not access fields of SysBusDevice rust: qdev: wrap Clock and DeviceState with Opaque<> rust: qom: wrap Object with Opaque<> rust: irq: wrap IRQState with Opaque<> rust: timer: wrap QEMUTimer with Opaque<> and express pinning requirements rust: hpet: embed Timer without the Option and Box indirection ... Signed-off-by: Stefan Hajnoczi <[email protected]>
2 parents d9a4282 + 8169453 commit 1843a0c

File tree

25 files changed

+1545
-1004
lines changed

25 files changed

+1545
-1004
lines changed

docs/devel/rust.rst

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,35 @@ of ``&mut self``; access to internal fields must use *interior mutability*
296296
to go from a shared reference to a ``&mut``.
297297

298298
Whenever C code provides you with an opaque ``void *``, avoid converting it
299-
to a Rust mutable reference, and use a shared reference instead. Rust code
300-
will then have to use QEMU's ``BqlRefCell`` and ``BqlCell`` type, which
301-
enforce that locking rules for the "Big QEMU Lock" are respected. These cell
302-
types are also known to the ``vmstate`` crate, which is able to "look inside"
303-
them when building an in-memory representation of a ``struct``'s layout.
304-
Note that the same is not true of a ``RefCell`` or ``Mutex``.
305-
306-
In the future, similar cell types might also be provided for ``AioContext``-based
307-
locking as well.
299+
to a Rust mutable reference, and use a shared reference instead. The
300+
``qemu_api::cell`` module provides wrappers that can be used to tell the
301+
Rust compiler about interior mutability, and optionally to enforce locking
302+
rules for the "Big QEMU Lock". In the future, similar cell types might
303+
also be provided for ``AioContext``-based locking as well.
304+
305+
In particular, device code will usually rely on the ``BqlRefCell`` and
306+
``BqlCell`` type to ensure that data is accessed correctly under the
307+
"Big QEMU Lock". These cell types are also known to the ``vmstate``
308+
crate, which is able to "look inside" them when building an in-memory
309+
representation of a ``struct``'s layout. Note that the same is not true
310+
of a ``RefCell`` or ``Mutex``.
311+
312+
Bindings code instead will usually use the ``Opaque`` type, which hides
313+
the contents of the underlying struct and can be easily converted to
314+
a raw pointer, for use in calls to C functions. It can be used for
315+
example as follows::
316+
317+
#[repr(transparent)]
318+
#[derive(Debug, qemu_api_macros::Wrapper)]
319+
pub struct Object(Opaque<bindings::Object>);
320+
321+
where the special ``derive`` macro provides useful methods such as
322+
``from_raw``, ``as_ptr`, ``as_mut_ptr`` and ``raw_get``. The bindings will
323+
then manually check for the big QEMU lock with assertions, which allows
324+
the wrapper to be declared thread-safe::
325+
326+
unsafe impl Send for Object {}
327+
unsafe impl Sync for Object {}
308328

309329
Writing bindings to C code
310330
''''''''''''''''''''''''''

meson.build

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,10 @@ if get_option('tsan')
601601
qemu_ldflags = ['-fsanitize=thread'] + qemu_ldflags
602602
endif
603603

604+
if get_option('debug') and get_option('split_debug')
605+
qemu_cflags += '-gsplit-dwarf'
606+
endif
607+
604608
# Detect support for PT_GNU_RELRO + DT_BIND_NOW.
605609
# The combination is known as "full relro", because .got.plt is read-only too.
606610
qemu_ldflags += cc.get_supported_link_arguments('-Wl,-z,relro', '-Wl,-z,now')
@@ -4015,7 +4019,7 @@ libchardev = static_library('chardev', chardev_ss.sources() + genh,
40154019
build_by_default: false)
40164020

40174021
chardev = declare_dependency(objects: libchardev.extract_all_objects(recursive: false),
4018-
dependencies: chardev_ss.dependencies())
4022+
dependencies: [chardev_ss.dependencies(), io])
40194023

40204024
hwcore_ss = hwcore_ss.apply({})
40214025
libhwcore = static_library('hwcore', sources: hwcore_ss.sources() + genh,
@@ -4100,13 +4104,6 @@ if have_rust
41004104
foreach enum : c_bitfields
41014105
bindgen_args += ['--bitfield-enum', enum]
41024106
endforeach
4103-
c_nocopy = [
4104-
'QEMUTimer',
4105-
]
4106-
# Used to customize Drop trait
4107-
foreach struct : c_nocopy
4108-
bindgen_args += ['--no-copy', struct]
4109-
endforeach
41104107

41114108
# TODO: Remove this comment when the clang/libclang mismatch issue is solved.
41124109
#
@@ -4590,6 +4587,8 @@ if have_rust
45904587
summary_info += {'bindgen': bindgen.full_path()}
45914588
summary_info += {'bindgen version': bindgen.version()}
45924589
endif
4590+
# option_cflags is purely for the summary display, meson will pass
4591+
# -g/-O options directly
45934592
option_cflags = (get_option('debug') ? ['-g'] : [])
45944593
if get_option('optimization') != 'plain'
45954594
option_cflags += ['-O' + get_option('optimization')]

meson_options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ option('debug_mutex', type: 'boolean', value: false,
362362
description: 'mutex debugging support')
363363
option('debug_stack_usage', type: 'boolean', value: false,
364364
description: 'measure coroutine stack usage')
365+
option('split_debug', type: 'boolean', value: true,
366+
description: 'split debug info from object files')
365367
option('qom_cast_debug', type: 'boolean', value: true,
366368
description: 'cast debugging support')
367369
option('slirp_smbd', type : 'feature', value : 'auto',

rust/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ result_unit_err = "allow"
3737
should_implement_trait = "deny"
3838
# can be for a reason, e.g. in callbacks
3939
unused_self = "allow"
40+
# common in device crates
41+
upper_case_acronyms = "allow"
4042

4143
# default-allow lints
4244
as_ptr_cast_mut = "deny"

0 commit comments

Comments
 (0)