Skip to content

Commit

Permalink
Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging
Browse files Browse the repository at this point in the history
* first commit for Rust support
* add CI job using Fedora + Rust nightly
* fix detection of ATOMIC128 on x86_64
* fix compilation with Sphinx 8.1.0

# -----BEGIN PGP SIGNATURE-----
#
# iQFIBAABCAAyFiEE8TM4V0tmI4mGbHaCv/vSX3jHroMFAmcJEKUUHHBib256aW5p
# QHJlZGhhdC5jb20ACgkQv/vSX3jHroOSZQf+LlvZm9npHR6lZ9DEruhu/uf0c1gO
# 9+dBJiKQ1OWopSQOqEgOsLL0J123Ls4V8O3tzZwIDuuRofCB2+wKswad6CHoydJx
# 4p9rRXv6MLlnTqqGxemm/dPZqJ7+6L0poHoDKW+s7AgfVDshhj1RSbQfs8Ujh41F
# f1sdi3DzopVWtK4CE+8/UeLy5Cxlixke9SKhYQrFHrdsANARP81gxQjczKApMc1z
# v9qkrLtkM06VUyuvbPps7CHSHDpzx9mXcmkkPgLqLX9MfbCztzi44aVSaS9HYk5G
# y54dSKdY7VJEuGhG916G+GMDJyow4nhT9Gk6tWtk63TQN5nExVsoZMOmdw==
# =PFGL
# -----END PGP SIGNATURE-----
# gpg: Signature made Fri 11 Oct 2024 12:48:53 BST
# 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:
  docs: use consistent markup for footnotes
  docs: avoid footnotes consisting of just URLs
  docs: fix invalid footnote syntax
  gitlab-ci: add Rust-enabled CI job
  dockerfiles: add a Dockerfile using a nightly Rust toolchain
  meson: ensure -mcx16 is passed when detecting ATOMIC128
  meson: define qemu_isa_flags
  meson: fix machine option for x86_version
  rust: add PL011 device model
  rust: add utility procedural macro crate
  scripts/archive-source: find directory name for subprojects
  rust: add crate to expose bindings and interfaces
  meson.build: add HAVE_GLIB_WITH_ALIGNED_ALLOC flag
  .gitattributes: add Rust diff and merge attributes
  rust: add bindgen step as a meson dependency
  configure, meson: detect Rust toolchain
  build-sys: Add rust feature option
  Require meson version 1.5.0

Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
pm215 committed Oct 11, 2024
2 parents 7e3b6d8 + 381d2c3 commit b38d263
Show file tree
Hide file tree
Showing 88 changed files with 3,474 additions and 75 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
*.h.inc diff=c
*.m diff=objc
*.py diff=python
*.rs diff=rust
*.rs.inc diff=rust
Cargo.lock diff=toml merge=binary
13 changes: 13 additions & 0 deletions .gitlab-ci.d/buildtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ build-system-fedora:
xtensa-softmmu m68k-softmmu riscv32-softmmu ppc-softmmu sparc64-softmmu
MAKE_CHECK_ARGS: check-build

build-system-fedora-rust-nightly:
extends:
- .native_build_job_template
- .native_build_artifact_template
needs:
job: amd64-fedora-rust-nightly-container
variables:
IMAGE: fedora-rust-nightly
CONFIGURE_ARGS: --disable-docs --enable-rust
TARGETS: aarch64-softmmu
MAKE_CHECK_ARGS: check-build
allow_failure: true

check-system-fedora:
extends: .native_test_job_template
needs:
Expand Down
6 changes: 6 additions & 0 deletions .gitlab-ci.d/containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ python-container:
extends: .container_job_template
variables:
NAME: python

amd64-fedora-rust-nightly-container:
extends: .container_job_template
variables:
NAME: fedora-rust-nightly
allow_failure: true
1 change: 1 addition & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ source accel/Kconfig
source target/Kconfig
source hw/Kconfig
source semihosting/Kconfig
source rust/Kconfig
3 changes: 3 additions & 0 deletions Kconfig.host
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ config VFIO_USER_SERVER_ALLOWED

config HV_BALLOON_POSSIBLE
bool

