From ba7c60c203eb068cff591e4d0e7dbcc2b5aa013a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 8 Nov 2021 14:47:54 +0100 Subject: [PATCH 01/16] configure: make $targetos lowercase, use windows instead of MINGW32 targetos is already mostly the same as Meson host_machine.system(), just in CamelCase. Adjust Windows, which is different, and switch to lowercase to match Meson. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- configure | 58 ++++++++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/configure b/configure index 28e1cf6291..e72e34b684 100755 --- a/configure +++ b/configure @@ -501,30 +501,30 @@ EOF } if check_define __linux__ ; then - targetos="Linux" + targetos=linux elif check_define _WIN32 ; then - targetos='MINGW32' + targetos=windows elif check_define __OpenBSD__ ; then - targetos='OpenBSD' + targetos=openbsd elif check_define __sun__ ; then - targetos='SunOS' + targetos=sunos elif check_define __HAIKU__ ; then - targetos='Haiku' + targetos=haiku elif check_define __FreeBSD__ ; then - targetos='FreeBSD' + targetos=freebsd elif check_define __FreeBSD_kernel__ && check_define __GLIBC__; then - targetos='GNU/kFreeBSD' + targetos=gnu/kfreebsd elif check_define __DragonFly__ ; then - targetos='DragonFly' + targetos=dragonfly elif check_define __NetBSD__; then - targetos='NetBSD' + targetos=netbsd elif check_define __APPLE__; then - targetos='Darwin' + targetos=darwin else # This is a fatal error, but don't report it yet, because we # might be going to just print the --help text, or it might # be the result of a missing compiler. - targetos='bogus' + targetos=bogus fi # Some host OSes need non-standard checks for which CPU to use. @@ -532,7 +532,7 @@ fi # cross-compiling to one of these OSes then you'll need to specify # the correct CPU with the --cpu option. case $targetos in -SunOS) +sunos) # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then cpu="x86_64" @@ -623,40 +623,40 @@ fi # OS specific case $targetos in -MINGW32*) +windows) mingw32="yes" plugins="no" pie="no" ;; -GNU/kFreeBSD) +gnu/kfreebsd) bsd="yes" ;; -FreeBSD) +freebsd) bsd="yes" bsd_user="yes" make="${MAKE-gmake}" # needed for kinfo_getvmmap(3) in libutil.h ;; -DragonFly) +dragonfly) bsd="yes" make="${MAKE-gmake}" ;; -NetBSD) +netbsd) bsd="yes" make="${MAKE-gmake}" ;; -OpenBSD) +openbsd) bsd="yes" make="${MAKE-gmake}" ;; -Darwin) +darwin) bsd="yes" darwin="yes" # Disable attempts to use ObjectiveC features in os/object.h since they # won't work when we're compiling with gcc as a C compiler. QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS" ;; -SunOS) +sunos) solaris="yes" make="${MAKE-gmake}" smbd="${SMBD-/usr/sfw/sbin/smbd}" @@ -665,11 +665,11 @@ SunOS) # needed for TIOCWIN* defines in termios.h QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS" ;; -Haiku) +haiku) pie="no" QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS" ;; -Linux) +linux) linux="yes" linux_user="yes" vhost_user=${default_feature:-yes} @@ -3334,8 +3334,8 @@ QEMU_GA_MSI_MINGW_DLL_PATH="$($pkg_config --variable=prefix glib-2.0)/bin" # Mac OS X ships with a broken assembler roms= if { test "$cpu" = "i386" || test "$cpu" = "x86_64"; } && \ - test "$targetos" != "Darwin" && test "$targetos" != "SunOS" && \ - test "$targetos" != "Haiku" && test "$softmmu" = yes ; then + test "$targetos" != "darwin" && test "$targetos" != "sunos" && \ + test "$targetos" != "haiku" && test "$softmmu" = yes ; then # Different host OS linkers have different ideas about the name of the ELF # emulation. Linux and OpenBSD/amd64 use 'elf_i386'; FreeBSD uses the _fbsd # variant; OpenBSD/i386 uses the _obsd variant; and Windows uses i386pe. @@ -3903,15 +3903,7 @@ if test "$skip_meson" = no; then if test "$cross_compile" = "yes"; then cross_arg="--cross-file config-meson.cross" echo "[host_machine]" >> $cross - if test "$mingw32" = "yes" ; then - echo "system = 'windows'" >> $cross - fi - if test "$linux" = "yes" ; then - echo "system = 'linux'" >> $cross - fi - if test "$darwin" = "yes" ; then - echo "system = 'darwin'" >> $cross - fi + echo "system = '$targetos'" >> $cross case "$ARCH" in i386) echo "cpu_family = 'x86'" >> $cross From 65eff01bcf920bcdbdb83dd0546005b522742c47 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 8 Nov 2021 22:52:35 +0100 Subject: [PATCH 02/16] configure: move target detection before CPU detection This makes more sense, since target detection can affect CPU detection on Solaris. Signed-off-by: Paolo Bonzini --- configure | 115 ++++++++++++++++++++++++++---------------------------- 1 file changed, 55 insertions(+), 60 deletions(-) diff --git a/configure b/configure index e72e34b684..f0a82dd8f5 100755 --- a/configure +++ b/configure @@ -527,16 +527,67 @@ else targetos=bogus fi -# Some host OSes need non-standard checks for which CPU to use. -# Note that these checks are broken for cross-compilation: if you're -# cross-compiling to one of these OSes then you'll need to specify -# the correct CPU with the --cpu option. +# OS specific + case $targetos in +windows) + mingw32="yes" + plugins="no" + pie="no" +;; +gnu/kfreebsd) + bsd="yes" +;; +freebsd) + bsd="yes" + bsd_user="yes" + make="${MAKE-gmake}" + # needed for kinfo_getvmmap(3) in libutil.h +;; +dragonfly) + bsd="yes" + make="${MAKE-gmake}" +;; +netbsd) + bsd="yes" + make="${MAKE-gmake}" +;; +openbsd) + bsd="yes" + make="${MAKE-gmake}" +;; +darwin) + bsd="yes" + darwin="yes" + # Disable attempts to use ObjectiveC features in os/object.h since they + # won't work when we're compiling with gcc as a C compiler. + QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS" +;; sunos) + solaris="yes" + make="${MAKE-gmake}" + smbd="${SMBD-/usr/sfw/sbin/smbd}" +# needed for CMSG_ macros in sys/socket.h + QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS" +# needed for TIOCWIN* defines in termios.h + QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS" # $(uname -m) returns i86pc even on an x86_64 box, so default based on isainfo + # Note that this check is broken for cross-compilation: if you're + # cross-compiling to one of these OSes then you'll need to specify + # the correct CPU with the --cpu option. if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then cpu="x86_64" fi +;; +haiku) + pie="no" + QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS" +;; +linux) + linux="yes" + linux_user="yes" + vhost_user=${default_feature:-yes} +;; esac if test ! -z "$cpu" ; then @@ -620,62 +671,6 @@ if test -z "$ARCH"; then ARCH="$cpu" fi -# OS specific - -case $targetos in -windows) - mingw32="yes" - plugins="no" - pie="no" -;; -gnu/kfreebsd) - bsd="yes" -;; -freebsd) - bsd="yes" - bsd_user="yes" - make="${MAKE-gmake}" - # needed for kinfo_getvmmap(3) in libutil.h -;; -dragonfly) - bsd="yes" - make="${MAKE-gmake}" -;; -netbsd) - bsd="yes" - make="${MAKE-gmake}" -;; -openbsd) - bsd="yes" - make="${MAKE-gmake}" -;; -darwin) - bsd="yes" - darwin="yes" - # Disable attempts to use ObjectiveC features in os/object.h since they - # won't work when we're compiling with gcc as a C compiler. - QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS" -;; -sunos) - solaris="yes" - make="${MAKE-gmake}" - smbd="${SMBD-/usr/sfw/sbin/smbd}" -# needed for CMSG_ macros in sys/socket.h - QEMU_CFLAGS="-D_XOPEN_SOURCE=600 $QEMU_CFLAGS" -# needed for TIOCWIN* defines in termios.h - QEMU_CFLAGS="-D__EXTENSIONS__ $QEMU_CFLAGS" -;; -haiku) - pie="no" - QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -D_BSD_SOURCE -fPIC $QEMU_CFLAGS" -;; -linux) - linux="yes" - linux_user="yes" - vhost_user=${default_feature:-yes} -;; -esac - : ${make=${MAKE-make}} # We prefer python 3.x. A bare 'python' is traditionally From e4da0e39dfce5366b22b3e28ec63d0470c1df550 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 9 Nov 2021 09:23:56 +0100 Subject: [PATCH 03/16] configure: unify two case statements on $cpu Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- configure | 67 ++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/configure b/configure index f0a82dd8f5..77ccc15b73 100755 --- a/configure +++ b/configure @@ -636,32 +636,47 @@ else fi ARCH= -# Normalise host CPU name and set ARCH. +# Normalise host CPU name, set ARCH and multilib cflags # Note that this case should only have supported host CPUs, not guests. case "$cpu" in - ppc|ppc64|s390x|sparc64|x32|riscv) - ;; - ppc64le) - ARCH="ppc64" - ;; + aarch64|riscv) ;; + armv*b|armv*l|arm) + cpu="arm" ;; + i386|i486|i586|i686|i86pc|BePC) cpu="i386" - ;; + CPU_CFLAGS="-m32" ;; + x32) + CPU_CFLAGS="-mx32" ;; x86_64|amd64) cpu="x86_64" - ;; - armv*b|armv*l|arm) - cpu="arm" - ;; - aarch64) - cpu="aarch64" - ;; + # ??? Only extremely old AMD cpus do not have cmpxchg16b. + # If we truly care, we should simply detect this case at + # runtime and generate the fallback to serial emulation. + CPU_CFLAGS="-m64 -mcx16" ;; + mips*) - cpu="mips" - ;; + cpu="mips" ;; + + ppc) + CPU_CFLAGS="-m32" ;; + ppc64) + CPU_CFLAGS="-m64" ;; + ppc64le) + ARCH="ppc64" ;; + + s390) + CPU_CFLAGS="-m31" + ARCH=unknown ;; + s390x) + CPU_CFLAGS="-m64" ;; + sparc|sun4[cdmuv]) cpu="sparc" - ;; + CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;; + sparc64) + CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;; + *) # This will result in either an error or falling back to TCI later ARCH=unknown @@ -1252,24 +1267,6 @@ local_statedir="${local_statedir:-$prefix/var}" firmwarepath="${firmwarepath:-$datadir/qemu-firmware}" localedir="${localedir:-$datadir/locale}" -case "$cpu" in - ppc) CPU_CFLAGS="-m32" ;; - ppc64) CPU_CFLAGS="-m64" ;; - sparc) CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;; - sparc64) CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;; - s390) CPU_CFLAGS="-m31" ;; - s390x) CPU_CFLAGS="-m64" ;; - i386) CPU_CFLAGS="-m32" ;; - x32) CPU_CFLAGS="-mx32" ;; - - # ??? Only extremely old AMD cpus do not have cmpxchg16b. - # If we truly care, we should simply detect this case at - # runtime and generate the fallback to serial emulation. - x86_64) CPU_CFLAGS="-m64 -mcx16" ;; - - # No special flags required for other host CPUs -esac - if eval test -z "\${cross_cc_$cpu}"; then eval "cross_cc_${cpu}=\$cc" cross_cc_vars="$cross_cc_vars cross_cc_${cpu}" From d8ff892dc23e9921db49d2053036240675bb50f8 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 9 Nov 2021 09:18:20 +0100 Subject: [PATCH 04/16] configure: unify ppc64 and ppc64le MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only difference between the two, as far as either configure or Meson are concerned, is the default endianness of the compiler. For tests/tcg, specify the endianness explicitly on the command line; for configure, do the same so that it is possible to have --cpu=ppc64le on a bigendian system or vice versa. Apart from this, cpu=ppc64le can be normalized to ppc64 also in configure and not just in the meson cross file. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- configure | 10 ++++------ tests/tcg/configure.sh | 4 +++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/configure b/configure index 77ccc15b73..85caf2e9ef 100755 --- a/configure +++ b/configure @@ -661,9 +661,10 @@ case "$cpu" in ppc) CPU_CFLAGS="-m32" ;; ppc64) - CPU_CFLAGS="-m64" ;; + CPU_CFLAGS="-m64 -mbig" ;; ppc64le) - ARCH="ppc64" ;; + cpu="ppc64" + CPU_CFLAGS="-m64 -mlittle" ;; s390) CPU_CFLAGS="-m31" @@ -3721,7 +3722,7 @@ if test "$linux" = "yes" ; then i386|x86_64|x32) linux_arch=x86 ;; - ppc|ppc64|ppc64le) + ppc|ppc64) linux_arch=powerpc ;; s390x) @@ -3903,9 +3904,6 @@ if test "$skip_meson" = no; then x86_64|x32) echo "cpu_family = 'x86_64'" >> $cross ;; - ppc64le) - echo "cpu_family = 'ppc64'" >> $cross - ;; *) echo "cpu_family = '$ARCH'" >> $cross ;; diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh index 9b76f58258..9ef913df5b 100755 --- a/tests/tcg/configure.sh +++ b/tests/tcg/configure.sh @@ -64,7 +64,9 @@ fi : ${cross_cc_ppc="powerpc-linux-gnu-gcc"} : ${cross_cc_cflags_ppc="-m32"} : ${cross_cc_ppc64="powerpc64-linux-gnu-gcc"} -: ${cross_cc_ppc64le="powerpc64le-linux-gnu-gcc"} +: ${cross_cc_cflags_ppc64="-m64 -mbig"} +: ${cross_cc_ppc64le="$cross_cc_ppc64"} +: ${cross_cc_cflags_ppc64le="-m64 -mlittle"} : ${cross_cc_riscv64="riscv64-linux-gnu-gcc"} : ${cross_cc_s390x="s390x-linux-gnu-gcc"} : ${cross_cc_sh4="sh4-linux-gnu-gcc"} From 4da270be1c4ac32c0e60a364e3173b57b1f79dba Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 9 Nov 2021 09:36:10 +0100 Subject: [PATCH 05/16] configure: unify x86_64 and x32 The only difference between the two, as far as either configure or Meson are concerned, is in the multilib flags passed to the compiler. For QEMU, this fixes the handling of TYPE_OLDDEVT in include/exec/user/thunk.h and enables testing of dirty ring buffer, because both are using HOST_X86_64. For tests/tcg, this means that on a hypothetical x32 host the cross compiler will not be used to build the tests. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- configure | 6 ++---- meson.build | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/configure b/configure index 85caf2e9ef..108b7621e2 100755 --- a/configure +++ b/configure @@ -647,6 +647,7 @@ case "$cpu" in cpu="i386" CPU_CFLAGS="-m32" ;; x32) + cpu="x86_64" CPU_CFLAGS="-mx32" ;; x86_64|amd64) cpu="x86_64" @@ -3719,7 +3720,7 @@ fi if test "$linux" = "yes" ; then mkdir -p linux-headers case "$cpu" in - i386|x86_64|x32) + i386|x86_64) linux_arch=x86 ;; ppc|ppc64) @@ -3901,9 +3902,6 @@ if test "$skip_meson" = no; then i386) echo "cpu_family = 'x86'" >> $cross ;; - x86_64|x32) - echo "cpu_family = 'x86_64'" >> $cross - ;; *) echo "cpu_family = '$ARCH'" >> $cross ;; diff --git a/meson.build b/meson.build index ae67ca28ab..69cca2aa9f 100644 --- a/meson.build +++ b/meson.build @@ -355,7 +355,7 @@ if not get_option('tcg').disabled() tcg_arch = 'tci' elif config_host['ARCH'] == 'sparc64' tcg_arch = 'sparc' - elif config_host['ARCH'] in ['x86_64', 'x32'] + elif config_host['ARCH'] == 'x86_64' tcg_arch = 'i386' elif config_host['ARCH'] == 'ppc64' tcg_arch = 'ppc' @@ -1806,7 +1806,6 @@ disassemblers = { 'hppa' : ['CONFIG_HPPA_DIS'], 'i386' : ['CONFIG_I386_DIS'], 'x86_64' : ['CONFIG_I386_DIS'], - 'x32' : ['CONFIG_I386_DIS'], 'm68k' : ['CONFIG_M68K_DIS'], 'microblaze' : ['CONFIG_MICROBLAZE_DIS'], 'mips' : ['CONFIG_MIPS_DIS'], From ffb91f68b1c13a1cc36124350eacfe14095d5e1e Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 8 Nov 2021 15:44:39 +0100 Subject: [PATCH 06/16] meson: rename "arch" variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid confusion between the ARCH variable of configure/config-host.mak and the same-named variable of meson.build. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- meson.build | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index 69cca2aa9f..4fdaa65b05 100644 --- a/meson.build +++ b/meson.build @@ -2850,7 +2850,7 @@ emulators = {} foreach target : target_dirs config_target = config_target_mak[target] target_name = config_target['TARGET_NAME'] - arch = config_target['TARGET_BASE_ARCH'] + target_base_arch = config_target['TARGET_BASE_ARCH'] arch_srcs = [config_target_h[target]] arch_deps = [] c_args = ['-DNEED_CPU_H', @@ -2866,11 +2866,11 @@ foreach target : target_dirs if target.endswith('-softmmu') qemu_target_name = 'qemu-system-' + target_name target_type='system' - t = target_softmmu_arch[arch].apply(config_target, strict: false) + t = target_softmmu_arch[target_base_arch].apply(config_target, strict: false) arch_srcs += t.sources() arch_deps += t.dependencies() - hw_dir = target_name == 'sparc64' ? 'sparc64' : arch + hw_dir = target_name == 'sparc64' ? 'sparc64' : target_base_arch hw = hw_arch[hw_dir].apply(config_target, strict: false) arch_srcs += hw.sources() arch_deps += hw.dependencies() @@ -2881,8 +2881,8 @@ foreach target : target_dirs abi = config_target['TARGET_ABI_DIR'] target_type='user' qemu_target_name = 'qemu-' + target_name - if arch in target_user_arch - t = target_user_arch[arch].apply(config_target, strict: false) + if target_base_arch in target_user_arch + t = target_user_arch[target_base_arch].apply(config_target, strict: false) arch_srcs += t.sources() arch_deps += t.dependencies() endif @@ -2920,7 +2920,7 @@ foreach target : target_dirs arch_srcs += gdbstub_xml endif - t = target_arch[arch].apply(config_target, strict: false) + t = target_arch[target_base_arch].apply(config_target, strict: false) arch_srcs += t.sources() arch_deps += t.dependencies() From 823eb013452e93d34fc0630fea98717d7d8f240a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 8 Nov 2021 14:18:17 +0100 Subject: [PATCH 07/16] configure, meson: move ARCH to meson.build $ARCH and the HOST_* symbols are only used by the QEMU build; configure uses $cpu instead. Remove it from config-host.mak. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- configure | 21 ++++----------------- meson.build | 26 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/configure b/configure index 108b7621e2..6e06ac6161 100755 --- a/configure +++ b/configure @@ -635,11 +635,9 @@ else cpu=$(uname -m) fi -ARCH= -# Normalise host CPU name, set ARCH and multilib cflags +# Normalise host CPU name, set multilib cflags # Note that this case should only have supported host CPUs, not guests. case "$cpu" in - aarch64|riscv) ;; armv*b|armv*l|arm) cpu="arm" ;; @@ -668,8 +666,7 @@ case "$cpu" in CPU_CFLAGS="-m64 -mlittle" ;; s390) - CPU_CFLAGS="-m31" - ARCH=unknown ;; + CPU_CFLAGS="-m31" ;; s390x) CPU_CFLAGS="-m64" ;; @@ -678,15 +675,7 @@ case "$cpu" in CPU_CFLAGS="-m32 -mv8plus -mcpu=ultrasparc" ;; sparc64) CPU_CFLAGS="-m64 -mcpu=ultrasparc" ;; - - *) - # This will result in either an error or falling back to TCI later - ARCH=unknown - ;; esac -if test -z "$ARCH"; then - ARCH="$cpu" -fi : ${make=${MAKE-make}} @@ -3406,8 +3395,6 @@ echo "GIT=$git" >> $config_host_mak echo "GIT_SUBMODULES=$git_submodules" >> $config_host_mak echo "GIT_SUBMODULES_ACTION=$git_submodules_action" >> $config_host_mak -echo "ARCH=$ARCH" >> $config_host_mak - if test "$debug_tcg" = "yes" ; then echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak fi @@ -3898,12 +3885,12 @@ if test "$skip_meson" = no; then cross_arg="--cross-file config-meson.cross" echo "[host_machine]" >> $cross echo "system = '$targetos'" >> $cross - case "$ARCH" in + case "$cpu" in i386) echo "cpu_family = 'x86'" >> $cross ;; *) - echo "cpu_family = '$ARCH'" >> $cross + echo "cpu_family = '$cpu'" >> $cross ;; esac echo "cpu = '$cpu'" >> $cross diff --git a/meson.build b/meson.build index 4fdaa65b05..2495360fd0 100644 --- a/meson.build +++ b/meson.build @@ -67,6 +67,14 @@ endif targetos = host_machine.system() +if cpu not in supported_cpus + host_arch = 'unknown' +elif cpu == 'x86' + host_arch = 'i386' +else + host_arch = cpu +endif + if cpu in ['x86', 'x86_64'] kvm_targets = ['i386-softmmu', 'x86_64-softmmu'] elif cpu == 'aarch64' @@ -335,9 +343,9 @@ if targetos == 'netbsd' endif endif -tcg_arch = config_host['ARCH'] +tcg_arch = host_arch if not get_option('tcg').disabled() - if cpu not in supported_cpus + if host_arch == 'unknown' if get_option('tcg_interpreter') warning('Unsupported CPU @0@, will use TCG with TCI (slow)'.format(cpu)) else @@ -353,11 +361,11 @@ if not get_option('tcg').disabled() endif if get_option('tcg_interpreter') tcg_arch = 'tci' - elif config_host['ARCH'] == 'sparc64' + elif host_arch == 'sparc64' tcg_arch = 'sparc' - elif config_host['ARCH'] == 'x86_64' + elif host_arch == 'x86_64' tcg_arch = 'i386' - elif config_host['ARCH'] == 'ppc64' + elif host_arch == 'ppc64' tcg_arch = 'ppc' endif add_project_arguments('-iquote', meson.current_source_dir() / 'tcg' / tcg_arch, @@ -1426,6 +1434,8 @@ config_host_data.set_quoted('CONFIG_QEMU_LOCALSTATEDIR', get_option('prefix') / config_host_data.set_quoted('CONFIG_QEMU_MODDIR', get_option('prefix') / qemu_moddir) config_host_data.set_quoted('CONFIG_SYSCONFDIR', get_option('prefix') / get_option('sysconfdir')) +config_host_data.set('HOST_' + host_arch.to_upper(), 1) + config_host_data.set('CONFIG_ATTR', libattr.found()) config_host_data.set('CONFIG_BRLAPI', brlapi.found()) config_host_data.set('CONFIG_COCOA', cocoa.found()) @@ -1775,8 +1785,6 @@ foreach k, v: config_host v = '"' + '", "'.join(v.split()) + '", ' endif config_host_data.set(k, v) - elif k == 'ARCH' - config_host_data.set('HOST_' + v.to_upper(), 1) elif strings.contains(k) config_host_data.set_quoted(k, v) elif k.startswith('CONFIG_') @@ -1919,7 +1927,7 @@ foreach target : target_dirs endif foreach k, v: disassemblers - if config_host['ARCH'].startswith(k) or config_target['TARGET_BASE_ARCH'].startswith(k) + if host_arch.startswith(k) or config_target['TARGET_BASE_ARCH'].startswith(k) foreach sym: v config_target += { sym: 'y' } config_all_disas += { sym: 'y' } @@ -2888,7 +2896,7 @@ foreach target : target_dirs endif if 'CONFIG_LINUX_USER' in config_target base_dir = 'linux-user' - target_inc += include_directories('linux-user/host/' / config_host['ARCH']) + target_inc += include_directories('linux-user/host/' / host_arch) endif if 'CONFIG_BSD_USER' in config_target base_dir = 'bsd-user' From 0f457147f41bd7cbb7fd1193b057af9226a2184a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 8 Nov 2021 10:45:30 +0100 Subject: [PATCH 08/16] configure: remove unnecessary symlinks Make pc-bios/meson.build use the files in the source tree as inputs to bzip2. Reviewed-by: Richard Henderson Signed-off-by: Paolo Bonzini --- configure | 1 - pc-bios/meson.build | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/configure b/configure index 6e06ac6161..ba85bbb54b 100755 --- a/configure +++ b/configure @@ -3801,7 +3801,6 @@ for bios_file in \ $source_path/pc-bios/*.img \ $source_path/pc-bios/openbios-* \ $source_path/pc-bios/u-boot.* \ - $source_path/pc-bios/edk2-*.fd.bz2 \ $source_path/pc-bios/palcode-* \ $source_path/pc-bios/qemu_vga.ndrv diff --git a/pc-bios/meson.build b/pc-bios/meson.build index b40ff3f2bd..1812a4084f 100644 --- a/pc-bios/meson.build +++ b/pc-bios/meson.build @@ -15,7 +15,7 @@ if unpack_edk2_blobs roms += custom_target(f, build_by_default: have_system, output: f, - input: '@0@.bz2'.format(f), + input: files('@0@.bz2'.format(f)), capture: true, install: get_option('install_blobs'), install_dir: qemu_datadir, From 5dce7b8d8ce6f397a2f2e46c236cc102d4e7a585 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Oct 2021 13:56:24 +0200 Subject: [PATCH 09/16] configure: remove DIRS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DIRS is used to create the directory in which the LINKS symbolic links reside, or to create directories for object files. The former can be done directly in the symlinking loop, while the latter is done by Meson already, so DIRS is not necessary. Reviewed-by: Peter Maydell Reviewed-by: Alex Bennée Tested-by: Alex Bennée Signed-off-by: Paolo Bonzini --- configure | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/configure b/configure index ba85bbb54b..8ccfe51673 100755 --- a/configure +++ b/configure @@ -3762,7 +3762,6 @@ if test "$safe_stack" = "yes"; then fi # If we're using a separate build tree, set it up now. -# DIRS are directories which we simply mkdir in the build tree; # LINKS are things to symlink back into the source tree # (these can be both files and directories). # Caution: do not add files or directories here using wildcards. This @@ -3774,12 +3773,6 @@ fi # UNLINK is used to remove symlinks from older development versions # that might get into the way when doing "git update" without doing # a "make distclean" in between. -DIRS="tests tests/tcg tests/qapi-schema tests/qtest/libqos" -DIRS="$DIRS tests/qtest tests/qemu-iotests tests/vm tests/fp tests/qgraph" -DIRS="$DIRS docs docs/interop fsdev scsi" -DIRS="$DIRS pc-bios/optionrom pc-bios/s390-ccw" -DIRS="$DIRS roms/seabios" -DIRS="$DIRS contrib/plugins/" LINKS="Makefile" LINKS="$LINKS tests/tcg/Makefile.target" LINKS="$LINKS pc-bios/optionrom/Makefile" @@ -3807,9 +3800,9 @@ for bios_file in \ do LINKS="$LINKS pc-bios/$(basename $bios_file)" done -mkdir -p $DIRS for f in $LINKS ; do if [ -e "$source_path/$f" ]; then + mkdir -p `dirname ./$f` symlink "$source_path/$f" "$f" fi done From 7a82413dbd8275303e4df9822c213bca15c34e86 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 13 Oct 2021 11:39:05 +0200 Subject: [PATCH 10/16] meson: reenable test-fdmon-epoll The test was disabled when CONFIG_EPOLL_CREATE1 was moved out of config-host.mak. Fix the condition. Signed-off-by: Paolo Bonzini --- tests/unit/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/meson.build b/tests/unit/meson.build index acac3622ed..90acf5b0da 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -112,7 +112,7 @@ if have_block if nettle.found() or gcrypt.found() tests += {'test-crypto-pbkdf': [io]} endif - if 'CONFIG_EPOLL_CREATE1' in config_host + if config_host_data.get('CONFIG_EPOLL_CREATE1') tests += {'test-fdmon-epoll': [testblock]} endif endif From ad5439bb537a296814e40947dec51f1f96078bec Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 8 Oct 2021 13:33:08 +0200 Subject: [PATCH 11/16] cpu: remove unnecessary #ifdef CONFIG_TCG "if (tcg_enabled())" allows elision of the code inside it; we only need the prototype to exist, so that the code compile even for the --disable-tcg case. Signed-off-by: Paolo Bonzini --- cpu.c | 5 ----- include/exec/cpu-all.h | 2 -- 2 files changed, 7 deletions(-) diff --git a/cpu.c b/cpu.c index 9bce67ef55..945dd3dded 100644 --- a/cpu.c +++ b/cpu.c @@ -137,12 +137,10 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) if (!accel_cpu_realizefn(cpu, errp)) { return; } -#ifdef CONFIG_TCG /* NB: errp parameter is unused currently */ if (tcg_enabled()) { tcg_exec_realizefn(cpu, errp); } -#endif /* CONFIG_TCG */ #ifdef CONFIG_USER_ONLY assert(qdev_get_vmsd(DEVICE(cpu)) == NULL || @@ -169,12 +167,9 @@ void cpu_exec_unrealizefn(CPUState *cpu) vmstate_unregister(NULL, &vmstate_cpu_common, cpu); } #endif -#ifdef CONFIG_TCG - /* NB: errp parameter is unused currently */ if (tcg_enabled()) { tcg_exec_unrealizefn(cpu); } -#endif /* CONFIG_TCG */ cpu_list_remove(cpu); } diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 3c8e24292b..bb37239efa 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -437,12 +437,10 @@ void dump_opcount_info(GString *buf); #endif /* !CONFIG_USER_ONLY */ -#ifdef CONFIG_TCG /* accel/tcg/cpu-exec.c */ int cpu_exec(CPUState *cpu); void tcg_exec_realizefn(CPUState *cpu, Error **errp); void tcg_exec_unrealizefn(CPUState *cpu); -#endif /* CONFIG_TCG */ /* Returns: 0 on success, -1 on error */ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, From b20a7ee6f0771b3ec7de9a4c7c7b0e5890b70f3e Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 17 Dec 2021 09:52:03 +0100 Subject: [PATCH 12/16] meson: add "check" argument to run_command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Meson is planning to change the default of the "check" argument to run_command (from false to true). Be explicit and include it in all invocations. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Paolo Bonzini --- docs/meson.build | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/meson.build b/docs/meson.build index 27c6e156ff..57b28a3146 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -18,12 +18,12 @@ if sphinx_build.found() # This is a bit awkward but works: create a trivial document and # try to run it with our configuration file (which enforces a # version requirement). This will fail if sphinx-build is too old. - run_command('mkdir', ['-p', tmpdir / 'sphinx']) - run_command('touch', [tmpdir / 'sphinx/index.rst']) + run_command('mkdir', ['-p', tmpdir / 'sphinx'], check: true) + run_command('touch', [tmpdir / 'sphinx/index.rst'], check: true) sphinx_build_test_out = run_command(SPHINX_ARGS + [ '-c', meson.current_source_dir(), '-b', 'html', tmpdir / 'sphinx', - tmpdir / 'sphinx/out']) + tmpdir / 'sphinx/out'], check: false) build_docs = (sphinx_build_test_out.returncode() == 0) if not build_docs From 7a3ce79c062117501e89a10a7768051b8b52d562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 22 Nov 2021 11:47:44 +0100 Subject: [PATCH 13/16] hw/scsi: Fix scsi_bus_init_named() docstring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 739e95f5741 ("scsi: Replace scsi_bus_new() with scsi_bus_init(), scsi_bus_init_named()") forgot to rename scsi_bus_init() in the function documentation string. Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20211122104744.1051554-1-f4bug@amsat.org> Reviewed-by: Peter Maydell Signed-off-by: Paolo Bonzini --- include/hw/scsi/scsi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index a567a5ed86..2ef80af6dc 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -158,7 +158,7 @@ struct SCSIBus { * provided by the caller. It is the caller's responsibility to make * sure that name does not clash with the name of any other bus in the * system. Unless you need the new bus to have a specific name, you - * should use scsi_bus_new() instead. + * should use scsi_bus_init() instead. */ void scsi_bus_init_named(SCSIBus *bus, size_t bus_size, DeviceState *host, const SCSIBusInfo *info, const char *bus_name); From 97a2b074d150918a7a3a4065b946a52d4d0be8a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 19 Nov 2021 21:11:40 +0100 Subject: [PATCH 14/16] hw/scsi/megasas: Fails command if SGL buffer overflows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we detect an overflow on the SGL buffer, do not keep processing the command: discard it. TARGET_FAILURE sense code will be returned (MFI_STAT_SCSI_DONE_WITH_ERROR). Reported-by: Alexander Bulekov Resolves: https://gitlab.com/qemu-project/qemu/-/issues/521 Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Darren Kenny Message-Id: <20211119201141.532377-2-philmd@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/megasas.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index 4ff51221d4..8f35784100 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -303,6 +303,7 @@ static int megasas_map_sgl(MegasasState *s, MegasasCmd *cmd, union mfi_sgl *sgl) } if (cmd->iov_size > iov_size) { trace_megasas_iovec_overflow(cmd->index, iov_size, cmd->iov_size); + goto unmap; } else if (cmd->iov_size < iov_size) { trace_megasas_iovec_underflow(cmd->index, iov_size, cmd->iov_size); } From 08c34c642dbcb5f7d9d94b07b471f80e333541cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Fri, 19 Nov 2021 21:11:41 +0100 Subject: [PATCH 15/16] tests/qtest/fuzz-megasas-test: Add test for GitLab issue #521 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without the previous commit, this test triggers: $ make check-qtest-x86_64 [...] Running test qtest-x86_64/fuzz-megasas-test qemu-system-x86_64: softmmu/physmem.c:3229: address_space_unmap: Assertion `mr != NULL' failed. Broken pipe ERROR qtest-x86_64/fuzz-megasas-test - too few tests run (expected 2, got 1) Suggested-by: Alexander Bulekov Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Darren Kenny Message-Id: <20211119201141.532377-3-philmd@redhat.com> Signed-off-by: Paolo Bonzini --- tests/qtest/fuzz-megasas-test.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/qtest/fuzz-megasas-test.c b/tests/qtest/fuzz-megasas-test.c index 940a76bf25..e1141c58a4 100644 --- a/tests/qtest/fuzz-megasas-test.c +++ b/tests/qtest/fuzz-megasas-test.c @@ -34,6 +34,34 @@ static void test_lp1878263_megasas_zero_iov_cnt(void) qtest_quit(s); } +/* + * Overflow SGL buffer. + * https://gitlab.com/qemu-project/qemu/-/issues/521 + */ +static void test_gitlab_issue521_megasas_sgl_ovf(void) +{ + QTestState *s = qtest_init("-display none -m 32M -machine q35 " + "-nodefaults -device megasas " + "-device scsi-cd,drive=null0 " + "-blockdev " + "driver=null-co,read-zeroes=on,node-name=null0"); + qtest_outl(s, 0xcf8, 0x80000818); + qtest_outl(s, 0xcfc, 0xc000); + qtest_outl(s, 0xcf8, 0x80000804); + qtest_outw(s, 0xcfc, 0x05); + qtest_bufwrite(s, 0x0, "\x01", 0x1); + qtest_bufwrite(s, 0x7, "\x01", 0x1); + qtest_bufwrite(s, 0x10, "\x02", 0x1); + qtest_bufwrite(s, 0x16, "\x01", 0x1); + qtest_bufwrite(s, 0x28, "\x01", 0x1); + qtest_bufwrite(s, 0x33, "\x01", 0x1); + qtest_outb(s, 0xc040, 0x0); + qtest_outb(s, 0xc040, 0x20); + qtest_outl(s, 0xc040, 0x20000000); + qtest_outb(s, 0xc040, 0x20); + qtest_quit(s); +} + int main(int argc, char **argv) { const char *arch = qtest_get_arch(); @@ -43,6 +71,8 @@ int main(int argc, char **argv) if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { qtest_add_func("fuzz/test_lp1878263_megasas_zero_iov_cnt", test_lp1878263_megasas_zero_iov_cnt); + qtest_add_func("fuzz/gitlab_issue521_megasas_sgl_ovf", + test_gitlab_issue521_megasas_sgl_ovf); } return g_test_run(); From 5a3a2eb3b1096a52580c1b8c3eb0739714e7d941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Wed, 1 Dec 2021 23:32:53 +0100 Subject: [PATCH 16/16] hw/i386/vmmouse: Require 'i8042' property to be set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the 'i8042' property is not set, mouse events handled by vmmouse_mouse_event() end calling i8042_isa_mouse_fake_event() with a NULL argument, resulting in ps2_mouse_fake_event() being called with invalid PS2MouseState pointer. Fix by requiring the 'i8042' property to be always set: $ qemu-system-x86_64 -device vmmouse qemu-system-x86_64: -device vmmouse: 'i8042' link is not set Fixes: 91c9e09147b ("vmmouse: convert to qdev") Reported-by: Calvin Buckley Resolves: https://gitlab.com/qemu-project/qemu/-/issues/752 Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20211201223253.36080-1-f4bug@amsat.org> Signed-off-by: Paolo Bonzini --- hw/i386/vmmouse.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/i386/vmmouse.c b/hw/i386/vmmouse.c index 3d66368286..a56c185f15 100644 --- a/hw/i386/vmmouse.c +++ b/hw/i386/vmmouse.c @@ -286,6 +286,10 @@ static void vmmouse_realizefn(DeviceState *dev, Error **errp) DPRINTF("vmmouse_init\n"); + if (!s->i8042) { + error_setg(errp, "'i8042' link is not set"); + return; + } if (!object_resolve_path_type("", TYPE_VMPORT, NULL)) { error_setg(errp, "vmmouse needs a machine with vmport"); return;