
* 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>
2896 lines
95 KiB
C
2896 lines
95 KiB
C
/*
|
|
* ARM page table walking.
|
|
*
|
|
* This code is licensed under the GNU GPL v2 or later.
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/log.h"
|
|
#include "qemu/range.h"
|
|
#include "qemu/main-loop.h"
|
|
#include "exec/exec-all.h"
|
|
#include "cpu.h"
|
|
#include "internals.h"
|
|
#include "idau.h"
|
|
|
|
|
|
typedef struct S1Translate {
|
|
ARMMMUIdx in_mmu_idx;
|
|
ARMMMUIdx in_ptw_idx;
|
|
bool in_secure;
|
|
bool in_debug;
|
|
bool out_secure;
|
|
bool out_rw;
|
|
bool out_be;
|
|
hwaddr out_virt;
|
|
hwaddr out_phys;
|
|
void *out_host;
|
|
} S1Translate;
|
|
|
|
static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw,
|
|
uint64_t address,
|
|
MMUAccessType access_type, bool s1_is_el0,
|
|
GetPhysAddrResult *result, ARMMMUFaultInfo *fi)
|
|
__attribute__((nonnull));
|
|
|
|
static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw,
|
|
target_ulong address,
|
|
MMUAccessType access_type,
|
|
GetPhysAddrResult *result,
|
|
ARMMMUFaultInfo *fi)
|
|
__attribute__((nonnull));
|
|
|
|
/* This mapping is common between ID_AA64MMFR0.PARANGE and TCR_ELx.{I}PS. */
|
|
static const uint8_t pamax_map[] = {
|
|
[0] = 32,
|
|
[1] = 36,
|
|
[2] = 40,
|
|
[3] = 42,
|
|
[4] = 44,
|
|
[5] = 48,
|
|
[6] = 52,
|
|
};
|
|
|
|
/* The cpu-specific constant value of PAMax; also used by hw/arm/virt. */
|
|
unsigned int arm_pamax(ARMCPU *cpu)
|
|
{
|
|
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
|
|
unsigned int parange =
|
|
FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE);
|
|
|
|
/*
|
|
* id_aa64mmfr0 is a read-only register so values outside of the
|
|
* supported mappings can be considered an implementation error.
|
|
*/
|
|
assert(parange < ARRAY_SIZE(pamax_map));
|
|
return pamax_map[parange];
|
|
}
|
|
|
|
/*
|
|
* In machvirt_init, we call arm_pamax on a cpu that is not fully
|
|
* initialized, so we can't rely on the propagation done in realize.
|
|
*/
|
|
if (arm_feature(&cpu->env, ARM_FEATURE_LPAE) ||
|
|
arm_feature(&cpu->env, ARM_FEATURE_V7VE)) {
|
|
/* v7 with LPAE */
|
|
return 40;
|
|
}
|
|
/* Anything else */
|
|
return 32;
|
|
}
|
|
|
|
/*
|
|
* Convert a possible stage1+2 MMU index into the appropriate stage 1 MMU index
|
|
*/
|
|
ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx)
|
|
{
|
|
switch (mmu_idx) {
|
|
case ARMMMUIdx_E10_0:
|
|
return ARMMMUIdx_Stage1_E0;
|
|
case ARMMMUIdx_E10_1:
|
|
return ARMMMUIdx_Stage1_E1;
|
|
case ARMMMUIdx_E10_1_PAN:
|
|
return ARMMMUIdx_Stage1_E1_PAN;
|
|
default:
|
|
return mmu_idx;
|
|
}
|
|
}
|
|
|
|
ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env)
|
|
{
|
|
return stage_1_mmu_idx(arm_mmu_idx(env));
|
|
}
|
|
|
|
static bool regime_translation_big_endian(CPUARMState *env, ARMMMUIdx mmu_idx)
|
|
{
|
|
return (regime_sctlr(env, mmu_idx) & SCTLR_EE) != 0;
|
|
}
|
|
|
|
/* Return the TTBR associated with this translation regime */
|
|
static uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, int ttbrn)
|
|
{
|
|
if (mmu_idx == ARMMMUIdx_Stage2) {
|
|
return env->cp15.vttbr_el2;
|
|
}
|
|
if (mmu_idx == ARMMMUIdx_Stage2_S) {
|
|
return env->cp15.vsttbr_el2;
|
|
}
|
|
if (ttbrn == 0) {
|
|
return env->cp15.ttbr0_el[regime_el(env, mmu_idx)];
|
|
} else {
|
|
return env->cp15.ttbr1_el[regime_el(env, mmu_idx)];
|
|
}
|
|
}
|
|
|
|
/* Return true if the specified stage of address translation is disabled */
|
|
static bool regime_translation_disabled(CPUARMState *env, ARMMMUIdx mmu_idx,
|
|
bool is_secure)
|
|
{
|
|
uint64_t hcr_el2;
|
|
|
|
if (arm_feature(env, ARM_FEATURE_M)) {
|
|
switch (env->v7m.mpu_ctrl[is_secure] &
|
|
(R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK)) {
|
|
case R_V7M_MPU_CTRL_ENABLE_MASK:
|
|
/* Enabled, but not for HardFault and NMI */
|
|
return mmu_idx & ARM_MMU_IDX_M_NEGPRI;
|
|
case R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK:
|
|
/* Enabled for all cases */
|
|
return false;
|
|
case 0:
|
|
default:
|
|
/*
|
|
* HFNMIENA set and ENABLE clear is UNPREDICTABLE, but
|
|
* we warned about that in armv7m_nvic.c when the guest set it.
|
|
*/
|
|
return true;
|
|
}
|
|
}
|
|
|
|
hcr_el2 = arm_hcr_el2_eff_secstate(env, is_secure);
|
|
|
|
switch (mmu_idx) {
|
|
case ARMMMUIdx_Stage2:
|
|
case ARMMMUIdx_Stage2_S:
|
|
/* HCR.DC means HCR.VM behaves as 1 */
|
|
return (hcr_el2 & (HCR_DC | HCR_VM)) == 0;
|
|
|
|
case ARMMMUIdx_E10_0:
|
|
case ARMMMUIdx_E10_1:
|
|
case ARMMMUIdx_E10_1_PAN:
|
|
/* TGE means that EL0/1 act as if SCTLR_EL1.M is zero */
|
|
if (hcr_el2 & HCR_TGE) {
|
|
return true;
|
|
}
|
|
break;
|
|
|
|
case ARMMMUIdx_Stage1_E0:
|
|
case ARMMMUIdx_Stage1_E1:
|
|
case ARMMMUIdx_Stage1_E1_PAN:
|
|
/* HCR.DC means SCTLR_EL1.M behaves as 0 */
|
|
if (hcr_el2 & HCR_DC) {
|
|
return true;
|
|
}
|
|
break;
|
|
|
|
case ARMMMUIdx_E20_0:
|
|
case ARMMMUIdx_E20_2:
|
|
case ARMMMUIdx_E20_2_PAN:
|
|
case ARMMMUIdx_E2:
|
|
case ARMMMUIdx_E3:
|
|
break;
|
|
|
|
case ARMMMUIdx_Phys_NS:
|
|
case ARMMMUIdx_Phys_S:
|
|
/* No translation for physical address spaces. */
|
|
return true;
|
|
|
|
default:
|
|
g_assert_not_reached();
|
|
}
|
|
|
|
return (regime_sctlr(env, mmu_idx) & SCTLR_M) == 0;
|
|
}
|
|
|
|
static bool S2_attrs_are_device(uint64_t hcr, uint8_t attrs)
|
|
{
|
|
/*
|
|
* For an S1 page table walk, the stage 1 attributes are always
|
|
* some form of "this is Normal memory". The combined S1+S2
|
|
* attributes are therefore only Device if stage 2 specifies Device.
|
|
* With HCR_EL2.FWB == 0 this is when descriptor bits [5:4] are 0b00,
|
|
* ie when cacheattrs.attrs bits [3:2] are 0b00.
|
|
* With HCR_EL2.FWB == 1 this is when descriptor bit [4] is 0, ie
|
|
* when cacheattrs.attrs bit [2] is 0.
|
|
*/
|
|
if (hcr & HCR_FWB) {
|
|
return (attrs & 0x4) == 0;
|
|
} else {
|
|
return (attrs & 0xc) == 0;
|
|
}
|
|
}
|
|
|
|
/* Translate a S1 pagetable walk through S2 if needed. */
|
|
static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw,
|
|
hwaddr addr, ARMMMUFaultInfo *fi)
|
|
{
|
|
bool is_secure = ptw->in_secure;
|
|
ARMMMUIdx mmu_idx = ptw->in_mmu_idx;
|
|
ARMMMUIdx s2_mmu_idx = ptw->in_ptw_idx;
|
|
uint8_t pte_attrs;
|
|
bool pte_secure;
|
|
|
|
ptw->out_virt = addr;
|
|
|
|
if (unlikely(ptw->in_debug)) {
|
|
/*
|
|
* From gdbstub, do not use softmmu so that we don't modify the
|
|
* state of the cpu at all, including softmmu tlb contents.
|
|
*/
|
|
if (regime_is_stage2(s2_mmu_idx)) {
|
|
S1Translate s2ptw = {
|
|
.in_mmu_idx = s2_mmu_idx,
|
|
.in_ptw_idx = is_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_Phys_NS,
|
|
.in_secure = is_secure,
|
|
.in_debug = true,
|
|
};
|
|
GetPhysAddrResult s2 = { };
|
|
|
|
if (!get_phys_addr_lpae(env, &s2ptw, addr, MMU_DATA_LOAD,
|
|
false, &s2, fi)) {
|
|
goto fail;
|
|
}
|
|
ptw->out_phys = s2.f.phys_addr;
|
|
pte_attrs = s2.cacheattrs.attrs;
|
|
pte_secure = s2.f.attrs.secure;
|
|
} else {
|
|
/* Regime is physical. */
|
|
ptw->out_phys = addr;
|
|
pte_attrs = 0;
|
|
pte_secure = is_secure;
|
|
}
|
|
ptw->out_host = NULL;
|
|
ptw->out_rw = false;
|
|
} else {
|
|
CPUTLBEntryFull *full;
|
|
int flags;
|
|
|
|
env->tlb_fi = fi;
|
|
flags = probe_access_full(env, addr, MMU_DATA_LOAD,
|
|
arm_to_core_mmu_idx(s2_mmu_idx),
|
|
true, &ptw->out_host, &full, 0);
|
|
env->tlb_fi = NULL;
|
|
|
|
if (unlikely(flags & TLB_INVALID_MASK)) {
|
|
goto fail;
|
|
}
|
|
ptw->out_phys = full->phys_addr;
|
|
ptw->out_rw = full->prot & PAGE_WRITE;
|
|
pte_attrs = full->pte_attrs;
|
|
pte_secure = full->attrs.secure;
|
|
}
|
|
|
|
if (regime_is_stage2(s2_mmu_idx)) {
|
|
uint64_t hcr = arm_hcr_el2_eff_secstate(env, is_secure);
|
|
|
|
if ((hcr & HCR_PTW) && S2_attrs_are_device(hcr, pte_attrs)) {
|
|
/*
|
|
* PTW set and S1 walk touched S2 Device memory:
|
|
* generate Permission fault.
|
|
*/
|
|
fi->type = ARMFault_Permission;
|
|
fi->s2addr = addr;
|
|
fi->stage2 = true;
|
|
fi->s1ptw = true;
|
|
fi->s1ns = !is_secure;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/* Check if page table walk is to secure or non-secure PA space. */
|
|
ptw->out_secure = (is_secure
|
|
&& !(pte_secure
|
|
? env->cp15.vstcr_el2 & VSTCR_SW
|
|
: env->cp15.vtcr_el2 & VTCR_NSW));
|
|
ptw->out_be = regime_translation_big_endian(env, mmu_idx);
|
|
return true;
|
|
|
|
fail:
|
|
assert(fi->type != ARMFault_None);
|
|
fi->s2addr = addr;
|
|
fi->stage2 = true;
|
|
fi->s1ptw = true;
|
|
fi->s1ns = !is_secure;
|
|
return false;
|
|
}
|
|
|
|
/* All loads done in the course of a page table walk go through here. */
|
|
static uint32_t arm_ldl_ptw(CPUARMState *env, S1Translate *ptw,
|
|
ARMMMUFaultInfo *fi)
|
|
{
|
|
CPUState *cs = env_cpu(env);
|
|
void *host = ptw->out_host;
|
|
uint32_t data;
|
|
|
|
if (likely(host)) {
|
|
/* Page tables are in RAM, and we have the host address. */
|
|
data = qatomic_read((uint32_t *)host);
|
|
if (ptw->out_be) {
|
|
data = be32_to_cpu(data);
|
|
} else {
|
|
data = le32_to_cpu(data);
|
|
}
|
|
} else {
|
|
/* Page tables are in MMIO. */
|
|
MemTxAttrs attrs = { .secure = ptw->out_secure };
|
|
AddressSpace *as = arm_addressspace(cs, attrs);
|
|
MemTxResult result = MEMTX_OK;
|
|
|
|
if (ptw->out_be) {
|
|
data = address_space_ldl_be(as, ptw->out_phys, attrs, &result);
|
|
} else {
|
|
data = address_space_ldl_le(as, ptw->out_phys, attrs, &result);
|
|
}
|
|
if (unlikely(result != MEMTX_OK)) {
|
|
fi->type = ARMFault_SyncExternalOnWalk;
|
|
fi->ea = arm_extabort_type(result);
|
|
return 0;
|
|
}
|
|
}
|
|
return data;
|
|
}
|
|
|
|
static uint64_t arm_ldq_ptw(CPUARMState *env, S1Translate *ptw,
|
|
ARMMMUFaultInfo *fi)
|
|
{
|
|
CPUState *cs = env_cpu(env);
|
|
void *host = ptw->out_host;
|
|
uint64_t data;
|
|
|
|
if (likely(host)) {
|
|
/* Page tables are in RAM, and we have the host address. */
|
|
#ifdef CONFIG_ATOMIC64
|
|
data = qatomic_read__nocheck((uint64_t *)host);
|
|
if (ptw->out_be) {
|
|
data = be64_to_cpu(data);
|
|
} else {
|
|
data = le64_to_cpu(data);
|
|
}
|
|
#else
|
|
if (ptw->out_be) {
|
|
data = ldq_be_p(host);
|
|
} else {
|
|
data = ldq_le_p(host);
|
|
}
|
|
#endif
|
|
} else {
|
|
/* Page tables are in MMIO. */
|
|
MemTxAttrs attrs = { .secure = ptw->out_secure };
|
|
AddressSpace *as = arm_addressspace(cs, attrs);
|
|
MemTxResult result = MEMTX_OK;
|
|
|
|
if (ptw->out_be) {
|
|
data = address_space_ldq_be(as, ptw->out_phys, attrs, &result);
|
|
} else {
|
|
data = address_space_ldq_le(as, ptw->out_phys, attrs, &result);
|
|
}
|
|
if (unlikely(result != MEMTX_OK)) {
|
|
fi->type = ARMFault_SyncExternalOnWalk;
|
|
fi->ea = arm_extabort_type(result);
|
|
return 0;
|
|
}
|
|
}
|
|
return data;
|
|
}
|
|
|
|
static uint64_t arm_casq_ptw(CPUARMState *env, uint64_t old_val,
|
|
uint64_t new_val, S1Translate *ptw,
|
|
ARMMMUFaultInfo *fi)
|
|
{
|
|
uint64_t cur_val;
|
|
void *host = ptw->out_host;
|
|
|
|
if (unlikely(!host)) {
|
|
fi->type = ARMFault_UnsuppAtomicUpdate;
|
|
fi->s1ptw = true;
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Raising a stage2 Protection fault for an atomic update to a read-only
|
|
* page is delayed until it is certain that there is a change to make.
|
|
*/
|
|
if (unlikely(!ptw->out_rw)) {
|
|
int flags;
|
|
void *discard;
|
|
|
|
env->tlb_fi = fi;
|
|
flags = probe_access_flags(env, ptw->out_virt, MMU_DATA_STORE,
|
|
arm_to_core_mmu_idx(ptw->in_ptw_idx),
|
|
true, &discard, 0);
|
|
env->tlb_fi = NULL;
|
|
|
|
if (unlikely(flags & TLB_INVALID_MASK)) {
|
|
assert(fi->type != ARMFault_None);
|
|
fi->s2addr = ptw->out_virt;
|
|
fi->stage2 = true;
|
|
fi->s1ptw = true;
|
|
fi->s1ns = !ptw->in_secure;
|
|
return 0;
|
|
}
|
|
|
|
/* In case CAS mismatches and we loop, remember writability. */
|
|
ptw->out_rw = true;
|
|
}
|
|
|
|
#ifdef CONFIG_ATOMIC64
|
|
if (ptw->out_be) {
|
|
old_val = cpu_to_be64(old_val);
|
|
new_val = cpu_to_be64(new_val);
|
|
cur_val = qatomic_cmpxchg__nocheck((uint64_t *)host, old_val, new_val);
|
|
cur_val = be64_to_cpu(cur_val);
|
|
} else {
|
|
old_val = cpu_to_le64(old_val);
|
|
new_val = cpu_to_le64(new_val);
|
|
cur_val = qatomic_cmpxchg__nocheck((uint64_t *)host, old_val, new_val);
|
|
cur_val = le64_to_cpu(cur_val);
|
|
}
|
|
#else
|
|
/*
|
|
* We can't support the full 64-bit atomic cmpxchg on the host.
|
|
* Because this is only used for FEAT_HAFDBS, which is only for AA64,
|
|
* we know that TCG_OVERSIZED_GUEST is set, which means that we are
|
|
* running in round-robin mode and could only race with dma i/o.
|
|
*/
|
|
#ifndef TCG_OVERSIZED_GUEST
|
|
# error "Unexpected configuration"
|
|
#endif
|
|
bool locked = qemu_mutex_iothread_locked();
|
|
if (!locked) {
|
|
qemu_mutex_lock_iothread();
|
|
}
|
|
if (ptw->out_be) {
|
|
cur_val = ldq_be_p(host);
|
|
if (cur_val == old_val) {
|
|
stq_be_p(host, new_val);
|
|
}
|
|
} else {
|
|
cur_val = ldq_le_p(host);
|
|
if (cur_val == old_val) {
|
|
stq_le_p(host, new_val);
|
|
}
|
|
}
|
|
if (!locked) {
|
|
qemu_mutex_unlock_iothread();
|
|
}
|
|
#endif
|
|
|
|
return cur_val;
|
|
}
|
|
|
|
static bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx,
|
|
uint32_t *table, uint32_t address)
|
|
{
|
|
/* Note that we can only get here for an AArch32 PL0/PL1 lookup */
|
|
uint64_t tcr = regime_tcr(env, mmu_idx);
|
|
int maskshift = extract32(tcr, 0, 3);
|
|
uint32_t mask = ~(((uint32_t)0xffffffffu) >> maskshift);
|
|
uint32_t base_mask;
|
|
|
|
if (address & mask) {
|
|
if (tcr & TTBCR_PD1) {
|
|
/* Translation table walk disabled for TTBR1 */
|
|
return false;
|
|
}
|
|
*table = regime_ttbr(env, mmu_idx, 1) & 0xffffc000;
|
|
} else {
|
|
if (tcr & TTBCR_PD0) {
|
|
/* Translation table walk disabled for TTBR0 */
|
|
return false;
|
|
}
|
|
base_mask = ~((uint32_t)0x3fffu >> maskshift);
|
|
*table = regime_ttbr(env, mmu_idx, 0) & base_mask;
|
|
}
|
|
*table |= (address >> 18) & 0x3ffc;
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
* Translate section/page access permissions to page R/W protection flags
|
|
* @env: CPUARMState
|
|
* @mmu_idx: MMU index indicating required translation regime
|
|
* @ap: The 3-bit access permissions (AP[2:0])
|
|
* @domain_prot: The 2-bit domain access permissions
|
|
* @is_user: TRUE if accessing from PL0
|
|
*/
|
|
static int ap_to_rw_prot_is_user(CPUARMState *env, ARMMMUIdx mmu_idx,
|
|
int ap, int domain_prot, bool is_user)
|
|
{
|
|
if (domain_prot == 3) {
|
|
return PAGE_READ | PAGE_WRITE;
|
|
}
|
|
|
|
switch (ap) {
|
|
case 0:
|
|
if (arm_feature(env, ARM_FEATURE_V7)) {
|
|
return 0;
|
|
}
|
|
switch (regime_sctlr(env, mmu_idx) & (SCTLR_S | SCTLR_R)) {
|
|
case SCTLR_S:
|
|
return is_user ? 0 : PAGE_READ;
|
|
case SCTLR_R:
|
|
return PAGE_READ;
|
|
default:
|
|
return 0;
|
|
}
|
|
case 1:
|
|
return is_user ? 0 : PAGE_READ | PAGE_WRITE;
|
|
case 2:
|
|
if (is_user) {
|
|
return PAGE_READ;
|
|
} else {
|
|
return PAGE_READ | PAGE_WRITE;
|
|
}
|
|
case 3:
|
|
return PAGE_READ | PAGE_WRITE;
|
|
case 4: /* Reserved. */
|
|
return 0;
|
|
case 5:
|
|
return is_user ? 0 : PAGE_READ;
|
|
case 6:
|
|
return PAGE_READ;
|
|
case 7:
|
|
if (!arm_feature(env, ARM_FEATURE_V6K)) {
|
|
return 0;
|
|
}
|
|
return PAGE_READ;
|
|
default:
|
|
g_assert_not_reached();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Translate section/page access permissions to page R/W protection flags
|
|
* @env: CPUARMState
|
|
* @mmu_idx: MMU index indicating required translation regime
|
|
* @ap: The 3-bit access permissions (AP[2:0])
|
|
* @domain_prot: The 2-bit domain access permissions
|
|
*/
|
|
static int ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx,
|
|
int ap, int domain_prot)
|
|
{
|
|
return ap_to_rw_prot_is_user(env, mmu_idx, ap, domain_prot,
|
|
regime_is_user(env, mmu_idx));
|
|
}
|
|
|
|
/*
|
|
* Translate section/page access permissions to page R/W protection flags.
|
|
* @ap: The 2-bit simple AP (AP[2:1])
|
|
* @is_user: TRUE if accessing from PL0
|
|
*/
|
|
static int simple_ap_to_rw_prot_is_user(int ap, bool is_user)
|
|
{
|
|
switch (ap) {
|
|
case 0:
|
|
return is_user ? 0 : PAGE_READ | PAGE_WRITE;
|
|
case 1:
|
|
return PAGE_READ | PAGE_WRITE;
|
|
case 2:
|
|
return is_user ? 0 : PAGE_READ;
|
|
case 3:
|
|
return PAGE_READ;
|
|
default:
|
|
g_assert_not_reached();
|
|
}
|
|
}
|
|
|
|
static int simple_ap_to_rw_prot(CPUARMState *env, ARMMMUIdx mmu_idx, int ap)
|
|
{
|
|
return simple_ap_to_rw_prot_is_user(ap, regime_is_user(env, mmu_idx));
|
|
}
|
|
|
|
static bool get_phys_addr_v5(CPUARMState *env, S1Translate *ptw,
|
|
uint32_t address, MMUAccessType access_type,
|
|
GetPhysAddrResult *result, ARMMMUFaultInfo *fi)
|
|
{
|
|
int level = 1;
|
|
uint32_t table;
|
|
uint32_t desc;
|
|
int type;
|
|
int ap;
|
|
int domain = 0;
|
|
int domain_prot;
|
|
hwaddr phys_addr;
|
|
uint32_t dacr;
|
|
|
|
/* Pagetable walk. */
|
|
/* Lookup l1 descriptor. */
|
|
if (!get_level1_table_address(env, ptw->in_mmu_idx, &table, address)) {
|
|
/* Section translation fault if page walk is disabled by PD0 or PD1 */
|
|
fi->type = ARMFault_Translation;
|
|
goto do_fault;
|
|
}
|
|
if (!S1_ptw_translate(env, ptw, table, fi)) {
|
|
goto do_fault;
|
|
}
|
|
desc = arm_ldl_ptw(env, ptw, fi);
|
|
if (fi->type != ARMFault_None) {
|
|
goto do_fault;
|
|
}
|
|
type = (desc & 3);
|
|
domain = (desc >> 5) & 0x0f;
|
|
if (regime_el(env, ptw->in_mmu_idx) == 1) {
|
|
dacr = env->cp15.dacr_ns;
|
|
} else {
|
|
dacr = env->cp15.dacr_s;
|
|
}
|
|
domain_prot = (dacr >> (domain * 2)) & 3;
|
|
if (type == 0) {
|
|
/* Section translation fault. */
|
|
fi->type = ARMFault_Translation;
|
|
goto do_fault;
|
|
}
|
|
if (type != 2) {
|
|
level = 2;
|
|
}
|
|
if (domain_prot == 0 || domain_prot == 2) {
|
|
fi->type = ARMFault_Domain;
|
|
goto do_fault;
|
|
}
|
|
if (type == 2) {
|
|
/* 1Mb section. */
|
|
phys_addr = (desc & 0xfff00000) | (address & 0x000fffff);
|
|
ap = (desc >> 10) & 3;
|
|
result->f.lg_page_size = 20; /* 1MB */
|
|
} else {
|
|
/* Lookup l2 entry. */
|
|
if (type == 1) {
|
|
/* Coarse pagetable. */
|
|
table = (desc & 0xfffffc00) | ((address >> 10) & 0x3fc);
|
|
} else {
|
|
/* Fine pagetable. */
|
|
table = (desc & 0xfffff000) | ((address >> 8) & 0xffc);
|
|
}
|
|
if (!S1_ptw_translate(env, ptw, table, fi)) {
|
|
goto do_fault;
|
|
}
|
|
desc = arm_ldl_ptw(env, ptw, fi);
|
|
if (fi->type != ARMFault_None) {
|
|
goto do_fault;
|
|
}
|
|
switch (desc & 3) {
|
|
case 0: /* Page translation fault. */
|
|
fi->type = ARMFault_Translation;
|
|
goto do_fault;
|
|
case 1: /* 64k page. */
|
|
phys_addr = (desc & 0xffff0000) | (address & 0xffff);
|
|
ap = (desc >> (4 + ((address >> 13) & 6))) & 3;
|
|
result->f.lg_page_size = 16;
|
|
break;
|
|
case 2: /* 4k page. */
|
|
phys_addr = (desc & 0xfffff000) | (address & 0xfff);
|
|
ap = (desc >> (4 + ((address >> 9) & 6))) & 3;
|
|
result->f.lg_page_size = 12;
|
|
break;
|
|
case 3: /* 1k page, or ARMv6/XScale "extended small (4k) page" */
|
|
if (type == 1) {
|
|
/* ARMv6/XScale extended small page format */
|
|
if (arm_feature(env, ARM_FEATURE_XSCALE)
|
|
|| arm_feature(env, ARM_FEATURE_V6)) {
|
|
phys_addr = (desc & 0xfffff000) | (address & 0xfff);
|
|
result->f.lg_page_size = 12;
|
|
} else {
|
|
/*
|
|
* UNPREDICTABLE in ARMv5; we choose to take a
|
|
* page translation fault.
|
|
*/
|
|
fi->type = ARMFault_Translation;
|
|
goto do_fault;
|
|
}
|
|
} else {
|
|
phys_addr = (desc & 0xfffffc00) | (address & 0x3ff);
|
|
result->f.lg_page_size = 10;
|
|
}
|
|
ap = (desc >> 4) & 3;
|
|
break;
|
|
default:
|
|
/* Never happens, but compiler isn't smart enough to tell. */
|
|
g_assert_not_reached();
|
|
}
|
|
}
|
|
result->f.prot = ap_to_rw_prot(env, ptw->in_mmu_idx, ap, domain_prot);
|
|
result->f.prot |= result->f.prot ? PAGE_EXEC : 0;
|
|
if (!(result->f.prot & (1 << access_type))) {
|
|
/* Access permission fault. */
|
|
fi->type = ARMFault_Permission;
|
|
goto do_fault;
|
|
}
|
|
result->f.phys_addr = phys_addr;
|
|
return false;
|
|
do_fault:
|
|
fi->domain = domain;
|
|
fi->level = level;
|
|
return true;
|
|
}
|
|
|
|
static bool get_phys_addr_v6(CPUARMState *env, S1Translate *ptw,
|
|
uint32_t address, MMUAccessType access_type,
|
|
GetPhysAddrResult *result, ARMMMUFaultInfo *fi)
|
|
{
|
|
ARMCPU *cpu = env_archcpu(env);
|
|
ARMMMUIdx mmu_idx = ptw->in_mmu_idx;
|
|
int level = 1;
|
|
uint32_t table;
|
|
uint32_t desc;
|
|
uint32_t xn;
|
|
uint32_t pxn = 0;
|
|
int type;
|
|
int ap;
|
|
int domain = 0;
|
|
int domain_prot;
|
|
hwaddr phys_addr;
|
|
uint32_t dacr;
|
|
bool ns;
|
|
int user_prot;
|
|
|
|
/* Pagetable walk. */
|
|
/* Lookup l1 descriptor. */
|
|
if (!get_level1_table_address(env, mmu_idx, &table, address)) {
|
|
/* Section translation fault if page walk is disabled by PD0 or PD1 */
|
|
fi->type = ARMFault_Translation;
|
|
goto do_fault;
|
|
}
|
|
if (!S1_ptw_translate(env, ptw, table, fi)) {
|
|
goto do_fault;
|
|
}
|
|
desc = arm_ldl_ptw(env, ptw, fi);
|
|
if (fi->type != ARMFault_None) {
|
|
goto do_fault;
|
|
}
|
|
type = (desc & 3);
|
|
if (type == 0 || (type == 3 && !cpu_isar_feature(aa32_pxn, cpu))) {
|
|
/* Section translation fault, or attempt to use the encoding
|
|
* which is Reserved on implementations without PXN.
|
|
*/
|
|
fi->type = ARMFault_Translation;
|
|
goto do_fault;
|
|
}
|
|
if ((type == 1) || !(desc & (1 << 18))) {
|
|
/* Page or Section. */
|
|
domain = (desc >> 5) & 0x0f;
|
|
}
|
|
if (regime_el(env, mmu_idx) == 1) {
|
|
dacr = env->cp15.dacr_ns;
|
|
} else {
|
|
dacr = env->cp15.dacr_s;
|
|
}
|
|
if (type == 1) {
|
|
level = 2;
|
|
}
|
|
domain_prot = (dacr >> (domain * 2)) & 3;
|
|
if (domain_prot == 0 || domain_prot == 2) {
|
|
/* Section or Page domain fault */
|
|
fi->type = ARMFault_Domain;
|
|
goto do_fault;
|
|
}
|
|
if (type != 1) {
|
|
if (desc & (1 << 18)) {
|
|
/* Supersection. */
|
|
phys_addr = (desc & 0xff000000) | (address & 0x00ffffff);
|
|
phys_addr |= (uint64_t)extract32(desc, 20, 4) << 32;
|
|
phys_addr |= (uint64_t)extract32(desc, 5, 4) << 36;
|
|
result->f.lg_page_size = 24; /* 16MB */
|
|
} else {
|
|
/* Section. */
|
|
phys_addr = (desc & 0xfff00000) | (address & 0x000fffff);
|
|
result->f.lg_page_size = 20; /* 1MB */
|
|
}
|
|
ap = ((desc >> 10) & 3) | ((desc >> 13) & 4);
|
|
xn = desc & (1 << 4);
|
|
pxn = desc & 1;
|
|
ns = extract32(desc, 19, 1);
|
|
} else {
|
|
if (cpu_isar_feature(aa32_pxn, cpu)) {
|
|
pxn = (desc >> 2) & 1;
|
|
}
|
|
ns = extract32(desc, 3, 1);
|
|
/* Lookup l2 entry. */
|
|
table = (desc & 0xfffffc00) | ((address >> 10) & 0x3fc);
|
|
if (!S1_ptw_translate(env, ptw, table, fi)) {
|
|
goto do_fault;
|
|
}
|
|
desc = arm_ldl_ptw(env, ptw, fi);
|
|
if (fi->type != ARMFault_None) {
|
|
goto do_fault;
|
|
}
|
|
ap = ((desc >> 4) & 3) | ((desc >> 7) & 4);
|
|
switch (desc & 3) {
|
|
case 0: /* Page translation fault. */
|
|
fi->type = ARMFault_Translation;
|
|
goto do_fault;
|
|
case 1: /* 64k page. */
|
|
phys_addr = (desc & 0xffff0000) | (address & 0xffff);
|
|
xn = desc & (1 << 15);
|
|
result->f.lg_page_size = 16;
|
|
break;
|
|
case 2: case 3: /* 4k page. */
|
|
phys_addr = (desc & 0xfffff000) | (address & 0xfff);
|
|
xn = desc & 1;
|
|
result->f.lg_page_size = 12;
|
|
break;
|
|
default:
|
|
/* Never happens, but compiler isn't smart enough to tell. */
|
|
g_assert_not_reached();
|
|
}
|
|
}
|
|
if (domain_prot == 3) {
|
|
result->f.prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
|
} else {
|
|
if (pxn && !regime_is_user(env, mmu_idx)) {
|
|
xn = 1;
|
|
}
|
|
if (xn && access_type == MMU_INST_FETCH) {
|
|
fi->type = ARMFault_Permission;
|
|
goto do_fault;
|
|
}
|
|
|
|
if (arm_feature(env, ARM_FEATURE_V6K) &&
|
|
(regime_sctlr(env, mmu_idx) & SCTLR_AFE)) {
|
|
/* The simplified model uses AP[0] as an access control bit. */
|
|
if ((ap & 1) == 0) {
|
|
/* Access flag fault. */
|
|
fi->type = ARMFault_AccessFlag;
|
|
goto do_fault;
|
|
}
|
|
result->f.prot = simple_ap_to_rw_prot(env, mmu_idx, ap >> 1);
|
|
user_prot = simple_ap_to_rw_prot_is_user(ap >> 1, 1);
|
|
} else {
|
|
result->f.prot = ap_to_rw_prot(env, mmu_idx, ap, domain_prot);
|
|
user_prot = ap_to_rw_prot_is_user(env, mmu_idx, ap, domain_prot, 1);
|
|
}
|
|
if (result->f.prot && !xn) {
|
|
result->f.prot |= PAGE_EXEC;
|
|
}
|
|
if (!(result->f.prot & (1 << access_type))) {
|
|
/* Access permission fault. */
|
|
fi->type = ARMFault_Permission;
|
|
goto do_fault;
|
|
}
|
|
if (regime_is_pan(env, mmu_idx) &&
|
|
!regime_is_user(env, mmu_idx) &&
|
|
user_prot &&
|
|
access_type != MMU_INST_FETCH) {
|
|
/* Privileged Access Never fault */
|
|
fi->type = ARMFault_Permission;
|
|
goto do_fault;
|
|
}
|
|
}
|
|
if (ns) {
|
|
/* The NS bit will (as required by the architecture) have no effect if
|
|
* the CPU doesn't support TZ or this is a non-secure translation
|
|
* regime, because the attribute will already be non-secure.
|
|
*/
|
|
result->f.attrs.secure = false;
|
|
}
|
|
result->f.phys_addr = phys_addr;
|
|
return false;
|
|
do_fault:
|
|
fi->domain = domain;
|
|
fi->level = level;
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
* Translate S2 section/page access permissions to protection flags
|
|
* @env: CPUARMState
|
|
* @s2ap: The 2-bit stage2 access permissions (S2AP)
|
|
* @xn: XN (execute-never) bits
|
|
* @s1_is_el0: true if this is S2 of an S1+2 walk for EL0
|
|
*/
|
|
static int get_S2prot(CPUARMState *env, int s2ap, int xn, bool s1_is_el0)
|
|
{
|
|
int prot = 0;
|
|
|
|
if (s2ap & 1) {
|
|
prot |= PAGE_READ;
|
|
}
|
|
if (s2ap & 2) {
|
|
prot |= PAGE_WRITE;
|
|
}
|
|
|
|
if (cpu_isar_feature(any_tts2uxn, env_archcpu(env))) {
|
|
switch (xn) {
|
|
case 0:
|
|
prot |= PAGE_EXEC;
|
|
break;
|
|
case 1:
|
|
if (s1_is_el0) {
|
|
prot |= PAGE_EXEC;
|
|
}
|
|
break;
|
|
case 2:
|
|
break;
|
|
case 3:
|
|
if (!s1_is_el0) {
|
|
prot |= PAGE_EXEC;
|
|
}
|
|
break;
|
|
default:
|
|
g_assert_not_reached();
|
|
}
|
|
} else {
|
|
if (!extract32(xn, 1, 1)) {
|
|
if (arm_el_is_aa64(env, 2) || prot & PAGE_READ) {
|
|
prot |= PAGE_EXEC;
|
|
}
|
|
}
|
|
}
|
|
return prot;
|
|
}
|
|
|
|
/*
|
|
* Translate section/page access permissions to protection flags
|
|
* @env: CPUARMState
|
|
* @mmu_idx: MMU index indicating required translation regime
|
|
* @is_aa64: TRUE if AArch64
|
|
* @ap: The 2-bit simple AP (AP[2:1])
|
|
* @ns: NS (non-secure) bit
|
|
* @xn: XN (execute-never) bit
|
|
* @pxn: PXN (privileged execute-never) bit
|
|
*/
|
|
static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64,
|
|
int ap, int ns, int xn, int pxn)
|
|
{
|
|
bool is_user = regime_is_user(env, mmu_idx);
|
|
int prot_rw, user_rw;
|
|
bool have_wxn;
|
|
int wxn = 0;
|
|
|
|
assert(!regime_is_stage2(mmu_idx));
|
|
|
|
user_rw = simple_ap_to_rw_prot_is_user(ap, true);
|
|
if (is_user) {
|
|
prot_rw = user_rw;
|
|
} else {
|
|
if (user_rw && regime_is_pan(env, mmu_idx)) {
|
|
/* PAN forbids data accesses but doesn't affect insn fetch */
|
|
prot_rw = 0;
|
|
} else {
|
|
prot_rw = simple_ap_to_rw_prot_is_user(ap, false);
|
|
}
|
|
}
|
|
|
|
if (ns && arm_is_secure(env) && (env->cp15.scr_el3 & SCR_SIF)) {
|
|
return prot_rw;
|
|
}
|
|
|
|
/* TODO have_wxn should be replaced with
|
|
* ARM_FEATURE_V8 || (ARM_FEATURE_V7 && ARM_FEATURE_EL2)
|
|
* when ARM_FEATURE_EL2 starts getting set. For now we assume all LPAE
|
|
* compatible processors have EL2, which is required for [U]WXN.
|
|
*/
|
|
have_wxn = arm_feature(env, ARM_FEATURE_LPAE);
|
|
|
|
if (have_wxn) {
|
|
wxn = regime_sctlr(env, mmu_idx) & SCTLR_WXN;
|
|
}
|
|
|
|
if (is_aa64) {
|
|
if (regime_has_2_ranges(mmu_idx) && !is_user) {
|
|
xn = pxn || (user_rw & PAGE_WRITE);
|
|
}
|
|
} else if (arm_feature(env, ARM_FEATURE_V7)) {
|
|
switch (regime_el(env, mmu_idx)) {
|
|
case 1:
|
|
case 3:
|
|
if (is_user) {
|
|
xn = xn || !(user_rw & PAGE_READ);
|
|
} else {
|
|
int uwxn = 0;
|
|
if (have_wxn) {
|
|
uwxn = regime_sctlr(env, mmu_idx) & SCTLR_UWXN;
|
|
}
|
|
xn = xn || !(prot_rw & PAGE_READ) || pxn ||
|
|
(uwxn && (user_rw & PAGE_WRITE));
|
|
}
|
|
break;
|
|
case 2:
|
|
break;
|
|
}
|
|
} else {
|
|
xn = wxn = 0;
|
|
}
|
|
|
|
if (xn || (wxn && (prot_rw & PAGE_WRITE))) {
|
|
return prot_rw;
|
|
}
|
|
return prot_rw | PAGE_EXEC;
|
|
}
|
|
|
|
static ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va,
|
|
ARMMMUIdx mmu_idx)
|
|
{
|
|
uint64_t tcr = regime_tcr(env, mmu_idx);
|
|
uint32_t el = regime_el(env, mmu_idx);
|
|
int select, tsz;
|
|
bool epd, hpd;
|
|
|
|
assert(mmu_idx != ARMMMUIdx_Stage2_S);
|
|
|
|
if (mmu_idx == ARMMMUIdx_Stage2) {
|
|
/* VTCR */
|
|
bool sext = extract32(tcr, 4, 1);
|
|
bool sign = extract32(tcr, 3, 1);
|
|
|
|
/*
|
|
* If the sign-extend bit is not the same as t0sz[3], the result
|
|
* is unpredictable. Flag this as a guest error.
|
|
*/
|
|
if (sign != sext) {
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
"AArch32: VTCR.S / VTCR.T0SZ[3] mismatch\n");
|
|
}
|
|
tsz = sextract32(tcr, 0, 4) + 8;
|
|
select = 0;
|
|
hpd = false;
|
|
epd = false;
|
|
} else if (el == 2) {
|
|
/* HTCR */
|
|
tsz = extract32(tcr, 0, 3);
|
|
select = 0;
|
|
hpd = extract64(tcr, 24, 1);
|
|
epd = false;
|
|
} else {
|
|
int t0sz = extract32(tcr, 0, 3);
|
|
int t1sz = extract32(tcr, 16, 3);
|
|
|
|
if (t1sz == 0) {
|
|
select = va > (0xffffffffu >> t0sz);
|
|
} else {
|
|
/* Note that we will detect errors later. */
|
|
select = va >= ~(0xffffffffu >> t1sz);
|
|
}
|
|
if (!select) {
|
|
tsz = t0sz;
|
|
epd = extract32(tcr, 7, 1);
|
|
hpd = extract64(tcr, 41, 1);
|
|
} else {
|
|
tsz = t1sz;
|
|
epd = extract32(tcr, 23, 1);
|
|
hpd = extract64(tcr, 42, 1);
|
|
}
|
|
/* For aarch32, hpd0 is not enabled without t2e as well. */
|
|
hpd &= extract32(tcr, 6, 1);
|
|
}
|
|
|
|
return (ARMVAParameters) {
|
|
.tsz = tsz,
|
|
.select = select,
|
|
.epd = epd,
|
|
.hpd = hpd,
|
|
};
|
|
}
|
|
|
|
/*
|
|
* check_s2_mmu_setup
|
|
* @cpu: ARMCPU
|
|
* @is_aa64: True if the translation regime is in AArch64 state
|
|
* @startlevel: Suggested starting level
|
|
* @inputsize: Bitsize of IPAs
|
|
* @stride: Page-table stride (See the ARM ARM)
|
|
*
|
|
* Returns true if the suggested S2 translation parameters are OK and
|
|
* false otherwise.
|
|
*/
|
|
static bool check_s2_mmu_setup(ARMCPU *cpu, bool is_aa64, int level,
|
|
int inputsize, int stride, int outputsize)
|
|
{
|
|
const int grainsize = stride + 3;
|
|
int startsizecheck;
|
|
|
|
/*
|
|
* Negative levels are usually not allowed...
|
|
* Except for FEAT_LPA2, 4k page table, 52-bit address space, which
|
|
* begins with level -1. Note that previous feature tests will have
|
|
* eliminated this combination if it is not enabled.
|
|
*/
|
|
if (level < (inputsize == 52 && stride == 9 ? -1 : 0)) {
|
|
return false;
|
|
}
|
|
|
|
startsizecheck = inputsize - ((3 - level) * stride + grainsize);
|
|
if (startsizecheck < 1 || startsizecheck > stride + 4) {
|
|
return false;
|
|
}
|
|
|
|
if (is_aa64) {
|
|
switch (stride) {
|
|
case 13: /* 64KB Pages. */
|
|
if (level == 0 || (level == 1 && outputsize <= 42)) {
|
|
return false;
|
|
}
|
|
break;
|
|
case 11: /* 16KB Pages. */
|
|
if (level == 0 || (level == 1 && outputsize <= 40)) {
|
|
return false;
|
|
}
|
|
break;
|
|
case 9: /* 4KB Pages. */
|
|
if (level == 0 && outputsize <= 42) {
|
|
return false;
|
|
}
|
|
break;
|
|
default:
|
|
g_assert_not_reached();
|
|
}
|
|
|
|
/* Inputsize checks. */
|
|
if (inputsize > outputsize &&
|
|
(arm_el_is_aa64(&cpu->env, 1) || inputsize > 40)) {
|
|
/* This is CONSTRAINED UNPREDICTABLE and we choose to fault. */
|
|
return false;
|
|
}
|
|
} else {
|
|
/* AArch32 only supports 4KB pages. Assert on that. */
|
|
assert(stride == 9);
|
|
|
|
if (level == 0) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* get_phys_addr_lpae: perform one stage of page table walk, LPAE format
|
|
*
|
|
* 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 long-format DFSR/IFSR fault register, with the following caveat:
|
|
* the WnR bit is never set (the caller must do this).
|
|
*
|
|
* @env: CPUARMState
|
|
* @ptw: Current and next stage parameters for the walk.
|
|
* @address: virtual address to get physical address for
|
|
* @access_type: MMU_DATA_LOAD, MMU_DATA_STORE or MMU_INST_FETCH
|
|
* @s1_is_el0: if @ptw->in_mmu_idx is ARMMMUIdx_Stage2
|
|
* (so this is a stage 2 page table walk),
|
|
* must be true if this is stage 2 of a stage 1+2
|
|
* walk for an EL0 access. If @mmu_idx is anything else,
|
|
* @s1_is_el0 is ignored.
|
|
* @result: set on translation success,
|
|
* @fi: set to fault info if the translation fails
|
|
*/
|
|
static bool get_phys_addr_lpae(CPUARMState *env, S1Translate *ptw,
|
|
uint64_t address,
|
|
MMUAccessType access_type, bool s1_is_el0,
|
|
GetPhysAddrResult *result, ARMMMUFaultInfo *fi)
|
|
{
|
|
ARMCPU *cpu = env_archcpu(env);
|
|
ARMMMUIdx mmu_idx = ptw->in_mmu_idx;
|
|
bool is_secure = ptw->in_secure;
|
|
int32_t level;
|
|
ARMVAParameters param;
|
|
uint64_t ttbr;
|
|
hwaddr descaddr, indexmask, indexmask_grainsize;
|
|
uint32_t tableattrs;
|
|
target_ulong page_size;
|
|
uint64_t attrs;
|
|
int32_t stride;
|
|
int addrsize, inputsize, outputsize;
|
|
uint64_t tcr = regime_tcr(env, mmu_idx);
|
|
int ap, ns, xn, pxn;
|
|
uint32_t el = regime_el(env, mmu_idx);
|
|
uint64_t descaddrmask;
|
|
bool aarch64 = arm_el_is_aa64(env, el);
|
|
uint64_t descriptor, new_descriptor;
|
|
bool nstable;
|
|
|
|
/* TODO: This code does not support shareability levels. */
|
|
if (aarch64) {
|
|
int ps;
|
|
|
|
param = aa64_va_parameters(env, address, mmu_idx,
|
|
access_type != MMU_INST_FETCH);
|
|
level = 0;
|
|
|
|
/*
|
|
* If TxSZ is programmed to a value larger than the maximum,
|
|
* or smaller than the effective minimum, it is IMPLEMENTATION
|
|
* DEFINED whether we behave as if the field were programmed
|
|
* within bounds, or if a level 0 Translation fault is generated.
|
|
*
|
|
* With FEAT_LVA, fault on less than minimum becomes required,
|
|
* so our choice is to always raise the fault.
|
|
*/
|
|
if (param.tsz_oob) {
|
|
goto do_translation_fault;
|
|
}
|
|
|
|
addrsize = 64 - 8 * param.tbi;
|
|
inputsize = 64 - param.tsz;
|
|
|
|
/*
|
|
* Bound PS by PARANGE to find the effective output address size.
|
|
* ID_AA64MMFR0 is a read-only register so values outside of the
|
|
* supported mappings can be considered an implementation error.
|
|
*/
|
|
ps = FIELD_EX64(cpu->isar.id_aa64mmfr0, ID_AA64MMFR0, PARANGE);
|
|
ps = MIN(ps, param.ps);
|
|
assert(ps < ARRAY_SIZE(pamax_map));
|
|
outputsize = pamax_map[ps];
|
|
|
|
/*
|
|
* With LPA2, the effective output address (OA) size is at most 48 bits
|
|
* unless TCR.DS == 1
|
|
*/
|
|
if (!param.ds && param.gran != Gran64K) {
|
|
outputsize = MIN(outputsize, 48);
|
|
}
|
|
} else {
|
|
param = aa32_va_parameters(env, address, mmu_idx);
|
|
level = 1;
|
|
addrsize = (mmu_idx == ARMMMUIdx_Stage2 ? 40 : 32);
|
|
inputsize = addrsize - param.tsz;
|
|
outputsize = 40;
|
|
}
|
|
|
|
/*
|
|
* We determined the region when collecting the parameters, but we
|
|
* have not yet validated that the address is valid for the region.
|
|
* Extract the top bits and verify that they all match select.
|
|
*
|
|
* For aa32, if inputsize == addrsize, then we have selected the
|
|
* region by exclusion in aa32_va_parameters and there is no more
|
|
* validation to do here.
|
|
*/
|
|
if (inputsize < addrsize) {
|
|
target_ulong top_bits = sextract64(address, inputsize,
|
|
addrsize - inputsize);
|
|
if (-top_bits != param.select) {
|
|
/* The gap between the two regions is a Translation fault */
|
|
goto do_translation_fault;
|
|
}
|
|
}
|
|
|
|
stride = arm_granule_bits(param.gran) - 3;
|
|
|
|
/*
|
|
* Note that QEMU ignores shareability and cacheability attributes,
|
|
* so we don't need to do anything with the SH, ORGN, IRGN fields
|
|
* in the TTBCR. Similarly, TTBCR:A1 selects whether we get the
|
|
* ASID from TTBR0 or TTBR1, but QEMU's TLB doesn't currently
|
|
* implement any ASID-like capability so we can ignore it (instead
|
|
* we will always flush the TLB any time the ASID is changed).
|
|
*/
|
|
ttbr = regime_ttbr(env, mmu_idx, param.select);
|
|
|
|
/*
|
|
* Here we should have set up all the parameters for the translation:
|
|
* inputsize, ttbr, epd, stride, tbi
|
|
*/
|
|
|
|
if (param.epd) {
|
|
/*
|
|
* Translation table walk disabled => Translation fault on TLB miss
|
|
* Note: This is always 0 on 64-bit EL2 and EL3.
|
|
*/
|
|
goto do_translation_fault;
|
|
}
|
|
|
|
if (!regime_is_stage2(mmu_idx)) {
|
|
/*
|
|
* The starting level depends on the virtual address size (which can
|
|
* be up to 48 bits) and the translation granule size. It indicates
|
|
* the number of strides (stride bits at a time) needed to
|
|
* consume the bits of the input address. In the pseudocode this is:
|
|
* level = 4 - RoundUp((inputsize - grainsize) / stride)
|
|
* where their 'inputsize' is our 'inputsize', 'grainsize' is
|
|
* our 'stride + 3' and 'stride' is our 'stride'.
|
|
* Applying the usual "rounded up m/n is (m+n-1)/n" and simplifying:
|
|
* = 4 - (inputsize - stride - 3 + stride - 1) / stride
|
|
* = 4 - (inputsize - 4) / stride;
|
|
*/
|
|
level = 4 - (inputsize - 4) / stride;
|
|
} else {
|
|
/*
|
|
* For stage 2 translations the starting level is specified by the
|
|
* VTCR_EL2.SL0 field (whose interpretation depends on the page size)
|
|
*/
|
|
uint32_t sl0 = extract32(tcr, 6, 2);
|
|
uint32_t sl2 = extract64(tcr, 33, 1);
|
|
int32_t startlevel;
|
|
bool ok;
|
|
|
|
/* SL2 is RES0 unless DS=1 & 4kb granule. */
|
|
if (param.ds && stride == 9 && sl2) {
|
|
if (sl0 != 0) {
|
|
level = 0;
|
|
goto do_translation_fault;
|
|
}
|
|
startlevel = -1;
|
|
} else if (!aarch64 || stride == 9) {
|
|
/* AArch32 or 4KB pages */
|
|
startlevel = 2 - sl0;
|
|
|
|
if (cpu_isar_feature(aa64_st, cpu)) {
|
|
startlevel &= 3;
|
|
}
|
|
} else {
|
|
/* 16KB or 64KB pages */
|
|
startlevel = 3 - sl0;
|
|
}
|
|
|
|
/* Check that the starting level is valid. */
|
|
ok = check_s2_mmu_setup(cpu, aarch64, startlevel,
|
|
inputsize, stride, outputsize);
|
|
if (!ok) {
|
|
goto do_translation_fault;
|
|
}
|
|
level = startlevel;
|
|
}
|
|
|
|
indexmask_grainsize = MAKE_64BIT_MASK(0, stride + 3);
|
|
indexmask = MAKE_64BIT_MASK(0, inputsize - (stride * (4 - level)));
|
|
|
|
/* Now we can extract the actual base address from the TTBR */
|
|
descaddr = extract64(ttbr, 0, 48);
|
|
|
|
/*
|
|
* For FEAT_LPA and PS=6, bits [51:48] of descaddr are in [5:2] of TTBR.
|
|
*
|
|
* Otherwise, if the base address is out of range, raise AddressSizeFault.
|
|
* In the pseudocode, this is !IsZero(baseregister<47:outputsize>),
|
|
* but we've just cleared the bits above 47, so simplify the test.
|
|
*/
|
|
if (outputsize > 48) {
|
|
descaddr |= extract64(ttbr, 2, 4) << 48;
|
|
} else if (descaddr >> outputsize) {
|
|
level = 0;
|
|
fi->type = ARMFault_AddressSize;
|
|
goto do_fault;
|
|
}
|
|
|
|
/*
|
|
* We rely on this masking to clear the RES0 bits at the bottom of the TTBR
|
|
* and also to mask out CnP (bit 0) which could validly be non-zero.
|
|
*/
|
|
descaddr &= ~indexmask;
|
|
|
|
/*
|
|
* For AArch32, the address field in the descriptor goes up to bit 39
|
|
* for both v7 and v8. However, for v8 the SBZ bits [47:40] must be 0
|
|
* or an AddressSize fault is raised. So for v8 we extract those SBZ
|
|
* bits as part of the address, which will be checked via outputsize.
|
|
* For AArch64, the address field goes up to bit 47, or 49 with FEAT_LPA2;
|
|
* the highest bits of a 52-bit output are placed elsewhere.
|
|
*/
|
|
if (param.ds) {
|
|
descaddrmask = MAKE_64BIT_MASK(0, 50);
|
|
} else if (arm_feature(env, ARM_FEATURE_V8)) {
|
|
descaddrmask = MAKE_64BIT_MASK(0, 48);
|
|
} else {
|
|
descaddrmask = MAKE_64BIT_MASK(0, 40);
|
|
}
|
|
descaddrmask &= ~indexmask_grainsize;
|
|
|
|
/*
|
|
* Secure accesses start with the page table in secure memory and
|
|
* can be downgraded to non-secure at any step. Non-secure accesses
|
|
* remain non-secure. We implement this by just ORing in the NSTable/NS
|
|
* bits at each step.
|
|
*/
|
|
tableattrs = is_secure ? 0 : (1 << 4);
|
|
|
|
next_level:
|
|
descaddr |= (address >> (stride * (4 - level))) & indexmask;
|
|
descaddr &= ~7ULL;
|
|
nstable = extract32(tableattrs, 4, 1);
|
|
if (nstable) {
|
|
/*
|
|
* Stage2_S -> Stage2 or Phys_S -> Phys_NS
|
|
* Assert that the non-secure idx are even, and relative order.
|
|
*/
|
|
QEMU_BUILD_BUG_ON((ARMMMUIdx_Phys_NS & 1) != 0);
|
|
QEMU_BUILD_BUG_ON((ARMMMUIdx_Stage2 & 1) != 0);
|
|
QEMU_BUILD_BUG_ON(ARMMMUIdx_Phys_NS + 1 != ARMMMUIdx_Phys_S);
|
|
QEMU_BUILD_BUG_ON(ARMMMUIdx_Stage2 + 1 != ARMMMUIdx_Stage2_S);
|
|
ptw->in_ptw_idx &= ~1;
|
|
ptw->in_secure = false;
|
|
}
|
|
if (!S1_ptw_translate(env, ptw, descaddr, fi)) {
|
|
goto do_fault;
|
|
}
|
|
descriptor = arm_ldq_ptw(env, ptw, fi);
|
|
if (fi->type != ARMFault_None) {
|
|
goto do_fault;
|
|
}
|
|
new_descriptor = descriptor;
|
|
|
|
restart_atomic_update:
|
|
if (!(descriptor & 1) || (!(descriptor & 2) && (level == 3))) {
|
|
/* Invalid, or the Reserved level 3 encoding */
|
|
goto do_translation_fault;
|
|
}
|
|
|
|
descaddr = descriptor & descaddrmask;
|
|
|
|
/*
|
|
* For FEAT_LPA and PS=6, bits [51:48] of descaddr are in [15:12]
|
|
* of descriptor. For FEAT_LPA2 and effective DS, bits [51:50] of
|
|
* descaddr are in [9:8]. Otherwise, if descaddr is out of range,
|
|
* raise AddressSizeFault.
|
|
*/
|
|
if (outputsize > 48) {
|
|
if (param.ds) {
|
|
descaddr |= extract64(descriptor, 8, 2) << 50;
|
|
} else {
|
|
descaddr |= extract64(descriptor, 12, 4) << 48;
|
|
}
|
|
} else if (descaddr >> outputsize) {
|
|
fi->type = ARMFault_AddressSize;
|
|
goto do_fault;
|
|
}
|
|
|
|
if ((descriptor & 2) && (level < 3)) {
|
|
/*
|
|
* Table entry. The top five bits are attributes which may
|
|
* propagate down through lower levels of the table (and
|
|
* which are all arranged so that 0 means "no effect", so
|
|
* we can gather them up by ORing in the bits at each level).
|
|
*/
|
|
tableattrs |= extract64(descriptor, 59, 5);
|
|
level++;
|
|
indexmask = indexmask_grainsize;
|
|
goto next_level;
|
|
}
|
|
|
|
/*
|
|
* Block entry at level 1 or 2, or page entry at level 3.
|
|
* These are basically the same thing, although the number
|
|
* of bits we pull in from the vaddr varies. Note that although
|
|
* descaddrmask masks enough of the low bits of the descriptor
|
|
* to give a correct page or table address, the address field
|
|
* in a block descriptor is smaller; so we need to explicitly
|
|
* clear the lower bits here before ORing in the low vaddr bits.
|
|
*
|
|
* Afterward, descaddr is the final physical address.
|
|
*/
|
|
page_size = (1ULL << ((stride * (4 - level)) + 3));
|
|
descaddr &= ~(hwaddr)(page_size - 1);
|
|
descaddr |= (address & (page_size - 1));
|
|
|
|
if (likely(!ptw->in_debug)) {
|
|
/*
|
|
* Access flag.
|
|
* If HA is enabled, prepare to update the descriptor below.
|
|
* Otherwise, pass the access fault on to software.
|
|
*/
|
|
if (!(descriptor & (1 << 10))) {
|
|
if (param.ha) {
|
|
new_descriptor |= 1 << 10; /* AF */
|
|
} else {
|
|
fi->type = ARMFault_AccessFlag;
|
|
goto do_fault;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Dirty Bit.
|
|
* If HD is enabled, pre-emptively set/clear the appropriate AP/S2AP
|
|
* bit for writeback. The actual write protection test may still be
|
|
* overridden by tableattrs, to be merged below.
|
|
*/
|
|
if (param.hd
|
|
&& extract64(descriptor, 51, 1) /* DBM */
|
|
&& access_type == MMU_DATA_STORE) {
|
|
if (regime_is_stage2(mmu_idx)) {
|
|
new_descriptor |= 1ull << 7; /* set S2AP[1] */
|
|
} else {
|
|
new_descriptor &= ~(1ull << 7); /* clear AP[2] */
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Extract attributes from the (modified) descriptor, and apply
|
|
* table descriptors. Stage 2 table descriptors do not include
|
|
* any attribute fields. HPD disables all the table attributes
|
|
* except NSTable.
|
|
*/
|
|
attrs = new_descriptor & (MAKE_64BIT_MASK(2, 10) | MAKE_64BIT_MASK(50, 14));
|
|
if (!regime_is_stage2(mmu_idx)) {
|
|
attrs |= nstable << 5; /* NS */
|
|
if (!param.hpd) {
|
|
attrs |= extract64(tableattrs, 0, 2) << 53; /* XN, PXN */
|
|
/*
|
|
* The sense of AP[1] vs APTable[0] is reversed, as APTable[0] == 1
|
|
* means "force PL1 access only", which means forcing AP[1] to 0.
|
|
*/
|
|
attrs &= ~(extract64(tableattrs, 2, 1) << 6); /* !APT[0] => AP[1] */
|
|
attrs |= extract32(tableattrs, 3, 1) << 7; /* APT[1] => AP[2] */
|
|
}
|
|
}
|
|
|
|
ap = extract32(attrs, 6, 2);
|
|
if (regime_is_stage2(mmu_idx)) {
|
|
ns = mmu_idx == ARMMMUIdx_Stage2;
|
|
xn = extract64(attrs, 53, 2);
|
|
result->f.prot = get_S2prot(env, ap, xn, s1_is_el0);
|
|
} else {
|
|
ns = extract32(attrs, 5, 1);
|
|
xn = extract64(attrs, 54, 1);
|
|
pxn = extract64(attrs, 53, 1);
|
|
result->f.prot = get_S1prot(env, mmu_idx, aarch64, ap, ns, xn, pxn);
|
|
}
|
|
|
|
if (!(result->f.prot & (1 << access_type))) {
|
|
fi->type = ARMFault_Permission;
|
|
goto do_fault;
|
|
}
|
|
|
|
/* If FEAT_HAFDBS has made changes, update the PTE. */
|
|
if (new_descriptor != descriptor) {
|
|
new_descriptor = arm_casq_ptw(env, descriptor, new_descriptor, ptw, fi);
|
|
if (fi->type != ARMFault_None) {
|
|
goto do_fault;
|
|
}
|
|
/*
|
|
* I_YZSVV says that if the in-memory descriptor has changed,
|
|
* then we must use the information in that new value
|
|
* (which might include a different output address, different
|
|
* attributes, or generate a fault).
|
|
* Restart the handling of the descriptor value from scratch.
|
|
*/
|
|
if (new_descriptor != descriptor) {
|
|
descriptor = new_descriptor;
|
|
goto restart_atomic_update;
|
|
}
|
|
}
|
|
|
|
if (ns) {
|
|
/*
|
|
* The NS bit will (as required by the architecture) have no effect if
|
|
* the CPU doesn't support TZ or this is a non-secure translation
|
|
* regime, because the attribute will already be non-secure.
|
|
*/
|
|
result->f.attrs.secure = false;
|
|
}
|
|
|
|
/* When in aarch64 mode, and BTI is enabled, remember GP in the TLB. */
|
|
if (aarch64 && cpu_isar_feature(aa64_bti, cpu)) {
|
|
result->f.guarded = extract64(attrs, 50, 1); /* GP */
|
|
}
|
|
|
|
if (regime_is_stage2(mmu_idx)) {
|
|
result->cacheattrs.is_s2_format = true;
|
|
result->cacheattrs.attrs = extract32(attrs, 2, 4);
|
|
} else {
|
|
/* Index into MAIR registers for cache attributes */
|
|
uint8_t attrindx = extract32(attrs, 2, 3);
|
|
uint64_t mair = env->cp15.mair_el[regime_el(env, mmu_idx)];
|
|
assert(attrindx <= 7);
|
|
result->cacheattrs.is_s2_format = false;
|
|
result->cacheattrs.attrs = extract64(mair, attrindx * 8, 8);
|
|
}
|
|
|
|
/*
|
|
* For FEAT_LPA2 and effective DS, the SH field in the attributes
|
|
* was re-purposed for output address bits. The SH attribute in
|
|
* that case comes from TCR_ELx, which we extracted earlier.
|
|
*/
|
|
if (param.ds) {
|
|
result->cacheattrs.shareability = param.sh;
|
|
} else {
|
|
result->cacheattrs.shareability = extract32(attrs, 8, 2);
|
|
}
|
|
|
|
result->f.phys_addr = descaddr;
|
|
result->f.lg_page_size = ctz64(page_size);
|
|
return false;
|
|
|
|
do_translation_fault:
|
|
fi->type = ARMFault_Translation;
|
|
do_fault:
|
|
fi->level = level;
|
|
/* Tag the error as S2 for failed S1 PTW at S2 or ordinary S2. */
|
|
fi->stage2 = fi->s1ptw || regime_is_stage2(mmu_idx);
|
|
fi->s1ns = mmu_idx == ARMMMUIdx_Stage2;
|
|
return true;
|
|
}
|
|
|
|
static bool get_phys_addr_pmsav5(CPUARMState *env, uint32_t address,
|
|
MMUAccessType access_type, ARMMMUIdx mmu_idx,
|
|
bool is_secure, GetPhysAddrResult *result,
|
|
ARMMMUFaultInfo *fi)
|
|
{
|
|
int n;
|
|
uint32_t mask;
|
|
uint32_t base;
|
|
bool is_user = regime_is_user(env, mmu_idx);
|
|
|
|
if (regime_translation_disabled(env, mmu_idx, is_secure)) {
|
|
/* MPU disabled. */
|
|
result->f.phys_addr = address;
|
|
result->f.prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
|
return false;
|
|
}
|
|
|
|
result->f.phys_addr = address;
|
|
for (n = 7; n >= 0; n--) {
|
|
base = env->cp15.c6_region[n];
|
|
if ((base & 1) == 0) {
|
|
continue;
|
|
}
|
|
mask = 1 << ((base >> 1) & 0x1f);
|
|
/* Keep this shift separate from the above to avoid an
|
|
(undefined) << 32. */
|
|
mask = (mask << 1) - 1;
|
|
if (((base ^ address) & ~mask) == 0) {
|
|
break;
|
|
}
|
|
}
|
|
if (n < 0) {
|
|
fi->type = ARMFault_Background;
|
|
return true;
|
|
}
|
|
|
|
if (access_type == MMU_INST_FETCH) {
|
|
mask = env->cp15.pmsav5_insn_ap;
|
|
} else {
|
|
mask = env->cp15.pmsav5_data_ap;
|
|
}
|
|
mask = (mask >> (n * 4)) & 0xf;
|
|
switch (mask) {
|
|
case 0:
|
|
fi->type = ARMFault_Permission;
|
|
fi->level = 1;
|
|
return true;
|
|
case 1:
|
|
if (is_user) {
|
|
fi->type = ARMFault_Permission;
|
|
fi->level = 1;
|
|
return true;
|
|
}
|
|
result->f.prot = PAGE_READ | PAGE_WRITE;
|
|
break;
|
|
case 2:
|
|
result->f.prot = PAGE_READ;
|
|
if (!is_user) {
|
|
result->f.prot |= PAGE_WRITE;
|
|
}
|
|
break;
|
|
case 3:
|
|
result->f.prot = PAGE_READ | PAGE_WRITE;
|
|
break;
|
|
case 5:
|
|
if (is_user) {
|
|
fi->type = ARMFault_Permission;
|
|
fi->level = 1;
|
|
return true;
|
|
}
|
|
result->f.prot = PAGE_READ;
|
|
break;
|
|
case 6:
|
|
result->f.prot = PAGE_READ;
|
|
break;
|
|
default:
|
|
/* Bad permission. */
|
|
fi->type = ARMFault_Permission;
|
|
fi->level = 1;
|
|
return true;
|
|
}
|
|
result->f.prot |= PAGE_EXEC;
|
|
return false;
|
|
}
|
|
|
|
static void get_phys_addr_pmsav7_default(CPUARMState *env, ARMMMUIdx mmu_idx,
|
|
int32_t address, uint8_t *prot)
|
|
{
|
|
if (!arm_feature(env, ARM_FEATURE_M)) {
|
|
*prot = PAGE_READ | PAGE_WRITE;
|
|
switch (address) {
|
|
case 0xF0000000 ... 0xFFFFFFFF:
|
|
if (regime_sctlr(env, mmu_idx) & SCTLR_V) {
|
|
/* hivecs execing is ok */
|
|
*prot |= PAGE_EXEC;
|
|
}
|
|
break;
|
|
case 0x00000000 ... 0x7FFFFFFF:
|
|
*prot |= PAGE_EXEC;
|
|
break;
|
|
}
|
|
} else {
|
|
/* Default system address map for M profile cores.
|
|
* The architecture specifies which regions are execute-never;
|
|
* at the MPU level no other checks are defined.
|
|
*/
|
|
switch (address) {
|
|
case 0x00000000 ... 0x1fffffff: /* ROM */
|
|
case 0x20000000 ... 0x3fffffff: /* SRAM */
|
|
case 0x60000000 ... 0x7fffffff: /* RAM */
|
|
case 0x80000000 ... 0x9fffffff: /* RAM */
|
|
*prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
|
break;
|
|
case 0x40000000 ... 0x5fffffff: /* Peripheral */
|
|
case 0xa0000000 ... 0xbfffffff: /* Device */
|
|
case 0xc0000000 ... 0xdfffffff: /* Device */
|
|
case 0xe0000000 ... 0xffffffff: /* System */
|
|
*prot = PAGE_READ | PAGE_WRITE;
|
|
break;
|
|
default:
|
|
g_assert_not_reached();
|
|
}
|
|
}
|
|
}
|
|
|
|
static bool m_is_ppb_region(CPUARMState *env, uint32_t address)
|
|
{
|
|
/* True if address is in the M profile PPB region 0xe0000000 - 0xe00fffff */
|
|
return arm_feature(env, ARM_FEATURE_M) &&
|
|
extract32(address, 20, 12) == 0xe00;
|
|
}
|
|
|
|
static bool m_is_system_region(CPUARMState *env, uint32_t address)
|
|
{
|
|
/*
|
|
* True if address is in the M profile system region
|
|
* 0xe0000000 - 0xffffffff
|
|
*/
|
|
return arm_feature(env, ARM_FEATURE_M) && extract32(address, 29, 3) == 0x7;
|
|
}
|
|
|
|
static bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx,
|
|
bool is_secure, bool is_user)
|
|
{
|
|
/*
|
|
* Return true if we should use the default memory map as a
|
|
* "background" region if there are no hits against any MPU regions.
|
|
*/
|
|
CPUARMState *env = &cpu->env;
|
|
|
|
if (is_user) {
|
|
return false;
|
|
}
|
|
|
|
if (arm_feature(env, ARM_FEATURE_M)) {
|
|
return env->v7m.mpu_ctrl[is_secure] & R_V7M_MPU_CTRL_PRIVDEFENA_MASK;
|
|
} else {
|
|
return regime_sctlr(env, mmu_idx) & SCTLR_BR;
|
|
}
|
|
}
|
|
|
|
static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address,
|
|
MMUAccessType access_type, ARMMMUIdx mmu_idx,
|
|
bool secure, GetPhysAddrResult *result,
|
|
ARMMMUFaultInfo *fi)
|
|
{
|
|
ARMCPU *cpu = env_archcpu(env);
|
|
int n;
|
|
bool is_user = regime_is_user(env, mmu_idx);
|
|
|
|
result->f.phys_addr = address;
|
|
result->f.lg_page_size = TARGET_PAGE_BITS;
|
|
result->f.prot = 0;
|
|
|
|
if (regime_translation_disabled(env, mmu_idx, secure) ||
|
|
m_is_ppb_region(env, address)) {
|
|
/*
|
|
* MPU disabled or M profile PPB access: use default memory map.
|
|
* The other case which uses the default memory map in the
|
|
* v7M ARM ARM pseudocode is exception vector reads from the vector
|
|
* table. In QEMU those accesses are done in arm_v7m_load_vector(),
|
|
* which always does a direct read using address_space_ldl(), rather
|
|
* than going via this function, so we don't need to check that here.
|
|
*/
|
|
get_phys_addr_pmsav7_default(env, mmu_idx, address, &result->f.prot);
|
|
} else { /* MPU enabled */
|
|
for (n = (int)cpu->pmsav7_dregion - 1; n >= 0; n--) {
|
|
/* region search */
|
|
uint32_t base = env->pmsav7.drbar[n];
|
|
uint32_t rsize = extract32(env->pmsav7.drsr[n], 1, 5);
|
|
uint32_t rmask;
|
|
bool srdis = false;
|
|
|
|
if (!(env->pmsav7.drsr[n] & 0x1)) {
|
|
continue;
|
|
}
|
|
|
|
if (!rsize) {
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
"DRSR[%d]: Rsize field cannot be 0\n", n);
|
|
continue;
|
|
}
|
|
rsize++;
|
|
rmask = (1ull << rsize) - 1;
|
|
|
|
if (base & rmask) {
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
"DRBAR[%d]: 0x%" PRIx32 " misaligned "
|
|
"to DRSR region size, mask = 0x%" PRIx32 "\n",
|
|
n, base, rmask);
|
|
continue;
|
|
}
|
|
|
|
if (address < base || address > base + rmask) {
|
|
/*
|
|
* Address not in this region. We must check whether the
|
|
* region covers addresses in the same page as our address.
|
|
* In that case we must not report a size that covers the
|
|
* whole page for a subsequent hit against a different MPU
|
|
* region or the background region, because it would result in
|
|
* incorrect TLB hits for subsequent accesses to addresses that
|
|
* are in this MPU region.
|
|
*/
|
|
if (ranges_overlap(base, rmask,
|
|
address & TARGET_PAGE_MASK,
|
|
TARGET_PAGE_SIZE)) {
|
|
result->f.lg_page_size = 0;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
/* Region matched */
|
|
|
|
if (rsize >= 8) { /* no subregions for regions < 256 bytes */
|
|
int i, snd;
|
|
uint32_t srdis_mask;
|
|
|
|
rsize -= 3; /* sub region size (power of 2) */
|
|
snd = ((address - base) >> rsize) & 0x7;
|
|
srdis = extract32(env->pmsav7.drsr[n], snd + 8, 1);
|
|
|
|
srdis_mask = srdis ? 0x3 : 0x0;
|
|
for (i = 2; i <= 8 && rsize < TARGET_PAGE_BITS; i *= 2) {
|
|
/*
|
|
* This will check in groups of 2, 4 and then 8, whether
|
|
* the subregion bits are consistent. rsize is incremented
|
|
* back up to give the region size, considering consistent
|
|
* adjacent subregions as one region. Stop testing if rsize
|
|
* is already big enough for an entire QEMU page.
|
|
*/
|
|
int snd_rounded = snd & ~(i - 1);
|
|
uint32_t srdis_multi = extract32(env->pmsav7.drsr[n],
|
|
snd_rounded + 8, i);
|
|
if (srdis_mask ^ srdis_multi) {
|
|
break;
|
|
}
|
|
srdis_mask = (srdis_mask << i) | srdis_mask;
|
|
rsize++;
|
|
}
|
|
}
|
|
if (srdis) {
|
|
continue;
|
|
}
|
|
if (rsize < TARGET_PAGE_BITS) {
|
|
result->f.lg_page_size = rsize;
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (n == -1) { /* no hits */
|
|
if (!pmsav7_use_background_region(cpu, mmu_idx, secure, is_user)) {
|
|
/* background fault */
|
|
fi->type = ARMFault_Background;
|
|
return true;
|
|
}
|
|
get_phys_addr_pmsav7_default(env, mmu_idx, address,
|
|
&result->f.prot);
|
|
} else { /* a MPU hit! */
|
|
uint32_t ap = extract32(env->pmsav7.dracr[n], 8, 3);
|
|
uint32_t xn = extract32(env->pmsav7.dracr[n], 12, 1);
|
|
|
|
if (m_is_system_region(env, address)) {
|
|
/* System space is always execute never */
|
|
xn = 1;
|
|
}
|
|
|
|
if (is_user) { /* User mode AP bit decoding */
|
|
switch (ap) {
|
|
case 0:
|
|
case 1:
|
|
case 5:
|
|
break; /* no access */
|
|
case 3:
|
|
result->f.prot |= PAGE_WRITE;
|
|
/* fall through */
|
|
case 2:
|
|
case 6:
|
|
result->f.prot |= PAGE_READ | PAGE_EXEC;
|
|
break;
|
|
case 7:
|
|
/* for v7M, same as 6; for R profile a reserved value */
|
|
if (arm_feature(env, ARM_FEATURE_M)) {
|
|
result->f.prot |= PAGE_READ | PAGE_EXEC;
|
|
break;
|
|
}
|
|
/* fall through */
|
|
default:
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
"DRACR[%d]: Bad value for AP bits: 0x%"
|
|
PRIx32 "\n", n, ap);
|
|
}
|
|
} else { /* Priv. mode AP bits decoding */
|
|
switch (ap) {
|
|
case 0:
|
|
break; /* no access */
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
result->f.prot |= PAGE_WRITE;
|
|
/* fall through */
|
|
case 5:
|
|
case 6:
|
|
result->f.prot |= PAGE_READ | PAGE_EXEC;
|
|
break;
|
|
case 7:
|
|
/* for v7M, same as 6; for R profile a reserved value */
|
|
if (arm_feature(env, ARM_FEATURE_M)) {
|
|
result->f.prot |= PAGE_READ | PAGE_EXEC;
|
|
break;
|
|
}
|
|
/* fall through */
|
|
default:
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
"DRACR[%d]: Bad value for AP bits: 0x%"
|
|
PRIx32 "\n", n, ap);
|
|
}
|
|
}
|
|
|
|
/* execute never */
|
|
if (xn) {
|
|
result->f.prot &= ~PAGE_EXEC;
|
|
}
|
|
}
|
|
}
|
|
|
|
fi->type = ARMFault_Permission;
|
|
fi->level = 1;
|
|
return !(result->f.prot & (1 << access_type));
|
|
}
|
|
|
|
bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
|
|
MMUAccessType access_type, ARMMMUIdx mmu_idx,
|
|
bool secure, GetPhysAddrResult *result,
|
|
ARMMMUFaultInfo *fi, uint32_t *mregion)
|
|
{
|
|
/*
|
|
* Perform a PMSAv8 MPU lookup (without also doing the SAU check
|
|
* that a full phys-to-virt translation does).
|
|
* mregion is (if not NULL) set to the region number which matched,
|
|
* or -1 if no region number is returned (MPU off, address did not
|
|
* hit a region, address hit in multiple regions).
|
|
* If the region hit doesn't cover the entire TARGET_PAGE the address
|
|
* is within, then we set the result page_size to 1 to force the
|
|
* memory system to use a subpage.
|
|
*/
|
|
ARMCPU *cpu = env_archcpu(env);
|
|
bool is_user = regime_is_user(env, mmu_idx);
|
|
int n;
|
|
int matchregion = -1;
|
|
bool hit = false;
|
|
uint32_t addr_page_base = address & TARGET_PAGE_MASK;
|
|
uint32_t addr_page_limit = addr_page_base + (TARGET_PAGE_SIZE - 1);
|
|
|
|
result->f.lg_page_size = TARGET_PAGE_BITS;
|
|
result->f.phys_addr = address;
|
|
result->f.prot = 0;
|
|
if (mregion) {
|
|
*mregion = -1;
|
|
}
|
|
|
|
/*
|
|
* Unlike the ARM ARM pseudocode, we don't need to check whether this
|
|
* was an exception vector read from the vector table (which is always
|
|
* done using the default system address map), because those accesses
|
|
* are done in arm_v7m_load_vector(), which always does a direct
|
|
* read using address_space_ldl(), rather than going via this function.
|
|
*/
|
|
if (regime_translation_disabled(env, mmu_idx, secure)) { /* MPU disabled */
|
|
hit = true;
|
|
} else if (m_is_ppb_region(env, address)) {
|
|
hit = true;
|
|
} else {
|
|
if (pmsav7_use_background_region(cpu, mmu_idx, secure, is_user)) {
|
|
hit = true;
|
|
}
|
|
|
|
for (n = (int)cpu->pmsav7_dregion - 1; n >= 0; n--) {
|
|
/* region search */
|
|
/*
|
|
* Note that the base address is bits [31:5] from the register
|
|
* with bits [4:0] all zeroes, but the limit address is bits
|
|
* [31:5] from the register with bits [4:0] all ones.
|
|
*/
|
|
uint32_t base = env->pmsav8.rbar[secure][n] & ~0x1f;
|
|
uint32_t limit = env->pmsav8.rlar[secure][n] | 0x1f;
|
|
|
|
if (!(env->pmsav8.rlar[secure][n] & 0x1)) {
|
|
/* Region disabled */
|
|
continue;
|
|
}
|
|
|
|
if (address < base || address > limit) {
|
|
/*
|
|
* Address not in this region. We must check whether the
|
|
* region covers addresses in the same page as our address.
|
|
* In that case we must not report a size that covers the
|
|
* whole page for a subsequent hit against a different MPU
|
|
* region or the background region, because it would result in
|
|
* incorrect TLB hits for subsequent accesses to addresses that
|
|
* are in this MPU region.
|
|
*/
|
|
if (limit >= base &&
|
|
ranges_overlap(base, limit - base + 1,
|
|
addr_page_base,
|
|
TARGET_PAGE_SIZE)) {
|
|
result->f.lg_page_size = 0;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (base > addr_page_base || limit < addr_page_limit) {
|
|
result->f.lg_page_size = 0;
|
|
}
|
|
|
|
if (matchregion != -1) {
|
|
/*
|
|
* Multiple regions match -- always a failure (unlike
|
|
* PMSAv7 where highest-numbered-region wins)
|
|
*/
|
|
fi->type = ARMFault_Permission;
|
|
fi->level = 1;
|
|
return true;
|
|
}
|
|
|
|
matchregion = n;
|
|
hit = true;
|
|
}
|
|
}
|
|
|
|
if (!hit) {
|
|
/* background fault */
|
|
fi->type = ARMFault_Background;
|
|
return true;
|
|
}
|
|
|
|
if (matchregion == -1) {
|
|
/* hit using the background region */
|
|
get_phys_addr_pmsav7_default(env, mmu_idx, address, &result->f.prot);
|
|
} else {
|
|
uint32_t ap = extract32(env->pmsav8.rbar[secure][matchregion], 1, 2);
|
|
uint32_t xn = extract32(env->pmsav8.rbar[secure][matchregion], 0, 1);
|
|
bool pxn = false;
|
|
|
|
if (arm_feature(env, ARM_FEATURE_V8_1M)) {
|
|
pxn = extract32(env->pmsav8.rlar[secure][matchregion], 4, 1);
|
|
}
|
|
|
|
if (m_is_system_region(env, address)) {
|
|
/* System space is always execute never */
|
|
xn = 1;
|
|
}
|
|
|
|
result->f.prot = simple_ap_to_rw_prot(env, mmu_idx, ap);
|
|
if (result->f.prot && !xn && !(pxn && !is_user)) {
|
|
result->f.prot |= PAGE_EXEC;
|
|
}
|
|
/*
|
|
* We don't need to look the attribute up in the MAIR0/MAIR1
|
|
* registers because that only tells us about cacheability.
|
|
*/
|
|
if (mregion) {
|
|
*mregion = matchregion;
|
|
}
|
|
}
|
|
|
|
fi->type = ARMFault_Permission;
|
|
fi->level = 1;
|
|
return !(result->f.prot & (1 << access_type));
|
|
}
|
|
|
|
static bool v8m_is_sau_exempt(CPUARMState *env,
|
|
uint32_t address, MMUAccessType access_type)
|
|
{
|
|
/*
|
|
* The architecture specifies that certain address ranges are
|
|
* exempt from v8M SAU/IDAU checks.
|
|
*/
|
|
return
|
|
(access_type == MMU_INST_FETCH && m_is_system_region(env, address)) ||
|
|
(address >= 0xe0000000 && address <= 0xe0002fff) ||
|
|
(address >= 0xe000e000 && address <= 0xe000efff) ||
|
|
(address >= 0xe002e000 && address <= 0xe002efff) ||
|
|
(address >= 0xe0040000 && address <= 0xe0041fff) ||
|
|
(address >= 0xe00ff000 && address <= 0xe00fffff);
|
|
}
|
|
|
|
void v8m_security_lookup(CPUARMState *env, uint32_t address,
|
|
MMUAccessType access_type, ARMMMUIdx mmu_idx,
|
|
bool is_secure, V8M_SAttributes *sattrs)
|
|
{
|
|
/*
|
|
* Look up the security attributes for this address. Compare the
|
|
* pseudocode SecurityCheck() function.
|
|
* We assume the caller has zero-initialized *sattrs.
|
|
*/
|
|
ARMCPU *cpu = env_archcpu(env);
|
|
int r;
|
|
bool idau_exempt = false, idau_ns = true, idau_nsc = true;
|
|
int idau_region = IREGION_NOTVALID;
|
|
uint32_t addr_page_base = address & TARGET_PAGE_MASK;
|
|
uint32_t addr_page_limit = addr_page_base + (TARGET_PAGE_SIZE - 1);
|
|
|
|
if (cpu->idau) {
|
|
IDAUInterfaceClass *iic = IDAU_INTERFACE_GET_CLASS(cpu->idau);
|
|
IDAUInterface *ii = IDAU_INTERFACE(cpu->idau);
|
|
|
|
iic->check(ii, address, &idau_region, &idau_exempt, &idau_ns,
|
|
&idau_nsc);
|
|
}
|
|
|
|
if (access_type == MMU_INST_FETCH && extract32(address, 28, 4) == 0xf) {
|
|
/* 0xf0000000..0xffffffff is always S for insn fetches */
|
|
return;
|
|
}
|
|
|
|
if (idau_exempt || v8m_is_sau_exempt(env, address, access_type)) {
|
|
sattrs->ns = !is_secure;
|
|
return;
|
|
}
|
|
|
|
if (idau_region != IREGION_NOTVALID) {
|
|
sattrs->irvalid = true;
|
|
sattrs->iregion = idau_region;
|
|
}
|
|
|
|
switch (env->sau.ctrl & 3) {
|
|
case 0: /* SAU.ENABLE == 0, SAU.ALLNS == 0 */
|
|
break;
|
|
case 2: /* SAU.ENABLE == 0, SAU.ALLNS == 1 */
|
|
sattrs->ns = true;
|
|
break;
|
|
default: /* SAU.ENABLE == 1 */
|
|
for (r = 0; r < cpu->sau_sregion; r++) {
|
|
if (env->sau.rlar[r] & 1) {
|
|
uint32_t base = env->sau.rbar[r] & ~0x1f;
|
|
uint32_t limit = env->sau.rlar[r] | 0x1f;
|
|
|
|
if (base <= address && limit >= address) {
|
|
if (base > addr_page_base || limit < addr_page_limit) {
|
|
sattrs->subpage = true;
|
|
}
|
|
if (sattrs->srvalid) {
|
|
/*
|
|
* If we hit in more than one region then we must report
|
|
* as Secure, not NS-Callable, with no valid region
|
|
* number info.
|
|
*/
|
|
sattrs->ns = false;
|
|
sattrs->nsc = false;
|
|
sattrs->sregion = 0;
|
|
sattrs->srvalid = false;
|
|
break;
|
|
} else {
|
|
if (env->sau.rlar[r] & 2) {
|
|
sattrs->nsc = true;
|
|
} else {
|
|
sattrs->ns = true;
|
|
}
|
|
sattrs->srvalid = true;
|
|
sattrs->sregion = r;
|
|
}
|
|
} else {
|
|
/*
|
|
* Address not in this region. We must check whether the
|
|
* region covers addresses in the same page as our address.
|
|
* In that case we must not report a size that covers the
|
|
* whole page for a subsequent hit against a different MPU
|
|
* region or the background region, because it would result
|
|
* in incorrect TLB hits for subsequent accesses to
|
|
* addresses that are in this MPU region.
|
|
*/
|
|
if (limit >= base &&
|
|
ranges_overlap(base, limit - base + 1,
|
|
addr_page_base,
|
|
TARGET_PAGE_SIZE)) {
|
|
sattrs->subpage = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
/*
|
|
* The IDAU will override the SAU lookup results if it specifies
|
|
* higher security than the SAU does.
|
|
*/
|
|
if (!idau_ns) {
|
|
if (sattrs->ns || (!idau_nsc && sattrs->nsc)) {
|
|
sattrs->ns = false;
|
|
sattrs->nsc = idau_nsc;
|
|
}
|
|
}
|
|
}
|
|
|
|
static bool get_phys_addr_pmsav8(CPUARMState *env, uint32_t address,
|
|
MMUAccessType access_type, ARMMMUIdx mmu_idx,
|
|
bool secure, GetPhysAddrResult *result,
|
|
ARMMMUFaultInfo *fi)
|
|
{
|
|
V8M_SAttributes sattrs = {};
|
|
bool ret;
|
|
|
|
if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
|
|
v8m_security_lookup(env, address, access_type, mmu_idx,
|
|
secure, &sattrs);
|
|
if (access_type == MMU_INST_FETCH) {
|
|
/*
|
|
* Instruction fetches always use the MMU bank and the
|
|
* transaction attribute determined by the fetch address,
|
|
* regardless of CPU state. This is painful for QEMU
|
|
* to handle, because it would mean we need to encode
|
|
* into the mmu_idx not just the (user, negpri) information
|
|
* for the current security state but also that for the
|
|
* other security state, which would balloon the number
|
|
* of mmu_idx values needed alarmingly.
|
|
* Fortunately we can avoid this because it's not actually
|
|
* possible to arbitrarily execute code from memory with
|
|
* the wrong security attribute: it will always generate
|
|
* an exception of some kind or another, apart from the
|
|
* special case of an NS CPU executing an SG instruction
|
|
* in S&NSC memory. So we always just fail the translation
|
|
* here and sort things out in the exception handler
|
|
* (including possibly emulating an SG instruction).
|
|
*/
|
|
if (sattrs.ns != !secure) {
|
|
if (sattrs.nsc) {
|
|
fi->type = ARMFault_QEMU_NSCExec;
|
|
} else {
|
|
fi->type = ARMFault_QEMU_SFault;
|
|
}
|
|
result->f.lg_page_size = sattrs.subpage ? 0 : TARGET_PAGE_BITS;
|
|
result->f.phys_addr = address;
|
|
result->f.prot = 0;
|
|
return true;
|
|
}
|
|
} else {
|
|
/*
|
|
* For data accesses we always use the MMU bank indicated
|
|
* by the current CPU state, but the security attributes
|
|
* might downgrade a secure access to nonsecure.
|
|
*/
|
|
if (sattrs.ns) {
|
|
result->f.attrs.secure = false;
|
|
} else if (!secure) {
|
|
/*
|
|
* NS access to S memory must fault.
|
|
* Architecturally we should first check whether the
|
|
* MPU information for this address indicates that we
|
|
* are doing an unaligned access to Device memory, which
|
|
* should generate a UsageFault instead. QEMU does not
|
|
* currently check for that kind of unaligned access though.
|
|
* If we added it we would need to do so as a special case
|
|
* for M_FAKE_FSR_SFAULT in arm_v7m_cpu_do_interrupt().
|
|
*/
|
|
fi->type = ARMFault_QEMU_SFault;
|
|
result->f.lg_page_size = sattrs.subpage ? 0 : TARGET_PAGE_BITS;
|
|
result->f.phys_addr = address;
|
|
result->f.prot = 0;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
ret = pmsav8_mpu_lookup(env, address, access_type, mmu_idx, secure,
|
|
result, fi, NULL);
|
|
if (sattrs.subpage) {
|
|
result->f.lg_page_size = 0;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Translate from the 4-bit stage 2 representation of
|
|
* memory attributes (without cache-allocation hints) to
|
|
* the 8-bit representation of the stage 1 MAIR registers
|
|
* (which includes allocation hints).
|
|
*
|
|
* ref: shared/translation/attrs/S2AttrDecode()
|
|
* .../S2ConvertAttrsHints()
|
|
*/
|
|
static uint8_t convert_stage2_attrs(uint64_t hcr, uint8_t s2attrs)
|
|
{
|
|
uint8_t hiattr = extract32(s2attrs, 2, 2);
|
|
uint8_t loattr = extract32(s2attrs, 0, 2);
|
|
uint8_t hihint = 0, lohint = 0;
|
|
|
|
if (hiattr != 0) { /* normal memory */
|
|
if (hcr & HCR_CD) { /* cache disabled */
|
|
hiattr = loattr = 1; /* non-cacheable */
|
|
} else {
|
|
if (hiattr != 1) { /* Write-through or write-back */
|
|
hihint = 3; /* RW allocate */
|
|
}
|
|
if (loattr != 1) { /* Write-through or write-back */
|
|
lohint = 3; /* RW allocate */
|
|
}
|
|
}
|
|
}
|
|
|
|
return (hiattr << 6) | (hihint << 4) | (loattr << 2) | lohint;
|
|
}
|
|
|
|
/*
|
|
* Combine either inner or outer cacheability attributes for normal
|
|
* memory, according to table D4-42 and pseudocode procedure
|
|
* CombineS1S2AttrHints() of ARM DDI 0487B.b (the ARMv8 ARM).
|
|
*
|
|
* NB: only stage 1 includes allocation hints (RW bits), leading to
|
|
* some asymmetry.
|
|
*/
|
|
static uint8_t combine_cacheattr_nibble(uint8_t s1, uint8_t s2)
|
|
{
|
|
if (s1 == 4 || s2 == 4) {
|
|
/* non-cacheable has precedence */
|
|
return 4;
|
|
} else if (extract32(s1, 2, 2) == 0 || extract32(s1, 2, 2) == 2) {
|
|
/* stage 1 write-through takes precedence */
|
|
return s1;
|
|
} else if (extract32(s2, 2, 2) == 2) {
|
|
/* stage 2 write-through takes precedence, but the allocation hint
|
|
* is still taken from stage 1
|
|
*/
|
|
return (2 << 2) | extract32(s1, 0, 2);
|
|
} else { /* write-back */
|
|
return s1;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Combine the memory type and cacheability attributes of
|
|
* s1 and s2 for the HCR_EL2.FWB == 0 case, returning the
|
|
* combined attributes in MAIR_EL1 format.
|
|
*/
|
|
static uint8_t combined_attrs_nofwb(uint64_t hcr,
|
|
ARMCacheAttrs s1, ARMCacheAttrs s2)
|
|
{
|
|
uint8_t s1lo, s2lo, s1hi, s2hi, s2_mair_attrs, ret_attrs;
|
|
|
|
s2_mair_attrs = convert_stage2_attrs(hcr, s2.attrs);
|
|
|
|
s1lo = extract32(s1.attrs, 0, 4);
|
|
s2lo = extract32(s2_mair_attrs, 0, 4);
|
|
s1hi = extract32(s1.attrs, 4, 4);
|
|
s2hi = extract32(s2_mair_attrs, 4, 4);
|
|
|
|
/* Combine memory type and cacheability attributes */
|
|
if (s1hi == 0 || s2hi == 0) {
|
|
/* Device has precedence over normal */
|
|
if (s1lo == 0 || s2lo == 0) {
|
|
/* nGnRnE has precedence over anything */
|
|
ret_attrs = 0;
|
|
} else if (s1lo == 4 || s2lo == 4) {
|
|
/* non-Reordering has precedence over Reordering */
|
|
ret_attrs = 4; /* nGnRE */
|
|
} else if (s1lo == 8 || s2lo == 8) {
|
|
/* non-Gathering has precedence over Gathering */
|
|
ret_attrs = 8; /* nGRE */
|
|
} else {
|
|
ret_attrs = 0xc; /* GRE */
|
|
}
|
|
} else { /* Normal memory */
|
|
/* Outer/inner cacheability combine independently */
|
|
ret_attrs = combine_cacheattr_nibble(s1hi, s2hi) << 4
|
|
| combine_cacheattr_nibble(s1lo, s2lo);
|
|
}
|
|
return ret_attrs;
|
|
}
|
|
|
|
static uint8_t force_cacheattr_nibble_wb(uint8_t attr)
|
|
{
|
|
/*
|
|
* Given the 4 bits specifying the outer or inner cacheability
|
|
* in MAIR format, return a value specifying Normal Write-Back,
|
|
* with the allocation and transient hints taken from the input
|
|
* if the input specified some kind of cacheable attribute.
|
|
*/
|
|
if (attr == 0 || attr == 4) {
|
|
/*
|
|
* 0 == an UNPREDICTABLE encoding
|
|
* 4 == Non-cacheable
|
|
* Either way, force Write-Back RW allocate non-transient
|
|
*/
|
|
return 0xf;
|
|
}
|
|
/* Change WriteThrough to WriteBack, keep allocation and transient hints */
|
|
return attr | 4;
|
|
}
|
|
|
|
/*
|
|
* Combine the memory type and cacheability attributes of
|
|
* s1 and s2 for the HCR_EL2.FWB == 1 case, returning the
|
|
* combined attributes in MAIR_EL1 format.
|
|
*/
|
|
static uint8_t combined_attrs_fwb(ARMCacheAttrs s1, ARMCacheAttrs s2)
|
|
{
|
|
switch (s2.attrs) {
|
|
case 7:
|
|
/* Use stage 1 attributes */
|
|
return s1.attrs;
|
|
case 6:
|
|
/*
|
|
* Force Normal Write-Back. Note that if S1 is Normal cacheable
|
|
* then we take the allocation hints from it; otherwise it is
|
|
* RW allocate, non-transient.
|
|
*/
|
|
if ((s1.attrs & 0xf0) == 0) {
|
|
/* S1 is Device */
|
|
return 0xff;
|
|
}
|
|
/* Need to check the Inner and Outer nibbles separately */
|
|
return force_cacheattr_nibble_wb(s1.attrs & 0xf) |
|
|
force_cacheattr_nibble_wb(s1.attrs >> 4) << 4;
|
|
case 5:
|
|
/* If S1 attrs are Device, use them; otherwise Normal Non-cacheable */
|
|
if ((s1.attrs & 0xf0) == 0) {
|
|
return s1.attrs;
|
|
}
|
|
return 0x44;
|
|
case 0 ... 3:
|
|
/* Force Device, of subtype specified by S2 */
|
|
return s2.attrs << 2;
|
|
default:
|
|
/*
|
|
* RESERVED values (including RES0 descriptor bit [5] being nonzero);
|
|
* arbitrarily force Device.
|
|
*/
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Combine S1 and S2 cacheability/shareability attributes, per D4.5.4
|
|
* and CombineS1S2Desc()
|
|
*
|
|
* @env: CPUARMState
|
|
* @s1: Attributes from stage 1 walk
|
|
* @s2: Attributes from stage 2 walk
|
|
*/
|
|
static ARMCacheAttrs combine_cacheattrs(uint64_t hcr,
|
|
ARMCacheAttrs s1, ARMCacheAttrs s2)
|
|
{
|
|
ARMCacheAttrs ret;
|
|
bool tagged = false;
|
|
|
|
assert(s2.is_s2_format && !s1.is_s2_format);
|
|
ret.is_s2_format = false;
|
|
|
|
if (s1.attrs == 0xf0) {
|
|
tagged = true;
|
|
s1.attrs = 0xff;
|
|
}
|
|
|
|
/* Combine shareability attributes (table D4-43) */
|
|
if (s1.shareability == 2 || s2.shareability == 2) {
|
|
/* if either are outer-shareable, the result is outer-shareable */
|
|
ret.shareability = 2;
|
|
} else if (s1.shareability == 3 || s2.shareability == 3) {
|
|
/* if either are inner-shareable, the result is inner-shareable */
|
|
ret.shareability = 3;
|
|
} else {
|
|
/* both non-shareable */
|
|
ret.shareability = 0;
|
|
}
|
|
|
|
/* Combine memory type and cacheability attributes */
|
|
if (hcr & HCR_FWB) {
|
|
ret.attrs = combined_attrs_fwb(s1, s2);
|
|
} else {
|
|
ret.attrs = combined_attrs_nofwb(hcr, s1, s2);
|
|
}
|
|
|
|
/*
|
|
* Any location for which the resultant memory type is any
|
|
* type of Device memory is always treated as Outer Shareable.
|
|
* Any location for which the resultant memory type is Normal
|
|
* Inner Non-cacheable, Outer Non-cacheable is always treated
|
|
* as Outer Shareable.
|
|
* TODO: FEAT_XS adds another value (0x40) also meaning iNCoNC
|
|
*/
|
|
if ((ret.attrs & 0xf0) == 0 || ret.attrs == 0x44) {
|
|
ret.shareability = 2;
|
|
}
|
|
|
|
/* TODO: CombineS1S2Desc does not consider transient, only WB, RWA. */
|
|
if (tagged && ret.attrs == 0xff) {
|
|
ret.attrs = 0xf0;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* MMU disabled. S1 addresses within aa64 translation regimes are
|
|
* still checked for bounds -- see AArch64.S1DisabledOutput().
|
|
*/
|
|
static bool get_phys_addr_disabled(CPUARMState *env, target_ulong address,
|
|
MMUAccessType access_type,
|
|
ARMMMUIdx mmu_idx, bool is_secure,
|
|
GetPhysAddrResult *result,
|
|
ARMMMUFaultInfo *fi)
|
|
{
|
|
uint8_t memattr = 0x00; /* Device nGnRnE */
|
|
uint8_t shareability = 0; /* non-sharable */
|
|
int r_el;
|
|
|
|
switch (mmu_idx) {
|
|
case ARMMMUIdx_Stage2:
|
|
case ARMMMUIdx_Stage2_S:
|
|
case ARMMMUIdx_Phys_NS:
|
|
case ARMMMUIdx_Phys_S:
|
|
break;
|
|
|
|
default:
|
|
r_el = regime_el(env, mmu_idx);
|
|
if (arm_el_is_aa64(env, r_el)) {
|
|
int pamax = arm_pamax(env_archcpu(env));
|
|
uint64_t tcr = env->cp15.tcr_el[r_el];
|
|
int addrtop, tbi;
|
|
|
|
tbi = aa64_va_parameter_tbi(tcr, mmu_idx);
|
|
if (access_type == MMU_INST_FETCH) {
|
|
tbi &= ~aa64_va_parameter_tbid(tcr, mmu_idx);
|
|
}
|
|
tbi = (tbi >> extract64(address, 55, 1)) & 1;
|
|
addrtop = (tbi ? 55 : 63);
|
|
|
|
if (extract64(address, pamax, addrtop - pamax + 1) != 0) {
|
|
fi->type = ARMFault_AddressSize;
|
|
fi->level = 0;
|
|
fi->stage2 = false;
|
|
return 1;
|
|
}
|
|
|
|
/*
|
|
* When TBI is disabled, we've just validated that all of the
|
|
* bits above PAMax are zero, so logically we only need to
|
|
* clear the top byte for TBI. But it's clearer to follow
|
|
* the pseudocode set of addrdesc.paddress.
|
|
*/
|
|
address = extract64(address, 0, 52);
|
|
}
|
|
|
|
/* Fill in cacheattr a-la AArch64.TranslateAddressS1Off. */
|
|
if (r_el == 1) {
|
|
uint64_t hcr = arm_hcr_el2_eff_secstate(env, is_secure);
|
|
if (hcr & HCR_DC) {
|
|
if (hcr & HCR_DCT) {
|
|
memattr = 0xf0; /* Tagged, Normal, WB, RWA */
|
|
} else {
|
|
memattr = 0xff; /* Normal, WB, RWA */
|
|
}
|
|
}
|
|
}
|
|
if (memattr == 0 && access_type == MMU_INST_FETCH) {
|
|
if (regime_sctlr(env, mmu_idx) & SCTLR_I) {
|
|
memattr = 0xee; /* Normal, WT, RA, NT */
|
|
} else {
|
|
memattr = 0x44; /* Normal, NC, No */
|
|
}
|
|
shareability = 2; /* outer sharable */
|
|
}
|
|
result->cacheattrs.is_s2_format = false;
|
|
break;
|
|
}
|
|
|
|
result->f.phys_addr = address;
|
|
result->f.prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
|
result->f.lg_page_size = TARGET_PAGE_BITS;
|
|
result->cacheattrs.shareability = shareability;
|
|
result->cacheattrs.attrs = memattr;
|
|
return false;
|
|
}
|
|
|
|
static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw,
|
|
target_ulong address,
|
|
MMUAccessType access_type,
|
|
GetPhysAddrResult *result,
|
|
ARMMMUFaultInfo *fi)
|
|
{
|
|
hwaddr ipa;
|
|
int s1_prot, s1_lgpgsz;
|
|
bool is_secure = ptw->in_secure;
|
|
bool ret, ipa_secure, s2walk_secure;
|
|
ARMCacheAttrs cacheattrs1;
|
|
bool is_el0;
|
|
uint64_t hcr;
|
|
|
|
ret = get_phys_addr_with_struct(env, ptw, address, access_type, result, fi);
|
|
|
|
/* If S1 fails, return early. */
|
|
if (ret) {
|
|
return ret;
|
|
}
|
|
|
|
ipa = result->f.phys_addr;
|
|
ipa_secure = result->f.attrs.secure;
|
|
if (is_secure) {
|
|
/* Select TCR based on the NS bit from the S1 walk. */
|
|
s2walk_secure = !(ipa_secure
|
|
? env->cp15.vstcr_el2 & VSTCR_SW
|
|
: env->cp15.vtcr_el2 & VTCR_NSW);
|
|
} else {
|
|
assert(!ipa_secure);
|
|
s2walk_secure = false;
|
|
}
|
|
|
|
is_el0 = ptw->in_mmu_idx == ARMMMUIdx_Stage1_E0;
|
|
ptw->in_mmu_idx = s2walk_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2;
|
|
ptw->in_ptw_idx = s2walk_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_Phys_NS;
|
|
ptw->in_secure = s2walk_secure;
|
|
|
|
/*
|
|
* S1 is done, now do S2 translation.
|
|
* Save the stage1 results so that we may merge prot and cacheattrs later.
|
|
*/
|
|
s1_prot = result->f.prot;
|
|
s1_lgpgsz = result->f.lg_page_size;
|
|
cacheattrs1 = result->cacheattrs;
|
|
memset(result, 0, sizeof(*result));
|
|
|
|
ret = get_phys_addr_lpae(env, ptw, ipa, access_type, is_el0, result, fi);
|
|
fi->s2addr = ipa;
|
|
|
|
/* Combine the S1 and S2 perms. */
|
|
result->f.prot &= s1_prot;
|
|
|
|
/* If S2 fails, return early. */
|
|
if (ret) {
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Use the maximum of the S1 & S2 page size, so that invalidation
|
|
* of pages > TARGET_PAGE_SIZE works correctly.
|
|
*/
|
|
if (result->f.lg_page_size < s1_lgpgsz) {
|
|
result->f.lg_page_size = s1_lgpgsz;
|
|
}
|
|
|
|
/* Combine the S1 and S2 cache attributes. */
|
|
hcr = arm_hcr_el2_eff_secstate(env, is_secure);
|
|
if (hcr & HCR_DC) {
|
|
/*
|
|
* HCR.DC forces the first stage attributes to
|
|
* Normal Non-Shareable,
|
|
* Inner Write-Back Read-Allocate Write-Allocate,
|
|
* Outer Write-Back Read-Allocate Write-Allocate.
|
|
* Do not overwrite Tagged within attrs.
|
|
*/
|
|
if (cacheattrs1.attrs != 0xf0) {
|
|
cacheattrs1.attrs = 0xff;
|
|
}
|
|
cacheattrs1.shareability = 0;
|
|
}
|
|
result->cacheattrs = combine_cacheattrs(hcr, cacheattrs1,
|
|
result->cacheattrs);
|
|
|
|
/*
|
|
* Check if IPA translates to secure or non-secure PA space.
|
|
* Note that VSTCR overrides VTCR and {N}SW overrides {N}SA.
|
|
*/
|
|
result->f.attrs.secure =
|
|
(is_secure
|
|
&& !(env->cp15.vstcr_el2 & (VSTCR_SA | VSTCR_SW))
|
|
&& (ipa_secure
|
|
|| !(env->cp15.vtcr_el2 & (VTCR_NSA | VTCR_NSW))));
|
|
|
|
return false;
|
|
}
|
|
|
|
static bool get_phys_addr_with_struct(CPUARMState *env, S1Translate *ptw,
|
|
target_ulong address,
|
|
MMUAccessType access_type,
|
|
GetPhysAddrResult *result,
|
|
ARMMMUFaultInfo *fi)
|
|
{
|
|
ARMMMUIdx mmu_idx = ptw->in_mmu_idx;
|
|
bool is_secure = ptw->in_secure;
|
|
ARMMMUIdx s1_mmu_idx;
|
|
|
|
/*
|
|
* The page table entries may downgrade secure to non-secure, but
|
|
* cannot upgrade an non-secure translation regime's attributes
|
|
* to secure.
|
|
*/
|
|
result->f.attrs.secure = is_secure;
|
|
|
|
switch (mmu_idx) {
|
|
case ARMMMUIdx_Phys_S:
|
|
case ARMMMUIdx_Phys_NS:
|
|
/* Checking Phys early avoids special casing later vs regime_el. */
|
|
return get_phys_addr_disabled(env, address, access_type, mmu_idx,
|
|
is_secure, result, fi);
|
|
|
|
case ARMMMUIdx_Stage1_E0:
|
|
case ARMMMUIdx_Stage1_E1:
|
|
case ARMMMUIdx_Stage1_E1_PAN:
|
|
/* First stage lookup uses second stage for ptw. */
|
|
ptw->in_ptw_idx = is_secure ? ARMMMUIdx_Stage2_S : ARMMMUIdx_Stage2;
|
|
break;
|
|
|
|
case ARMMMUIdx_E10_0:
|
|
s1_mmu_idx = ARMMMUIdx_Stage1_E0;
|
|
goto do_twostage;
|
|
case ARMMMUIdx_E10_1:
|
|
s1_mmu_idx = ARMMMUIdx_Stage1_E1;
|
|
goto do_twostage;
|
|
case ARMMMUIdx_E10_1_PAN:
|
|
s1_mmu_idx = ARMMMUIdx_Stage1_E1_PAN;
|
|
do_twostage:
|
|
/*
|
|
* Call ourselves recursively to do the stage 1 and then stage 2
|
|
* translations if mmu_idx is a two-stage regime, and EL2 present.
|
|
* Otherwise, a stage1+stage2 translation is just stage 1.
|
|
*/
|
|
ptw->in_mmu_idx = mmu_idx = s1_mmu_idx;
|
|
if (arm_feature(env, ARM_FEATURE_EL2) &&
|
|
!regime_translation_disabled(env, ARMMMUIdx_Stage2, is_secure)) {
|
|
return get_phys_addr_twostage(env, ptw, address, access_type,
|
|
result, fi);
|
|
}
|
|
/* fall through */
|
|
|
|
default:
|
|
/* Single stage and second stage uses physical for ptw. */
|
|
ptw->in_ptw_idx = is_secure ? ARMMMUIdx_Phys_S : ARMMMUIdx_Phys_NS;
|
|
break;
|
|
}
|
|
|
|
result->f.attrs.user = regime_is_user(env, mmu_idx);
|
|
|
|
/*
|
|
* Fast Context Switch Extension. This doesn't exist at all in v8.
|
|
* In v7 and earlier it affects all stage 1 translations.
|
|
*/
|
|
if (address < 0x02000000 && mmu_idx != ARMMMUIdx_Stage2
|
|
&& !arm_feature(env, ARM_FEATURE_V8)) {
|
|
if (regime_el(env, mmu_idx) == 3) {
|
|
address += env->cp15.fcseidr_s;
|
|
} else {
|
|
address += env->cp15.fcseidr_ns;
|
|
}
|
|
}
|
|
|
|
if (arm_feature(env, ARM_FEATURE_PMSA)) {
|
|
bool ret;
|
|
result->f.lg_page_size = TARGET_PAGE_BITS;
|
|
|
|
if (arm_feature(env, ARM_FEATURE_V8)) {
|
|
/* PMSAv8 */
|
|
ret = get_phys_addr_pmsav8(env, address, access_type, mmu_idx,
|
|
is_secure, result, fi);
|
|
} else if (arm_feature(env, ARM_FEATURE_V7)) {
|
|
/* PMSAv7 */
|
|
ret = get_phys_addr_pmsav7(env, address, access_type, mmu_idx,
|
|
is_secure, result, fi);
|
|
} else {
|
|
/* Pre-v7 MPU */
|
|
ret = get_phys_addr_pmsav5(env, address, access_type, mmu_idx,
|
|
is_secure, result, fi);
|
|
}
|
|
qemu_log_mask(CPU_LOG_MMU, "PMSA MPU lookup for %s at 0x%08" PRIx32
|
|
" mmu_idx %u -> %s (prot %c%c%c)\n",
|
|
access_type == MMU_DATA_LOAD ? "reading" :
|
|
(access_type == MMU_DATA_STORE ? "writing" : "execute"),
|
|
(uint32_t)address, mmu_idx,
|
|
ret ? "Miss" : "Hit",
|
|
result->f.prot & PAGE_READ ? 'r' : '-',
|
|
result->f.prot & PAGE_WRITE ? 'w' : '-',
|
|
result->f.prot & PAGE_EXEC ? 'x' : '-');
|
|
|
|
return ret;
|
|
}
|
|
|
|
/* Definitely a real MMU, not an MPU */
|
|
|
|
if (regime_translation_disabled(env, mmu_idx, is_secure)) {
|
|
return get_phys_addr_disabled(env, address, access_type, mmu_idx,
|
|
is_secure, result, fi);
|
|
}
|
|
|
|
if (regime_using_lpae_format(env, mmu_idx)) {
|
|
return get_phys_addr_lpae(env, ptw, address, access_type, false,
|
|
result, fi);
|
|
} else if (arm_feature(env, ARM_FEATURE_V7) ||
|
|
regime_sctlr(env, mmu_idx) & SCTLR_XP) {
|
|
return get_phys_addr_v6(env, ptw, address, access_type, result, fi);
|
|
} else {
|
|
return get_phys_addr_v5(env, ptw, address, access_type, result, fi);
|
|
}
|
|
}
|
|
|
|
bool get_phys_addr_with_secure(CPUARMState *env, target_ulong address,
|
|
MMUAccessType access_type, ARMMMUIdx mmu_idx,
|
|
bool is_secure, GetPhysAddrResult *result,
|
|
ARMMMUFaultInfo *fi)
|
|
{
|
|
S1Translate ptw = {
|
|
.in_mmu_idx = mmu_idx,
|
|
.in_secure = is_secure,
|
|
};
|
|
return get_phys_addr_with_struct(env, &ptw, address, access_type,
|
|
result, fi);
|
|
}
|
|
|
|
bool get_phys_addr(CPUARMState *env, target_ulong address,
|
|
MMUAccessType access_type, ARMMMUIdx mmu_idx,
|
|
GetPhysAddrResult *result, ARMMMUFaultInfo *fi)
|
|
{
|
|
bool is_secure;
|
|
|
|
switch (mmu_idx) {
|
|
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:
|
|
case ARMMMUIdx_Stage1_E0:
|
|
case ARMMMUIdx_Stage1_E1:
|
|
case ARMMMUIdx_Stage1_E1_PAN:
|
|
case ARMMMUIdx_E2:
|
|
is_secure = arm_is_secure_below_el3(env);
|
|
break;
|
|
case ARMMMUIdx_Stage2:
|
|
case ARMMMUIdx_Phys_NS:
|
|
case ARMMMUIdx_MPrivNegPri:
|
|
case ARMMMUIdx_MUserNegPri:
|
|
case ARMMMUIdx_MPriv:
|
|
case ARMMMUIdx_MUser:
|
|
is_secure = false;
|
|
break;
|
|
case ARMMMUIdx_E3:
|
|
case ARMMMUIdx_Stage2_S:
|
|
case ARMMMUIdx_Phys_S:
|
|
case ARMMMUIdx_MSPrivNegPri:
|
|
case ARMMMUIdx_MSUserNegPri:
|
|
case ARMMMUIdx_MSPriv:
|
|
case ARMMMUIdx_MSUser:
|
|
is_secure = true;
|
|
break;
|
|
default:
|
|
g_assert_not_reached();
|
|
}
|
|
return get_phys_addr_with_secure(env, address, access_type, mmu_idx,
|
|
is_secure, result, fi);
|
|
}
|
|
|
|
hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr,
|
|
MemTxAttrs *attrs)
|
|
{
|
|
ARMCPU *cpu = ARM_CPU(cs);
|
|
CPUARMState *env = &cpu->env;
|
|
S1Translate ptw = {
|
|
.in_mmu_idx = arm_mmu_idx(env),
|
|
.in_secure = arm_is_secure(env),
|
|
.in_debug = true,
|
|
};
|
|
GetPhysAddrResult res = {};
|
|
ARMMMUFaultInfo fi = {};
|
|
bool ret;
|
|
|
|
ret = get_phys_addr_with_struct(env, &ptw, addr, MMU_DATA_LOAD, &res, &fi);
|
|
*attrs = res.f.attrs;
|
|
|
|
if (ret) {
|
|
return -1;
|
|
}
|
|
return res.f.phys_addr;
|
|
}
|