| 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Functional test that boots a Realms environment on virt machine and a nested |
| 4 | # guest VM using it. |
| 5 | # |
| 6 | # Copyright (c) 2024 Linaro Ltd. |
| 7 | # |
| 8 | # Author: Pierrick Bouvier <pierrick.bouvier@linaro.org> |
| 9 | # |
| 10 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 11 | |
| 12 | from os.path import join |
| 13 | |
| 14 | from qemu_test import QemuSystemTest, Asset |
| 15 | from qemu_test import exec_command, wait_for_console_pattern |
| 16 | from qemu_test import exec_command_and_wait_for_pattern |
| 17 | |
| 18 | class Aarch64RMEVirtMachine(QemuSystemTest): |
| 19 | |
| 20 | # Stack is inspired from: |
| 21 | # https://linaro.atlassian.net/wiki/spaces/QEMU/pages/29051027459/ |
| 22 | # Built from: |
| 23 | # https://github.com/p-b-o/qemu-linux-stack/tree/rme_release |
| 24 | # ./build.sh && ./archive_artifacts.sh out.tar.xz |
| 25 | ASSET_RME_STACK_VIRT = Asset( |
| 26 | ('https://github.com/p-b-o/qemu-linux-stack/' |
| 27 | 'releases/download/build/rme_release-2701e89.tar.xz'), |
| 28 | '8c40af440f5bd1518f7add7d0a43b39289865ee48430979db8024cb897a74790') |
| 29 | |
| 30 | # This tests the FEAT_RME cpu implementation, by booting a VM supporting it, |
| 31 | # and launching a nested VM using it. |
| 32 | def test_aarch64_rme_virt(self): |
| 33 | self.set_machine('virt') |
| 34 | self.require_accelerator('tcg') |
| 35 | self.require_netdev('user') |
| 36 | |
| 37 | self.vm.set_console() |
| 38 | |
| 39 | stack_path_tar = self.ASSET_RME_STACK_VIRT.fetch() |
| 40 | self.archive_extract(stack_path_tar, format="tar") |
| 41 | |
| 42 | rme_stack = self.scratch_file('.') |
| 43 | kernel = join(rme_stack, 'out', 'Image') |
| 44 | bios = join(rme_stack, 'out', 'flash.bin') |
| 45 | rootfs = join(rme_stack, 'out', 'host.ext4') |
| 46 | |
| 47 | self.vm.add_args('-cpu', 'max,x-rme=on') |
| 48 | self.vm.add_args('-smp', '1') |
| 49 | self.vm.add_args('-m', '2G') |
| 50 | self.vm.add_args('-M', 'virt,acpi=off,' |
| 51 | 'virtualization=on,' |
| 52 | 'secure=on,' |
| 53 | 'gic-version=3') |
| 54 | self.vm.add_args('-bios', bios) |
| 55 | self.vm.add_args('-kernel', kernel) |
| 56 | self.vm.add_args('-drive', f'format=raw,file={rootfs},if=virtio') |
| 57 | self.vm.add_args('-virtfs', |
| 58 | f'local,path={rme_stack}/,mount_tag=host,' |
| 59 | 'security_model=mapped,readonly=off') |
| 60 | # We need to add nokaslr to avoid triggering this sporadic bug: |
| 61 | # https://gitlab.com/qemu-project/qemu/-/issues/2823 |
| 62 | self.vm.add_args('-append', |
| 63 | 'nokaslr root=/dev/vda rw init=/init --' |
| 64 | ' /host/out/lkvm run --realm' |
| 65 | ' -m 256m' |
| 66 | ' --restricted_mem' |
| 67 | ' --kernel /host/out/Image' |
| 68 | ' --disk /host/out/guest.ext4' |
| 69 | ' --params "root=/dev/vda rw init=/init"') |
| 70 | |
| 71 | self.vm.launch() |
| 72 | # Wait for host and guest VM boot to complete. |
| 73 | wait_for_console_pattern(self, 'root@guest', |
| 74 | failure_message='Kernel panic') |
| 75 | |
| 76 | if __name__ == '__main__': |
| 77 | QemuSystemTest.main() |