
* Run docker probe only if docker or podman are available The docker probe uses "sudo -n" which can cause an e-mail with a security warning each time when configure is run. Therefore run docker probe only if either docker or podman are available. That avoids the problematic "sudo -n" on build environments which have neither docker nor podman installed. Fixes: c4575b59155e2e00 ("configure: store container engine in config-host.mak") Signed-off-by: Stefan Weil <sw@weilnetz.de> Message-Id: <20221030083510.310584-1-sw@weilnetz.de> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-Id: <20221117172532.538149-2-alex.bennee@linaro.org> * tests/avocado/machine_aspeed.py: Reduce noise on the console for SDK tests The Aspeed SDK images are based on OpenBMC which starts a lot of services. The output noise on the console can break from time to time the test waiting for the logging prompt. Change the U-Boot bootargs variable to add "quiet" to the kernel command line and reduce the output volume. This also drops the test on the CPU id which was nice to have but not essential. Signed-off-by: Cédric Le Goater <clg@kaod.org> Message-Id: <20221104075347.370503-1-clg@kaod.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20221117172532.538149-3-alex.bennee@linaro.org> * tests/docker: allow user to override check target This is useful when trying to bisect a particular failing test behind a docker run. For example: make docker-test-clang@fedora \ TARGET_LIST=arm-softmmu \ TEST_COMMAND="meson test qtest-arm/qos-test" \ J=9 V=1 Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221117172532.538149-4-alex.bennee@linaro.org> * docs/devel: add a maintainers section to development process We don't currently have a clear place in the documentation to describe the roles and responsibilities of a maintainer. Lets create one so we can. I've moved a few small bits out of other files to try and keep everything in one place. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221117172532.538149-5-alex.bennee@linaro.org> * docs/devel: make language a little less code centric We welcome all sorts of patches. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221117172532.538149-6-alex.bennee@linaro.org> * docs/devel: simplify the minimal checklist The bullet points are quite long and contain process tips. Move those bits of the bullet to the relevant sections and link to them. Use a table for nicer formatting of the checklist. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221117172532.538149-7-alex.bennee@linaro.org> * docs/devel: try and improve the language around patch review It is important that contributors take the review process seriously and we collaborate in a respectful way while avoiding personal attacks. Try and make this clear in the language. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221117172532.538149-8-alex.bennee@linaro.org> * tests/avocado: Raise timeout for boot_linux.py:BootLinuxPPC64.test_pseries_tcg On my machine, a debug build of QEMU takes about 260 seconds to complete this test, so with the current timeout value of 180 seconds it always times out. Double the timeout value to 360 so the test definitely has enough time to complete. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20221110142901.3832318-1-peter.maydell@linaro.org> Message-Id: <20221117172532.538149-9-alex.bennee@linaro.org> * tests/avocado: introduce alpine virt test for CI The boot_linux tests download and run a full cloud image boot and start a full distro. While the ability to test the full boot chain is worthwhile it is perhaps a little too heavy weight and causes issues in CI. Fix this by introducing a new alpine linux ISO boot in machine_aarch64_virt. This boots a fully loaded -cpu max with all the bells and whistles in 31s on my machine. A full debug build takes around 180s on my machine so we set a more generous timeout to cover that. We don't add a test for lesser GIC versions although there is some coverage for that already in the boot_xen.py tests. If we want to introduce more comprehensive testing we can do it with a custom kernel and initrd rather than a full distro boot. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221117172532.538149-10-alex.bennee@linaro.org> * tests/avocado: skip aarch64 cloud TCG tests in CI We now have a much lighter weight test in machine_aarch64_virt which tests the full boot chain in less time. Rename the tests while we are at it to make it clear it is a Fedora cloud image. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221117172532.538149-11-alex.bennee@linaro.org> * gitlab: integrate coverage report This should hopefully give is nice coverage information about what our tests (or at least the subset we are running) have hit. Ideally we would want a way to trigger coverage on tests likely to be affected by the current commit. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Acked-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221117172532.538149-12-alex.bennee@linaro.org> * vhost: mask VIRTIO_F_RING_RESET for vhost and vhost-user devices Commit 69e1c14aa2 ("virtio: core: vq reset feature negotation support") enabled VIRTIO_F_RING_RESET by default for all virtio devices. This feature is not currently emulated by QEMU, so for vhost and vhost-user devices we need to make sure it is supported by the offloaded device emulation (in-kernel or in another process). To do this we need to add VIRTIO_F_RING_RESET to the features bitmap passed to vhost_get_features(). This way it will be masked if the device does not support it. This issue was initially discovered with vhost-vsock and vhost-user-vsock, and then also tested with vhost-user-rng which confirmed the same issue. They fail when sending features through VHOST_SET_FEATURES ioctl or VHOST_USER_SET_FEATURES message, since VIRTIO_F_RING_RESET is negotiated by the guest (Linux >= v6.0), but not supported by the device. Fixes: 69e1c14aa2 ("virtio: core: vq reset feature negotation support") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1318 Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Message-Id: <20221121101101.29400-1-sgarzare@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Acked-by: Raphael Norwitz <raphael.norwitz@nutanix.com> Acked-by: Jason Wang <jasowang@redhat.com> * tests: acpi: whitelist DSDT before moving PRQx to _SB scope Signed-off-by: Igor Mammedov <imammedo@redhat.com> Message-Id: <20221121153613.3972225-2-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> * acpi: x86: move RPQx field back to _SB scope Commit 47a373faa6b2 (acpi: pc/q35: drop ad-hoc PCI-ISA bridge AML routines and let bus ennumeration generate AML) moved ISA bridge AML generation to respective devices and was using aml_alias() to provide PRQx fields in _SB. scope. However, it turned out that SeaBIOS was not able to process Alias opcode when parsing DSDT, resulting in lack of keyboard during boot (SeaBIOS console, grub, FreeDOS). While fix for SeaBIOS is posted https://mail.coreboot.org/hyperkitty/list/seabios@seabios.org/thread/RGPL7HESH5U5JRLEO6FP77CZVHZK5J65/ fixed SeaBIOS might not make into QEMU-7.2 in time. Hence this workaround that puts PRQx back into _SB scope and gets rid of aliases in ISA bridge description, so DSDT will be parsable by broken SeaBIOS. That brings back hardcoded references to ISA bridge PCI0.S08.P40C/PCI0.SF8.PIRQ where middle part now is auto generated based on slot it's plugged in, but it should be fine as bridge initialization also hardcodes PCI address of the bridge so it can't ever move. Once QEMU tree has fixed SeaBIOS blob, we should be able to drop this part and revert back to alias based approach Reported-by: Volker Rümelin <vr_qemu@t-online.de> Signed-off-by: Igor Mammedov <imammedo@redhat.com> Message-Id: <20221121153613.3972225-3-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> * tests: acpi: x86: update expected DSDT after moving PRQx fields in _SB scope Expected DSDT changes, pc: - Field (P40C, ByteAcc, NoLock, Preserve) + Scope (\_SB) { - PRQ0, 8, - PRQ1, 8, - PRQ2, 8, - PRQ3, 8 + Field (PCI0.S08.P40C, ByteAcc, NoLock, Preserve) + { + PRQ0, 8, + PRQ1, 8, + PRQ2, 8, + PRQ3, 8 + } } - Alias (PRQ0, \_SB.PRQ0) - Alias (PRQ1, \_SB.PRQ1) - Alias (PRQ2, \_SB.PRQ2) - Alias (PRQ3, \_SB.PRQ3) q35: - Field (PIRQ, ByteAcc, NoLock, Preserve) - { - PRQA, 8, - PRQB, 8, - PRQC, 8, - PRQD, 8, - Offset (0x08), - PRQE, 8, - PRQF, 8, - PRQG, 8, - PRQH, 8 + Scope (\_SB) + { + Field (PCI0.SF8.PIRQ, ByteAcc, NoLock, Preserve) + { + PRQA, 8, + PRQB, 8, + PRQC, 8, + PRQD, 8, + Offset (0x08), + PRQE, 8, + PRQF, 8, + PRQG, 8, + PRQH, 8 + } } - Alias (PRQA, \_SB.PRQA) - Alias (PRQB, \_SB.PRQB) - Alias (PRQC, \_SB.PRQC) - Alias (PRQD, \_SB.PRQD) - Alias (PRQE, \_SB.PRQE) - Alias (PRQF, \_SB.PRQF) - Alias (PRQG, \_SB.PRQG) - Alias (PRQH, \_SB.PRQH) Signed-off-by: Igor Mammedov <imammedo@redhat.com> Message-Id: <20221121153613.3972225-4-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> * MAINTAINERS: add mst to list of biosbits maintainers Adding Michael's name to the list of bios bits maintainers so that all changes and fixes into biosbits framework can go through his tree and he is notified. Suggested-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Ani Sinha <ani@anisinha.ca> Message-Id: <20221111151138.36988-1-ani@anisinha.ca> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> * tests/avocado: configure acpi-bits to use avocado timeout Instead of using a hardcoded timeout, just rely on Avocado's built-in test case timeout. This helps avoid timeout issues on machines where 60 seconds is not sufficient. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20221115212759.3095751-1-jsnow@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Ani Sinha <ani@anisinha.ca> * acpi/tests/avocado/bits: keep the work directory when BITS_DEBUG is set in env Debugging bits issue often involves running the QEMU command line manually outside of the avocado environment with the generated ISO. Hence, its inconvenient if the iso gets cleaned up after the test has finished. This change makes sure that the work directory is kept after the test finishes if the test is run with BITS_DEBUG=1 in the environment so that the iso is available for use with the QEMU command line. CC: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Ani Sinha <ani@anisinha.ca> Message-Id: <20221117113630.543495-1-ani@anisinha.ca> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> * virtio: disable error for out of spec queue-enable Virtio 1.0 is pretty clear that features have to be negotiated before enabling VQs. Unfortunately Seabios ignored this ever since gaining 1.0 support (UEFI is ok). Comment the error out for now, and add a TODO. Fixes: 3c37f8b8d1 ("virtio: introduce virtio_queue_enable()") Cc: "Kangjie Xu" <kangjie.xu@linux.alibaba.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20221121200339.362452-1-mst@redhat.com> * hw/loongarch: Add default stdout uart in fdt Add "chosen" subnode into LoongArch fdt, and set it's "stdout-path" prop to uart node. Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> Reviewed-by: Song Gao <gaosong@loongson.cn> Message-Id: <20221115114923.3372414-1-yangxiaojuan@loongson.cn> Signed-off-by: Song Gao <gaosong@loongson.cn> * hw/loongarch: Fix setprop_sized method in fdt rtc node. Fix setprop_sized method in fdt rtc node. Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Song Gao <gaosong@loongson.cn> Message-Id: <20221116040300.3459818-1-yangxiaojuan@loongson.cn> Signed-off-by: Song Gao <gaosong@loongson.cn> * hw/loongarch: Replace the value of uart info with macro Using macro to replace the value of uart info such as addr, size in acpi_build method. Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> Reviewed-by: Song Gao <gaosong@loongson.cn> Message-Id: <20221115115008.3372489-1-yangxiaojuan@loongson.cn> Signed-off-by: Song Gao <gaosong@loongson.cn> * target/arm: Don't do two-stage lookup if stage 2 is disabled In get_phys_addr_with_struct(), we call get_phys_addr_twostage() if the CPU supports EL2. However, we don't check here that stage 2 is actually enabled. Instead we only check that inside get_phys_addr_twostage() to skip stage 2 translation. This means that even if stage 2 is disabled we still tell the stage 1 lookup to do its page table walks via stage 2. This works by luck for normal CPU accesses, but it breaks for debug accesses, which are used by the disassembler and also by semihosting file reads and writes, because the debug case takes a different code path inside S1_ptw_translate(). This means that setups that use semihosting for file loads are broken (a regression since 7.1, introduced in recent ptw refactoring), and that sometimes disassembly in debug logs reports "unable to read memory" rather than showing the guest insns. Fix the bug by hoisting the "is stage 2 enabled?" check up to get_phys_addr_with_struct(), so that we handle S2 disabled the same way we do the "no EL2" case, with a simple single stage lookup. Reported-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 20221121212404.1450382-1-peter.maydell@linaro.org * target/arm: Use signed quantity to represent VMSAv8-64 translation level The LPA2 extension implements 52-bit virtual addressing for 4k and 16k translation granules, and for the former, this means an additional level of translation is needed. This means we start counting at -1 instead of 0 when doing a walk, and so 'level' is now a signed quantity, and should be typed as such. So turn it from uint32_t into int32_t. This avoids a level of -1 getting misinterpreted as being >= 3, and terminating a page table walk prematurely with a bogus output address. Cc: Peter Maydell <peter.maydell@linaro.org> Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> Cc: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org> * Update VERSION for v7.2.0-rc2 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> * tests/avocado: Update the URLs of the advent calendar images The qemu-advent-calendar.org server will be decommissioned soon. I've mirrored the images that we use for the QEMU CI to gitlab, so update their URLs to point to the new location. Message-Id: <20221121102436.78635-1-thuth@redhat.com> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Thomas Huth <thuth@redhat.com> * tests/qtest: Decrease the amount of output from the qom-test The logs in the gitlab-CI have a size constraint, and sometimes we already hit this limit. The biggest part of the log then seems to be filled by the qom-test, so we should decrease the size of the output - which can be done easily by not printing the path for each property, since the path has already been logged at the beginning of each node that we handle here. However, if we omit the path, we should make sure to not recurse into child nodes in between, so that it is clear to which node each property belongs. Thus store the children and links in a temporary list and recurse only at the end of each node, when all properties have already been printed. Message-Id: <20221121194240.149268-1-thuth@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com> * tests/avocado: use new rootfs for orangepi test The old URL wasn't stable. I suspect the current URL will only be stable for a few months so maybe we need another strategy for hosting rootfs snapshots? Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20221118113309.1057790-1-alex.bennee@linaro.org> Signed-off-by: Thomas Huth <thuth@redhat.com> * Revert "usbredir: avoid queuing hello packet on snapshot restore" Run state is also in RUN_STATE_PRELAUNCH while "-S" is used. This reverts commit 0631d4b448454ae8a1ab091c447e3f71ab6e088a Signed-off-by: Joelle van Dyne <j@getutm.app> Reviewed-by: Ján Tomko <jtomko@redhat.com> The original commit broke the usage of usbredir with libvirt, which starts every domain with "-S". This workaround is no longer needed because the usbredir behavior has been fixed in the meantime: https://gitlab.freedesktop.org/spice/usbredir/-/merge_requests/61 Signed-off-by: Ján Tomko <jtomko@redhat.com> Message-Id: <1689cec3eadcea87255e390cb236033aca72e168.1669193161.git.jtomko@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> * gtk: disable GTK Clipboard with a new meson option The GTK Clipboard implementation may cause guest hangs. Therefore implement new configure switch: --enable-gtk-clipboard, as a meson option disabled by default, which warns in the help text about the experimental nature of the feature. Regenerate the meson build options to include it. The initialization of the clipboard is gtk.c, as well as the compilation of gtk-clipboard.c are now conditional on this new option to be set. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1150 Signed-off-by: Claudio Fontana <cfontana@suse.de> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Jim Fehlig <jfehlig@suse.com> Message-Id: <20221121135538.14625-1-cfontana@suse.de> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> * hw/usb/hcd-xhci.c: spelling: tranfer Fixes: effaf5a240e03020f4ae953e10b764622c3e87cc Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Stefan Weil <sw@weilnetz.de> Message-Id: <20221105114851.306206-1-mjt@msgid.tls.msk.ru> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> * ui/gtk: prevent ui lock up when dpy_gl_update called again before current draw event occurs A warning, "qemu: warning: console: no gl-unblock within" followed by guest scanout lockup can happen if dpy_gl_update is called in a row and the second call is made before gd_draw_event scheduled by the first call is taking place. This is because draw call returns without decrementing gl_block ref count if the dmabuf was already submitted as shown below. (gd_gl_area_draw/gd_egl_draw) if (dmabuf) { if (!dmabuf->draw_submitted) { return; } else { dmabuf->draw_submitted = false; } } So it should not schedule any redundant draw event in case draw_submitted is already set in gd_egl_fluch/gd_gl_area_scanout_flush. Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Vivek Kasireddy <vivek.kasireddy@intel.com> Signed-off-by: Dongwon Kim <dongwon.kim@intel.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20221021192315.9110-1-dongwon.kim@intel.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> * hw/usb/hcd-xhci: Reset the XHCIState with device_cold_reset() Currently the hcd-xhci-pci and hcd-xhci-sysbus devices, which are mostly wrappers around the TYPE_XHCI device, which is a direct subclass of TYPE_DEVICE. Since TYPE_DEVICE devices are not on any qbus and do not get automatically reset, the wrapper devices both reset the TYPE_XHCI device in their own reset functions. However, they do this using device_legacy_reset(), which will reset the device itself but not any bus it has. Switch to device_cold_reset(), which avoids using a deprecated function and also propagates reset along any child buses. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Message-Id: <20221014145423.2102706-1-peter.maydell@linaro.org> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> * hw/audio/intel-hda: don't reset codecs twice Currently the intel-hda device has a reset method which manually resets all the codecs by calling device_legacy_reset() on them. This means they get reset twice, once because child devices on a qbus get reset before the parent device's reset method is called, and then again because we're manually resetting them. Drop the manual reset call, and ensure that codecs are still reset when the guest does a reset via ICH6_GCTL_RESET by using device_cold_reset() (which resets all the devices on the qbus as well as the device itself) instead of a direct call to the reset function. This is a slight ordering change because the (only) codec reset now happens before the controller registers etc are reset, rather than once before and then once after, but the codec reset function hda_audio_reset() doesn't care. This lets us drop a use of device_legacy_reset(), which is deprecated. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221014142632.2092404-2-peter.maydell@linaro.org> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> * hw/audio/intel-hda: Drop unnecessary prototype The only use of intel_hda_reset() is after its definition, so we don't need to separately declare its prototype at the top of the file; drop the unnecessary line. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221014142632.2092404-3-peter.maydell@linaro.org> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> * add syx snapshot extras * it compiles! * virtiofsd: Add `sigreturn` to the seccomp whitelist The virtiofsd currently crashes on s390x. This is because of a `sigreturn` system call. See audit log below: type=SECCOMP msg=audit(1669382477.611:459): auid=4294967295 uid=0 gid=0 ses=4294967295 subj=system_u:system_r:virtd_t:s0-s0:c0.c1023 pid=6649 comm="virtiofsd" exe="/usr/libexec/virtiofsd" sig=31 arch=80000016 syscall=119 compat=0 ip=0x3fff15f748a code=0x80000000AUID="unset" UID="root" GID="root" ARCH=s390x SYSCALL=sigreturn Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com> Reviewed-by: German Maglione <gmaglione@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221125143946.27717-1-mhartmay@linux.ibm.com> * libvhost-user: Fix wrong type of argument to formatting function (reported by LGTM) Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Stefan Weil <sw@weilnetz.de> Message-Id: <20220422070144.1043697-2-sw@weilnetz.de> Signed-off-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221126152507.283271-2-sw@weilnetz.de> * libvhost-user: Fix format strings Signed-off-by: Stefan Weil <sw@weilnetz.de> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20220422070144.1043697-3-sw@weilnetz.de> Signed-off-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221126152507.283271-3-sw@weilnetz.de> * libvhost-user: Fix two more format strings This fix is required for 32 bit hosts. The bug was detected by CI for arm-linux, but is also relevant for i386-linux. Reported-by: Stefan Hajnoczi <stefanha@gmail.com> Signed-off-by: Stefan Weil <sw@weilnetz.de> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221126152507.283271-4-sw@weilnetz.de> * libvhost-user: Add format attribute to local function vu_panic Signed-off-by: Stefan Weil <sw@weilnetz.de> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20220422070144.1043697-4-sw@weilnetz.de> Signed-off-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221126152507.283271-5-sw@weilnetz.de> * MAINTAINERS: Add subprojects/libvhost-user to section "vhost" Signed-off-by: Stefan Weil <sw@weilnetz.de> [Michael agreed to act as maintainer for libvhost-user via email in https://lore.kernel.org/qemu-devel/20221123015218-mutt-send-email-mst@kernel.org/. --Stefan] Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221126152507.283271-6-sw@weilnetz.de> * Add G_GNUC_PRINTF to function qemu_set_info_str and fix related issues With the G_GNUC_PRINTF function attribute the compiler detects two potential insecure format strings: ../../../net/stream.c:248:31: warning: format string is not a string literal (potentially insecure) [-Wformat-security] qemu_set_info_str(&s->nc, uri); ^~~ ../../../net/stream.c:322:31: warning: format string is not a string literal (potentially insecure) [-Wformat-security] qemu_set_info_str(&s->nc, uri); ^~~ There are also two other warnings: ../../../net/socket.c:182:35: warning: zero-length gnu_printf format string [-Wformat-zero-length] 182 | qemu_set_info_str(&s->nc, ""); | ^~ ../../../net/stream.c:170:35: warning: zero-length gnu_printf format string [-Wformat-zero-length] 170 | qemu_set_info_str(&s->nc, ""); Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221126152507.283271-7-sw@weilnetz.de> * del ramfile * update seabios source from 1.16.0 to 1.16.1 git shortlog rel-1.16.0..rel-1.16.1 =================================== Gerd Hoffmann (3): malloc: use variable for ZoneHigh size malloc: use large ZoneHigh when there is enough memory virtio-blk: use larger default request size Igor Mammedov (1): acpi: parse Alias object Volker Rümelin (2): pci: refactor the pci_config_*() functions reset: force standard PCI configuration access Xiaofei Lee (1): virtio-blk: Fix incorrect type conversion in virtio_blk_op() Xuan Zhuo (2): virtio-mmio: read/write the hi 32 features for mmio virtio: finalize features before using device Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> * update seabios binaries to 1.16.1 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> * fix for non i386 archs * replay: Fix declaration of replay_read_next_clock Fixes the build with gcc 13: replay/replay-time.c:34:6: error: conflicting types for \ 'replay_read_next_clock' due to enum/integer mismatch; \ have 'void(ReplayClockKind)' [-Werror=enum-int-mismatch] 34 | void replay_read_next_clock(ReplayClockKind kind) | ^~~~~~~~~~~~~~~~~~~~~~ In file included from ../qemu/replay/replay-time.c:14: replay/replay-internal.h:139:6: note: previous declaration of \ 'replay_read_next_clock' with type 'void(unsigned int)' 139 | void replay_read_next_clock(unsigned int kind); | ^~~~~~~~~~~~~~~~~~~~~~ Fixes: 8eda206e090 ("replay: recording and replaying clock ticks") Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Wilfred Mallawa <wilfred.mallawa@wdc.com> Reviewed-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221129010547.284051-1-richard.henderson@linaro.org> * hw/display/qxl: Have qxl_log_command Return early if no log_cmd handler Only 3 command types are logged: no need to call qxl_phys2virt() for the other types. Using different cases will help to pass different structure sizes to qxl_phys2virt() in a pair of commits. Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221128202741.4945-2-philmd@linaro.org> * hw/display/qxl: Document qxl_phys2virt() Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221128202741.4945-3-philmd@linaro.org> * hw/display/qxl: Pass requested buffer size to qxl_phys2virt() Currently qxl_phys2virt() doesn't check for buffer overrun. In order to do so in the next commit, pass the buffer size as argument. For QXLCursor in qxl_render_cursor() -> qxl_cursor() we verify the size of the chunked data ahead, checking we can access 'sizeof(QXLCursor) + chunk->data_size' bytes. Since in the SPICE_CURSOR_TYPE_MONO case the cursor is assumed to fit in one chunk, no change are required. In SPICE_CURSOR_TYPE_ALPHA the ahead read is handled in qxl_unpack_chunks(). Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221128202741.4945-4-philmd@linaro.org> * hw/display/qxl: Avoid buffer overrun in qxl_phys2virt (CVE-2022-4144) Have qxl_get_check_slot_offset() return false if the requested buffer size does not fit within the slot memory region. Similarly qxl_phys2virt() now returns NULL in such case, and qxl_dirty_one_surface() aborts. This avoids buffer overrun in the host pointer returned by memory_region_get_ram_ptr(). Fixes: CVE-2022-4144 (out-of-bounds read) Reported-by: Wenxu Yin (@awxylitol) Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1336 Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221128202741.4945-5-philmd@linaro.org> * hw/display/qxl: Assert memory slot fits in preallocated MemoryRegion Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221128202741.4945-6-philmd@linaro.org> * block-backend: avoid bdrv_unregister_buf() NULL pointer deref bdrv_*() APIs expect a valid BlockDriverState. Calling them with bs=NULL leads to undefined behavior. Jonathan Cameron reported this following NULL pointer dereference when a VM with a virtio-blk device and a memory-backend-file object is terminated: 1. qemu_cleanup() closes all drives, setting blk->root to NULL 2. qemu_cleanup() calls user_creatable_cleanup(), which results in a RAM block notifier callback because the memory-backend-file is destroyed. 3. blk_unregister_buf() is called by virtio-blk's BlockRamRegistrar notifier callback and undefined behavior occurs. Fixes: baf422684d73 ("virtio-blk: use BDRV_REQ_REGISTERED_BUF optimization hint") Co-authored-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221121211923.1993171-1-stefanha@redhat.com> * target/arm: Set TCGCPUOps.restore_state_to_opc for v7m This setting got missed, breaking v7m. Fixes: 56c6c98df85c ("target/arm: Convert to tcg_ops restore_state_to_opc") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1347 Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Evgeny Ermakov <evgeny.v.ermakov@gmail.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221129204146.550394-1-richard.henderson@linaro.org> * Update VERSION for v7.2.0-rc3 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> * hooks are now post mem access * tests/qtests: override "force-legacy" for gpio virtio-mmio tests The GPIO device is a VIRTIO_F_VERSION_1 devices but running with a legacy MMIO interface we miss out that feature bit causing confusion. For the GPIO test force the mmio bus to support non-legacy so we can properly test it. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1333 Message-Id: <20221130112439.2527228-2-alex.bennee@linaro.org> Acked-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> * vhost: enable vrings in vhost_dev_start() for vhost-user devices Commit 02b61f38d3 ("hw/virtio: incorporate backend features in features") properly negotiates VHOST_USER_F_PROTOCOL_FEATURES with the vhost-user backend, but we forgot to enable vrings as specified in docs/interop/vhost-user.rst: If ``VHOST_USER_F_PROTOCOL_FEATURES`` has not been negotiated, the ring starts directly in the enabled state. If ``VHOST_USER_F_PROTOCOL_FEATURES`` has been negotiated, the ring is initialized in a disabled state and is enabled by ``VHOST_USER_SET_VRING_ENABLE`` with parameter 1. Some vhost-user front-ends already did this by calling vhost_ops.vhost_set_vring_enable() directly: - backends/cryptodev-vhost.c - hw/net/virtio-net.c - hw/virtio/vhost-user-gpio.c But most didn't do that, so we would leave the vrings disabled and some backends would not work. We observed this issue with the rust version of virtiofsd [1], which uses the event loop [2] provided by the vhost-user-backend crate where requests are not processed if vring is not enabled. Let's fix this issue by enabling the vrings in vhost_dev_start() for vhost-user front-ends that don't already do this directly. Same thing also in vhost_dev_stop() where we disable vrings. [1] https://gitlab.com/virtio-fs/virtiofsd [2] https://github.com/rust-vmm/vhost/blob/240fc2966/crates/vhost-user-backend/src/event_loop.rs#L217 Fixes: 02b61f38d3 ("hw/virtio: incorporate backend features in features") Reported-by: German Maglione <gmaglione@redhat.com> Tested-by: German Maglione <gmaglione@redhat.com> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Acked-by: Raphael Norwitz <raphael.norwitz@nutanix.com> Message-Id: <20221123131630.52020-1-sgarzare@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20221130112439.2527228-3-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> * hw/virtio: add started_vu status field to vhost-user-gpio As per the fix to vhost-user-blk in f5b22d06fb (vhost: recheck dev state in the vhost_migration_log routine) we really should track the connection and starting separately. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20221130112439.2527228-4-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> * hw/virtio: generalise CHR_EVENT_CLOSED handling ..and use for both virtio-user-blk and virtio-user-gpio. This avoids the circular close by deferring shutdown due to disconnection until a later point. virtio-user-blk already had this mechanism in place so generalise it as a vhost-user helper function and use for both blk and gpio devices. While we are at it we also fix up vhost-user-gpio to re-establish the event handler after close down so we can reconnect later. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com> Message-Id: <20221130112439.2527228-5-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> * include/hw: VM state takes precedence in virtio_device_should_start The VM status should always preempt the device status for these checks. This ensures the device is in the correct state when we suspend the VM prior to migrations. This restores the checks to the order they where in before the refactoring moved things around. While we are at it lets improve our documentation of the various fields involved and document the two functions. Fixes: 9f6bcfd99f (hw/virtio: move vm_running check to virtio_device_started) Fixes: 259d69c00b (hw/virtio: introduce virtio_device_should_start) Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Tested-by: Christian Borntraeger <borntraeger@linux.ibm.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Message-Id: <20221130112439.2527228-6-alex.bennee@linaro.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> * hw/nvme: fix aio cancel in format There are several bugs in the async cancel code for the Format command. Firstly, cancelling a format operation neglects to set iocb->ret as well as clearing the iocb->aiocb after cancelling the underlying aiocb which causes the aio callback to ignore the cancellation. Trivial fix. Secondly, and worse, because the request is queued up for posting to the CQ in a bottom half, if the cancellation is due to the submission queue being deleted (which calls blk_aio_cancel), the req structure is deallocated in nvme_del_sq prior to the bottom half being schedulued. Fix this by simply removing the bottom half, there is no reason to defer it anyway. Fixes: 3bcf26d3d619 ("hw/nvme: reimplement format nvm to allow cancellation") Reported-by: Jonathan Derrick <jonathan.derrick@linux.dev> Reviewed-by: Keith Busch <kbusch@kernel.org> Signed-off-by: Klaus Jensen <k.jensen@samsung.com> * hw/nvme: fix aio cancel in flush Make sure that iocb->aiocb is NULL'ed when cancelling. Fix a potential use-after-free by removing the bottom half and enqueuing the completion directly. Fixes: 38f4ac65ac88 ("hw/nvme: reimplement flush to allow cancellation") Reviewed-by: Keith Busch <kbusch@kernel.org> Signed-off-by: Klaus Jensen <k.jensen@samsung.com> * hw/nvme: fix aio cancel in zone reset If the zone reset operation is cancelled but the block unmap operation completes normally, the callback will continue resetting the next zone since it neglects to check iocb->ret which will have been set to -ECANCELED. Make sure that this is checked and bail out if an error is present. Secondly, fix a potential use-after-free by removing the bottom half and enqueuing the completion directly. Fixes: 63d96e4ffd71 ("hw/nvme: reimplement zone reset to allow cancellation") Reviewed-by: Keith Busch <kbusch@kernel.org> Signed-off-by: Klaus Jensen <k.jensen@samsung.com> * hw/nvme: fix aio cancel in dsm When the DSM operation is cancelled asynchronously, we set iocb->ret to -ECANCELED. However, the callback function only checks the return value of the completed aio, which may have completed succesfully prior to the cancellation and thus the callback ends up continuing the dsm operation instead of bailing out. Fix this. Secondly, fix a potential use-after-free by removing the bottom half and enqueuing the completion directly. Fixes: d7d1474fd85d ("hw/nvme: reimplement dsm to allow cancellation") Reviewed-by: Keith Busch <kbusch@kernel.org> Signed-off-by: Klaus Jensen <k.jensen@samsung.com> * hw/nvme: remove copy bh scheduling Fix a potential use-after-free by removing the bottom half and enqueuing the completion directly. Fixes: 796d20681d9b ("hw/nvme: reimplement the copy command to allow aio cancellation") Reviewed-by: Keith Busch <kbusch@kernel.org> Signed-off-by: Klaus Jensen <k.jensen@samsung.com> * target/i386: allow MMX instructions with CR4.OSFXSR=0 MMX state is saved/restored by FSAVE/FRSTOR so the instructions are not illegal opcodes even if CR4.OSFXSR=0. Make sure that validate_vex takes into account the prefix and only checks HF_OSFXSR_MASK in the presence of an SSE instruction. Fixes: 20581aadec5e ("target/i386: validate VEX prefixes via the instructions' exception classes", 2022-10-18) Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1350 Reported-by: Helge Konetzka (@hejko on gitlab.com) Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> * target/i386: Always completely initialize TranslateFault In get_physical_address, the canonical address check failed to set TranslateFault.stage2, which resulted in an uninitialized read from the struct when reporting the fault in x86_cpu_tlb_fill. Adjust all error paths to use structure assignment so that the entire struct is always initialized. Reported-by: Daniel Hoffman <dhoff749@gmail.com> Fixes: 9bbcf372193a ("target/i386: Reorg GET_HPHYS") Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20221201074522.178498-1-richard.henderson@linaro.org> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1324 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> * hw/loongarch/virt: Add cfi01 pflash device Add cfi01 pflash device for LoongArch virt machine Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20221130100647.398565-1-yangxiaojuan@loongson.cn> Signed-off-by: Song Gao <gaosong@loongson.cn> * Sync pc on breakpoints * tests/qtest/migration-test: Fix unlink error and memory leaks When running the migration test compiled with Clang from Fedora 37 and sanitizers enabled, there is an error complaining about unlink(): ../tests/qtest/migration-test.c:1072:12: runtime error: null pointer passed as argument 1, which is declared to never be null /usr/include/unistd.h:858:48: note: nonnull attribute specified here SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../tests/qtest/migration-test.c:1072:12 in (test program exited with status code 1) TAP parsing error: Too few tests run (expected 33, got 20) The data->clientcert and data->clientkey pointers can indeed be unset in some tests, so we have to check them before calling unlink() with those. While we're at it, I also noticed that the code is only freeing some but not all of the allocated strings in this function, and indeed, valgrind is also complaining about memory leaks here. So let's call g_free() on all allocated strings to avoid leaking memory here. Message-Id: <20221125083054.117504-1-thuth@redhat.com> Tested-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com> * target/s390x/tcg: Fix and improve the SACF instruction The SET ADDRESS SPACE CONTROL FAST instruction is not privileged, it can be used from problem space, too. Just the switching to the home address space is privileged and should still generate a privilege exception. This bug is e.g. causing programs like Java that use the "getcpu" vdso kernel function to crash (see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=990417#26 ). While we're at it, also check if DAT is not enabled. In that case the instruction is supposed to generate a special operation exception. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/655 Message-Id: <20221201184443.136355-1-thuth@redhat.com> Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Thomas Huth <thuth@redhat.com> * hw/display/next-fb: Fix comment typo Signed-off-by: Evgeny Ermakov <evgeny.v.ermakov@gmail.com> Message-Id: <20221125160849.23711-1-evgeny.v.ermakov@gmail.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Thomas Huth <thuth@redhat.com> * fix dev snapshots * working syx snaps * Revert "hw/loongarch/virt: Add cfi01 pflash device" This reverts commit 14dccc8ea6ece7ee63273144fb55e4770a05e0fd. Signed-off-by: Song Gao <gaosong@loongson.cn> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20221205113007.683505-1-gaosong@loongson.cn> * Update VERSION for v7.2.0-rc4 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Cédric Le Goater <clg@kaod.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Igor Mammedov <imammedo@redhat.com> Signed-off-by: Ani Sinha <ani@anisinha.ca> Signed-off-by: John Snow <jsnow@redhat.com> Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> Signed-off-by: Song Gao <gaosong@loongson.cn> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Claudio Fontana <cfontana@suse.de> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Dongwon Kim <dongwon.kim@intel.com> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Evgeny Ermakov <evgeny.v.ermakov@gmail.com> Signed-off-by: Klaus Jensen <k.jensen@samsung.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Co-authored-by: Stefan Weil <sw@weilnetz.de> Co-authored-by: Cédric Le Goater <clg@kaod.org> Co-authored-by: Alex Bennée <alex.bennee@linaro.org> Co-authored-by: Peter Maydell <peter.maydell@linaro.org> Co-authored-by: Stefano Garzarella <sgarzare@redhat.com> Co-authored-by: Igor Mammedov <imammedo@redhat.com> Co-authored-by: Ani Sinha <ani@anisinha.ca> Co-authored-by: John Snow <jsnow@redhat.com> Co-authored-by: Michael S. Tsirkin <mst@redhat.com> Co-authored-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> Co-authored-by: Stefan Hajnoczi <stefanha@redhat.com> Co-authored-by: Ard Biesheuvel <ardb@kernel.org> Co-authored-by: Thomas Huth <thuth@redhat.com> Co-authored-by: Joelle van Dyne <j@getutm.app> Co-authored-by: Claudio Fontana <cfontana@suse.de> Co-authored-by: Michael Tokarev <mjt@tls.msk.ru> Co-authored-by: Dongwon Kim <dongwon.kim@intel.com> Co-authored-by: Marc Hartmayer <mhartmay@linux.ibm.com> Co-authored-by: Stefan Weil via <qemu-devel@nongnu.org> Co-authored-by: Gerd Hoffmann <kraxel@redhat.com> Co-authored-by: Richard Henderson <richard.henderson@linaro.org> Co-authored-by: Philippe Mathieu-Daudé <philmd@linaro.org> Co-authored-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Co-authored-by: Evgeny Ermakov <evgeny.v.ermakov@gmail.com> Co-authored-by: Klaus Jensen <k.jensen@samsung.com> Co-authored-by: Paolo Bonzini <pbonzini@redhat.com> Co-authored-by: Song Gao <gaosong@loongson.cn>
1377 lines
41 KiB
C
1377 lines
41 KiB
C
/*
|
|
* QEMU ARM CPU -- internal functions and types
|
|
*
|
|
* Copyright (c) 2014 Linaro Ltd
|
|
*
|
|
* 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
|
|
* <http://www.gnu.org/licenses/gpl-2.0.html>
|
|
*
|
|
* This header defines functions, types, etc which need to be shared
|
|
* between different source files within target/arm/ but which are
|
|
* private to it and not required by the rest of QEMU.
|
|
*/
|
|
|
|
#ifndef TARGET_ARM_INTERNALS_H
|
|
#define TARGET_ARM_INTERNALS_H
|
|
|
|
#include "hw/registerfields.h"
|
|
#include "tcg/tcg-gvec-desc.h"
|
|
#include "syndrome.h"
|
|
|
|
/* register banks for CPU modes */
|
|
#define BANK_USRSYS 0
|
|
#define BANK_SVC 1
|
|
#define BANK_ABT 2
|
|
#define BANK_UND 3
|
|
#define BANK_IRQ 4
|
|
#define BANK_FIQ 5
|
|
#define BANK_HYP 6
|
|
#define BANK_MON 7
|
|
|
|
static inline bool excp_is_internal(int excp)
|
|
{
|
|
/* Return true if this exception number represents a QEMU-internal
|
|
* exception that will not be passed to the guest.
|
|
*/
|
|
return excp == EXCP_INTERRUPT
|
|
|| excp == EXCP_HLT
|
|
|| excp == EXCP_DEBUG
|
|
|| excp == EXCP_HALTED
|
|
|| excp == EXCP_EXCEPTION_EXIT
|
|
|| excp == EXCP_KERNEL_TRAP
|
|
|| excp == EXCP_SEMIHOST;
|
|
}
|
|
|
|
/* Scale factor for generic timers, ie number of ns per tick.
|
|
* This gives a 62.5MHz timer.
|
|
*/
|
|
#define GTIMER_SCALE 16
|
|
|
|
/* Bit definitions for the v7M CONTROL register */
|
|
FIELD(V7M_CONTROL, NPRIV, 0, 1)
|
|
FIELD(V7M_CONTROL, SPSEL, 1, 1)
|
|
FIELD(V7M_CONTROL, FPCA, 2, 1)
|
|
FIELD(V7M_CONTROL, SFPA, 3, 1)
|
|
|
|
/* Bit definitions for v7M exception return payload */
|
|
FIELD(V7M_EXCRET, ES, 0, 1)
|
|
FIELD(V7M_EXCRET, RES0, 1, 1)
|
|
FIELD(V7M_EXCRET, SPSEL, 2, 1)
|
|
FIELD(V7M_EXCRET, MODE, 3, 1)
|
|
FIELD(V7M_EXCRET, FTYPE, 4, 1)
|
|
FIELD(V7M_EXCRET, DCRS, 5, 1)
|
|
FIELD(V7M_EXCRET, S, 6, 1)
|
|
FIELD(V7M_EXCRET, RES1, 7, 25) /* including the must-be-1 prefix */
|
|
|
|
/* Minimum value which is a magic number for exception return */
|
|
#define EXC_RETURN_MIN_MAGIC 0xff000000
|
|
/* Minimum number which is a magic number for function or exception return
|
|
* when using v8M security extension
|
|
*/
|
|
#define FNC_RETURN_MIN_MAGIC 0xfefffffe
|
|
|
|
/* Bit definitions for DBGWCRn and DBGWCRn_EL1 */
|
|
FIELD(DBGWCR, E, 0, 1)
|
|
FIELD(DBGWCR, PAC, 1, 2)
|
|
FIELD(DBGWCR, LSC, 3, 2)
|
|
FIELD(DBGWCR, BAS, 5, 8)
|
|
FIELD(DBGWCR, HMC, 13, 1)
|
|
FIELD(DBGWCR, SSC, 14, 2)
|
|
FIELD(DBGWCR, LBN, 16, 4)
|
|
FIELD(DBGWCR, WT, 20, 1)
|
|
FIELD(DBGWCR, MASK, 24, 5)
|
|
FIELD(DBGWCR, SSCE, 29, 1)
|
|
|
|
/* We use a few fake FSR values for internal purposes in M profile.
|
|
* M profile cores don't have A/R format FSRs, but currently our
|
|
* get_phys_addr() code assumes A/R profile and reports failures via
|
|
* an A/R format FSR value. We then translate that into the proper
|
|
* M profile exception and FSR status bit in arm_v7m_cpu_do_interrupt().
|
|
* Mostly the FSR values we use for this are those defined for v7PMSA,
|
|
* since we share some of that codepath. A few kinds of fault are
|
|
* only for M profile and have no A/R equivalent, though, so we have
|
|
* to pick a value from the reserved range (which we never otherwise
|
|
* generate) to use for these.
|
|
* These values will never be visible to the guest.
|
|
*/
|
|
#define M_FAKE_FSR_NSC_EXEC 0xf /* NS executing in S&NSC memory */
|
|
#define M_FAKE_FSR_SFAULT 0xe /* SecureFault INVTRAN, INVEP or AUVIOL */
|
|
|
|
/**
|
|
* raise_exception: Raise the specified exception.
|
|
* Raise a guest exception with the specified value, syndrome register
|
|
* and target exception level. This should be called from helper functions,
|
|
* and never returns because we will longjump back up to the CPU main loop.
|
|
*/
|
|
G_NORETURN void raise_exception(CPUARMState *env, uint32_t excp,
|
|
uint32_t syndrome, uint32_t target_el);
|
|
|
|
/*
|
|
* Similarly, but also use unwinding to restore cpu state.
|
|
*/
|
|
G_NORETURN void raise_exception_ra(CPUARMState *env, uint32_t excp,
|
|
uint32_t syndrome, uint32_t target_el,
|
|
uintptr_t ra);
|
|
|
|
/*
|
|
* For AArch64, map a given EL to an index in the banked_spsr array.
|
|
* Note that this mapping and the AArch32 mapping defined in bank_number()
|
|
* must agree such that the AArch64<->AArch32 SPSRs have the architecturally
|
|
* mandated mapping between each other.
|
|
*/
|
|
static inline unsigned int aarch64_banked_spsr_index(unsigned int el)
|
|
{
|
|
static const unsigned int map[4] = {
|
|
[1] = BANK_SVC, /* EL1. */
|
|
[2] = BANK_HYP, /* EL2. */
|
|
[3] = BANK_MON, /* EL3. */
|
|
};
|
|
assert(el >= 1 && el <= 3);
|
|
return map[el];
|
|
}
|
|
|
|
/* Map CPU modes onto saved register banks. */
|
|
static inline int bank_number(int mode)
|
|
{
|
|
switch (mode) {
|
|
case ARM_CPU_MODE_USR:
|
|
case ARM_CPU_MODE_SYS:
|
|
return BANK_USRSYS;
|
|
case ARM_CPU_MODE_SVC:
|
|
return BANK_SVC;
|
|
case ARM_CPU_MODE_ABT:
|
|
return BANK_ABT;
|
|
case ARM_CPU_MODE_UND:
|
|
return BANK_UND;
|
|
case ARM_CPU_MODE_IRQ:
|
|
return BANK_IRQ;
|
|
case ARM_CPU_MODE_FIQ:
|
|
return BANK_FIQ;
|
|
case ARM_CPU_MODE_HYP:
|
|
return BANK_HYP;
|
|
case ARM_CPU_MODE_MON:
|
|
return BANK_MON;
|
|
}
|
|
g_assert_not_reached();
|
|
}
|
|
|
|
/**
|
|
* r14_bank_number: Map CPU mode onto register bank for r14
|
|
*
|
|
* Given an AArch32 CPU mode, return the index into the saved register
|
|
* banks to use for the R14 (LR) in that mode. This is the same as
|
|
* bank_number(), except for the special case of Hyp mode, where
|
|
* R14 is shared with USR and SYS, unlike its R13 and SPSR.
|
|
* This should be used as the index into env->banked_r14[], and
|
|
* bank_number() used for the index into env->banked_r13[] and
|
|
* env->banked_spsr[].
|
|
*/
|
|
static inline int r14_bank_number(int mode)
|
|
{
|
|
return (mode == ARM_CPU_MODE_HYP) ? BANK_USRSYS : bank_number(mode);
|
|
}
|
|
|
|
void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu);
|
|
void arm_translate_init(void);
|
|
|
|
void arm_restore_state_to_opc(CPUState *cs,
|
|
const TranslationBlock *tb,
|
|
const uint64_t *data);
|
|
|
|
#ifdef CONFIG_TCG
|
|
void arm_cpu_synchronize_from_tb(CPUState *cs, const TranslationBlock *tb);
|
|
#endif /* CONFIG_TCG */
|
|
|
|
enum arm_fprounding {
|
|
FPROUNDING_TIEEVEN,
|
|
FPROUNDING_POSINF,
|
|
FPROUNDING_NEGINF,
|
|
FPROUNDING_ZERO,
|
|
FPROUNDING_TIEAWAY,
|
|
FPROUNDING_ODD
|
|
};
|
|
|
|
int arm_rmode_to_sf(int rmode);
|
|
|
|
static inline void aarch64_save_sp(CPUARMState *env, int el)
|
|
{
|
|
if (env->pstate & PSTATE_SP) {
|
|
env->sp_el[el] = env->xregs[31];
|
|
} else {
|
|
env->sp_el[0] = env->xregs[31];
|
|
}
|
|
}
|
|
|
|
static inline void aarch64_restore_sp(CPUARMState *env, int el)
|
|
{
|
|
if (env->pstate & PSTATE_SP) {
|
|
env->xregs[31] = env->sp_el[el];
|
|
} else {
|
|
env->xregs[31] = env->sp_el[0];
|
|
}
|
|
}
|
|
|
|
static inline void update_spsel(CPUARMState *env, uint32_t imm)
|
|
{
|
|
unsigned int cur_el = arm_current_el(env);
|
|
/* Update PSTATE SPSel bit; this requires us to update the
|
|
* working stack pointer in xregs[31].
|
|
*/
|
|
if (!((imm ^ env->pstate) & PSTATE_SP)) {
|
|
return;
|
|
}
|
|
aarch64_save_sp(env, cur_el);
|
|
env->pstate = deposit32(env->pstate, 0, 1, imm);
|
|
|
|
/* We rely on illegal updates to SPsel from EL0 to get trapped
|
|
* at translation time.
|
|
*/
|
|
assert(cur_el >= 1 && cur_el <= 3);
|
|
aarch64_restore_sp(env, cur_el);
|
|
}
|
|
|
|
/*
|
|
* arm_pamax
|
|
* @cpu: ARMCPU
|
|
*
|
|
* Returns the implementation defined bit-width of physical addresses.
|
|
* The ARMv8 reference manuals refer to this as PAMax().
|
|
*/
|
|
unsigned int arm_pamax(ARMCPU *cpu);
|
|
|
|
/* Return true if extended addresses are enabled.
|
|
* This is always the case if our translation regime is 64 bit,
|
|
* but depends on TTBCR.EAE for 32 bit.
|
|
*/
|
|
static inline bool extended_addresses_enabled(CPUARMState *env)
|
|
{
|
|
uint64_t tcr = env->cp15.tcr_el[arm_is_secure(env) ? 3 : 1];
|
|
return arm_el_is_aa64(env, 1) ||
|
|
(arm_feature(env, ARM_FEATURE_LPAE) && (tcr & TTBCR_EAE));
|
|
}
|
|
|
|
/* Update a QEMU watchpoint based on the information the guest has set in the
|
|
* DBGWCR<n>_EL1 and DBGWVR<n>_EL1 registers.
|
|
*/
|
|
void hw_watchpoint_update(ARMCPU *cpu, int n);
|
|
/* Update the QEMU watchpoints for every guest watchpoint. This does a
|
|
* complete delete-and-reinstate of the QEMU watchpoint list and so is
|
|
* suitable for use after migration or on reset.
|
|
*/
|
|
void hw_watchpoint_update_all(ARMCPU *cpu);
|
|
/* Update a QEMU breakpoint based on the information the guest has set in the
|
|
* DBGBCR<n>_EL1 and DBGBVR<n>_EL1 registers.
|
|
*/
|
|
void hw_breakpoint_update(ARMCPU *cpu, int n);
|
|
/* Update the QEMU breakpoints for every guest breakpoint. This does a
|
|
* complete delete-and-reinstate of the QEMU breakpoint list and so is
|
|
* suitable for use after migration or on reset.
|
|
*/
|
|
void hw_breakpoint_update_all(ARMCPU *cpu);
|
|
|
|
/* Callback function for checking if a breakpoint should trigger. */
|
|
bool arm_debug_check_breakpoint(CPUState *cs);
|
|
|
|
/* Callback function for checking if a watchpoint should trigger. */
|
|
bool arm_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp);
|
|
|
|
/* Adjust addresses (in BE32 mode) before testing against watchpoint
|
|
* addresses.
|
|
*/
|
|
vaddr arm_adjust_watchpoint_address(CPUState *cs, vaddr addr, int len);
|
|
|
|
/* Callback function for when a watchpoint or breakpoint triggers. */
|
|
void arm_debug_excp_handler(CPUState *cs);
|
|
|
|
#if defined(CONFIG_USER_ONLY) || !defined(CONFIG_TCG)
|
|
static inline bool arm_is_psci_call(ARMCPU *cpu, int excp_type)
|
|
{
|
|
return false;
|
|
}
|
|
static inline void arm_handle_psci_call(ARMCPU *cpu)
|
|
{
|
|
g_assert_not_reached();
|
|
}
|
|
#else
|
|
/* Return true if the r0/x0 value indicates that this SMC/HVC is a PSCI call. */
|
|
bool arm_is_psci_call(ARMCPU *cpu, int excp_type);
|
|
/* Actually handle a PSCI call */
|
|
void arm_handle_psci_call(ARMCPU *cpu);
|
|
#endif
|
|
|
|
/**
|
|
* arm_clear_exclusive: clear the exclusive monitor
|
|
* @env: CPU env
|
|
* Clear the CPU's exclusive monitor, like the guest CLREX instruction.
|
|
*/
|
|
static inline void arm_clear_exclusive(CPUARMState *env)
|
|
{
|
|
env->exclusive_addr = -1;
|
|
}
|
|
|
|
/**
|
|
* ARMFaultType: type of an ARM MMU fault
|
|
* This corresponds to the v8A pseudocode's Fault enumeration,
|
|
* with extensions for QEMU internal conditions.
|
|
*/
|
|
typedef enum ARMFaultType {
|
|
ARMFault_None,
|
|
ARMFault_AccessFlag,
|
|
ARMFault_Alignment,
|
|
ARMFault_Background,
|
|
ARMFault_Domain,
|
|
ARMFault_Permission,
|
|
ARMFault_Translation,
|
|
ARMFault_AddressSize,
|
|
ARMFault_SyncExternal,
|
|
ARMFault_SyncExternalOnWalk,
|
|
ARMFault_SyncParity,
|
|
ARMFault_SyncParityOnWalk,
|
|
ARMFault_AsyncParity,
|
|
ARMFault_AsyncExternal,
|
|
ARMFault_Debug,
|
|
ARMFault_TLBConflict,
|
|
ARMFault_UnsuppAtomicUpdate,
|
|
ARMFault_Lockdown,
|
|
ARMFault_Exclusive,
|
|
ARMFault_ICacheMaint,
|
|
ARMFault_QEMU_NSCExec, /* v8M: NS executing in S&NSC memory */
|
|
ARMFault_QEMU_SFault, /* v8M: SecureFault INVTRAN, INVEP or AUVIOL */
|
|
} ARMFaultType;
|
|
|
|
/**
|
|
* ARMMMUFaultInfo: Information describing an ARM MMU Fault
|
|
* @type: Type of fault
|
|
* @level: Table walk level (for translation, access flag and permission faults)
|
|
* @domain: Domain of the fault address (for non-LPAE CPUs only)
|
|
* @s2addr: Address that caused a fault at stage 2
|
|
* @stage2: True if we faulted at stage 2
|
|
* @s1ptw: True if we faulted at stage 2 while doing a stage 1 page-table walk
|
|
* @s1ns: True if we faulted on a non-secure IPA while in secure state
|
|
* @ea: True if we should set the EA (external abort type) bit in syndrome
|
|
*/
|
|
typedef struct ARMMMUFaultInfo ARMMMUFaultInfo;
|
|
struct ARMMMUFaultInfo {
|
|
ARMFaultType type;
|
|
target_ulong s2addr;
|
|
int level;
|
|
int domain;
|
|
bool stage2;
|
|
bool s1ptw;
|
|
bool s1ns;
|
|
bool ea;
|
|
};
|
|
|
|
/**
|
|
* arm_fi_to_sfsc: Convert fault info struct to short-format FSC
|
|
* Compare pseudocode EncodeSDFSC(), though unlike that function
|
|
* we set up a whole FSR-format code including domain field and
|
|
* putting the high bit of the FSC into bit 10.
|
|
*/
|
|
static inline uint32_t arm_fi_to_sfsc(ARMMMUFaultInfo *fi)
|
|
{
|
|
uint32_t fsc;
|
|
|
|
switch (fi->type) {
|
|
case ARMFault_None:
|
|
return 0;
|
|
case ARMFault_AccessFlag:
|
|
fsc = fi->level == 1 ? 0x3 : 0x6;
|
|
break;
|
|
case ARMFault_Alignment:
|
|
fsc = 0x1;
|
|
break;
|
|
case ARMFault_Permission:
|
|
fsc = fi->level == 1 ? 0xd : 0xf;
|
|
break;
|
|
case ARMFault_Domain:
|
|
fsc = fi->level == 1 ? 0x9 : 0xb;
|
|
break;
|
|
case ARMFault_Translation:
|
|
fsc = fi->level == 1 ? 0x5 : 0x7;
|
|
break;
|
|
case ARMFault_SyncExternal:
|
|
fsc = 0x8 | (fi->ea << 12);
|
|
break;
|
|
case ARMFault_SyncExternalOnWalk:
|
|
fsc = fi->level == 1 ? 0xc : 0xe;
|
|
fsc |= (fi->ea << 12);
|
|
break;
|
|
case ARMFault_SyncParity:
|
|
fsc = 0x409;
|
|
break;
|
|
case ARMFault_SyncParityOnWalk:
|
|
fsc = fi->level == 1 ? 0x40c : 0x40e;
|
|
break;
|
|
case ARMFault_AsyncParity:
|
|
fsc = 0x408;
|
|
break;
|
|
case ARMFault_AsyncExternal:
|
|
fsc = 0x406 | (fi->ea << 12);
|
|
break;
|
|
case ARMFault_Debug:
|
|
fsc = 0x2;
|
|
break;
|
|
case ARMFault_TLBConflict:
|
|
fsc = 0x400;
|
|
break;
|
|
case ARMFault_Lockdown:
|
|
fsc = 0x404;
|
|
break;
|
|
case ARMFault_Exclusive:
|
|
fsc = 0x405;
|
|
break;
|
|
case ARMFault_ICacheMaint:
|
|
fsc = 0x4;
|
|
break;
|
|
case ARMFault_Background:
|
|
fsc = 0x0;
|
|
break;
|
|
case ARMFault_QEMU_NSCExec:
|
|
fsc = M_FAKE_FSR_NSC_EXEC;
|
|
break;
|
|
case ARMFault_QEMU_SFault:
|
|
fsc = M_FAKE_FSR_SFAULT;
|
|
break;
|
|
default:
|
|
/* Other faults can't occur in a context that requires a
|
|
* short-format status code.
|
|
*/
|
|
g_assert_not_reached();
|
|
}
|
|
|
|
fsc |= (fi->domain << 4);
|
|
return fsc;
|
|
}
|
|
|
|
/**
|
|
* arm_fi_to_lfsc: Convert fault info struct to long-format FSC
|
|
* Compare pseudocode EncodeLDFSC(), though unlike that function
|
|
* we fill in also the LPAE bit 9 of a DFSR format.
|
|
*/
|
|
static inline uint32_t arm_fi_to_lfsc(ARMMMUFaultInfo *fi)
|
|
{
|
|
uint32_t fsc;
|
|
|
|
switch (fi->type) {
|
|
case ARMFault_None:
|
|
return 0;
|
|
case ARMFault_AddressSize:
|
|
assert(fi->level >= -1 && fi->level <= 3);
|
|
if (fi->level < 0) {
|
|
fsc = 0b101001;
|
|
} else {
|
|
fsc = fi->level;
|
|
}
|
|
break;
|
|
case ARMFault_AccessFlag:
|
|
assert(fi->level >= 0 && fi->level <= 3);
|
|
fsc = 0b001000 | fi->level;
|
|
break;
|
|
case ARMFault_Permission:
|
|
assert(fi->level >= 0 && fi->level <= 3);
|
|
fsc = 0b001100 | fi->level;
|
|
break;
|
|
case ARMFault_Translation:
|
|
assert(fi->level >= -1 && fi->level <= 3);
|
|
if (fi->level < 0) {
|
|
fsc = 0b101011;
|
|
} else {
|
|
fsc = 0b000100 | fi->level;
|
|
}
|
|
break;
|
|
case ARMFault_SyncExternal:
|
|
fsc = 0x10 | (fi->ea << 12);
|
|
break;
|
|
case ARMFault_SyncExternalOnWalk:
|
|
assert(fi->level >= -1 && fi->level <= 3);
|
|
if (fi->level < 0) {
|
|
fsc = 0b010011;
|
|
} else {
|
|
fsc = 0b010100 | fi->level;
|
|
}
|
|
fsc |= fi->ea << 12;
|
|
break;
|
|
case ARMFault_SyncParity:
|
|
fsc = 0x18;
|
|
break;
|
|
case ARMFault_SyncParityOnWalk:
|
|
assert(fi->level >= -1 && fi->level <= 3);
|
|
if (fi->level < 0) {
|
|
fsc = 0b011011;
|
|
} else {
|
|
fsc = 0b011100 | fi->level;
|
|
}
|
|
break;
|
|
case ARMFault_AsyncParity:
|
|
fsc = 0x19;
|
|
break;
|
|
case ARMFault_AsyncExternal:
|
|
fsc = 0x11 | (fi->ea << 12);
|
|
break;
|
|
case ARMFault_Alignment:
|
|
fsc = 0x21;
|
|
break;
|
|
case ARMFault_Debug:
|
|
fsc = 0x22;
|
|
break;
|
|
case ARMFault_TLBConflict:
|
|
fsc = 0x30;
|
|
break;
|
|
case ARMFault_UnsuppAtomicUpdate:
|
|
fsc = 0x31;
|
|
break;
|
|
case ARMFault_Lockdown:
|
|
fsc = 0x34;
|
|
break;
|
|
case ARMFault_Exclusive:
|
|
fsc = 0x35;
|
|
break;
|
|
default:
|
|
/* Other faults can't occur in a context that requires a
|
|
* long-format status code.
|
|
*/
|
|
g_assert_not_reached();
|
|
}
|
|
|
|
fsc |= 1 << 9;
|
|
return fsc;
|
|
}
|
|
|
|
static inline bool arm_extabort_type(MemTxResult result)
|
|
{
|
|
/* The EA bit in syndromes and fault status registers is an
|
|
* IMPDEF classification of external aborts. ARM implementations
|
|
* usually use this to indicate AXI bus Decode error (0) or
|
|
* Slave error (1); in QEMU we follow that.
|
|
*/
|
|
return result != MEMTX_DECODE_ERROR;
|
|
}
|
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
void arm_cpu_record_sigsegv(CPUState *cpu, vaddr addr,
|
|
MMUAccessType access_type,
|
|
bool maperr, uintptr_t ra);
|
|
void arm_cpu_record_sigbus(CPUState *cpu, vaddr addr,
|
|
MMUAccessType access_type, uintptr_t ra);
|
|
#else
|
|
bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
|
|
MMUAccessType access_type, int mmu_idx,
|
|
bool probe, uintptr_t retaddr);
|
|
#endif
|
|
|
|
static inline int arm_to_core_mmu_idx(ARMMMUIdx mmu_idx)
|
|
{
|
|
return mmu_idx & ARM_MMU_IDX_COREIDX_MASK;
|
|
}
|
|
|
|
static inline ARMMMUIdx core_to_arm_mmu_idx(CPUARMState *env, int mmu_idx)
|
|
{
|
|
if (arm_feature(env, ARM_FEATURE_M)) {
|
|
return mmu_idx | ARM_MMU_IDX_M;
|
|
} else {
|
|
return mmu_idx | ARM_MMU_IDX_A;
|
|
}
|
|
}
|
|
|
|
static inline ARMMMUIdx core_to_aa64_mmu_idx(int mmu_idx)
|
|
{
|
|
/* AArch64 is always a-profile. */
|
|
return mmu_idx | ARM_MMU_IDX_A;
|
|
}
|
|
|
|
int arm_mmu_idx_to_el(ARMMMUIdx mmu_idx);
|
|
|
|
/*
|
|
* Return the MMU index for a v7M CPU with all relevant information
|
|
* manually specified.
|
|
*/
|
|
ARMMMUIdx arm_v7m_mmu_idx_all(CPUARMState *env,
|
|
bool secstate, bool priv, bool negpri);
|
|
|
|
/*
|
|
* Return the MMU index for a v7M CPU in the specified security and
|
|
* privilege state.
|
|
*/
|
|
ARMMMUIdx arm_v7m_mmu_idx_for_secstate_and_priv(CPUARMState *env,
|
|
bool secstate, bool priv);
|
|
|
|
/* Return the MMU index for a v7M CPU in the specified security state */
|
|
ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState *env, bool secstate);
|
|
|
|
/* Return true if the translation regime is using LPAE format page tables */
|
|
bool regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx);
|
|
|
|
/*
|
|
* Return true if the stage 1 translation regime is using LPAE
|
|
* format page tables
|
|
*/
|
|
bool arm_s1_regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx);
|
|
|
|
/* Raise a data fault alignment exception for the specified virtual address */
|
|
G_NORETURN void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr,
|
|
MMUAccessType access_type,
|
|
int mmu_idx, uintptr_t retaddr);
|
|
|
|
/* arm_cpu_do_transaction_failed: handle a memory system error response
|
|
* (eg "no device/memory present at address") by raising an external abort
|
|
* exception
|
|
*/
|
|
void arm_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
|
|
vaddr addr, unsigned size,
|
|
MMUAccessType access_type,
|
|
int mmu_idx, MemTxAttrs attrs,
|
|
MemTxResult response, uintptr_t retaddr);
|
|
|
|
/* Call any registered EL change hooks */
|
|
static inline void arm_call_pre_el_change_hook(ARMCPU *cpu)
|
|
{
|
|
ARMELChangeHook *hook, *next;
|
|
QLIST_FOREACH_SAFE(hook, &cpu->pre_el_change_hooks, node, next) {
|
|
hook->hook(cpu, hook->opaque);
|
|
}
|
|
}
|
|
static inline void arm_call_el_change_hook(ARMCPU *cpu)
|
|
{
|
|
ARMELChangeHook *hook, *next;
|
|
QLIST_FOREACH_SAFE(hook, &cpu->el_change_hooks, node, next) {
|
|
hook->hook(cpu, hook->opaque);
|
|
}
|
|
}
|
|
|
|
/* Return true if this address translation regime has two ranges. */
|
|
static inline bool regime_has_2_ranges(ARMMMUIdx mmu_idx)
|
|
{
|
|
switch (mmu_idx) {
|
|
case ARMMMUIdx_Stage1_E0:
|
|
case ARMMMUIdx_Stage1_E1:
|
|
case ARMMMUIdx_Stage1_E1_PAN:
|
|
case ARMMMUIdx_E10_0:
|
|
case ARMMMUIdx_E10_1:
|
|
case ARMMMUIdx_E10_1_PAN:
|
|
case ARMMMUIdx_E20_0:
|
|
case ARMMMUIdx_E20_2:
|
|
case ARMMMUIdx_E20_2_PAN:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static inline bool regime_is_pan(CPUARMState *env, ARMMMUIdx mmu_idx)
|
|
{
|
|
switch (mmu_idx) {
|
|
case ARMMMUIdx_Stage1_E1_PAN:
|
|
case ARMMMUIdx_E10_1_PAN:
|
|
case ARMMMUIdx_E20_2_PAN:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static inline bool regime_is_stage2(ARMMMUIdx mmu_idx)
|
|
{
|
|
return mmu_idx == ARMMMUIdx_Stage2 || mmu_idx == ARMMMUIdx_Stage2_S;
|
|
}
|
|
|
|
/* Return the exception level which controls this address translation regime */
|
|
static inline uint32_t regime_el(CPUARMState *env, ARMMMUIdx mmu_idx)
|
|
{
|
|
switch (mmu_idx) {
|
|
case ARMMMUIdx_E20_0:
|
|
case ARMMMUIdx_E20_2:
|
|
case ARMMMUIdx_E20_2_PAN:
|
|
case ARMMMUIdx_Stage2:
|
|
case ARMMMUIdx_Stage2_S:
|
|
case ARMMMUIdx_E2:
|
|
return 2;
|
|
case ARMMMUIdx_E3:
|
|
return 3;
|
|
case ARMMMUIdx_E10_0:
|
|
case ARMMMUIdx_Stage1_E0:
|
|
return arm_el_is_aa64(env, 3) || !arm_is_secure_below_el3(env) ? 1 : 3;
|
|
case ARMMMUIdx_Stage1_E1:
|
|
case ARMMMUIdx_Stage1_E1_PAN:
|
|
case ARMMMUIdx_E10_1:
|
|
case ARMMMUIdx_E10_1_PAN:
|
|
case ARMMMUIdx_MPrivNegPri:
|
|
case ARMMMUIdx_MUserNegPri:
|
|
case ARMMMUIdx_MPriv:
|
|
case ARMMMUIdx_MUser:
|
|
case ARMMMUIdx_MSPrivNegPri:
|
|
case ARMMMUIdx_MSUserNegPri:
|
|
case ARMMMUIdx_MSPriv:
|
|
case ARMMMUIdx_MSUser:
|
|
return 1;
|
|
default:
|
|
g_assert_not_reached();
|
|
}
|
|
}
|
|
|
|
static inline bool regime_is_user(CPUARMState *env, ARMMMUIdx mmu_idx)
|
|
{
|
|
switch (mmu_idx) {
|
|
case ARMMMUIdx_E20_0:
|
|
case ARMMMUIdx_Stage1_E0:
|
|
case ARMMMUIdx_MUser:
|
|
case ARMMMUIdx_MSUser:
|
|
case ARMMMUIdx_MUserNegPri:
|
|
case ARMMMUIdx_MSUserNegPri:
|
|
return true;
|
|
default:
|
|
return false;
|
|
case ARMMMUIdx_E10_0:
|
|
case ARMMMUIdx_E10_1:
|
|
case ARMMMUIdx_E10_1_PAN:
|
|
g_assert_not_reached();
|
|
}
|
|
}
|
|
|
|
/* Return the SCTLR value which controls this address translation regime */
|
|
static inline uint64_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx)
|
|
{
|
|
return env->cp15.sctlr_el[regime_el(env, mmu_idx)];
|
|
}
|
|
|
|
/*
|
|
* These are the fields in VTCR_EL2 which affect both the Secure stage 2
|
|
* and the Non-Secure stage 2 translation regimes (and hence which are
|
|
* not present in VSTCR_EL2).
|
|
*/
|
|
#define VTCR_SHARED_FIELD_MASK \
|
|
(R_VTCR_IRGN0_MASK | R_VTCR_ORGN0_MASK | R_VTCR_SH0_MASK | \
|
|
R_VTCR_PS_MASK | R_VTCR_VS_MASK | R_VTCR_HA_MASK | R_VTCR_HD_MASK | \
|
|
R_VTCR_DS_MASK)
|
|
|
|
/* Return the value of the TCR controlling this translation regime */
|
|
static inline uint64_t regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx)
|
|
{
|
|
if (mmu_idx == ARMMMUIdx_Stage2) {
|
|
return env->cp15.vtcr_el2;
|
|
}
|
|
if (mmu_idx == ARMMMUIdx_Stage2_S) {
|
|
/*
|
|
* Secure stage 2 shares fields from VTCR_EL2. We merge those
|
|
* in with the VSTCR_EL2 value to synthesize a single VTCR_EL2 format
|
|
* value so the callers don't need to special case this.
|
|
*
|
|
* If a future architecture change defines bits in VSTCR_EL2 that
|
|
* overlap with these VTCR_EL2 fields we may need to revisit this.
|
|
*/
|
|
uint64_t v = env->cp15.vstcr_el2 & ~VTCR_SHARED_FIELD_MASK;
|
|
v |= env->cp15.vtcr_el2 & VTCR_SHARED_FIELD_MASK;
|
|
return v;
|
|
}
|
|
return env->cp15.tcr_el[regime_el(env, mmu_idx)];
|
|
}
|
|
|
|
/**
|
|
* arm_num_brps: Return number of implemented breakpoints.
|
|
* Note that the ID register BRPS field is "number of bps - 1",
|
|
* and we return the actual number of breakpoints.
|
|
*/
|
|
static inline int arm_num_brps(ARMCPU *cpu)
|
|
{
|
|
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
|
|
return FIELD_EX64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, BRPS) + 1;
|
|
} else {
|
|
return FIELD_EX32(cpu->isar.dbgdidr, DBGDIDR, BRPS) + 1;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* arm_num_wrps: Return number of implemented watchpoints.
|
|
* Note that the ID register WRPS field is "number of wps - 1",
|
|
* and we return the actual number of watchpoints.
|
|
*/
|
|
static inline int arm_num_wrps(ARMCPU *cpu)
|
|
{
|
|
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
|
|
return FIELD_EX64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, WRPS) + 1;
|
|
} else {
|
|
return FIELD_EX32(cpu->isar.dbgdidr, DBGDIDR, WRPS) + 1;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* arm_num_ctx_cmps: Return number of implemented context comparators.
|
|
* Note that the ID register CTX_CMPS field is "number of cmps - 1",
|
|
* and we return the actual number of comparators.
|
|
*/
|
|
static inline int arm_num_ctx_cmps(ARMCPU *cpu)
|
|
{
|
|
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
|
|
return FIELD_EX64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, CTX_CMPS) + 1;
|
|
} else {
|
|
return FIELD_EX32(cpu->isar.dbgdidr, DBGDIDR, CTX_CMPS) + 1;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* v7m_using_psp: Return true if using process stack pointer
|
|
* Return true if the CPU is currently using the process stack
|
|
* pointer, or false if it is using the main stack pointer.
|
|
*/
|
|
static inline bool v7m_using_psp(CPUARMState *env)
|
|
{
|
|
/* Handler mode always uses the main stack; for thread mode
|
|
* the CONTROL.SPSEL bit determines the answer.
|
|
* Note that in v7M it is not possible to be in Handler mode with
|
|
* CONTROL.SPSEL non-zero, but in v8M it is, so we must check both.
|
|
*/
|
|
return !arm_v7m_is_handler_mode(env) &&
|
|
env->v7m.control[env->v7m.secure] & R_V7M_CONTROL_SPSEL_MASK;
|
|
}
|
|
|
|
/**
|
|
* v7m_sp_limit: Return SP limit for current CPU state
|
|
* Return the SP limit value for the current CPU security state
|
|
* and stack pointer.
|
|
*/
|
|
static inline uint32_t v7m_sp_limit(CPUARMState *env)
|
|
{
|
|
if (v7m_using_psp(env)) {
|
|
return env->v7m.psplim[env->v7m.secure];
|
|
} else {
|
|
return env->v7m.msplim[env->v7m.secure];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* v7m_cpacr_pass:
|
|
* Return true if the v7M CPACR permits access to the FPU for the specified
|
|
* security state and privilege level.
|
|
*/
|
|
static inline bool v7m_cpacr_pass(CPUARMState *env,
|
|
bool is_secure, bool is_priv)
|
|
{
|
|
switch (extract32(env->v7m.cpacr[is_secure], 20, 2)) {
|
|
case 0:
|
|
case 2: /* UNPREDICTABLE: we treat like 0 */
|
|
return false;
|
|
case 1:
|
|
return is_priv;
|
|
case 3:
|
|
return true;
|
|
default:
|
|
g_assert_not_reached();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* aarch32_mode_name(): Return name of the AArch32 CPU mode
|
|
* @psr: Program Status Register indicating CPU mode
|
|
*
|
|
* Returns, for debug logging purposes, a printable representation
|
|
* of the AArch32 CPU mode ("svc", "usr", etc) as indicated by
|
|
* the low bits of the specified PSR.
|
|
*/
|
|
static inline const char *aarch32_mode_name(uint32_t psr)
|
|
{
|
|
static const char cpu_mode_names[16][4] = {
|
|
"usr", "fiq", "irq", "svc", "???", "???", "mon", "abt",
|
|
"???", "???", "hyp", "und", "???", "???", "???", "sys"
|
|
};
|
|
|
|
return cpu_mode_names[psr & 0xf];
|
|
}
|
|
|
|
/**
|
|
* arm_cpu_update_virq: Update CPU_INTERRUPT_VIRQ bit in cs->interrupt_request
|
|
*
|
|
* Update the CPU_INTERRUPT_VIRQ bit in cs->interrupt_request, following
|
|
* a change to either the input VIRQ line from the GIC or the HCR_EL2.VI bit.
|
|
* Must be called with the iothread lock held.
|
|
*/
|
|
void arm_cpu_update_virq(ARMCPU *cpu);
|
|
|
|
/**
|
|
* arm_cpu_update_vfiq: Update CPU_INTERRUPT_VFIQ bit in cs->interrupt_request
|
|
*
|
|
* Update the CPU_INTERRUPT_VFIQ bit in cs->interrupt_request, following
|
|
* a change to either the input VFIQ line from the GIC or the HCR_EL2.VF bit.
|
|
* Must be called with the iothread lock held.
|
|
*/
|
|
void arm_cpu_update_vfiq(ARMCPU *cpu);
|
|
|
|
/**
|
|
* arm_cpu_update_vserr: Update CPU_INTERRUPT_VSERR bit
|
|
*
|
|
* Update the CPU_INTERRUPT_VSERR bit in cs->interrupt_request,
|
|
* following a change to the HCR_EL2.VSE bit.
|
|
*/
|
|
void arm_cpu_update_vserr(ARMCPU *cpu);
|
|
|
|
/**
|
|
* arm_mmu_idx_el:
|
|
* @env: The cpu environment
|
|
* @el: The EL to use.
|
|
*
|
|
* Return the full ARMMMUIdx for the translation regime for EL.
|
|
*/
|
|
ARMMMUIdx arm_mmu_idx_el(CPUARMState *env, int el);
|
|
|
|
/**
|
|
* arm_mmu_idx:
|
|
* @env: The cpu environment
|
|
*
|
|
* Return the full ARMMMUIdx for the current translation regime.
|
|
*/
|
|
ARMMMUIdx arm_mmu_idx(CPUARMState *env);
|
|
|
|
/**
|
|
* arm_stage1_mmu_idx:
|
|
* @env: The cpu environment
|
|
*
|
|
* Return the ARMMMUIdx for the stage1 traversal for the current regime.
|
|
*/
|
|
#ifdef CONFIG_USER_ONLY
|
|
static inline ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx)
|
|
{
|
|
return ARMMMUIdx_Stage1_E0;
|
|
}
|
|
static inline ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env)
|
|
{
|
|
return ARMMMUIdx_Stage1_E0;
|
|
}
|
|
#else
|
|
ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx);
|
|
ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env);
|
|
#endif
|
|
|
|
/**
|
|
* arm_mmu_idx_is_stage1_of_2:
|
|
* @mmu_idx: The ARMMMUIdx to test
|
|
*
|
|
* Return true if @mmu_idx is a NOTLB mmu_idx that is the
|
|
* first stage of a two stage regime.
|
|
*/
|
|
static inline bool arm_mmu_idx_is_stage1_of_2(ARMMMUIdx mmu_idx)
|
|
{
|
|
switch (mmu_idx) {
|
|
case ARMMMUIdx_Stage1_E0:
|
|
case ARMMMUIdx_Stage1_E1:
|
|
case ARMMMUIdx_Stage1_E1_PAN:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static inline uint32_t aarch32_cpsr_valid_mask(uint64_t features,
|
|
const ARMISARegisters *id)
|
|
{
|
|
uint32_t valid = CPSR_M | CPSR_AIF | CPSR_IL | CPSR_NZCV;
|
|
|
|
if ((features >> ARM_FEATURE_V4T) & 1) {
|
|
valid |= CPSR_T;
|
|
}
|
|
if ((features >> ARM_FEATURE_V5) & 1) {
|
|
valid |= CPSR_Q; /* V5TE in reality*/
|
|
}
|
|
if ((features >> ARM_FEATURE_V6) & 1) {
|
|
valid |= CPSR_E | CPSR_GE;
|
|
}
|
|
if ((features >> ARM_FEATURE_THUMB2) & 1) {
|
|
valid |= CPSR_IT;
|
|
}
|
|
if (isar_feature_aa32_jazelle(id)) {
|
|
valid |= CPSR_J;
|
|
}
|
|
if (isar_feature_aa32_pan(id)) {
|
|
valid |= CPSR_PAN;
|
|
}
|
|
if (isar_feature_aa32_dit(id)) {
|
|
valid |= CPSR_DIT;
|
|
}
|
|
if (isar_feature_aa32_ssbs(id)) {
|
|
valid |= CPSR_SSBS;
|
|
}
|
|
|
|
return valid;
|
|
}
|
|
|
|
static inline uint32_t aarch64_pstate_valid_mask(const ARMISARegisters *id)
|
|
{
|
|
uint32_t valid;
|
|
|
|
valid = PSTATE_M | PSTATE_DAIF | PSTATE_IL | PSTATE_SS | PSTATE_NZCV;
|
|
if (isar_feature_aa64_bti(id)) {
|
|
valid |= PSTATE_BTYPE;
|
|
}
|
|
if (isar_feature_aa64_pan(id)) {
|
|
valid |= PSTATE_PAN;
|
|
}
|
|
if (isar_feature_aa64_uao(id)) {
|
|
valid |= PSTATE_UAO;
|
|
}
|
|
if (isar_feature_aa64_dit(id)) {
|
|
valid |= PSTATE_DIT;
|
|
}
|
|
if (isar_feature_aa64_ssbs(id)) {
|
|
valid |= PSTATE_SSBS;
|
|
}
|
|
if (isar_feature_aa64_mte(id)) {
|
|
valid |= PSTATE_TCO;
|
|
}
|
|
|
|
return valid;
|
|
}
|
|
|
|
/* Granule size (i.e. page size) */
|
|
typedef enum ARMGranuleSize {
|
|
/* Same order as TG0 encoding */
|
|
Gran4K,
|
|
Gran64K,
|
|
Gran16K,
|
|
GranInvalid,
|
|
} ARMGranuleSize;
|
|
|
|
/**
|
|
* arm_granule_bits: Return address size of the granule in bits
|
|
*
|
|
* Return the address size of the granule in bits. This corresponds
|
|
* to the pseudocode TGxGranuleBits().
|
|
*/
|
|
static inline int arm_granule_bits(ARMGranuleSize gran)
|
|
{
|
|
switch (gran) {
|
|
case Gran64K:
|
|
return 16;
|
|
case Gran16K:
|
|
return 14;
|
|
case Gran4K:
|
|
return 12;
|
|
default:
|
|
g_assert_not_reached();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Parameters of a given virtual address, as extracted from the
|
|
* translation control register (TCR) for a given regime.
|
|
*/
|
|
typedef struct ARMVAParameters {
|
|
unsigned tsz : 8;
|
|
unsigned ps : 3;
|
|
unsigned sh : 2;
|
|
unsigned select : 1;
|
|
bool tbi : 1;
|
|
bool epd : 1;
|
|
bool hpd : 1;
|
|
bool tsz_oob : 1; /* tsz has been clamped to legal range */
|
|
bool ds : 1;
|
|
bool ha : 1;
|
|
bool hd : 1;
|
|
ARMGranuleSize gran : 2;
|
|
} ARMVAParameters;
|
|
|
|
ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va,
|
|
ARMMMUIdx mmu_idx, bool data);
|
|
|
|
int aa64_va_parameter_tbi(uint64_t tcr, ARMMMUIdx mmu_idx);
|
|
int aa64_va_parameter_tbid(uint64_t tcr, ARMMMUIdx mmu_idx);
|
|
|
|
/* Determine if allocation tags are available. */
|
|
static inline bool allocation_tag_access_enabled(CPUARMState *env, int el,
|
|
uint64_t sctlr)
|
|
{
|
|
if (el < 3
|
|
&& arm_feature(env, ARM_FEATURE_EL3)
|
|
&& !(env->cp15.scr_el3 & SCR_ATA)) {
|
|
return false;
|
|
}
|
|
if (el < 2 && arm_is_el2_enabled(env)) {
|
|
uint64_t hcr = arm_hcr_el2_eff(env);
|
|
if (!(hcr & HCR_ATA) && (!(hcr & HCR_E2H) || !(hcr & HCR_TGE))) {
|
|
return false;
|
|
}
|
|
}
|
|
sctlr &= (el == 0 ? SCTLR_ATA0 : SCTLR_ATA);
|
|
return sctlr != 0;
|
|
}
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
/* Security attributes for an address, as returned by v8m_security_lookup. */
|
|
typedef struct V8M_SAttributes {
|
|
bool subpage; /* true if these attrs don't cover the whole TARGET_PAGE */
|
|
bool ns;
|
|
bool nsc;
|
|
uint8_t sregion;
|
|
bool srvalid;
|
|
uint8_t iregion;
|
|
bool irvalid;
|
|
} V8M_SAttributes;
|
|
|
|
void v8m_security_lookup(CPUARMState *env, uint32_t address,
|
|
MMUAccessType access_type, ARMMMUIdx mmu_idx,
|
|
bool secure, V8M_SAttributes *sattrs);
|
|
|
|
/* Cacheability and shareability attributes for a memory access */
|
|
typedef struct ARMCacheAttrs {
|
|
/*
|
|
* If is_s2_format is true, attrs is the S2 descriptor bits [5:2]
|
|
* Otherwise, attrs is the same as the MAIR_EL1 8-bit format
|
|
*/
|
|
unsigned int attrs:8;
|
|
unsigned int shareability:2; /* as in the SH field of the VMSAv8-64 PTEs */
|
|
bool is_s2_format:1;
|
|
bool guarded:1; /* guarded bit of the v8-64 PTE */
|
|
} ARMCacheAttrs;
|
|
|
|
/* Fields that are valid upon success. */
|
|
typedef struct GetPhysAddrResult {
|
|
CPUTLBEntryFull f;
|
|
ARMCacheAttrs cacheattrs;
|
|
} GetPhysAddrResult;
|
|
|
|
/**
|
|
* get_phys_addr_with_secure: get the physical address for a virtual address
|
|
* @env: CPUARMState
|
|
* @address: virtual address to get physical address for
|
|
* @access_type: 0 for read, 1 for write, 2 for execute
|
|
* @mmu_idx: MMU index indicating required translation regime
|
|
* @is_secure: security state for the access
|
|
* @result: set on translation success.
|
|
* @fi: set to fault info if the translation fails
|
|
*
|
|
* Find the physical address corresponding to the given virtual address,
|
|
* by doing a translation table walk on MMU based systems or using the
|
|
* MPU state on MPU based systems.
|
|
*
|
|
* Returns false if the translation was successful. Otherwise, phys_ptr, attrs,
|
|
* prot and page_size may not be filled in, and the populated fsr value provides
|
|
* information on why the translation aborted, in the format of a
|
|
* DFSR/IFSR fault register, with the following caveats:
|
|
* * we honour the short vs long DFSR format differences.
|
|
* * the WnR bit is never set (the caller must do this).
|
|
* * for PSMAv5 based systems we don't bother to return a full FSR format
|
|
* value.
|
|
*/
|
|
bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address,
|
|
MMUAccessType access_type,
|
|
ARMMMUIdx mmu_idx, bool is_secure,
|
|
GetPhysAddrResult *result, ARMMMUFaultInfo *fi)
|
|
__attribute__((nonnull));
|
|
|
|
/**
|
|
* get_phys_addr: get the physical address for a virtual address
|
|
* @env: CPUARMState
|
|
* @address: virtual address to get physical address for
|
|
* @access_type: 0 for read, 1 for write, 2 for execute
|
|
* @mmu_idx: MMU index indicating required translation regime
|
|
* @result: set on translation success.
|
|
* @fi: set to fault info if the translation fails
|
|
*
|
|
* Similarly, but use the security regime of @mmu_idx.
|
|
*/
|
|
bool get_phys_addr(CPUARMState *env, target_ulong address,
|
|
MMUAccessType access_type, ARMMMUIdx mmu_idx,
|
|
GetPhysAddrResult *result, ARMMMUFaultInfo *fi)
|
|
__attribute__((nonnull));
|
|
|
|
bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
|
|
MMUAccessType access_type, ARMMMUIdx mmu_idx,
|
|
bool is_secure, GetPhysAddrResult *result,
|
|
ARMMMUFaultInfo *fi, uint32_t *mregion);
|
|
|
|
void arm_log_exception(CPUState *cs);
|
|
|
|
#endif /* !CONFIG_USER_ONLY */
|
|
|
|
/*
|
|
* The log2 of the words in the tag block, for GMID_EL1.BS.
|
|
* The is the maximum, 256 bytes, which manipulates 64-bits of tags.
|
|
*/
|
|
#define GMID_EL1_BS 6
|
|
|
|
/*
|
|
* SVE predicates are 1/8 the size of SVE vectors, and cannot use
|
|
* the same simd_desc() encoding due to restrictions on size.
|
|
* Use these instead.
|
|
*/
|
|
FIELD(PREDDESC, OPRSZ, 0, 6)
|
|
FIELD(PREDDESC, ESZ, 6, 2)
|
|
FIELD(PREDDESC, DATA, 8, 24)
|
|
|
|
/*
|
|
* The SVE simd_data field, for memory ops, contains either
|
|
* rd (5 bits) or a shift count (2 bits).
|
|
*/
|
|
#define SVE_MTEDESC_SHIFT 5
|
|
|
|
/* Bits within a descriptor passed to the helper_mte_check* functions. */
|
|
FIELD(MTEDESC, MIDX, 0, 4)
|
|
FIELD(MTEDESC, TBI, 4, 2)
|
|
FIELD(MTEDESC, TCMA, 6, 2)
|
|
FIELD(MTEDESC, WRITE, 8, 1)
|
|
FIELD(MTEDESC, SIZEM1, 9, SIMD_DATA_BITS - 9) /* size - 1 */
|
|
|
|
bool mte_probe(CPUARMState *env, uint32_t desc, uint64_t ptr);
|
|
uint64_t mte_check(CPUARMState *env, uint32_t desc, uint64_t ptr, uintptr_t ra);
|
|
|
|
static inline int allocation_tag_from_addr(uint64_t ptr)
|
|
{
|
|
return extract64(ptr, 56, 4);
|
|
}
|
|
|
|
static inline uint64_t address_with_allocation_tag(uint64_t ptr, int rtag)
|
|
{
|
|
return deposit64(ptr, 56, 4, rtag);
|
|
}
|
|
|
|
/* Return true if tbi bits mean that the access is checked. */
|
|
static inline bool tbi_check(uint32_t desc, int bit55)
|
|
{
|
|
return (desc >> (R_MTEDESC_TBI_SHIFT + bit55)) & 1;
|
|
}
|
|
|
|
/* Return true if tcma bits mean that the access is unchecked. */
|
|
static inline bool tcma_check(uint32_t desc, int bit55, int ptr_tag)
|
|
{
|
|
/*
|
|
* We had extracted bit55 and ptr_tag for other reasons, so fold
|
|
* (ptr<59:55> == 00000 || ptr<59:55> == 11111) into a single test.
|
|
*/
|
|
bool match = ((ptr_tag + bit55) & 0xf) == 0;
|
|
bool tcma = (desc >> (R_MTEDESC_TCMA_SHIFT + bit55)) & 1;
|
|
return tcma && match;
|
|
}
|
|
|
|
/*
|
|
* For TBI, ideally, we would do nothing. Proper behaviour on fault is
|
|
* for the tag to be present in the FAR_ELx register. But for user-only
|
|
* mode, we do not have a TLB with which to implement this, so we must
|
|
* remove the top byte.
|
|
*/
|
|
static inline uint64_t useronly_clean_ptr(uint64_t ptr)
|
|
{
|
|
#ifdef CONFIG_USER_ONLY
|
|
/* TBI0 is known to be enabled, while TBI1 is disabled. */
|
|
ptr &= sextract64(ptr, 0, 56);
|
|
#endif
|
|
return ptr;
|
|
}
|
|
|
|
static inline uint64_t useronly_maybe_clean_ptr(uint32_t desc, uint64_t ptr)
|
|
{
|
|
#ifdef CONFIG_USER_ONLY
|
|
int64_t clean_ptr = sextract64(ptr, 0, 56);
|
|
if (tbi_check(desc, clean_ptr < 0)) {
|
|
ptr = clean_ptr;
|
|
}
|
|
#endif
|
|
return ptr;
|
|
}
|
|
|
|
/* Values for M-profile PSR.ECI for MVE insns */
|
|
enum MVEECIState {
|
|
ECI_NONE = 0, /* No completed beats */
|
|
ECI_A0 = 1, /* Completed: A0 */
|
|
ECI_A0A1 = 2, /* Completed: A0, A1 */
|
|
/* 3 is reserved */
|
|
ECI_A0A1A2 = 4, /* Completed: A0, A1, A2 */
|
|
ECI_A0A1A2B0 = 5, /* Completed: A0, A1, A2, B0 */
|
|
/* All other values reserved */
|
|
};
|
|
|
|
/* Definitions for the PMU registers */
|
|
#define PMCRN_MASK 0xf800
|
|
#define PMCRN_SHIFT 11
|
|
#define PMCRLP 0x80
|
|
#define PMCRLC 0x40
|
|
#define PMCRDP 0x20
|
|
#define PMCRX 0x10
|
|
#define PMCRD 0x8
|
|
#define PMCRC 0x4
|
|
#define PMCRP 0x2
|
|
#define PMCRE 0x1
|
|
/*
|
|
* Mask of PMCR bits writable by guest (not including WO bits like C, P,
|
|
* which can be written as 1 to trigger behaviour but which stay RAZ).
|
|
*/
|
|
#define PMCR_WRITABLE_MASK (PMCRLP | PMCRLC | PMCRDP | PMCRX | PMCRD | PMCRE)
|
|
|
|
#define PMXEVTYPER_P 0x80000000
|
|
#define PMXEVTYPER_U 0x40000000
|
|
#define PMXEVTYPER_NSK 0x20000000
|
|
#define PMXEVTYPER_NSU 0x10000000
|
|
#define PMXEVTYPER_NSH 0x08000000
|
|
#define PMXEVTYPER_M 0x04000000
|
|
#define PMXEVTYPER_MT 0x02000000
|
|
#define PMXEVTYPER_EVTCOUNT 0x0000ffff
|
|
#define PMXEVTYPER_MASK (PMXEVTYPER_P | PMXEVTYPER_U | PMXEVTYPER_NSK | \
|
|
PMXEVTYPER_NSU | PMXEVTYPER_NSH | \
|
|
PMXEVTYPER_M | PMXEVTYPER_MT | \
|
|
PMXEVTYPER_EVTCOUNT)
|
|
|
|
#define PMCCFILTR 0xf8000000
|
|
#define PMCCFILTR_M PMXEVTYPER_M
|
|
#define PMCCFILTR_EL0 (PMCCFILTR | PMCCFILTR_M)
|
|
|
|
static inline uint32_t pmu_num_counters(CPUARMState *env)
|
|
{
|
|
ARMCPU *cpu = env_archcpu(env);
|
|
|
|
return (cpu->isar.reset_pmcr_el0 & PMCRN_MASK) >> PMCRN_SHIFT;
|
|
}
|
|
|
|
/* Bits allowed to be set/cleared for PMCNTEN* and PMINTEN* */
|
|
static inline uint64_t pmu_counter_mask(CPUARMState *env)
|
|
{
|
|
return (1ULL << 31) | ((1ULL << pmu_num_counters(env)) - 1);
|
|
}
|
|
|
|
#ifdef TARGET_AARCH64
|
|
int arm_gdb_get_svereg(CPUARMState *env, GByteArray *buf, int reg);
|
|
int arm_gdb_set_svereg(CPUARMState *env, uint8_t *buf, int reg);
|
|
int aarch64_fpu_gdb_get_reg(CPUARMState *env, GByteArray *buf, int reg);
|
|
int aarch64_fpu_gdb_set_reg(CPUARMState *env, uint8_t *buf, int reg);
|
|
void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp);
|
|
void arm_cpu_sme_finalize(ARMCPU *cpu, Error **errp);
|
|
void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp);
|
|
void arm_cpu_lpa2_finalize(ARMCPU *cpu, Error **errp);
|
|
#endif
|
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
static inline void define_cortex_a72_a57_a53_cp_reginfo(ARMCPU *cpu) { }
|
|
#else
|
|
void define_cortex_a72_a57_a53_cp_reginfo(ARMCPU *cpu);
|
|
#endif
|
|
|
|
bool el_is_in_host(CPUARMState *env, int el);
|
|
|
|
void aa32_max_features(ARMCPU *cpu);
|
|
int exception_target_el(CPUARMState *env);
|
|
bool arm_singlestep_active(CPUARMState *env);
|
|
bool arm_generate_debug_exceptions(CPUARMState *env);
|
|
|
|
/* Add the cpreg definitions for debug related system registers */
|
|
void define_debug_regs(ARMCPU *cpu);
|
|
|
|
/* Effective value of MDCR_EL2 */
|
|
static inline uint64_t arm_mdcr_el2_eff(CPUARMState *env)
|
|
{
|
|
return arm_is_el2_enabled(env) ? env->cp15.mdcr_el2 : 0;
|
|
}
|
|
|
|
/* Powers of 2 for sve_vq_map et al. */
|
|
#define SVE_VQ_POW2_MAP \
|
|
((1 << (1 - 1)) | (1 << (2 - 1)) | \
|
|
(1 << (4 - 1)) | (1 << (8 - 1)) | (1 << (16 - 1)))
|
|
|
|
#endif
|