| 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Functional test that boots a Realms environment on sbsa-ref machine and a |
| 4 | # nested 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 | import os |
| 13 | from os.path import join |
| 14 | import shutil |
| 15 | |
| 16 | from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern |
| 17 | |
| 18 | |
| 19 | class Aarch64RMESbsaRefMachine(QemuSystemTest): |
| 20 | |
| 21 | # Stack is inspired from: |
| 22 | # https://linaro.atlassian.net/wiki/spaces/QEMU/pages/29051027459/ |
| 23 | # Built from: |
| 24 | # https://github.com/p-b-o/qemu-linux-stack/tree/rme_sbsa_release |
| 25 | # ./build.sh && ./archive_artifacts.sh out.tar.xz |
| 26 | ASSET_RME_STACK_SBSA = Asset( |
| 27 | ('https://github.com/p-b-o/qemu-linux-stack/' |
| 28 | 'releases/download/build/rme_sbsa_release-74b7fab.tar.xz'), |
| 29 | '82a754bacea04e709cb1cf2759d1d12d09fabd612e014961eb32368723c7920a') |
| 30 | |
| 31 | # This tests the FEAT_RME cpu implementation, by booting a VM supporting it, |
| 32 | # and launching a nested VM using it. |
| 33 | def test_aarch64_rme_sbsaref(self): |
| 34 | self.set_machine('sbsa-ref') |
| 35 | self.require_accelerator('tcg') |
| 36 | self.require_netdev('user') |
| 37 | |
| 38 | self.vm.set_console() |
| 39 | |
| 40 | stack_path_tar = self.ASSET_RME_STACK_SBSA.fetch() |
| 41 | self.archive_extract(stack_path_tar, format="tar") |
| 42 | |
| 43 | rme_stack = self.scratch_file('.') |
| 44 | pflash0 = join(rme_stack, 'out', 'SBSA_FLASH0.fd') |
| 45 | pflash1 = join(rme_stack, 'out', 'SBSA_FLASH1.fd') |
| 46 | rootfs = join(rme_stack, 'out', 'host.ext4') |
| 47 | |
| 48 | efi = join(rme_stack, 'out', 'EFI') |
| 49 | os.makedirs(efi, exist_ok=True) |
| 50 | shutil.copyfile(join(rme_stack, 'out', 'Image'), join(efi, 'Image')) |
| 51 | with open(join(efi, 'startup.nsh'), 'w', encoding='ascii') as startup: |
| 52 | startup.write('fs0:Image nokaslr root=/dev/vda rw init=/init --' |
| 53 | ' /host/out/lkvm run --realm' |
| 54 | ' -m 256m' |
| 55 | ' --restricted_mem' |
| 56 | ' --kernel /host/out/Image' |
| 57 | ' --disk /host/out/guest.ext4' |
| 58 | ' --params "root=/dev/vda rw init=/init"') |
| 59 | |
| 60 | self.vm.add_args('-cpu', 'max,x-rme=on') |
| 61 | self.vm.add_args('-smp', '1') |
| 62 | self.vm.add_args('-m', '2G') |
| 63 | self.vm.add_args('-M', 'sbsa-ref') |
| 64 | self.vm.add_args('-drive', f'file={pflash0},format=raw,if=pflash') |
| 65 | self.vm.add_args('-drive', f'file={pflash1},format=raw,if=pflash') |
| 66 | self.vm.add_args('-drive', f'file=fat:rw:{efi},format=raw') |
| 67 | self.vm.add_args('-drive', f'format=raw,file={rootfs},if=virtio') |
| 68 | self.vm.add_args('-virtfs', |
| 69 | f'local,path={rme_stack}/,mount_tag=host,' |
| 70 | 'security_model=mapped,readonly=off') |
| 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() |