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
* document what configure does with virtual environments
* Bump known good meson version to v1.2.3
* Upgrade macOS to 13 (Ventura) and Add manual testing of macOS 14 (Sonoma)
* use simple assertions instead of Coverity models

# -----BEGIN PGP SIGNATURE-----
#
# iQFIBAABCAAyFiEE8TM4V0tmI4mGbHaCv/vSX3jHroMFAmVN+kcUHHBib256aW5p
# QHJlZGhhdC5jb20ACgkQv/vSX3jHroPUowf/cnIY/3uICnaJLQZ7DESczHiOikc9
# 3q9tVRKYsef8hQaYjIgXXUAHE4vORX0I7O46UfG0Q/FwhTj/1CJoADfoWVmJlzYM
# clzLVD/3U87jj9DZnzNomCL78MXno2ZzdfrVsUoo4ioMQXe5dioIq6Uw0v5ROjYC
# vBQWtFnEv0vrNRjN7flXdkL1PRIBu7NSHviVW8C1UtzF7jMzHJpe4rOSjnyqIXso
# lNXTt3q8qQjS7tI84MXicFEYCBEE7ae3wbErbWV+ulQ4TiyzjSyduWQHsAJ63te/
# OiLvxgcWCyda1SMpMgmy5+zpfG0ZwCrGD7lN+Dfz+D12wknN7ztlNEx1LQ==
# =JkYJ
# -----END PGP SIGNATURE-----
# gpg: Signature made Fri 10 Nov 2023 17:39:19 HKT
# gpg:                using RSA key F13338574B662389866C7682BFFBD25F78C7AE83
# gpg:                issuer "pbonzini@redhat.com"
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" [full]
# gpg:                 aka "Paolo Bonzini <pbonzini@redhat.com>" [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:
  .gitlab-ci.d/cirrus: Add manual testing of macOS 14 (Sonoma)
  .gitlab-ci.d/cirrus: Upgrade macOS to 13 (Ventura)
  buildsys: Bump known good meson version to v1.2.3
  docs: document what configure does with virtual environments
  tests: respect --enable/--disable-download for Avocado
  coverity: physmem: use simple assertions instead of modelling

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
stefanhaRH committed Nov 12, 2023
2 parents 6968074 + 1d802d0 commit 4bb351b
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 106 deletions.
22 changes: 19 additions & 3 deletions .gitlab-ci.d/cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ x64-freebsd-13-build:
INSTALL_COMMAND: pkg install -y
TEST_TARGETS: check

aarch64-macos-12-base-build:
aarch64-macos-13-base-build:
extends: .cirrus_build_job
variables:
NAME: macos-12
NAME: macos-13
CIRRUS_VM_INSTANCE_TYPE: macos_instance
CIRRUS_VM_IMAGE_SELECTOR: image
CIRRUS_VM_IMAGE_NAME: ghcr.io/cirruslabs/macos-monterey-base:latest
CIRRUS_VM_IMAGE_NAME: ghcr.io/cirruslabs/macos-ventura-base:latest
CIRRUS_VM_CPUS: 12
CIRRUS_VM_RAM: 24G
UPDATE_COMMAND: brew update
Expand All @@ -74,6 +74,22 @@ aarch64-macos-12-base-build:
PKG_CONFIG_PATH: /opt/homebrew/curl/lib/pkgconfig:/opt/homebrew/ncurses/lib/pkgconfig:/opt/homebrew/readline/lib/pkgconfig
TEST_TARGETS: check-unit check-block check-qapi-schema check-softfloat check-qtest-x86_64

aarch64-macos-14-base-build:
extends: .cirrus_build_job
variables:
NAME: macos-14
CIRRUS_VM_INSTANCE_TYPE: macos_instance
CIRRUS_VM_IMAGE_SELECTOR: image
CIRRUS_VM_IMAGE_NAME: ghcr.io/cirruslabs/macos-sonoma-base:latest
CIRRUS_VM_CPUS: 12
CIRRUS_VM_RAM: 24G
UPDATE_COMMAND: brew update
INSTALL_COMMAND: brew install
PATH_EXTRA: /opt/homebrew/ccache/libexec:/opt/homebrew/gettext/bin
PKG_CONFIG_PATH: /opt/homebrew/curl/lib/pkgconfig:/opt/homebrew/ncurses/lib/pkgconfig:/opt/homebrew/readline/lib/pkgconfig
TEST_TARGETS: check-unit check-block check-qapi-schema check-softfloat check-qtest-x86_64
QEMU_JOB_OPTIONAL: 1


