From: Peter Maydell Date: Fri, 20 Dec 2019 18:25:32 +0000 (+0000) Subject: Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging X-Git-Tag: v5.0.0-rc3~211 X-Git-Url: https://git.proxmox.com/?p=mirror_qemu.git;a=commitdiff_plain;h=1010af540b8bdd54ba05cf5567fd85aafa76dd7d;hp=f62f08ab7a9d902da70078992248ec5c98f652ad Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging Block layer patches: - qemu-img: fix info --backing-chain --image-opts - Error out on image creation with conflicting size options - Fix external snapshot with VM state - hmp: Allow using qdev ID for qemu-io command - Misc code cleanup - Many iotests improvements # gpg: Signature made Thu 19 Dec 2019 17:23:11 GMT # gpg: using RSA key 7F09B272C88F2FD6 # gpg: Good signature from "Kevin Wolf " [full] # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6 * remotes/kevin/tags/for-upstream: (30 commits) iotests: Test external snapshot with VM state hmp: Allow using qdev ID for qemu-io command block: Activate recursively even for already active nodes iotests: 211: Remove duplication with VM.blockdev_create() iotests: 207: Remove duplication with VM.blockdev_create() iotests: 266: Convert to VM.blockdev_create() iotests: 237: Convert to VM.blockdev_create() iotests: 213: Convert to VM.blockdev_create() iotests: 212: Convert to VM.blockdev_create() iotests: 210: Convert to VM.blockdev_create() iotests: 206: Convert to VM.blockdev_create() iotests: 255: Drop blockdev_create() iotests: Create VM.blockdev_create() qcow2: Move error check of local_err near its assignment iotests: Fix IMGOPTSSYNTAX for nbd iotests/273: Filter format-specific information iotests: Add more "_require_drivers" checks to the shell-based tests MAINTAINERS: fix qcow2-bitmap.c under Dirty Bitmaps header qcow2: Use offset_into_cluster() iotests: Support job-complete in run_job() ... Signed-off-by: Peter Maydell --- diff --git a/.cirrus.yml b/.cirrus.yml index 27efc48619..90645fede6 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -22,7 +22,9 @@ macos_task: install_script: - brew install pkg-config python gnu-sed glib pixman make sdl2 script: - - ./configure --python=/usr/local/bin/python3 || { cat config.log; exit 1; } + - mkdir build + - cd build + - ../configure --python=/usr/local/bin/python3 || { cat config.log; exit 1; } - gmake -j$(sysctl -n hw.ncpu) - gmake check -j$(sysctl -n hw.ncpu) @@ -33,6 +35,8 @@ macos_xcode_task: install_script: - brew install pkg-config gnu-sed glib pixman make sdl2 script: - - ./configure --cc=clang || { cat config.log; exit 1; } + - mkdir build + - cd build + - ../configure --cc=clang || { cat config.log; exit 1; } - gmake -j$(sysctl -n hw.ncpu) - gmake check -j$(sysctl -n hw.ncpu) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e3db1b847c..ebcef0ebe9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,7 +6,9 @@ build-system1: script: - apt-get install -y -qq libgtk-3-dev libvte-dev nettle-dev libcacard-dev libusb-dev libvde-dev libspice-protocol-dev libgl1-mesa-dev libvdeplug-dev - - ./configure --enable-werror --target-list="aarch64-softmmu alpha-softmmu + - mkdir build + - cd build + - ../configure --enable-werror --target-list="aarch64-softmmu alpha-softmmu cris-softmmu hppa-softmmu lm32-softmmu moxie-softmmu microblazeel-softmmu mips64el-softmmu m68k-softmmu ppc-softmmu riscv64-softmmu sparc-softmmu" - make -j2 @@ -16,7 +18,9 @@ build-system2: script: - apt-get install -y -qq libsdl2-dev libgcrypt-dev libbrlapi-dev libaio-dev libfdt-dev liblzo2-dev librdmacm-dev libibverbs-dev libibumad-dev - - ./configure --enable-werror --target-list="tricore-softmmu unicore32-softmmu + - mkdir build + - cd build + - ../configure --enable-werror --target-list="tricore-softmmu unicore32-softmmu microblaze-softmmu mips-softmmu riscv32-softmmu s390x-softmmu sh4-softmmu sparc64-softmmu x86_64-softmmu xtensa-softmmu nios2-softmmu or1k-softmmu" - make -j2 @@ -24,7 +28,9 @@ build-system2: build-disabled: script: - - ./configure --enable-werror --disable-rdma --disable-slirp --disable-curl + - mkdir build + - cd build + - ../configure --enable-werror --disable-rdma --disable-slirp --disable-curl --disable-capstone --disable-live-block-migration --disable-glusterfs --disable-replication --disable-coroutine-pool --disable-smartcard --disable-guest-agent --disable-curses --disable-libxml2 --disable-tpm @@ -37,7 +43,9 @@ build-disabled: build-tcg-disabled: script: - apt-get install -y -qq clang libgtk-3-dev libusb-dev - - ./configure --cc=clang --enable-werror --disable-tcg --audio-drv-list="" + - mkdir build + - cd build + - ../configure --cc=clang --enable-werror --disable-tcg --audio-drv-list="" - make -j2 - make check-unit - make check-qapi-schema @@ -52,7 +60,9 @@ build-tcg-disabled: build-user: script: - - ./configure --enable-werror --disable-system --disable-guest-agent + - mkdir build + - cd build + - ../configure --enable-werror --disable-system --disable-guest-agent --disable-capstone --disable-slirp --disable-fdt - make -j2 - make run-tcg-tests-i386-linux-user run-tcg-tests-x86_64-linux-user @@ -61,7 +71,9 @@ build-clang: script: - apt-get install -y -qq clang libsdl2-dev libattr1-dev libcap-ng-dev xfslibs-dev libiscsi-dev libnfs-dev libseccomp-dev gnutls-dev librbd-dev - - ./configure --cc=clang --cxx=clang++ --enable-werror + - mkdir build + - cd build + - ../configure --cc=clang --cxx=clang++ --enable-werror --target-list="alpha-softmmu arm-softmmu m68k-softmmu mips64-softmmu ppc-softmmu s390x-softmmu x86_64-softmmu arm-linux-user" - make -j2 @@ -70,7 +82,9 @@ build-clang: build-tci: script: - TARGETS="aarch64 alpha arm hppa m68k microblaze moxie ppc64 s390x x86_64" - - ./configure --enable-tcg-interpreter + - mkdir build + - cd build + - ../configure --enable-tcg-interpreter --target-list="$(for tg in $TARGETS; do echo -n ${tg}'-softmmu '; done)" - make -j2 - make tests/boot-serial-test tests/cdrom-test tests/pxe-test diff --git a/.shippable.yml b/.shippable.yml index f74a3de3ff..83aae08bb4 100644 --- a/.shippable.yml +++ b/.shippable.yml @@ -35,5 +35,7 @@ build: options: "-e HOME=/root" ci: - unset CC - - ./configure ${QEMU_CONFIGURE_OPTS} --target-list=${TARGET_LIST} + - mkdir build + - cd build + - ../configure ${QEMU_CONFIGURE_OPTS} --target-list=${TARGET_LIST} - make -j$(($(getconf _NPROCESSORS_ONLN) + 1)) diff --git a/.travis.yml b/.travis.yml index 6cb8af6fa5..376b7d6dfa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -73,8 +73,8 @@ notifications: env: global: - - SRC_DIR="." - - BUILD_DIR="." + - SRC_DIR=".." + - BUILD_DIR="build" - BASE_CONFIG="--disable-docs --disable-tools" - TEST_CMD="make check V=1" # This is broadly a list of "mainline" softmmu targets which have support across the major distros @@ -180,18 +180,13 @@ matrix: compiler: clang - - env: - - CONFIG="--disable-user --target-list=${MAIN_SOFTMMU_TARGETS}" - - CACHE_NAME="${TRAVIS_BRANCH}-linux-clang-default" - compiler: clang - - - env: - CONFIG="--target-list=${MAIN_SOFTMMU_TARGETS} " - CACHE_NAME="${TRAVIS_BRANCH}-linux-clang-sanitize" compiler: clang before_script: - - ./configure ${CONFIG} --extra-cflags="-fsanitize=undefined -Werror" || { cat config.log && exit 1; } + - mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} + - ${SRC_DIR}/configure ${CONFIG} --extra-cflags="-fsanitize=undefined -Werror" || { cat config.log && exit 1; } - env: @@ -214,10 +209,11 @@ matrix: - TEST_CMD="" - # We manually include builds which we disable "make check" for + # Check the TCG interpreter (TCI) - env: - - CONFIG="--enable-debug --enable-tcg-interpreter" - - TEST_CMD="" + - CONFIG="--enable-debug-tcg --enable-tcg-interpreter --disable-kvm --disable-containers + --target-list=alpha-softmmu,arm-softmmu,hppa-softmmu,m68k-softmmu,microblaze-softmmu,moxie-softmmu,ppc-softmmu,s390x-softmmu,x86_64-softmmu" + - TEST_CMD="make check-qtest check-tcg V=1" # We don't need to exercise every backend with every front-end @@ -322,7 +318,8 @@ matrix: - CONFIG="--cc=gcc-9 --cxx=g++-9 --disable-pie --disable-linux-user" - TEST_CMD="" before_script: - - ./configure ${CONFIG} --extra-cflags="-g3 -O0 -Wno-error=stringop-truncation -fsanitize=thread -fuse-ld=gold" || { cat config.log && exit 1; } + - mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} + - ${SRC_DIR}/configure ${CONFIG} --extra-cflags="-g3 -O0 -Wno-error=stringop-truncation -fsanitize=thread -fuse-ld=gold" || { cat config.log && exit 1; } # Run check-tcg against linux-user @@ -353,6 +350,92 @@ matrix: - TEST_CMD="make -j3 check-tcg V=1" - CACHE_NAME="${TRAVIS_BRANCH}-linux-gcc-debug-tcg" + - arch: arm64 + dist: xenial + addons: + apt_packages: + - libaio-dev + - libattr1-dev + - libbrlapi-dev + - libcap-ng-dev + - libgcrypt20-dev + - libgnutls28-dev + - libgtk-3-dev + - libiscsi-dev + - liblttng-ust-dev + - libncurses5-dev + - libnfs-dev + - libnss3-dev + - libpixman-1-dev + - libpng-dev + - librados-dev + - libsdl2-dev + - libseccomp-dev + - liburcu-dev + - libusb-1.0-0-dev + - libvdeplug-dev + - libvte-2.91-dev + env: + - TEST_CMD="make check check-tcg V=1" + - CONFIG="--disable-containers --target-list=${MAIN_SOFTMMU_TARGETS}" + + - arch: ppc64le + dist: xenial + addons: + apt_packages: + - libaio-dev + - libattr1-dev + - libbrlapi-dev + - libcap-ng-dev + - libgcrypt20-dev + - libgnutls28-dev + - libgtk-3-dev + - libiscsi-dev + - liblttng-ust-dev + - libncurses5-dev + - libnfs-dev + - libnss3-dev + - libpixman-1-dev + - libpng-dev + - librados-dev + - libsdl2-dev + - libseccomp-dev + - liburcu-dev + - libusb-1.0-0-dev + - libvdeplug-dev + - libvte-2.91-dev + env: + - TEST_CMD="make check check-tcg V=1" + - CONFIG="--disable-containers --target-list=${MAIN_SOFTMMU_TARGETS},ppc64le-linux-user" + + - arch: s390x + dist: bionic + addons: + apt_packages: + - libaio-dev + - libattr1-dev + - libbrlapi-dev + - libcap-ng-dev + - libgcrypt20-dev + - libgnutls28-dev + - libgtk-3-dev + - libiscsi-dev + - liblttng-ust-dev + - libncurses5-dev + - libnfs-dev + - libnss3-dev + - libpixman-1-dev + - libpng-dev + - librados-dev + - libsdl2-dev + - libseccomp-dev + - liburcu-dev + - libusb-1.0-0-dev + - libvdeplug-dev + - libvte-2.91-dev + env: + - TEST_CMD="make check check-tcg V=1" + - CONFIG="--disable-containers --target-list=${MAIN_SOFTMMU_TARGETS},s390x-linux-user" # Release builds # The make-release script expect a QEMU version, so our tag must start with a 'v'. @@ -373,5 +456,6 @@ matrix: - make -C ${SRC_DIR} qemu-${QEMU_VERSION}.tar.bz2 - ls -l ${SRC_DIR}/qemu-${QEMU_VERSION}.tar.bz2 - tar -xf ${SRC_DIR}/qemu-${QEMU_VERSION}.tar.bz2 && cd qemu-${QEMU_VERSION} - - ./configure ${BASE_CONFIG} ${CONFIG} || { cat config.log && exit 1; } + - mkdir -p release-build && cd release-build + - ../configure ${BASE_CONFIG} ${CONFIG} || { cat config.log && exit 1; } - make install diff --git a/Kconfig.host b/Kconfig.host index bb6e116e2a..55136e037d 100644 --- a/Kconfig.host +++ b/Kconfig.host @@ -25,6 +25,11 @@ config TPM config VHOST_USER bool + select VHOST + +config VHOST_KERNEL + bool + select VHOST config XEN bool diff --git a/MAINTAINERS b/MAINTAINERS index dc81c89ccb..8571327881 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -420,6 +420,7 @@ F: hw/block/dataplane/xen* F: hw/xen/ F: hw/xenpv/ F: hw/i386/xen/ +F: hw/pci-host/xen_igd_pt.c F: include/hw/block/dataplane/xen* F: include/hw/xen/ F: include/sysemu/xen-mapcache.h @@ -1482,6 +1483,7 @@ S: Odd Fixes F: include/hw/sd/sd* F: hw/sd/core.c F: hw/sd/sd* +F: hw/sd/ssi-sd.c F: tests/sd* USB diff --git a/Makefile b/Makefile index 1361def144..6b5ad1121b 100644 --- a/Makefile +++ b/Makefile @@ -321,14 +321,10 @@ HELPERS-y = HELPERS-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_LINUX)) = qemu-bridge-helper$(EXESUF) -ifdef CONFIG_LINUX -ifdef CONFIG_VIRGL -ifdef CONFIG_GBM +ifeq ($(CONFIG_LINUX)$(CONFIG_VIRGL)$(CONFIG_GBM)$(CONFIG_TOOLS),yyyy) HELPERS-y += vhost-user-gpu$(EXESUF) vhost-user-json-y += contrib/vhost-user-gpu/50-qemu-gpu.json endif -endif -endif # Sphinx does not allow building manuals into the same directory as # the source files, so if we're doing an in-tree QEMU build we must @@ -386,6 +382,7 @@ MINIKCONF_ARGS = \ CONFIG_OPENGL=$(CONFIG_OPENGL) \ CONFIG_X11=$(CONFIG_X11) \ CONFIG_VHOST_USER=$(CONFIG_VHOST_USER) \ + CONFIG_VHOST_KERNEL=$(CONFIG_VHOST_KERNEL) \ CONFIG_VIRTFS=$(CONFIG_VIRTFS) \ CONFIG_LINUX=$(CONFIG_LINUX) \ CONFIG_PVRDMA=$(CONFIG_PVRDMA) @@ -440,15 +437,10 @@ dummy := $(call unnest-vars,, \ block-obj-y \ block-obj-m \ crypto-obj-y \ - crypto-user-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ common-obj-m \ - ui-obj-y \ - ui-obj-m \ - audio-obj-y \ - audio-obj-m \ trace-obj-y) include $(SRC_PATH)/tests/Makefile.include @@ -532,7 +524,7 @@ subdir-capstone: capstone/all subdir-slirp: slirp/all $(filter %/all, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \ - $(qom-obj-y) $(crypto-user-obj-$(CONFIG_USER_ONLY)) + $(qom-obj-y) ROM_DIRS = $(addprefix pc-bios/, $(ROMS)) ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS))) @@ -1009,7 +1001,7 @@ sphinxdocs: $(MANUAL_BUILDDIR)/devel/index.html $(MANUAL_BUILDDIR)/interop/index # Note the use of different doctree for each (manual, builder) tuple; # this works around Sphinx not handling parallel invocation on # a single doctree: https://github.com/sphinx-doc/sphinx/issues/2946 -build-manual = $(call quiet-command,CONFDIR="$(qemu_confdir)" sphinx-build $(if $(V),,-q) -W -n -b $2 -D version=$(VERSION) -D release="$(FULL_VERSION)" -d .doctrees/$1-$2 $(SRC_PATH)/docs/$1 $(MANUAL_BUILDDIR)/$1 ,"SPHINX","$(MANUAL_BUILDDIR)/$1") +build-manual = $(call quiet-command,CONFDIR="$(qemu_confdir)" sphinx-build $(if $(V),,-q) -W -b $2 -D version=$(VERSION) -D release="$(FULL_VERSION)" -d .doctrees/$1-$2 $(SRC_PATH)/docs/$1 $(MANUAL_BUILDDIR)/$1 ,"SPHINX","$(MANUAL_BUILDDIR)/$1") # We assume all RST files in the manual's directory are used in it manual-deps = $(wildcard $(SRC_PATH)/docs/$1/*.rst) $(SRC_PATH)/docs/$1/conf.py $(SRC_PATH)/docs/conf.py diff --git a/Makefile.objs b/Makefile.objs index 4e4d6ddbb3..02bf5ce11d 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -1,7 +1,7 @@ ####################################################################### # Common libraries for tools and emulators -stub-obj-y = stubs/ util/ crypto/ -util-obj-y = util/ qobject/ qapi/ +stub-obj-y = stubs/ +util-obj-y = crypto/ util/ qobject/ qapi/ chardev-obj-y = chardev/ @@ -25,7 +25,6 @@ block-obj-m = block/ # crypto-obj-y is code used by both qemu system emulation and qemu-img crypto-obj-y = crypto/ -crypto-user-obj-y = crypto/ ####################################################################### # qom-obj-y is code used by both qemu system emulation and qemu-img @@ -55,6 +54,7 @@ common-obj-$(CONFIG_POSIX) += os-posix.o common-obj-$(CONFIG_LINUX) += fsdev/ +common-obj-y += accel/ common-obj-y += migration/ common-obj-y += audio/ diff --git a/Makefile.target b/Makefile.target index 24d79d26eb..6e61f607b1 100644 --- a/Makefile.target +++ b/Makefile.target @@ -184,7 +184,6 @@ dummy := $(call unnest-vars,.., \ block-obj-m \ chardev-obj-y \ crypto-obj-y \ - crypto-user-obj-y \ qom-obj-y \ io-obj-y \ common-obj-y \ @@ -193,7 +192,6 @@ all-obj-y += $(common-obj-y) all-obj-y += $(qom-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y) -all-obj-$(CONFIG_USER_ONLY) += $(crypto-user-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y) diff --git a/accel/Makefile.objs b/accel/Makefile.objs index 8b498d39d8..17e5ac6061 100644 --- a/accel/Makefile.objs +++ b/accel/Makefile.objs @@ -1,4 +1,4 @@ -obj-$(CONFIG_SOFTMMU) += accel.o +common-obj-$(CONFIG_SOFTMMU) += accel.o obj-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_POSIX)) += qtest.o obj-$(CONFIG_KVM) += kvm/ obj-$(CONFIG_TCG) += tcg/ diff --git a/accel/accel.c b/accel/accel.c index 5fa31717b4..1c5c3a6abb 100644 --- a/accel/accel.c +++ b/accel/accel.c @@ -28,13 +28,7 @@ #include "hw/boards.h" #include "sysemu/arch_init.h" #include "sysemu/sysemu.h" -#include "sysemu/kvm.h" -#include "sysemu/qtest.h" -#include "hw/xen/xen.h" #include "qom/object.h" -#include "qemu/error-report.h" -#include "qemu/option.h" -#include "qapi/error.h" static const TypeInfo accel_type = { .name = TYPE_ACCEL, @@ -44,7 +38,7 @@ static const TypeInfo accel_type = { }; /* Lookup AccelClass from opt_name. Returns NULL if not found */ -static AccelClass *accel_find(const char *opt_name) +AccelClass *accel_find(const char *opt_name) { char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name); AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name)); @@ -52,11 +46,9 @@ static AccelClass *accel_find(const char *opt_name) return ac; } -static int accel_init_machine(AccelClass *acc, MachineState *ms) +int accel_init_machine(AccelState *accel, MachineState *ms) { - ObjectClass *oc = OBJECT_CLASS(acc); - const char *cname = object_class_get_name(oc); - AccelState *accel = ACCEL(object_new(cname)); + AccelClass *acc = ACCEL_GET_CLASS(accel); int ret; ms->accelerator = accel; *(acc->allowed) = true; @@ -71,65 +63,6 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms) return ret; } -void configure_accelerator(MachineState *ms, const char *progname) -{ - const char *accel; - char **accel_list, **tmp; - int ret; - bool accel_initialised = false; - bool init_failed = false; - AccelClass *acc = NULL; - - accel = qemu_opt_get(qemu_get_machine_opts(), "accel"); - if (accel == NULL) { - /* Select the default accelerator */ - int pnlen = strlen(progname); - if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) { - /* If the program name ends with "kvm", we prefer KVM */ - accel = "kvm:tcg"; - } else { -#if defined(CONFIG_TCG) - accel = "tcg"; -#elif defined(CONFIG_KVM) - accel = "kvm"; -#else - error_report("No accelerator selected and" - " no default accelerator available"); - exit(1); -#endif - } - } - - accel_list = g_strsplit(accel, ":", 0); - - for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { - acc = accel_find(*tmp); - if (!acc) { - continue; - } - ret = accel_init_machine(acc, ms); - if (ret < 0) { - init_failed = true; - error_report("failed to initialize %s: %s", - acc->name, strerror(-ret)); - } else { - accel_initialised = true; - } - } - g_strfreev(accel_list); - - if (!accel_initialised) { - if (!init_failed) { - error_report("-machine accel=%s: No accelerator found", accel); - } - exit(1); - } - - if (init_failed) { - error_report("Back to %s accelerator", acc->name); - } -} - void accel_setup_post(MachineState *ms) { AccelState *accel = ms->accelerator; diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index ca00daa2f5..b2f1a5bcb5 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -41,6 +41,9 @@ #include "hw/irq.h" #include "sysemu/sev.h" #include "sysemu/balloon.h" +#include "qapi/visitor.h" +#include "qapi/qapi-types-common.h" +#include "qapi/qapi-visit-common.h" #include "hw/boards.h" @@ -92,6 +95,10 @@ struct KVMState int max_nested_state_len; int many_ioeventfds; int intx_set_mask; + int kvm_shadow_mem; + bool kernel_irqchip_allowed; + bool kernel_irqchip_required; + bool kernel_irqchip_split; bool sync_mmu; bool manual_dirty_log_protect; /* The man page (and posix) say ioctl numbers are signed int, but @@ -518,6 +525,27 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1)) +/* Allocate the dirty bitmap for a slot */ +static void kvm_memslot_init_dirty_bitmap(KVMSlot *mem) +{ + /* + * XXX bad kernel interface alert + * For dirty bitmap, kernel allocates array of size aligned to + * bits-per-long. But for case when the kernel is 64bits and + * the userspace is 32bits, userspace can't align to the same + * bits-per-long, since sizeof(long) is different between kernel + * and user space. This way, userspace will provide buffer which + * may be 4 bytes less than the kernel will use, resulting in + * userspace memory corruption (which is not detectable by valgrind + * too, in most cases). + * So for now, let's align to 64 instead of HOST_LONG_BITS here, in + * a hope that sizeof(long) won't become >8 any time soon. + */ + hwaddr bitmap_size = ALIGN(((mem->memory_size) >> TARGET_PAGE_BITS), + /*HOST_LONG_BITS*/ 64) / 8; + mem->dirty_bmap = g_malloc0(bitmap_size); +} + /** * kvm_physical_sync_dirty_bitmap - Sync dirty bitmap from kernel space * @@ -550,23 +578,9 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, goto out; } - /* XXX bad kernel interface alert - * For dirty bitmap, kernel allocates array of size aligned to - * bits-per-long. But for case when the kernel is 64bits and - * the userspace is 32bits, userspace can't align to the same - * bits-per-long, since sizeof(long) is different between kernel - * and user space. This way, userspace will provide buffer which - * may be 4 bytes less than the kernel will use, resulting in - * userspace memory corruption (which is not detectable by valgrind - * too, in most cases). - * So for now, let's align to 64 instead of HOST_LONG_BITS here, in - * a hope that sizeof(long) won't become >8 any time soon. - */ if (!mem->dirty_bmap) { - hwaddr bitmap_size = ALIGN(((mem->memory_size) >> TARGET_PAGE_BITS), - /*HOST_LONG_BITS*/ 64) / 8; /* Allocate on the first log_sync, once and for all */ - mem->dirty_bmap = g_malloc0(bitmap_size); + kvm_memslot_init_dirty_bitmap(mem); } d.dirty_bitmap = mem->dirty_bmap; @@ -1067,6 +1081,13 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, mem->ram = ram; mem->flags = kvm_mem_flags(mr); + if (mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { + /* + * Reallocate the bmap; it means it doesn't disappear in + * middle of a migrate. + */ + kvm_memslot_init_dirty_bitmap(mem); + } err = kvm_set_user_memory_region(kml, mem, true); if (err) { fprintf(stderr, "%s: error registering slot: %s\n", __func__, @@ -1758,7 +1779,7 @@ void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi) g_hash_table_insert(s->gsimap, irq, GINT_TO_POINTER(gsi)); } -static void kvm_irqchip_create(MachineState *machine, KVMState *s) +static void kvm_irqchip_create(KVMState *s) { int ret; @@ -1776,9 +1797,9 @@ static void kvm_irqchip_create(MachineState *machine, KVMState *s) /* First probe and see if there's a arch-specific hook to create the * in-kernel irqchip for us */ - ret = kvm_arch_irqchip_create(machine, s); + ret = kvm_arch_irqchip_create(s); if (ret == 0) { - if (machine_kernel_irqchip_split(machine)) { + if (s->kernel_irqchip_split) { perror("Split IRQ chip mode not supported."); exit(1); } else { @@ -2049,8 +2070,8 @@ static int kvm_init(MachineState *ms) goto err; } - if (machine_kernel_irqchip_allowed(ms)) { - kvm_irqchip_create(ms, s); + if (s->kernel_irqchip_allowed) { + kvm_irqchip_create(s); } if (kvm_eventfds_allowed) { @@ -2940,6 +2961,93 @@ static bool kvm_accel_has_memory(MachineState *ms, AddressSpace *as, return false; } +static void kvm_get_kvm_shadow_mem(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s = KVM_STATE(obj); + int64_t value = s->kvm_shadow_mem; + + visit_type_int(v, name, &value, errp); +} + +static void kvm_set_kvm_shadow_mem(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s = KVM_STATE(obj); + Error *error = NULL; + int64_t value; + + visit_type_int(v, name, &value, &error); + if (error) { + error_propagate(errp, error); + return; + } + + s->kvm_shadow_mem = value; +} + +static void kvm_set_kernel_irqchip(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Error *err = NULL; + KVMState *s = KVM_STATE(obj); + OnOffSplit mode; + + visit_type_OnOffSplit(v, name, &mode, &err); + if (err) { + error_propagate(errp, err); + return; + } else { + switch (mode) { + case ON_OFF_SPLIT_ON: + s->kernel_irqchip_allowed = true; + s->kernel_irqchip_required = true; + s->kernel_irqchip_split = false; + break; + case ON_OFF_SPLIT_OFF: + s->kernel_irqchip_allowed = false; + s->kernel_irqchip_required = false; + s->kernel_irqchip_split = false; + break; + case ON_OFF_SPLIT_SPLIT: + s->kernel_irqchip_allowed = true; + s->kernel_irqchip_required = true; + s->kernel_irqchip_split = true; + break; + default: + /* The value was checked in visit_type_OnOffSplit() above. If + * we get here, then something is wrong in QEMU. + */ + abort(); + } + } +} + +bool kvm_kernel_irqchip_allowed(void) +{ + return kvm_state->kernel_irqchip_allowed; +} + +bool kvm_kernel_irqchip_required(void) +{ + return kvm_state->kernel_irqchip_required; +} + +bool kvm_kernel_irqchip_split(void) +{ + return kvm_state->kernel_irqchip_split; +} + +static void kvm_accel_instance_init(Object *obj) +{ + KVMState *s = KVM_STATE(obj); + + s->kvm_shadow_mem = -1; +} + static void kvm_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac = ACCEL_CLASS(oc); @@ -2947,11 +3055,24 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data) ac->init_machine = kvm_init; ac->has_memory = kvm_accel_has_memory; ac->allowed = &kvm_allowed; + + object_class_property_add(oc, "kernel-irqchip", "on|off|split", + NULL, kvm_set_kernel_irqchip, + NULL, NULL, &error_abort); + object_class_property_set_description(oc, "kernel-irqchip", + "Configure KVM in-kernel irqchip", &error_abort); + + object_class_property_add(oc, "kvm-shadow-mem", "int", + kvm_get_kvm_shadow_mem, kvm_set_kvm_shadow_mem, + NULL, NULL, &error_abort); + object_class_property_set_description(oc, "kvm-shadow-mem", + "KVM shadow MMU size", &error_abort); } static const TypeInfo kvm_accel_type = { .name = TYPE_KVM_ACCEL, .parent = TYPE_ACCEL, + .instance_init = kvm_accel_instance_init, .class_init = kvm_accel_class_init, .instance_size = sizeof(KVMState), }; diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index c01f59c743..62068d10c3 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -156,7 +156,7 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) #if defined(DEBUG_DISAS) if (qemu_loglevel_mask(CPU_LOG_TB_CPU) && qemu_log_in_addr_range(itb->pc)) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); int flags = 0; if (qemu_loglevel_mask(CPU_LOG_TB_FPU)) { flags |= CPU_DUMP_FPU; @@ -165,7 +165,7 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) flags |= CPU_DUMP_CCOP; #endif log_cpu_state(cpu, flags); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif /* DEBUG_DISAS */ diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c index c59d5b0024..1dc384c8d2 100644 --- a/accel/tcg/tcg-all.c +++ b/accel/tcg/tcg-all.c @@ -30,8 +30,23 @@ #include "cpu.h" #include "sysemu/cpus.h" #include "qemu/main-loop.h" +#include "tcg/tcg.h" +#include "include/qapi/error.h" +#include "include/qemu/error-report.h" +#include "include/hw/boards.h" +#include "qapi/qapi-builtin-visit.h" -unsigned long tcg_tb_size; +typedef struct TCGState { + AccelState parent_obj; + + bool mttcg_enabled; + unsigned long tb_size; +} TCGState; + +#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg") + +#define TCG_STATE(obj) \ + OBJECT_CHECK(TCGState, (obj), TYPE_TCG_ACCEL) /* mask must never be zero, except for A20 change call */ static void tcg_handle_interrupt(CPUState *cpu, int mask) @@ -58,27 +73,153 @@ static void tcg_handle_interrupt(CPUState *cpu, int mask) } } +/* + * We default to false if we know other options have been enabled + * which are currently incompatible with MTTCG. Otherwise when each + * guest (target) has been updated to support: + * - atomic instructions + * - memory ordering primitives (barriers) + * they can set the appropriate CONFIG flags in ${target}-softmmu.mak + * + * Once a guest architecture has been converted to the new primitives + * there are two remaining limitations to check. + * + * - The guest can't be oversized (e.g. 64 bit guest on 32 bit host) + * - The host must have a stronger memory order than the guest + * + * It may be possible in future to support strong guests on weak hosts + * but that will require tagging all load/stores in a guest with their + * implicit memory order requirements which would likely slow things + * down a lot. + */ + +static bool check_tcg_memory_orders_compatible(void) +{ +#if defined(TCG_GUEST_DEFAULT_MO) && defined(TCG_TARGET_DEFAULT_MO) + return (TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO) == 0; +#else + return false; +#endif +} + +static bool default_mttcg_enabled(void) +{ + if (use_icount || TCG_OVERSIZED_GUEST) { + return false; + } else { +#ifdef TARGET_SUPPORTS_MTTCG + return check_tcg_memory_orders_compatible(); +#else + return false; +#endif + } +} + +static void tcg_accel_instance_init(Object *obj) +{ + TCGState *s = TCG_STATE(obj); + + s->mttcg_enabled = default_mttcg_enabled(); +} + static int tcg_init(MachineState *ms) { - tcg_exec_init(tcg_tb_size * 1024 * 1024); + TCGState *s = TCG_STATE(current_machine->accelerator); + + tcg_exec_init(s->tb_size * 1024 * 1024); cpu_interrupt_handler = tcg_handle_interrupt; + mttcg_enabled = s->mttcg_enabled; return 0; } +static char *tcg_get_thread(Object *obj, Error **errp) +{ + TCGState *s = TCG_STATE(obj); + + return g_strdup(s->mttcg_enabled ? "multi" : "single"); +} + +static void tcg_set_thread(Object *obj, const char *value, Error **errp) +{ + TCGState *s = TCG_STATE(obj); + + if (strcmp(value, "multi") == 0) { + if (TCG_OVERSIZED_GUEST) { + error_setg(errp, "No MTTCG when guest word size > hosts"); + } else if (use_icount) { + error_setg(errp, "No MTTCG when icount is enabled"); + } else { +#ifndef TARGET_SUPPORTS_MTTCG + warn_report("Guest not yet converted to MTTCG - " + "you may get unexpected results"); +#endif + if (!check_tcg_memory_orders_compatible()) { + warn_report("Guest expects a stronger memory ordering " + "than the host provides"); + error_printf("This may cause strange/hard to debug errors\n"); + } + s->mttcg_enabled = true; + } + } else if (strcmp(value, "single") == 0) { + s->mttcg_enabled = false; + } else { + error_setg(errp, "Invalid 'thread' setting %s", value); + } +} + +static void tcg_get_tb_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + TCGState *s = TCG_STATE(obj); + uint32_t value = s->tb_size; + + visit_type_uint32(v, name, &value, errp); +} + +static void tcg_set_tb_size(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + TCGState *s = TCG_STATE(obj); + Error *error = NULL; + uint32_t value; + + visit_type_uint32(v, name, &value, &error); + if (error) { + error_propagate(errp, error); + return; + } + + s->tb_size = value; +} + static void tcg_accel_class_init(ObjectClass *oc, void *data) { AccelClass *ac = ACCEL_CLASS(oc); ac->name = "tcg"; ac->init_machine = tcg_init; ac->allowed = &tcg_allowed; -} -#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg") + object_class_property_add_str(oc, "thread", + tcg_get_thread, + tcg_set_thread, + NULL); + + object_class_property_add(oc, "tb-size", "int", + tcg_get_tb_size, tcg_set_tb_size, + NULL, NULL, &error_abort); + object_class_property_set_description(oc, "tb-size", + "TCG translation block cache size", &error_abort); + +} static const TypeInfo tcg_accel_type = { .name = TYPE_TCG_ACCEL, .parent = TYPE_ACCEL, + .instance_init = tcg_accel_instance_init, .class_init = tcg_accel_class_init, + .instance_size = sizeof(TCGState), }; static void register_accel_types(void) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 9f48da9472..bb325a2bc4 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1804,7 +1804,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM) && qemu_log_in_addr_range(tb->pc)) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("OUT: [size=%d]\n", gen_code_size); if (tcg_ctx->data_gen_ptr) { size_t code_size = tcg_ctx->data_gen_ptr - tb->tc.ptr; @@ -1829,7 +1829,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } qemu_log("\n"); qemu_log_flush(); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index f977682be7..603d17ff83 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -138,11 +138,11 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) && qemu_log_in_addr_range(db->pc_first)) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("----------------\n"); ops->disas_log(db, cpu); qemu_log("\n"); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif } diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 3c071eab95..5a9735684e 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -176,19 +176,10 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp) { CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc); CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc); - Error *local_err = NULL; if (bc->init) { - bc->init(backend, &local_err); - if (local_err) { - goto out; - } + bc->init(backend, errp); } - - return; - -out: - error_propagate(errp, local_err); } void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used) diff --git a/block/nbd.c b/block/nbd.c index 5f18f78a94..d085554f21 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -866,6 +866,7 @@ typedef struct NBDReplyChunkIter { static void nbd_iter_channel_error(NBDReplyChunkIter *iter, int ret, Error **local_err) { + assert(local_err && *local_err); assert(ret < 0); if (!iter->ret) { diff --git a/block/snapshot.c b/block/snapshot.c index 8081616ae9..bd9fb01817 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -426,7 +426,7 @@ fail: } int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs, - Error **err) + Error **errp) { int ret = 0; BlockDriverState *bs; @@ -441,7 +441,7 @@ int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs, bdrv_snapshot_find(bs, snapshot, name) >= 0) { ret = bdrv_snapshot_delete(bs, snapshot->id_str, - snapshot->name, err); + snapshot->name, errp); } aio_context_release(ctx); if (ret < 0) { diff --git a/bsd-user/main.c b/bsd-user/main.c index 470a8bf79e..7f4e3cd627 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -963,7 +963,7 @@ int main(int argc, char **argv) if (qemu_loglevel_mask(CPU_LOG_PAGE)) { qemu_log("guest_base 0x%lx\n", guest_base); - log_page_dump(); + log_page_dump("binary load"); qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); qemu_log("end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code); diff --git a/configure b/configure index 84b413dbfc..940bf9e87a 100755 --- a/configure +++ b/configure @@ -101,7 +101,7 @@ update_cxxflags() { # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those # options which some versions of GCC's C++ compiler complain about # because they only make sense for C programs. - QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS" + QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS" for arg in $QEMU_CFLAGS; do case $arg in @@ -302,6 +302,7 @@ audio_win_int="" libs_qga="" debug_info="yes" stack_protector="" +use_containers="yes" if test -e "$source_path/.git" then @@ -595,6 +596,7 @@ QEMU_CFLAGS="-Wall -Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS" QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS" QEMU_INCLUDES="-iquote . -iquote \$(SRC_PATH) -iquote \$(SRC_PATH)/accel/tcg -iquote \$(SRC_PATH)/include" +QEMU_INCLUDES="$QEMU_INCLUDES -iquote \$(SRC_PATH)/disas/libvixl" if test "$debug_info" = "yes"; then CFLAGS="-g $CFLAGS" LDFLAGS="-g $LDFLAGS" @@ -907,7 +909,7 @@ for binary in "${PYTHON-python3}" python python2 do if has "$binary" then - python="$binary" + python=$(command -v "$binary") break fi done @@ -925,7 +927,7 @@ if test "$mingw32" = "yes" ; then DSOSUF=".dll" # MinGW needs -mthreads for TLS and macro _MT. QEMU_CFLAGS="-mthreads $QEMU_CFLAGS" - LIBS="-lwinmm -lws2_32 -liphlpapi $LIBS" + LIBS="-lwinmm -lws2_32 $LIBS" write_c_skeleton; if compile_prog "" "-liberty" ; then LIBS="-liberty $LIBS" @@ -1534,6 +1536,10 @@ for opt do ;; --disable-plugins) plugins="no" ;; + --enable-containers) use_containers="yes" + ;; + --disable-containers) use_containers="no" + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1717,6 +1723,7 @@ Advanced options (experts only): track the maximum stack usage of stacks created by qemu_alloc_stack --enable-plugins enable plugins via shared library loading + --disable-containers don't use containers for cross-building Optional features, enabled with --enable-FEATURE and disabled with --disable-FEATURE, default is enabled if available: @@ -6027,6 +6034,9 @@ case "$slirp" in mkdir -p slirp slirp_cflags="-I\$(SRC_PATH)/slirp/src -I\$(BUILD_DIR)/slirp/src" slirp_libs="-L\$(BUILD_DIR)/slirp -lslirp" + if test "$mingw32" = "yes" ; then + slirp_libs="$slirp_libs -lws2_32 -liphlpapi" + fi ;; system) @@ -6395,6 +6405,7 @@ else echo "local state directory queried at runtime" echo "Windows SDK $win_sdk" fi +echo "Build directory $(pwd)" echo "Source path $source_path" echo "GIT binary $git" echo "GIT submodules $git_submodules" @@ -6716,7 +6727,7 @@ if test "$l2tpv3" = "yes" ; then echo "CONFIG_L2TPV3=y" >> $config_host_mak fi if test "$cap_ng" = "yes" ; then - echo "CONFIG_LIBCAP=y" >> $config_host_mak + echo "CONFIG_LIBCAP_NG=y" >> $config_host_mak fi echo "CONFIG_AUDIO_DRIVERS=$audio_drv_list" >> $config_host_mak for drv in $audio_drv_list; do @@ -7992,7 +8003,7 @@ done (for i in $cross_cc_vars; do export $i done -export target_list source_path +export target_list source_path use_containers $source_path/tests/tcg/configure.sh) # temporary config to build submodules diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c index 0fc14d7899..7a1db164c8 100644 --- a/contrib/vhost-user-scsi/vhost-user-scsi.c +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c @@ -115,7 +115,7 @@ static int get_cdb_len(uint8_t *cdb) case 4: return 16; case 5: return 12; } - g_warning("Unable to determine cdb len (0x%02hhX)", cdb[0] >> 5); + g_warning("Unable to determine cdb len (0x%02hhX)", (uint8_t)(cdb[0] >> 5)); return -1; } diff --git a/cpus.c b/cpus.c index 63bda152f5..b472378b70 100644 --- a/cpus.c +++ b/cpus.c @@ -166,78 +166,6 @@ typedef struct TimersState { static TimersState timers_state; bool mttcg_enabled; -/* - * We default to false if we know other options have been enabled - * which are currently incompatible with MTTCG. Otherwise when each - * guest (target) has been updated to support: - * - atomic instructions - * - memory ordering primitives (barriers) - * they can set the appropriate CONFIG flags in ${target}-softmmu.mak - * - * Once a guest architecture has been converted to the new primitives - * there are two remaining limitations to check. - * - * - The guest can't be oversized (e.g. 64 bit guest on 32 bit host) - * - The host must have a stronger memory order than the guest - * - * It may be possible in future to support strong guests on weak hosts - * but that will require tagging all load/stores in a guest with their - * implicit memory order requirements which would likely slow things - * down a lot. - */ - -static bool check_tcg_memory_orders_compatible(void) -{ -#if defined(TCG_GUEST_DEFAULT_MO) && defined(TCG_TARGET_DEFAULT_MO) - return (TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO) == 0; -#else - return false; -#endif -} - -static bool default_mttcg_enabled(void) -{ - if (use_icount || TCG_OVERSIZED_GUEST) { - return false; - } else { -#ifdef TARGET_SUPPORTS_MTTCG - return check_tcg_memory_orders_compatible(); -#else - return false; -#endif - } -} - -void qemu_tcg_configure(QemuOpts *opts, Error **errp) -{ - const char *t = qemu_opt_get(opts, "thread"); - if (t) { - if (strcmp(t, "multi") == 0) { - if (TCG_OVERSIZED_GUEST) { - error_setg(errp, "No MTTCG when guest word size > hosts"); - } else if (use_icount) { - error_setg(errp, "No MTTCG when icount is enabled"); - } else { -#ifndef TARGET_SUPPORTS_MTTCG - warn_report("Guest not yet converted to MTTCG - " - "you may get unexpected results"); -#endif - if (!check_tcg_memory_orders_compatible()) { - warn_report("Guest expects a stronger memory ordering " - "than the host provides"); - error_printf("This may cause strange/hard to debug errors\n"); - } - mttcg_enabled = true; - } - } else if (strcmp(t, "single") == 0) { - mttcg_enabled = false; - } else { - error_setg(errp, "Invalid 'thread' setting %s", t); - } - } else { - mttcg_enabled = default_mttcg_enabled(); - } -} /* The current number of executed instructions is based on what we * originally budgeted minus the current state of the decrementing diff --git a/crypto/Makefile.objs b/crypto/Makefile.objs index cdb01f9de9..c2a371b0b4 100644 --- a/crypto/Makefile.objs +++ b/crypto/Makefile.objs @@ -19,13 +19,10 @@ crypto-obj-y += tlscredspsk.o crypto-obj-y += tlscredsx509.o crypto-obj-y += tlssession.o crypto-obj-y += secret.o -crypto-rng-obj-$(CONFIG_GCRYPT) += random-gcrypt.o -crypto-rng-obj-$(if $(CONFIG_GCRYPT),n,$(CONFIG_GNUTLS)) += random-gnutls.o -crypto-rng-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,y)) += random-platform.o -crypto-obj-y += $(crypto-rng-obj-y) crypto-obj-y += pbkdf.o crypto-obj-$(CONFIG_NETTLE) += pbkdf-nettle.o crypto-obj-$(if $(CONFIG_NETTLE),n,$(CONFIG_GCRYPT)) += pbkdf-gcrypt.o +crypto-obj-$(if $(CONFIG_NETTLE),n,$(if $(CONFIG_GCRYPT),n,y)) += pbkdf-stub.o crypto-obj-y += ivgen.o crypto-obj-y += ivgen-essiv.o crypto-obj-y += ivgen-plain.o @@ -36,7 +33,7 @@ crypto-obj-y += block.o crypto-obj-y += block-qcow.o crypto-obj-y += block-luks.o -# Let the userspace emulators avoid linking stuff they won't use. -crypto-user-obj-y = aes.o $(crypto-rng-obj-y) init.o - -stub-obj-y += pbkdf-stub.o +util-obj-$(CONFIG_GCRYPT) += random-gcrypt.o +util-obj-$(if $(CONFIG_GCRYPT),n,$(CONFIG_GNUTLS)) += random-gnutls.o +util-obj-$(if $(CONFIG_GCRYPT),n,$(if $(CONFIG_GNUTLS),n,y)) += random-platform.o +util-obj-y += aes.o init.o diff --git a/crypto/tlscredsx509.c b/crypto/tlscredsx509.c index 01fc304e5d..53a4368f49 100644 --- a/crypto/tlscredsx509.c +++ b/crypto/tlscredsx509.c @@ -380,7 +380,7 @@ qcrypto_tls_creds_load_cert(QCryptoTLSCredsX509 *creds, gnutls_x509_crt_t cert = NULL; g_autofree char *buf = NULL; gsize buflen; - GError *gerr; + GError *gerr = NULL; int ret = -1; int err; diff --git a/disas/libvixl/Makefile.objs b/disas/libvixl/Makefile.objs index 27183b7c20..99a637f6a0 100644 --- a/disas/libvixl/Makefile.objs +++ b/disas/libvixl/Makefile.objs @@ -1,14 +1,5 @@ -libvixl_OBJS = vixl/utils.o \ +common-obj-$(CONFIG_ARM_A64_DIS) = vixl/utils.o \ vixl/compiler-intrinsics.o \ vixl/a64/instructions-a64.o \ vixl/a64/decoder-a64.o \ vixl/a64/disasm-a64.o - -# The -Wno-sign-compare is needed only for gcc 4.6, which complains about -# some signed-unsigned equality comparisons which later gcc versions do not. -$(addprefix $(obj)/,$(libvixl_OBJS)): QEMU_CXXFLAGS := -I$(SRC_PATH)/disas/libvixl $(QEMU_CXXFLAGS) -Wno-sign-compare -# Ensure that C99 macros are defined regardless of the inclusion order of -# headers in vixl. This is required at least on NetBSD. -$(addprefix $(obj)/,$(libvixl_OBJS)): QEMU_CXXFLAGS += -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS - -common-obj-$(CONFIG_ARM_A64_DIS) += $(libvixl_OBJS) diff --git a/docs/conf.py b/docs/conf.py index b7edb0666b..259c6049da 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -54,7 +54,7 @@ needs_sphinx = '1.3' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['qmp_lexer'] +extensions = ['kerneldoc', 'qmp_lexer'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -216,3 +216,8 @@ texinfo_documents = [ +# We use paths starting from qemu_docdir here so that you can run +# sphinx-build from anywhere and the kerneldoc extension can still +# find everything. +kerneldoc_bin = os.path.join(qemu_docdir, '../scripts/kernel-doc') +kerneldoc_srctree = os.path.join(qemu_docdir, '..') diff --git a/docs/devel/bitops.rst b/docs/devel/bitops.rst new file mode 100644 index 0000000000..6addaecf8d --- /dev/null +++ b/docs/devel/bitops.rst @@ -0,0 +1,8 @@ +================== +Bitwise operations +================== + +The header ``qemu/bitops.h`` provides utility functions for +performing bitwise operations. + +.. kernel-doc:: include/qemu/bitops.h diff --git a/docs/devel/index.rst b/docs/devel/index.rst index c86a3cdff2..ac862152dc 100644 --- a/docs/devel/index.rst +++ b/docs/devel/index.rst @@ -23,3 +23,4 @@ Contents: secure-coding-practices tcg tcg-plugins + bitops diff --git a/docs/devel/memory.rst b/docs/devel/memory.rst index b6a4c37ea5..5dc8a12682 100644 --- a/docs/devel/memory.rst +++ b/docs/devel/memory.rst @@ -361,3 +361,8 @@ callbacks are called: - .impl.unaligned specifies that the *implementation* supports unaligned accesses; if false, unaligned accesses will be emulated by two aligned accesses. + +API Reference +------------- + +.. kernel-doc:: include/exec/memory.h diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst index 27f286858a..ab5be0c729 100644 --- a/docs/devel/testing.rst +++ b/docs/devel/testing.rst @@ -418,13 +418,15 @@ access, so they SHOULD NOT be exposed to external interfaces if you are concerned about attackers taking control of the guest and potentially exploiting a QEMU security bug to compromise the host. -QEMU binary ------------ +QEMU binaries +------------- By default, qemu-system-x86_64 is searched in $PATH to run the guest. If there isn't one, or if it is older than 2.10, the test won't work. In this case, provide the QEMU binary in env var: ``QEMU=/path/to/qemu-2.10+``. +Likewise the path to qemu-img can be set in QEMU_IMG environment variable. + Make jobs --------- diff --git a/docs/sphinx/kerneldoc.py b/docs/sphinx/kerneldoc.py new file mode 100644 index 0000000000..1159405cb9 --- /dev/null +++ b/docs/sphinx/kerneldoc.py @@ -0,0 +1,172 @@ +# coding=utf-8 +# +# Copyright © 2016 Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# Authors: +# Jani Nikula +# +# Please make sure this works on both python2 and python3. +# + +import codecs +import os +import subprocess +import sys +import re +import glob + +from docutils import nodes, statemachine +from docutils.statemachine import ViewList +from docutils.parsers.rst import directives, Directive + +# +# AutodocReporter is only good up to Sphinx 1.7 +# +import sphinx + +Use_SSI = sphinx.__version__[:3] >= '1.7' +if Use_SSI: + from sphinx.util.docutils import switch_source_input +else: + from sphinx.ext.autodoc import AutodocReporter + +import kernellog + +__version__ = '1.0' + +class KernelDocDirective(Directive): + """Extract kernel-doc comments from the specified file""" + required_argument = 1 + optional_arguments = 4 + option_spec = { + 'doc': directives.unchanged_required, + 'functions': directives.unchanged, + 'export': directives.unchanged, + 'internal': directives.unchanged, + } + has_content = False + + def run(self): + env = self.state.document.settings.env + cmd = [env.config.kerneldoc_bin, '-rst', '-enable-lineno'] + + filename = env.config.kerneldoc_srctree + '/' + self.arguments[0] + export_file_patterns = [] + + # Tell sphinx of the dependency + env.note_dependency(os.path.abspath(filename)) + + tab_width = self.options.get('tab-width', self.state.document.settings.tab_width) + + # FIXME: make this nicer and more robust against errors + if 'export' in self.options: + cmd += ['-export'] + export_file_patterns = str(self.options.get('export')).split() + elif 'internal' in self.options: + cmd += ['-internal'] + export_file_patterns = str(self.options.get('internal')).split() + elif 'doc' in self.options: + cmd += ['-function', str(self.options.get('doc'))] + elif 'functions' in self.options: + functions = self.options.get('functions').split() + if functions: + for f in functions: + cmd += ['-function', f] + else: + cmd += ['-no-doc-sections'] + + for pattern in export_file_patterns: + for f in glob.glob(env.config.kerneldoc_srctree + '/' + pattern): + env.note_dependency(os.path.abspath(f)) + cmd += ['-export-file', f] + + cmd += [filename] + + try: + kernellog.verbose(env.app, + 'calling kernel-doc \'%s\'' % (" ".join(cmd))) + + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = p.communicate() + + out, err = codecs.decode(out, 'utf-8'), codecs.decode(err, 'utf-8') + + if p.returncode != 0: + sys.stderr.write(err) + + kernellog.warn(env.app, + 'kernel-doc \'%s\' failed with return code %d' % (" ".join(cmd), p.returncode)) + return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))] + elif env.config.kerneldoc_verbosity > 0: + sys.stderr.write(err) + + lines = statemachine.string2lines(out, tab_width, convert_whitespace=True) + result = ViewList() + + lineoffset = 0; + line_regex = re.compile("^#define LINENO ([0-9]+)$") + for line in lines: + match = line_regex.search(line) + if match: + # sphinx counts lines from 0 + lineoffset = int(match.group(1)) - 1 + # we must eat our comments since the upset the markup + else: + result.append(line, filename, lineoffset) + lineoffset += 1 + + node = nodes.section() + self.do_parse(result, node) + + return node.children + + except Exception as e: # pylint: disable=W0703 + kernellog.warn(env.app, 'kernel-doc \'%s\' processing failed with: %s' % + (" ".join(cmd), str(e))) + return [nodes.error(None, nodes.paragraph(text = "kernel-doc missing"))] + + def do_parse(self, result, node): + if Use_SSI: + with switch_source_input(self.state, result): + self.state.nested_parse(result, 0, node, match_titles=1) + else: + save = self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter + self.state.memo.reporter = AutodocReporter(result, self.state.memo.reporter) + self.state.memo.title_styles, self.state.memo.section_level = [], 0 + try: + self.state.nested_parse(result, 0, node, match_titles=1) + finally: + self.state.memo.title_styles, self.state.memo.section_level, self.state.memo.reporter = save + + +def setup(app): + app.add_config_value('kerneldoc_bin', None, 'env') + app.add_config_value('kerneldoc_srctree', None, 'env') + app.add_config_value('kerneldoc_verbosity', 1, 'env') + + app.add_directive('kernel-doc', KernelDocDirective) + + return dict( + version = __version__, + parallel_read_safe = True, + parallel_write_safe = True + ) diff --git a/docs/sphinx/kernellog.py b/docs/sphinx/kernellog.py new file mode 100644 index 0000000000..af924f51a7 --- /dev/null +++ b/docs/sphinx/kernellog.py @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Sphinx has deprecated its older logging interface, but the replacement +# only goes back to 1.6. So here's a wrapper layer to keep around for +# as long as we support 1.4. +# +import sphinx + +if sphinx.__version__[:3] >= '1.6': + UseLogging = True + from sphinx.util import logging + logger = logging.getLogger('kerneldoc') +else: + UseLogging = False + +def warn(app, message): + if UseLogging: + logger.warning(message) + else: + app.warn(message) + +def verbose(app, message): + if UseLogging: + logger.verbose(message) + else: + app.verbose(message) + + diff --git a/dump/dump-hmp-cmds.c b/dump/dump-hmp-cmds.c index 3dbf44372c..e5053b04cd 100644 --- a/dump/dump-hmp-cmds.c +++ b/dump/dump-hmp-cmds.c @@ -32,7 +32,7 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) if (zlib + lzo + snappy + win_dmp > 1) { error_setg(&err, "only one of '-z|-l|-s|-w' can be set"); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } @@ -66,7 +66,7 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin, has_length, length, true, dump_format, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); g_free(prot); } diff --git a/exec.c b/exec.c index a34c348184..d4b769d0d4 100644 --- a/exec.c +++ b/exec.c @@ -1225,13 +1225,13 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...) fprintf(stderr, "\n"); cpu_dump_state(cpu, stderr, CPU_DUMP_FPU | CPU_DUMP_CCOP); if (qemu_log_separate()) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("qemu: fatal: "); qemu_log_vprintf(fmt, ap2); qemu_log("\n"); log_cpu_state(cpu, CPU_DUMP_FPU | CPU_DUMP_CCOP); qemu_log_flush(); - qemu_log_unlock(); + qemu_log_unlock(logfile); qemu_log_close(); } va_end(ap2); @@ -1843,6 +1843,7 @@ static void *file_ram_alloc(RAMBlock *block, bool truncate, Error **errp) { + Error *err = NULL; MachineState *ms = MACHINE(qdev_get_machine()); void *area; @@ -1900,8 +1901,9 @@ static void *file_ram_alloc(RAMBlock *block, } if (mem_prealloc) { - os_mem_prealloc(fd, area, memory, ms->smp.cpus, errp); - if (errp && *errp) { + os_mem_prealloc(fd, area, memory, ms->smp.cpus, &err); + if (err) { + error_propagate(errp, err); qemu_ram_munmap(fd, area, memory); return NULL; } @@ -3901,10 +3903,9 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) if ((start + length) <= rb->used_length) { bool need_madvise, need_fallocate; - uint8_t *host_endaddr = host_startaddr + length; - if ((uintptr_t)host_endaddr & (rb->page_size - 1)) { - error_report("ram_block_discard_range: Unaligned end address: %p", - host_endaddr); + if (length & (rb->page_size - 1)) { + error_report("ram_block_discard_range: Unaligned length: %zx", + length); goto err; } diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 4708c0bd89..ca641390fb 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1473,7 +1473,7 @@ static void local_cleanup(FsContext *ctx) g_free(data); } -static void error_append_security_model_hint(Error **errp) +static void error_append_security_model_hint(Error *const *errp) { error_append_hint(errp, "Valid options are: security_model=" "[passthrough|mapped-xattr|mapped-file|none]\n"); diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index 97ab9c58a5..8136e1342d 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -1114,7 +1114,7 @@ static int connect_namedsocket(const char *path, Error **errp) return sockfd; } -static void error_append_socket_sockfd_hint(Error **errp) +static void error_append_socket_sockfd_hint(Error *const *errp) { error_append_hint(errp, "Either specify socket=/some/path where /some/path" " points to a listening AF_UNIX socket or sock_fd=fd" diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs index 655a9c1973..99253057e1 100644 --- a/hw/acpi/Makefile.objs +++ b/hw/acpi/Makefile.objs @@ -8,6 +8,7 @@ common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o common-obj-$(CONFIG_ACPI_HW_REDUCED) += generic_event_device.o common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o +common-obj-$(call lnot,$(CONFIG_PC)) += acpi-x86-stub.o common-obj-y += acpi_interface.o common-obj-y += bios-linker-loader.o @@ -20,4 +21,4 @@ common-obj-$(call lnot,$(CONFIG_IPMI)) += ipmi-stub.o else common-obj-y += acpi-stub.o endif -common-obj-$(CONFIG_ALL) += acpi-stub.o ipmi-stub.o +common-obj-$(CONFIG_ALL) += acpi-stub.o acpi-x86-stub.o ipmi-stub.o diff --git a/hw/acpi/acpi-x86-stub.c b/hw/acpi/acpi-x86-stub.c new file mode 100644 index 0000000000..f88d6a090b --- /dev/null +++ b/hw/acpi/acpi-x86-stub.c @@ -0,0 +1,7 @@ +#include "qemu/osdep.h" +#include "hw/i386/pc.h" + +void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid, + const CPUArchIdList *apic_ids, GArray *entry) +{ +} diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c index 3ac2045a95..9c3bcc84de 100644 --- a/hw/acpi/cpu_hotplug.c +++ b/hw/acpi/cpu_hotplug.c @@ -55,8 +55,7 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = { }, }; -static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, - Error **errp) +static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu) { CPUClass *k = CPU_GET_CLASS(cpu); int64_t cpu_id; @@ -74,10 +73,7 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu, void legacy_acpi_cpu_plug_cb(HotplugHandler *hotplug_dev, AcpiCpuHotplug *g, DeviceState *dev, Error **errp) { - acpi_set_cpu_present_bit(g, CPU(dev), errp); - if (*errp != NULL) { - return; - } + acpi_set_cpu_present_bit(g, CPU(dev)); acpi_send_event(DEVICE(hotplug_dev), ACPI_CPU_HOTPLUG_STATUS); } @@ -92,7 +88,7 @@ void legacy_acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner, gpe_cpu->device = owner; CPU_FOREACH(cpu) { - acpi_set_cpu_present_bit(gpe_cpu, cpu, &error_abort); + acpi_set_cpu_present_bit(gpe_cpu, cpu); } } diff --git a/hw/alpha/alpha_sys.h b/hw/alpha/alpha_sys.h index 4e127a6de8..95033d7f0b 100644 --- a/hw/alpha/alpha_sys.h +++ b/hw/alpha/alpha_sys.h @@ -7,7 +7,8 @@ #include "hw/pci/pci.h" #include "hw/pci/pci_host.h" #include "hw/ide.h" -#include "hw/i386/pc.h" +#include "hw/boards.h" +#include "hw/intc/i8259.h" PCIBus *typhoon_init(ram_addr_t, ISABus **, qemu_irq *, AlphaCPU *[4], diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c index 51b3cf7a61..f2026fda6d 100644 --- a/hw/alpha/dp264.c +++ b/hw/alpha/dp264.c @@ -19,6 +19,7 @@ #include "hw/timer/i8254.h" #include "hw/isa/superio.h" #include "hw/dma/i8257.h" +#include "net/net.h" #include "qemu/cutils.h" #define MAX_IDE_BUS 2 diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c index a136b97f68..78cda88333 100644 --- a/hw/audio/ac97.c +++ b/hw/audio/ac97.c @@ -161,7 +161,6 @@ typedef struct AC97BusMasterRegs { typedef struct AC97LinkState { PCIDevice dev; QEMUSoundCard card; - uint32_t use_broken_id; uint32_t glob_cnt; uint32_t glob_sta; uint32_t cas; @@ -1373,13 +1372,6 @@ static void ac97_realize(PCIDevice *dev, Error **errp) c[PCI_BASE_ADDRESS_0 + 6] = 0x00; c[PCI_BASE_ADDRESS_0 + 7] = 0x00; - if (s->use_broken_id) { - c[PCI_SUBSYSTEM_VENDOR_ID] = 0x86; - c[PCI_SUBSYSTEM_VENDOR_ID + 1] = 0x80; - c[PCI_SUBSYSTEM_ID] = 0x00; - c[PCI_SUBSYSTEM_ID + 1] = 0x00; - } - c[PCI_INTERRUPT_LINE] = 0x00; /* intr_ln interrupt line rw */ c[PCI_INTERRUPT_PIN] = 0x01; /* intr_pn interrupt pin ro */ @@ -1411,7 +1403,6 @@ static int ac97_init (PCIBus *bus) static Property ac97_properties[] = { DEFINE_AUDIO_PROPERTIES(AC97LinkState, card), - DEFINE_PROP_UINT32 ("use_broken_id", AC97LinkState, use_broken_id, 0), DEFINE_PROP_END_OF_LIST (), }; diff --git a/hw/core/loader-fit.c b/hw/core/loader-fit.c index 953b16bc82..c465921b8f 100644 --- a/hw/core/loader-fit.c +++ b/hw/core/loader-fit.c @@ -178,11 +178,12 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb, int cfg, void *opaque, const void *match_data, hwaddr kernel_end, Error **errp) { + Error *err = NULL; const char *name; const void *data; const void *load_data; hwaddr load_addr; - int img_off, err; + int img_off; size_t sz; int ret; @@ -197,13 +198,13 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb, return -EINVAL; } - err = fit_image_addr(itb, img_off, "load", &load_addr, errp); - if (err == -ENOENT) { + ret = fit_image_addr(itb, img_off, "load", &load_addr, &err); + if (ret == -ENOENT) { load_addr = ROUND_UP(kernel_end, 64 * KiB) + (10 * MiB); - error_free(*errp); - } else if (err) { - error_prepend(errp, "unable to read FDT load address from FIT: "); - ret = err; + error_free(err); + } else if (ret) { + error_propagate_prepend(errp, err, + "unable to read FDT load address from FIT: "); goto out; } diff --git a/hw/core/machine-hmp-cmds.c b/hw/core/machine-hmp-cmds.c index cd970cc4c5..b76f7223af 100644 --- a/hw/core/machine-hmp-cmds.c +++ b/hw/core/machine-hmp-cmds.c @@ -55,7 +55,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict) cpuid = qdict_get_int(qdict, "id"); qmp_cpu_add(cpuid, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict) @@ -66,7 +66,7 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict) CpuInstanceProperties *c; if (err != NULL) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } @@ -135,7 +135,7 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict) monitor_printf(mon, "\n"); qapi_free_MemdevList(memdev_list); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_info_numa(Monitor *mon, const QDict *qdict) diff --git a/hw/core/machine.c b/hw/core/machine.c index 023548b4f3..56137e9bf0 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -178,86 +178,6 @@ GlobalProperty hw_compat_2_1[] = { }; const size_t hw_compat_2_1_len = G_N_ELEMENTS(hw_compat_2_1); -static char *machine_get_accel(Object *obj, Error **errp) -{ - MachineState *ms = MACHINE(obj); - - return g_strdup(ms->accel); -} - -static void machine_set_accel(Object *obj, const char *value, Error **errp) -{ - MachineState *ms = MACHINE(obj); - - g_free(ms->accel); - ms->accel = g_strdup(value); -} - -static void machine_set_kernel_irqchip(Object *obj, Visitor *v, - const char *name, void *opaque, - Error **errp) -{ - Error *err = NULL; - MachineState *ms = MACHINE(obj); - OnOffSplit mode; - - visit_type_OnOffSplit(v, name, &mode, &err); - if (err) { - error_propagate(errp, err); - return; - } else { - switch (mode) { - case ON_OFF_SPLIT_ON: - ms->kernel_irqchip_allowed = true; - ms->kernel_irqchip_required = true; - ms->kernel_irqchip_split = false; - break; - case ON_OFF_SPLIT_OFF: - ms->kernel_irqchip_allowed = false; - ms->kernel_irqchip_required = false; - ms->kernel_irqchip_split = false; - break; - case ON_OFF_SPLIT_SPLIT: - ms->kernel_irqchip_allowed = true; - ms->kernel_irqchip_required = true; - ms->kernel_irqchip_split = true; - break; - default: - /* The value was checked in visit_type_OnOffSplit() above. If - * we get here, then something is wrong in QEMU. - */ - abort(); - } - } -} - -static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v, - const char *name, void *opaque, - Error **errp) -{ - MachineState *ms = MACHINE(obj); - int64_t value = ms->kvm_shadow_mem; - - visit_type_int(v, name, &value, errp); -} - -static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v, - const char *name, void *opaque, - Error **errp) -{ - MachineState *ms = MACHINE(obj); - Error *error = NULL; - int64_t value; - - visit_type_int(v, name, &value, &error); - if (error) { - error_propagate(errp, error); - return; - } - - ms->kvm_shadow_mem = value; -} - static char *machine_get_kernel(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj); @@ -432,20 +352,6 @@ static void machine_set_graphics(Object *obj, bool value, Error **errp) ms->enable_graphics = value; } -static bool machine_get_igd_gfx_passthru(Object *obj, Error **errp) -{ - MachineState *ms = MACHINE(obj); - - return ms->igd_gfx_passthru; -} - -static void machine_set_igd_gfx_passthru(Object *obj, bool value, Error **errp) -{ - MachineState *ms = MACHINE(obj); - - ms->igd_gfx_passthru = value; -} - static char *machine_get_firmware(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj); @@ -813,23 +719,6 @@ static void machine_class_init(ObjectClass *oc, void *data) mc->numa_mem_align_shift = 23; mc->numa_auto_assign_ram = numa_default_auto_assign_ram; - object_class_property_add_str(oc, "accel", - machine_get_accel, machine_set_accel, &error_abort); - object_class_property_set_description(oc, "accel", - "Accelerator list", &error_abort); - - object_class_property_add(oc, "kernel-irqchip", "on|off|split", - NULL, machine_set_kernel_irqchip, - NULL, NULL, &error_abort); - object_class_property_set_description(oc, "kernel-irqchip", - "Configure KVM in-kernel irqchip", &error_abort); - - object_class_property_add(oc, "kvm-shadow-mem", "int", - machine_get_kvm_shadow_mem, machine_set_kvm_shadow_mem, - NULL, NULL, &error_abort); - object_class_property_set_description(oc, "kvm-shadow-mem", - "KVM shadow MMU size", &error_abort); - object_class_property_add_str(oc, "kernel", machine_get_kernel, machine_set_kernel, &error_abort); object_class_property_set_description(oc, "kernel", @@ -887,12 +776,6 @@ static void machine_class_init(ObjectClass *oc, void *data) object_class_property_set_description(oc, "graphics", "Set on/off to enable/disable graphics emulation", &error_abort); - object_class_property_add_bool(oc, "igd-passthru", - machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru, - &error_abort); - object_class_property_set_description(oc, "igd-passthru", - "Set on/off to enable/disable igd passthrou", &error_abort); - object_class_property_add_str(oc, "firmware", machine_get_firmware, machine_set_firmware, &error_abort); @@ -935,9 +818,6 @@ static void machine_initfn(Object *obj) MachineState *ms = MACHINE(obj); MachineClass *mc = MACHINE_GET_CLASS(obj); - ms->kernel_irqchip_allowed = true; - ms->kernel_irqchip_split = mc->default_kernel_irqchip_split; - ms->kvm_shadow_mem = -1; ms->dump_guest_core = true; ms->mem_merge = true; ms->enable_graphics = true; @@ -976,7 +856,6 @@ static void machine_finalize(Object *obj) { MachineState *ms = MACHINE(obj); - g_free(ms->accel); g_free(ms->kernel_filename); g_free(ms->initrd_filename); g_free(ms->kernel_cmdline); @@ -994,26 +873,6 @@ bool machine_usb(MachineState *machine) return machine->usb; } -bool machine_kernel_irqchip_allowed(MachineState *machine) -{ - return machine->kernel_irqchip_allowed; -} - -bool machine_kernel_irqchip_required(MachineState *machine) -{ - return machine->kernel_irqchip_required; -} - -bool machine_kernel_irqchip_split(MachineState *machine) -{ - return machine->kernel_irqchip_split; -} - -int machine_kvm_shadow_mem(MachineState *machine) -{ - return machine->kvm_shadow_mem; -} - int machine_phandle_start(MachineState *machine) { return machine->phandle_start; diff --git a/hw/core/qdev.c b/hw/core/qdev.c index cf1ba28fe3..82d3ee590a 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -820,12 +820,12 @@ static bool device_get_realized(Object *obj, Error **errp) return dev->realized; } -static bool check_only_migratable(Object *obj, Error **err) +static bool check_only_migratable(Object *obj, Error **errp) { DeviceClass *dc = DEVICE_GET_CLASS(obj); if (!vmstate_check_only_migratable(dc->vmsd)) { - error_setg(err, "Device %s is not migratable, but " + error_setg(errp, "Device %s is not migratable, but " "--only-migratable was specified", object_get_typename(obj)); return false; @@ -874,10 +874,9 @@ static void device_set_realized(Object *obj, bool value, Error **errp) if (dc->realize) { dc->realize(dev, &local_err); - } - - if (local_err != NULL) { - goto fail; + if (local_err != NULL) { + goto fail; + } } DEVICE_LISTENER_CALL(realize, Forward, dev); @@ -918,27 +917,26 @@ static void device_set_realized(Object *obj, bool value, Error **errp) } } else if (!value && dev->realized) { - Error **local_errp = NULL; + /* We want local_err to track only the first error */ QLIST_FOREACH(bus, &dev->child_bus, sibling) { - local_errp = local_err ? NULL : &local_err; object_property_set_bool(OBJECT(bus), false, "realized", - local_errp); + local_err ? NULL : &local_err); } if (qdev_get_vmsd(dev)) { vmstate_unregister(dev, qdev_get_vmsd(dev), dev); } if (dc->unrealize) { - local_errp = local_err ? NULL : &local_err; - dc->unrealize(dev, local_errp); + dc->unrealize(dev, local_err ? NULL : &local_err); } dev->pending_deleted_event = true; DEVICE_LISTENER_CALL(unrealize, Reverse, dev); - } - if (local_err != NULL) { - goto fail; + if (local_err != NULL) { + goto fail; + } } + assert(local_err == NULL); dev->realized = value; return; @@ -976,7 +974,7 @@ static bool device_get_hotpluggable(Object *obj, Error **errp) qbus_is_hotpluggable(dev->parent_bus)); } -static bool device_get_hotplugged(Object *obj, Error **err) +static bool device_get_hotplugged(Object *obj, Error **errp) { DeviceState *dev = DEVICE(obj); diff --git a/hw/display/vga-isa-mm.c b/hw/display/vga-isa-mm.c index e9c43e5530..7321b7a06d 100644 --- a/hw/display/vga-isa-mm.c +++ b/hw/display/vga-isa-mm.c @@ -106,6 +106,9 @@ int isa_vga_mm_init(hwaddr vram_base, s->vga.con = graphic_console_init(NULL, 0, s->vga.hw_ops, s); - vga_init_vbe(&s->vga, NULL, address_space); + memory_region_add_subregion(address_space, + VBE_DISPI_LFB_PHYSICAL_ADDRESS, + &s->vga.vram); + return 0; } diff --git a/hw/display/vga-isa.c b/hw/display/vga-isa.c index 873e5e9706..08a2730db5 100644 --- a/hw/display/vga-isa.c +++ b/hw/display/vga-isa.c @@ -76,7 +76,9 @@ static void vga_isa_realizefn(DeviceState *dev, Error **errp) memory_region_set_coalescing(vga_io_memory); s->con = graphic_console_init(DEVICE(dev), 0, s->hw_ops, s); - vga_init_vbe(s, OBJECT(dev), isa_address_space(isadev)); + memory_region_add_subregion(isa_address_space(isadev), + VBE_DISPI_LFB_PHYSICAL_ADDRESS, + &s->vram); /* ROM BIOS */ rom_add_vga(VGABIOS_FILENAME); } diff --git a/hw/display/vga-pci.c b/hw/display/vga-pci.c index a27b88122d..cfe095713e 100644 --- a/hw/display/vga-pci.c +++ b/hw/display/vga-pci.c @@ -264,11 +264,6 @@ static void pci_std_vga_realize(PCIDevice *dev, Error **errp) pci_register_bar(&d->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio); } - - if (!dev->rom_bar) { - /* compatibility with pc-0.13 and older */ - vga_init_vbe(s, OBJECT(dev), pci_address_space(dev)); - } } static void pci_std_vga_init(Object *obj) diff --git a/hw/display/vga.c b/hw/display/vga.c index 82ebe53610..061fd9ab8f 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -2301,17 +2301,3 @@ void vga_init(VGACommonState *s, Object *obj, MemoryRegion *address_space, portio_list_add(&s->vbe_port_list, address_space_io, 0x1ce); } } - -void vga_init_vbe(VGACommonState *s, Object *obj, MemoryRegion *system_memory) -{ - /* With pc-0.12 and below we map both the PCI BAR and the fixed VBE region, - * so use an alias to avoid double-mapping the same region. - */ - memory_region_init_alias(&s->vram_vbe, obj, "vram.vbe", - &s->vram, 0, memory_region_size(&s->vram)); - /* XXX: use optimized standard vga accesses */ - memory_region_add_subregion(system_memory, - VBE_DISPI_LFB_PHYSICAL_ADDRESS, - &s->vram_vbe); - s->vbe_mapped = 1; -} diff --git a/hw/display/vga_int.h b/hw/display/vga_int.h index 55c418eab5..847e784ca6 100644 --- a/hw/display/vga_int.h +++ b/hw/display/vga_int.h @@ -60,7 +60,6 @@ typedef struct VGACommonState { MemoryRegion *legacy_address_space; uint8_t *vram_ptr; MemoryRegion vram; - MemoryRegion vram_vbe; uint32_t vram_size; uint32_t vram_size_mb; /* property */ uint32_t vbe_size; @@ -106,7 +105,6 @@ typedef struct VGACommonState { uint32_t vbe_start_addr; uint32_t vbe_line_offset; uint32_t vbe_bank_mask; - int vbe_mapped; /* display refresh support */ QemuConsole *con; uint32_t font_offsets[2]; @@ -178,7 +176,6 @@ void vga_invalidate_scanlines(VGACommonState *s, int y1, int y2); int vga_ioport_invalid(VGACommonState *s, uint32_t addr); -void vga_init_vbe(VGACommonState *s, Object *obj, MemoryRegion *address_space); uint32_t vbe_ioport_read_data(void *opaque, uint32_t addr); void vbe_ioport_write_index(void *opaque, uint32_t addr, uint32_t val); void vbe_ioport_write_data(void *opaque, uint32_t addr, uint32_t val); diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c index 23dc8910cc..ead754eccf 100644 --- a/hw/display/vmware_vga.c +++ b/hw/display/vmware_vga.c @@ -1312,11 +1312,6 @@ static void pci_vmsvga_realize(PCIDevice *dev, Error **errp) &s->chip.vga.vram); pci_register_bar(dev, 2, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->chip.fifo_ram); - - if (!dev->rom_bar) { - /* compatibility with pc-0.13 and older */ - vga_init_vbe(&s->chip.vga, OBJECT(dev), pci_address_space(dev)); - } } static Property vga_vmware_properties[] = { diff --git a/hw/hppa/hppa_sys.h b/hw/hppa/hppa_sys.h index 43d25d21fc..4e5019695e 100644 --- a/hw/hppa/hppa_sys.h +++ b/hw/hppa/hppa_sys.h @@ -6,7 +6,8 @@ #include "hw/pci/pci.h" #include "hw/pci/pci_host.h" #include "hw/ide.h" -#include "hw/i386/pc.h" +#include "hw/boards.h" +#include "hw/intc/i8259.h" #include "hppa_hardware.h" diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c index b30aba6d54..5d0de26140 100644 --- a/hw/hppa/machine.c +++ b/hw/hppa/machine.c @@ -19,6 +19,7 @@ #include "hppa_sys.h" #include "qemu/units.h" #include "qapi/error.h" +#include "net/net.h" #include "qemu/log.h" #define MAX_IDE_BUS 2 diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 6ebf31c310..da8ce82725 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -546,14 +546,14 @@ uint16_t hyperv_hcall_post_message(uint64_t param, bool fast) } ret = HV_STATUS_INVALID_CONNECTION_ID; - rcu_read_lock(); - QLIST_FOREACH_RCU(mh, &msg_handlers, link) { - if (mh->conn_id == (msg->connection_id & HV_CONNECTION_ID_MASK)) { - ret = mh->handler(msg, mh->data); - break; + WITH_RCU_READ_LOCK_GUARD() { + QLIST_FOREACH_RCU(mh, &msg_handlers, link) { + if (mh->conn_id == (msg->connection_id & HV_CONNECTION_ID_MASK)) { + ret = mh->handler(msg, mh->data); + break; + } } } - rcu_read_unlock(); unmap: cpu_physical_memory_unmap(msg, len, 0, 0); @@ -619,7 +619,6 @@ int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast) { - uint16_t ret; EventFlagHandler *handler; if (unlikely(!fast)) { @@ -645,15 +644,12 @@ uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast) return HV_STATUS_INVALID_HYPERCALL_INPUT; } - ret = HV_STATUS_INVALID_CONNECTION_ID; - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); QLIST_FOREACH_RCU(handler, &event_flag_handlers, link) { if (handler->conn_id == param) { event_notifier_set(handler->notifier); - ret = 0; - break; + return 0; } } - rcu_read_unlock(); - return ret; + return HV_STATUS_INVALID_CONNECTION_ID; } diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index 5a494342ea..91cf5843b4 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -103,11 +103,17 @@ config MICROVM select MC146818RTC select VIRTIO_MMIO +config X86_IOMMU + bool + depends on PC + config VTD bool + select X86_IOMMU config AMD_IOMMU bool + select X86_IOMMU config VMPORT bool diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs index 0d195b5210..8ce1b26533 100644 --- a/hw/i386/Makefile.objs +++ b/hw/i386/Makefile.objs @@ -1,17 +1,19 @@ obj-$(CONFIG_KVM) += kvm/ obj-y += e820_memory_layout.o multiboot.o obj-y += x86.o -obj-y += pc.o +obj-$(CONFIG_PC) += pc.o pc_sysfw.o obj-$(CONFIG_I440FX) += pc_piix.o obj-$(CONFIG_Q35) += pc_q35.o obj-$(CONFIG_MICROVM) += microvm.o -obj-y += fw_cfg.o pc_sysfw.o -obj-y += x86-iommu.o +obj-y += fw_cfg.o +obj-$(CONFIG_X86_IOMMU) += x86-iommu.o +obj-$(call lnot,$(CONFIG_X86_IOMMU)) += x86-iommu-stub.o obj-$(CONFIG_VTD) += intel_iommu.o obj-$(CONFIG_AMD_IOMMU) += amd_iommu.o obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-$(CONFIG_VMPORT) += vmport.o obj-$(CONFIG_VMMOUSE) += vmmouse.o +obj-$(CONFIG_PC) += port92.o obj-y += kvmvapic.o -obj-y += acpi-build.o +obj-$(CONFIG_PC) += acpi-build.o diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 12ff55fcfb..7b8da62d41 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -53,6 +53,7 @@ /* Supported chipsets: */ #include "hw/southbridge/piix.h" #include "hw/acpi/pcihp.h" +#include "hw/i386/fw_cfg.h" #include "hw/i386/ich9.h" #include "hw/pci/pci_bus.h" #include "hw/pci-host/q35.h" diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index d55dbf07fc..b1175e52c7 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -1533,7 +1533,7 @@ static void amdvi_reset(DeviceState *dev) amdvi_init(s); } -static void amdvi_realize(DeviceState *dev, Error **err) +static void amdvi_realize(DeviceState *dev, Error **errp) { int ret = 0; AMDVIState *s = AMD_IOMMU_DEVICE(dev); @@ -1549,21 +1549,21 @@ static void amdvi_realize(DeviceState *dev, Error **err) /* This device should take care of IOMMU PCI properties */ x86_iommu->type = TYPE_AMD; qdev_set_parent_bus(DEVICE(&s->pci), &bus->qbus); - object_property_set_bool(OBJECT(&s->pci), true, "realized", err); + object_property_set_bool(OBJECT(&s->pci), true, "realized", errp); ret = pci_add_capability(&s->pci.dev, AMDVI_CAPAB_ID_SEC, 0, - AMDVI_CAPAB_SIZE, err); + AMDVI_CAPAB_SIZE, errp); if (ret < 0) { return; } s->capab_offset = ret; ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_MSI, 0, - AMDVI_CAPAB_REG_SIZE, err); + AMDVI_CAPAB_REG_SIZE, errp); if (ret < 0) { return; } ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_HT, 0, - AMDVI_CAPAB_REG_SIZE, err); + AMDVI_CAPAB_REG_SIZE, errp); if (ret < 0) { return; } @@ -1578,8 +1578,8 @@ static void amdvi_realize(DeviceState *dev, Error **err) sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mmio); sysbus_mmio_map(SYS_BUS_DEVICE(s), 0, AMDVI_BASE_ADDR); pci_setup_iommu(bus, amdvi_host_dma_iommu, s); - s->devid = object_property_get_int(OBJECT(&s->pci), "addr", err); - msi_init(&s->pci.dev, 0, 1, true, false, err); + s->devid = object_property_get_int(OBJECT(&s->pci), "addr", errp); + msi_init(&s->pci.dev, 0, 1, true, false, errp); amdvi_init(s); } diff --git a/hw/i386/fw_cfg.c b/hw/i386/fw_cfg.c index 39b6bc6052..da60ada594 100644 --- a/hw/i386/fw_cfg.c +++ b/hw/i386/fw_cfg.c @@ -16,12 +16,14 @@ #include "sysemu/numa.h" #include "hw/acpi/acpi.h" #include "hw/firmware/smbios.h" -#include "hw/i386/pc.h" #include "hw/i386/fw_cfg.h" #include "hw/timer/hpet.h" #include "hw/nvram/fw_cfg.h" #include "e820_memory_layout.h" #include "kvm_i386.h" +#include "config-devices.h" + +struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX}; const char *fw_cfg_arch_key_name(uint16_t key) { @@ -46,6 +48,7 @@ const char *fw_cfg_arch_key_name(uint16_t key) void fw_cfg_build_smbios(MachineState *ms, FWCfgState *fw_cfg) { +#ifdef CONFIG_SMBIOS uint8_t *smbios_tables, *smbios_anchor; size_t smbios_tables_len, smbios_anchor_len; struct smbios_phys_mem_area *mem_array; @@ -83,6 +86,7 @@ void fw_cfg_build_smbios(MachineState *ms, FWCfgState *fw_cfg) fw_cfg_add_file(fw_cfg, "etc/smbios/smbios-anchor", smbios_anchor, smbios_anchor_len); } +#endif } FWCfgState *fw_cfg_arch_create(MachineState *ms, @@ -114,8 +118,10 @@ FWCfgState *fw_cfg_arch_create(MachineState *ms, */ fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, apic_id_limit); fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); +#ifdef CONFIG_ACPI fw_cfg_add_bytes(fw_cfg, FW_CFG_ACPI_TABLES, acpi_tables, acpi_tables_len); +#endif fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, kvm_allows_irq0_override()); fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, diff --git a/hw/i386/fw_cfg.h b/hw/i386/fw_cfg.h index e0856a3769..9e74278779 100644 --- a/hw/i386/fw_cfg.h +++ b/hw/i386/fw_cfg.h @@ -12,6 +12,8 @@ #include "hw/boards.h" #include "hw/nvram/fw_cfg.h" +#define FW_CFG_IO_BASE 0x510 + #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0) #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1) #define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2) diff --git a/hw/i386/kvm/Makefile.objs b/hw/i386/kvm/Makefile.objs index 4224ed900e..0c8d5f2dee 100644 --- a/hw/i386/kvm/Makefile.objs +++ b/hw/i386/kvm/Makefile.objs @@ -1 +1,5 @@ -obj-y += clock.o apic.o i8259.o ioapic.o i8254.o +obj-y += clock.o +obj-$(CONFIG_APIC) += apic.o +obj-$(CONFIG_IOAPIC) += ioapic.o +obj-$(CONFIG_I8254) += i8254.o +obj-$(CONFIG_I8259) += i8259.o diff --git a/hw/i386/kvm/i8259.c b/hw/i386/kvm/i8259.c index d0c1b1deac..e404fdcdac 100644 --- a/hw/i386/kvm/i8259.c +++ b/hw/i386/kvm/i8259.c @@ -12,6 +12,7 @@ #include "qemu/osdep.h" #include "hw/isa/i8259_internal.h" +#include "hw/intc/i8259.h" #include "qemu/module.h" #include "hw/i386/apic_internal.h" #include "hw/irq.h" diff --git a/hw/i386/kvm/ioapic.c b/hw/i386/kvm/ioapic.c index f94729c565..973e2b2af1 100644 --- a/hw/i386/kvm/ioapic.c +++ b/hw/i386/kvm/ioapic.c @@ -12,7 +12,7 @@ #include "qemu/osdep.h" #include "monitor/monitor.h" -#include "hw/i386/pc.h" +#include "hw/i386/x86.h" #include "hw/irq.h" #include "hw/qdev-properties.h" #include "hw/i386/ioapic_internal.h" @@ -48,18 +48,6 @@ void kvm_pc_setup_irq_routing(bool pci_enabled) } } -void kvm_pc_gsi_handler(void *opaque, int n, int level) -{ - GSIState *s = opaque; - - if (n < ISA_NUM_IRQS) { - /* Kernel will forward to both PIC and IOAPIC */ - qemu_set_irq(s->i8259_irq[n], level); - } else { - qemu_set_irq(s->ioapic_irq[n], level); - } -} - typedef struct KVMIOAPICState KVMIOAPICState; struct KVMIOAPICState { diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index def37e60f7..827ce29e58 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -32,8 +32,8 @@ #include "hw/kvm/clock.h" #include "hw/i386/microvm.h" #include "hw/i386/x86.h" -#include "hw/i386/pc.h" #include "target/i386/cpu.h" +#include "hw/intc/i8259.h" #include "hw/timer/i8254.h" #include "hw/rtc/mc146818rtc.h" #include "hw/char/serial.h" @@ -132,7 +132,7 @@ static void microvm_devices_init(MicrovmMachineState *mms) if (mms->pic == ON_OFF_AUTO_ON || mms->pic == ON_OFF_AUTO_AUTO) { qemu_irq *i8259; - i8259 = i8259_init(isa_bus, pc_allocate_cpu_irq()); + i8259 = i8259_init(isa_bus, x86_allocate_cpu_irq()); for (i = 0; i < ISA_NUM_IRQS; i++) { gsi_state->i8259_irq[i] = i8259[i]; } diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 58867f987d..42014b06de 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -44,6 +44,7 @@ #include "migration/vmstate.h" #include "multiboot.h" #include "hw/rtc/mc146818rtc.h" +#include "hw/intc/i8259.h" #include "hw/dma/i8257.h" #include "hw/timer/i8254.h" #include "hw/input/i8042.h" @@ -90,18 +91,7 @@ #include "config-devices.h" #include "e820_memory_layout.h" #include "fw_cfg.h" - -/* debug PC/ISA interrupts */ -//#define DEBUG_IRQ - -#ifdef DEBUG_IRQ -#define DPRINTF(fmt, ...) \ - do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0) -#else -#define DPRINTF(fmt, ...) -#endif - -struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX}; +#include "trace.h" GlobalProperty pc_compat_4_2[] = {}; const size_t pc_compat_4_2_len = G_N_ELEMENTS(pc_compat_4_2); @@ -347,17 +337,6 @@ GlobalProperty pc_compat_1_4[] = { }; const size_t pc_compat_1_4_len = G_N_ELEMENTS(pc_compat_1_4); -void gsi_handler(void *opaque, int n, int level) -{ - GSIState *s = opaque; - - DPRINTF("pc: %s GSI %d\n", level ? "raising" : "lowering", n); - if (n < ISA_NUM_IRQS) { - qemu_set_irq(s->i8259_irq[n], level); - } - qemu_set_irq(s->ioapic_irq[n], level); -} - GSIState *pc_gsi_create(qemu_irq **irqs, bool pci_enabled) { GSIState *s; @@ -365,10 +344,8 @@ GSIState *pc_gsi_create(qemu_irq **irqs, bool pci_enabled) s = g_new0(GSIState, 1); if (kvm_ioapic_in_kernel()) { kvm_pc_setup_irq_routing(pci_enabled); - *irqs = qemu_allocate_irqs(kvm_pc_gsi_handler, s, GSI_NUM_PINS); - } else { - *irqs = qemu_allocate_irqs(gsi_handler, s, GSI_NUM_PINS); } + *irqs = qemu_allocate_irqs(gsi_handler, s, GSI_NUM_PINS); return s; } @@ -397,55 +374,6 @@ static uint64_t ioportF0_read(void *opaque, hwaddr addr, unsigned size) return 0xffffffffffffffffULL; } -/* TSC handling */ -uint64_t cpu_get_tsc(CPUX86State *env) -{ - return cpu_get_ticks(); -} - -/* IRQ handling */ -int cpu_get_pic_interrupt(CPUX86State *env) -{ - X86CPU *cpu = env_archcpu(env); - int intno; - - if (!kvm_irqchip_in_kernel()) { - intno = apic_get_interrupt(cpu->apic_state); - if (intno >= 0) { - return intno; - } - /* read the irq from the PIC */ - if (!apic_accept_pic_intr(cpu->apic_state)) { - return -1; - } - } - - intno = pic_read_irq(isa_pic); - return intno; -} - -static void pic_irq_request(void *opaque, int irq, int level) -{ - CPUState *cs = first_cpu; - X86CPU *cpu = X86_CPU(cs); - - DPRINTF("pic_irqs: %s irq %d\n", level? "raise" : "lower", irq); - if (cpu->apic_state && !kvm_irqchip_in_kernel()) { - CPU_FOREACH(cs) { - cpu = X86_CPU(cs); - if (apic_accept_pic_intr(cpu->apic_state)) { - apic_deliver_pic_intr(cpu->apic_state, level); - } - } - } else { - if (level) { - cpu_interrupt(cs, CPU_INTERRUPT_HARD); - } else { - cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); - } - } -} - /* PC cmos mappings */ #define REG_EQUIPMENT_BYTE 0x14 @@ -745,124 +673,6 @@ void pc_cmos_init(PCMachineState *pcms, qemu_register_reset(pc_cmos_init_late, &arg); } -#define TYPE_PORT92 "port92" -#define PORT92(obj) OBJECT_CHECK(Port92State, (obj), TYPE_PORT92) - -/* port 92 stuff: could be split off */ -typedef struct Port92State { - ISADevice parent_obj; - - MemoryRegion io; - uint8_t outport; - qemu_irq a20_out; -} Port92State; - -static void port92_write(void *opaque, hwaddr addr, uint64_t val, - unsigned size) -{ - Port92State *s = opaque; - int oldval = s->outport; - - DPRINTF("port92: write 0x%02" PRIx64 "\n", val); - s->outport = val; - qemu_set_irq(s->a20_out, (val >> 1) & 1); - if ((val & 1) && !(oldval & 1)) { - qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); - } -} - -static uint64_t port92_read(void *opaque, hwaddr addr, - unsigned size) -{ - Port92State *s = opaque; - uint32_t ret; - - ret = s->outport; - DPRINTF("port92: read 0x%02x\n", ret); - return ret; -} - -static void port92_init(ISADevice *dev, qemu_irq a20_out) -{ - qdev_connect_gpio_out_named(DEVICE(dev), PORT92_A20_LINE, 0, a20_out); -} - -static const VMStateDescription vmstate_port92_isa = { - .name = "port92", - .version_id = 1, - .minimum_version_id = 1, - .fields = (VMStateField[]) { - VMSTATE_UINT8(outport, Port92State), - VMSTATE_END_OF_LIST() - } -}; - -static void port92_reset(DeviceState *d) -{ - Port92State *s = PORT92(d); - - s->outport &= ~1; -} - -static const MemoryRegionOps port92_ops = { - .read = port92_read, - .write = port92_write, - .impl = { - .min_access_size = 1, - .max_access_size = 1, - }, - .endianness = DEVICE_LITTLE_ENDIAN, -}; - -static void port92_initfn(Object *obj) -{ - Port92State *s = PORT92(obj); - - memory_region_init_io(&s->io, OBJECT(s), &port92_ops, s, "port92", 1); - - s->outport = 0; - - qdev_init_gpio_out_named(DEVICE(obj), &s->a20_out, PORT92_A20_LINE, 1); -} - -static void port92_realizefn(DeviceState *dev, Error **errp) -{ - ISADevice *isadev = ISA_DEVICE(dev); - Port92State *s = PORT92(dev); - - isa_register_ioport(isadev, &s->io, 0x92); -} - -static void port92_class_initfn(ObjectClass *klass, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(klass); - - dc->realize = port92_realizefn; - dc->reset = port92_reset; - dc->vmsd = &vmstate_port92_isa; - /* - * Reason: unlike ordinary ISA devices, this one needs additional - * wiring: its A20 output line needs to be wired up by - * port92_init(). - */ - dc->user_creatable = false; -} - -static const TypeInfo port92_info = { - .name = TYPE_PORT92, - .parent = TYPE_ISA_DEVICE, - .instance_size = sizeof(Port92State), - .instance_init = port92_initfn, - .class_init = port92_class_initfn, -}; - -static void port92_register_types(void) -{ - type_register_static(&port92_info); -} - -type_init(port92_register_types) - static void handle_a20_line_change(void *opaque, int irq, int level) { X86CPU *cpu = opaque; @@ -889,16 +699,6 @@ void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd) nb_ne2k++; } -DeviceState *cpu_get_current_apic(void) -{ - if (current_cpu) { - X86CPU *cpu = X86_CPU(current_cpu); - return cpu->apic_state; - } else { - return NULL; - } -} - void pc_acpi_smi_interrupt(void *opaque, int irq, int level) { X86CPU *cpu = opaque; @@ -1294,11 +1094,6 @@ uint64_t pc_pci_hole64_start(void) return ROUND_UP(hole64_start, 1 * GiB); } -qemu_irq pc_allocate_cpu_irq(void) -{ - return qemu_allocate_irq(pic_irq_request, NULL, 0); -} - DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus) { DeviceState *dev = NULL; @@ -1365,11 +1160,12 @@ static void pc_superio_init(ISABus *isa_bus, bool create_fdctrl, bool no_vmport) qdev_prop_set_ptr(dev, "ps2_mouse", i8042); qdev_init_nofail(dev); } - port92 = isa_create_simple(isa_bus, "port92"); + port92 = isa_create_simple(isa_bus, TYPE_PORT92); a20_line = qemu_allocate_irqs(handle_a20_line_change, first_cpu, 2); i8042_setup_a20_line(i8042, a20_line[0]); - port92_init(port92, a20_line[1]); + qdev_connect_gpio_out_named(DEVICE(port92), + PORT92_A20_LINE, 0, a20_line[1]); g_free(a20_line); } @@ -1475,7 +1271,7 @@ void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs) } else if (xen_enabled()) { i8259 = xen_interrupt_controller_init(); } else { - i8259 = i8259_init(isa_bus, pc_allocate_cpu_irq()); + i8259 = i8259_init(isa_bus, x86_allocate_cpu_irq()); } for (size_t i = 0; i < ISA_NUM_IRQS; i++) { @@ -1485,30 +1281,6 @@ void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs) g_free(i8259); } -void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) -{ - DeviceState *dev; - SysBusDevice *d; - unsigned int i; - - if (kvm_ioapic_in_kernel()) { - dev = qdev_create(NULL, TYPE_KVM_IOAPIC); - } else { - dev = qdev_create(NULL, TYPE_IOAPIC); - } - if (parent_name) { - object_property_add_child(object_resolve_path(parent_name, NULL), - "ioapic", OBJECT(dev), NULL); - } - qdev_init_nofail(dev); - d = SYS_BUS_DEVICE(dev); - sysbus_mmio_map(d, 0, IO_APIC_DEFAULT_ADDRESS); - - for (i = 0; i < IOAPIC_NUM_PINS; i++) { - gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i); - } -} - static void pc_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp) { @@ -2032,48 +1804,6 @@ static void pc_machine_set_vmport(Object *obj, Visitor *v, const char *name, visit_type_OnOffAuto(v, name, &pcms->vmport, errp); } -bool pc_machine_is_smm_enabled(PCMachineState *pcms) -{ - bool smm_available = false; - - if (pcms->smm == ON_OFF_AUTO_OFF) { - return false; - } - - if (tcg_enabled() || qtest_enabled()) { - smm_available = true; - } else if (kvm_enabled()) { - smm_available = kvm_has_smm(); - } - - if (smm_available) { - return true; - } - - if (pcms->smm == ON_OFF_AUTO_ON) { - error_report("System Management Mode not supported by this hypervisor."); - exit(1); - } - return false; -} - -static void pc_machine_get_smm(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - PCMachineState *pcms = PC_MACHINE(obj); - OnOffAuto smm = pcms->smm; - - visit_type_OnOffAuto(v, name, &smm, errp); -} - -static void pc_machine_set_smm(Object *obj, Visitor *v, const char *name, - void *opaque, Error **errp) -{ - PCMachineState *pcms = PC_MACHINE(obj); - - visit_type_OnOffAuto(v, name, &pcms->smm, errp); -} - static bool pc_machine_get_smbus(Object *obj, Error **errp) { PCMachineState *pcms = PC_MACHINE(obj); @@ -2120,7 +1850,6 @@ static void pc_machine_initfn(Object *obj) { PCMachineState *pcms = PC_MACHINE(obj); - pcms->smm = ON_OFF_AUTO_AUTO; #ifdef CONFIG_VMPORT pcms->vmport = ON_OFF_AUTO_AUTO; #else @@ -2227,12 +1956,6 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) pc_machine_get_device_memory_region_size, NULL, NULL, NULL, &error_abort); - object_class_property_add(oc, PC_MACHINE_SMM, "OnOffAuto", - pc_machine_get_smm, pc_machine_set_smm, - NULL, NULL, &error_abort); - object_class_property_set_description(oc, PC_MACHINE_SMM, - "Enable SMM (pc & q35)", &error_abort); - object_class_property_add(oc, PC_MACHINE_VMPORT, "OnOffAuto", pc_machine_get_vmport, pc_machine_set_vmport, NULL, NULL, &error_abort); diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index ffb30c32ce..721c7aa64e 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -281,7 +281,7 @@ else { /* TODO: Populate SPD eeprom data. */ pcms->smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, x86ms->gsi[9], smi_irq, - pc_machine_is_smm_enabled(pcms), + x86_machine_is_smm_enabled(x86ms), &piix4_pm); smbus_eeprom_init(pcms->smbus, 8, NULL, 0); @@ -309,9 +309,9 @@ else { static void pc_compat_2_3_fn(MachineState *machine) { - PCMachineState *pcms = PC_MACHINE(machine); + X86MachineState *x86ms = X86_MACHINE(machine); if (kvm_enabled()) { - pcms->smm = ON_OFF_AUTO_OFF; + x86ms->smm = ON_OFF_AUTO_OFF; } } @@ -357,19 +357,13 @@ static void pc_compat_1_3(MachineState *machine) pc_compat_1_4_fn(machine); } -/* PC compat function for pc-0.14 to pc-1.2 */ +/* PC compat function for pc-1.0 to pc-1.2 */ static void pc_compat_1_2(MachineState *machine) { pc_compat_1_3(machine); x86_cpu_change_kvm_default("kvm-pv-eoi", NULL); } -/* PC compat function for pc-0.12 and pc-0.13 */ -static void pc_compat_0_13(MachineState *machine) -{ - pc_compat_1_2(machine); -} - static void pc_init_isa(MachineState *machine) { pc_init1(machine, TYPE_I440FX_PCI_HOST_BRIDGE, TYPE_I440FX_PCI_DEVICE); @@ -745,6 +739,7 @@ static void pc_i440fx_1_3_machine_options(MachineClass *m) pc_i440fx_1_4_machine_options(m); m->hw_version = "1.3.0"; + m->deprecation_reason = "use a newer machine type instead"; x86mc->compat_apic_id_mode = true; compat_props_add(m->compat_props, compat, G_N_ELEMENTS(compat)); } @@ -813,82 +808,6 @@ DEFINE_I440FX_MACHINE(v1_0, "pc-1.0", pc_compat_1_2, pc_i440fx_1_0_machine_options); -static void pc_i440fx_0_15_machine_options(MachineClass *m) -{ - static GlobalProperty compat[] = { - PC_CPU_MODEL_IDS("0.15") - }; - - pc_i440fx_1_0_machine_options(m); - m->hw_version = "0.15"; - m->deprecation_reason = "use a newer machine type instead"; - compat_props_add(m->compat_props, compat, G_N_ELEMENTS(compat)); -} - -DEFINE_I440FX_MACHINE(v0_15, "pc-0.15", pc_compat_1_2, - pc_i440fx_0_15_machine_options); - - -static void pc_i440fx_0_14_machine_options(MachineClass *m) -{ - static GlobalProperty compat[] = { - PC_CPU_MODEL_IDS("0.14") - { "virtio-blk-pci", "event_idx", "off" }, - { "virtio-serial-pci", "event_idx", "off" }, - { "virtio-net-pci", "event_idx", "off" }, - { "virtio-balloon-pci", "event_idx", "off" }, - { "qxl", "revision", "2" }, - { "qxl-vga", "revision", "2" }, - }; - - pc_i440fx_0_15_machine_options(m); - m->hw_version = "0.14"; - compat_props_add(m->compat_props, compat, G_N_ELEMENTS(compat)); -} - -DEFINE_I440FX_MACHINE(v0_14, "pc-0.14", pc_compat_1_2, - pc_i440fx_0_14_machine_options); - -static void pc_i440fx_0_13_machine_options(MachineClass *m) -{ - PCMachineClass *pcmc = PC_MACHINE_CLASS(m); - static GlobalProperty compat[] = { - PC_CPU_MODEL_IDS("0.13") - { TYPE_PCI_DEVICE, "command_serr_enable", "off" }, - { "AC97", "use_broken_id", "1" }, - { "virtio-9p-pci", "vectors", "0" }, - { "VGA", "rombar", "0" }, - { "vmware-svga", "rombar", "0" }, - }; - - pc_i440fx_0_14_machine_options(m); - m->hw_version = "0.13"; - compat_props_add(m->compat_props, compat, G_N_ELEMENTS(compat)); - pcmc->kvmclock_enabled = false; -} - -DEFINE_I440FX_MACHINE(v0_13, "pc-0.13", pc_compat_0_13, - pc_i440fx_0_13_machine_options); - -static void pc_i440fx_0_12_machine_options(MachineClass *m) -{ - static GlobalProperty compat[] = { - PC_CPU_MODEL_IDS("0.12") - { "virtio-serial-pci", "max_ports", "1" }, - { "virtio-serial-pci", "vectors", "0" }, - { "usb-mouse", "serial", "1" }, - { "usb-tablet", "serial", "1" }, - { "usb-kbd", "serial", "1" }, - }; - - pc_i440fx_0_13_machine_options(m); - m->hw_version = "0.12"; - compat_props_add(m->compat_props, compat, G_N_ELEMENTS(compat)); -} - -DEFINE_I440FX_MACHINE(v0_12, "pc-0.12", pc_compat_0_13, - pc_i440fx_0_12_machine_options); - typedef struct { uint16_t gpu_device_id; uint16_t pch_device_id; diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 7398d7baa2..52f45735e4 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -276,7 +276,7 @@ static void pc_q35_init(MachineState *machine) 0xff0104); /* connect pm stuff to lpc */ - ich9_lpc_pm_init(lpc, pc_machine_is_smm_enabled(pcms)); + ich9_lpc_pm_init(lpc, x86_machine_is_smm_enabled(x86ms)); if (pcms->sata_enabled) { /* ahci and SATA device, for q35 1 ahci controller is built-in */ diff --git a/hw/i386/port92.c b/hw/i386/port92.c new file mode 100644 index 0000000000..19866c44ef --- /dev/null +++ b/hw/i386/port92.c @@ -0,0 +1,126 @@ +/* + * QEMU I/O port 0x92 (System Control Port A, to handle Fast Gate A20) + * + * Copyright (c) 2003-2004 Fabrice Bellard + * + * SPDX-License-Identifier: MIT + */ + +#include "qemu/osdep.h" +#include "sysemu/runstate.h" +#include "migration/vmstate.h" +#include "hw/irq.h" +#include "hw/i386/pc.h" +#include "trace.h" + +#define PORT92(obj) OBJECT_CHECK(Port92State, (obj), TYPE_PORT92) + +typedef struct Port92State { + ISADevice parent_obj; + + MemoryRegion io; + uint8_t outport; + qemu_irq a20_out; +} Port92State; + +static void port92_write(void *opaque, hwaddr addr, uint64_t val, + unsigned size) +{ + Port92State *s = opaque; + int oldval = s->outport; + + trace_port92_write(val); + s->outport = val; + qemu_set_irq(s->a20_out, (val >> 1) & 1); + if ((val & 1) && !(oldval & 1)) { + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); + } +} + +static uint64_t port92_read(void *opaque, hwaddr addr, + unsigned size) +{ + Port92State *s = opaque; + uint32_t ret; + + ret = s->outport; + trace_port92_read(ret); + + return ret; +} + +static const VMStateDescription vmstate_port92_isa = { + .name = "port92", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8(outport, Port92State), + VMSTATE_END_OF_LIST() + } +}; + +static void port92_reset(DeviceState *d) +{ + Port92State *s = PORT92(d); + + s->outport &= ~1; +} + +static const MemoryRegionOps port92_ops = { + .read = port92_read, + .write = port92_write, + .impl = { + .min_access_size = 1, + .max_access_size = 1, + }, + .endianness = DEVICE_LITTLE_ENDIAN, +}; + +static void port92_initfn(Object *obj) +{ + Port92State *s = PORT92(obj); + + memory_region_init_io(&s->io, OBJECT(s), &port92_ops, s, "port92", 1); + + s->outport = 0; + + qdev_init_gpio_out_named(DEVICE(obj), &s->a20_out, PORT92_A20_LINE, 1); +} + +static void port92_realizefn(DeviceState *dev, Error **errp) +{ + ISADevice *isadev = ISA_DEVICE(dev); + Port92State *s = PORT92(dev); + + isa_register_ioport(isadev, &s->io, 0x92); +} + +static void port92_class_initfn(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->realize = port92_realizefn; + dc->reset = port92_reset; + dc->vmsd = &vmstate_port92_isa; + /* + * Reason: unlike ordinary ISA devices, this one needs additional + * wiring: its A20 output line needs to be wired up with + * qdev_connect_gpio_out_named(). + */ + dc->user_creatable = false; +} + +static const TypeInfo port92_info = { + .name = TYPE_PORT92, + .parent = TYPE_ISA_DEVICE, + .instance_size = sizeof(Port92State), + .instance_init = port92_initfn, + .class_init = port92_class_initfn, +}; + +static void port92_register_types(void) +{ + type_register_static(&port92_info); +} + +type_init(port92_register_types) diff --git a/hw/i386/trace-events b/hw/i386/trace-events index c8bc464bc5..e48bef2b0d 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -111,3 +111,11 @@ amdvi_ir_irte_ga_val(uint64_t hi, uint64_t lo) "hi 0x%"PRIx64" lo 0x%"PRIx64 # vmport.c vmport_register(unsigned char command, void *func, void *opaque) "command: 0x%02x func: %p opaque: %p" vmport_command(unsigned char command) "command: 0x%02x" + +# x86.c +x86_gsi_interrupt(int irqn, int level) "GSI interrupt #%d level:%d" +x86_pic_interrupt(int irqn, int level) "PIC interrupt #%d level:%d" + +# port92.c +port92_read(uint8_t val) "port92: read 0x%02x" +port92_write(uint8_t val) "port92: write 0x%02x" diff --git a/hw/i386/x86-iommu-stub.c b/hw/i386/x86-iommu-stub.c new file mode 100644 index 0000000000..03576cdccb --- /dev/null +++ b/hw/i386/x86-iommu-stub.c @@ -0,0 +1,34 @@ +/* + * Stubs for X86 IOMMU emulation + * + * Copyright (C) 2019 Red Hat, Inc. + * + * Author: Paolo Bonzini + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License along + * with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "hw/i386/x86-iommu.h" + +void x86_iommu_iec_register_notifier(X86IOMMUState *iommu, + iec_notify_fn fn, void *data) +{ +} + +X86IOMMUState *x86_iommu_get_default(void) +{ + return NULL; +} + diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 394edc2f72..d8bb5c2a96 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -34,18 +34,23 @@ #include "sysemu/numa.h" #include "sysemu/replay.h" #include "sysemu/sysemu.h" +#include "trace.h" #include "hw/i386/x86.h" #include "target/i386/cpu.h" #include "hw/i386/topology.h" #include "hw/i386/fw_cfg.h" +#include "hw/intc/i8259.h" #include "hw/acpi/cpu_hotplug.h" +#include "hw/irq.h" #include "hw/nmi.h" #include "hw/loader.h" #include "multiboot.h" #include "elf.h" #include "standard-headers/asm-x86/bootparam.h" +#include "config-devices.h" +#include "kvm_i386.h" #define BIOS_FILENAME "bios.bin" @@ -220,6 +225,105 @@ static long get_file_size(FILE *f) return size; } +/* TSC handling */ +uint64_t cpu_get_tsc(CPUX86State *env) +{ + return cpu_get_ticks(); +} + +/* IRQ handling */ +static void pic_irq_request(void *opaque, int irq, int level) +{ + CPUState *cs = first_cpu; + X86CPU *cpu = X86_CPU(cs); + + trace_x86_pic_interrupt(irq, level); + if (cpu->apic_state && !kvm_irqchip_in_kernel()) { + CPU_FOREACH(cs) { + cpu = X86_CPU(cs); + if (apic_accept_pic_intr(cpu->apic_state)) { + apic_deliver_pic_intr(cpu->apic_state, level); + } + } + } else { + if (level) { + cpu_interrupt(cs, CPU_INTERRUPT_HARD); + } else { + cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); + } + } +} + +qemu_irq x86_allocate_cpu_irq(void) +{ + return qemu_allocate_irq(pic_irq_request, NULL, 0); +} + +int cpu_get_pic_interrupt(CPUX86State *env) +{ + X86CPU *cpu = env_archcpu(env); + int intno; + + if (!kvm_irqchip_in_kernel()) { + intno = apic_get_interrupt(cpu->apic_state); + if (intno >= 0) { + return intno; + } + /* read the irq from the PIC */ + if (!apic_accept_pic_intr(cpu->apic_state)) { + return -1; + } + } + + intno = pic_read_irq(isa_pic); + return intno; +} + +DeviceState *cpu_get_current_apic(void) +{ + if (current_cpu) { + X86CPU *cpu = X86_CPU(current_cpu); + return cpu->apic_state; + } else { + return NULL; + } +} + +void gsi_handler(void *opaque, int n, int level) +{ + GSIState *s = opaque; + + trace_x86_gsi_interrupt(n, level); + if (n < ISA_NUM_IRQS) { + /* Under KVM, Kernel will forward to both PIC and IOAPIC */ + qemu_set_irq(s->i8259_irq[n], level); + } + qemu_set_irq(s->ioapic_irq[n], level); +} + +void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name) +{ + DeviceState *dev; + SysBusDevice *d; + unsigned int i; + + assert(parent_name); + if (kvm_ioapic_in_kernel()) { + dev = qdev_create(NULL, TYPE_KVM_IOAPIC); + } else { + dev = qdev_create(NULL, TYPE_IOAPIC); + } + object_property_add_child(object_resolve_path(parent_name, NULL), + "ioapic", OBJECT(dev), NULL); + qdev_init_nofail(dev); + d = SYS_BUS_DEVICE(dev); + sysbus_mmio_map(d, 0, IO_APIC_DEFAULT_ADDRESS); + + for (i = 0; i < IOAPIC_NUM_PINS; i++) { + gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i); + } +} + struct setup_data { uint64_t next; uint32_t type; @@ -745,10 +849,53 @@ static void x86_machine_set_max_ram_below_4g(Object *obj, Visitor *v, x86ms->max_ram_below_4g = value; } +bool x86_machine_is_smm_enabled(X86MachineState *x86ms) +{ + bool smm_available = false; + + if (x86ms->smm == ON_OFF_AUTO_OFF) { + return false; + } + + if (tcg_enabled() || qtest_enabled()) { + smm_available = true; + } else if (kvm_enabled()) { + smm_available = kvm_has_smm(); + } + + if (smm_available) { + return true; + } + + if (x86ms->smm == ON_OFF_AUTO_ON) { + error_report("System Management Mode not supported by this hypervisor."); + exit(1); + } + return false; +} + +static void x86_machine_get_smm(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + X86MachineState *x86ms = X86_MACHINE(obj); + OnOffAuto smm = x86ms->smm; + + visit_type_OnOffAuto(v, name, &smm, errp); +} + +static void x86_machine_set_smm(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + X86MachineState *x86ms = X86_MACHINE(obj); + + visit_type_OnOffAuto(v, name, &x86ms->smm, errp); +} + static void x86_machine_initfn(Object *obj) { X86MachineState *x86ms = X86_MACHINE(obj); + x86ms->smm = ON_OFF_AUTO_AUTO; x86ms->max_ram_below_4g = 0; /* use default */ x86ms->smp_dies = 1; } @@ -769,9 +916,14 @@ static void x86_machine_class_init(ObjectClass *oc, void *data) object_class_property_add(oc, X86_MACHINE_MAX_RAM_BELOW_4G, "size", x86_machine_get_max_ram_below_4g, x86_machine_set_max_ram_below_4g, NULL, NULL, &error_abort); - object_class_property_set_description(oc, X86_MACHINE_MAX_RAM_BELOW_4G, "Maximum ram below the 4G boundary (32bit boundary)", &error_abort); + + object_class_property_add(oc, X86_MACHINE_SMM, "OnOffAuto", + x86_machine_get_smm, x86_machine_set_smm, + NULL, NULL, &error_abort); + object_class_property_set_description(oc, X86_MACHINE_SMM, + "Enable SMM", &error_abort); } static const TypeInfo x86_machine_info = { diff --git a/hw/input/pckbd.c b/hw/input/pckbd.c index f0acfd86f7..2f09f780ba 100644 --- a/hw/input/pckbd.c +++ b/hw/input/pckbd.c @@ -26,7 +26,6 @@ #include "qemu/log.h" #include "hw/isa/isa.h" #include "migration/vmstate.h" -#include "hw/i386/pc.h" #include "hw/input/ps2.h" #include "hw/irq.h" #include "hw/input/i8042.h" diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig index 5347f8412c..10a680b53a 100644 --- a/hw/intc/Kconfig +++ b/hw/intc/Kconfig @@ -9,6 +9,7 @@ config PL190 config IOAPIC bool + select I8259 config ARM_GIC bool @@ -21,6 +22,7 @@ config OPENPIC config APIC bool select MSI_NONBROKEN + select I8259 config ARM_GIC_KVM bool diff --git a/hw/intc/apic.c b/hw/intc/apic.c index 2a74f7b4bf..bd40467965 100644 --- a/hw/intc/apic.c +++ b/hw/intc/apic.c @@ -22,10 +22,10 @@ #include "hw/i386/apic_internal.h" #include "hw/i386/apic.h" #include "hw/i386/ioapic.h" +#include "hw/intc/i8259.h" #include "hw/pci/msi.h" #include "qemu/host-utils.h" #include "trace.h" -#include "hw/i386/pc.h" #include "hw/i386/apic-msidef.h" #include "qapi/error.h" diff --git a/hw/intc/i8259.c b/hw/intc/i8259.c index 211a98962e..51b27f6a34 100644 --- a/hw/intc/i8259.c +++ b/hw/intc/i8259.c @@ -23,7 +23,7 @@ */ #include "qemu/osdep.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/irq.h" #include "hw/isa/isa.h" #include "qemu/timer.h" diff --git a/hw/intc/i8259_common.c b/hw/intc/i8259_common.c index bd37bb5e68..e7b1a10436 100644 --- a/hw/intc/i8259_common.c +++ b/hw/intc/i8259_common.c @@ -24,7 +24,7 @@ */ #include "qemu/osdep.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/isa/i8259_internal.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" diff --git a/hw/intc/ioapic.c b/hw/intc/ioapic.c index ead14e1888..4f5577678a 100644 --- a/hw/intc/ioapic.c +++ b/hw/intc/ioapic.c @@ -23,10 +23,11 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "monitor/monitor.h" -#include "hw/i386/pc.h" #include "hw/i386/apic.h" #include "hw/i386/ioapic.h" #include "hw/i386/ioapic_internal.h" +#include "hw/i386/x86.h" +#include "hw/intc/i8259.h" #include "hw/pci/msi.h" #include "hw/qdev-properties.h" #include "sysemu/kvm.h" diff --git a/hw/intc/s390_flic_kvm.c b/hw/intc/s390_flic_kvm.c index c9ee80eaae..dddd33ea61 100644 --- a/hw/intc/s390_flic_kvm.c +++ b/hw/intc/s390_flic_kvm.c @@ -582,20 +582,21 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp) struct kvm_create_device cd = {0}; struct kvm_device_attr test_attr = {0}; int ret; - Error *errp_local = NULL; + Error *err = NULL; - KVM_S390_FLIC_GET_CLASS(dev)->parent_realize(dev, &errp_local); - if (errp_local) { - goto fail; + KVM_S390_FLIC_GET_CLASS(dev)->parent_realize(dev, &err); + if (err) { + error_propagate(errp, err); + return; } flic_state->fd = -1; cd.type = KVM_DEV_TYPE_FLIC; ret = kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd); if (ret < 0) { - error_setg_errno(&errp_local, errno, "Creating the KVM device failed"); + error_setg_errno(errp, errno, "Creating the KVM device failed"); trace_flic_create_device(errno); - goto fail; + return; } flic_state->fd = cd.fd; @@ -603,9 +604,6 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp) test_attr.group = KVM_DEV_FLIC_CLEAR_IO_IRQ; flic_state->clear_io_supported = !ioctl(flic_state->fd, KVM_HAS_DEVICE_ATTR, test_attr); - return; -fail: - error_propagate(errp, errp_local); } static void kvm_s390_flic_reset(DeviceState *dev) diff --git a/hw/ipmi/isa_ipmi_bt.c b/hw/ipmi/isa_ipmi_bt.c index 9a87ffd3f0..9fba5ed383 100644 --- a/hw/ipmi/isa_ipmi_bt.c +++ b/hw/ipmi/isa_ipmi_bt.c @@ -70,6 +70,7 @@ static void isa_ipmi_bt_lower_irq(IPMIBT *ib) static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp) { + Error *err = NULL; ISADevice *isadev = ISA_DEVICE(dev); ISAIPMIBTDevice *iib = ISA_IPMI_BT(dev); IPMIInterface *ii = IPMI_INTERFACE(dev); @@ -85,9 +86,11 @@ static void isa_ipmi_bt_realize(DeviceState *dev, Error **errp) iib->bt.bmc->intf = ii; iib->bt.opaque = iib; - iic->init(ii, 0, errp); - if (*errp) + iic->init(ii, 0, &err); + if (err) { + error_propagate(errp, err); return; + } if (iib->isairq > 0) { isa_init_irq(isadev, &iib->irq, iib->isairq); diff --git a/hw/ipmi/isa_ipmi_kcs.c b/hw/ipmi/isa_ipmi_kcs.c index ca3ea36a3f..cc6bd817f2 100644 --- a/hw/ipmi/isa_ipmi_kcs.c +++ b/hw/ipmi/isa_ipmi_kcs.c @@ -69,6 +69,7 @@ static void isa_ipmi_kcs_lower_irq(IPMIKCS *ik) static void ipmi_isa_realize(DeviceState *dev, Error **errp) { + Error *err = NULL; ISADevice *isadev = ISA_DEVICE(dev); ISAIPMIKCSDevice *iik = ISA_IPMI_KCS(dev); IPMIInterface *ii = IPMI_INTERFACE(dev); @@ -84,9 +85,11 @@ static void ipmi_isa_realize(DeviceState *dev, Error **errp) iik->kcs.bmc->intf = ii; iik->kcs.opaque = iik; - iic->init(ii, 0, errp); - if (*errp) + iic->init(ii, 0, &err); + if (err) { + error_propagate(errp, err); return; + } if (iik->isairq > 0) { isa_init_irq(isadev, &iik->irq, iik->isairq); diff --git a/hw/ipmi/pci_ipmi_bt.c b/hw/ipmi/pci_ipmi_bt.c index 6ed925a665..ba9cf016b5 100644 --- a/hw/ipmi/pci_ipmi_bt.c +++ b/hw/ipmi/pci_ipmi_bt.c @@ -54,6 +54,7 @@ static void pci_ipmi_lower_irq(IPMIBT *ik) static void pci_ipmi_bt_realize(PCIDevice *pd, Error **errp) { + Error *err = NULL; PCIIPMIBTDevice *pik = PCI_IPMI_BT(pd); IPMIInterface *ii = IPMI_INTERFACE(pd); IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii); @@ -74,8 +75,9 @@ static void pci_ipmi_bt_realize(PCIDevice *pd, Error **errp) pik->bt.raise_irq = pci_ipmi_raise_irq; pik->bt.lower_irq = pci_ipmi_lower_irq; - iic->init(ii, 8, errp); - if (*errp) { + iic->init(ii, 8, &err); + if (err) { + error_propagate(errp, err); return; } pci_register_bar(pd, 0, PCI_BASE_ADDRESS_SPACE_IO, &pik->bt.io); diff --git a/hw/ipmi/pci_ipmi_kcs.c b/hw/ipmi/pci_ipmi_kcs.c index eeba63baa4..99f46152f4 100644 --- a/hw/ipmi/pci_ipmi_kcs.c +++ b/hw/ipmi/pci_ipmi_kcs.c @@ -54,6 +54,7 @@ static void pci_ipmi_lower_irq(IPMIKCS *ik) static void pci_ipmi_kcs_realize(PCIDevice *pd, Error **errp) { + Error *err = NULL; PCIIPMIKCSDevice *pik = PCI_IPMI_KCS(pd); IPMIInterface *ii = IPMI_INTERFACE(pd); IPMIInterfaceClass *iic = IPMI_INTERFACE_GET_CLASS(ii); @@ -74,8 +75,9 @@ static void pci_ipmi_kcs_realize(PCIDevice *pd, Error **errp) pik->kcs.raise_irq = pci_ipmi_raise_irq; pik->kcs.lower_irq = pci_ipmi_lower_irq; - iic->init(ii, 8, errp); - if (*errp) { + iic->init(ii, 8, &err); + if (err) { + error_propagate(errp, err); return; } pci_register_bar(pd, 0, PCI_BASE_ADDRESS_SPACE_IO, &pik->kcs.io); diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c index de276cdf10..dcb6b479ea 100644 --- a/hw/isa/i82378.c +++ b/hw/isa/i82378.c @@ -19,8 +19,8 @@ #include "qemu/osdep.h" #include "hw/pci/pci.h" -#include "hw/i386/pc.h" #include "hw/irq.h" +#include "hw/intc/i8259.h" #include "hw/timer/i8254.h" #include "migration/vmstate.h" #include "hw/audio/pcspk.h" diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c index 388800603b..798dd9194e 100644 --- a/hw/isa/isa-bus.c +++ b/hw/isa/isa-bus.c @@ -82,24 +82,27 @@ void isa_bus_irqs(ISABus *bus, qemu_irq *irqs) * This function is only for special cases such as the 'ferr', and * temporary use for normal devices until they are converted to qdev. */ -qemu_irq isa_get_irq(ISADevice *dev, int isairq) +qemu_irq isa_get_irq(ISADevice *dev, unsigned isairq) { assert(!dev || ISA_BUS(qdev_get_parent_bus(DEVICE(dev))) == isabus); - if (isairq < 0 || isairq > 15) { + if (isairq >= ISA_NUM_IRQS) { hw_error("isa irq %d invalid", isairq); } return isabus->irqs[isairq]; } -void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq) +void isa_init_irq(ISADevice *dev, qemu_irq *p, unsigned isairq) { assert(dev->nirqs < ARRAY_SIZE(dev->isairq)); + if (isairq >= ISA_NUM_IRQS) { + hw_error("isa irq %d invalid", isairq); + } dev->isairq[dev->nirqs] = isairq; *p = isa_get_irq(dev, isairq); dev->nirqs++; } -void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, int isairq) +void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, unsigned isairq) { qemu_irq irq; isa_init_irq(isadev, &irq, isairq); diff --git a/hw/isa/lpc_ich9.c b/hw/isa/lpc_ich9.c index 17c292e306..170792a4fc 100644 --- a/hw/isa/lpc_ich9.c +++ b/hw/isa/lpc_ich9.c @@ -35,7 +35,6 @@ #include "hw/isa/isa.h" #include "hw/sysbus.h" #include "migration/vmstate.h" -#include "hw/i386/pc.h" #include "hw/irq.h" #include "hw/isa/apm.h" #include "hw/i386/ioapic.h" diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c index 86678e6829..7edec5e149 100644 --- a/hw/isa/piix4.c +++ b/hw/isa/piix4.c @@ -26,11 +26,11 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "hw/irq.h" -#include "hw/i386/pc.h" #include "hw/southbridge/piix.h" #include "hw/pci/pci.h" #include "hw/isa/isa.h" #include "hw/sysbus.h" +#include "hw/intc/i8259.h" #include "hw/dma/i8257.h" #include "hw/timer/i8254.h" #include "hw/rtc/mc146818rtc.h" diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index aef148c1d7..4bc9cf0917 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -99,6 +99,7 @@ static uint64_t memory_device_get_free_addr(MachineState *ms, uint64_t align, uint64_t size, Error **errp) { + Error *err = NULL; GSList *list = NULL, *item; Range as, new = range_empty; @@ -123,8 +124,9 @@ static uint64_t memory_device_get_free_addr(MachineState *ms, return 0; } - memory_device_check_addable(ms, size, errp); - if (*errp) { + memory_device_check_addable(ms, size, &err); + if (err) { + error_propagate(errp, err); return 0; } diff --git a/hw/mips/gt64xxx_pci.c b/hw/mips/gt64xxx_pci.c index f1af840d8e..b2ea13f09d 100644 --- a/hw/mips/gt64xxx_pci.c +++ b/hw/mips/gt64xxx_pci.c @@ -30,7 +30,7 @@ #include "hw/pci/pci_host.h" #include "hw/southbridge/piix.h" #include "migration/vmstate.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/irq.h" #include "exec/address-spaces.h" #include "trace.h" diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c index 03a27e1767..9eaa6e2222 100644 --- a/hw/mips/mips_fulong2e.c +++ b/hw/mips/mips_fulong2e.c @@ -23,7 +23,7 @@ #include "qemu/units.h" #include "qapi/error.h" #include "cpu.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/dma/i8257.h" #include "hw/isa/superio.h" #include "net/net.h" diff --git a/hw/mips/mips_jazz.c b/hw/mips/mips_jazz.c index ac4d7acb2b..291fd6c1b8 100644 --- a/hw/mips/mips_jazz.c +++ b/hw/mips/mips_jazz.c @@ -26,7 +26,7 @@ #include "qemu-common.h" #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/dma/i8257.h" #include "hw/char/serial.h" #include "hw/char/parallel.h" diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c index 3891be657c..fd926a3575 100644 --- a/hw/mips/mips_r4k.c +++ b/hw/mips/mips_r4k.c @@ -15,7 +15,7 @@ #include "cpu.h" #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/char/serial.h" #include "hw/isa/isa.h" #include "net/net.h" diff --git a/hw/net/can/can_sja1000.c b/hw/net/can/can_sja1000.c index 1f81341554..39c78faf9b 100644 --- a/hw/net/can/can_sja1000.c +++ b/hw/net/can/can_sja1000.c @@ -247,8 +247,8 @@ int can_sja_accept_filter(CanSJA1000State *s, static void can_display_msg(const char *prefix, const qemu_can_frame *msg) { int i; + FILE *logfile = qemu_log_lock(); - qemu_log_lock(); qemu_log("%s%03X [%01d] %s %s", prefix, msg->can_id & QEMU_CAN_EFF_MASK, @@ -261,7 +261,7 @@ static void can_display_msg(const char *prefix, const qemu_can_frame *msg) } qemu_log("\n"); qemu_log_flush(); - qemu_log_unlock(); + qemu_log_unlock(logfile); } static void buff2frame_pel(const uint8_t *buff, qemu_can_frame *frame) diff --git a/hw/pci-host/Kconfig b/hw/pci-host/Kconfig index b0aa8351c4..9642c77e98 100644 --- a/hw/pci-host/Kconfig +++ b/hw/pci-host/Kconfig @@ -1,6 +1,11 @@ config PAM bool +config XEN_IGD_PASSTHROUGH + bool + default y + depends on XEN && PCI_I440FX + config PREP_PCI bool select PCI diff --git a/hw/pci-host/Makefile.objs b/hw/pci-host/Makefile.objs index efd752b766..9c466fab01 100644 --- a/hw/pci-host/Makefile.objs +++ b/hw/pci-host/Makefile.objs @@ -14,6 +14,7 @@ common-obj-$(CONFIG_VERSATILE_PCI) += versatile.o common-obj-$(CONFIG_PCI_SABRE) += sabre.o common-obj-$(CONFIG_FULONG) += bonito.o common-obj-$(CONFIG_PCI_I440FX) += i440fx.o +common-obj-$(CONFIG_XEN_IGD_PASSTHROUGH) += xen_igd_pt.o common-obj-$(CONFIG_PCI_EXPRESS_Q35) += q35.o common-obj-$(CONFIG_PCI_EXPRESS_GENERIC_BRIDGE) += gpex.o common-obj-$(CONFIG_PCI_EXPRESS_XILINX) += xilinx-pcie.o diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c index 4692d419e5..cc6545c8a8 100644 --- a/hw/pci-host/bonito.c +++ b/hw/pci-host/bonito.c @@ -41,7 +41,6 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" #include "hw/pci/pci.h" -#include "hw/i386/pc.h" #include "hw/irq.h" #include "hw/mips/mips.h" #include "hw/pci/pci_host.h" diff --git a/hw/pci-host/i440fx.c b/hw/pci-host/i440fx.c index f27131102d..bae7b42327 100644 --- a/hw/pci-host/i440fx.c +++ b/hw/pci-host/i440fx.c @@ -1,5 +1,5 @@ /* - * QEMU i440FX/PIIX3 PCI Bridge Emulation + * QEMU i440FX PCI Bridge Emulation * * Copyright (c) 2006 Fabrice Bellard * @@ -31,7 +31,6 @@ #include "hw/sysbus.h" #include "qapi/error.h" #include "migration/vmstate.h" -#include "hw/pci-host/pam.h" #include "qapi/visitor.h" #include "qemu/error-report.h" @@ -51,23 +50,6 @@ typedef struct I440FXState { uint32_t short_root_bus; } I440FXState; -#define I440FX_PCI_DEVICE(obj) \ - OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE) - -struct PCII440FXState { - /*< private >*/ - PCIDevice parent_obj; - /*< public >*/ - - MemoryRegion *system_memory; - MemoryRegion *pci_address_space; - MemoryRegion *ram_memory; - PAMMemoryRegion pam_regions[13]; - MemoryRegion smram_region; - MemoryRegion smram, low_smram; -}; - - #define I440FX_PAM 0x59 #define I440FX_PAM_SIZE 7 #define I440FX_SMRAM 0x72 @@ -386,90 +368,6 @@ static const TypeInfo i440fx_info = { }, }; -/* IGD Passthrough Host Bridge. */ -typedef struct { - uint8_t offset; - uint8_t len; -} IGDHostInfo; - -/* Here we just expose minimal host bridge offset subset. */ -static const IGDHostInfo igd_host_bridge_infos[] = { - {0x08, 2}, /* revision id */ - {0x2c, 2}, /* sybsystem vendor id */ - {0x2e, 2}, /* sybsystem id */ - {0x50, 2}, /* SNB: processor graphics control register */ - {0x52, 2}, /* processor graphics control register */ - {0xa4, 4}, /* SNB: graphics base of stolen memory */ - {0xa8, 4}, /* SNB: base of GTT stolen memory */ -}; - -static void host_pci_config_read(int pos, int len, uint32_t *val, Error **errp) -{ - int rc, config_fd; - /* Access real host bridge. */ - char *path = g_strdup_printf("/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s", - 0, 0, 0, 0, "config"); - - config_fd = open(path, O_RDWR); - if (config_fd < 0) { - error_setg_errno(errp, errno, "Failed to open: %s", path); - goto out; - } - - if (lseek(config_fd, pos, SEEK_SET) != pos) { - error_setg_errno(errp, errno, "Failed to seek: %s", path); - goto out_close_fd; - } - - do { - rc = read(config_fd, (uint8_t *)val, len); - } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); - if (rc != len) { - error_setg_errno(errp, errno, "Failed to read: %s", path); - } - -out_close_fd: - close(config_fd); -out: - g_free(path); -} - -static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp) -{ - uint32_t val = 0; - int i, num; - int pos, len; - Error *local_err = NULL; - - num = ARRAY_SIZE(igd_host_bridge_infos); - for (i = 0; i < num; i++) { - pos = igd_host_bridge_infos[i].offset; - len = igd_host_bridge_infos[i].len; - host_pci_config_read(pos, len, &val, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - pci_default_write_config(pci_dev, pos, val, len); - } -} - -static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(klass); - PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - - k->realize = igd_pt_i440fx_realize; - dc->desc = "IGD Passthrough Host bridge"; -} - -static const TypeInfo igd_passthrough_i440fx_info = { - .name = TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE, - .parent = TYPE_I440FX_PCI_DEVICE, - .instance_size = sizeof(PCII440FXState), - .class_init = igd_passthrough_i440fx_class_init, -}; - static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, PCIBus *rootbus) { @@ -514,7 +412,6 @@ static const TypeInfo i440fx_pcihost_info = { static void i440fx_register_types(void) { type_register_static(&i440fx_info); - type_register_static(&igd_passthrough_i440fx_info); type_register_static(&i440fx_pcihost_info); } diff --git a/hw/pci-host/prep.c b/hw/pci-host/prep.c index 85d7ba9037..afa136ded3 100644 --- a/hw/pci-host/prep.c +++ b/hw/pci-host/prep.c @@ -32,7 +32,7 @@ #include "hw/pci/pci_host.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" -#include "hw/i386/pc.h" +#include "hw/intc/i8259.h" #include "hw/irq.h" #include "hw/loader.h" #include "hw/or-irq.h" diff --git a/hw/pci-host/xen_igd_pt.c b/hw/pci-host/xen_igd_pt.c new file mode 100644 index 0000000000..efcc9347ff --- /dev/null +++ b/hw/pci-host/xen_igd_pt.c @@ -0,0 +1,120 @@ +/* + * QEMU Intel IGD Passthrough Host Bridge Emulation + * + * Copyright (c) 2006 Fabrice Bellard + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" +#include "hw/pci-host/i440fx.h" +#include "qapi/error.h" + +typedef struct { + uint8_t offset; + uint8_t len; +} IGDHostInfo; + +/* Here we just expose minimal host bridge offset subset. */ +static const IGDHostInfo igd_host_bridge_infos[] = { + {PCI_REVISION_ID, 2}, + {PCI_SUBSYSTEM_VENDOR_ID, 2}, + {PCI_SUBSYSTEM_ID, 2}, + {0x50, 2}, /* SNB: processor graphics control register */ + {0x52, 2}, /* processor graphics control register */ + {0xa4, 4}, /* SNB: graphics base of stolen memory */ + {0xa8, 4}, /* SNB: base of GTT stolen memory */ +}; + +static void host_pci_config_read(int pos, int len, uint32_t *val, Error **errp) +{ + int rc, config_fd; + /* Access real host bridge. */ + char *path = g_strdup_printf("/sys/bus/pci/devices/%04x:%02x:%02x.%d/%s", + 0, 0, 0, 0, "config"); + + config_fd = open(path, O_RDWR); + if (config_fd < 0) { + error_setg_errno(errp, errno, "Failed to open: %s", path); + goto out; + } + + if (lseek(config_fd, pos, SEEK_SET) != pos) { + error_setg_errno(errp, errno, "Failed to seek: %s", path); + goto out_close_fd; + } + + do { + rc = read(config_fd, (uint8_t *)val, len); + } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); + if (rc != len) { + error_setg_errno(errp, errno, "Failed to read: %s", path); + } + + out_close_fd: + close(config_fd); + out: + g_free(path); +} + +static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp) +{ + uint32_t val = 0; + size_t i; + int pos, len; + Error *local_err = NULL; + + for (i = 0; i < ARRAY_SIZE(igd_host_bridge_infos); i++) { + pos = igd_host_bridge_infos[i].offset; + len = igd_host_bridge_infos[i].len; + host_pci_config_read(pos, len, &val, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + pci_default_write_config(pci_dev, pos, val, len); + } +} + +static void igd_passthrough_i440fx_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + + k->realize = igd_pt_i440fx_realize; + dc->desc = "IGD Passthrough Host bridge"; +} + +static const TypeInfo igd_passthrough_i440fx_info = { + .name = TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE, + .parent = TYPE_I440FX_PCI_DEVICE, + .instance_size = sizeof(PCII440FXState), + .class_init = igd_passthrough_i440fx_class_init, +}; + +static void igd_pt_i440fx_register_types(void) +{ + type_register_static(&igd_passthrough_i440fx_info); +} + +type_init(igd_pt_i440fx_register_types) diff --git a/hw/pci/pci-stub.c b/hw/pci/pci-stub.c index c04a5df651..cc2a2e1f73 100644 --- a/hw/pci/pci-stub.c +++ b/hw/pci/pci-stub.c @@ -26,6 +26,7 @@ #include "qapi/qmp/qerror.h" #include "hw/pci/pci.h" #include "hw/pci/msi.h" +#include "hw/pci/msix.h" bool msi_nonbroken; bool pci_available; @@ -64,3 +65,29 @@ void msi_notify(PCIDevice *dev, unsigned int vector) { g_assert_not_reached(); } + +/* Required by target/i386/kvm.c */ +bool msi_is_masked(const PCIDevice *dev, unsigned vector) +{ + g_assert_not_reached(); +} + +MSIMessage msi_get_message(PCIDevice *dev, unsigned int vector) +{ + g_assert_not_reached(); +} + +int msix_enabled(PCIDevice *dev) +{ + return false; +} + +bool msix_is_masked(PCIDevice *dev, unsigned vector) +{ + g_assert_not_reached(); +} + +MSIMessage msix_get_message(PCIDevice *dev, unsigned int vector) +{ + g_assert_not_reached(); +} diff --git a/hw/pci/pci.c b/hw/pci/pci.c index cbc7a32568..e3d310365d 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -69,8 +69,6 @@ static Property pci_props[] = { DEFINE_PROP_UINT32("rombar", PCIDevice, rom_bar, 1), DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present, QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false), - DEFINE_PROP_BIT("command_serr_enable", PCIDevice, cap_present, - QEMU_PCI_CAP_SERR_BITNR, true), DEFINE_PROP_BIT("x-pcie-lnksta-dllla", PCIDevice, cap_present, QEMU_PCIE_LNKSTA_DLLLA_BITNR, true), DEFINE_PROP_BIT("x-pcie-extcap-init", PCIDevice, cap_present, @@ -751,9 +749,7 @@ static void pci_init_wmask(PCIDevice *dev) pci_set_word(dev->wmask + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INTX_DISABLE); - if (dev->cap_present & QEMU_PCI_CAP_SERR) { - pci_word_test_and_set_mask(dev->wmask + PCI_COMMAND, PCI_COMMAND_SERR); - } + pci_word_test_and_set_mask(dev->wmask + PCI_COMMAND, PCI_COMMAND_SERR); memset(dev->wmask + PCI_CONFIG_HEADER_SIZE, 0xff, config_size - PCI_CONFIG_HEADER_SIZE); diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index 91cd4c26f9..12b6a5b2a8 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -793,7 +793,6 @@ static DeviceState *ppce500_init_mpic(PPCE500MachineState *pms, MemoryRegion *ccsr, IrqLines *irqs) { - MachineState *machine = MACHINE(pms); const PPCE500MachineClass *pmc = PPCE500_MACHINE_GET_CLASS(pms); DeviceState *dev = NULL; SysBusDevice *s; @@ -801,10 +800,10 @@ static DeviceState *ppce500_init_mpic(PPCE500MachineState *pms, if (kvm_enabled()) { Error *err = NULL; - if (machine_kernel_irqchip_allowed(machine)) { + if (kvm_kernel_irqchip_allowed()) { dev = ppce500_init_mpic_kvm(pmc, irqs, &err); } - if (machine_kernel_irqchip_required(machine) && !dev) { + if (kvm_kernel_irqchip_required() && !dev) { error_reportf_err(err, "kernel_irqchip requested but unavailable: "); exit(1); diff --git a/hw/ppc/spapr_irq.c b/hw/ppc/spapr_irq.c index 07e08d6544..373505d28b 100644 --- a/hw/ppc/spapr_irq.c +++ b/hw/ppc/spapr_irq.c @@ -75,12 +75,11 @@ int spapr_irq_init_kvm(SpaprInterruptControllerInitKvm fn, uint32_t nr_servers, Error **errp) { - MachineState *machine = MACHINE(qdev_get_machine()); Error *local_err = NULL; - if (kvm_enabled() && machine_kernel_irqchip_allowed(machine)) { + if (kvm_enabled() && kvm_kernel_irqchip_allowed()) { if (fn(intc, nr_servers, &local_err) < 0) { - if (machine_kernel_irqchip_required(machine)) { + if (kvm_kernel_irqchip_required()) { error_prepend(&local_err, "kernel_irqchip requested but unavailable: "); error_propagate(errp, local_err); @@ -185,7 +184,7 @@ static int spapr_irq_check(SpaprMachineState *spapr, Error **errp) */ if (kvm_enabled() && spapr->irq == &spapr_irq_dual && - machine_kernel_irqchip_required(machine) && + kvm_kernel_irqchip_required() && xics_kvm_has_broken_disconnect(spapr)) { error_setg(errp, "KVM is too old to support ic-mode=dual,kernel-irqchip=on"); return -1; @@ -288,20 +287,13 @@ uint32_t spapr_irq_nr_msis(SpaprMachineState *spapr) void spapr_irq_init(SpaprMachineState *spapr, Error **errp) { - MachineState *machine = MACHINE(spapr); SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr); - if (machine_kernel_irqchip_split(machine)) { + if (kvm_enabled() && kvm_kernel_irqchip_split()) { error_setg(errp, "kernel_irqchip split mode not supported on pseries"); return; } - if (!kvm_enabled() && machine_kernel_irqchip_required(machine)) { - error_setg(errp, - "kernel_irqchip requested but only available with KVM"); - return; - } - if (spapr_irq_check(spapr, errp) < 0) { return; } diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index f6fbcf99ed..723373de73 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -2042,13 +2042,13 @@ void spapr_phb_dma_reset(SpaprPhbState *sphb) static void spapr_phb_reset(DeviceState *qdev) { SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(qdev); - Error *errp = NULL; + Error *err = NULL; spapr_phb_dma_reset(sphb); spapr_phb_nvgpu_free(sphb); - spapr_phb_nvgpu_setup(sphb, &errp); - if (errp) { - error_report_err(errp); + spapr_phb_nvgpu_setup(sphb, &err); + if (err) { + error_report_err(err); } /* Reset the IOMMU state */ @@ -2326,7 +2326,7 @@ int spapr_dt_phb(SpaprMachineState *spapr, SpaprPhbState *phb, cpu_to_be32(phb->numa_node)}; SpaprTceTable *tcet; SpaprDrc *drc; - Error *errp = NULL; + Error *err = NULL; /* Start populating the FDT */ _FDT(bus_off = fdt_add_subnode(fdt, 0, phb->dtbusname)); @@ -2408,9 +2408,9 @@ int spapr_dt_phb(SpaprMachineState *spapr, SpaprPhbState *phb, return ret; } - spapr_phb_nvgpu_populate_dt(phb, fdt, bus_off, &errp); - if (errp) { - error_report_err(errp); + spapr_phb_nvgpu_populate_dt(phb, fdt, bus_off, &err); + if (err) { + error_report_err(err); } spapr_phb_nvgpu_ram_populate_dt(phb, fdt); diff --git a/hw/ppc/spapr_pci_nvlink2.c b/hw/ppc/spapr_pci_nvlink2.c index 4aa89ede23..8332d5694e 100644 --- a/hw/ppc/spapr_pci_nvlink2.c +++ b/hw/ppc/spapr_pci_nvlink2.c @@ -57,7 +57,7 @@ struct SpaprPhbPciNvGpuConfig { uint64_t nv2_atsd_current; int num; /* number of non empty (i.e. tgt!=0) entries in slots[] */ SpaprPhbPciNvGpuSlot slots[NVGPU_MAX_NUM]; - Error *errp; + Error *err; }; static SpaprPhbPciNvGpuSlot * @@ -153,7 +153,7 @@ static void spapr_phb_pci_collect_nvgpu(PCIBus *bus, PCIDevice *pdev, spapr_pci_collect_nvnpu(nvgpus, pdev, tgt, MEMORY_REGION(mr_npu), &local_err); } - error_propagate(&nvgpus->errp, local_err); + error_propagate(&nvgpus->err, local_err); } if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) != PCI_HEADER_TYPE_BRIDGE)) { @@ -187,9 +187,9 @@ void spapr_phb_nvgpu_setup(SpaprPhbState *sphb, Error **errp) pci_for_each_device(bus, pci_bus_num(bus), spapr_phb_pci_collect_nvgpu, sphb->nvgpus); - if (sphb->nvgpus->errp) { - error_propagate(errp, sphb->nvgpus->errp); - sphb->nvgpus->errp = NULL; + if (sphb->nvgpus->err) { + error_propagate(errp, sphb->nvgpus->err); + sphb->nvgpus->err = NULL; goto cleanup_exit; } diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c index cdcf9154c4..6afe278cad 100644 --- a/hw/s390x/event-facility.c +++ b/hw/s390x/event-facility.c @@ -441,7 +441,7 @@ static void sclp_event_set_allow_all_mask_sizes(Object *obj, bool value, ef->allow_all_mask_sizes = value; } -static bool sclp_event_get_allow_all_mask_sizes(Object *obj, Error **e) +static bool sclp_event_get_allow_all_mask_sizes(Object *obj, Error **errp) { SCLPEventFacility *ef = (SCLPEventFacility *)obj; diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c index bf5ac014c4..58121b9f68 100644 --- a/hw/s390x/s390-stattrib.c +++ b/hw/s390x/s390-stattrib.c @@ -352,7 +352,8 @@ static void s390_stattrib_class_init(ObjectClass *oc, void *data) dc->realize = s390_stattrib_realize; } -static inline bool s390_stattrib_get_migration_enabled(Object *obj, Error **e) +static inline bool s390_stattrib_get_migration_enabled(Object *obj, + Error **errp) { S390StAttribState *s = S390_STATTRIB(obj); diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c index 88404d0e9d..18c0c052ce 100644 --- a/hw/sd/sdhci.c +++ b/hw/sd/sdhci.c @@ -1459,7 +1459,7 @@ static void sdhci_sysbus_finalize(Object *obj) sdhci_uninitfn(s); } -static void sdhci_sysbus_realize(DeviceState *dev, Error ** errp) +static void sdhci_sysbus_realize(DeviceState *dev, Error **errp) { SDHCIState *s = SYSBUS_SDHCI(dev); SysBusDevice *sbd = SYS_BUS_DEVICE(dev); diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 22f9113432..10d587ed40 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -155,7 +155,7 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu, const uint8_t *in, uint32_t in_len, uint8_t *out, uint32_t out_len, bool *selftest_done, - Error **err) + Error **errp) { ssize_t ret; bool is_selftest = false; @@ -165,20 +165,20 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu, is_selftest = tpm_util_is_selftest(in, in_len); } - ret = qio_channel_write_all(tpm_emu->data_ioc, (char *)in, in_len, err); + ret = qio_channel_write_all(tpm_emu->data_ioc, (char *)in, in_len, errp); if (ret != 0) { return -1; } ret = qio_channel_read_all(tpm_emu->data_ioc, (char *)out, - sizeof(struct tpm_resp_hdr), err); + sizeof(struct tpm_resp_hdr), errp); if (ret != 0) { return -1; } ret = qio_channel_read_all(tpm_emu->data_ioc, (char *)out + sizeof(struct tpm_resp_hdr), - tpm_cmd_get_size(out) - sizeof(struct tpm_resp_hdr), err); + tpm_cmd_get_size(out) - sizeof(struct tpm_resp_hdr), errp); if (ret != 0) { return -1; } diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 5de6213cc4..b81a8abe83 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -1342,7 +1342,7 @@ static NetClientInfo net_usbnet_info = { .cleanup = usbnet_cleanup, }; -static void usb_net_realize(USBDevice *dev, Error **errrp) +static void usb_net_realize(USBDevice *dev, Error **errp) { USBNetState *s = USB_NET(dev); diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index da6a20669d..8fbaa724c2 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -89,14 +89,13 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp) { int ret; char *mdevid; - Error *local_err = NULL; VFIOGroup *vfio_group; APDevice *apdev = AP_DEVICE(dev); VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev); - vfio_group = vfio_ap_get_group(vapdev, &local_err); + vfio_group = vfio_ap_get_group(vapdev, errp); if (!vfio_group) { - goto out_err; + return; } vapdev->vdev.ops = &vfio_ap_ops; @@ -113,7 +112,7 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp) */ vapdev->vdev.balloon_allowed = true; - ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err); + ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, errp); if (ret) { goto out_get_dev_err; } @@ -123,8 +122,6 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp) out_get_dev_err: vfio_ap_put_device(vapdev); vfio_put_group(vfio_group); -out_err: - error_propagate(errp, local_err); } static void vfio_ap_unrealize(DeviceState *dev, Error **errp) diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 3724ff8bac..f87def27a6 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -1,3 +1,6 @@ +config VHOST + bool + config VIRTIO bool diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index e2f70fbb89..de0f5fc39b 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -2,8 +2,8 @@ ifeq ($(CONFIG_VIRTIO),y) common-obj-y += virtio-bus.o obj-y += virtio.o -obj-$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_VHOST_KERNEL)) += vhost.o vhost-backend.o -common-obj-$(call lnot,$(call lor,$(CONFIG_VHOST_USER),$(CONFIG_VHOST_KERNEL))) += vhost-stub.o +obj-$(CONFIG_VHOST) += vhost.o vhost-backend.o +common-obj-$(call lnot,$(CONFIG_VHOST)) += vhost-stub.o obj-$(CONFIG_VHOST_USER) += vhost-user.o common-obj-$(CONFIG_VIRTIO_RNG) += virtio-rng.o diff --git a/hw/xen/xen-common.c b/hw/xen/xen-common.c index 5284b0dec1..15650d7f6a 100644 --- a/hw/xen/xen-common.c +++ b/hw/xen/xen-common.c @@ -11,7 +11,9 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" #include "qemu/module.h" +#include "qapi/error.h" #include "hw/xen/xen-legacy-backend.h" +#include "hw/xen/xen_pt.h" #include "chardev/char.h" #include "sysemu/accel.h" #include "sysemu/runstate.h" @@ -124,6 +126,16 @@ static void xen_change_state_handler(void *opaque, int running, } } +static bool xen_get_igd_gfx_passthru(Object *obj, Error **errp) +{ + return has_igd_gfx_passthru; +} + +static void xen_set_igd_gfx_passthru(Object *obj, bool value, Error **errp) +{ + has_igd_gfx_passthru = value; +} + static void xen_setup_post(MachineState *ms, AccelState *accel) { int rc; @@ -177,6 +189,12 @@ static void xen_accel_class_init(ObjectClass *oc, void *data) ac->compat_props = g_ptr_array_new(); compat_props_add(ac->compat_props, compat, G_N_ELEMENTS(compat)); + + object_class_property_add_bool(oc, "igd-passthru", + xen_get_igd_gfx_passthru, xen_set_igd_gfx_passthru, + &error_abort); + object_class_property_set_description(oc, "igd-passthru", + "Set on/off to enable/disable igd passthrou", &error_abort); } #define TYPE_XEN_ACCEL ACCEL_CLASS_NAME("xen") diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index 8fbaf2eae9..9e767d4244 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -65,6 +65,8 @@ #include "qemu/range.h" #include "exec/address-spaces.h" +bool has_igd_gfx_passthru; + #define XEN_PT_NR_IRQS (256) static uint8_t xen_pt_mapped_machine_irq[XEN_PT_NR_IRQS] = {0}; diff --git a/include/block/snapshot.h b/include/block/snapshot.h index b5d5084a12..2bfcd57578 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -78,7 +78,7 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs, bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs); int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bsd_bs, - Error **err); + Error **errp); int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_bs, Error **errp); int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_bs); diff --git a/include/crypto/tlssession.h b/include/crypto/tlssession.h index e01e1a9dc2..15b9cef086 100644 --- a/include/crypto/tlssession.h +++ b/include/crypto/tlssession.h @@ -56,7 +56,7 @@ * * static int mysock_run_tls(int sockfd, * QCryptoTLSCreds *creds, - * Error *errp) + * Error **errp) * { * QCryptoTLSSession *sess; * diff --git a/include/exec/log.h b/include/exec/log.h index e2cfd436e6..fcc7b9e00b 100644 --- a/include/exec/log.h +++ b/include/exec/log.h @@ -15,8 +15,15 @@ */ static inline void log_cpu_state(CPUState *cpu, int flags) { + QemuLogFile *logfile; + if (qemu_log_enabled()) { - cpu_dump_state(cpu, qemu_logfile, flags); + rcu_read_lock(); + logfile = atomic_rcu_read(&qemu_logfile); + if (logfile) { + cpu_dump_state(cpu, logfile->fd, flags); + } + rcu_read_unlock(); } } @@ -40,19 +47,36 @@ static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags) static inline void log_target_disas(CPUState *cpu, target_ulong start, target_ulong len) { - target_disas(qemu_logfile, cpu, start, len); + QemuLogFile *logfile; + rcu_read_lock(); + logfile = atomic_rcu_read(&qemu_logfile); + if (logfile) { + target_disas(logfile->fd, cpu, start, len); + } + rcu_read_unlock(); } static inline void log_disas(void *code, unsigned long size) { - disas(qemu_logfile, code, size); + QemuLogFile *logfile; + rcu_read_lock(); + logfile = atomic_rcu_read(&qemu_logfile); + if (logfile) { + disas(logfile->fd, code, size); + } + rcu_read_unlock(); } #if defined(CONFIG_USER_ONLY) /* page_dump() output to the log file: */ -static inline void log_page_dump(void) +static inline void log_page_dump(const char *operation) { - page_dump(qemu_logfile); + FILE *logfile = qemu_log_lock(); + if (logfile) { + qemu_log("page layout changed following %s\n", operation); + page_dump(logfile); + } + qemu_log_unlock(logfile); } #endif #endif diff --git a/include/exec/memory.h b/include/exec/memory.h index 27a84e0cc3..e85b7de99a 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -360,10 +360,14 @@ typedef struct IOMMUMemoryRegionClass { typedef struct CoalescedMemoryRange CoalescedMemoryRange; typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; +/** MemoryRegion: + * + * A struct representing a memory region. + */ struct MemoryRegion { Object parent_obj; - /* All fields are private - violators will be prosecuted */ + /* private: */ /* The following fields should fit in a cache line */ bool romd_mode; @@ -419,30 +423,232 @@ struct IOMMUMemoryRegion { * Use with memory_listener_register() and memory_listener_unregister(). */ struct MemoryListener { + /** + * @begin: + * + * Called at the beginning of an address space update transaction. + * Followed by calls to #MemoryListener.region_add(), + * #MemoryListener.region_del(), #MemoryListener.region_nop(), + * #MemoryListener.log_start() and #MemoryListener.log_stop() in + * increasing address order. + * + * @listener: The #MemoryListener. + */ void (*begin)(MemoryListener *listener); + + /** + * @commit: + * + * Called at the end of an address space update transaction, + * after the last call to #MemoryListener.region_add(), + * #MemoryListener.region_del() or #MemoryListener.region_nop(), + * #MemoryListener.log_start() and #MemoryListener.log_stop(). + * + * @listener: The #MemoryListener. + */ void (*commit)(MemoryListener *listener); + + /** + * @region_add: + * + * Called during an address space update transaction, + * for a section of the address space that is new in this address space + * space since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The new #MemoryRegionSection. + */ void (*region_add)(MemoryListener *listener, MemoryRegionSection *section); + + /** + * @region_del: + * + * Called during an address space update transaction, + * for a section of the address space that has disappeared in the address + * space since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The old #MemoryRegionSection. + */ void (*region_del)(MemoryListener *listener, MemoryRegionSection *section); + + /** + * @region_nop: + * + * Called during an address space update transaction, + * for a section of the address space that is in the same place in the address + * space as in the last transaction. + * + * @listener: The #MemoryListener. + * @section: The #MemoryRegionSection. + */ void (*region_nop)(MemoryListener *listener, MemoryRegionSection *section); + + /** + * @log_start: + * + * Called during an address space update transaction, after + * one of #MemoryListener.region_add(),#MemoryListener.region_del() or + * #MemoryListener.region_nop(), if dirty memory logging clients have + * become active since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The #MemoryRegionSection. + * @old: A bitmap of dirty memory logging clients that were active in + * the previous transaction. + * @new: A bitmap of dirty memory logging clients that are active in + * the current transaction. + */ void (*log_start)(MemoryListener *listener, MemoryRegionSection *section, int old, int new); + + /** + * @log_stop: + * + * Called during an address space update transaction, after + * one of #MemoryListener.region_add(), #MemoryListener.region_del() or + * #MemoryListener.region_nop() and possibly after + * #MemoryListener.log_start(), if dirty memory logging clients have + * become inactive since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The #MemoryRegionSection. + * @old: A bitmap of dirty memory logging clients that were active in + * the previous transaction. + * @new: A bitmap of dirty memory logging clients that are active in + * the current transaction. + */ void (*log_stop)(MemoryListener *listener, MemoryRegionSection *section, int old, int new); + + /** + * @log_sync: + * + * Called by memory_region_snapshot_and_clear_dirty() and + * memory_global_dirty_log_sync(), before accessing QEMU's "official" + * copy of the dirty memory bitmap for a #MemoryRegionSection. + * + * @listener: The #MemoryListener. + * @section: The #MemoryRegionSection. + */ void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section); + + /** + * @log_clear: + * + * Called before reading the dirty memory bitmap for a + * #MemoryRegionSection. + * + * @listener: The #MemoryListener. + * @section: The #MemoryRegionSection. + */ void (*log_clear)(MemoryListener *listener, MemoryRegionSection *section); + + /** + * @log_global_start: + * + * Called by memory_global_dirty_log_start(), which + * enables the %DIRTY_LOG_MIGRATION client on all memory regions in + * the address space. #MemoryListener.log_global_start() is also + * called when a #MemoryListener is added, if global dirty logging is + * active at that time. + * + * @listener: The #MemoryListener. + */ void (*log_global_start)(MemoryListener *listener); + + /** + * @log_global_stop: + * + * Called by memory_global_dirty_log_stop(), which + * disables the %DIRTY_LOG_MIGRATION client on all memory regions in + * the address space. + * + * @listener: The #MemoryListener. + */ void (*log_global_stop)(MemoryListener *listener); + + /** + * @log_global_after_sync: + * + * Called after reading the dirty memory bitmap + * for any #MemoryRegionSection. + * + * @listener: The #MemoryListener. + */ void (*log_global_after_sync)(MemoryListener *listener); + + /** + * @eventfd_add: + * + * Called during an address space update transaction, + * for a section of the address space that has had a new ioeventfd + * registration since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The new #MemoryRegionSection. + * @match_data: The @match_data parameter for the new ioeventfd. + * @data: The @data parameter for the new ioeventfd. + * @e: The #EventNotifier parameter for the new ioeventfd. + */ void (*eventfd_add)(MemoryListener *listener, MemoryRegionSection *section, bool match_data, uint64_t data, EventNotifier *e); + + /** + * @eventfd_del: + * + * Called during an address space update transaction, + * for a section of the address space that has dropped an ioeventfd + * registration since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The new #MemoryRegionSection. + * @match_data: The @match_data parameter for the dropped ioeventfd. + * @data: The @data parameter for the dropped ioeventfd. + * @e: The #EventNotifier parameter for the dropped ioeventfd. + */ void (*eventfd_del)(MemoryListener *listener, MemoryRegionSection *section, bool match_data, uint64_t data, EventNotifier *e); + + /** + * @coalesced_io_add: + * + * Called during an address space update transaction, + * for a section of the address space that has had a new coalesced + * MMIO range registration since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The new #MemoryRegionSection. + * @addr: The starting address for the coalesced MMIO range. + * @len: The length of the coalesced MMIO range. + */ void (*coalesced_io_add)(MemoryListener *listener, MemoryRegionSection *section, hwaddr addr, hwaddr len); + + /** + * @coalesced_io_del: + * + * Called during an address space update transaction, + * for a section of the address space that has dropped a coalesced + * MMIO range since the last transaction. + * + * @listener: The #MemoryListener. + * @section: The new #MemoryRegionSection. + * @addr: The starting address for the coalesced MMIO range. + * @len: The length of the coalesced MMIO range. + */ void (*coalesced_io_del)(MemoryListener *listener, MemoryRegionSection *section, hwaddr addr, hwaddr len); - /* Lower = earlier (during add), later (during del) */ + /** + * @priority: + * + * Govern the order in which memory listeners are invoked. Lower priorities + * are invoked earlier for "add" or "start" callbacks, and later for "delete" + * or "stop" callbacks. + */ unsigned priority; + + /* private: */ AddressSpace *address_space; QTAILQ_ENTRY(MemoryListener) link; QTAILQ_ENTRY(MemoryListener) link_as; @@ -452,7 +658,7 @@ struct MemoryListener { * AddressSpace: describes a mapping of addresses to #MemoryRegion objects */ struct AddressSpace { - /* All fields are private. */ + /* private: */ struct rcu_head rcu; char *name; MemoryRegion *root; @@ -936,6 +1142,7 @@ void memory_region_init_rom(MemoryRegion *mr, * @mr: the #MemoryRegion to be initialized. * @owner: the object that tracks the region's reference count * @ops: callbacks for write access handling (must not be NULL). + * @opaque: passed to the read and write callbacks of the @ops structure. * @name: Region name, becomes part of RAMBlock name used in migration stream * must be unique within any device * @size: size of the region. @@ -1024,7 +1231,7 @@ static inline IOMMUMemoryRegion *memory_region_get_iommu(MemoryRegion *mr) * Returns pointer to IOMMUMemoryRegionClass if a memory region is an iommu, * otherwise NULL. This is fast path avoiding QOM checking, use with caution. * - * @mr: the memory region being queried + * @iommu_mr: the memory region being queried */ static inline IOMMUMemoryRegionClass *memory_region_get_iommu_class_nocheck( IOMMUMemoryRegion *iommu_mr) @@ -1094,6 +1301,7 @@ void memory_region_notify_one(IOMMUNotifier *notifier, * @n: the IOMMUNotifier to be added; the notify callback receives a * pointer to an #IOMMUTLBEntry as the opaque value; the pointer * ceases to be valid on exit from the notifier. + * @errp: pointer to Error*, to store an error if it happens. */ int memory_region_register_iommu_notifier(MemoryRegion *mr, IOMMUNotifier *n, Error **errp); @@ -1266,9 +1474,12 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr); void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errp); /** - * memory_region_do_writeback: Trigger writeback for selected address range - * [addr, addr + size] + * memory_region_do_writeback: Trigger cache writeback or msync for + * selected address range * + * @mr: the memory region to be updated + * @addr: the initial address of the range to be written back + * @size: the size of the range to be written back */ void memory_region_do_writeback(MemoryRegion *mr, hwaddr addr, hwaddr size); @@ -1587,6 +1798,8 @@ void memory_region_add_subregion_overlap(MemoryRegion *mr, /** * memory_region_get_ram_addr: Get the ram address associated with a memory * region + * + * @mr: the region to be queried */ ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr); @@ -1679,8 +1892,8 @@ bool memory_region_is_mapped(MemoryRegion *mr); * * Returns a #MemoryRegionSection that describes a contiguous overlap. * It will have the following characteristics: - * .@size = 0 iff no overlap was found - * .@mr is non-%NULL iff an overlap was found + * - @size = 0 iff no overlap was found + * - @mr is non-%NULL iff an overlap was found * * Remember that in the return value the @offset_within_region is * relative to the returned region (in the .@mr field), not to the @@ -1691,8 +1904,8 @@ bool memory_region_is_mapped(MemoryRegion *mr); * returned one. However, in the special case where the @mr argument * has no container (and thus is the root of the address space), the * following will hold: - * .@offset_within_address_space >= @addr - * .@offset_within_address_space + .@size <= @addr + @size + * - @offset_within_address_space >= @addr + * - @offset_within_address_space + .@size <= @addr + @size * * @mr: a MemoryRegion within which @addr is a relative address * @addr: start of the area within @as to be searched @@ -2157,6 +2370,7 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) * @addr: address within that address space * @attrs: memory transaction attributes * @buf: buffer with the data transferred + * @len: length of the data transferred */ static inline __attribute__((__always_inline__)) MemTxResult address_space_read(AddressSpace *as, hwaddr addr, @@ -2171,7 +2385,7 @@ MemTxResult address_space_read(AddressSpace *as, hwaddr addr, if (__builtin_constant_p(len)) { if (len) { - rcu_read_lock(); + RCU_READ_LOCK_GUARD(); fv = address_space_to_flatview(as); l = len; mr = flatview_translate(fv, addr, &addr1, &l, false, attrs); @@ -2182,7 +2396,6 @@ MemTxResult address_space_read(AddressSpace *as, hwaddr addr, result = flatview_read_continue(fv, addr, attrs, buf, len, addr1, l, mr); } - rcu_read_unlock(); } } else { result = address_space_read_full(as, addr, attrs, buf, len); diff --git a/include/hw/boards.h b/include/hw/boards.h index 24cbeecbae..61f8bb8e5a 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -63,10 +63,6 @@ extern MachineState *current_machine; void machine_run_board_init(MachineState *machine); bool machine_usb(MachineState *machine); -bool machine_kernel_irqchip_allowed(MachineState *machine); -bool machine_kernel_irqchip_required(MachineState *machine); -bool machine_kernel_irqchip_split(MachineState *machine); -int machine_kvm_shadow_mem(MachineState *machine); int machine_phandle_start(MachineState *machine); bool machine_dump_guest_core(MachineState *machine); bool machine_mem_merge(MachineState *machine); @@ -275,11 +271,9 @@ struct MachineState { /*< public >*/ - char *accel; bool kernel_irqchip_allowed; bool kernel_irqchip_required; bool kernel_irqchip_split; - int kvm_shadow_mem; char *dtb; char *dumpdtb; int phandle_start; @@ -288,7 +282,6 @@ struct MachineState { bool mem_merge; bool usb; bool usb_disabled; - bool igd_gfx_passthru; char *firmware; bool iommu; bool suppress_vmdesc; diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 61a998de46..d5ac76d54e 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -3,11 +3,9 @@ #include "exec/memory.h" #include "hw/boards.h" -#include "hw/isa/isa.h" #include "hw/block/fdc.h" #include "hw/block/flash.h" #include "net/net.h" -#include "hw/i386/ioapic.h" #include "hw/i386/x86.h" #include "qemu/range.h" @@ -43,7 +41,6 @@ struct PCMachineState { /* Configuration options: */ OnOffAuto vmport; - OnOffAuto smm; bool acpi_build_enabled; bool smbus_enabled; @@ -61,7 +58,6 @@ struct PCMachineState { #define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device" #define PC_MACHINE_DEVMEM_REGION_SIZE "device-memory-region-size" #define PC_MACHINE_VMPORT "vmport" -#define PC_MACHINE_SMM "smm" #define PC_MACHINE_SMBUS "smbus" #define PC_MACHINE_SATA "sata" #define PC_MACHINE_PIT "pit" @@ -134,27 +130,8 @@ typedef struct PCMachineClass { #define PC_MACHINE_CLASS(klass) \ OBJECT_CLASS_CHECK(PCMachineClass, (klass), TYPE_PC_MACHINE) -/* i8259.c */ - -extern DeviceState *isa_pic; -qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq); -qemu_irq *kvm_i8259_init(ISABus *bus); -int pic_read_irq(DeviceState *d); -int pic_get_output(DeviceState *d); - /* ioapic.c */ -/* Global System Interrupts */ - -#define GSI_NUM_PINS IOAPIC_NUM_PINS - -typedef struct GSIState { - qemu_irq i8259_irq[ISA_NUM_IRQS]; - qemu_irq ioapic_irq[IOAPIC_NUM_PINS]; -} GSIState; - -void gsi_handler(void *opaque, int n, int level); - GSIState *pc_gsi_create(qemu_irq **irqs, bool pci_enabled); /* vmport.c */ @@ -173,7 +150,6 @@ void vmmouse_set_data(const uint32_t *data); /* pc.c */ extern int fd_bootchk; -bool pc_machine_is_smm_enabled(PCMachineState *pcms); void pc_acpi_smi_interrupt(void *opaque, int irq, int level); void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp); @@ -199,7 +175,6 @@ void pc_memory_init(PCMachineState *pcms, MemoryRegion *rom_memory, MemoryRegion **ram_memory); uint64_t pc_pci_hole64_start(void); -qemu_irq pc_allocate_cpu_irq(void); DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus); void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, ISADevice **rtc_state, @@ -217,17 +192,14 @@ void pc_pci_device_init(PCIBus *pci_bus); typedef void (*cpu_set_smm_t)(int smm, void *arg); void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs); -void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name); ISADevice *pc_find_fdc0(void); int cmos_get_fd_drive_type(FloppyDriveType fd0); -#define FW_CFG_IO_BASE 0x510 - +/* port92.c */ #define PORT92_A20_LINE "a20" -/* hpet.c */ -extern int no_hpet; +#define TYPE_PORT92 "port92" /* pc_sysfw.c */ void pc_system_flash_create(PCMachineState *pcms); diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index 4b84917885..41fe37b8a3 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -23,6 +23,8 @@ #include "hw/boards.h" #include "hw/nmi.h" +#include "hw/isa/isa.h" +#include "hw/i386/ioapic.h" typedef struct { /*< private >*/ @@ -60,6 +62,8 @@ typedef struct { uint16_t boot_cpus; unsigned smp_dies; + OnOffAuto smm; + /* * Address space used by IOAPIC device. All IOAPIC interrupts * will be translated to MSI messages in the address space. @@ -68,6 +72,7 @@ typedef struct { } X86MachineState; #define X86_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g" +#define X86_MACHINE_SMM "smm" #define TYPE_X86_MACHINE MACHINE_TYPE_NAME("x86") #define X86_MACHINE(obj) \ @@ -95,4 +100,22 @@ void x86_load_linux(X86MachineState *x86ms, bool pvh_enabled, bool linuxboot_dma_enabled); +bool x86_machine_is_smm_enabled(X86MachineState *x86ms); + +/* Global System Interrupts */ + +#define GSI_NUM_PINS IOAPIC_NUM_PINS + +typedef struct GSIState { + qemu_irq i8259_irq[ISA_NUM_IRQS]; + qemu_irq ioapic_irq[IOAPIC_NUM_PINS]; +} GSIState; + +qemu_irq x86_allocate_cpu_irq(void); +void gsi_handler(void *opaque, int n, int level); +void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name); + +/* hpet.c */ +extern int no_hpet; + #endif diff --git a/include/hw/intc/i8259.h b/include/hw/intc/i8259.h new file mode 100644 index 0000000000..e2b1e8c59a --- /dev/null +++ b/include/hw/intc/i8259.h @@ -0,0 +1,12 @@ +#ifndef HW_I8259_H +#define HW_I8259_H + +/* i8259.c */ + +extern DeviceState *isa_pic; +qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq); +qemu_irq *kvm_i8259_init(ISABus *bus); +int pic_get_output(DeviceState *d); +int pic_read_irq(DeviceState *d); + +#endif diff --git a/include/hw/isa/i8259_internal.h b/include/hw/isa/i8259_internal.h index ee189e4a77..861d70d8f8 100644 --- a/include/hw/isa/i8259_internal.h +++ b/include/hw/isa/i8259_internal.h @@ -25,9 +25,9 @@ #ifndef QEMU_I8259_INTERNAL_H #define QEMU_I8259_INTERNAL_H -#include "hw/i386/pc.h" #include "hw/isa/isa.h" #include "hw/intc/intc.h" +#include "hw/intc/i8259.h" typedef struct PICCommonState PICCommonState; diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h index 79f703fd6c..e9ac1f1205 100644 --- a/include/hw/isa/isa.h +++ b/include/hw/isa/isa.h @@ -88,7 +88,7 @@ struct ISADevice { DeviceState parent_obj; /*< public >*/ - uint32_t isairq[2]; + int8_t isairq[2]; /* -1 = unassigned */ int nirqs; int ioport_id; }; @@ -96,9 +96,9 @@ struct ISADevice { ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space, MemoryRegion *address_space_io, Error **errp); void isa_bus_irqs(ISABus *bus, qemu_irq *irqs); -qemu_irq isa_get_irq(ISADevice *dev, int isairq); -void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq); -void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, int isairq); +qemu_irq isa_get_irq(ISADevice *dev, unsigned isairq); +void isa_init_irq(ISADevice *dev, qemu_irq *p, unsigned isairq); +void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, unsigned isairq); void isa_bus_dma(ISABus *bus, IsaDma *dma8, IsaDma *dma16); IsaDma *isa_get_dma(ISABus *bus, int nchan); MemoryRegion *isa_address_space(ISADevice *dev); diff --git a/include/hw/pci-host/i440fx.h b/include/hw/pci-host/i440fx.h index f54e6466e4..cc58d82ed4 100644 --- a/include/hw/pci-host/i440fx.h +++ b/include/hw/pci-host/i440fx.h @@ -13,12 +13,27 @@ #include "hw/hw.h" #include "hw/pci/pci_bus.h" - -typedef struct PCII440FXState PCII440FXState; +#include "hw/pci-host/pam.h" #define TYPE_I440FX_PCI_HOST_BRIDGE "i440FX-pcihost" #define TYPE_I440FX_PCI_DEVICE "i440FX" +#define I440FX_PCI_DEVICE(obj) \ + OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE) + +typedef struct PCII440FXState { + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + + MemoryRegion *system_memory; + MemoryRegion *pci_address_space; + MemoryRegion *ram_memory; + PAMMemoryRegion pam_regions[13]; + MemoryRegion smram_region; + MemoryRegion smram, low_smram; +} PCII440FXState; + #define TYPE_IGD_PASSTHROUGH_I440FX_PCI_DEVICE "igd-passthrough-i440FX" PCIBus *i440fx_init(const char *host_type, const char *pci_type, diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index db75c6dfd0..2acd8321af 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -174,7 +174,7 @@ enum { #define QEMU_PCI_CAP_MULTIFUNCTION_BITNR 3 QEMU_PCI_CAP_MULTIFUNCTION = (1 << QEMU_PCI_CAP_MULTIFUNCTION_BITNR), - /* command register SERR bit enabled */ + /* command register SERR bit enabled - unused since QEMU v5.0 */ #define QEMU_PCI_CAP_SERR_BITNR 4 QEMU_PCI_CAP_SERR = (1 << QEMU_PCI_CAP_SERR_BITNR), /* Standard hot plug controller. */ diff --git a/include/io/task.h b/include/io/task.h index 5cb9faf9f2..1abbfb8b65 100644 --- a/include/io/task.h +++ b/include/io/task.h @@ -119,7 +119,7 @@ typedef void (*QIOTaskWorker)(QIOTask *task, * gboolean myobject_operation_timer(gpointer opaque) * { * QIOTask *task = QIO_TASK(opaque); - * Error *err;* + * Error *err = NULL; * * ...check something important... * if (err) { diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index a0e9511440..3d329853b2 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -16,7 +16,7 @@ #include "qemu/readline.h" -void hmp_handle_error(Monitor *mon, Error **errp); +void hmp_handle_error(Monitor *mon, Error *err); void hmp_info_name(Monitor *mon, const QDict *qdict); void hmp_info_version(Monitor *mon, const QDict *qdict); diff --git a/include/qapi/error.h b/include/qapi/error.h index 3f95141a01..ad5b6e896d 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -233,13 +233,13 @@ void error_propagate_prepend(Error **dst_errp, Error *local_err, * Prepend some text to @errp's human-readable error message. * The text is made by formatting @fmt, @ap like vprintf(). */ -void error_vprepend(Error **errp, const char *fmt, va_list ap); +void error_vprepend(Error *const *errp, const char *fmt, va_list ap); /* * Prepend some text to @errp's human-readable error message. * The text is made by formatting @fmt, ... like printf(). */ -void error_prepend(Error **errp, const char *fmt, ...) +void error_prepend(Error *const *errp, const char *fmt, ...) GCC_FMT_ATTR(2, 3); /* @@ -256,7 +256,7 @@ void error_prepend(Error **errp, const char *fmt, ...) * May be called multiple times. The resulting hint should end with a * newline. */ -void error_append_hint(Error **errp, const char *fmt, ...) +void error_append_hint(Error *const *errp, const char *fmt, ...) GCC_FMT_ATTR(2, 3); /* diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index ee76552c06..02c1ce6a5d 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -424,13 +424,16 @@ static inline uint64_t deposit64(uint64_t value, int start, int length, /** * half_shuffle32: - * @value: 32-bit value (of which only the bottom 16 bits are of interest) + * @x: 32-bit value (of which only the bottom 16 bits are of interest) + * + * Given an input value:: + * + * xxxx xxxx xxxx xxxx ABCD EFGH IJKL MNOP * - * Given an input value: - * xxxx xxxx xxxx xxxx ABCD EFGH IJKL MNOP * return the value where the bottom 16 bits are spread out into - * the odd bits in the word, and the even bits are zeroed: - * 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N 0O0P + * the odd bits in the word, and the even bits are zeroed:: + * + * 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N 0O0P * * Any bits set in the top half of the input are ignored. * @@ -450,13 +453,16 @@ static inline uint32_t half_shuffle32(uint32_t x) /** * half_shuffle64: - * @value: 64-bit value (of which only the bottom 32 bits are of interest) + * @x: 64-bit value (of which only the bottom 32 bits are of interest) + * + * Given an input value:: + * + * xxxx xxxx xxxx .... xxxx xxxx ABCD EFGH IJKL MNOP QRST UVWX YZab cdef * - * Given an input value: - * xxxx xxxx xxxx .... xxxx xxxx ABCD EFGH IJKL MNOP QRST UVWX YZab cdef * return the value where the bottom 32 bits are spread out into - * the odd bits in the word, and the even bits are zeroed: - * 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N .... 0U0V 0W0X 0Y0Z 0a0b 0c0d 0e0f + * the odd bits in the word, and the even bits are zeroed:: + * + * 0A0B 0C0D 0E0F 0G0H 0I0J 0K0L 0M0N .... 0U0V 0W0X 0Y0Z 0a0b 0c0d 0e0f * * Any bits set in the top half of the input are ignored. * @@ -477,13 +483,16 @@ static inline uint64_t half_shuffle64(uint64_t x) /** * half_unshuffle32: - * @value: 32-bit value (of which only the odd bits are of interest) + * @x: 32-bit value (of which only the odd bits are of interest) + * + * Given an input value:: + * + * xAxB xCxD xExF xGxH xIxJ xKxL xMxN xOxP * - * Given an input value: - * xAxB xCxD xExF xGxH xIxJ xKxL xMxN xOxP * return the value where all the odd bits are compressed down - * into the low half of the word, and the high half is zeroed: - * 0000 0000 0000 0000 ABCD EFGH IJKL MNOP + * into the low half of the word, and the high half is zeroed:: + * + * 0000 0000 0000 0000 ABCD EFGH IJKL MNOP * * Any even bits set in the input are ignored. * @@ -504,13 +513,16 @@ static inline uint32_t half_unshuffle32(uint32_t x) /** * half_unshuffle64: - * @value: 64-bit value (of which only the odd bits are of interest) + * @x: 64-bit value (of which only the odd bits are of interest) + * + * Given an input value:: + * + * xAxB xCxD xExF xGxH xIxJ xKxL xMxN .... xUxV xWxX xYxZ xaxb xcxd xexf * - * Given an input value: - * xAxB xCxD xExF xGxH xIxJ xKxL xMxN .... xUxV xWxX xYxZ xaxb xcxd xexf * return the value where all the odd bits are compressed down - * into the low half of the word, and the high half is zeroed: - * 0000 0000 0000 .... 0000 0000 ABCD EFGH IJKL MNOP QRST UVWX YZab cdef + * into the low half of the word, and the high half is zeroed:: + * + * 0000 0000 0000 .... 0000 0000 ABCD EFGH IJKL MNOP QRST UVWX YZab cdef * * Any even bits set in the input are ignored. * diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h index 00d069b20f..87532d8596 100644 --- a/include/qemu/error-report.h +++ b/include/qemu/error-report.h @@ -73,6 +73,7 @@ void error_init(const char *argv0); }) const char *error_get_progname(void); -extern bool enable_timestamp_msg; + +extern bool error_with_timestamp; #endif diff --git a/include/qemu/log.h b/include/qemu/log.h index a91105b2ad..e0f4e40628 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -3,9 +3,16 @@ /* A small part of this API is split into its own header */ #include "qemu/log-for-trace.h" +#include "qemu/rcu.h" + +typedef struct QemuLogFile { + struct rcu_head rcu; + FILE *fd; +} QemuLogFile; /* Private global variable, don't use */ -extern FILE *qemu_logfile; +extern QemuLogFile *qemu_logfile; + /* * The new API: @@ -25,7 +32,16 @@ static inline bool qemu_log_enabled(void) */ static inline bool qemu_log_separate(void) { - return qemu_logfile != NULL && qemu_logfile != stderr; + QemuLogFile *logfile; + bool res = false; + + rcu_read_lock(); + logfile = atomic_rcu_read(&qemu_logfile); + if (logfile && logfile->fd != stderr) { + res = true; + } + rcu_read_unlock(); + return res; } #define CPU_LOG_TB_OUT_ASM (1 << 0) @@ -53,14 +69,25 @@ static inline bool qemu_log_separate(void) * qemu_loglevel is never set when qemu_logfile is unset. */ -static inline void qemu_log_lock(void) +static inline FILE *qemu_log_lock(void) { - qemu_flockfile(qemu_logfile); + QemuLogFile *logfile; + rcu_read_lock(); + logfile = atomic_rcu_read(&qemu_logfile); + if (logfile) { + qemu_flockfile(logfile->fd); + return logfile->fd; + } else { + return NULL; + } } -static inline void qemu_log_unlock(void) +static inline void qemu_log_unlock(FILE *fd) { - qemu_funlockfile(qemu_logfile); + if (fd) { + qemu_funlockfile(fd); + } + rcu_read_unlock(); } /* Logging functions: */ @@ -70,9 +97,14 @@ static inline void qemu_log_unlock(void) static inline void GCC_FMT_ATTR(1, 0) qemu_log_vprintf(const char *fmt, va_list va) { - if (qemu_logfile) { - vfprintf(qemu_logfile, fmt, va); + QemuLogFile *logfile; + + rcu_read_lock(); + logfile = atomic_rcu_read(&qemu_logfile); + if (logfile) { + vfprintf(logfile->fd, fmt, va); } + rcu_read_unlock(); } /* log only if a bit is set on the current loglevel mask: diff --git a/include/qom/object.h b/include/qom/object.h index 128d00c77f..1d7b7e5a79 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -200,8 +200,14 @@ typedef struct InterfaceInfo InterfaceInfo; * * Interfaces allow a limited form of multiple inheritance. Instances are * similar to normal types except for the fact that are only defined by - * their classes and never carry any state. You can dynamically cast an object - * to one of its #Interface types and vice versa. + * their classes and never carry any state. As a consequence, a pointer to + * an interface instance should always be of incomplete type in order to be + * sure it cannot be dereferenced. That is, you should define the + * 'typedef struct SomethingIf SomethingIf' so that you can pass around + * 'SomethingIf *si' arguments, but not define a 'struct SomethingIf { ... }'. + * The only things you can validly do with a 'SomethingIf *' are to pass it as + * an argument to a method on its corresponding SomethingIfClass, or to + * dynamically cast it to an object that implements the interface. * * # Methods # * @@ -592,6 +598,18 @@ struct InterfaceClass ((interface *)object_dynamic_cast_assert(OBJECT((obj)), (name), \ __FILE__, __LINE__, __func__)) +/** + * object_new_with_class: + * @klass: The class to instantiate. + * + * This function will initialize a new object using heap allocated memory. + * The returned object has a reference count of 1, and will be freed when + * the last reference is dropped. + * + * Returns: The newly allocated and instantiated object. + */ +Object *object_new_with_class(ObjectClass *klass); + /** * object_new: * @typename: The name of the type of the object to instantiate. @@ -679,6 +697,7 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp); void object_set_machine_compat_props(GPtrArray *compat_props); void object_set_accelerator_compat_props(GPtrArray *compat_props); +void object_register_sugar_prop(const char *driver, const char *prop, const char *value); void object_apply_compat_props(Object *obj); /** @@ -1635,9 +1654,9 @@ void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name, * property of type 'uint64'. */ void object_property_add_uint64_ptr(Object *obj, const char *name, - const uint64_t *v, Error **Errp); + const uint64_t *v, Error **errp); void object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name, - const uint64_t *v, Error **Errp); + const uint64_t *v, Error **errp); /** * object_property_add_alias: diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h index 8eb60b870b..d4c1429711 100644 --- a/include/sysemu/accel.h +++ b/include/sysemu/accel.h @@ -64,9 +64,9 @@ typedef struct AccelClass { #define ACCEL_GET_CLASS(obj) \ OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL) -extern unsigned long tcg_tb_size; +AccelClass *accel_find(const char *opt_name); +int accel_init_machine(AccelState *accel, MachineState *ms); -void configure_accelerator(MachineState *ms, const char *progname); /* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post(MachineState *ms); diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h index 32c05f27e7..3c1da6a018 100644 --- a/include/sysemu/cpus.h +++ b/include/sysemu/cpus.h @@ -40,6 +40,4 @@ extern int smp_threads; void list_cpus(const char *optarg); -void qemu_tcg_configure(QemuOpts *opts, Error **errp); - #endif diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 9fe233b9bf..141342de98 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -515,14 +515,16 @@ int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, qemu_irq irq); void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi); -void kvm_pc_gsi_handler(void *opaque, int n, int level); void kvm_pc_setup_irq_routing(bool pci_enabled); void kvm_init_irq_routing(KVMState *s); +bool kvm_kernel_irqchip_allowed(void); +bool kvm_kernel_irqchip_required(void); +bool kvm_kernel_irqchip_split(void); + /** * kvm_arch_irqchip_create: * @KVMState: The KVMState pointer - * @MachineState: The MachineState pointer * * Allow architectures to create an in-kernel irq chip themselves. * @@ -530,7 +532,7 @@ void kvm_init_irq_routing(KVMState *s); * 0: irq chip was not created * > 0: irq chip was created */ -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s); +int kvm_arch_irqchip_create(KVMState *s); /** * kvm_set_one_reg - set a register value in KVM via KVM_SET_ONE_REG ioctl diff --git a/linux-user/main.c b/linux-user/main.c index 6ff7851e86..8718d03ee2 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -826,7 +826,7 @@ int main(int argc, char **argv, char **envp) if (qemu_loglevel_mask(CPU_LOG_PAGE)) { qemu_log("guest_base 0x%lx\n", guest_base); - log_page_dump(); + log_page_dump("binary load"); qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk); qemu_log("end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code); diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 46a6e3a761..8685f02e7e 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -17,11 +17,10 @@ * along with this program; if not, see . */ #include "qemu/osdep.h" - +#include "trace.h" +#include "exec/log.h" #include "qemu.h" -//#define DEBUG_MMAP - static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER; static __thread int mmap_lock_count; @@ -66,13 +65,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot) abi_ulong end, host_start, host_end, addr; int prot1, ret; -#ifdef DEBUG_MMAP - printf("mprotect: start=0x" TARGET_ABI_FMT_lx - "len=0x" TARGET_ABI_FMT_lx " prot=%c%c%c\n", start, len, - prot & PROT_READ ? 'r' : '-', - prot & PROT_WRITE ? 'w' : '-', - prot & PROT_EXEC ? 'x' : '-'); -#endif + trace_target_mprotect(start, len, prot); if ((start & ~TARGET_PAGE_MASK) != 0) return -TARGET_EINVAL; @@ -369,32 +362,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_len; mmap_lock(); -#ifdef DEBUG_MMAP - { - printf("mmap: start=0x" TARGET_ABI_FMT_lx - " len=0x" TARGET_ABI_FMT_lx " prot=%c%c%c flags=", - start, len, - prot & PROT_READ ? 'r' : '-', - prot & PROT_WRITE ? 'w' : '-', - prot & PROT_EXEC ? 'x' : '-'); - if (flags & MAP_FIXED) - printf("MAP_FIXED "); - if (flags & MAP_ANONYMOUS) - printf("MAP_ANON "); - switch(flags & MAP_TYPE) { - case MAP_PRIVATE: - printf("MAP_PRIVATE "); - break; - case MAP_SHARED: - printf("MAP_SHARED "); - break; - default: - printf("[MAP_TYPE=0x%x] ", flags & MAP_TYPE); - break; - } - printf("fd=%d offset=" TARGET_ABI_FMT_lx "\n", fd, offset); - } -#endif + trace_target_mmap(start, len, prot, flags, fd, offset); if (!len) { errno = EINVAL; @@ -569,11 +537,10 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, the_end1: page_set_flags(start, start + len, prot | PAGE_VALID); the_end: -#ifdef DEBUG_MMAP - printf("ret=0x" TARGET_ABI_FMT_lx "\n", start); - page_dump(stdout); - printf("\n"); -#endif + trace_target_mmap_complete(start); + if (qemu_loglevel_mask(CPU_LOG_PAGE)) { + log_page_dump(__func__); + } tb_invalidate_phys_range(start, start + len); mmap_unlock(); return start; @@ -628,11 +595,8 @@ int target_munmap(abi_ulong start, abi_ulong len) abi_ulong end, real_start, real_end, addr; int prot, ret; -#ifdef DEBUG_MMAP - printf("munmap: start=0x" TARGET_ABI_FMT_lx " len=0x" - TARGET_ABI_FMT_lx "\n", - start, len); -#endif + trace_target_munmap(start, len); + if (start & ~TARGET_PAGE_MASK) return -TARGET_EINVAL; len = TARGET_PAGE_ALIGN(len); diff --git a/linux-user/trace-events b/linux-user/trace-events index 6df234bbb6..f6de1b8bef 100644 --- a/linux-user/trace-events +++ b/linux-user/trace-events @@ -11,3 +11,9 @@ user_handle_signal(void *env, int target_sig) "env=%p signal %d" user_host_signal(void *env, int host_sig, int target_sig) "env=%p signal %d (target %d(" user_queue_signal(void *env, int target_sig) "env=%p signal %d" user_s390x_restore_sigregs(void *env, uint64_t sc_psw_addr, uint64_t env_psw_addr) "env=%p frame psw.addr 0x%"PRIx64 " current psw.addr 0x%"PRIx64 + +# mmap.c +target_mprotect(uint64_t start, uint64_t len, int flags) "start=0x%"PRIx64 " len=0x%"PRIx64 " prot=0x%x" +target_mmap(uint64_t start, uint64_t len, int pflags, int mflags, int fd, uint64_t offset) "start=0x%"PRIx64 " len=0x%"PRIx64 " prot=0x%x flags=0x%x fd=%d offset=0x%"PRIx64 +target_mmap_complete(uint64_t retaddr) "retaddr=0x%"PRIx64 +target_munmap(uint64_t start, uint64_t len) "start=0x%"PRIx64" len=0x%"PRIx64 diff --git a/memory.c b/memory.c index 0228cad38d..d7b9bb6951 100644 --- a/memory.c +++ b/memory.c @@ -2991,7 +2991,6 @@ struct FlatViewInfo { bool dispatch_tree; bool owner; AccelClass *ac; - const char *ac_name; }; static void mtree_print_flatview(gpointer key, gpointer value, @@ -3061,7 +3060,7 @@ static void mtree_print_flatview(gpointer key, gpointer value, if (fvi->ac->has_memory(current_machine, as, int128_get64(range->addr.start), MR_SIZE(range->addr.size) + 1)) { - qemu_printf(" %s", fvi->ac_name); + qemu_printf(" %s", fvi->ac->name); } } } @@ -3109,8 +3108,6 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner) if (ac->has_memory) { fvi.ac = ac; - fvi.ac_name = current_machine->accel ? current_machine->accel : - object_class_get_name(OBJECT_CLASS(ac)); } /* Gather all FVs in one table */ diff --git a/migration/ram.c b/migration/ram.c index 38070f1bb2..96feb4062c 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -863,15 +863,17 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) p->next_packet_size = be32_to_cpu(packet->next_packet_size); p->packet_num = be64_to_cpu(packet->packet_num); - if (p->pages->used) { - /* make sure that ramblock is 0 terminated */ - packet->ramblock[255] = 0; - block = qemu_ram_block_by_name(packet->ramblock); - if (!block) { - error_setg(errp, "multifd: unknown ram block %s", - packet->ramblock); - return -1; - } + if (p->pages->used == 0) { + return 0; + } + + /* make sure that ramblock is 0 terminated */ + packet->ramblock[255] = 0; + block = qemu_ram_block_by_name(packet->ramblock); + if (!block) { + error_setg(errp, "multifd: unknown ram block %s", + packet->ramblock); + return -1; } for (i = 0; i < p->pages->used; i++) { @@ -3888,26 +3890,27 @@ int colo_init_ram_cache(void) { RAMBlock *block; - rcu_read_lock(); - RAMBLOCK_FOREACH_NOT_IGNORED(block) { - block->colo_cache = qemu_anon_ram_alloc(block->used_length, - NULL, - false); - if (!block->colo_cache) { - error_report("%s: Can't alloc memory for COLO cache of block %s," - "size 0x" RAM_ADDR_FMT, __func__, block->idstr, - block->used_length); - RAMBLOCK_FOREACH_NOT_IGNORED(block) { - if (block->colo_cache) { - qemu_anon_ram_free(block->colo_cache, block->used_length); - block->colo_cache = NULL; + WITH_RCU_READ_LOCK_GUARD() { + RAMBLOCK_FOREACH_NOT_IGNORED(block) { + block->colo_cache = qemu_anon_ram_alloc(block->used_length, + NULL, + false); + if (!block->colo_cache) { + error_report("%s: Can't alloc memory for COLO cache of block %s," + "size 0x" RAM_ADDR_FMT, __func__, block->idstr, + block->used_length); + RAMBLOCK_FOREACH_NOT_IGNORED(block) { + if (block->colo_cache) { + qemu_anon_ram_free(block->colo_cache, block->used_length); + block->colo_cache = NULL; + } } + return -errno; } - return -errno; + memcpy(block->colo_cache, block->host, block->used_length); } - memcpy(block->colo_cache, block->host, block->used_length); } - rcu_read_unlock(); + /* * Record the dirty pages that sent by PVM, we use this dirty bitmap together * with to decide which page in cache should be flushed into SVM's RAM. Here diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 5f8941d298..d0e0af893a 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -60,11 +60,10 @@ #include #endif -void hmp_handle_error(Monitor *mon, Error **errp) +void hmp_handle_error(Monitor *mon, Error *err) { - assert(errp); - if (*errp) { - error_reportf_err(*errp, "Error: "); + if (err) { + error_reportf_err(err, "Error: "); } } @@ -734,7 +733,7 @@ void hmp_info_vnc(Monitor *mon, const QDict *qdict) info2l = qmp_query_vnc_servers(&err); if (err) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } if (!info2l) { @@ -850,7 +849,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict) info = qmp_query_balloon(&err); if (err) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } @@ -1172,7 +1171,7 @@ void hmp_sync_profile(Monitor *mon, const QDict *qdict) Error *err = NULL; error_setg(&err, QERR_INVALID_PARAMETER, op); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } } @@ -1191,7 +1190,7 @@ void hmp_exit_preconfig(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_x_exit_preconfig(&err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_cpu(Monitor *mon, const QDict *qdict) @@ -1220,7 +1219,7 @@ void hmp_memsave(Monitor *mon, const QDict *qdict) } qmp_memsave(addr, size, filename, true, cpu_index, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_pmemsave(Monitor *mon, const QDict *qdict) @@ -1231,7 +1230,7 @@ void hmp_pmemsave(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_pmemsave(addr, size, filename, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) @@ -1242,7 +1241,7 @@ void hmp_ringbuf_write(Monitor *mon, const QDict *qdict) qmp_ringbuf_write(chardev, data, false, 0, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) @@ -1255,7 +1254,7 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) data = qmp_ringbuf_read(chardev, size, false, 0, &err); if (err) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } @@ -1280,7 +1279,7 @@ void hmp_cont(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_cont(&err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_system_wakeup(Monitor *mon, const QDict *qdict) @@ -1288,7 +1287,7 @@ void hmp_system_wakeup(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_system_wakeup(&err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_nmi(Monitor *mon, const QDict *qdict) @@ -1296,7 +1295,7 @@ void hmp_nmi(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_inject_nmi(&err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_set_link(Monitor *mon, const QDict *qdict) @@ -1306,7 +1305,7 @@ void hmp_set_link(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_set_link(name, up, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_block_passwd(Monitor *mon, const QDict *qdict) @@ -1316,7 +1315,7 @@ void hmp_block_passwd(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_block_passwd(true, device, false, NULL, password, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_balloon(Monitor *mon, const QDict *qdict) @@ -1325,7 +1324,7 @@ void hmp_balloon(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_balloon(value, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_block_resize(Monitor *mon, const QDict *qdict) @@ -1335,7 +1334,7 @@ void hmp_block_resize(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_block_resize(true, device, false, NULL, size, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_drive_mirror(Monitor *mon, const QDict *qdict) @@ -1358,11 +1357,11 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict) if (!filename) { error_setg(&err, QERR_MISSING_PARAMETER, "target"); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } qmp_drive_mirror(&mirror, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_drive_backup(Monitor *mon, const QDict *qdict) @@ -1388,12 +1387,12 @@ void hmp_drive_backup(Monitor *mon, const QDict *qdict) if (!filename) { error_setg(&err, QERR_MISSING_PARAMETER, "target"); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } qmp_drive_backup(&backup, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) @@ -1409,7 +1408,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) /* In the future, if 'snapshot-file' is not specified, the snapshot will be taken internally. Today it's actually required. */ error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file"); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } @@ -1418,7 +1417,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict) filename, false, NULL, !!format, format, true, mode, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict) @@ -1428,7 +1427,7 @@ void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_blockdev_snapshot_internal_sync(device, name, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict) @@ -1440,7 +1439,7 @@ void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict) qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id, true, name, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_loadvm(Monitor *mon, const QDict *qdict) @@ -1454,7 +1453,7 @@ void hmp_loadvm(Monitor *mon, const QDict *qdict) if (load_snapshot(name, &err) == 0 && saved_vm_running) { vm_start(); } - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_savevm(Monitor *mon, const QDict *qdict) @@ -1462,7 +1461,7 @@ void hmp_savevm(Monitor *mon, const QDict *qdict) Error *err = NULL; save_snapshot(qdict_get_try_str(qdict, "name"), &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_delvm(Monitor *mon, const QDict *qdict) @@ -1476,7 +1475,7 @@ void hmp_delvm(Monitor *mon, const QDict *qdict) "deleting snapshot on device '%s': ", bdrv_get_device_name(bs)); } - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_info_snapshots(Monitor *mon, const QDict *qdict) @@ -1652,7 +1651,7 @@ void hmp_migrate_continue(Monitor *mon, const QDict *qdict) qmp_migrate_continue(val, &err); } - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) @@ -1662,7 +1661,7 @@ void hmp_migrate_incoming(Monitor *mon, const QDict *qdict) qmp_migrate_incoming(uri, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_migrate_recover(Monitor *mon, const QDict *qdict) @@ -1672,7 +1671,7 @@ void hmp_migrate_recover(Monitor *mon, const QDict *qdict) qmp_migrate_recover(uri, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_migrate_pause(Monitor *mon, const QDict *qdict) @@ -1681,7 +1680,7 @@ void hmp_migrate_pause(Monitor *mon, const QDict *qdict) qmp_migrate_pause(&err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } /* Kept for backwards compatibility */ @@ -1697,7 +1696,7 @@ void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_migrate_set_cache_size(value, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } /* Kept for backwards compatibility */ @@ -1728,7 +1727,7 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict) end: qapi_free_MigrationCapabilityStatusList(caps); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) @@ -1869,7 +1868,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) cleanup: qapi_free_MigrateSetParameters(p); visit_free(v); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) @@ -1886,14 +1885,14 @@ void hmp_client_migrate_info(Monitor *mon, const QDict *qdict) qmp_client_migrate_info(protocol, hostname, has_port, port, has_tls_port, tls_port, !!cert_subject, cert_subject, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict) { Error *err = NULL; qmp_migrate_start_postcopy(&err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) @@ -1901,7 +1900,7 @@ void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_x_colo_lost_heartbeat(&err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_set_password(Monitor *mon, const QDict *qdict) @@ -1912,7 +1911,7 @@ void hmp_set_password(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_set_password(protocol, password, !!connected, connected, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_expire_password(Monitor *mon, const QDict *qdict) @@ -1922,7 +1921,7 @@ void hmp_expire_password(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_expire_password(protocol, whenstr, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_eject(Monitor *mon, const QDict *qdict) @@ -1932,7 +1931,7 @@ void hmp_eject(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_eject(true, device, false, NULL, true, force, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } #ifdef CONFIG_VNC @@ -1978,7 +1977,7 @@ void hmp_change(Monitor *mon, const QDict *qdict) read_only, BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err); if (err) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } } @@ -1988,7 +1987,7 @@ void hmp_change(Monitor *mon, const QDict *qdict) &err); } - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) @@ -2016,7 +2015,7 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict) } qmp_block_set_io_throttle(&throttle, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_block_stream(Monitor *mon, const QDict *qdict) @@ -2031,7 +2030,7 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict) BLOCKDEV_ON_ERROR_REPORT, false, false, false, false, &error); - hmp_handle_error(mon, &error); + hmp_handle_error(mon, error); } void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) @@ -2042,7 +2041,7 @@ void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict) qmp_block_job_set_speed(device, value, &error); - hmp_handle_error(mon, &error); + hmp_handle_error(mon, error); } void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) @@ -2053,7 +2052,7 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict) qmp_block_job_cancel(device, true, force, &error); - hmp_handle_error(mon, &error); + hmp_handle_error(mon, error); } void hmp_block_job_pause(Monitor *mon, const QDict *qdict) @@ -2063,7 +2062,7 @@ void hmp_block_job_pause(Monitor *mon, const QDict *qdict) qmp_block_job_pause(device, &error); - hmp_handle_error(mon, &error); + hmp_handle_error(mon, error); } void hmp_block_job_resume(Monitor *mon, const QDict *qdict) @@ -2073,7 +2072,7 @@ void hmp_block_job_resume(Monitor *mon, const QDict *qdict) qmp_block_job_resume(device, &error); - hmp_handle_error(mon, &error); + hmp_handle_error(mon, error); } void hmp_block_job_complete(Monitor *mon, const QDict *qdict) @@ -2083,7 +2082,7 @@ void hmp_block_job_complete(Monitor *mon, const QDict *qdict) qmp_block_job_complete(device, &error); - hmp_handle_error(mon, &error); + hmp_handle_error(mon, error); } typedef struct HMPMigrationStatus @@ -2143,7 +2142,7 @@ void hmp_migrate(Monitor *mon, const QDict *qdict) qmp_migrate(uri, !!blk, blk, !!inc, inc, false, false, true, resume, &err); if (err) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } @@ -2181,7 +2180,7 @@ void hmp_netdev_add(Monitor *mon, const QDict *qdict) } out: - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_netdev_del(Monitor *mon, const QDict *qdict) @@ -2190,7 +2189,7 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_netdev_del(id, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_object_add(Monitor *mon, const QDict *qdict) @@ -2201,7 +2200,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict) opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); if (err) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } @@ -2209,7 +2208,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict) qemu_opts_del(opts); if (err) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } if (obj) { object_unref(obj); @@ -2222,7 +2221,7 @@ void hmp_getfd(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_getfd(fdname, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_closefd(Monitor *mon, const QDict *qdict) @@ -2231,7 +2230,7 @@ void hmp_closefd(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_closefd(fdname, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_sendkey(Monitor *mon, const QDict *qdict) @@ -2290,7 +2289,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) } qmp_send_key(head, has_hold_time, hold_time, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); out: qapi_free_KeyValueList(head); @@ -2309,7 +2308,7 @@ void hmp_screendump(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_screendump(filename, id != NULL, id, id != NULL, head, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) @@ -2364,7 +2363,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) qapi_free_BlockInfoList(block_list); exit: - hmp_handle_error(mon, &local_err); + hmp_handle_error(mon, local_err); } void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) @@ -2376,7 +2375,7 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) qmp_nbd_server_add(device, !!name, name, true, writable, false, NULL, &local_err); - hmp_handle_error(mon, &local_err); + hmp_handle_error(mon, local_err); } void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) @@ -2387,7 +2386,7 @@ void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */ qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) @@ -2395,7 +2394,7 @@ void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_nbd_server_stop(&err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_chardev_add(Monitor *mon, const QDict *qdict) @@ -2411,7 +2410,7 @@ void hmp_chardev_add(Monitor *mon, const QDict *qdict) qemu_chr_new_from_opts(opts, NULL, &err); qemu_opts_del(opts); } - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_chardev_change(Monitor *mon, const QDict *qdict) @@ -2445,7 +2444,7 @@ end: qapi_free_ChardevReturn(ret); qapi_free_ChardevBackend(backend); qemu_opts_del(opts); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_chardev_remove(Monitor *mon, const QDict *qdict) @@ -2453,7 +2452,7 @@ void hmp_chardev_remove(Monitor *mon, const QDict *qdict) Error *local_err = NULL; qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err); - hmp_handle_error(mon, &local_err); + hmp_handle_error(mon, local_err); } void hmp_chardev_send_break(Monitor *mon, const QDict *qdict) @@ -2461,7 +2460,7 @@ void hmp_chardev_send_break(Monitor *mon, const QDict *qdict) Error *local_err = NULL; qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err); - hmp_handle_error(mon, &local_err); + hmp_handle_error(mon, local_err); } void hmp_qemu_io(Monitor *mon, const QDict *qdict) @@ -2525,7 +2524,7 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) fail: blk_unref(local_blk); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_object_del(Monitor *mon, const QDict *qdict) @@ -2534,7 +2533,7 @@ void hmp_object_del(Monitor *mon, const QDict *qdict) Error *err = NULL; user_creatable_del(id, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) @@ -2584,7 +2583,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) } qapi_free_MemoryDeviceInfoList(info_list); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_info_iothreads(Monitor *mon, const QDict *qdict) @@ -2613,7 +2612,7 @@ void hmp_rocker(Monitor *mon, const QDict *qdict) rocker = qmp_query_rocker(name, &err); if (err != NULL) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } @@ -2632,7 +2631,7 @@ void hmp_rocker_ports(Monitor *mon, const QDict *qdict) list = qmp_query_rocker_ports(name, &err); if (err != NULL) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } @@ -2661,7 +2660,7 @@ void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict) list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err); if (err != NULL) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } @@ -2812,7 +2811,7 @@ void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict) list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err); if (err != NULL) { - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); return; } @@ -2919,7 +2918,7 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) if (info) { monitor_printf(mon, "%s\n", info->guid); } - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); qapi_free_GuidInfo(info); } @@ -2938,5 +2937,5 @@ void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) qapi_free_MemoryInfo(info); } - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } diff --git a/monitor/misc.c b/monitor/misc.c index 3baa15f3bf..a04d7edde0 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -106,9 +106,6 @@ struct MonFdset { QLIST_ENTRY(MonFdset) next; }; -/* QMP checker flags */ -#define QMP_ACCEPT_UNKNOWNS 1 - /* Protects mon_fdsets */ static QemuMutex mon_fdsets_lock; static QLIST_HEAD(, MonFdset) mon_fdsets; @@ -394,7 +391,7 @@ int monitor_set_cpu(int cpu_index) /* Callers must hold BQL. */ static CPUState *mon_get_cpu_sync(bool synchronize) { - CPUState *cpu; + CPUState *cpu = NULL; if (cur_mon->mon_cpu_path) { cpu = (CPUState *) object_resolve_path_type(cur_mon->mon_cpu_path, @@ -411,6 +408,7 @@ static CPUState *mon_get_cpu_sync(bool synchronize) monitor_set_cpu(first_cpu->cpu_index); cpu = first_cpu; } + assert(cpu != NULL); if (synchronize) { cpu_synchronize_state(cpu); } diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 0880341a2d..c6faa3eaf0 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -109,7 +109,7 @@ void qmp_system_reset(Error **errp) qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP_SYSTEM_RESET); } -void qmp_system_powerdown(Error **erp) +void qmp_system_powerdown(Error **errp) { qemu_system_powerdown_request(); } diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c index 8a6ffad40c..29bfacd4f8 100644 --- a/net/can/can_socketcan.c +++ b/net/can/can_socketcan.c @@ -76,8 +76,7 @@ QEMU_BUILD_BUG_ON(offsetof(qemu_can_frame, data) static void can_host_socketcan_display_msg(struct qemu_can_frame *msg) { int i; - - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("[cansocketcan]: %03X [%01d] %s %s", msg->can_id & QEMU_CAN_EFF_MASK, msg->can_dlc, @@ -89,7 +88,7 @@ static void can_host_socketcan_display_msg(struct qemu_can_frame *msg) } qemu_log("\n"); qemu_log_flush(); - qemu_log_unlock(); + qemu_log_unlock(logfile); } static void can_host_socketcan_read(void *opaque) diff --git a/net/net.c b/net/net.c index 84aa6d8d00..9e93c3f8a1 100644 --- a/net/net.c +++ b/net/net.c @@ -1126,16 +1126,13 @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) prefix_addr = substrings[0]; - if (substrings[1]) { - /* User-specified prefix length. */ - int err; - - err = qemu_strtoul(substrings[1], NULL, 10, &prefix_len); - if (err) { - error_setg(errp, QERR_INVALID_PARAMETER_VALUE, - "ipv6-prefixlen", "a number"); - goto out; - } + /* Handle user-specified prefix length. */ + if (substrings[1] && + qemu_strtoul(substrings[1], NULL, 10, &prefix_len)) + { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "ipv6-prefixlen", "a number"); + goto out; } qemu_opt_set(opts, "ipv6-prefix", prefix_addr, &error_abort); diff --git a/os-posix.c b/os-posix.c index 86cffd2c7d..3cd52e1e70 100644 --- a/os-posix.c +++ b/os-posix.c @@ -80,41 +80,26 @@ void os_setup_signal_handling(void) sigaction(SIGTERM, &act, NULL); } -/* Find a likely location for support files using the location of the binary. - For installed binaries this will be "$bindir/../share/qemu". When - running from the build tree this will be "$bindir/../pc-bios". */ -#define SHARE_SUFFIX "/share/qemu" -#define BUILD_SUFFIX "/pc-bios" +/* + * Find a likely location for support files using the location of the binary. + * When running from the build tree this will be "$bindir/../pc-bios". + * Otherwise, this is CONFIG_QEMU_DATADIR. + */ char *os_find_datadir(void) { - char *dir, *exec_dir; - char *res; - size_t max_len; + g_autofree char *exec_dir = NULL; + g_autofree char *dir = NULL; exec_dir = qemu_get_exec_dir(); - if (exec_dir == NULL) { - return NULL; - } - dir = g_path_get_dirname(exec_dir); - - max_len = strlen(dir) + - MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1; - res = g_malloc0(max_len); - snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX); - if (access(res, R_OK)) { - snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX); - if (access(res, R_OK)) { - g_free(res); - res = NULL; - } + g_return_val_if_fail(exec_dir != NULL, NULL); + + dir = g_build_filename(exec_dir, "..", "pc-bios", NULL); + if (g_file_test(dir, G_FILE_TEST_IS_DIR)) { + return g_steal_pointer(&dir); } - g_free(dir); - g_free(exec_dir); - return res; + return g_strdup(CONFIG_QEMU_DATADIR); } -#undef SHARE_SUFFIX -#undef BUILD_SUFFIX void os_set_proc_name(const char *s) { diff --git a/pc-bios/s390-ccw.img b/pc-bios/s390-ccw.img index c84ae93561..91cdee4436 100644 Binary files a/pc-bios/s390-ccw.img and b/pc-bios/s390-ccw.img differ diff --git a/pc-bios/s390-ccw/jump2ipl.c b/pc-bios/s390-ccw/jump2ipl.c index 266f1502b9..da13c43cc0 100644 --- a/pc-bios/s390-ccw/jump2ipl.c +++ b/pc-bios/s390-ccw/jump2ipl.c @@ -12,11 +12,11 @@ #define KERN_IMAGE_START 0x010000UL #define PSW_MASK_64 0x0000000100000000ULL #define PSW_MASK_32 0x0000000080000000ULL -#define IPL_PSW_MASK (PSW_MASK_32 | PSW_MASK_64) +#define PSW_MASK_SHORTPSW 0x0008000000000000ULL +#define RESET_PSW_MASK (PSW_MASK_SHORTPSW | PSW_MASK_32 | PSW_MASK_64) typedef struct ResetInfo { - uint32_t ipl_mask; - uint32_t ipl_addr; + uint64_t ipl_psw; uint32_t ipl_continue; } ResetInfo; @@ -50,7 +50,9 @@ void jump_to_IPL_code(uint64_t address) ResetInfo *current = 0; save = *current; - current->ipl_addr = (uint32_t) (uint64_t) &jump_to_IPL_2; + + current->ipl_psw = (uint64_t) &jump_to_IPL_2; + current->ipl_psw |= RESET_PSW_MASK; current->ipl_continue = address & 0x7fffffff; debug_print_int("set IPL addr to", current->ipl_continue); @@ -82,7 +84,7 @@ void jump_to_low_kernel(void) } /* Trying to get PSW at zero address */ - if (*((uint64_t *)0) & IPL_PSW_MASK) { + if (*((uint64_t *)0) & RESET_PSW_MASK) { jump_to_IPL_code((*((uint64_t *)0)) & 0x7fffffff); } diff --git a/pc-bios/s390-netboot.img b/pc-bios/s390-netboot.img index f9ef28ef1a..6bb5c86eb0 100644 Binary files a/pc-bios/s390-netboot.img and b/pc-bios/s390-netboot.img differ diff --git a/qdev-monitor.c b/qdev-monitor.c index e6b112eb0a..3465a1e2d0 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -328,7 +328,8 @@ static Object *qdev_get_peripheral_anon(void) return dev; } -static void qbus_list_bus(DeviceState *dev, Error **errp) +static void qbus_error_append_bus_list_hint(DeviceState *dev, + Error *const *errp) { BusState *child; const char *sep = " "; @@ -342,7 +343,8 @@ static void qbus_list_bus(DeviceState *dev, Error **errp) error_append_hint(errp, "\n"); } -static void qbus_list_dev(BusState *bus, Error **errp) +static void qbus_error_append_dev_list_hint(BusState *bus, + Error *const *errp) { BusChild *kid; const char *sep = " "; @@ -500,7 +502,7 @@ static BusState *qbus_find(const char *path, Error **errp) if (!dev) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", elem); - qbus_list_dev(bus, errp); + qbus_error_append_dev_list_hint(bus, errp); return NULL; } @@ -518,7 +520,7 @@ static BusState *qbus_find(const char *path, Error **errp) if (dev->num_child_bus) { error_setg(errp, "Device '%s' has multiple child buses", elem); - qbus_list_bus(dev, errp); + qbus_error_append_bus_list_hint(dev, errp); } else { error_setg(errp, "Device '%s' has no child bus", elem); } @@ -534,7 +536,7 @@ static BusState *qbus_find(const char *path, Error **errp) bus = qbus_find_bus(dev, elem); if (!bus) { error_setg(errp, "Bus '%s' not found", elem); - qbus_list_bus(dev, errp); + qbus_error_append_bus_list_hint(dev, errp); return NULL; } } @@ -890,7 +892,7 @@ void hmp_device_add(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_device_add((QDict *)qdict, NULL, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_device_del(Monitor *mon, const QDict *qdict) @@ -899,7 +901,7 @@ void hmp_device_del(Monitor *mon, const QDict *qdict) Error *err = NULL; qmp_device_del(id, &err); - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } BlockBackend *blk_by_qdev_id(const char *id, Error **errp) diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index 3d50ec094c..88b26747fc 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -43,7 +43,7 @@ #include "net/tap-linux.h" -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG #include #endif @@ -207,7 +207,7 @@ static int send_fd(int c, int fd) return sendmsg(c, &msg, 0); } -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG static int drop_privileges(void) { /* clear all capabilities */ @@ -246,7 +246,7 @@ int main(int argc, char **argv) int access_allowed, access_denied; int ret = EXIT_SUCCESS; -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG /* if we're run from an suid binary, immediately drop privileges preserving * cap_net_admin */ if (geteuid() == 0 && getuid() != geteuid()) { diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi index 62680f7bd5..97ba3cb88c 100644 --- a/qemu-deprecated.texi +++ b/qemu-deprecated.texi @@ -142,6 +142,12 @@ QEMU 4.1 has three options, please migrate to one of these three: to do is specify the kernel they want to boot with the -kernel option 3. ``-bios `` - Tells QEMU to load the specified file as the firmwrae. +@subsection -tb-size option (since 5.0) + +QEMU 5.0 introduced an alternative syntax to specify the size of the translation +block cache, @option{-accel tcg,tb-size=}. The new syntax deprecates the +previously available @option{-tb-size} option. + @section QEMU Machine Protocol (QMP) commands @subsection change (since 2.5.0) @@ -259,7 +265,7 @@ The 'scsi-disk' device is deprecated. Users should use 'scsi-hd' or This machine type is very old and unmaintained. Users should use the 'malta' machine type instead. -@subsection pc-0.12, pc-0.13, pc-0.14 and pc-0.15 (since 4.0) +@subsection pc-1.0, pc-1.1, pc-1.2 and pc-1.3 (since 5.0) These machine types are very old and likely can not be used for live migration from old QEMU versions anymore. A newer machine type should be used instead. diff --git a/qemu-doc.texi b/qemu-doc.texi index eea91a2d1e..39f950471f 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -38,7 +38,6 @@ * Introduction:: * QEMU PC System emulator:: * QEMU System emulator for non PC targets:: -* QEMU Guest Agent:: * QEMU User space emulator:: * System requirements:: * Security:: diff --git a/qemu-options.hx b/qemu-options.hx index c63e794b64..e9d6231438 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -32,12 +32,9 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " selects emulated machine ('-machine help' for list)\n" " property accel=accel1[:accel2[:...]] selects accelerator\n" " supported accelerators are kvm, xen, hax, hvf, whpx or tcg (default: tcg)\n" - " kernel_irqchip=on|off|split controls accelerated irqchip support (default=off)\n" " vmport=on|off|auto controls emulation of vmport (default: auto)\n" - " kvm_shadow_mem=size of KVM shadow MMU in bytes\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" - " igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n" " suppress-vmdesc=on|off disables self-describing migration (default=off)\n" @@ -69,16 +66,10 @@ This is used to enable an accelerator. Depending on the target architecture, kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If there is more than one accelerator specified, the next one is used if the previous one fails to initialize. -@item kernel_irqchip=on|off -Controls in-kernel irqchip support for the chosen accelerator when available. -@item gfx_passthru=on|off -Enables IGD GFX passthrough support for the chosen machine when available. @item vmport=on|off|auto Enables emulation of VMWare IO port, for vmmouse etc. auto says to select the value based on accel. For accel=xen the default is off otherwise the default is on. -@item kvm_shadow_mem=size -Defines the size of the KVM shadow MMU. @item dump-guest-core=on|off Include guest memory in a core dump. The default is on. @item mem-merge=on|off @@ -118,8 +109,12 @@ Select CPU model (@code{-cpu help} for list and additional feature selection) ETEXI DEF("accel", HAS_ARG, QEMU_OPTION_accel, - "-accel [accel=]accelerator[,thread=single|multi]\n" + "-accel [accel=]accelerator[,prop[=value][,...]]\n" " select accelerator (kvm, xen, hax, hvf, whpx or tcg; use 'help' for a list)\n" + " igd-passthru=on|off (enable Xen integrated Intel graphics passthrough, default=off)\n" + " kernel-irqchip=on|off|split controls accelerated irqchip support (default=on)\n" + " kvm-shadow-mem=size of KVM shadow MMU in bytes\n" + " tb-size=n (TCG translation block cache size)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) STEXI @item -accel @var{name}[,prop=@var{value}[,...]] @@ -129,6 +124,18 @@ kvm, xen, hax, hvf, whpx or tcg can be available. By default, tcg is used. If th more than one accelerator specified, the next one is used if the previous one fails to initialize. @table @option +@item igd-passthru=on|off +When Xen is in use, this option controls whether Intel integrated graphics +devices can be passed through to the guest (default=off) +@item kernel-irqchip=on|off|split +Controls KVM in-kernel irqchip support. The default is full acceleration of the +interrupt controllers. On x86, split irqchip reduces the kernel attack +surface, at a performance cost for non-MSI interrupts. Disabling the in-kernel +irqchip completely is not recommended except for debugging purposes. +@item kvm-shadow-mem=size +Defines the size of the KVM shadow MMU. +@item tb-size=@var{n} +Controls the size (in MiB) of the TCG translation block cache. @item thread=single|multi Controls number of TCG threads. When the TCG is multi-threaded there will be one thread per vCPU therefor taking advantage of additional host cores. The default @@ -327,8 +334,8 @@ format(true color). The resolution should be supported by the SVGA mode, so the recommended is 320x240, 640x480, 800x640. A timeout could be passed to bios, guest will pause for @var{rb_timeout} ms -when boot failed, then reboot. If @option{reboot-timeout} is not set, -guest will not reboot by default. Currently Seabios for X86 +when boot failed, then reboot. If @var{rb_timeout} is '-1', guest will not +reboot, qemu passes '-1' to bios by default. Currently Seabios for X86 system support it. Do strict boot via @option{strict=on} as far as firmware/BIOS @@ -3923,7 +3930,8 @@ DEF("tb-size", HAS_ARG, QEMU_OPTION_tb_size, \ STEXI @item -tb-size @var{n} @findex -tb-size -Set TB size. +Set TCG translation block cache size. Deprecated, use @samp{-accel tcg,tb-size=@var{n}} +instead. ETEXI DEF("incoming", HAS_ARG, QEMU_OPTION_incoming, \ @@ -4167,13 +4175,17 @@ DEF("no-kvm", 0, QEMU_OPTION_no_kvm, "", QEMU_ARCH_I386) DEF("msg", HAS_ARG, QEMU_OPTION_msg, "-msg timestamp[=on|off]\n" - " change the format of messages\n" - " on|off controls leading timestamps (default:on)\n", + " control error message format\n" + " timestamp=on enables timestamps (default: off)\n", QEMU_ARCH_ALL) STEXI @item -msg timestamp[=on|off] @findex -msg -prepend a timestamp to each log message.(default:on) +Control error message format. +@table @option +@item timestamp=on|off +Prefix messages with a timestamp. Default is off. +@end table ETEXI DEF("dump-vmstate", HAS_ARG, QEMU_OPTION_dump_vmstate, diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 0be301a4ea..93474ff770 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1060,6 +1060,7 @@ static void build_guest_fsinfo_for_virtual_device(char const *syspath, GuestFilesystemInfo *fs, Error **errp) { + Error *err = NULL; DIR *dir; char *dirpath; struct dirent *entry; @@ -1089,10 +1090,11 @@ static void build_guest_fsinfo_for_virtual_device(char const *syspath, g_debug(" slave device '%s'", entry->d_name); path = g_strdup_printf("%s/slaves/%s", syspath, entry->d_name); - build_guest_fsinfo_for_device(path, fs, errp); + build_guest_fsinfo_for_device(path, fs, &err); g_free(path); - if (*errp) { + if (err) { + error_propagate(errp, err); break; } } @@ -2792,7 +2794,7 @@ static double ga_get_login_time(struct utmpx *user_info) return seconds + useconds; } -GuestUserList *qmp_guest_get_users(Error **err) +GuestUserList *qmp_guest_get_users(Error **errp) { GHashTable *cache = NULL; GuestUserList *head = NULL, *cur_item = NULL; diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 55ba5b263a..2461fd19bf 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1946,7 +1946,7 @@ typedef struct _GA_WTSINFOA { } GA_WTSINFOA; -GuestUserList *qmp_guest_get_users(Error **err) +GuestUserList *qmp_guest_get_users(Error **errp) { #define QGA_NANOSECONDS 10000000 diff --git a/qga/commands.c b/qga/commands.c index 0c7d1385c2..43c323cead 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -143,7 +143,7 @@ static GuestExecInfo *guest_exec_info_find(int64_t pid_numeric) return NULL; } -GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **err) +GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **errp) { GuestExecInfo *gei; GuestExecStatus *ges; @@ -152,7 +152,7 @@ GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **err) gei = guest_exec_info_find(pid); if (gei == NULL) { - error_setg(err, QERR_INVALID_PARAMETER, "pid"); + error_setg(errp, QERR_INVALID_PARAMETER, "pid"); return NULL; } @@ -385,7 +385,7 @@ GuestExec *qmp_guest_exec(const char *path, bool has_env, strList *env, bool has_input_data, const char *input_data, bool has_capture_output, bool capture_output, - Error **err) + Error **errp) { GPid pid; GuestExec *ge = NULL; @@ -405,7 +405,7 @@ GuestExec *qmp_guest_exec(const char *path, arglist.next = has_arg ? arg : NULL; if (has_input_data) { - input = qbase64_decode(input_data, -1, &ninput, err); + input = qbase64_decode(input_data, -1, &ninput, errp); if (!input) { return NULL; } @@ -424,7 +424,7 @@ GuestExec *qmp_guest_exec(const char *path, guest_exec_task_setup, NULL, &pid, has_input_data ? &in_fd : NULL, has_output ? &out_fd : NULL, has_output ? &err_fd : NULL, &gerr); if (!ret) { - error_setg(err, QERR_QGA_COMMAND_FAILED, gerr->message); + error_setg(errp, QERR_QGA_COMMAND_FAILED, gerr->message); g_error_free(gerr); goto done; } @@ -499,7 +499,7 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp) return -1; } -GuestHostName *qmp_guest_get_host_name(Error **err) +GuestHostName *qmp_guest_get_host_name(Error **errp) { GuestHostName *result = NULL; gchar const *hostname = g_get_host_name(); diff --git a/qom/object.c b/qom/object.c index d51b57fba1..0d971ca897 100644 --- a/qom/object.c +++ b/qom/object.c @@ -414,10 +414,29 @@ void object_apply_global_props(Object *obj, const GPtrArray *props, Error **errp * Global property defaults * Slot 0: accelerator's global property defaults * Slot 1: machine's global property defaults + * Slot 2: global properties from legacy command line option * Each is a GPtrArray of of GlobalProperty. * Applied in order, later entries override earlier ones. */ -static GPtrArray *object_compat_props[2]; +static GPtrArray *object_compat_props[3]; + +/* + * Retrieve @GPtrArray for global property defined with options + * other than "-global". These are generally used for syntactic + * sugar and legacy command line options. + */ +void object_register_sugar_prop(const char *driver, const char *prop, const char *value) +{ + GlobalProperty *g; + if (!object_compat_props[2]) { + object_compat_props[2] = g_ptr_array_new(); + } + g = g_new0(GlobalProperty, 1); + g->driver = g_strdup(driver); + g->property = g_strdup(prop); + g->value = g_strdup(value); + g_ptr_array_add(object_compat_props[2], g); +} /* * Set machine's global property defaults to @compat_props. @@ -445,7 +464,7 @@ void object_apply_compat_props(Object *obj) for (i = 0; i < ARRAY_SIZE(object_compat_props); i++) { object_apply_global_props(obj, object_compat_props[i], - &error_abort); + i == 2 ? &error_fatal : &error_abort); } } @@ -639,6 +658,11 @@ static Object *object_new_with_type(Type type) return obj; } +Object *object_new_with_class(ObjectClass *klass) +{ + return object_new_with_type(klass->type); +} + Object *object_new(const char *typename) { TypeImpl *ti = type_get_by_name(typename); diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c index a268e01eb4..cd08233a4c 100644 --- a/qom/qom-hmp-cmds.c +++ b/qom/qom-hmp-cmds.c @@ -37,7 +37,7 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict) } qapi_free_ObjectPropertyInfoList(start); } - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } void hmp_qom_set(Monitor *mon, const QDict *qdict) @@ -59,7 +59,7 @@ void hmp_qom_set(Monitor *mon, const QDict *qdict) } object_property_parse(obj, value, property, &err); } - hmp_handle_error(mon, &err); + hmp_handle_error(mon, err); } typedef struct QOMCompositionState { diff --git a/scripts/kernel-doc b/scripts/kernel-doc new file mode 100755 index 0000000000..af470eb321 --- /dev/null +++ b/scripts/kernel-doc @@ -0,0 +1,2236 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 + +use warnings; +use strict; + +## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## +## Copyright (C) 2000, 1 Tim Waugh ## +## Copyright (C) 2001 Simon Huggins ## +## Copyright (C) 2005-2012 Randy Dunlap ## +## Copyright (C) 2012 Dan Luedtke ## +## ## +## #define enhancements by Armin Kuster ## +## Copyright (c) 2000 MontaVista Software, Inc. ## +## ## +## This software falls under the GNU General Public License. ## +## Please read the COPYING file for more information ## + +# 18/01/2001 - Cleanups +# Functions prototyped as foo(void) same as foo() +# Stop eval'ing where we don't need to. +# -- huggie@earth.li + +# 27/06/2001 - Allowed whitespace after initial "/**" and +# allowed comments before function declarations. +# -- Christian Kreibich + +# Still to do: +# - add perldoc documentation +# - Look more closely at some of the scarier bits :) + +# 26/05/2001 - Support for separate source and object trees. +# Return error code. +# Keith Owens + +# 23/09/2001 - Added support for typedefs, structs, enums and unions +# Support for Context section; can be terminated using empty line +# Small fixes (like spaces vs. \s in regex) +# -- Tim Jansen + +# 25/07/2012 - Added support for HTML5 +# -- Dan Luedtke + +sub usage { + my $message = <<"EOF"; +Usage: $0 [OPTION ...] FILE ... + +Read C language source or header FILEs, extract embedded documentation comments, +and print formatted documentation to standard output. + +The documentation comments are identified by "/**" opening comment mark. See +Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax. + +Output format selection (mutually exclusive): + -man Output troff manual page format. This is the default. + -rst Output reStructuredText format. + -none Do not output documentation, only warnings. + +Output selection (mutually exclusive): + -export Only output documentation for symbols that have been + exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() + in any input FILE or -export-file FILE. + -internal Only output documentation for symbols that have NOT been + exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() + in any input FILE or -export-file FILE. + -function NAME Only output documentation for the given function(s) + or DOC: section title(s). All other functions and DOC: + sections are ignored. May be specified multiple times. + -nofunction NAME Do NOT output documentation for the given function(s); + only output documentation for the other functions and + DOC: sections. May be specified multiple times. + +Output selection modifiers: + -no-doc-sections Do not output DOC: sections. + -enable-lineno Enable output of #define LINENO lines. Only works with + reStructuredText format. + -export-file FILE Specify an additional FILE in which to look for + EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with + -export or -internal. May be specified multiple times. + +Other parameters: + -v Verbose output, more warnings and other information. + -h Print this help. + +EOF + print $message; + exit 1; +} + +# +# format of comments. +# In the following table, (...)? signifies optional structure. +# (...)* signifies 0 or more structure elements +# /** +# * function_name(:)? (- short description)? +# (* @parameterx: (description of parameter x)?)* +# (* a blank line)? +# * (Description:)? (Description of function)? +# * (section header: (section description)? )* +# (*)?*/ +# +# So .. the trivial example would be: +# +# /** +# * my_function +# */ +# +# If the Description: header tag is omitted, then there must be a blank line +# after the last parameter specification. +# e.g. +# /** +# * my_function - does my stuff +# * @my_arg: its mine damnit +# * +# * Does my stuff explained. +# */ +# +# or, could also use: +# /** +# * my_function - does my stuff +# * @my_arg: its mine damnit +# * Description: Does my stuff explained. +# */ +# etc. +# +# Besides functions you can also write documentation for structs, unions, +# enums and typedefs. Instead of the function name you must write the name +# of the declaration; the struct/union/enum/typedef must always precede +# the name. Nesting of declarations is not supported. +# Use the argument mechanism to document members or constants. +# e.g. +# /** +# * struct my_struct - short description +# * @a: first member +# * @b: second member +# * +# * Longer description +# */ +# struct my_struct { +# int a; +# int b; +# /* private: */ +# int c; +# }; +# +# All descriptions can be multiline, except the short function description. +# +# For really longs structs, you can also describe arguments inside the +# body of the struct. +# eg. +# /** +# * struct my_struct - short description +# * @a: first member +# * @b: second member +# * +# * Longer description +# */ +# struct my_struct { +# int a; +# int b; +# /** +# * @c: This is longer description of C +# * +# * You can use paragraphs to describe arguments +# * using this method. +# */ +# int c; +# }; +# +# This should be use only for struct/enum members. +# +# You can also add additional sections. When documenting kernel functions you +# should document the "Context:" of the function, e.g. whether the functions +# can be called form interrupts. Unlike other sections you can end it with an +# empty line. +# A non-void function should have a "Return:" section describing the return +# value(s). +# Example-sections should contain the string EXAMPLE so that they are marked +# appropriately in DocBook. +# +# Example: +# /** +# * user_function - function that can only be called in user context +# * @a: some argument +# * Context: !in_interrupt() +# * +# * Some description +# * Example: +# * user_function(22); +# */ +# ... +# +# +# All descriptive text is further processed, scanning for the following special +# patterns, which are highlighted appropriately. +# +# 'funcname()' - function +# '$ENVVAR' - environmental variable +# '&struct_name' - name of a structure (up to two words including 'struct') +# '&struct_name.member' - name of a structure member +# '@parameter' - name of a parameter +# '%CONST' - name of a constant. +# '``LITERAL``' - literal string without any spaces on it. + +## init lots of data + +my $errors = 0; +my $warnings = 0; +my $anon_struct_union = 0; + +# match expressions used to find embedded type information +my $type_constant = '\b``([^\`]+)``\b'; +my $type_constant2 = '\%([-_\w]+)'; +my $type_func = '(\w+)\(\)'; +my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; +my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params +my $type_env = '(\$\w+)'; +my $type_enum = '#(enum\s*([_\w]+))'; +my $type_struct = '#(struct\s*([_\w]+))'; +my $type_typedef = '#(([A-Z][_\w]*))'; +my $type_union = '#(union\s*([_\w]+))'; +my $type_member = '#([_\w]+)(\.|->)([_\w]+)'; +my $type_fallback = '(?!)'; # this never matches +my $type_member_func = $type_member . '\(\)'; + +# Output conversion substitutions. +# One for each output format + +# these are pretty rough +my @highlights_man = ( + [$type_constant, "\$1"], + [$type_constant2, "\$1"], + [$type_func, "\\\\fB\$1\\\\fP"], + [$type_enum, "\\\\fI\$1\\\\fP"], + [$type_struct, "\\\\fI\$1\\\\fP"], + [$type_typedef, "\\\\fI\$1\\\\fP"], + [$type_union, "\\\\fI\$1\\\\fP"], + [$type_param, "\\\\fI\$1\\\\fP"], + [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], + [$type_fallback, "\\\\fI\$1\\\\fP"] + ); +my $blankline_man = ""; + +# rst-mode +my @highlights_rst = ( + [$type_constant, "``\$1``"], + [$type_constant2, "``\$1``"], + # Note: need to escape () to avoid func matching later + [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], + [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], + [$type_fp_param, "**\$1\\\\(\\\\)**"], + [$type_func, "\$1()"], + [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], + [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], + [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], + [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], + # in rst this can refer to any type + [$type_fallback, "\\:c\\:type\\:`\$1`"], + [$type_param, "**\$1**"] + ); +my $blankline_rst = "\n"; + +# read arguments +if ($#ARGV == -1) { + usage(); +} + +my $kernelversion; +my $dohighlight = ""; + +my $verbose = 0; +my $output_mode = "rst"; +my $output_preformatted = 0; +my $no_doc_sections = 0; +my $enable_lineno = 0; +my @highlights = @highlights_rst; +my $blankline = $blankline_rst; +my $modulename = "Kernel API"; + +use constant { + OUTPUT_ALL => 0, # output all symbols and doc sections + OUTPUT_INCLUDE => 1, # output only specified symbols + OUTPUT_EXCLUDE => 2, # output everything except specified symbols + OUTPUT_EXPORTED => 3, # output exported symbols + OUTPUT_INTERNAL => 4, # output non-exported symbols +}; +my $output_selection = OUTPUT_ALL; +my $show_not_found = 0; # No longer used + +my @export_file_list; + +my @build_time; +if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && + (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { + @build_time = gmtime($seconds); +} else { + @build_time = localtime; +} + +my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', + 'July', 'August', 'September', 'October', + 'November', 'December')[$build_time[4]] . + " " . ($build_time[5]+1900); + +# Essentially these are globals. +# They probably want to be tidied up, made more localised or something. +# CAVEAT EMPTOR! Some of the others I localised may not want to be, which +# could cause "use of undefined value" or other bugs. +my ($function, %function_table, %parametertypes, $declaration_purpose); +my $declaration_start_line; +my ($type, $declaration_name, $return_type); +my ($newsection, $newcontents, $prototype, $brcount, %source_map); + +if (defined($ENV{'KBUILD_VERBOSE'})) { + $verbose = "$ENV{'KBUILD_VERBOSE'}"; +} + +# Generated docbook code is inserted in a template at a point where +# docbook v3.1 requires a non-zero sequence of RefEntry's; see: +# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html +# We keep track of number of generated entries and generate a dummy +# if needs be to ensure the expanded template can be postprocessed +# into html. +my $section_counter = 0; + +my $lineprefix=""; + +# Parser states +use constant { + STATE_NORMAL => 0, # normal code + STATE_NAME => 1, # looking for function name + STATE_BODY_MAYBE => 2, # body - or maybe more description + STATE_BODY => 3, # the body of the comment + STATE_PROTO => 4, # scanning prototype + STATE_DOCBLOCK => 5, # documentation block + STATE_INLINE => 6, # gathering documentation outside main block +}; +my $state; +my $in_doc_sect; +my $leading_space; + +# Inline documentation state +use constant { + STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) + STATE_INLINE_NAME => 1, # looking for member name (@foo:) + STATE_INLINE_TEXT => 2, # looking for member documentation + STATE_INLINE_END => 3, # done + STATE_INLINE_ERROR => 4, # error - Comment without header was found. + # Spit a warning as it's not + # proper kernel-doc and ignore the rest. +}; +my $inline_doc_state; + +#declaration types: can be +# 'function', 'struct', 'union', 'enum', 'typedef' +my $decl_type; + +my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. +my $doc_end = '\*/'; +my $doc_com = '\s*\*\s*'; +my $doc_com_body = '\s*\* ?'; +my $doc_decl = $doc_com . '(\w+)'; +# @params and a strictly limited set of supported section names +my $doc_sect = $doc_com . + '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; +my $doc_content = $doc_com_body . '(.*)'; +my $doc_block = $doc_com . 'DOC:\s*(.*)?'; +my $doc_inline_start = '^\s*/\*\*\s*$'; +my $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; +my $doc_inline_end = '^\s*\*/\s*$'; +my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; +my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; + +my %parameterdescs; +my %parameterdesc_start_lines; +my @parameterlist; +my %sections; +my @sectionlist; +my %section_start_lines; +my $sectcheck; +my $struct_actual; + +my $contents = ""; +my $new_start_line = 0; + +# the canonical section names. see also $doc_sect above. +my $section_default = "Description"; # default section +my $section_intro = "Introduction"; +my $section = $section_default; +my $section_context = "Context"; +my $section_return = "Return"; + +my $undescribed = "-- undescribed --"; + +reset_state(); + +while ($ARGV[0] =~ m/^--?(.*)/) { + my $cmd = $1; + shift @ARGV; + if ($cmd eq "man") { + $output_mode = "man"; + @highlights = @highlights_man; + $blankline = $blankline_man; + } elsif ($cmd eq "rst") { + $output_mode = "rst"; + @highlights = @highlights_rst; + $blankline = $blankline_rst; + } elsif ($cmd eq "none") { + $output_mode = "none"; + } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document + $modulename = shift @ARGV; + } elsif ($cmd eq "function") { # to only output specific functions + $output_selection = OUTPUT_INCLUDE; + $function = shift @ARGV; + $function_table{$function} = 1; + } elsif ($cmd eq "nofunction") { # output all except specific functions + $output_selection = OUTPUT_EXCLUDE; + $function = shift @ARGV; + $function_table{$function} = 1; + } elsif ($cmd eq "export") { # only exported symbols + $output_selection = OUTPUT_EXPORTED; + %function_table = (); + } elsif ($cmd eq "internal") { # only non-exported symbols + $output_selection = OUTPUT_INTERNAL; + %function_table = (); + } elsif ($cmd eq "export-file") { + my $file = shift @ARGV; + push(@export_file_list, $file); + } elsif ($cmd eq "v") { + $verbose = 1; + } elsif (($cmd eq "h") || ($cmd eq "help")) { + usage(); + } elsif ($cmd eq 'no-doc-sections') { + $no_doc_sections = 1; + } elsif ($cmd eq 'enable-lineno') { + $enable_lineno = 1; + } elsif ($cmd eq 'show-not-found') { + $show_not_found = 1; # A no-op but don't fail + } else { + # Unknown argument + usage(); + } +} + +# continue execution near EOF; + +# get kernel version from env +sub get_kernel_version() { + my $version = 'unknown kernel version'; + + if (defined($ENV{'KERNELVERSION'})) { + $version = $ENV{'KERNELVERSION'}; + } + return $version; +} + +# +sub print_lineno { + my $lineno = shift; + if ($enable_lineno && defined($lineno)) { + print "#define LINENO " . $lineno . "\n"; + } +} +## +# dumps section contents to arrays/hashes intended for that purpose. +# +sub dump_section { + my $file = shift; + my $name = shift; + my $contents = join "\n", @_; + + if ($name =~ m/$type_param/) { + $name = $1; + $parameterdescs{$name} = $contents; + $sectcheck = $sectcheck . $name . " "; + $parameterdesc_start_lines{$name} = $new_start_line; + $new_start_line = 0; + } elsif ($name eq "@\.\.\.") { + $name = "..."; + $parameterdescs{$name} = $contents; + $sectcheck = $sectcheck . $name . " "; + $parameterdesc_start_lines{$name} = $new_start_line; + $new_start_line = 0; + } else { + if (defined($sections{$name}) && ($sections{$name} ne "")) { + # Only warn on user specified duplicate section names. + if ($name ne $section_default) { + print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; + ++$warnings; + } + $sections{$name} .= $contents; + } else { + $sections{$name} = $contents; + push @sectionlist, $name; + $section_start_lines{$name} = $new_start_line; + $new_start_line = 0; + } + } +} + +## +# dump DOC: section after checking that it should go out +# +sub dump_doc_section { + my $file = shift; + my $name = shift; + my $contents = join "\n", @_; + + if ($no_doc_sections) { + return; + } + + if (($output_selection == OUTPUT_ALL) || + ($output_selection == OUTPUT_INCLUDE && + defined($function_table{$name})) || + ($output_selection == OUTPUT_EXCLUDE && + !defined($function_table{$name}))) + { + dump_section($file, $name, $contents); + output_blockhead({'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'module' => $modulename, + 'content-only' => ($output_selection != OUTPUT_ALL), }); + } +} + +## +# output function +# +# parameterdescs, a hash. +# function => "function name" +# parameterlist => @list of parameters +# parameterdescs => %parameter descriptions +# sectionlist => @list of sections +# sections => %section descriptions +# + +sub output_highlight { + my $contents = join "\n",@_; + my $line; + +# DEBUG +# if (!defined $contents) { +# use Carp; +# confess "output_highlight got called with no args?\n"; +# } + +# print STDERR "contents b4:$contents\n"; + eval $dohighlight; + die $@ if $@; +# print STDERR "contents af:$contents\n"; + + foreach $line (split "\n", $contents) { + if (! $output_preformatted) { + $line =~ s/^\s*//; + } + if ($line eq ""){ + if (! $output_preformatted) { + print $lineprefix, $blankline; + } + } else { + if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { + print "\\&$line"; + } else { + print $lineprefix, $line; + } + } + print "\n"; + } +} + +## +# output function in man +sub output_function_man(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + + print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; + + print ".SH NAME\n"; + print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; + + print ".SH SYNOPSIS\n"; + if ($args{'functiontype'} ne "") { + print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; + } else { + print ".B \"" . $args{'function'} . "\n"; + } + $count = 0; + my $parenth = "("; + my $post = ","; + foreach my $parameter (@{$args{'parameterlist'}}) { + if ($count == $#{$args{'parameterlist'}}) { + $post = ");"; + } + $type = $args{'parametertypes'}{$parameter}; + if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { + # pointer-to-function + print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; + } else { + $type =~ s/([^\*])$/$1 /; + print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; + } + $count++; + $parenth = ""; + } + + print ".SH ARGUMENTS\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + + print ".IP \"" . $parameter . "\" 12\n"; + output_highlight($args{'parameterdescs'}{$parameter_name}); + } + foreach $section (@{$args{'sectionlist'}}) { + print ".SH \"", uc $section, "\"\n"; + output_highlight($args{'sections'}{$section}); + } +} + +## +# output enum in man +sub output_enum_man(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + + print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; + + print ".SH NAME\n"; + print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; + + print ".SH SYNOPSIS\n"; + print "enum " . $args{'enum'} . " {\n"; + $count = 0; + foreach my $parameter (@{$args{'parameterlist'}}) { + print ".br\n.BI \" $parameter\"\n"; + if ($count == $#{$args{'parameterlist'}}) { + print "\n};\n"; + last; + } + else { + print ", \n.br\n"; + } + $count++; + } + + print ".SH Constants\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + + print ".IP \"" . $parameter . "\" 12\n"; + output_highlight($args{'parameterdescs'}{$parameter_name}); + } + foreach $section (@{$args{'sectionlist'}}) { + print ".SH \"$section\"\n"; + output_highlight($args{'sections'}{$section}); + } +} + +## +# output struct in man +sub output_struct_man(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + + print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; + + print ".SH NAME\n"; + print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; + + my $declaration = $args{'definition'}; + $declaration =~ s/\t/ /g; + $declaration =~ s/\n/"\n.br\n.BI \"/g; + print ".SH SYNOPSIS\n"; + print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; + print ".BI \"$declaration\n};\n.br\n\n"; + + print ".SH Members\n"; + foreach $parameter (@{$args{'parameterlist'}}) { + ($parameter =~ /^#/) && next; + + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + + ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; + print ".IP \"" . $parameter . "\" 12\n"; + output_highlight($args{'parameterdescs'}{$parameter_name}); + } + foreach $section (@{$args{'sectionlist'}}) { + print ".SH \"$section\"\n"; + output_highlight($args{'sections'}{$section}); + } +} + +## +# output typedef in man +sub output_typedef_man(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + + print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; + + print ".SH NAME\n"; + print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; + + foreach $section (@{$args{'sectionlist'}}) { + print ".SH \"$section\"\n"; + output_highlight($args{'sections'}{$section}); + } +} + +sub output_blockhead_man(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + my $count; + + print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; + + foreach $section (@{$args{'sectionlist'}}) { + print ".SH \"$section\"\n"; + output_highlight($args{'sections'}{$section}); + } +} + +## +# output in restructured text +# + +# +# This could use some work; it's used to output the DOC: sections, and +# starts by putting out the name of the doc section itself, but that tends +# to duplicate a header already in the template file. +# +sub output_blockhead_rst(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + + foreach $section (@{$args{'sectionlist'}}) { + if ($output_selection != OUTPUT_INCLUDE) { + print "**$section**\n\n"; + } + print_lineno($section_start_lines{$section}); + output_highlight_rst($args{'sections'}{$section}); + print "\n"; + } +} + +# +# Apply the RST highlights to a sub-block of text. +# +sub highlight_block($) { + # The dohighlight kludge requires the text be called $contents + my $contents = shift; + eval $dohighlight; + die $@ if $@; + return $contents; +} + +# +# Regexes used only here. +# +my $sphinx_literal = '^[^.].*::$'; +my $sphinx_cblock = '^\.\.\ +code-block::'; + +sub output_highlight_rst { + my $input = join "\n",@_; + my $output = ""; + my $line; + my $in_literal = 0; + my $litprefix; + my $block = ""; + + foreach $line (split "\n",$input) { + # + # If we're in a literal block, see if we should drop out + # of it. Otherwise pass the line straight through unmunged. + # + if ($in_literal) { + if (! ($line =~ /^\s*$/)) { + # + # If this is the first non-blank line in a literal + # block we need to figure out what the proper indent is. + # + if ($litprefix eq "") { + $line =~ /^(\s*)/; + $litprefix = '^' . $1; + $output .= $line . "\n"; + } elsif (! ($line =~ /$litprefix/)) { + $in_literal = 0; + } else { + $output .= $line . "\n"; + } + } else { + $output .= $line . "\n"; + } + } + # + # Not in a literal block (or just dropped out) + # + if (! $in_literal) { + $block .= $line . "\n"; + if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { + $in_literal = 1; + $litprefix = ""; + $output .= highlight_block($block); + $block = "" + } + } + } + + if ($block) { + $output .= highlight_block($block); + } + foreach $line (split "\n", $output) { + print $lineprefix . $line . "\n"; + } +} + +sub output_function_rst(%) { + my %args = %{$_[0]}; + my ($parameter, $section); + my $oldprefix = $lineprefix; + my $start = ""; + + if ($args{'typedef'}) { + print ".. c:type:: ". $args{'function'} . "\n\n"; + print_lineno($declaration_start_line); + print " **Typedef**: "; + $lineprefix = ""; + output_highlight_rst($args{'purpose'}); + $start = "\n\n**Syntax**\n\n ``"; + } else { + print ".. c:function:: "; + } + if ($args{'functiontype'} ne "") { + $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; + } else { + $start .= $args{'function'} . " ("; + } + print $start; + + my $count = 0; + foreach my $parameter (@{$args{'parameterlist'}}) { + if ($count ne 0) { + print ", "; + } + $count++; + $type = $args{'parametertypes'}{$parameter}; + + if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { + # pointer-to-function + print $1 . $parameter . ") (" . $2; + } else { + print $type . " " . $parameter; + } + } + if ($args{'typedef'}) { + print ");``\n\n"; + } else { + print ")\n\n"; + print_lineno($declaration_start_line); + $lineprefix = " "; + output_highlight_rst($args{'purpose'}); + print "\n"; + } + + print "**Parameters**\n\n"; + $lineprefix = " "; + foreach $parameter (@{$args{'parameterlist'}}) { + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + $type = $args{'parametertypes'}{$parameter}; + + if ($type ne "") { + print "``$type $parameter``\n"; + } else { + print "``$parameter``\n"; + } + + print_lineno($parameterdesc_start_lines{$parameter_name}); + + if (defined($args{'parameterdescs'}{$parameter_name}) && + $args{'parameterdescs'}{$parameter_name} ne $undescribed) { + output_highlight_rst($args{'parameterdescs'}{$parameter_name}); + } else { + print " *undescribed*\n"; + } + print "\n"; + } + + $lineprefix = $oldprefix; + output_section_rst(@_); +} + +sub output_section_rst(%) { + my %args = %{$_[0]}; + my $section; + my $oldprefix = $lineprefix; + $lineprefix = ""; + + foreach $section (@{$args{'sectionlist'}}) { + print "**$section**\n\n"; + print_lineno($section_start_lines{$section}); + output_highlight_rst($args{'sections'}{$section}); + print "\n"; + } + print "\n"; + $lineprefix = $oldprefix; +} + +sub output_enum_rst(%) { + my %args = %{$_[0]}; + my ($parameter); + my $oldprefix = $lineprefix; + my $count; + my $name = "enum " . $args{'enum'}; + + print "\n\n.. c:type:: " . $name . "\n\n"; + print_lineno($declaration_start_line); + $lineprefix = " "; + output_highlight_rst($args{'purpose'}); + print "\n"; + + print "**Constants**\n\n"; + $lineprefix = " "; + foreach $parameter (@{$args{'parameterlist'}}) { + print "``$parameter``\n"; + if ($args{'parameterdescs'}{$parameter} ne $undescribed) { + output_highlight_rst($args{'parameterdescs'}{$parameter}); + } else { + print " *undescribed*\n"; + } + print "\n"; + } + + $lineprefix = $oldprefix; + output_section_rst(@_); +} + +sub output_typedef_rst(%) { + my %args = %{$_[0]}; + my ($parameter); + my $oldprefix = $lineprefix; + my $name = "typedef " . $args{'typedef'}; + + print "\n\n.. c:type:: " . $name . "\n\n"; + print_lineno($declaration_start_line); + $lineprefix = " "; + output_highlight_rst($args{'purpose'}); + print "\n"; + + $lineprefix = $oldprefix; + output_section_rst(@_); +} + +sub output_struct_rst(%) { + my %args = %{$_[0]}; + my ($parameter); + my $oldprefix = $lineprefix; + my $name = $args{'type'} . " " . $args{'struct'}; + + print "\n\n.. c:type:: " . $name . "\n\n"; + print_lineno($declaration_start_line); + $lineprefix = " "; + output_highlight_rst($args{'purpose'}); + print "\n"; + + print "**Definition**\n\n"; + print "::\n\n"; + my $declaration = $args{'definition'}; + $declaration =~ s/\t/ /g; + print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; + + print "**Members**\n\n"; + $lineprefix = " "; + foreach $parameter (@{$args{'parameterlist'}}) { + ($parameter =~ /^#/) && next; + + my $parameter_name = $parameter; + $parameter_name =~ s/\[.*//; + + ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; + $type = $args{'parametertypes'}{$parameter}; + print_lineno($parameterdesc_start_lines{$parameter_name}); + print "``" . $parameter . "``\n"; + output_highlight_rst($args{'parameterdescs'}{$parameter_name}); + print "\n"; + } + print "\n"; + + $lineprefix = $oldprefix; + output_section_rst(@_); +} + +## none mode output functions + +sub output_function_none(%) { +} + +sub output_enum_none(%) { +} + +sub output_typedef_none(%) { +} + +sub output_struct_none(%) { +} + +sub output_blockhead_none(%) { +} + +## +# generic output function for all types (function, struct/union, typedef, enum); +# calls the generated, variable output_ function name based on +# functype and output_mode +sub output_declaration { + no strict 'refs'; + my $name = shift; + my $functype = shift; + my $func = "output_${functype}_$output_mode"; + if (($output_selection == OUTPUT_ALL) || + (($output_selection == OUTPUT_INCLUDE || + $output_selection == OUTPUT_EXPORTED) && + defined($function_table{$name})) || + (($output_selection == OUTPUT_EXCLUDE || + $output_selection == OUTPUT_INTERNAL) && + !($functype eq "function" && defined($function_table{$name})))) + { + &$func(@_); + $section_counter++; + } +} + +## +# generic output function - calls the right one based on current output mode. +sub output_blockhead { + no strict 'refs'; + my $func = "output_blockhead_" . $output_mode; + &$func(@_); + $section_counter++; +} + +## +# takes a declaration (struct, union, enum, typedef) and +# invokes the right handler. NOT called for functions. +sub dump_declaration($$) { + no strict 'refs'; + my ($prototype, $file) = @_; + if ($decl_type eq 'type name') { + if ($prototype =~ /^(enum|struct|union)\s+/) { + $decl_type = $1; + } else { + return; + } + } + + my $func = "dump_" . $decl_type; + &$func(@_); +} + +sub dump_union($$) { + dump_struct(@_); +} + +sub dump_struct($$) { + my $x = shift; + my $file = shift; + + if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*(__packed|__aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*/) { + my $decl_type = $1; + $declaration_name = $2; + my $members = $3; + + # ignore members marked private: + $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; + $members =~ s/\/\*\s*private:.*//gosi; + # strip comments: + $members =~ s/\/\*.*?\*\///gos; + # strip attributes + $members =~ s/\s*__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)//gi; + $members =~ s/\s*__aligned\s*\([^;]*\)//gos; + $members =~ s/\s*__packed\s*//gos; + $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; + # replace DECLARE_BITMAP + $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; + # replace DECLARE_HASHTABLE + $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; + # replace DECLARE_KFIFO + $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; + # replace DECLARE_KFIFO_PTR + $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; + + my $declaration = $members; + + # Split nested struct/union elements as newer ones + while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) { + my $newmember; + my $maintype = $1; + my $ids = $4; + my $content = $3; + foreach my $id(split /,/, $ids) { + $newmember .= "$maintype $id; "; + + $id =~ s/[:\[].*//; + $id =~ s/^\s*\**(\S+)\s*/$1/; + foreach my $arg (split /;/, $content) { + next if ($arg =~ m/^\s*$/); + if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { + # pointer-to-function + my $type = $1; + my $name = $2; + my $extra = $3; + next if (!$name); + if ($id =~ m/^\s*$/) { + # anonymous struct/union + $newmember .= "$type$name$extra; "; + } else { + $newmember .= "$type$id.$name$extra; "; + } + } else { + my $type; + my $names; + $arg =~ s/^\s+//; + $arg =~ s/\s+$//; + # Handle bitmaps + $arg =~ s/:\s*\d+\s*//g; + # Handle arrays + $arg =~ s/\[.*\]//g; + # The type may have multiple words, + # and multiple IDs can be defined, like: + # const struct foo, *bar, foobar + # So, we remove spaces when parsing the + # names, in order to match just names + # and commas for the names + $arg =~ s/\s*,\s*/,/g; + if ($arg =~ m/(.*)\s+([\S+,]+)/) { + $type = $1; + $names = $2; + } else { + $newmember .= "$arg; "; + next; + } + foreach my $name (split /,/, $names) { + $name =~ s/^\s*\**(\S+)\s*/$1/; + next if (($name =~ m/^\s*$/)); + if ($id =~ m/^\s*$/) { + # anonymous struct/union + $newmember .= "$type $name; "; + } else { + $newmember .= "$type $id.$name; "; + } + } + } + } + } + $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/$newmember/; + } + + # Ignore other nested elements, like enums + $members =~ s/(\{[^\{\}]*\})//g; + + create_parameterlist($members, ';', $file, $declaration_name); + check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); + + # Adjust declaration for better display + $declaration =~ s/([\{;])/$1\n/g; + $declaration =~ s/\}\s+;/};/g; + # Better handle inlined enums + do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); + + my @def_args = split /\n/, $declaration; + my $level = 1; + $declaration = ""; + foreach my $clause (@def_args) { + $clause =~ s/^\s+//; + $clause =~ s/\s+$//; + $clause =~ s/\s+/ /; + next if (!$clause); + $level-- if ($clause =~ m/(\})/ && $level > 1); + if (!($clause =~ m/^\s*#/)) { + $declaration .= "\t" x $level; + } + $declaration .= "\t" . $clause . "\n"; + $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); + } + output_declaration($declaration_name, + 'struct', + {'struct' => $declaration_name, + 'module' => $modulename, + 'definition' => $declaration, + 'parameterlist' => \@parameterlist, + 'parameterdescs' => \%parameterdescs, + 'parametertypes' => \%parametertypes, + 'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'purpose' => $declaration_purpose, + 'type' => $decl_type + }); + } + else { + print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; + ++$errors; + } +} + + +sub show_warnings($$) { + my $functype = shift; + my $name = shift; + + return 1 if ($output_selection == OUTPUT_ALL); + + if ($output_selection == OUTPUT_EXPORTED) { + if (defined($function_table{$name})) { + return 1; + } else { + return 0; + } + } + if ($output_selection == OUTPUT_INTERNAL) { + if (!($functype eq "function" && defined($function_table{$name}))) { + return 1; + } else { + return 0; + } + } + if ($output_selection == OUTPUT_INCLUDE) { + if (defined($function_table{$name})) { + return 1; + } else { + return 0; + } + } + if ($output_selection == OUTPUT_EXCLUDE) { + if (!defined($function_table{$name})) { + return 1; + } else { + return 0; + } + } + die("Please add the new output type at show_warnings()"); +} + +sub dump_enum($$) { + my $x = shift; + my $file = shift; + + $x =~ s@/\*.*?\*/@@gos; # strip comments. + # strip #define macros inside enums + $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; + + if ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { + $declaration_name = $1; + my $members = $2; + my %_members; + + $members =~ s/\s+$//; + + foreach my $arg (split ',', $members) { + $arg =~ s/^\s*(\w+).*/$1/; + push @parameterlist, $arg; + if (!$parameterdescs{$arg}) { + $parameterdescs{$arg} = $undescribed; + if (show_warnings("enum", $declaration_name)) { + print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n"; + } + } + $_members{$arg} = 1; + } + + while (my ($k, $v) = each %parameterdescs) { + if (!exists($_members{$k})) { + if (show_warnings("enum", $declaration_name)) { + print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n"; + } + } + } + + output_declaration($declaration_name, + 'enum', + {'enum' => $declaration_name, + 'module' => $modulename, + 'parameterlist' => \@parameterlist, + 'parameterdescs' => \%parameterdescs, + 'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'purpose' => $declaration_purpose + }); + } + else { + print STDERR "${file}:$.: error: Cannot parse enum!\n"; + ++$errors; + } +} + +sub dump_typedef($$) { + my $x = shift; + my $file = shift; + + $x =~ s@/\*.*?\*/@@gos; # strip comments. + + # Parse function prototypes + if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || + $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { + + # Function typedefs + $return_type = $1; + $declaration_name = $2; + my $args = $3; + + create_parameterlist($args, ',', $file, $declaration_name); + + output_declaration($declaration_name, + 'function', + {'function' => $declaration_name, + 'typedef' => 1, + 'module' => $modulename, + 'functiontype' => $return_type, + 'parameterlist' => \@parameterlist, + 'parameterdescs' => \%parameterdescs, + 'parametertypes' => \%parametertypes, + 'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'purpose' => $declaration_purpose + }); + return; + } + + while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { + $x =~ s/\(*.\)\s*;$/;/; + $x =~ s/\[*.\]\s*;$/;/; + } + + if ($x =~ /typedef.*\s+(\w+)\s*;/) { + $declaration_name = $1; + + output_declaration($declaration_name, + 'typedef', + {'typedef' => $declaration_name, + 'module' => $modulename, + 'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'purpose' => $declaration_purpose + }); + } + else { + print STDERR "${file}:$.: error: Cannot parse typedef!\n"; + ++$errors; + } +} + +sub save_struct_actual($) { + my $actual = shift; + + # strip all spaces from the actual param so that it looks like one string item + $actual =~ s/\s*//g; + $struct_actual = $struct_actual . $actual . " "; +} + +sub create_parameterlist($$$$) { + my $args = shift; + my $splitter = shift; + my $file = shift; + my $declaration_name = shift; + my $type; + my $param; + + # temporarily replace commas inside function pointer definition + while ($args =~ /(\([^\),]+),/) { + $args =~ s/(\([^\),]+),/$1#/g; + } + + foreach my $arg (split($splitter, $args)) { + # strip comments + $arg =~ s/\/\*.*\*\///; + # strip leading/trailing spaces + $arg =~ s/^\s*//; + $arg =~ s/\s*$//; + $arg =~ s/\s+/ /; + + if ($arg =~ /^#/) { + # Treat preprocessor directive as a typeless variable just to fill + # corresponding data structures "correctly". Catch it later in + # output_* subs. + push_parameter($arg, "", $file); + } elsif ($arg =~ m/\(.+\)\s*\(/) { + # pointer-to-function + $arg =~ tr/#/,/; + $arg =~ m/[^\(]+\(\*?\s*([\w\.]*)\s*\)/; + $param = $1; + $type = $arg; + $type =~ s/([^\(]+\(\*?)\s*$param/$1/; + save_struct_actual($param); + push_parameter($param, $type, $file, $declaration_name); + } elsif ($arg) { + $arg =~ s/\s*:\s*/:/g; + $arg =~ s/\s*\[/\[/g; + + my @args = split('\s*,\s*', $arg); + if ($args[0] =~ m/\*/) { + $args[0] =~ s/(\*+)\s*/ $1/; + } + + my @first_arg; + if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { + shift @args; + push(@first_arg, split('\s+', $1)); + push(@first_arg, $2); + } else { + @first_arg = split('\s+', shift @args); + } + + unshift(@args, pop @first_arg); + $type = join " ", @first_arg; + + foreach $param (@args) { + if ($param =~ m/^(\*+)\s*(.*)/) { + save_struct_actual($2); + push_parameter($2, "$type $1", $file, $declaration_name); + } + elsif ($param =~ m/(.*?):(\d+)/) { + if ($type ne "") { # skip unnamed bit-fields + save_struct_actual($1); + push_parameter($1, "$type:$2", $file, $declaration_name) + } + } + else { + save_struct_actual($param); + push_parameter($param, $type, $file, $declaration_name); + } + } + } + } +} + +sub push_parameter($$$$) { + my $param = shift; + my $type = shift; + my $file = shift; + my $declaration_name = shift; + + if (($anon_struct_union == 1) && ($type eq "") && + ($param eq "}")) { + return; # ignore the ending }; from anon. struct/union + } + + $anon_struct_union = 0; + $param =~ s/[\[\)].*//; + + if ($type eq "" && $param =~ /\.\.\.$/) + { + if (!$param =~ /\w\.\.\.$/) { + # handles unnamed variable parameters + $param = "..."; + } + if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { + $parameterdescs{$param} = "variable arguments"; + } + } + elsif ($type eq "" && ($param eq "" or $param eq "void")) + { + $param="void"; + $parameterdescs{void} = "no arguments"; + } + elsif ($type eq "" && ($param eq "struct" or $param eq "union")) + # handle unnamed (anonymous) union or struct: + { + $type = $param; + $param = "{unnamed_" . $param . "}"; + $parameterdescs{$param} = "anonymous\n"; + $anon_struct_union = 1; + } + + # warn if parameter has no description + # (but ignore ones starting with # as these are not parameters + # but inline preprocessor statements); + # Note: It will also ignore void params and unnamed structs/unions + if (!defined $parameterdescs{$param} && $param !~ /^#/) { + $parameterdescs{$param} = $undescribed; + + if (show_warnings($type, $declaration_name) && $param !~ /\./) { + print STDERR + "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n"; + ++$warnings; + } + } + + # strip spaces from $param so that it is one continuous string + # on @parameterlist; + # this fixes a problem where check_sections() cannot find + # a parameter like "addr[6 + 2]" because it actually appears + # as "addr[6", "+", "2]" on the parameter list; + # but it's better to maintain the param string unchanged for output, + # so just weaken the string compare in check_sections() to ignore + # "[blah" in a parameter string; + ###$param =~ s/\s*//g; + push @parameterlist, $param; + $type =~ s/\s\s+/ /g; + $parametertypes{$param} = $type; +} + +sub check_sections($$$$$) { + my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; + my @sects = split ' ', $sectcheck; + my @prms = split ' ', $prmscheck; + my $err; + my ($px, $sx); + my $prm_clean; # strip trailing "[array size]" and/or beginning "*" + + foreach $sx (0 .. $#sects) { + $err = 1; + foreach $px (0 .. $#prms) { + $prm_clean = $prms[$px]; + $prm_clean =~ s/\[.*\]//; + $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; + # ignore array size in a parameter string; + # however, the original param string may contain + # spaces, e.g.: addr[6 + 2] + # and this appears in @prms as "addr[6" since the + # parameter list is split at spaces; + # hence just ignore "[..." for the sections check; + $prm_clean =~ s/\[.*//; + + ##$prm_clean =~ s/^\**//; + if ($prm_clean eq $sects[$sx]) { + $err = 0; + last; + } + } + if ($err) { + if ($decl_type eq "function") { + print STDERR "${file}:$.: warning: " . + "Excess function parameter " . + "'$sects[$sx]' " . + "description in '$decl_name'\n"; + ++$warnings; + } + } + } +} + +## +# Checks the section describing the return value of a function. +sub check_return_section { + my $file = shift; + my $declaration_name = shift; + my $return_type = shift; + + # Ignore an empty return type (It's a macro) + # Ignore functions with a "void" return type. (But don't ignore "void *") + if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { + return; + } + + if (!defined($sections{$section_return}) || + $sections{$section_return} eq "") { + print STDERR "${file}:$.: warning: " . + "No description found for return value of " . + "'$declaration_name'\n"; + ++$warnings; + } +} + +## +# takes a function prototype and the name of the current file being +# processed and spits out all the details stored in the global +# arrays/hashes. +sub dump_function($$) { + my $prototype = shift; + my $file = shift; + my $noret = 0; + + $prototype =~ s/^static +//; + $prototype =~ s/^extern +//; + $prototype =~ s/^asmlinkage +//; + $prototype =~ s/^inline +//; + $prototype =~ s/^__inline__ +//; + $prototype =~ s/^__inline +//; + $prototype =~ s/^__always_inline +//; + $prototype =~ s/^noinline +//; + $prototype =~ s/__init +//; + $prototype =~ s/__init_or_module +//; + $prototype =~ s/__meminit +//; + $prototype =~ s/__must_check +//; + $prototype =~ s/__weak +//; + $prototype =~ s/__sched +//; + $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//; + my $define = $prototype =~ s/^#\s*define\s+//; #ak added + $prototype =~ s/__attribute__\s*\(\( + (?: + [\w\s]++ # attribute name + (?:\([^)]*+\))? # attribute arguments + \s*+,? # optional comma at the end + )+ + \)\)\s+//x; + + # Yes, this truly is vile. We are looking for: + # 1. Return type (may be nothing if we're looking at a macro) + # 2. Function name + # 3. Function parameters. + # + # All the while we have to watch out for function pointer parameters + # (which IIRC is what the two sections are for), C types (these + # regexps don't even start to express all the possibilities), and + # so on. + # + # If you mess with these regexps, it's a good idea to check that + # the following functions' documentation still comes out right: + # - parport_register_device (function pointer parameters) + # - atomic_set (macro) + # - pci_match_device, __copy_to_user (long return type) + + if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { + # This is an object-like macro, it has no return type and no parameter + # list. + # Function-like macros are not allowed to have spaces between + # declaration_name and opening parenthesis (notice the \s+). + $return_type = $1; + $declaration_name = $2; + $noret = 1; + } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { + $return_type = $1; + $declaration_name = $2; + my $args = $3; + + create_parameterlist($args, ',', $file, $declaration_name); + } else { + print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; + return; + } + + my $prms = join " ", @parameterlist; + check_sections($file, $declaration_name, "function", $sectcheck, $prms); + + # This check emits a lot of warnings at the moment, because many + # functions don't have a 'Return' doc section. So until the number + # of warnings goes sufficiently down, the check is only performed in + # verbose mode. + # TODO: always perform the check. + if ($verbose && !$noret) { + check_return_section($file, $declaration_name, $return_type); + } + + output_declaration($declaration_name, + 'function', + {'function' => $declaration_name, + 'module' => $modulename, + 'functiontype' => $return_type, + 'parameterlist' => \@parameterlist, + 'parameterdescs' => \%parameterdescs, + 'parametertypes' => \%parametertypes, + 'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'purpose' => $declaration_purpose + }); +} + +sub reset_state { + $function = ""; + %parameterdescs = (); + %parametertypes = (); + @parameterlist = (); + %sections = (); + @sectionlist = (); + $sectcheck = ""; + $struct_actual = ""; + $prototype = ""; + + $state = STATE_NORMAL; + $inline_doc_state = STATE_INLINE_NA; +} + +sub tracepoint_munge($) { + my $file = shift; + my $tracepointname = 0; + my $tracepointargs = 0; + + if ($prototype =~ m/TRACE_EVENT\((.*?),/) { + $tracepointname = $1; + } + if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { + $tracepointname = $1; + } + if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { + $tracepointname = $2; + } + $tracepointname =~ s/^\s+//; #strip leading whitespace + if ($prototype =~ m/TP_PROTO\((.*?)\)/) { + $tracepointargs = $1; + } + if (($tracepointname eq 0) || ($tracepointargs eq 0)) { + print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". + "$prototype\n"; + } else { + $prototype = "static inline void trace_$tracepointname($tracepointargs)"; + } +} + +sub syscall_munge() { + my $void = 0; + + $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's +## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { + if ($prototype =~ m/SYSCALL_DEFINE0/) { + $void = 1; +## $prototype = "long sys_$1(void)"; + } + + $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name + if ($prototype =~ m/long (sys_.*?),/) { + $prototype =~ s/,/\(/; + } elsif ($void) { + $prototype =~ s/\)/\(void\)/; + } + + # now delete all of the odd-number commas in $prototype + # so that arg types & arg names don't have a comma between them + my $count = 0; + my $len = length($prototype); + if ($void) { + $len = 0; # skip the for-loop + } + for (my $ix = 0; $ix < $len; $ix++) { + if (substr($prototype, $ix, 1) eq ',') { + $count++; + if ($count % 2 == 1) { + substr($prototype, $ix, 1) = ' '; + } + } + } +} + +sub process_proto_function($$) { + my $x = shift; + my $file = shift; + + $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line + + if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { + # do nothing + } + elsif ($x =~ /([^\{]*)/) { + $prototype .= $1; + } + + if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { + $prototype =~ s@/\*.*?\*/@@gos; # strip comments. + $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. + $prototype =~ s@^\s+@@gos; # strip leading spaces + if ($prototype =~ /SYSCALL_DEFINE/) { + syscall_munge(); + } + if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || + $prototype =~ /DEFINE_SINGLE_EVENT/) + { + tracepoint_munge($file); + } + dump_function($prototype, $file); + reset_state(); + } +} + +sub process_proto_type($$) { + my $x = shift; + my $file = shift; + + $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. + $x =~ s@^\s+@@gos; # strip leading spaces + $x =~ s@\s+$@@gos; # strip trailing spaces + $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line + + if ($x =~ /^#/) { + # To distinguish preprocessor directive from regular declaration later. + $x .= ";"; + } + + while (1) { + if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { + if( length $prototype ) { + $prototype .= " " + } + $prototype .= $1 . $2; + ($2 eq '{') && $brcount++; + ($2 eq '}') && $brcount--; + if (($2 eq ';') && ($brcount == 0)) { + dump_declaration($prototype, $file); + reset_state(); + last; + } + $x = $3; + } else { + $prototype .= $x; + last; + } + } +} + + +sub map_filename($) { + my $file; + my ($orig_file) = @_; + + if (defined($ENV{'SRCTREE'})) { + $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; + } else { + $file = $orig_file; + } + + if (defined($source_map{$file})) { + $file = $source_map{$file}; + } + + return $file; +} + +sub process_export_file($) { + my ($orig_file) = @_; + my $file = map_filename($orig_file); + + if (!open(IN,"<$file")) { + print STDERR "Error: Cannot open file $file\n"; + ++$errors; + return; + } + + while () { + if (/$export_symbol/) { + $function_table{$2} = 1; + } + } + + close(IN); +} + +# +# Parsers for the various processing states. +# +# STATE_NORMAL: looking for the /** to begin everything. +# +sub process_normal() { + if (/$doc_start/o) { + $state = STATE_NAME; # next line is always the function name + $in_doc_sect = 0; + $declaration_start_line = $. + 1; + } +} + +# +# STATE_NAME: Looking for the "name - description" line +# +sub process_name($$) { + my $file = shift; + my $identifier; + my $descr; + + if (/$doc_block/o) { + $state = STATE_DOCBLOCK; + $contents = ""; + $new_start_line = $. + 1; + + if ( $1 eq "" ) { + $section = $section_intro; + } else { + $section = $1; + } + } + elsif (/$doc_decl/o) { + $identifier = $1; + if (/\s*([\w\s]+?)(\s*-|:)/) { + $identifier = $1; + } + + $state = STATE_BODY; + # if there's no @param blocks need to set up default section + # here + $contents = ""; + $section = $section_default; + $new_start_line = $. + 1; + if (/[-:](.*)/) { + # strip leading/trailing/multiple spaces + $descr= $1; + $descr =~ s/^\s*//; + $descr =~ s/\s*$//; + $descr =~ s/\s+/ /g; + $declaration_purpose = $descr; + $state = STATE_BODY_MAYBE; + } else { + $declaration_purpose = ""; + } + + if (($declaration_purpose eq "") && $verbose) { + print STDERR "${file}:$.: warning: missing initial short description on line:\n"; + print STDERR $_; + ++$warnings; + } + + if ($identifier =~ m/^[A-Z]/) { + $decl_type = 'type name'; + } elsif ($identifier =~ m/^struct\b/) { + $decl_type = 'struct'; + } elsif ($identifier =~ m/^union\b/) { + $decl_type = 'union'; + } elsif ($identifier =~ m/^enum\b/) { + $decl_type = 'enum'; + } elsif ($identifier =~ m/^typedef\b/) { + $decl_type = 'typedef'; + } else { + $decl_type = 'function'; + } + + if ($verbose) { + print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; + } + } else { + print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", + " - I thought it was a doc line\n"; + ++$warnings; + $state = STATE_NORMAL; + } +} + + +# +# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. +# +sub process_body($$) { + my $file = shift; + + if (/$doc_sect/i) { # case insensitive for supported section names + $newsection = $1; + $newcontents = $2; + + # map the supported section names to the canonical names + if ($newsection =~ m/^description$/i) { + $newsection = $section_default; + } elsif ($newsection =~ m/^context$/i) { + $newsection = $section_context; + } elsif ($newsection =~ m/^returns?$/i) { + $newsection = $section_return; + } elsif ($newsection =~ m/^\@return$/) { + # special: @return is a section, not a param description + $newsection = $section_return; + } + + if (($contents ne "") && ($contents ne "\n")) { + if (!$in_doc_sect && $verbose) { + print STDERR "${file}:$.: warning: contents before sections\n"; + ++$warnings; + } + dump_section($file, $section, $contents); + $section = $section_default; + } + + $in_doc_sect = 1; + $state = STATE_BODY; + $contents = $newcontents; + $new_start_line = $.; + while (substr($contents, 0, 1) eq " ") { + $contents = substr($contents, 1); + } + if ($contents ne "") { + $contents .= "\n"; + } + $section = $newsection; + $leading_space = undef; + } elsif (/$doc_end/) { + if (($contents ne "") && ($contents ne "\n")) { + dump_section($file, $section, $contents); + $section = $section_default; + $contents = ""; + } + # look for doc_com + + doc_end: + if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { + print STDERR "${file}:$.: warning: suspicious ending line: $_"; + ++$warnings; + } + + $prototype = ""; + $state = STATE_PROTO; + $brcount = 0; + } elsif (/$doc_content/) { + # miguel-style comment kludge, look for blank lines after + # @parameter line to signify start of description + if ($1 eq "") { + if ($section =~ m/^@/ || $section eq $section_context) { + dump_section($file, $section, $contents); + $section = $section_default; + $contents = ""; + $new_start_line = $.; + } else { + $contents .= "\n"; + } + $state = STATE_BODY; + } elsif ($state == STATE_BODY_MAYBE) { + # Continued declaration purpose + chomp($declaration_purpose); + $declaration_purpose .= " " . $1; + $declaration_purpose =~ s/\s+/ /g; + } else { + my $cont = $1; + if ($section =~ m/^@/ || $section eq $section_context) { + if (!defined $leading_space) { + if ($cont =~ m/^(\s+)/) { + $leading_space = $1; + } else { + $leading_space = ""; + } + } + $cont =~ s/^$leading_space//; + } + $contents .= $cont . "\n"; + } + } else { + # i dont know - bad line? ignore. + print STDERR "${file}:$.: warning: bad line: $_"; + ++$warnings; + } +} + + +# +# STATE_PROTO: reading a function/whatever prototype. +# +sub process_proto($$) { + my $file = shift; + + if (/$doc_inline_oneline/) { + $section = $1; + $contents = $2; + if ($contents ne "") { + $contents .= "\n"; + dump_section($file, $section, $contents); + $section = $section_default; + $contents = ""; + } + } elsif (/$doc_inline_start/) { + $state = STATE_INLINE; + $inline_doc_state = STATE_INLINE_NAME; + } elsif ($decl_type eq 'function') { + process_proto_function($_, $file); + } else { + process_proto_type($_, $file); + } +} + +# +# STATE_DOCBLOCK: within a DOC: block. +# +sub process_docblock($$) { + my $file = shift; + + if (/$doc_end/) { + dump_doc_section($file, $section, $contents); + $section = $section_default; + $contents = ""; + $function = ""; + %parameterdescs = (); + %parametertypes = (); + @parameterlist = (); + %sections = (); + @sectionlist = (); + $prototype = ""; + $state = STATE_NORMAL; + } elsif (/$doc_content/) { + if ( $1 eq "" ) { + $contents .= $blankline; + } else { + $contents .= $1 . "\n"; + } + } +} + +# +# STATE_INLINE: docbook comments within a prototype. +# +sub process_inline($$) { + my $file = shift; + + # First line (state 1) needs to be a @parameter + if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { + $section = $1; + $contents = $2; + $new_start_line = $.; + if ($contents ne "") { + while (substr($contents, 0, 1) eq " ") { + $contents = substr($contents, 1); + } + $contents .= "\n"; + } + $inline_doc_state = STATE_INLINE_TEXT; + # Documentation block end */ + } elsif (/$doc_inline_end/) { + if (($contents ne "") && ($contents ne "\n")) { + dump_section($file, $section, $contents); + $section = $section_default; + $contents = ""; + } + $state = STATE_PROTO; + $inline_doc_state = STATE_INLINE_NA; + # Regular text + } elsif (/$doc_content/) { + if ($inline_doc_state == STATE_INLINE_TEXT) { + $contents .= $1 . "\n"; + # nuke leading blank lines + if ($contents =~ /^\s*$/) { + $contents = ""; + } + } elsif ($inline_doc_state == STATE_INLINE_NAME) { + $inline_doc_state = STATE_INLINE_ERROR; + print STDERR "${file}:$.: warning: "; + print STDERR "Incorrect use of kernel-doc format: $_"; + ++$warnings; + } + } +} + + +sub process_file($) { + my $file; + my $initial_section_counter = $section_counter; + my ($orig_file) = @_; + + $file = map_filename($orig_file); + + if (!open(IN,"<$file")) { + print STDERR "Error: Cannot open file $file\n"; + ++$errors; + return; + } + + $. = 1; + + $section_counter = 0; + while () { + while (s/\\\s*$//) { + $_ .= ; + } + # Replace tabs by spaces + while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; + # Hand this line to the appropriate state handler + if ($state == STATE_NORMAL) { + process_normal(); + } elsif ($state == STATE_NAME) { + process_name($file, $_); + } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) { + process_body($file, $_); + } elsif ($state == STATE_INLINE) { # scanning for inline parameters + process_inline($file, $_); + } elsif ($state == STATE_PROTO) { + process_proto($file, $_); + } elsif ($state == STATE_DOCBLOCK) { + process_docblock($file, $_); + } + } + + # Make sure we got something interesting. + if ($initial_section_counter == $section_counter && $ + output_mode ne "none") { + if ($output_selection == OUTPUT_INCLUDE) { + print STDERR "${file}:1: warning: '$_' not found\n" + for keys %function_table; + } + else { + print STDERR "${file}:1: warning: no structured comments found\n"; + } + } +} + + +$kernelversion = get_kernel_version(); + +# generate a sequence of code that will splice in highlighting information +# using the s// operator. +for (my $k = 0; $k < @highlights; $k++) { + my $pattern = $highlights[$k][0]; + my $result = $highlights[$k][1]; +# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; + $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; +} + +# Read the file that maps relative names to absolute names for +# separate source and object directories and for shadow trees. +if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { + my ($relname, $absname); + while() { + chop(); + ($relname, $absname) = (split())[0..1]; + $relname =~ s:^/+::; + $source_map{$relname} = $absname; + } + close(SOURCE_MAP); +} + +if ($output_selection == OUTPUT_EXPORTED || + $output_selection == OUTPUT_INTERNAL) { + + push(@export_file_list, @ARGV); + + foreach (@export_file_list) { + chomp; + process_export_file($_); + } +} + +foreach (@ARGV) { + chomp; + process_file($_); +} +if ($verbose && $errors) { + print STDERR "$errors errors\n"; +} +if ($verbose && $warnings) { + print STDERR "$warnings warnings\n"; +} + +exit($output_mode eq "none" ? 0 : $errors); diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index debb18f4aa..0659ceef09 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -24,7 +24,7 @@ #include #include -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG #include #endif #include @@ -70,7 +70,7 @@ static int num_active_sockets = 1; static int noisy; static int verbose; -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG static int uid = -1; static int gid = -1; #endif @@ -97,7 +97,7 @@ static void usage(const char *name) " (default '%s')\n" " -T, --trace [[enable=]][,events=][,file=]\n" " specify tracing options\n" -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG " -u, --user=USER user to drop privileges to\n" " -g, --group=GROUP group to drop privileges to\n" #endif @@ -827,7 +827,7 @@ static void close_server_socket(void) num_active_sockets--; } -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG static int drop_privileges(void) { /* clear all capabilities */ @@ -920,7 +920,7 @@ int main(int argc, char **argv) pidfile = g_strdup(optarg); pidfile_specified = true; break; -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG case 'u': { unsigned long res; struct passwd *userinfo = getpwnam(optarg); @@ -1056,7 +1056,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG if (drop_privileges() < 0) { error_report("Failed to drop privileges: %s", strerror(errno)); exit(EXIT_FAILURE); diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 4a50e95ec3..8b0ff25508 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -33,7 +33,6 @@ stub-obj-y += fd-register.o stub-obj-y += qmp_memory_device.o stub-obj-y += target-monitor-defs.o stub-obj-y += target-get-monitor-def.o -stub-obj-y += pc_madt_cpu_entry.o stub-obj-y += vmgenid.o stub-obj-y += xen-common.o stub-obj-y += xen-hvm.o diff --git a/stubs/pc_madt_cpu_entry.c b/stubs/pc_madt_cpu_entry.c deleted file mode 100644 index f88d6a090b..0000000000 --- a/stubs/pc_madt_cpu_entry.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "qemu/osdep.h" -#include "hw/i386/pc.h" - -void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid, - const CPUArchIdList *apic_ids, GArray *entry) -{ -} diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 5b82cefef6..b87b59a02a 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -741,11 +741,11 @@ void kvm_arch_init_irq_routing(KVMState *s) { } -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s) +int kvm_arch_irqchip_create(KVMState *s) { - if (machine_kernel_irqchip_split(ms)) { - perror("-machine kernel_irqchip=split is not supported on ARM."); - exit(1); + if (kvm_kernel_irqchip_split()) { + perror("-machine kernel_irqchip=split is not supported on ARM."); + exit(1); } /* If we can create the VGIC using the newer device control API, we diff --git a/target/cris/translate.c b/target/cris/translate.c index e752bd0609..cb57516a44 100644 --- a/target/cris/translate.c +++ b/target/cris/translate.c @@ -3273,11 +3273,11 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) #if !DISAS_CRIS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) && qemu_log_in_addr_range(pc_start)) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("--------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); log_target_disas(cs, pc_start, dc->pc - pc_start); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif #endif diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 0a9ac65974..e1eb9f4739 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4695,7 +4695,7 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc, return; } - xc = X86_CPU(object_new(object_class_get_name(OBJECT_CLASS(xcc)))); + xc = X86_CPU(object_new_with_class(OBJECT_CLASS(xcc))); x86_cpu_expand_features(xc, &err); if (err) { @@ -4763,7 +4763,7 @@ static GSList *get_sorted_cpu_model_list(void) static char *x86_cpu_class_get_model_id(X86CPUClass *xc) { - Object *obj = object_new(object_class_get_name(OBJECT_CLASS(xc))); + Object *obj = object_new_with_class(OBJECT_CLASS(xc)); char *r = object_property_get_str(obj, "model-id", &error_abort); object_unref(obj); return r; @@ -5141,7 +5141,7 @@ static X86CPU *x86_cpu_from_model(const char *model, QDict *props, Error **errp) goto out; } - xc = X86_CPU(object_new(object_class_get_name(OBJECT_CLASS(xcc)))); + xc = X86_CPU(object_new_with_class(OBJECT_CLASS(xcc))); if (props) { object_apply_props(OBJECT(xc), props, &err); if (err) { @@ -5983,7 +5983,7 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp) APICCommonState *apic; ObjectClass *apic_class = OBJECT_CLASS(apic_get_class()); - cpu->apic_state = DEVICE(object_new(object_class_get_name(apic_class))); + cpu->apic_state = DEVICE(object_new_with_class(apic_class)); object_property_add_child(OBJECT(cpu), "lapic", OBJECT(cpu->apic_state), &error_abort); diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 1d10046a6c..0b511906e3 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -35,7 +35,7 @@ #include "qemu/main-loop.h" #include "qemu/config-file.h" #include "qemu/error-report.h" -#include "hw/i386/pc.h" +#include "hw/i386/x86.h" #include "hw/i386/apic.h" #include "hw/i386/apic_internal.h" #include "hw/i386/apic-msidef.h" @@ -2163,7 +2163,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } qemu_register_reset(kvm_unpoison_all, NULL); - shadow_mem = machine_kvm_shadow_mem(ms); + shadow_mem = object_property_get_int(OBJECT(s), "kvm-shadow-mem", &error_abort); if (shadow_mem != -1) { shadow_mem /= 4096; ret = kvm_vm_ioctl(s, KVM_SET_NR_MMU_PAGES, shadow_mem); @@ -2173,8 +2173,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } if (kvm_check_extension(s, KVM_CAP_X86_SMM) && - object_dynamic_cast(OBJECT(ms), TYPE_PC_MACHINE) && - pc_machine_is_smm_enabled(PC_MACHINE(ms))) { + x86_machine_is_smm_enabled(X86_MACHINE(ms))) { smram_machine_done.notify = register_smram_listener; qemu_add_machine_init_done_notifier(&smram_machine_done); } @@ -4494,10 +4493,10 @@ void kvm_arch_init_irq_routing(KVMState *s) } } -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s) +int kvm_arch_irqchip_create(KVMState *s) { int ret; - if (machine_kernel_irqchip_split(ms)) { + if (kvm_kernel_irqchip_split()) { ret = kvm_vm_enable_cap(s, KVM_CAP_SPLIT_IRQCHIP, 0, 24); if (ret) { error_report("Could not enable split irqchip mode: %s", @@ -4513,146 +4512,6 @@ int kvm_arch_irqchip_create(MachineState *ms, KVMState *s) } } -/* Classic KVM device assignment interface. Will remain x86 only. */ -int kvm_device_pci_assign(KVMState *s, PCIHostDeviceAddress *dev_addr, - uint32_t flags, uint32_t *dev_id) -{ - struct kvm_assigned_pci_dev dev_data = { - .segnr = dev_addr->domain, - .busnr = dev_addr->bus, - .devfn = PCI_DEVFN(dev_addr->slot, dev_addr->function), - .flags = flags, - }; - int ret; - - dev_data.assigned_dev_id = - (dev_addr->domain << 16) | (dev_addr->bus << 8) | dev_data.devfn; - - ret = kvm_vm_ioctl(s, KVM_ASSIGN_PCI_DEVICE, &dev_data); - if (ret < 0) { - return ret; - } - - *dev_id = dev_data.assigned_dev_id; - - return 0; -} - -int kvm_device_pci_deassign(KVMState *s, uint32_t dev_id) -{ - struct kvm_assigned_pci_dev dev_data = { - .assigned_dev_id = dev_id, - }; - - return kvm_vm_ioctl(s, KVM_DEASSIGN_PCI_DEVICE, &dev_data); -} - -static int kvm_assign_irq_internal(KVMState *s, uint32_t dev_id, - uint32_t irq_type, uint32_t guest_irq) -{ - struct kvm_assigned_irq assigned_irq = { - .assigned_dev_id = dev_id, - .guest_irq = guest_irq, - .flags = irq_type, - }; - - if (kvm_check_extension(s, KVM_CAP_ASSIGN_DEV_IRQ)) { - return kvm_vm_ioctl(s, KVM_ASSIGN_DEV_IRQ, &assigned_irq); - } else { - return kvm_vm_ioctl(s, KVM_ASSIGN_IRQ, &assigned_irq); - } -} - -int kvm_device_intx_assign(KVMState *s, uint32_t dev_id, bool use_host_msi, - uint32_t guest_irq) -{ - uint32_t irq_type = KVM_DEV_IRQ_GUEST_INTX | - (use_host_msi ? KVM_DEV_IRQ_HOST_MSI : KVM_DEV_IRQ_HOST_INTX); - - return kvm_assign_irq_internal(s, dev_id, irq_type, guest_irq); -} - -int kvm_device_intx_set_mask(KVMState *s, uint32_t dev_id, bool masked) -{ - struct kvm_assigned_pci_dev dev_data = { - .assigned_dev_id = dev_id, - .flags = masked ? KVM_DEV_ASSIGN_MASK_INTX : 0, - }; - - return kvm_vm_ioctl(s, KVM_ASSIGN_SET_INTX_MASK, &dev_data); -} - -static int kvm_deassign_irq_internal(KVMState *s, uint32_t dev_id, - uint32_t type) -{ - struct kvm_assigned_irq assigned_irq = { - .assigned_dev_id = dev_id, - .flags = type, - }; - - return kvm_vm_ioctl(s, KVM_DEASSIGN_DEV_IRQ, &assigned_irq); -} - -int kvm_device_intx_deassign(KVMState *s, uint32_t dev_id, bool use_host_msi) -{ - return kvm_deassign_irq_internal(s, dev_id, KVM_DEV_IRQ_GUEST_INTX | - (use_host_msi ? KVM_DEV_IRQ_HOST_MSI : KVM_DEV_IRQ_HOST_INTX)); -} - -int kvm_device_msi_assign(KVMState *s, uint32_t dev_id, int virq) -{ - return kvm_assign_irq_internal(s, dev_id, KVM_DEV_IRQ_HOST_MSI | - KVM_DEV_IRQ_GUEST_MSI, virq); -} - -int kvm_device_msi_deassign(KVMState *s, uint32_t dev_id) -{ - return kvm_deassign_irq_internal(s, dev_id, KVM_DEV_IRQ_GUEST_MSI | - KVM_DEV_IRQ_HOST_MSI); -} - -bool kvm_device_msix_supported(KVMState *s) -{ - /* The kernel lacks a corresponding KVM_CAP, so we probe by calling - * KVM_ASSIGN_SET_MSIX_NR with an invalid parameter. */ - return kvm_vm_ioctl(s, KVM_ASSIGN_SET_MSIX_NR, NULL) == -EFAULT; -} - -int kvm_device_msix_init_vectors(KVMState *s, uint32_t dev_id, - uint32_t nr_vectors) -{ - struct kvm_assigned_msix_nr msix_nr = { - .assigned_dev_id = dev_id, - .entry_nr = nr_vectors, - }; - - return kvm_vm_ioctl(s, KVM_ASSIGN_SET_MSIX_NR, &msix_nr); -} - -int kvm_device_msix_set_vector(KVMState *s, uint32_t dev_id, uint32_t vector, - int virq) -{ - struct kvm_assigned_msix_entry msix_entry = { - .assigned_dev_id = dev_id, - .gsi = virq, - .entry = vector, - }; - - return kvm_vm_ioctl(s, KVM_ASSIGN_SET_MSIX_ENTRY, &msix_entry); -} - -int kvm_device_msix_assign(KVMState *s, uint32_t dev_id) -{ - return kvm_assign_irq_internal(s, dev_id, KVM_DEV_IRQ_HOST_MSIX | - KVM_DEV_IRQ_GUEST_MSIX, 0); -} - -int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id) -{ - return kvm_deassign_irq_internal(s, dev_id, KVM_DEV_IRQ_GUEST_MSIX | - KVM_DEV_IRQ_HOST_MSIX); -} - int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, uint64_t address, uint32_t data, PCIDevice *dev) { diff --git a/target/i386/kvm_i386.h b/target/i386/kvm_i386.h index 06fe06bdb3..7d0242f5fb 100644 --- a/target/i386/kvm_i386.h +++ b/target/i386/kvm_i386.h @@ -40,26 +40,6 @@ void kvm_synchronize_all_tsc(void); void kvm_arch_reset_vcpu(X86CPU *cs); void kvm_arch_do_init_vcpu(X86CPU *cs); -int kvm_device_pci_assign(KVMState *s, PCIHostDeviceAddress *dev_addr, - uint32_t flags, uint32_t *dev_id); -int kvm_device_pci_deassign(KVMState *s, uint32_t dev_id); - -int kvm_device_intx_assign(KVMState *s, uint32_t dev_id, - bool use_host_msi, uint32_t guest_irq); -int kvm_device_intx_set_mask(KVMState *s, uint32_t dev_id, bool masked); -int kvm_device_intx_deassign(KVMState *s, uint32_t dev_id, bool use_host_msi); - -int kvm_device_msi_assign(KVMState *s, uint32_t dev_id, int virq); -int kvm_device_msi_deassign(KVMState *s, uint32_t dev_id); - -bool kvm_device_msix_supported(KVMState *s); -int kvm_device_msix_init_vectors(KVMState *s, uint32_t dev_id, - uint32_t nr_vectors); -int kvm_device_msix_set_vector(KVMState *s, uint32_t dev_id, uint32_t vector, - int virq); -int kvm_device_msix_assign(KVMState *s, uint32_t dev_id); -int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id); - void kvm_put_apicbase(X86CPU *cpu, uint64_t value); bool kvm_enable_x2apic(void); diff --git a/target/i386/machine.c b/target/i386/machine.c index 2699eed94e..0c96531a56 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -1,10 +1,10 @@ #include "qemu/osdep.h" #include "cpu.h" #include "exec/exec-all.h" -#include "hw/i386/pc.h" #include "hw/isa/isa.h" #include "migration/cpu.h" #include "hyperv.h" +#include "hw/i386/x86.h" #include "kvm_i386.h" #include "sysemu/kvm.h" @@ -261,7 +261,7 @@ static int cpu_pre_save(void *opaque) * intercepted anymore. * * Furthermore, when a L2 exception is intercepted by L1 - * hypervisor, it's exception payload (CR2/DR6 on #PF/#DB) + * hypervisor, its exception payload (CR2/DR6 on #PF/#DB) * should not be set yet in the respective vCPU register. * Thus, in case an exception is pending, it is * important to save the exception payload seperately. @@ -271,9 +271,9 @@ static int cpu_pre_save(void *opaque) * distinguish between a pending and injected exception * and we don't need to store seperately the exception payload. * - * In order to preserve better backwards-compatabile migration, + * In order to preserve better backwards-compatible migration, * convert a pending exception to an injected exception in - * case it is not important to distingiush between them + * case it is not important to distinguish between them * as described above. */ if (env->exception_pending && !(env->hflags & HF_GUEST_MASK)) { @@ -415,7 +415,7 @@ static bool exception_info_needed(void *opaque) /* * It is important to save exception-info only in case - * we need to distingiush between a pending and injected + * we need to distinguish between a pending and injected * exception. Which is only required in case there is a * pending exception and vCPU is running L2. * For more info, refer to comment in cpu_pre_save(). diff --git a/target/i386/monitor.c b/target/i386/monitor.c index 9fb4d641d5..27ebfa3ad2 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -28,7 +28,6 @@ #include "monitor/hmp-target.h" #include "monitor/hmp.h" #include "qapi/qmp/qdict.h" -#include "hw/i386/pc.h" #include "sysemu/kvm.h" #include "sysemu/sev.h" #include "qapi/error.h" diff --git a/target/i386/translate.c b/target/i386/translate.c index 77e932d827..7c99ef1385 100644 --- a/target/i386/translate.c +++ b/target/i386/translate.c @@ -2502,14 +2502,15 @@ static void gen_unknown_opcode(CPUX86State *env, DisasContext *s) gen_illegal_opcode(s); if (qemu_loglevel_mask(LOG_UNIMP)) { + FILE *logfile = qemu_log_lock(); target_ulong pc = s->pc_start, end = s->pc; - qemu_log_lock(); + qemu_log("ILLOPC: " TARGET_FMT_lx ":", pc); for (; pc < end; ++pc) { qemu_log(" %02x", cpu_ldub_code(env, pc)); } qemu_log("\n"); - qemu_log_unlock(); + qemu_log_unlock(logfile); } } diff --git a/target/i386/whp-dispatch.h b/target/i386/whp-dispatch.h index 23791fbb47..87d049ceab 100644 --- a/target/i386/whp-dispatch.h +++ b/target/i386/whp-dispatch.h @@ -50,5 +50,9 @@ extern struct WHPDispatch whp_dispatch; bool init_whp_dispatch(void); +typedef enum WHPFunctionList { + WINHV_PLATFORM_FNS_DEFAULT, + WINHV_EMULATION_FNS_DEFAULT, +} WHPFunctionList; #endif /* WHP_DISPATCH_H */ diff --git a/target/i386/whpx-all.c b/target/i386/whpx-all.c index def0c28480..3ed2aa1892 100644 --- a/target/i386/whpx-all.c +++ b/target/i386/whpx-all.c @@ -1355,6 +1355,58 @@ static void whpx_handle_interrupt(CPUState *cpu, int mask) } } +/* + * Load the functions from the given library, using the given handle. If a + * handle is provided, it is used, otherwise the library is opened. The + * handle will be updated on return with the opened one. + */ +static bool load_whp_dispatch_fns(HMODULE *handle, + WHPFunctionList function_list) +{ + HMODULE hLib = *handle; + + #define WINHV_PLATFORM_DLL "WinHvPlatform.dll" + #define WINHV_EMULATION_DLL "WinHvEmulation.dll" + #define WHP_LOAD_FIELD(return_type, function_name, signature) \ + whp_dispatch.function_name = \ + (function_name ## _t)GetProcAddress(hLib, #function_name); \ + if (!whp_dispatch.function_name) { \ + error_report("Could not load function %s", #function_name); \ + goto error; \ + } \ + + #define WHP_LOAD_LIB(lib_name, handle_lib) \ + if (!handle_lib) { \ + handle_lib = LoadLibrary(lib_name); \ + if (!handle_lib) { \ + error_report("Could not load library %s.", lib_name); \ + goto error; \ + } \ + } \ + + switch (function_list) { + case WINHV_PLATFORM_FNS_DEFAULT: + WHP_LOAD_LIB(WINHV_PLATFORM_DLL, hLib) + LIST_WINHVPLATFORM_FUNCTIONS(WHP_LOAD_FIELD) + break; + + case WINHV_EMULATION_FNS_DEFAULT: + WHP_LOAD_LIB(WINHV_EMULATION_DLL, hLib) + LIST_WINHVEMULATION_FUNCTIONS(WHP_LOAD_FIELD) + break; + } + + *handle = hLib; + return true; + +error: + if (hLib) { + FreeLibrary(hLib); + } + + return false; +} + /* * Partition support */ @@ -1490,51 +1542,30 @@ static void whpx_type_init(void) bool init_whp_dispatch(void) { - const char *lib_name; - HMODULE hLib; - if (whp_dispatch_initialized) { return true; } - #define WHP_LOAD_FIELD(return_type, function_name, signature) \ - whp_dispatch.function_name = \ - (function_name ## _t)GetProcAddress(hLib, #function_name); \ - if (!whp_dispatch.function_name) { \ - error_report("Could not load function %s from library %s.", \ - #function_name, lib_name); \ - goto error; \ - } \ - - lib_name = "WinHvPlatform.dll"; - hWinHvPlatform = LoadLibrary(lib_name); - if (!hWinHvPlatform) { - error_report("Could not load library %s.", lib_name); + if (!load_whp_dispatch_fns(&hWinHvPlatform, WINHV_PLATFORM_FNS_DEFAULT)) { goto error; } - hLib = hWinHvPlatform; - LIST_WINHVPLATFORM_FUNCTIONS(WHP_LOAD_FIELD) - lib_name = "WinHvEmulation.dll"; - hWinHvEmulation = LoadLibrary(lib_name); - if (!hWinHvEmulation) { - error_report("Could not load library %s.", lib_name); + if (!load_whp_dispatch_fns(&hWinHvEmulation, WINHV_EMULATION_FNS_DEFAULT)) { goto error; } - hLib = hWinHvEmulation; - LIST_WINHVEMULATION_FUNCTIONS(WHP_LOAD_FIELD) whp_dispatch_initialized = true; - return true; - - error: + return true; +error: if (hWinHvPlatform) { FreeLibrary(hWinHvPlatform); } + if (hWinHvEmulation) { FreeLibrary(hWinHvEmulation); } + return false; } diff --git a/target/lm32/translate.c b/target/lm32/translate.c index 778cae1e81..73db9654d6 100644 --- a/target/lm32/translate.c +++ b/target/lm32/translate.c @@ -1137,10 +1137,10 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) && qemu_log_in_addr_range(pc_start)) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("\n"); log_target_disas(cs, pc_start, dc->pc - pc_start); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif } diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c index bdc7d5326a..525115b041 100644 --- a/target/microblaze/translate.c +++ b/target/microblaze/translate.c @@ -1765,10 +1765,10 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) #if !SIM_COMPAT if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) && qemu_log_in_addr_range(pc_start)) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("--------------\n"); log_target_disas(cs, pc_start, dc->pc - pc_start); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif #endif diff --git a/target/mips/kvm.c b/target/mips/kvm.c index 578bc14625..de3e26ef1f 100644 --- a/target/mips/kvm.c +++ b/target/mips/kvm.c @@ -57,7 +57,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) return 0; } -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s) +int kvm_arch_irqchip_create(KVMState *s) { return 0; } diff --git a/target/nios2/translate.c b/target/nios2/translate.c index e17656e66f..82107bf270 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -892,11 +892,11 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) && qemu_log_in_addr_range(tb->pc)) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("IN: %s\n", lookup_symbol(tb->pc)); log_target_disas(cs, tb->pc, dc->pc - tb->pc); qemu_log("\n"); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif } diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 7406d18945..d1c334f0e3 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -152,7 +152,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) return 0; } -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s) +int kvm_arch_irqchip_create(KVMState *s) { return 0; } @@ -2076,7 +2076,7 @@ int kvmppc_set_smt_threads(int smt) return ret; } -void kvmppc_error_append_smt_possible_hint(Error **errp_in) +void kvmppc_error_append_smt_possible_hint(Error *const *errp) { int i; GString *g; @@ -2091,10 +2091,10 @@ void kvmppc_error_append_smt_possible_hint(Error **errp_in) } } s = g_string_free(g, false); - error_append_hint(errp_in, "%s.\n", s); + error_append_hint(errp, "%s.\n", s); g_free(s); } else { - error_append_hint(errp_in, + error_append_hint(errp, "This KVM seems to be too old to support VSMT.\n"); } } diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index 47b08a4030..f22daabf51 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -28,7 +28,7 @@ void kvmppc_set_papr(PowerPCCPU *cpu); int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr); void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy); int kvmppc_smt_threads(void); -void kvmppc_error_append_smt_possible_hint(Error **errp_in); +void kvmppc_error_append_smt_possible_hint(Error *const *errp); int kvmppc_set_smt_threads(int smt); int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits); int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits); @@ -164,7 +164,7 @@ static inline int kvmppc_smt_threads(void) return 1; } -static inline void kvmppc_error_append_smt_possible_hint(Error **errp_in) +static inline void kvmppc_error_append_smt_possible_hint(Error *const *errp) { return; } diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 99ea09085a..625daeedd1 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -76,8 +76,16 @@ static bool s390_cpu_has_work(CPUState *cs) static void s390_cpu_load_normal(CPUState *s) { S390CPU *cpu = S390_CPU(s); - cpu->env.psw.addr = ldl_phys(s->as, 4) & PSW_MASK_ESA_ADDR; - cpu->env.psw.mask = PSW_MASK_32 | PSW_MASK_64; + uint64_t spsw = ldq_phys(s->as, 0); + + cpu->env.psw.mask = spsw & 0xffffffff80000000ULL; + /* + * Invert short psw indication, so SIE will report a specification + * exception if it was not set. + */ + cpu->env.psw.mask ^= PSW_MASK_SHORTPSW; + cpu->env.psw.addr = spsw & 0x7fffffffULL; + s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu); } #endif diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index aa829e954c..e195e5c7c8 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -269,6 +269,7 @@ extern const VMStateDescription vmstate_s390_cpu; #define PSW_MASK_EXT 0x0100000000000000ULL #define PSW_MASK_KEY 0x00F0000000000000ULL #define PSW_SHIFT_KEY 52 +#define PSW_MASK_SHORTPSW 0x0008000000000000ULL #define PSW_MASK_MCHECK 0x0004000000000000ULL #define PSW_MASK_WAIT 0x0002000000000000ULL #define PSW_MASK_PSTATE 0x0001000000000000ULL diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 547bab8ac3..7c32180269 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -440,7 +440,7 @@ static void create_cpu_model_list(ObjectClass *klass, void *opaque) if (cpu_list_data->model) { Object *obj; S390CPU *sc; - obj = object_new(object_class_get_name(klass)); + obj = object_new_with_class(klass); sc = S390_CPU(obj); if (sc->model) { info->has_unavailable_features = true; @@ -498,7 +498,7 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info, error_setg(errp, "The CPU definition '%s' requires KVM", info->name); return; } - obj = object_new(object_class_get_name(oc)); + obj = object_new_with_class(oc); cpu = S390_CPU(obj); if (!cpu->model) { diff --git a/target/s390x/helper.h b/target/s390x/helper.h index 56e8149866..b5813c2ac2 100644 --- a/target/s390x/helper.h +++ b/target/s390x/helper.h @@ -324,13 +324,10 @@ DEF_HELPER_FLAGS_4(ipte, TCG_CALL_NO_RWG, void, env, i64, i64, i32) DEF_HELPER_FLAGS_1(ptlb, TCG_CALL_NO_RWG, void, env) DEF_HELPER_FLAGS_1(purge, TCG_CALL_NO_RWG, void, env) DEF_HELPER_2(lra, i64, env, i64) -DEF_HELPER_FLAGS_2(lura, TCG_CALL_NO_WG, i64, env, i64) -DEF_HELPER_FLAGS_2(lurag, TCG_CALL_NO_WG, i64, env, i64) -DEF_HELPER_FLAGS_3(stura, TCG_CALL_NO_WG, void, env, i64, i64) -DEF_HELPER_FLAGS_3(sturg, TCG_CALL_NO_WG, void, env, i64, i64) DEF_HELPER_1(per_check_exception, void, env) DEF_HELPER_FLAGS_3(per_branch, TCG_CALL_NO_RWG, void, env, i64, i64) DEF_HELPER_FLAGS_2(per_ifetch, TCG_CALL_NO_RWG, void, env, i64) +DEF_HELPER_FLAGS_1(per_store_real, TCG_CALL_NO_RWG, void, env) DEF_HELPER_FLAGS_1(stfl, TCG_CALL_NO_RWG, void, env) DEF_HELPER_2(xsch, void, env, i64) diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def index 449eee1662..2bc77f0871 100644 --- a/target/s390x/insn-data.def +++ b/target/s390x/insn-data.def @@ -1275,8 +1275,8 @@ F(0xe313, LRAY, RXY_a, LD, 0, a2, r1, 0, lra, 0, IF_PRIV) F(0xe303, LRAG, RXY_a, Z, 0, a2, r1, 0, lra, 0, IF_PRIV) /* LOAD USING REAL ADDRESS */ - F(0xb24b, LURA, RRE, Z, 0, r2, new, r1_32, lura, 0, IF_PRIV) - F(0xb905, LURAG, RRE, Z, 0, r2, r1, 0, lurag, 0, IF_PRIV) + E(0xb24b, LURA, RRE, Z, 0, 0, new, r1_32, lura, 0, MO_TEUL, IF_PRIV) + E(0xb905, LURAG, RRE, Z, 0, 0, r1, 0, lura, 0, MO_TEQ, IF_PRIV) /* MOVE TO PRIMARY */ F(0xda00, MVCP, SS_d, Z, la1, a2, 0, 0, mvcp, 0, IF_PRIV) /* MOVE TO SECONDARY */ @@ -1329,8 +1329,8 @@ /* STORE THEN OR SYSTEM MASK */ F(0xad00, STOSM, SI, Z, la1, 0, 0, 0, stnosm, 0, IF_PRIV) /* STORE USING REAL ADDRESS */ - F(0xb246, STURA, RRE, Z, r1_o, r2_o, 0, 0, stura, 0, IF_PRIV) - F(0xb925, STURG, RRE, Z, r1_o, r2_o, 0, 0, sturg, 0, IF_PRIV) + E(0xb246, STURA, RRE, Z, r1_o, 0, 0, 0, stura, 0, MO_TEUL, IF_PRIV) + E(0xb925, STURG, RRE, Z, r1_o, 0, 0, 0, stura, 0, MO_TEQ, IF_PRIV) /* TEST BLOCK */ F(0xb22c, TB, RRE, Z, 0, r2_o, 0, 0, testblock, 0, IF_PRIV) /* TEST PROTECTION */ diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index ad6e38c876..15260aeb9a 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -374,7 +374,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) return 0; } -int kvm_arch_irqchip_create(MachineState *ms, KVMState *s) +int kvm_arch_irqchip_create(KVMState *s) { return 0; } diff --git a/target/s390x/mem_helper.c b/target/s390x/mem_helper.c index 2325767f17..2921419c27 100644 --- a/target/s390x/mem_helper.c +++ b/target/s390x/mem_helper.c @@ -2329,44 +2329,6 @@ void HELPER(purge)(CPUS390XState *env) tlb_flush_all_cpus_synced(env_cpu(env)); } -/* load using real address */ -uint64_t HELPER(lura)(CPUS390XState *env, uint64_t addr) -{ - return cpu_ldl_real_ra(env, wrap_address(env, addr), GETPC()); -} - -uint64_t HELPER(lurag)(CPUS390XState *env, uint64_t addr) -{ - return cpu_ldq_real_ra(env, wrap_address(env, addr), GETPC()); -} - -/* store using real address */ -void HELPER(stura)(CPUS390XState *env, uint64_t addr, uint64_t v1) -{ - cpu_stl_real_ra(env, wrap_address(env, addr), (uint32_t)v1, GETPC()); - - if ((env->psw.mask & PSW_MASK_PER) && - (env->cregs[9] & PER_CR9_EVENT_STORE) && - (env->cregs[9] & PER_CR9_EVENT_STORE_REAL)) { - /* PSW is saved just before calling the helper. */ - env->per_address = env->psw.addr; - env->per_perc_atmid = PER_CODE_EVENT_STORE_REAL | get_per_atmid(env); - } -} - -void HELPER(sturg)(CPUS390XState *env, uint64_t addr, uint64_t v1) -{ - cpu_stq_real_ra(env, wrap_address(env, addr), v1, GETPC()); - - if ((env->psw.mask & PSW_MASK_PER) && - (env->cregs[9] & PER_CR9_EVENT_STORE) && - (env->cregs[9] & PER_CR9_EVENT_STORE_REAL)) { - /* PSW is saved just before calling the helper. */ - env->per_address = env->psw.addr; - env->per_perc_atmid = PER_CODE_EVENT_STORE_REAL | get_per_atmid(env); - } -} - /* load real address */ uint64_t HELPER(lra)(CPUS390XState *env, uint64_t addr) { diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c index bfb457fb63..58dbc023eb 100644 --- a/target/s390x/misc_helper.c +++ b/target/s390x/misc_helper.c @@ -620,6 +620,16 @@ void HELPER(per_ifetch)(CPUS390XState *env, uint64_t addr) } } } + +void HELPER(per_store_real)(CPUS390XState *env) +{ + if ((env->cregs[9] & PER_CR9_EVENT_STORE) && + (env->cregs[9] & PER_CR9_EVENT_STORE_REAL)) { + /* PSW is saved just before calling the helper. */ + env->per_address = env->psw.addr; + env->per_perc_atmid = PER_CODE_EVENT_STORE_REAL | get_per_atmid(env); + } +} #endif static uint8_t stfl_bytes[2048]; diff --git a/target/s390x/translate.c b/target/s390x/translate.c index 151dfa91fb..4292bb0dd0 100644 --- a/target/s390x/translate.c +++ b/target/s390x/translate.c @@ -3272,13 +3272,8 @@ static DisasJumpType op_lpq(DisasContext *s, DisasOps *o) #ifndef CONFIG_USER_ONLY static DisasJumpType op_lura(DisasContext *s, DisasOps *o) { - gen_helper_lura(o->out, cpu_env, o->in2); - return DISAS_NEXT; -} - -static DisasJumpType op_lurag(DisasContext *s, DisasOps *o) -{ - gen_helper_lurag(o->out, cpu_env, o->in2); + o->addr1 = get_address(s, 0, get_field(s->fields, r2), 0); + tcg_gen_qemu_ld_tl(o->out, o->addr1, MMU_REAL_IDX, s->insn->data); return DISAS_NEXT; } #endif @@ -4506,13 +4501,13 @@ static DisasJumpType op_stnosm(DisasContext *s, DisasOps *o) static DisasJumpType op_stura(DisasContext *s, DisasOps *o) { - gen_helper_stura(cpu_env, o->in2, o->in1); - return DISAS_NEXT; -} + o->addr1 = get_address(s, 0, get_field(s->fields, r2), 0); + tcg_gen_qemu_st_tl(o->in1, o->addr1, MMU_REAL_IDX, s->insn->data); -static DisasJumpType op_sturg(DisasContext *s, DisasOps *o) -{ - gen_helper_sturg(cpu_env, o->in2, o->in1); + if (s->base.tb->flags & FLAG_MASK_PER) { + update_psw_addr(s); + gen_helper_per_store_real(cpu_env); + } return DISAS_NEXT; } #endif diff --git a/target/sparc/TODO b/target/sparc/TODO deleted file mode 100644 index b8c727e858..0000000000 --- a/target/sparc/TODO +++ /dev/null @@ -1,88 +0,0 @@ -TODO-list: - -CPU common: -- Unimplemented features/bugs: - - Delay slot handling may fail sometimes (branch end of page, delay - slot next page) - - Atomical instructions - - CPU features should match real CPUs (also ASI selection) -- Optimizations/improvements: - - Condition code/branch handling like x86, also for FPU? - - Remove remaining explicit alignment checks - - Global register for regwptr, so that windowed registers can be - accessed directly - - Improve Sparc32plus addressing - - NPC/PC static optimisations (use JUMP_TB when possible)? (Is this - obsolete?) - - Synthetic instructions - - MMU model dependent on CPU model - - Select ASI helper at translation time (on V9 only if known) - - KQemu/KVM support for VM only - - Hardware breakpoint/watchpoint support - - Cache emulation mode - - Reverse-endian pages - - Faster FPU emulation - - Busy loop detection - -Sparc32 CPUs: -- Unimplemented features/bugs: - - Sun4/Sun4c MMUs - - Some V8 ASIs - -Sparc64 CPUs: -- Unimplemented features/bugs: - - Interrupt handling - - Secondary address space, other MMU functions - - Many V9/UA2005/UA2007 ASIs - - Rest of V9 instructions, missing VIS instructions - - IG/MG/AG vs. UA2007 globals - - Full hypervisor support - - SMP/CMT - - Sun4v CPUs - -Sun4: -- To be added - -Sun4c: -- A lot of unimplemented features -- Maybe split from Sun4m - -Sun4m: -- Unimplemented features/bugs: - - Hardware devices do not match real boards - - Floppy does not work - - CS4231: merge with cs4231a, add DMA - - Add cg6, bwtwo - - Arbitrary resolution support - - PCI for MicroSparc-IIe - - JavaStation machines - - SBus slot probing, FCode ROM support - - SMP probing support - - Interrupt routing does not match real HW - - SuSE 7.3 keyboard sometimes unresponsive - - Gentoo 2004.1 SMP does not work - - SS600MP ledma -> lebuffer - - Type 5 keyboard - - Less fixed hardware choices - - DBRI audio (Am7930) - - BPP parallel - - Diagnostic switch - - ESP PIO mode - -Sun4d: -- A lot of unimplemented features: - - SBI - - IO-unit -- Maybe split from Sun4m - -Sun4u: -- Unimplemented features/bugs: - - Interrupt controller - - PCI/IOMMU support (Simba, JIO, Tomatillo, Psycho, Schizo, Safari...) - - SMP - - Happy Meal Ethernet, flash, I2C, GPIO - - A lot of real machine types - -Sun4v: -- A lot of unimplemented features - - A lot of real machine types diff --git a/target/tilegx/translate.c b/target/tilegx/translate.c index 68dd4aa2d8..abce7e1c75 100644 --- a/target/tilegx/translate.c +++ b/target/tilegx/translate.c @@ -2388,7 +2388,6 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) dc->zero = NULL; if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { - qemu_log_lock(); qemu_log("IN: %s\n", lookup_symbol(pc_start)); } gen_tb_start(tb); @@ -2417,11 +2416,6 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) gen_tb_end(tb, num_insns); tb->size = dc->pc - pc_start; tb->icount = num_insns; - - if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { - qemu_log("\n"); - qemu_log_unlock(); - } } void restore_state_to_opc(CPUTLGState *env, TranslationBlock *tb, diff --git a/target/unicore32/translate.c b/target/unicore32/translate.c index 0e01f35856..0f6891b8aa 100644 --- a/target/unicore32/translate.c +++ b/target/unicore32/translate.c @@ -1994,12 +1994,12 @@ done_generating: #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) && qemu_log_in_addr_range(pc_start)) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(pc_start)); log_target_disas(cs, pc_start, dc->pc - pc_start); qemu_log("\n"); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif tb->size = dc->pc - pc_start; diff --git a/tcg/tcg.c b/tcg/tcg.c index 5475d49ed1..4f616ba38b 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1085,7 +1085,7 @@ void tcg_prologue_init(TCGContext *s) #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("PROLOGUE: [size=%zu]\n", prologue_size); if (s->data_gen_ptr) { size_t code_size = s->data_gen_ptr - buf0; @@ -1110,7 +1110,7 @@ void tcg_prologue_init(TCGContext *s) } qemu_log("\n"); qemu_log_flush(); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif @@ -2114,9 +2114,17 @@ static void tcg_dump_ops(TCGContext *s, bool have_prefs) } if (have_prefs || op->life) { - for (; col < 40; ++col) { - putc(' ', qemu_logfile); + + QemuLogFile *logfile; + + rcu_read_lock(); + logfile = atomic_rcu_read(&qemu_logfile); + if (logfile) { + for (; col < 40; ++col) { + putc(' ', logfile->fd); + } } + rcu_read_unlock(); } if (op->life) { @@ -4041,11 +4049,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP) && qemu_log_in_addr_range(tb->pc))) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("OP:\n"); tcg_dump_ops(s, false); qemu_log("\n"); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif @@ -4086,11 +4094,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_IND) && qemu_log_in_addr_range(tb->pc))) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("OP before indirect lowering:\n"); tcg_dump_ops(s, false); qemu_log("\n"); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif /* Replace indirect temps with direct temps. */ @@ -4107,11 +4115,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_OPT) && qemu_log_in_addr_range(tb->pc))) { - qemu_log_lock(); + FILE *logfile = qemu_log_lock(); qemu_log("OP after optimization and liveness analysis:\n"); tcg_dump_ops(s, true); qemu_log("\n"); - qemu_log_unlock(); + qemu_log_unlock(logfile); } #endif diff --git a/tests/Makefile.include b/tests/Makefile.include index b381387048..31b86674e5 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -167,7 +167,7 @@ check-qtest-pci-$(CONFIG_IVSHMEM_DEVICE) += tests/ivshmem-test$(EXESUF) check-qtest-i386-$(CONFIG_ISA_TESTDEV) = tests/endianness-test$(EXESUF) check-qtest-i386-y += tests/fdc-test$(EXESUF) check-qtest-i386-y += tests/ide-test$(EXESUF) -check-qtest-i386-y += tests/ahci-test$(EXESUF) +check-qtest-i386-$(CONFIG_TOOLS) += tests/ahci-test$(EXESUF) check-qtest-i386-y += tests/hd-geo-test$(EXESUF) check-qtest-i386-y += tests/boot-order-test$(EXESUF) check-qtest-i386-y += tests/bios-tables-test$(EXESUF) @@ -1191,7 +1191,9 @@ check-acceptance: check-venv $(TESTS_RESULTS_DIR) .PHONY: check-block check-qapi-schema check-qtest check-unit check check-clean check-qapi-schema: check-tests/qapi-schema/frontend check-tests/qapi-schema/doc-good.texi check-qtest: $(patsubst %,check-qtest-%, $(QTEST_TARGETS)) +ifeq ($(CONFIG_TOOLS),y) check-block: $(patsubst %,check-%, $(check-block-y)) +endif check: check-block check-qapi-schema check-unit check-softfloat check-qtest check-decodetree check-clean: rm -rf $(check-unit-y) tests/*.o $(QEMU_IOTESTS_HELPERS-y) diff --git a/tests/arm-cpu-features.c b/tests/arm-cpu-features.c index 6e99aa951e..bef3ed24b6 100644 --- a/tests/arm-cpu-features.c +++ b/tests/arm-cpu-features.c @@ -20,8 +20,8 @@ */ #define SVE_MAX_VQ 16 -#define MACHINE "-machine virt,gic-version=max,accel=tcg " -#define MACHINE_KVM "-machine virt,gic-version=max,accel=kvm:tcg " +#define MACHINE "-machine virt,gic-version=max -accel tcg " +#define MACHINE_KVM "-machine virt,gic-version=max -accel kvm -accel tcg " #define QUERY_HEAD "{ 'execute': 'query-cpu-model-expansion', " \ " 'arguments': { 'type': 'full', " #define QUERY_TAIL "}}" diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index 79f5da092f..bc0ad594a1 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -51,7 +51,7 @@ #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML" typedef struct { - const char *accel; + bool tcg_only; const char *machine; const char *variant; const char *uefi_fl1; @@ -607,19 +607,19 @@ static void test_acpi_one(const char *params, test_data *data) * TODO: convert '-drive if=pflash' to new syntax (see e33763be7cd3) * when arm/virt boad starts to support it. */ - args = g_strdup_printf("-machine %s,accel=%s -nodefaults -nographic " + args = g_strdup_printf("-machine %s %s -accel tcg -nodefaults -nographic " "-drive if=pflash,format=raw,file=%s,readonly " "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s", - data->machine, data->accel ? data->accel : "kvm:tcg", + data->machine, data->tcg_only ? "" : "-accel kvm", data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : ""); } else { /* Disable kernel irqchip to be able to override apic irq0. */ - args = g_strdup_printf("-machine %s,accel=%s,kernel-irqchip=off " + args = g_strdup_printf("-machine %s,kernel-irqchip=off %s -accel tcg " "-net none -display none %s " "-drive id=hd0,if=none,file=%s,format=raw " "-device ide-hd,drive=hd0 ", - data->machine, data->accel ? data->accel : "kvm:tcg", + data->machine, data->tcg_only ? "" : "-accel kvm", params ? params : "", disk); } @@ -904,7 +904,7 @@ static void test_acpi_virt_tcg_memhp(void) { test_data data = { .machine = "virt", - .accel = "tcg", + .tcg_only = true, .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", @@ -929,7 +929,7 @@ static void test_acpi_virt_tcg_numamem(void) { test_data data = { .machine = "virt", - .accel = "tcg", + .tcg_only = true, .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", @@ -951,7 +951,7 @@ static void test_acpi_virt_tcg(void) { test_data data = { .machine = "virt", - .accel = "tcg", + .tcg_only = true, .uefi_fl1 = "pc-bios/edk2-aarch64-code.fd", .uefi_fl2 = "pc-bios/edk2-arm-vars.fd", .cd = "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2", diff --git a/tests/boot-sector.c b/tests/boot-sector.c index 7824286b9a..9e66c6d013 100644 --- a/tests/boot-sector.c +++ b/tests/boot-sector.c @@ -75,11 +75,11 @@ static const uint8_t s390x_psw_and_magic[] = { 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* in the s390-ccw bios */ }; static const uint8_t s390x_code[] = { - 0xa7, 0xf4, 0x00, 0x0a, /* j 0x10010 */ + 0xa7, 0xf4, 0x00, 0x08, /* j 0x10010 */ 0x00, 0x00, 0x00, 0x00, 'S', '3', '9', '0', 'E', 'P', 0x00, 0x01, - 0xa7, 0x38, HIGH(SIGNATURE_ADDR), LOW(SIGNATURE_ADDR), /* lhi r3,0x7c10 */ + 0xa7, 0x39, HIGH(SIGNATURE_ADDR), LOW(SIGNATURE_ADDR), /* lghi r3,0x7c10 */ 0xa7, 0x48, LOW(SIGNATURE), HIGH(SIGNATURE), /* lhi r4,0xadde */ 0x40, 0x40, 0x30, 0x00, /* sth r4,0(r3) */ 0xa7, 0xf4, 0xff, 0xfa /* j 0x10010 */ diff --git a/tests/boot-serial-test.c b/tests/boot-serial-test.c index d3a54a0ba5..05c7f44457 100644 --- a/tests/boot-serial-test.c +++ b/tests/boot-serial-test.c @@ -215,9 +215,9 @@ static void test_machine(const void *data) * Make sure that this test uses tcg if available: It is used as a * fast-enough smoketest for that. */ - qts = qtest_initf("%s %s -M %s,accel=tcg:kvm -no-shutdown " + qts = qtest_initf("%s %s -M %s -no-shutdown " "-chardev file,id=serial0,path=%s " - "-serial chardev:serial0 %s", + "-serial chardev:serial0 -accel tcg -accel kvm %s", codeparam, code ? codetmp : "", test->machine, serialtmp, test->extra); if (code) { diff --git a/tests/cdrom-test.c b/tests/cdrom-test.c index 34e9974634..67635e387a 100644 --- a/tests/cdrom-test.c +++ b/tests/cdrom-test.c @@ -120,7 +120,7 @@ static void test_cdboot(gconstpointer data) { QTestState *qts; - qts = qtest_initf("-M accel=kvm:tcg -no-shutdown %s%s", (const char *)data, + qts = qtest_initf("-accel kvm -accel tcg -no-shutdown %s%s", (const char *)data, isoimage); boot_sector_test(qts); qtest_quit(qts); diff --git a/tests/cpu-plug-test.c b/tests/cpu-plug-test.c index 30e514bbfb..e8ffbbce4b 100644 --- a/tests/cpu-plug-test.c +++ b/tests/cpu-plug-test.c @@ -148,11 +148,7 @@ static void add_pc_test_case(const char *mname) (strcmp(mname, "pc-1.3") == 0) || (strcmp(mname, "pc-1.2") == 0) || (strcmp(mname, "pc-1.1") == 0) || - (strcmp(mname, "pc-1.0") == 0) || - (strcmp(mname, "pc-0.15") == 0) || - (strcmp(mname, "pc-0.14") == 0) || - (strcmp(mname, "pc-0.13") == 0) || - (strcmp(mname, "pc-0.12") == 0)) { + (strcmp(mname, "pc-1.0") == 0)) { path = g_strdup_printf("cpu-plug/%s/init/%ux%ux%u&maxcpus=%u", mname, data->sockets, data->cores, data->threads, data->maxcpus); diff --git a/tests/docker/common.rc b/tests/docker/common.rc index 512202b0a1..02cd67a8c5 100755 --- a/tests/docker/common.rc +++ b/tests/docker/common.rc @@ -53,12 +53,7 @@ check_qemu() INVOCATION="$@" fi - if command -v gtester > /dev/null 2>&1 && \ - gtester --version > /dev/null 2>&1; then - make $MAKEFLAGS $INVOCATION - else - echo "No working gtester, skipping make $INVOCATION" - fi + make $MAKEFLAGS $INVOCATION } test_fail() diff --git a/tests/hd-geo-test.c b/tests/hd-geo-test.c index 7e86c5416c..a249800544 100644 --- a/tests/hd-geo-test.c +++ b/tests/hd-geo-test.c @@ -34,8 +34,13 @@ static char *create_test_img(int secs) fd = mkstemp(template); g_assert(fd >= 0); ret = ftruncate(fd, (off_t)secs * 512); - g_assert(ret == 0); close(fd); + + if (ret) { + free(template); + template = NULL; + } + return template; } @@ -934,6 +939,10 @@ int main(int argc, char **argv) for (i = 0; i < backend_last; i++) { if (img_secs[i] >= 0) { img_file_name[i] = create_test_img(img_secs[i]); + if (!img_file_name[i]) { + g_test_message("Could not create test images."); + goto test_add_done; + } } else { img_file_name[i] = NULL; } @@ -965,6 +974,7 @@ int main(int argc, char **argv) "skipping hd-geo/override/* tests"); } +test_add_done: ret = g_test_run(); for (i = 0; i < backend_last; i++) { diff --git a/tests/libqtest.c b/tests/libqtest.c index f36e30a4de..76c9f8eade 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -241,9 +241,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args) "-qtest-log %s " "-chardev socket,path=%s,id=char0 " "-mon chardev=char0,mode=control " - "-accel qtest " "-display none " - "%s", qemu_binary, socket_path, + "%s" + " -accel qtest", qemu_binary, socket_path, getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null", qmp_socket_path, extra_args ?: ""); diff --git a/tests/migration-test.c b/tests/migration-test.c index a5343fdc66..e56e6dcb00 100644 --- a/tests/migration-test.c +++ b/tests/migration-test.c @@ -380,13 +380,6 @@ static void cleanup(const char *filename) g_free(path); } -static char *get_shmem_opts(const char *mem_size, const char *shmem_path) -{ - return g_strdup_printf("-object memory-backend-file,id=mem0,size=%s" - ",mem-path=%s,share=on -numa node,memdev=mem0", - mem_size, shmem_path); -} - static char *SocketAddress_to_str(SocketAddress *addr) { switch (addr->type) { @@ -551,27 +544,47 @@ static void migrate_postcopy_start(QTestState *from, QTestState *to) qtest_qmp_eventwait(to, "RESUME"); } +typedef struct { + bool hide_stderr; + bool use_shmem; + char *opts_source; + char *opts_target; +} MigrateStart; + +static MigrateStart *migrate_start_new(void) +{ + MigrateStart *args = g_new0(MigrateStart, 1); + + args->opts_source = g_strdup(""); + args->opts_target = g_strdup(""); + return args; +} + +static void migrate_start_destroy(MigrateStart *args) +{ + g_free(args->opts_source); + g_free(args->opts_target); + g_free(args); +} + static int test_migrate_start(QTestState **from, QTestState **to, - const char *uri, bool hide_stderr, - bool use_shmem, const char *opts_src, - const char *opts_dst) + const char *uri, MigrateStart *args) { - gchar *cmd_src, *cmd_dst; + gchar *arch_source, *arch_target; + gchar *cmd_source, *cmd_target; + const gchar *ignore_stderr; char *bootpath = NULL; - char *extra_opts = NULL; - char *shmem_path = NULL; + char *shmem_opts; + char *shmem_path; const char *arch = qtest_get_arch(); - const char *accel = "kvm:tcg"; + const char *machine_opts = NULL; + const char *memory_size; - opts_src = opts_src ? opts_src : ""; - opts_dst = opts_dst ? opts_dst : ""; - - if (use_shmem) { + if (args->use_shmem) { if (!g_file_test("/dev/shm", G_FILE_TEST_IS_DIR)) { g_test_skip("/dev/shm is not supported"); return -1; } - shmem_path = g_strdup_printf("/dev/shm/qemu-%d", getpid()); } got_stop = false; @@ -580,75 +593,37 @@ static int test_migrate_start(QTestState **from, QTestState **to, /* the assembled x86 boot sector should be exactly one sector large */ assert(sizeof(x86_bootsect) == 512); init_bootfile(bootpath, x86_bootsect, sizeof(x86_bootsect)); - extra_opts = use_shmem ? get_shmem_opts("150M", shmem_path) : NULL; - cmd_src = g_strdup_printf("-machine accel=%s -m 150M" - " -name source,debug-threads=on" - " -serial file:%s/src_serial" - " -drive file=%s,format=raw %s %s", - accel, tmpfs, bootpath, - extra_opts ? extra_opts : "", opts_src); - cmd_dst = g_strdup_printf("-machine accel=%s -m 150M" - " -name target,debug-threads=on" - " -serial file:%s/dest_serial" - " -drive file=%s,format=raw" - " -incoming %s %s %s", - accel, tmpfs, bootpath, uri, - extra_opts ? extra_opts : "", opts_dst); + memory_size = "150M"; + arch_source = g_strdup_printf("-drive file=%s,format=raw", bootpath); + arch_target = g_strdup(arch_source); start_address = X86_TEST_MEM_START; end_address = X86_TEST_MEM_END; } else if (g_str_equal(arch, "s390x")) { init_bootfile(bootpath, s390x_elf, sizeof(s390x_elf)); - extra_opts = use_shmem ? get_shmem_opts("128M", shmem_path) : NULL; - cmd_src = g_strdup_printf("-machine accel=%s -m 128M" - " -name source,debug-threads=on" - " -serial file:%s/src_serial -bios %s %s %s", - accel, tmpfs, bootpath, - extra_opts ? extra_opts : "", opts_src); - cmd_dst = g_strdup_printf("-machine accel=%s -m 128M" - " -name target,debug-threads=on" - " -serial file:%s/dest_serial -bios %s" - " -incoming %s %s %s", - accel, tmpfs, bootpath, uri, - extra_opts ? extra_opts : "", opts_dst); + memory_size = "128M"; + arch_source = g_strdup_printf("-bios %s", bootpath); + arch_target = g_strdup(arch_source); start_address = S390_TEST_MEM_START; end_address = S390_TEST_MEM_END; } else if (strcmp(arch, "ppc64") == 0) { - extra_opts = use_shmem ? get_shmem_opts("256M", shmem_path) : NULL; - cmd_src = g_strdup_printf("-machine accel=%s,vsmt=8 -m 256M -nodefaults" - " -name source,debug-threads=on" - " -serial file:%s/src_serial" - " -prom-env 'use-nvramrc?=true' -prom-env " - "'nvramrc=hex .\" _\" begin %x %x " - "do i c@ 1 + i c! 1000 +loop .\" B\" 0 " - "until' %s %s", accel, tmpfs, end_address, - start_address, extra_opts ? extra_opts : "", - opts_src); - cmd_dst = g_strdup_printf("-machine accel=%s,vsmt=8 -m 256M" - " -name target,debug-threads=on" - " -serial file:%s/dest_serial" - " -incoming %s %s %s", - accel, tmpfs, uri, - extra_opts ? extra_opts : "", opts_dst); - + machine_opts = "vsmt=8"; + memory_size = "256M"; + arch_source = g_strdup_printf("-nodefaults " + "-prom-env 'use-nvramrc?=true' -prom-env " + "'nvramrc=hex .\" _\" begin %x %x " + "do i c@ 1 + i c! 1000 +loop .\" B\" 0 " + "until'", end_address, start_address); + arch_target = g_strdup(""); start_address = PPC_TEST_MEM_START; end_address = PPC_TEST_MEM_END; } else if (strcmp(arch, "aarch64") == 0) { init_bootfile(bootpath, aarch64_kernel, sizeof(aarch64_kernel)); - extra_opts = use_shmem ? get_shmem_opts("150M", shmem_path) : NULL; - cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=max " - "-name vmsource,debug-threads=on -cpu max " - "-m 150M -serial file:%s/src_serial " - "-kernel %s %s %s", - accel, tmpfs, bootpath, - extra_opts ? extra_opts : "", opts_src); - cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=max " - "-name vmdest,debug-threads=on -cpu max " - "-m 150M -serial file:%s/dest_serial " - "-kernel %s " - "-incoming %s %s %s", - accel, tmpfs, bootpath, uri, - extra_opts ? extra_opts : "", opts_dst); - + machine_opts = "virt,gic-version=max"; + memory_size = "150M"; + arch_source = g_strdup_printf("-cpu max " + "-kernel %s", + bootpath); + arch_target = g_strdup(arch_source); start_address = ARM_TEST_MEM_START; end_address = ARM_TEST_MEM_END; @@ -658,34 +633,64 @@ static int test_migrate_start(QTestState **from, QTestState **to, } g_free(bootpath); - g_free(extra_opts); - - if (hide_stderr) { - gchar *tmp; - tmp = g_strdup_printf("%s 2>/dev/null", cmd_src); - g_free(cmd_src); - cmd_src = tmp; - tmp = g_strdup_printf("%s 2>/dev/null", cmd_dst); - g_free(cmd_dst); - cmd_dst = tmp; + if (args->hide_stderr) { + ignore_stderr = "2>/dev/null"; + } else { + ignore_stderr = ""; } - *from = qtest_init(cmd_src); - g_free(cmd_src); - - *to = qtest_init(cmd_dst); - g_free(cmd_dst); + if (args->use_shmem) { + shmem_path = g_strdup_printf("/dev/shm/qemu-%d", getpid()); + shmem_opts = g_strdup_printf( + "-object memory-backend-file,id=mem0,size=%s" + ",mem-path=%s,share=on -numa node,memdev=mem0", + memory_size, shmem_path); + } else { + shmem_path = NULL; + shmem_opts = g_strdup(""); + } + cmd_source = g_strdup_printf("-accel kvm -accel tcg%s%s " + "-name source,debug-threads=on " + "-m %s " + "-serial file:%s/src_serial " + "%s %s %s %s", + machine_opts ? " -machine " : "", + machine_opts ? machine_opts : "", + memory_size, tmpfs, + arch_source, shmem_opts, args->opts_source, + ignore_stderr); + g_free(arch_source); + *from = qtest_init(cmd_source); + g_free(cmd_source); + + cmd_target = g_strdup_printf("-accel kvm -accel tcg%s%s " + "-name target,debug-threads=on " + "-m %s " + "-serial file:%s/dest_serial " + "-incoming %s " + "%s %s %s %s", + machine_opts ? " -machine " : "", + machine_opts ? machine_opts : "", + memory_size, tmpfs, uri, + arch_target, shmem_opts, + args->opts_target, ignore_stderr); + g_free(arch_target); + *to = qtest_init(cmd_target); + g_free(cmd_target); + + g_free(shmem_opts); /* * Remove shmem file immediately to avoid memory leak in test failed case. * It's valid becase QEMU has already opened this file */ - if (use_shmem) { + if (args->use_shmem) { unlink(shmem_path); g_free(shmem_path); } + migrate_start_destroy(args); return 0; } @@ -771,13 +776,13 @@ static void test_deprecated(void) } static int migrate_postcopy_prepare(QTestState **from_ptr, - QTestState **to_ptr, - bool hide_error) + QTestState **to_ptr, + MigrateStart *args) { char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); QTestState *from, *to; - if (test_migrate_start(&from, &to, uri, hide_error, false, NULL, NULL)) { + if (test_migrate_start(&from, &to, uri, args)) { return -1; } @@ -822,9 +827,10 @@ static void migrate_postcopy_complete(QTestState *from, QTestState *to) static void test_postcopy(void) { + MigrateStart *args = migrate_start_new(); QTestState *from, *to; - if (migrate_postcopy_prepare(&from, &to, false)) { + if (migrate_postcopy_prepare(&from, &to, args)) { return; } migrate_postcopy_start(from, to); @@ -833,10 +839,13 @@ static void test_postcopy(void) static void test_postcopy_recovery(void) { + MigrateStart *args = migrate_start_new(); QTestState *from, *to; char *uri; - if (migrate_postcopy_prepare(&from, &to, true)) { + args->hide_stderr = true; + + if (migrate_postcopy_prepare(&from, &to, args)) { return; } @@ -919,9 +928,12 @@ static void wait_for_migration_fail(QTestState *from, bool allow_active) static void test_baddest(void) { + MigrateStart *args = migrate_start_new(); QTestState *from, *to; - if (test_migrate_start(&from, &to, "tcp:0:0", true, false, NULL, NULL)) { + args->hide_stderr = true; + + if (test_migrate_start(&from, &to, "tcp:0:0", args)) { return; } migrate(from, "tcp:0:0", "{}"); @@ -932,9 +944,10 @@ static void test_baddest(void) static void test_precopy_unix(void) { char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateStart *args = migrate_start_new(); QTestState *from, *to; - if (test_migrate_start(&from, &to, uri, false, false, NULL, NULL)) { + if (test_migrate_start(&from, &to, uri, args)) { return; } @@ -1010,9 +1023,10 @@ static void test_ignore_shared(void) static void test_xbzrle(const char *uri) { + MigrateStart *args = migrate_start_new(); QTestState *from, *to; - if (test_migrate_start(&from, &to, uri, false, false, NULL, NULL)) { + if (test_migrate_start(&from, &to, uri, args)) { return; } @@ -1061,11 +1075,11 @@ static void test_xbzrle_unix(void) static void test_precopy_tcp(void) { + MigrateStart *args = migrate_start_new(); char *uri; QTestState *from, *to; - if (test_migrate_start(&from, &to, "tcp:127.0.0.1:0", false, false, - NULL, NULL)) { + if (test_migrate_start(&from, &to, "tcp:127.0.0.1:0", args)) { return; } @@ -1105,13 +1119,14 @@ static void test_precopy_tcp(void) static void test_migrate_fd_proto(void) { + MigrateStart *args = migrate_start_new(); QTestState *from, *to; int ret; int pair[2]; QDict *rsp; const char *error_desc; - if (test_migrate_start(&from, &to, "defer", false, false, NULL, NULL)) { + if (test_migrate_start(&from, &to, "defer", args)) { return; } @@ -1187,15 +1202,12 @@ static void test_migrate_fd_proto(void) test_migrate_end(from, to, true); } -static void do_test_validate_uuid(const char *uuid_arg_src, - const char *uuid_arg_dst, - bool should_fail, bool hide_stderr) +static void do_test_validate_uuid(MigrateStart *args, bool should_fail) { char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); QTestState *from, *to; - if (test_migrate_start(&from, &to, uri, hide_stderr, false, - uuid_arg_src, uuid_arg_dst)) { + if (test_migrate_start(&from, &to, uri, args)) { return; } @@ -1225,33 +1237,45 @@ static void do_test_validate_uuid(const char *uuid_arg_src, static void test_validate_uuid(void) { - do_test_validate_uuid("-uuid 11111111-1111-1111-1111-111111111111", - "-uuid 11111111-1111-1111-1111-111111111111", - false, false); + MigrateStart *args = migrate_start_new(); + + args->opts_source = g_strdup("-uuid 11111111-1111-1111-1111-111111111111"); + args->opts_target = g_strdup("-uuid 11111111-1111-1111-1111-111111111111"); + do_test_validate_uuid(args, false); } static void test_validate_uuid_error(void) { - do_test_validate_uuid("-uuid 11111111-1111-1111-1111-111111111111", - "-uuid 22222222-2222-2222-2222-222222222222", - true, true); + MigrateStart *args = migrate_start_new(); + + args->opts_source = g_strdup("-uuid 11111111-1111-1111-1111-111111111111"); + args->opts_target = g_strdup("-uuid 22222222-2222-2222-2222-222222222222"); + args->hide_stderr = true; + do_test_validate_uuid(args, true); } static void test_validate_uuid_src_not_set(void) { - do_test_validate_uuid(NULL, "-uuid 11111111-1111-1111-1111-111111111111", - false, true); + MigrateStart *args = migrate_start_new(); + + args->opts_target = g_strdup("-uuid 22222222-2222-2222-2222-222222222222"); + args->hide_stderr = true; + do_test_validate_uuid(args, false); } static void test_validate_uuid_dst_not_set(void) { - do_test_validate_uuid("-uuid 11111111-1111-1111-1111-111111111111", NULL, - false, true); + MigrateStart *args = migrate_start_new(); + + args->opts_source = g_strdup("-uuid 11111111-1111-1111-1111-111111111111"); + args->hide_stderr = true; + do_test_validate_uuid(args, false); } static void test_migrate_auto_converge(void) { char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); + MigrateStart *args = migrate_start_new(); QTestState *from, *to; int64_t remaining, percentage; @@ -1270,7 +1294,7 @@ static void test_migrate_auto_converge(void) */ const int64_t expected_threshold = max_bandwidth * downtime_limit / 1000; - if (test_migrate_start(&from, &to, uri, false, false, NULL, NULL)) { + if (test_migrate_start(&from, &to, uri, args)) { return; } diff --git a/tests/pflash-cfi02-test.c b/tests/pflash-cfi02-test.c index d3b23f4f66..17aa669b2e 100644 --- a/tests/pflash-cfi02-test.c +++ b/tests/pflash-cfi02-test.c @@ -260,7 +260,7 @@ static void test_geometry(const void *opaque) { const FlashConfig *config = opaque; QTestState *qtest; - qtest = qtest_initf("-M musicpal,accel=qtest" + qtest = qtest_initf("-M musicpal" " -drive if=pflash,file=%s,format=raw,copy-on-read" /* Device geometry properties. */ " -global driver=cfi.pflash02," @@ -580,7 +580,7 @@ static void test_cfi_in_autoselect(const void *opaque) { const FlashConfig *config = opaque; QTestState *qtest; - qtest = qtest_initf("-M musicpal,accel=qtest" + qtest = qtest_initf("-M musicpal" " -drive if=pflash,file=%s,format=raw,copy-on-read", image_path); FlashConfig explicit_config = expand_config_defaults(config); diff --git a/tests/pnv-xscom-test.c b/tests/pnv-xscom-test.c index 9fddc7d5f9..2c46d5cf6d 100644 --- a/tests/pnv-xscom-test.c +++ b/tests/pnv-xscom-test.c @@ -84,7 +84,7 @@ static void test_cfam_id(const void *data) machine = "powernv9"; } - qts = qtest_initf("-M %s,accel=tcg -cpu %s", + qts = qtest_initf("-M %s -accel tcg -cpu %s", machine, chip->cpu_model); test_xscom_cfam_id(qts, chip); qtest_quit(qts); @@ -125,7 +125,7 @@ static void test_core(const void *data) machine = "powernv9"; } - qts = qtest_initf("-M %s,accel=tcg -cpu %s", + qts = qtest_initf("-M %s -accel tcg -cpu %s", machine, chip->cpu_model); test_xscom_core(qts, chip); qtest_quit(qts); diff --git a/tests/prom-env-test.c b/tests/prom-env-test.c index 61bc1d1e7b..9be52c766f 100644 --- a/tests/prom-env-test.c +++ b/tests/prom-env-test.c @@ -57,7 +57,7 @@ static void test_machine(const void *machine) " -machine cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken"; } - qts = qtest_initf("-M %s,accel=tcg %s -prom-env 'use-nvramrc?=true' " + qts = qtest_initf("-M %s -accel tcg %s -prom-env 'use-nvramrc?=true' " "-prom-env 'nvramrc=%x %x l!' ", (const char *)machine, extra_args, MAGIC, ADDRESS); check_guest_memory(qts); diff --git a/tests/pxe-test.c b/tests/pxe-test.c index aaae54f755..f68d0aadbb 100644 --- a/tests/pxe-test.c +++ b/tests/pxe-test.c @@ -74,7 +74,7 @@ static void test_pxe_one(const testdef_t *test, bool ipv6) } args = g_strdup_printf( - "-machine %s,accel=kvm:tcg -nodefaults -boot order=n " + "-accel kvm -accel tcg -machine %s -nodefaults -boot order=n " "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s " "-device %s,bootindex=1,netdev=" NETNAME " %s", test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off", diff --git a/tests/tcg/Makefile.prereqs b/tests/tcg/Makefile.prereqs index 7494b31b95..9a29604a83 100644 --- a/tests/tcg/Makefile.prereqs +++ b/tests/tcg/Makefile.prereqs @@ -13,6 +13,6 @@ DOCKER_IMAGE:= ifneq ($(DOCKER_IMAGE),) build-tcg-tests-$(PROBE_TARGET): docker-image-$(DOCKER_IMAGE) +endif $(BUILD_DIR)/tests/tcg/config_$(PROBE_TARGET).mak: config-host.mak config-host.mak: $(SRC_PATH)/tests/tcg/configure.sh -endif diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh index 6c4a471aea..210e68396f 100755 --- a/tests/tcg/configure.sh +++ b/tests/tcg/configure.sh @@ -36,8 +36,10 @@ TMPC="${TMPDIR1}/qemu-conf.c" TMPE="${TMPDIR1}/qemu-conf.exe" container="no" -if has "docker" || has "podman"; then - container=$($python $source_path/tests/docker/docker.py probe) +if test $use_containers = "yes"; then + if has "docker" || has "podman"; then + container=$($python $source_path/tests/docker/docker.py probe) + fi fi # cross compilers defaults, can be overridden with --cross-cc-ARCH diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index 7844c9ffcb..4eeb184caf 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -34,13 +34,13 @@ static BlockJob *mk_job(BlockBackend *blk, const char *id, int flags) { BlockJob *job; - Error *errp = NULL; + Error *err = NULL; job = block_job_create(id, drv, NULL, blk_bs(blk), 0, BLK_PERM_ALL, 0, flags, block_job_cb, - NULL, &errp); + NULL, &err); if (should_succeed) { - g_assert_null(errp); + g_assert_null(err); g_assert_nonnull(job); if (id) { g_assert_cmpstr(job->job.id, ==, id); @@ -48,9 +48,8 @@ static BlockJob *mk_job(BlockBackend *blk, const char *id, g_assert_cmpstr(job->job.id, ==, blk_name(blk)); } } else { - g_assert_nonnull(errp); + error_free_or_abort(&err); g_assert_null(job); - error_free(errp); } return job; @@ -80,9 +79,9 @@ static BlockBackend *create_blk(const char *name) bdrv_unref(bs); if (name) { - Error *errp = NULL; - monitor_add_blk(blk, name, &errp); - g_assert_null(errp); + Error *err = NULL; + monitor_add_blk(blk, name, &err); + g_assert_null(err); } return blk; diff --git a/tests/test-keyval.c b/tests/test-keyval.c index 09b0ae3c68..e331a84149 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -478,7 +478,7 @@ static void test_keyval_visit_size(void) visit_free(v); /* Trailing crap */ - qdict = keyval_parse("sz1=16E,sz2=16Gi", NULL, &error_abort); + qdict = keyval_parse("sz1=0Z,sz2=16Gi", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); qobject_unref(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); diff --git a/tests/test-logging.c b/tests/test-logging.c index a12585f70a..1e646f045d 100644 --- a/tests/test-logging.c +++ b/tests/test-logging.c @@ -108,6 +108,82 @@ static void test_parse_path(gconstpointer data) error_free_or_abort(&err); } +static void test_logfile_write(gconstpointer data) +{ + QemuLogFile *logfile; + QemuLogFile *logfile2; + gchar const *dir = data; + Error *err = NULL; + g_autofree gchar *file_path; + g_autofree gchar *file_path1; + FILE *orig_fd; + + /* + * Before starting test, set log flags, to ensure the file gets + * opened below with the call to qemu_set_log_filename(). + * In cases where a logging backend other than log is used, + * this is needed. + */ + qemu_set_log(CPU_LOG_TB_OUT_ASM); + file_path = g_build_filename(dir, "qemu_test_log_write0.log", NULL); + file_path1 = g_build_filename(dir, "qemu_test_log_write1.log", NULL); + + /* + * Test that even if an open file handle is changed, + * our handle remains valid due to RCU. + */ + qemu_set_log_filename(file_path, &err); + g_assert(!err); + rcu_read_lock(); + logfile = atomic_rcu_read(&qemu_logfile); + orig_fd = logfile->fd; + g_assert(logfile && logfile->fd); + fprintf(logfile->fd, "%s 1st write to file\n", __func__); + fflush(logfile->fd); + + /* Change the logfile and ensure that the handle is still valid. */ + qemu_set_log_filename(file_path1, &err); + g_assert(!err); + logfile2 = atomic_rcu_read(&qemu_logfile); + g_assert(logfile->fd == orig_fd); + g_assert(logfile2->fd != logfile->fd); + fprintf(logfile->fd, "%s 2nd write to file\n", __func__); + fflush(logfile->fd); + rcu_read_unlock(); +} + +static void test_logfile_lock(gconstpointer data) +{ + FILE *logfile; + gchar const *dir = data; + Error *err = NULL; + g_autofree gchar *file_path; + + file_path = g_build_filename(dir, "qemu_test_logfile_lock0.log", NULL); + + /* + * Test the use of the logfile lock, such + * that even if an open file handle is closed, + * our handle remains valid for use due to RCU. + */ + qemu_set_log_filename(file_path, &err); + logfile = qemu_log_lock(); + g_assert(logfile); + fprintf(logfile, "%s 1st write to file\n", __func__); + fflush(logfile); + + /* + * Initiate a close file and make sure our handle remains + * valid since we still have the logfile lock. + */ + qemu_log_close(); + fprintf(logfile, "%s 2nd write to file\n", __func__); + fflush(logfile); + qemu_log_unlock(logfile); + + g_assert(!err); +} + /* Remove a directory and all its entries (non-recursive). */ static void rmdir_full(gchar const *root) { @@ -134,6 +210,10 @@ int main(int argc, char **argv) g_test_add_func("/logging/parse_range", test_parse_range); g_test_add_data_func("/logging/parse_path", tmp_path, test_parse_path); + g_test_add_data_func("/logging/logfile_write_path", + tmp_path, test_logfile_write); + g_test_add_data_func("/logging/logfile_lock_path", + tmp_path, test_logfile_lock); rc = g_test_run(); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-output-visitor.c index 3e993e5ba8..d7761ebf84 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -145,10 +145,10 @@ static void test_visitor_out_enum_errors(TestOutputVisitorData *data, const void *unused) { EnumOne i, bad_values[] = { ENUM_ONE__MAX, -1 }; - Error *err; for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) { - err = NULL; + Error *err = NULL; + visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err); error_free_or_abort(&err); visitor_reset(data); @@ -240,11 +240,11 @@ static void test_visitor_out_struct_errors(TestOutputVisitorData *data, EnumOne bad_values[] = { ENUM_ONE__MAX, -1 }; UserDefOne u = {0}; UserDefOne *pu = &u; - Error *err; int i; for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) { - err = NULL; + Error *err = NULL; + u.has_enum1 = true; u.enum1 = bad_values[i]; visit_type_UserDefOne(data->ov, "unused", &pu, &err); diff --git a/tests/test-string-output-visitor.c b/tests/test-string-output-visitor.c index 02766c0f65..1be1540767 100644 --- a/tests/test-string-output-visitor.c +++ b/tests/test-string-output-visitor.c @@ -207,10 +207,10 @@ static void test_visitor_out_enum_errors(TestOutputVisitorData *data, const void *unused) { EnumOne i, bad_values[] = { ENUM_ONE__MAX, -1 }; - Error *err; for (i = 0; i < ARRAY_SIZE(bad_values) ; i++) { - err = NULL; + Error *err = NULL; + visit_type_EnumOne(data->ov, "unused", &bad_values[i], &err); error_free_or_abort(&err); } diff --git a/tests/test-util-filemonitor.c b/tests/test-util-filemonitor.c index 301cd2db61..45009c69f4 100644 --- a/tests/test-util-filemonitor.c +++ b/tests/test-util-filemonitor.c @@ -406,10 +406,21 @@ test_file_monitor_events(void) char *pathdst = NULL; QFileMonitorTestData data; GHashTable *ids = g_hash_table_new(g_int64_hash, g_int64_equal); + char *travis_arch; qemu_mutex_init(&data.lock); data.records = NULL; + /* + * This test does not work on Travis LXD containers since some + * syscalls are blocked in that environment. + */ + travis_arch = getenv("TRAVIS_ARCH"); + if (travis_arch && !g_str_equal(travis_arch, "x86_64")) { + g_test_skip("Test does not work on non-x86 Travis containers."); + return; + } + /* * The file monitor needs the main loop running in * order to receive events from inotify. We must diff --git a/tests/vm/Makefile.include b/tests/vm/Makefile.include index fea348e845..9e7c46a473 100644 --- a/tests/vm/Makefile.include +++ b/tests/vm/Makefile.include @@ -34,6 +34,7 @@ vm-help vm-test: @echo " DEBUG=1 - Enable verbose output on host and interactive debugging" @echo " V=1 - Enable verbose ouput on host and guest commands" @echo " QEMU=/path/to/qemu - Change path to QEMU binary" + @echo " QEMU_IMG=/path/to/qemu-img - Change path to qemu-img tool" vm-build-all: $(addprefix vm-build-, $(IMAGES)) diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py index 53b9515ee2..ed5dd4f3d0 100755 --- a/tests/vm/basevm.py +++ b/tests/vm/basevm.py @@ -152,6 +152,11 @@ class BaseVM(object): def build_image(self, img): raise NotImplementedError + def exec_qemu_img(self, *args): + cmd = [os.environ.get("QEMU_IMG", "qemu-img")] + cmd.extend(list(args)) + subprocess.check_call(cmd) + def add_source_dir(self, src_dir): name = "data-" + hashlib.sha1(src_dir.encode("utf-8")).hexdigest()[:5] tarfile = os.path.join(self._tmpdir, name + ".tar") diff --git a/tests/vm/centos b/tests/vm/centos index b9e851f2d3..f2f0befd84 100755 --- a/tests/vm/centos +++ b/tests/vm/centos @@ -68,7 +68,7 @@ class CentosVM(basevm.BaseVM): sys.stderr.write("Extracting the image...\n") subprocess.check_call(["ln", "-f", cimg, img_tmp + ".xz"]) subprocess.check_call(["xz", "--keep", "-dvf", img_tmp + ".xz"]) - subprocess.check_call(["qemu-img", "resize", img_tmp, "50G"]) + self.exec_qemu_img("resize", img_tmp, "50G") self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()]) self.wait_ssh() self.ssh_root_check("touch /etc/cloud/cloud-init.disabled") diff --git a/tests/vm/fedora b/tests/vm/fedora index 7fec1479fb..8e270fc0f0 100755 --- a/tests/vm/fedora +++ b/tests/vm/fedora @@ -74,9 +74,7 @@ class FedoraVM(basevm.BaseVM): self.print_step("Preparing iso and disk image") subprocess.check_call(["cp", "-f", cimg, iso]) - subprocess.check_call(["qemu-img", "create", "-f", "qcow2", - img_tmp, self.size]) - + self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size) self.print_step("Booting installer") self.boot(img_tmp, extra_args = [ "-bios", "pc-bios/bios-256k.bin", diff --git a/tests/vm/freebsd b/tests/vm/freebsd index 2a19461a90..1825cc5821 100755 --- a/tests/vm/freebsd +++ b/tests/vm/freebsd @@ -82,8 +82,7 @@ class FreeBSDVM(basevm.BaseVM): self.print_step("Preparing iso and disk image") subprocess.check_call(["cp", "-f", cimg, iso_xz]) subprocess.check_call(["xz", "-dvf", iso_xz]) - subprocess.check_call(["qemu-img", "create", "-f", "qcow2", - img_tmp, self.size]) + self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size) self.print_step("Booting installer") self.boot(img_tmp, extra_args = [ diff --git a/tests/vm/netbsd b/tests/vm/netbsd index 611e6cc5b5..ec6f3563b2 100755 --- a/tests/vm/netbsd +++ b/tests/vm/netbsd @@ -77,8 +77,7 @@ class NetBSDVM(basevm.BaseVM): self.print_step("Preparing iso and disk image") subprocess.check_call(["ln", "-f", cimg, iso]) - subprocess.check_call(["qemu-img", "create", "-f", "qcow2", - img_tmp, self.size]) + self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size) self.print_step("Booting installer") self.boot(img_tmp, extra_args = [ diff --git a/tests/vm/openbsd b/tests/vm/openbsd index b92c39f89a..6df5162dbf 100755 --- a/tests/vm/openbsd +++ b/tests/vm/openbsd @@ -73,8 +73,7 @@ class OpenBSDVM(basevm.BaseVM): self.print_step("Preparing iso and disk image") subprocess.check_call(["cp", "-f", cimg, iso]) - subprocess.check_call(["qemu-img", "create", "-f", "qcow2", - img_tmp, self.size]) + self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size) self.print_step("Booting installer") self.boot(img_tmp, extra_args = [ diff --git a/tests/vm/ubuntu.i386 b/tests/vm/ubuntu.i386 index f611bebdc9..3834cd7a8d 100755 --- a/tests/vm/ubuntu.i386 +++ b/tests/vm/ubuntu.i386 @@ -70,7 +70,7 @@ class UbuntuX86VM(basevm.BaseVM): sha256sum="28969840626d1ea80bb249c08eef1a4533e8904aa51a327b40f37ac4b4ff04ef") img_tmp = img + ".tmp" subprocess.check_call(["cp", "-f", cimg, img_tmp]) - subprocess.check_call(["qemu-img", "resize", img_tmp, "50G"]) + self.exec_qemu_img("resize", img_tmp, "50G") self.boot(img_tmp, extra_args = ["-cdrom", self._gen_cloud_init_iso()]) self.wait_ssh() self.ssh_root_check("touch /etc/cloud/cloud-init.disabled") diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c index 85d8e6463e..efba76e716 100644 --- a/tests/vmgenid-test.c +++ b/tests/vmgenid-test.c @@ -109,7 +109,7 @@ static void read_guid_from_monitor(QTestState *qts, QemuUUID *guid) static char disk[] = "tests/vmgenid-test-disk-XXXXXX"; #define GUID_CMD(guid) \ - "-machine accel=kvm:tcg " \ + "-accel kvm -accel tcg " \ "-device vmgenid,id=testvgid,guid=%s " \ "-drive id=hd0,if=none,file=%s,format=raw " \ "-device ide-hd,drive=hd0 ", guid, disk diff --git a/trace/control.c b/trace/control.c index d9cafc161b..0fb8124160 100644 --- a/trace/control.c +++ b/trace/control.c @@ -98,38 +98,6 @@ TraceEvent *trace_event_name(const char *name) return NULL; } -static bool pattern_glob(const char *pat, const char *ev) -{ - while (*pat != '\0' && *ev != '\0') { - if (*pat == *ev) { - pat++; - ev++; - } - else if (*pat == '*') { - if (pattern_glob(pat, ev+1)) { - return true; - } else if (pattern_glob(pat+1, ev)) { - return true; - } else { - return false; - } - } else { - return false; - } - } - - while (*pat == '*') { - pat++; - } - - if (*pat == '\0' && *ev == '\0') { - return true; - } else { - return false; - } -} - - void trace_event_iter_init(TraceEventIter *iter, const char *pattern) { iter->event = 0; @@ -148,8 +116,7 @@ TraceEvent *trace_event_iter_next(TraceEventIter *iter) iter->group++; } if (!iter->pattern || - pattern_glob(iter->pattern, - trace_event_get_name(ev))) { + g_pattern_match_simple(iter->pattern, trace_event_get_name(ev))) { return ev; } } diff --git a/ui/vnc.c b/ui/vnc.c index 87b8045afe..4100d6e404 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -1312,7 +1312,7 @@ void vnc_disconnect_finish(VncState *vs) g_free(vs); } -size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp) +size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error *err) { if (ret <= 0) { if (ret == 0) { @@ -1320,15 +1320,11 @@ size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp) vnc_disconnect_start(vs); } else if (ret != QIO_CHANNEL_ERR_BLOCK) { trace_vnc_client_io_error(vs, vs->ioc, - errp ? error_get_pretty(*errp) : - "Unknown"); + err ? error_get_pretty(err) : "Unknown"); vnc_disconnect_start(vs); } - if (errp) { - error_free(*errp); - *errp = NULL; - } + error_free(err); return 0; } return ret; @@ -1361,10 +1357,9 @@ size_t vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen) { Error *err = NULL; ssize_t ret; - ret = qio_channel_write( - vs->ioc, (const char *)data, datalen, &err); + ret = qio_channel_write(vs->ioc, (const char *)data, datalen, &err); VNC_DEBUG("Wrote wire %p %zd -> %ld\n", data, datalen, ret); - return vnc_client_io_error(vs, ret, &err); + return vnc_client_io_error(vs, ret, err); } @@ -1488,10 +1483,9 @@ size_t vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen) { ssize_t ret; Error *err = NULL; - ret = qio_channel_read( - vs->ioc, (char *)data, datalen, &err); + ret = qio_channel_read(vs->ioc, (char *)data, datalen, &err); VNC_DEBUG("Read wire %p %zd -> %ld\n", data, datalen, ret); - return vnc_client_io_error(vs, ret, &err); + return vnc_client_io_error(vs, ret, err); } diff --git a/ui/vnc.h b/ui/vnc.h index fea79c2fc9..4e2637ce6c 100644 --- a/ui/vnc.h +++ b/ui/vnc.h @@ -547,7 +547,7 @@ uint32_t read_u32(uint8_t *data, size_t offset); /* Protocol stage functions */ void vnc_client_error(VncState *vs); -size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp); +size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error *err); void start_client_init(VncState *vs); void start_auth_vnc(VncState *vs); diff --git a/util/Makefile.objs b/util/Makefile.objs index df124af1c5..63599d62aa 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -52,8 +52,7 @@ util-obj-y += stats64.o util-obj-y += systemd.o util-obj-y += iova-tree.o util-obj-$(CONFIG_INOTIFY1) += filemonitor-inotify.o +util-obj-$(call lnot,$(CONFIG_INOTIFY1)) += filemonitor-stub.o util-obj-$(CONFIG_LINUX) += vfio-helpers.o util-obj-$(CONFIG_POSIX) += drm.o util-obj-y += guest-random.o - -stub-obj-y += filemonitor-stub.o diff --git a/util/cutils.c b/util/cutils.c index 2380165230..36ce712271 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -542,7 +542,7 @@ int qemu_strtoul(const char *nptr, const char **endptr, int base, * Convert string @nptr to an int64_t. * * Works like qemu_strtol(), except it stores INT64_MAX on overflow, - * and INT_MIN on underflow. + * and INT64_MIN on underflow. */ int qemu_strtoi64(const char *nptr, const char **endptr, int base, int64_t *result) @@ -557,8 +557,9 @@ int qemu_strtoi64(const char *nptr, const char **endptr, int base, return -EINVAL; } + /* This assumes int64_t is long long TODO relax */ + QEMU_BUILD_BUG_ON(sizeof(int64_t) != sizeof(long long)); errno = 0; - /* FIXME This assumes int64_t is long long */ *result = strtoll(nptr, &ep, base); return check_strtox_error(nptr, ep, endptr, errno); } @@ -581,8 +582,9 @@ int qemu_strtou64(const char *nptr, const char **endptr, int base, return -EINVAL; } + /* This assumes uint64_t is unsigned long long TODO relax */ + QEMU_BUILD_BUG_ON(sizeof(uint64_t) != sizeof(unsigned long long)); errno = 0; - /* FIXME This assumes uint64_t is unsigned long long */ *result = strtoull(nptr, &ep, base); /* Windows returns 1 for negative out-of-range values. */ if (errno == ERANGE) { diff --git a/util/error.c b/util/error.c index d4532ce318..b6c89d1412 100644 --- a/util/error.c +++ b/util/error.c @@ -121,7 +121,7 @@ void error_setg_file_open_internal(Error **errp, "Could not open '%s'", filename); } -void error_vprepend(Error **errp, const char *fmt, va_list ap) +void error_vprepend(Error *const *errp, const char *fmt, va_list ap) { GString *newmsg; @@ -136,7 +136,7 @@ void error_vprepend(Error **errp, const char *fmt, va_list ap) (*errp)->msg = g_string_free(newmsg, 0); } -void error_prepend(Error **errp, const char *fmt, ...) +void error_prepend(Error *const *errp, const char *fmt, ...) { va_list ap; @@ -145,7 +145,7 @@ void error_prepend(Error **errp, const char *fmt, ...) va_end(ap); } -void error_append_hint(Error **errp, const char *fmt, ...) +void error_append_hint(Error *const *errp, const char *fmt, ...) { va_list ap; int saved_errno = errno; diff --git a/util/log.c b/util/log.c index 1ca13059ee..867264da8d 100644 --- a/util/log.c +++ b/util/log.c @@ -24,9 +24,11 @@ #include "qapi/error.h" #include "qemu/cutils.h" #include "trace/control.h" +#include "qemu/thread.h" static char *logfilename; -FILE *qemu_logfile; +static QemuMutex qemu_logfile_mutex; +QemuLogFile *qemu_logfile; int qemu_loglevel; static int log_append = 0; static GArray *debug_regions; @@ -35,10 +37,14 @@ static GArray *debug_regions; int qemu_log(const char *fmt, ...) { int ret = 0; - if (qemu_logfile) { + QemuLogFile *logfile; + + rcu_read_lock(); + logfile = atomic_rcu_read(&qemu_logfile); + if (logfile) { va_list ap; va_start(ap, fmt); - ret = vfprintf(qemu_logfile, fmt, ap); + ret = vfprintf(logfile->fd, fmt, ap); va_end(ap); /* Don't pass back error results. */ @@ -46,57 +52,91 @@ int qemu_log(const char *fmt, ...) ret = 0; } } + rcu_read_unlock(); return ret; } +static void __attribute__((__constructor__)) qemu_logfile_init(void) +{ + qemu_mutex_init(&qemu_logfile_mutex); +} + +static void qemu_logfile_free(QemuLogFile *logfile) +{ + g_assert(logfile); + + if (logfile->fd != stderr) { + fclose(logfile->fd); + } + g_free(logfile); +} + static bool log_uses_own_buffers; /* enable or disable low levels log */ void qemu_set_log(int log_flags) { + bool need_to_open_file = false; + QemuLogFile *logfile; + qemu_loglevel = log_flags; #ifdef CONFIG_TRACE_LOG qemu_loglevel |= LOG_TRACE; #endif - if (!qemu_logfile && - (is_daemonized() ? logfilename != NULL : qemu_loglevel)) { + /* + * In all cases we only log if qemu_loglevel is set. + * Also: + * If not daemonized we will always log either to stderr + * or to a file (if there is a logfilename). + * If we are daemonized, + * we will only log if there is a logfilename. + */ + if (qemu_loglevel && (!is_daemonized() || logfilename)) { + need_to_open_file = true; + } + qemu_mutex_lock(&qemu_logfile_mutex); + if (qemu_logfile && !need_to_open_file) { + logfile = qemu_logfile; + atomic_rcu_set(&qemu_logfile, NULL); + call_rcu(logfile, qemu_logfile_free, rcu); + } else if (!qemu_logfile && need_to_open_file) { + logfile = g_new0(QemuLogFile, 1); if (logfilename) { - qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); - if (!qemu_logfile) { + logfile->fd = fopen(logfilename, log_append ? "a" : "w"); + if (!logfile->fd) { + g_free(logfile); perror(logfilename); _exit(1); } /* In case we are a daemon redirect stderr to logfile */ if (is_daemonized()) { - dup2(fileno(qemu_logfile), STDERR_FILENO); - fclose(qemu_logfile); + dup2(fileno(logfile->fd), STDERR_FILENO); + fclose(logfile->fd); /* This will skip closing logfile in qemu_log_close() */ - qemu_logfile = stderr; + logfile->fd = stderr; } } else { /* Default to stderr if no log file specified */ assert(!is_daemonized()); - qemu_logfile = stderr; + logfile->fd = stderr; } /* must avoid mmap() usage of glibc by setting a buffer "by hand" */ if (log_uses_own_buffers) { static char logfile_buf[4096]; - setvbuf(qemu_logfile, logfile_buf, _IOLBF, sizeof(logfile_buf)); + setvbuf(logfile->fd, logfile_buf, _IOLBF, sizeof(logfile_buf)); } else { #if defined(_WIN32) /* Win32 doesn't support line-buffering, so use unbuffered output. */ - setvbuf(qemu_logfile, NULL, _IONBF, 0); + setvbuf(logfile->fd, NULL, _IONBF, 0); #else - setvbuf(qemu_logfile, NULL, _IOLBF, 0); + setvbuf(logfile->fd, NULL, _IOLBF, 0); #endif log_append = 1; } + atomic_rcu_set(&qemu_logfile, logfile); } - if (qemu_logfile && - (is_daemonized() ? logfilename == NULL : !qemu_loglevel)) { - qemu_log_close(); - } + qemu_mutex_unlock(&qemu_logfile_mutex); } void qemu_log_needs_buffers(void) @@ -113,6 +153,7 @@ void qemu_set_log_filename(const char *filename, Error **errp) { char *pidstr; g_free(logfilename); + logfilename = NULL; pidstr = strstr(filename, "%"); if (pidstr) { @@ -224,18 +265,29 @@ out: /* fflush() the log file */ void qemu_log_flush(void) { - fflush(qemu_logfile); + QemuLogFile *logfile; + + rcu_read_lock(); + logfile = atomic_rcu_read(&qemu_logfile); + if (logfile) { + fflush(logfile->fd); + } + rcu_read_unlock(); } /* Close the log file */ void qemu_log_close(void) { - if (qemu_logfile) { - if (qemu_logfile != stderr) { - fclose(qemu_logfile); - } - qemu_logfile = NULL; + QemuLogFile *logfile; + + qemu_mutex_lock(&qemu_logfile_mutex); + logfile = qemu_logfile; + + if (logfile) { + atomic_rcu_set(&qemu_logfile, NULL); + call_rcu(logfile, qemu_logfile_free, rcu); } + qemu_mutex_unlock(&qemu_logfile_mutex); } const QEMULogItem qemu_log_items[] = { diff --git a/util/qemu-error.c b/util/qemu-error.c index f373f3b3b0..dac7c7dc50 100644 --- a/util/qemu-error.c +++ b/util/qemu-error.c @@ -24,6 +24,9 @@ typedef enum { REPORT_TYPE_INFO, } report_type; +/* Prepend timestamp to messages */ +bool error_with_timestamp; + int error_printf(const char *fmt, ...) { va_list ap; @@ -191,7 +194,6 @@ static void print_loc(void) } } -bool enable_timestamp_msg; /* * Print a message to current monitor if we have one, else to stderr. * @report_type is the type of message: error, warning or informational. @@ -204,7 +206,7 @@ static void vreport(report_type type, const char *fmt, va_list ap) GTimeVal tv; gchar *timestr; - if (enable_timestamp_msg && !cur_mon) { + if (error_with_timestamp && !cur_mon) { g_get_current_time(&tv); timestr = g_time_val_to_iso8601(&tv); error_printf("%s ", timestr); diff --git a/util/qsp.c b/util/qsp.c index 62265417fd..7d5147f1b2 100644 --- a/util/qsp.c +++ b/util/qsp.c @@ -598,7 +598,6 @@ static void qsp_ht_delete(void *p, uint32_t h, void *htp) static void qsp_mktree(GTree *tree, bool callsite_coalesce) { - QSPSnapshot *snap; struct qht ht, coalesce_ht; struct qht *htp; @@ -610,20 +609,19 @@ static void qsp_mktree(GTree *tree, bool callsite_coalesce) * We must remain in an RCU read-side critical section until we're done * with the snapshot. */ - rcu_read_lock(); - snap = atomic_rcu_read(&qsp_snapshot); + WITH_RCU_READ_LOCK_GUARD() { + QSPSnapshot *snap = atomic_rcu_read(&qsp_snapshot); - /* Aggregate all results from the global hash table into a local one */ - qht_init(&ht, qsp_entry_no_thread_cmp, QSP_INITIAL_SIZE, - QHT_MODE_AUTO_RESIZE | QHT_MODE_RAW_MUTEXES); - qht_iter(&qsp_ht, qsp_aggregate, &ht); + /* Aggregate all results from the global hash table into a local one */ + qht_init(&ht, qsp_entry_no_thread_cmp, QSP_INITIAL_SIZE, + QHT_MODE_AUTO_RESIZE | QHT_MODE_RAW_MUTEXES); + qht_iter(&qsp_ht, qsp_aggregate, &ht); - /* compute the difference wrt the snapshot, if any */ - if (snap) { - qsp_diff(&snap->ht, &ht); + /* compute the difference wrt the snapshot, if any */ + if (snap) { + qsp_diff(&snap->ht, &ht); + } } - /* done with the snapshot; RCU can reclaim it */ - rcu_read_unlock(); htp = &ht; if (callsite_coalesce) { diff --git a/vl.c b/vl.c index 94508300c3..86474a55c9 100644 --- a/vl.c +++ b/vl.c @@ -292,19 +292,13 @@ static QemuOptsList qemu_accel_opts = { .name = "accel", .implied_opt_name = "accel", .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head), - .merge_lists = true, .desc = { - { - .name = "accel", - .type = QEMU_OPT_STRING, - .help = "Select the type of accelerator", - }, - { - .name = "thread", - .type = QEMU_OPT_STRING, - .help = "Enable/disable multi-threaded TCG", - }, - { /* end of list */ } + /* + * no elements => accept any + * sanity checking will happen later + * when setting accelerator properties + */ + { } }, }; @@ -896,13 +890,9 @@ static void configure_rtc(QemuOpts *opts) value = qemu_opt_get(opts, "driftfix"); if (value) { if (!strcmp(value, "slew")) { - static GlobalProperty slew_lost_ticks = { - .driver = "mc146818rtc", - .property = "lost_tick_policy", - .value = "slew", - }; - - qdev_prop_register_global(&slew_lost_ticks); + object_register_sugar_prop("mc146818rtc", + "lost_tick_policy", + "slew"); } else if (!strcmp(value, "none")) { /* discard is default */ } else { @@ -1139,17 +1129,10 @@ static void realtime_init(void) static void configure_msg(QemuOpts *opts) { - enable_timestamp_msg = qemu_opt_get_bool(opts, "timestamp", true); + error_with_timestamp = qemu_opt_get_bool(opts, "timestamp", false); } -/* Now we still need this for compatibility with XEN. */ -bool has_igd_gfx_passthru; -static void igd_gfx_passthru(void) -{ - has_igd_gfx_passthru = current_machine->igd_gfx_passthru; -} - /***********************************************************/ /* USB devices */ @@ -2490,27 +2473,17 @@ static MachineClass *select_machine(void) return machine_class; } -static int machine_set_property(void *opaque, - const char *name, const char *value, - Error **errp) +static int object_parse_property_opt(Object *obj, + const char *name, const char *value, + const char *skip, Error **errp) { - Object *obj = OBJECT(opaque); Error *local_err = NULL; - char *p, *qom_name; - if (strcmp(name, "type") == 0) { + if (g_str_equal(name, skip)) { return 0; } - qom_name = g_strdup(name); - for (p = qom_name; *p; p++) { - if (*p == '_') { - *p = '-'; - } - } - - object_property_parse(obj, value, qom_name, &local_err); - g_free(qom_name); + object_property_parse(obj, value, name, &local_err); if (local_err) { error_propagate(errp, local_err); @@ -2520,6 +2493,35 @@ static int machine_set_property(void *opaque, return 0; } +static int machine_set_property(void *opaque, + const char *name, const char *value, + Error **errp) +{ + g_autofree char *qom_name = g_strdup(name); + char *p; + + for (p = qom_name; *p; p++) { + if (*p == '_') { + *p = '-'; + } + } + + /* Legacy options do not correspond to MachineState properties. */ + if (g_str_equal(qom_name, "accel")) { + return 0; + } + if (g_str_equal(qom_name, "igd-passthru")) { + object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value); + return 0; + } + if (g_str_equal(qom_name, "kvm-shadow-mem") || + g_str_equal(qom_name, "kernel-irqchip")) { + object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value); + return 0; + } + + return object_parse_property_opt(opaque, name, value, "type", errp); +} /* * Initial object creation happens before all other @@ -2700,6 +2702,118 @@ static void user_register_global_props(void) global_init_func, NULL, NULL); } +static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp) +{ + configure_icount(opts, errp); + return 0; +} + +static int accelerator_set_property(void *opaque, + const char *name, const char *value, + Error **errp) +{ + return object_parse_property_opt(opaque, name, value, "accel", errp); +} + +static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp) +{ + bool *p_init_failed = opaque; + const char *acc = qemu_opt_get(opts, "accel"); + AccelClass *ac = accel_find(acc); + AccelState *accel; + int ret; + + if (!ac) { + *p_init_failed = true; + error_report("invalid accelerator %s", acc); + return 0; + } + accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac))); + object_apply_compat_props(OBJECT(accel)); + qemu_opt_foreach(opts, accelerator_set_property, + accel, + &error_fatal); + + ret = accel_init_machine(accel, current_machine); + if (ret < 0) { + *p_init_failed = true; + error_report("failed to initialize %s: %s", + acc, strerror(-ret)); + return 0; + } + + return 1; +} + +static void configure_accelerators(const char *progname) +{ + const char *accel; + char **accel_list, **tmp; + bool accel_initialised = false; + bool init_failed = false; + + qemu_opts_foreach(qemu_find_opts("icount"), + do_configure_icount, NULL, &error_fatal); + + accel = qemu_opt_get(qemu_get_machine_opts(), "accel"); + if (QTAILQ_EMPTY(&qemu_accel_opts.head)) { + if (accel == NULL) { + /* Select the default accelerator */ + if (!accel_find("tcg") && !accel_find("kvm")) { + error_report("No accelerator selected and" + " no default accelerator available"); + exit(1); + } else { + int pnlen = strlen(progname); + if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) { + /* If the program name ends with "kvm", we prefer KVM */ + accel = "kvm:tcg"; + } else { + accel = "tcg:kvm"; + } + } + } + + accel_list = g_strsplit(accel, ":", 0); + + for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) { + /* + * Filter invalid accelerators here, to prevent obscenities + * such as "-machine accel=tcg,,thread=single". + */ + if (accel_find(*tmp)) { + qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp, true); + } else { + init_failed = true; + error_report("invalid accelerator %s", *tmp); + } + } + } else { + if (accel != NULL) { + error_report("The -accel and \"-machine accel=\" options are incompatible"); + exit(1); + } + } + + if (!qemu_opts_foreach(qemu_find_opts("accel"), + do_configure_accelerator, &init_failed, &error_fatal)) { + if (!init_failed) { + error_report("no accelerator found"); + } + exit(1); + } + + if (init_failed) { + AccelClass *ac = ACCEL_GET_CLASS(current_machine->accelerator); + error_report("falling back to %s", ac->name); + } + + if (use_icount && !(tcg_enabled() || qtest_enabled())) { + error_report("-icount is not allowed with hardware virtualization"); + exit(1); + } +} + int main(int argc, char **argv, char **envp) { int i; @@ -3374,9 +3488,6 @@ int main(int argc, char **argv, char **envp) "use -M accel=... for now instead"); exit(1); } - opts = qemu_opts_create(qemu_find_opts("machine"), NULL, - false, &error_abort); - qemu_opt_set(opts, "accel", optarg, &error_abort); break; case QEMU_OPTION_usb: olist = qemu_find_opts("machine"); @@ -3483,10 +3594,8 @@ int main(int argc, char **argv, char **envp) error_report("TCG is disabled"); exit(1); #endif - if (qemu_strtoul(optarg, NULL, 0, &tcg_tb_size) < 0) { - error_report("Invalid argument to -tb-size"); - exit(1); - } + warn_report("The -tb-size option is deprecated, use -accel tcg,tb-size instead"); + object_register_sugar_prop(ACCEL_CLASS_NAME("tcg"), "tb-size", optarg); break; case QEMU_OPTION_icount: icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"), @@ -3731,8 +3840,7 @@ int main(int argc, char **argv, char **envp) cleanup_add_fd, NULL, &error_fatal); #endif - current_machine = MACHINE(object_new(object_class_get_name( - OBJECT_CLASS(machine_class)))); + current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class))); if (machine_help_func(qemu_get_machine_opts(), current_machine)) { exit(0); } @@ -4010,7 +4118,7 @@ int main(int argc, char **argv, char **envp) * Note: uses machine properties such as kernel-irqchip, must run * after machine_set_property(). */ - configure_accelerator(current_machine, argv[0]); + configure_accelerators(argv[0]); /* * Beware, QOM objects created before this point miss global and @@ -4095,18 +4203,6 @@ int main(int argc, char **argv, char **envp) qemu_spice_init(); cpu_ticks_init(); - if (icount_opts) { - if (!tcg_enabled()) { - error_report("-icount is not allowed with hardware virtualization"); - exit(1); - } - configure_icount(icount_opts, &error_abort); - qemu_opts_del(icount_opts); - } - - if (tcg_enabled()) { - qemu_tcg_configure(accel_opts, &error_fatal); - } if (default_net) { QemuOptsList *net = qemu_find_opts("net"); @@ -4203,9 +4299,6 @@ int main(int argc, char **argv, char **envp) exit(1); } - /* Check if IGD GFX passthrough. */ - igd_gfx_passthru(); - /* init generic devices */ rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); qemu_opts_foreach(qemu_find_opts("device"),