config HAVE_RUST
bool
21 changes: 21 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,11 @@ F: include/hw/*/microbit*.h
F: tests/qtest/microbit-test.c
F: docs/system/arm/nrf.rst

ARM PL011 Rust device
M: Manos Pitsidianakis <[email protected]>
S: Maintained
F: rust/hw/char/pl011/

AVR Machines
-------------

Expand Down Expand Up @@ -3286,6 +3291,13 @@ F: hw/core/register.c
F: include/hw/register.h
F: include/hw/registerfields.h

Rust
M: Manos Pitsidianakis <[email protected]>
S: Maintained
F: rust/qemu-api
F: rust/qemu-api-macros
F: rust/rustfmt.toml

SLIRP
M: Samuel Thibault <[email protected]>
S: Maintained
Expand Down Expand Up @@ -4183,6 +4195,15 @@ F: docs/sphinx/
F: docs/_templates/
F: docs/devel/docs.rst

Rust build system integration
M: Manos Pitsidianakis <[email protected]>
S: Maintained
F: scripts/rust/
F: rust/.gitignore
F: rust/Kconfig
F: rust/meson.build
F: rust/wrapper.h

Miscellaneous
-------------
Performance Tools and Tests
Expand Down
170 changes: 168 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ for opt do
;;
--objcc=*) objcc="$optarg"
;;
--rustc=*) RUSTC="$optarg"
;;
--cpu=*) cpu="$optarg"
;;
--extra-cflags=*)
Expand Down Expand Up @@ -252,6 +254,8 @@ python=
download="enabled"
skip_meson=no
use_containers="yes"
rust="disabled"
rust_target_triple=""
gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
gdb_arches=""

Expand Down Expand Up @@ -310,13 +314,16 @@ objcopy="${OBJCOPY-${cross_prefix}objcopy}"
ld="${LD-${cross_prefix}ld}"
ranlib="${RANLIB-${cross_prefix}ranlib}"
nm="${NM-${cross_prefix}nm}"
readelf="${READELF-${cross_prefix}readelf}"
strip="${STRIP-${cross_prefix}strip}"
widl="${WIDL-${cross_prefix}widl}"
windres="${WINDRES-${cross_prefix}windres}"
windmc="${WINDMC-${cross_prefix}windmc}"
pkg_config="${PKG_CONFIG-${cross_prefix}pkg-config}"
sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"

rustc="${RUSTC-rustc}"

check_define() {
cat > $TMPC <<EOF
#if !defined($1)
Expand Down Expand Up @@ -425,6 +432,7 @@ fi
# Please keep it sorted and synchronized with meson.build's host_arch.
host_arch=
linux_arch=
raw_cpu=$cpu
case "$cpu" in
aarch64)
host_arch=aarch64
Expand Down Expand Up @@ -658,6 +666,8 @@ for opt do
;;
--objcc=*)
;;
--rustc=*)
;;
--make=*)
;;
--install=*)
Expand Down Expand Up @@ -777,8 +787,14 @@ for opt do
;;
--container-engine=*) container_engine="$optarg"
;;
--rust-target-triple=*) rust_target_triple="$optarg"
;;
--gdb=*) gdb_bin="$optarg"
;;
--enable-rust) rust=enabled
;;
--disable-rust) rust=disabled
;;
# everything else has the same name in configure and meson
--*) meson_option_parse "$opt" "$optarg"
;;
Expand Down Expand Up @@ -881,6 +897,7 @@ Advanced options (experts only):
at build time [$host_cc]
--cxx=CXX use C++ compiler CXX [$cxx]
--objcc=OBJCC use Objective-C compiler OBJCC [$objcc]
--rustc=RUSTC use Rust compiler RUSTC [$rustc]
--extra-cflags=CFLAGS append extra C compiler flags CFLAGS
--extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
--extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
Expand All @@ -891,8 +908,9 @@ Advanced options (experts only):
--python=PYTHON use specified python [$python]
--ninja=NINJA use specified ninja [$ninja]
--static enable static build [$static]
--without-default-features default all --enable-* options to "disabled"
--without-default-devices do not include any device that is not needed to
--rust-target-triple=TRIPLE compilation target for Rust code [autodetect]
--without-default-features default all --enable-* options to "disabled"
--without-default-devices do not include any device that is not needed to
start the emulator (only use if you are including
desired devices in configs/devices/)
--with-devices-ARCH=NAME override default configs/devices
Expand Down Expand Up @@ -1166,6 +1184,132 @@ EOF
fi
fi

##########################################
# detect rust triple

if test "$rust" != disabled && has "$rustc" && $rustc -vV > "${TMPDIR1}/${TMPB}.out"; then
rust_host_triple=$(sed -n 's/^host: //p' "${TMPDIR1}/${TMPB}.out")
else
if test "$rust" = enabled; then
error_exit "could not execute rustc binary \"$rustc\""
fi
rust=disabled
fi
if test "$rust" != disabled && test -z "$rust_target_triple"; then
# arch and os generally matches between meson and rust
rust_arch=$host_arch
rust_os=$host_os
rust_machine=unknown
rust_osvariant=

# tweak rust_os if needed; also, machine and variant depend on the OS
android=no
case "$host_os" in
darwin)
# e.g. aarch64-apple-darwin
rust_machine=apple
;;

linux)
# detect android/glibc/musl
if check_define __ANDROID__; then
rust_osvariant=android
android=yes
else
cat > $TMPC << EOF
#define _GNU_SOURCE
#include <features.h>
#ifndef __USE_GNU
error using musl
#endif
EOF
if compile_object; then
rust_osvariant=gnu
else
rust_osvariant=musl
fi
fi

case "$host_arch" in
arm)
# e.g. arm-unknown-linux-gnueabi, arm-unknown-linux-gnueabihf
write_c_skeleton
compile_object
if $READELF -A $TMPO | grep Tag_API_VFP_args: > /dev/null; then
rust_osvariant=${rust_osvariant}eabihf
else
rust_osvariant=${rust_osvariant}eabi
fi
;;

mips64)
# e.g. mips64-unknown-linux-gnuabi64
rust_osvariant=${rust_osvariant}abi64
;;
esac
;;

netbsd)
# e.g. arm-unknown-netbsd-eabihf
test "$host_arch" = arm && rust_osvariant=eabihf
;;

sunos)
rust_machine=pc
rust_os=solaris
;;

windows)
# e.g. aarch64-pc-windows-gnullvm, x86_64-pc-windows-gnu (MSVC not supported)
rust_machine=pc
if test "$host_arch" = aarch64; then
rust_osvariant=gnullvm
else
rust_osvariant=gnu
fi
;;
esac

# now tweak the architecture part, possibly based on pre-canonicalization --cpu
case "$host_arch" in
arm)
# preserve ISA version (armv7 etc.) from $raw_cpu if passed via --cpu
rust_arch=$raw_cpu
test "$rust_arch" = arm && test "$rust_os" != linux && rust_arch=armv7
;;

mips|mips64)
# preserve ISA version (mipsisa64r6 etc.) and include endianness
rust_arch=${raw_cpu%el}
test "$bigendian" = no && rust_arch=${rust_arch}el
;;

riscv32|riscv64)
# e.g. riscv64gc-unknown-linux-gnu, but riscv64-linux-android
test "$android" = no && rust_arch=${rust_arch}gc
;;

sparc64)
if test "$rust_os" = solaris; then
rust_arch=sparcv9
rust_machine=sun
fi
;;

x86_64)
# e.g. x86_64-unknown-linux-gnux32
test "$raw_cpu" = x32 && rust_osvariant=${rust_osvariant}x32
;;
esac

if test "$android" = yes; then
# e.g. aarch64-linux-android
rust_target_triple=$rust_arch-$rust_os-$rust_osvariant
else
rust_target_triple=$rust_arch-$rust_machine-$rust_os${rust_osvariant:+-$rust_osvariant}
fi
fi

##########################################
# functions to probe cross compilers

Expand Down Expand Up @@ -1628,6 +1772,9 @@ if test "$container" != no; then
echo "RUNC=$runc" >> $config_host_mak
fi
echo "SUBDIRS=$subdirs" >> $config_host_mak
if test "$rust" != disabled; then
echo "RUST_TARGET_TRIPLE=$rust_target_triple" >> $config_host_mak
fi
echo "PYTHON=$python" >> $config_host_mak
echo "MKVENV_ENSUREGROUP=$mkvenv ensuregroup $mkvenv_online_flag" >> $config_host_mak
echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
Expand Down Expand Up @@ -1764,12 +1911,20 @@ if test "$skip_meson" = no; then
echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
test -n "$objcc" && echo "objc = [$(meson_quote $objcc $CPU_CFLAGS)]" >> $cross
if test "$rust" != disabled; then
if test "$rust_host_triple" != "$rust_target_triple"; then
echo "rust = [$(meson_quote $rustc --target "$rust_target_triple")]" >> $cross
else
echo "rust = [$(meson_quote $rustc)]" >> $cross
fi
fi
echo "ar = [$(meson_quote $ar)]" >> $cross
echo "dlltool = [$(meson_quote $dlltool)]" >> $cross
echo "nm = [$(meson_quote $nm)]" >> $cross
echo "pkgconfig = [$(meson_quote $pkg_config)]" >> $cross
echo "pkg-config = [$(meson_quote $pkg_config)]" >> $cross
echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
echo "readelf = [$(meson_quote $readelf)]" >> $cross
if has $sdl2_config; then
echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
fi
Expand Down Expand Up @@ -1799,6 +1954,9 @@ if test "$skip_meson" = no; then
echo "# Automatically generated by configure - do not modify" > $native
echo "[binaries]" >> $native
echo "c = [$(meson_quote $host_cc)]" >> $native
if test "$rust" != disabled; then
echo "rust = [$(meson_quote $rustc)]" >> $cross
fi
mv $native config-meson.native
meson_option_add --native-file
meson_option_add config-meson.native
Expand All @@ -1817,6 +1975,7 @@ if test "$skip_meson" = no; then
test "$pie" = no && meson_option_add -Db_pie=false

# QEMU options
test "$rust" != "auto" && meson_option_add "-Drust=$rust"
test "$cfi" != false && meson_option_add "-Dcfi=$cfi" "-Db_lto=$cfi"
test "$docs" != auto && meson_option_add "-Ddocs=$docs"
test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
Expand Down Expand Up @@ -1901,3 +2060,10 @@ echo ' "$@"' >>config.status
chmod +x config.status

rm -r "$TMPDIR1"

if test "$rust" != disabled; then
echo '\nINFO: Rust bindings generation with `bindgen` might fail in some cases where'
echo 'the detected `libclang` does not match the expected `clang` version/target. In'
echo 'this case you must pass the path to `clang` and `libclang` to your build'
echo 'command invocation using the environment variables CLANG_PATH and LIBCLANG_PATH'
fi
6 changes: 3 additions & 3 deletions docs/devel/atomics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ They come in six kinds:
before the second with respect to the other components of the system.
Therefore, unlike ``smp_rmb()`` or ``qatomic_load_acquire()``,
``smp_read_barrier_depends()`` can be just a compiler barrier on
weakly-ordered architectures such as Arm or PPC[#]_.
weakly-ordered architectures such as Arm or PPC\ [#alpha]_.

Note that the first load really has to have a _data_ dependency and not
a control dependency. If the address for the second load is dependent
on the first load, but the dependency is through a conditional rather
than actually loading the address itself, then it's a _control_
dependency and a full read barrier or better is required.

.. [#] The DEC Alpha is an exception, because ``smp_read_barrier_depends()``
.. [#alpha] The DEC Alpha is an exception, because ``smp_read_barrier_depends()``
needs a processor barrier. On strongly-ordered architectures such
as x86 or s390, ``smp_rmb()`` and ``qatomic_load_acquire()`` can
also be compiler barriers only.
Expand Down Expand Up @@ -295,7 +295,7 @@ Acquire/release pairing and the *synchronizes-with* relation
------------------------------------------------------------

Atomic operations other than ``qatomic_set()`` and ``qatomic_read()`` have
either *acquire* or *release* semantics [#rmw]_. This has two effects:
either *acquire* or *release* semantics\ [#rmw]_. This has two effects:

.. [#rmw] Read-modify-write operations can have both---acquire applies to the
read part, and release to the write.
Expand Down
Loading

0 comments on commit b38d263

Please sign in to comment.