# The following jobs run VM-based tests via KVM on a Linux-based Cirrus-CI job
.cirrus_kvm_job:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTO-GENERATED
#
# $ lcitool variables macos-12 qemu
# $ lcitool variables macos-13 qemu
#
# https://gitlab.com/libvirt/libvirt-ci

Expand Down
16 changes: 16 additions & 0 deletions .gitlab-ci.d/cirrus/macos-14.vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# THIS FILE WAS AUTO-GENERATED
#
# $ lcitool variables macos-14 qemu
#
# https://gitlab.com/libvirt/libvirt-ci

CCACHE='/opt/homebrew/bin/ccache'
CPAN_PKGS=''
CROSS_PKGS=''
MAKE='/opt/homebrew/bin/gmake'
NINJA='/opt/homebrew/bin/ninja'
PACKAGING_COMMAND='brew'
PIP3='/opt/homebrew/bin/pip3'
PKGS='bash bc bison bzip2 capstone ccache cmocka ctags curl dbus diffutils dtc flex gcovr gettext git glib gnu-sed gnutls gtk+3 jemalloc jpeg-turbo json-c libepoxy libffi libgcrypt libiscsi libnfs libpng libslirp libssh libtasn1 libusb llvm lzo make meson mtools ncurses nettle ninja pixman pkg-config python3 rpm2cpio sdl2 sdl2_image snappy socat sparse spice-protocol swtpm tesseract usbredir vde vte3 xorriso zlib zstd'
PYPI_PKGS='PyYAML numpy pillow sphinx sphinx-rtd-theme tomli'
PYTHON='/opt/homebrew/bin/python3'
9 changes: 5 additions & 4 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -968,14 +968,14 @@ meson="$(cd pyvenv/bin; pwd)/meson"

# Conditionally ensure Sphinx is installed.

mkvenv_flags=""
if test "$download" = "enabled" -a "$docs" = "enabled" ; then
mkvenv_flags="--online"
mkvenv_online_flag=""
if test "$download" = "enabled" ; then
mkvenv_online_flag=" --online"
fi

if test "$docs" != "disabled" ; then
if ! $mkvenv ensuregroup \
$mkvenv_flags \
$(test "$docs" = "enabled" && echo "$mkvenv_online_flag") \
${source_path}/pythondeps.toml docs;
then
if test "$docs" = "enabled" ; then
Expand Down Expand Up @@ -1631,6 +1631,7 @@ if test "$container" != no; then
fi
echo "SUBDIRS=$subdirs" >> $config_host_mak
echo "PYTHON=$python" >> $config_host_mak
echo "MKVENV_ENSUREGROUP=$mkvenv ensuregroup $mkvenv_online_flag" >> $config_host_mak
echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
echo "MESON=$meson" >> $config_host_mak
echo "NINJA=$ninja" >> $config_host_mak
Expand Down
88 changes: 85 additions & 3 deletions docs/devel/build-system.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,78 @@ functioning. These are performed using a few more helper functions:
indicated by $TMPC.


Python virtual environments and the QEMU build system
-----------------------------------------------------
Python virtual environments and the build process
-------------------------------------------------

An important step in ``configure`` is to create a Python virtual
environment (venv) during the configuration phase. The Python interpreter
comes from the ``--python`` command line option, the ``$PYTHON`` variable
from the environment, or the system PATH, in this order. The venv resides
in the ``pyvenv`` directory in the build tree, and provides consistency
in how the build process runs Python code.

At this stage, ``configure`` also queries the chosen Python interpreter
about QEMU's build dependencies. Note that the build process does *not*
look for ``meson``, ``sphinx-build`` or ``avocado`` binaries in the PATH;
likewise, there are no options such as ``--meson`` or ``--sphinx-build``.
This avoids a potential mismatch, where Meson and Sphinx binaries on the
PATH might operate in a different Python environment than the one chosen
by the user during the build process. On the other hand, it introduces
a potential source of confusion where the user installs a dependency but
``configure`` is not able to find it. When this happens, the dependency
was installed in the ``site-packages`` directory of another interpreter,
or with the wrong ``pip`` program.

