From patchwork Tue Dec 3 00:17:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 13891447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 04479E6C5E4 for ; Tue, 3 Dec 2024 00:18:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIGbx-0004NY-Cg; Mon, 02 Dec 2024 19:17:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tIGbv-0004N2-4l for qemu-devel@nongnu.org; Mon, 02 Dec 2024 19:17:51 -0500 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIGbr-0003JK-TL for qemu-devel@nongnu.org; Mon, 02 Dec 2024 19:17:50 -0500 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-7250906bc63so3639627b3a.1 for ; Mon, 02 Dec 2024 16:17:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1733185066; x=1733789866; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xtafg9Dir4y2uIChFSy3qfJKxJ0Jsy/rXD79IqfNsb4=; b=nNAzjYqJCRtWoXKsMA5lawkJ96TTu5x2xfdrOtP/RnKE9wUtYLTqN6zzv11dpmqrvI lf9SC7RMwH89o4Qwzdy3jUTXq3+36Or5KzW5bEJ8LuwkK0icY1fveZITxCq2eYMxDi2h zq4Gx6jVsI87oG3le2ieOWDVT0NhYJJ1g4JPRlu8YA1mH9E0CWcfr7n2+gTleIfd4YVY /LSMJRm8jFbllt2NnJ9jZiiYJT3Bci9vDU7LC6XNEy1rCwn0hwigHYO8NKQUfPJKTrpi dsQiOcgd5n6+dUBxpXwlYTzL+rUtXg9vuJ2beqSjzwQF7SV+k7VVMezbvGfPNmfM3U1c iWHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733185066; x=1733789866; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xtafg9Dir4y2uIChFSy3qfJKxJ0Jsy/rXD79IqfNsb4=; b=bJm4bcCZRkC4/AtqBOSDXltMjxdM0Ec0qJO9pGh7bAUVSci1Op/72NPF+gHnitnGip PDeIMRok1vVLACGQQFUdHOuDmq00JdMXoFD//0UDpxTXGBnpNyvFw8BpoUuYVRvOhONG 1v2p2D7hduP+w1As1PIwvQjlbZpmduYhGFAm1FQFJ3BMbG0JXa3pZZ7F99W4U07x5rjH 3UtLEbqLaqyWjPU365I4igzpgIdIi6YwHSRsvJexMnz6AzeN2NBvC6kKQQ1OIlXFEzFI J1WWaGjF/hq6obV68w5EXCXb0/KmxGwgWUKwQmy3BD7yaojGRIUzX4RMKqvqNKmSIbgS v1AQ== X-Gm-Message-State: AOJu0YypziFic4Q8rbNc1gCDd21gBzdDIo+JDVmTN5Puo6i9Syge7BEZ T831lZwssPCbDhZxPP2zYElucQ52x7tOdcG1M1hTKaGLX6PtK6cfRENwgSBcAOSUgyiN74JnyrE ZBR4uHA== X-Gm-Gg: ASbGncuWfjsXHrV5yBLzNXPTOBzpINjZwUQ5fkv28eSDd9D6zTiC5aEg6u+p4kRa+D2 SpwfWsrcQkmULDVrgjkmUgcsR7C2I1OR8OuxFMLJelodUdyXddaZVeBnKakkBmauyTMhLcJMvhW a1f/vVsj+KKwKcXFL03CrjaIbErCOSq6gv6OUf0SKnP4fj314IA7HKLHfnNb6trCH2O1KPPzPIS Ytkzh4dOYdhxo8oATvmdKb/YqIqgYNXRy6Zse48gkvkI4rCznJq+YGY0j/vno+wv7gfTd7sXshC Owh2Vk9U X-Google-Smtp-Source: AGHT+IFTO30fnQ0nbsGpYUOrwVB+dfbfFpyxs1U0OsNewsPtItxdEOHLWMfQpgP50canlFkBB/YdRw== X-Received: by 2002:a17:902:e809:b0:215:758c:52ea with SMTP id d9443c01a7336-215bd8435dbmr6172185ad.9.1733185066062; Mon, 02 Dec 2024 16:17:46 -0800 (PST) Received: from pc.. (216-180-64-156.dyn.novuscom.net. [216.180.64.156]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21527a4375asm80704875ad.138.2024.12.02.16.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 16:17:45 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: marcin.juszkiewicz@linaro.org, gustavo.romero@linaro.org, qemu-arm@nongnu.org, alex.bennee@linaro.org, jean-philippe@linaro.org, mathieu.poirier@linaro.org, Peter Maydell , Pierrick Bouvier Subject: [PATCH v3] tests/functional/aarch64: add tests for FEAT_RME Date: Mon, 2 Dec 2024 16:17:41 -0800 Message-Id: <20241203001741.2068452-1-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This boot an OP-TEE environment, and launch a nested guest VM inside it using the Realms feature. We do it for virt and sbsa-ref platforms. Signed-off-by: Pierrick Bouvier ----- v2: - move test to its own file - add sbsa test - check output of `cca-workload-attestation report` v3: - build and run test with cca-v4 images - factorize nested guest test between both tests - remove accel tcg option as it is the default when running tests Note: It's a long test and there is a work in progress to understand why debug build is so slow (x12 vs optimized). Signed-off-by: Pierrick Bouvier --- tests/functional/meson.build | 4 + tests/functional/test_aarch64_rme_sbsaref.py | 70 +++++++++++++ tests/functional/test_aarch64_rme_virt.py | 100 +++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100755 tests/functional/test_aarch64_rme_sbsaref.py create mode 100755 tests/functional/test_aarch64_rme_virt.py diff --git a/tests/functional/meson.build b/tests/functional/meson.build index 5c048cfac6d..b975a1560df 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -13,6 +13,8 @@ endif test_timeouts = { 'aarch64_aspeed' : 600, 'aarch64_raspi4' : 480, + 'aarch64_rme_virt' : 720, + 'aarch64_rme_sbsaref' : 720, 'aarch64_sbsaref_alpine' : 720, 'aarch64_sbsaref_freebsd' : 720, 'aarch64_tuxrun' : 240, @@ -52,6 +54,8 @@ tests_aarch64_system_thorough = [ 'aarch64_aspeed', 'aarch64_raspi3', 'aarch64_raspi4', + 'aarch64_rme_virt', + 'aarch64_rme_sbsaref', 'aarch64_sbsaref', 'aarch64_sbsaref_alpine', 'aarch64_sbsaref_freebsd', diff --git a/tests/functional/test_aarch64_rme_sbsaref.py b/tests/functional/test_aarch64_rme_sbsaref.py new file mode 100755 index 00000000000..398562c166f --- /dev/null +++ b/tests/functional/test_aarch64_rme_sbsaref.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +# +# Functional test that boots a Realms environment on sbsa-ref machine and a +# nested guest VM using it. +# +# Copyright (c) 2024 Linaro Ltd. +# +# Author: Pierrick Bouvier +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import time +import os +import logging + +from qemu_test import QemuSystemTest, Asset +from qemu_test import exec_command, wait_for_console_pattern +from qemu_test import exec_command_and_wait_for_pattern +from qemu_test.utils import archive_extract +from test_aarch64_rme_virt import test_realms_guest + +class Aarch64RMESbsaRefMachine(QemuSystemTest): + + # Stack is built with OP-TEE build environment from those instructions: + # https://linaro.atlassian.net/wiki/spaces/QEMU/pages/29051027459/ + # https://github.com/pbo-linaro/qemu-rme-stack + ASSET_RME_STACK_SBSA = Asset( + ('https://fileserver.linaro.org/s/KJyeBxL82mz2r7F/' + 'download/rme-stack-op-tee-4.2.0-cca-v4-sbsa.tar.gz'), + 'dd9ab28ec869bdf3b5376116cb3689103b43433fd5c4bca0f4a8d8b3c104999e') + + # This tests the FEAT_RME cpu implementation, by booting a VM supporting it, + # and launching a nested VM using it. + def test_aarch64_rme_sbsaref(self): + stack_path_tar_gz = self.ASSET_RME_STACK_SBSA.fetch() + archive_extract(stack_path_tar_gz, self.workdir) + + self.set_machine('sbsa-ref') + self.vm.set_console() + self.require_accelerator('tcg') + + rme_stack = os.path.join(self.workdir, + 'rme-stack-op-tee-4.2.0-cca-v4-sbsa') + pflash0 = os.path.join(rme_stack, 'images', 'SBSA_FLASH0.fd') + pflash1 = os.path.join(rme_stack, 'images', 'SBSA_FLASH1.fd') + virtual = os.path.join(rme_stack, 'images', 'disks', 'virtual') + drive = os.path.join(rme_stack, 'out-br', 'images', 'rootfs.ext4') + + self.vm.add_args('-cpu', 'max,x-rme=on') + self.vm.add_args('-m', '2G') + self.vm.add_args('-M', 'sbsa-ref') + self.vm.add_args('-drive', f'file={pflash0},format=raw,if=pflash') + self.vm.add_args('-drive', f'file={pflash1},format=raw,if=pflash') + self.vm.add_args('-drive', f'file=fat:rw:{virtual},format=raw') + self.vm.add_args('-drive', f'format=raw,if=none,file={drive},id=hd0') + self.vm.add_args('-device', 'virtio-blk-pci,drive=hd0') + self.vm.add_args('-device', 'virtio-9p-pci,fsdev=shr0,mount_tag=shr0') + self.vm.add_args('-fsdev', f'local,security_model=none,path={rme_stack},id=shr0') + self.vm.add_args('-device', 'virtio-net-pci,netdev=net0') + self.vm.add_args('-netdev', 'user,id=net0') + + self.vm.launch() + # Wait for host VM boot to complete. + wait_for_console_pattern(self, 'Welcome to Buildroot') + exec_command_and_wait_for_pattern(self, 'root', '#') + + test_realms_guest(self) + +if __name__ == '__main__': + QemuSystemTest.main() diff --git a/tests/functional/test_aarch64_rme_virt.py b/tests/functional/test_aarch64_rme_virt.py new file mode 100755 index 00000000000..be240c691c2 --- /dev/null +++ b/tests/functional/test_aarch64_rme_virt.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 +# +# Functional test that boots a Realms environment on virt machine and a nested +# guest VM using it. +# +# Copyright (c) 2024 Linaro Ltd. +# +# Author: Pierrick Bouvier +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import time +import os +import logging + +from qemu_test import QemuSystemTest, Asset +from qemu_test import exec_command, wait_for_console_pattern +from qemu_test import exec_command_and_wait_for_pattern +from qemu_test.utils import archive_extract + +def test_realms_guest(test_rme_instance): + + # Boot the (nested) guest VM + exec_command(test_rme_instance, + 'qemu-system-aarch64 -M virt,gic-version=3 ' + '-cpu host -enable-kvm -m 512M ' + '-M confidential-guest-support=rme0 ' + '-object rme-guest,id=rme0 ' + '-device virtio-net-pci,netdev=net0,romfile= ' + '-netdev user,id=net0 ' + '-kernel /mnt/out/bin/Image ' + '-initrd /mnt/out-br/images/rootfs.cpio ' + '-serial stdio') + # Detect Realm activation during (nested) guest boot. + wait_for_console_pattern(test_rme_instance, + 'SMC_RMI_REALM_ACTIVATE') + # Wait for (nested) guest boot to complete. + wait_for_console_pattern(test_rme_instance, + 'Welcome to Buildroot') + exec_command_and_wait_for_pattern(test_rme_instance, 'root', '#') + # query (nested) guest cca report + exec_command(test_rme_instance, 'cca-workload-attestation report') + wait_for_console_pattern(test_rme_instance, + '"cca-platform-hash-algo-id": "sha-256"') + wait_for_console_pattern(test_rme_instance, + '"cca-realm-hash-algo-id": "sha-512"') + wait_for_console_pattern(test_rme_instance, + '"cca-realm-public-key-hash-algo-id": "sha-256"') + +class Aarch64RMEVirtMachine(QemuSystemTest): + + # Stack is built with OP-TEE build environment from those instructions: + # https://linaro.atlassian.net/wiki/spaces/QEMU/pages/29051027459/ + # https://github.com/pbo-linaro/qemu-rme-stack + ASSET_RME_STACK_VIRT = Asset( + ('https://fileserver.linaro.org/s/iaRsNDJp2CXHMSJ/' + 'download/rme-stack-op-tee-4.2.0-cca-v4-qemu_v8.tar.gz'), + '1851adc232b094384d8b879b9a2cfff07ef3d6205032b85e9b3a4a9ae6b0b7ad') + + # This tests the FEAT_RME cpu implementation, by booting a VM supporting it, + # and launching a nested VM using it. + def test_aarch64_rme_virt(self): + stack_path_tar_gz = self.ASSET_RME_STACK_VIRT.fetch() + archive_extract(stack_path_tar_gz, self.workdir) + + self.set_machine('virt') + self.vm.set_console() + self.require_accelerator('tcg') + + rme_stack = os.path.join(self.workdir, + 'rme-stack-op-tee-4.2.0-cca-v4-qemu_v8') + kernel = os.path.join(rme_stack, 'out', 'bin', 'Image') + bios = os.path.join(rme_stack, 'out', 'bin', 'flash.bin') + drive = os.path.join(rme_stack, 'out-br', 'images', 'rootfs.ext4') + + self.vm.add_args('-cpu', 'max,x-rme=on') + self.vm.add_args('-m', '2G') + self.vm.add_args('-M', 'virt,acpi=off,' + 'virtualization=on,' + 'secure=on,' + 'gic-version=3') + self.vm.add_args('-bios', bios) + self.vm.add_args('-kernel', kernel) + self.vm.add_args('-drive', f'format=raw,if=none,file={drive},id=hd0') + self.vm.add_args('-device', 'virtio-blk-pci,drive=hd0') + self.vm.add_args('-device', 'virtio-9p-device,fsdev=shr0,mount_tag=shr0') + self.vm.add_args('-fsdev', f'local,security_model=none,path={rme_stack},id=shr0') + self.vm.add_args('-device', 'virtio-net-pci,netdev=net0') + self.vm.add_args('-netdev', 'user,id=net0') + self.vm.add_args('-append', 'root=/dev/vda') + + self.vm.launch() + # Wait for host VM boot to complete. + wait_for_console_pattern(self, 'Welcome to Buildroot') + exec_command_and_wait_for_pattern(self, 'root', '#') + + test_realms_guest(self) + +if __name__ == '__main__': + QemuSystemTest.main()