If a package is available for the chosen interpreter, ``configure``
prepares a small script that invokes it from the venv itself[#distlib]_.
If not, ``configure`` can also optionally install dependencies in the
virtual environment with ``pip``, either from wheels in ``python/wheels``
or by downloading the package with PyPI. Downloading can be disabled with
``--disable-download``; and anyway, it only happens when a ``configure``
option (currently, only ``--enable-docs``) is explicitly enabled but
the dependencies are not present[#pip]_.

.. [#distlib] The scripts are created based on the package's metadata,
specifically the ``console_script`` entry points. This is the
same mechanism that ``pip`` uses when installing a package.
Currently, in all cases it would be possible to use ``python -m``
instead of an entry point script, which makes this approach a
bit overkill. On the other hand, creating the scripts is
future proof and it makes the contents of the ``pyvenv/bin``
directory more informative. Portability is also not an issue,
because the Python Packaging Authority provides a package
``distlib.scripts`` to perform this task.
.. [#pip] ``pip`` might also be used when running ``make check-avocado``
if downloading is enabled, to ensure that Avocado is
available.
The required versions of the packages are stored in a configuration file
``pythondeps.toml``. The format is custom to QEMU, but it is documented
at the top of the file itself and it should be easy to understand. The
requirements should make it possible to use the version that is packaged
that is provided by supported distros.

When dependencies are downloaded, instead, ``configure`` uses a "known
good" version that is also listed in ``pythondeps.toml``. In this
scenario, ``pythondeps.toml`` behaves like the "lock file" used by
``cargo``, ``poetry`` or other dependency management systems.


Bundled Python packages
-----------------------

Python packages that are **mandatory** dependencies to build QEMU,
but are not available in all supported distros, are bundled with the
QEMU sources. Currently this includes Meson (outdated in CentOS 8
and derivatives, Ubuntu 20.04 and 22.04, and openSUSE Leap) and tomli
(absent in Ubuntu 20.04).

If you need to update these, please do so by modifying and rerunning
``python/scripts/vendor.py``. This script embeds the sha256 hash of
package sources and checks it. The pypi.org web site provides an easy
way to retrieve the sha256 hash of the sources.

TBD

Stage 2: Meson
==============
Expand Down Expand Up @@ -376,6 +444,15 @@ This is needed to obey the --python= option passed to the configure
script, which may point to something other than the first python3
binary on the path.

By the time Meson runs, Python dependencies are available in the virtual
environment and should be invoked through the scripts that ``configure``
places under ``pyvenv``. One way to do so is as follows, using Meson's
``find_program`` function::

sphinx_build = find_program(
fs.parent(python.full_path()) / 'sphinx-build',
required: get_option('docs'))


Stage 3: Make
=============
Expand Down Expand Up @@ -434,6 +511,11 @@ number of dynamically created files listed later.
executables. Build rules for various subdirectories are included in
other meson.build files spread throughout the QEMU source tree.

``python/scripts/mkvenv.py``
A wrapper for the Python ``venv`` and ``distlib.scripts`` packages.
It handles creating the virtual environment, creating scripts in
``pyvenv/bin``, and calling ``pip`` to install dependencies.

``tests/Makefile.include``
Rules for external test harnesses. These include the TCG tests
and the Avocado-based integration tests.
Expand Down
4 changes: 2 additions & 2 deletions python/scripts/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def main() -> int:
parser.parse_args()

packages = {
"meson==0.63.3":
"d677b809c4895dcbaac9bf6c43703fcb3609a4b24c6057c78f828590049cf43a",
"meson==1.2.3":
"4533a43c34548edd1f63a276a42690fce15bde9409bcf20c4b8fa3d7e4d7cac1",

"tomli==2.0.1":
"939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc",
Expand Down
Binary file removed python/wheels/meson-0.63.3-py3-none-any.whl
Binary file not shown.
Binary file added python/wheels/meson-1.2.3-py3-none-any.whl
Binary file not shown.
5 changes: 3 additions & 2 deletions pythondeps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
# - accepted: accepted versions when using a system package
# - installed: fixed version to install in the virtual environment
# if a system package is not found; if not specified,
# the minimum and maximum
# defaults to the same as "accepted" or, if also missing,
# to the newest version available on PyPI.
# - canary: if specified, use this program name to present more
# precise error diagnostics to the user. For example,
# 'sphinx-build' can be used as a bellwether for the
# presence of 'sphinx' in the system.

[meson]
# The install key should match the version in python/wheels/
meson = { accepted = ">=0.63.0", installed = "0.63.3", canary = "meson" }
meson = { accepted = ">=0.63.0", installed = "1.2.3", canary = "meson" }

[docs]
sphinx = { accepted = ">=1.6", installed = "5.3.0", canary = "sphinx-build" }
Expand Down
88 changes: 0 additions & 88 deletions scripts/coverity-scan/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,94 +42,6 @@ typedef _Bool bool;

typedef struct va_list_str *va_list;

/* exec.c */

typedef struct AddressSpace AddressSpace;
typedef struct MemoryRegionCache MemoryRegionCache;
typedef uint64_t hwaddr;
typedef uint32_t MemTxResult;
typedef struct MemTxAttrs {} MemTxAttrs;

static void __bufwrite(uint8_t *buf, ssize_t len)
{
int first, last;
__coverity_negative_sink__(len);
if (len == 0) return;
buf[0] = first;
buf[len-1] = last;
__coverity_writeall__(buf);
}

static void __bufread(uint8_t *buf, ssize_t len)
{
__coverity_negative_sink__(len);
if (len == 0) return;
int first = buf[0];
int last = buf[len-1];
}

MemTxResult address_space_read_cached(MemoryRegionCache *cache, hwaddr addr,
MemTxAttrs attrs,
void *buf, int len)
{
MemTxResult result;
// TODO: investigate impact of treating reads as producing
// tainted data, with __coverity_tainted_data_argument__(buf).
__bufwrite(buf, len);
return result;
}

MemTxResult address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
MemTxAttrs attrs,
const void *buf, int len)
{
MemTxResult result;
__bufread(buf, len);
return result;
}

MemTxResult address_space_rw_cached(MemoryRegionCache *cache, hwaddr addr,
MemTxAttrs attrs,
void *buf, int len, bool is_write)
{
if (is_write) {
return address_space_write_cached(cache, addr, attrs, buf, len);
} else {
return address_space_read_cached(cache, addr, attrs, buf, len);
}
}

MemTxResult address_space_read(AddressSpace *as, hwaddr addr,
MemTxAttrs attrs,
void *buf, int len)
{
MemTxResult result;
// TODO: investigate impact of treating reads as producing
// tainted data, with __coverity_tainted_data_argument__(buf).
__bufwrite(buf, len);
return result;
}

MemTxResult address_space_write(AddressSpace *as, hwaddr addr,
MemTxAttrs attrs,
const void *buf, int len)
{
MemTxResult result;
__bufread(buf, len);
return result;
}

MemTxResult address_space_rw(AddressSpace *as, hwaddr addr,
MemTxAttrs attrs,
void *buf, int len, bool is_write)
{
if (is_write) {
return address_space_write(as, addr, attrs, buf, len);
} else {
return address_space_read(as, addr, attrs, buf, len);
}
}

/* Tainting */

typedef struct {} name2keysym_t;
Expand Down
22 changes: 22 additions & 0 deletions system/physmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2699,6 +2699,17 @@ static MemTxResult flatview_write_continue(FlatView *fv, hwaddr addr,
l = memory_access_size(mr, l, addr1);
/* XXX: could force current_cpu to NULL to avoid
potential bugs */

/*
* Assure Coverity (and ourselves) that we are not going to OVERRUN
* the buffer by following ldn_he_p().
*/
#ifdef QEMU_STATIC_ANALYSIS
assert((l == 1 && len >= 1) ||
(l == 2 && len >= 2) ||
(l == 4 && len >= 4) ||
(l == 8 && len >= 8));
#endif
val = ldn_he_p(buf, l);
result |= memory_region_dispatch_write(mr, addr1, val,
size_memop(l), attrs);
Expand Down Expand Up @@ -2769,6 +2780,17 @@ MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr,
l = memory_access_size(mr, l, addr1);
result |= memory_region_dispatch_read(mr, addr1, &val,
size_memop(l), attrs);

/*
* Assure Coverity (and ourselves) that we are not going to OVERRUN
* the buffer by following stn_he_p().
*/
#ifdef QEMU_STATIC_ANALYSIS
assert((l == 1 && len >= 1) ||
(l == 2 && len >= 2) ||
(l == 4 && len >= 4) ||
(l == 8 && len >= 8));
#endif
stn_he_p(buf, l, val);
} else {
/* RAM case */
Expand Down
2 changes: 1 addition & 1 deletion tests/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ quiet-venv-pip = $(quiet-@)$(call quiet-command-run, \

$(TESTS_VENV_TOKEN): $(SRC_PATH)/pythondeps.toml
$(call quiet-venv-pip,install -e "$(SRC_PATH)/python/")
$(PYTHON) python/scripts/mkvenv.py ensuregroup --online $< avocado
$(MKVENV_ENSUREGROUP) $< avocado
$(call quiet-command, touch $@)

$(TESTS_RESULTS_DIR):
Expand Down
2 changes: 1 addition & 1 deletion tests/lcitool/libvirt-ci
Submodule libvirt-ci updated from 36bc51 to 77c800
3 changes: 2 additions & 1 deletion tests/lcitool/refresh
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ try:
# Cirrus packages lists for GitLab
#
generate_cirrus("freebsd-13")
generate_cirrus("macos-12")
generate_cirrus("macos-13")
generate_cirrus("macos-14")

#
# VM packages lists
Expand Down

0 comments on commit 4bb351b

Please sign in to comment.