From nobody Wed Apr 9 01:04:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1736338730; cv=none; d=zohomail.com; s=zohoarc; b=UpkloG2bbN291DzMK1lCHGBCZaYKX10jYt26zK3NNcodE7cbe9wk2hB4mru/RbWeeVchJS+e9eYq0gF/oHZXxHxMxxrQj1RlcCFEtj/bOk2pu7rJCNCf05ssbwqdC2mlQBOoz5Y6DQsjn1y37hy5sLeSi2IIO2D2thsuO64RpHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736338730; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jQuRMWlbCCi01i6ad4dl2DxKLluayG2p5Bfu87XJ3wk=; b=gczY2tI1ItWhDn66MoAdBgxWFmsOWgczwxlD+rL1Irr2HpxPKgUiUIJCi2v9EHyXcHeMwjrUvc36Ts6Kfx2uMR3w8W2vzYYqZa+FmbG0q+UROWh7NSyHDrfOQazlJR24jy8OZlzSy4Ha5KxEgcRZnP4EGounRSR0G9g+74sMWc8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17363387308681020.8428356716319; Wed, 8 Jan 2025 04:18:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tVUzw-0008S8-Ag; Wed, 08 Jan 2025 07:17:20 -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 1tVUuX-0000qu-OQ for qemu-devel@nongnu.org; Wed, 08 Jan 2025 07:11:49 -0500 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tVUuQ-0007H1-OU for qemu-devel@nongnu.org; Wed, 08 Jan 2025 07:11:45 -0500 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5d96944401dso2596998a12.0 for ; Wed, 08 Jan 2025 04:11:04 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d80665253dsm25218279a12.0.2025.01.08.04.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2025 04:11:02 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 0FBC75F8FD; Wed, 8 Jan 2025 12:10:56 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736338263; x=1736943063; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jQuRMWlbCCi01i6ad4dl2DxKLluayG2p5Bfu87XJ3wk=; b=W/nI6uklwTqzVkMI+CUJ85WBDN+yPTdGsEQvMXbiTl/5kdoyV78UfBVtY7tnFn0waO dKTG1QHadKnkHaKbTAjv7rUMqjRgMxzI+RNnNwdCQKq760L1bGJVMMXjvQgjjzoUR2eR OtJZjvp7zZN1GjLkdbUXpF2F8EDUSCgZUeA+S7+sn0BLRqiOp/n2gJPNAtGhhD1szMZw IYarPwZO+IZhWjtHoGoRtbgryACuQREbsy41Q4RtFPyRIi4aRvF5ssAt5q+WBz2fgpzJ jXwjdPGabD0vDSGaCn+h3yEBILJ8iu9eQE8X5aN+qQ6wLBJ6MRBHXKECU+r6b3jXvs0L +tNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736338263; x=1736943063; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jQuRMWlbCCi01i6ad4dl2DxKLluayG2p5Bfu87XJ3wk=; b=RxWpCga4MDnpy7ZV5QdFXFYQyBWdiSC6c1Ap3dP/GBrhtcD+8rdYvVAA9xbx5VX8NE oob2n1DU9kPtDzZJwKE3WwGwv96Psm+6OADoBLFYuufpqNhtFI0iV4eDH2rPcLzOgCtX iOUH8LSUChJyB1iHZNRm+LtT8llshK57mqH6Jq3xznlSN7Z6pAvj1Kmr4QsbrKdVXD5B lcr9n1QtCTbrYsegT6jVTPKlUZkNcb75W47u7INVlfl1NRZjkM9gneFoaPEdEdJY5dds uoZi82yNwDRje1Puwk50CFWId9Ika/t2u0mBJU77j+QEN4w6E98NYHOTlc1h4c1XkvrU QzuQ== X-Gm-Message-State: AOJu0YySRWsHtJDNv7eO88Ef35oVZoMsFJoqI7+PwSAmZoRmUuBFlWg6 7JE/Srv0DVurEI79knF0vJH57wCZHzyOcWy0AxWhdXaEgcCg9BmZ4ipt//oWISc= X-Gm-Gg: ASbGncu7ffbzfcUPYxFd5ZD5E7/nn59ag3G+RXcGZJta5/h/LGL30seC5ve364ag6+D DORjocYujRmgZ/5QuYSlQEB7yskn64TDSO5c05QDf3f/7UCqL1q+6+DBm7XJmL0/66d9FGWqueg MCP0RzNcZjaHIDtLQTj7/neLwfxzw7zdm6JB3SuKpB6V3V4d+ez+2W3J9ttkXXUwdy4hydbgSpr UBqqvExN1IKrNhl+3HVB5+N5jo/X+daFdfc4oFOUgN3ZtzAFlxHAhU= X-Google-Smtp-Source: AGHT+IEK/lzeAmHbhxE6zwt6LTbKH1aVfqfRK7n59KxUXietLYf6pdjWxEs6fyxVEkrx/xpHfA7G0Q== X-Received: by 2002:a05:6402:27d2:b0:5d1:22d2:8965 with SMTP id 4fb4d7f45d1cf-5d972e6e417mr2286567a12.30.1736338263385; Wed, 08 Jan 2025 04:11:03 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Halil Pasic , Aurelien Jarno , qemu-riscv@nongnu.org, Radoslaw Biernacki , Daniel Henrique Barboza , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Marcel Apfelbaum , Richard Henderson , Beraldo Leal , Fabiano Rosas , Mark Cave-Ayland , Laurent Vivier , Nicholas Piggin , Marcin Juszkiewicz , Christian Borntraeger , Wainer dos Santos Moschetta , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Ed Maste , Jiaxun Yang , Bernhard Beschow , Bin Meng , qemu-ppc@nongnu.org, qemu-arm@nongnu.org, Laurent Vivier , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow , "Michael S. Tsirkin" , Pavel Dovgalyuk , Alistair Francis , Liu Zhiwei , Harsh Prateek Bora , Leif Lindholm , Cleber Rosa , Thomas Huth , Paolo Bonzini , qemu-s390x@nongnu.org, Eric Farman , Weiwei Li , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster , Daniel Henrique Barboza , Palmer Dabbelt , Peter Maydell , Li-Wen Hsu , Pierrick Bouvier Subject: [PATCH v4 15/32] tests/functional/aarch64: add tests for FEAT_RME Date: Wed, 8 Jan 2025 12:10:37 +0000 Message-Id: <20250108121054.1126164-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250108121054.1126164-1-alex.bennee@linaro.org> References: <20250108121054.1126164-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x529.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1736338732943116600 From: Pierrick Bouvier 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 Message-Id: <20241220165212.3653495-1-pierrick.bouvier@linaro.org> [AJB: tweak ordering of setup] Signed-off-by: Alex Benn=C3=A9e Tested-by: Thomas Huth ----- 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). v4: - use pauth-impdef=3Don to speed up build time execution (x2.5 faster) - increase timeout value v5: - migrate test to new archive_extract helper v6: - archive_extract helper needs explicit format for .tar.gz archives - move set_machine/require_accel to the front --- tests/functional/meson.build | 4 + tests/functional/test_aarch64_rme_sbsaref.py | 69 ++++++++++++++ tests/functional/test_aarch64_rme_virt.py | 98 ++++++++++++++++++++ 3 files changed, 171 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 7890dcb86d..bd3d903cfc 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -13,6 +13,8 @@ endif test_timeouts =3D { 'aarch64_aspeed' : 600, 'aarch64_raspi4' : 480, + 'aarch64_rme_virt' : 1200, + 'aarch64_rme_sbsaref' : 1200, 'aarch64_sbsaref_alpine' : 720, 'aarch64_sbsaref_freebsd' : 720, 'aarch64_tuxrun' : 240, @@ -60,6 +62,8 @@ tests_aarch64_system_thorough =3D [ '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/functiona= l/test_aarch64_rme_sbsaref.py new file mode 100755 index 0000000000..93bb528338 --- /dev/null +++ b/tests/functional/test_aarch64_rme_sbsaref.py @@ -0,0 +1,69 @@ +#!/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 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 =3D 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 supporti= ng it, + # and launching a nested VM using it. + def test_aarch64_rme_sbsaref(self): + self.set_machine('sbsa-ref') + self.require_accelerator('tcg') + + self.vm.set_console() + + stack_path_tar_gz =3D self.ASSET_RME_STACK_SBSA.fetch() + self.archive_extract(stack_path_tar_gz, format=3D"tar") + + rme_stack =3D self.scratch_file('rme-stack-op-tee-4.2.0-cca-v4-sbs= a') + pflash0 =3D os.path.join(rme_stack, 'images', 'SBSA_FLASH0.fd') + pflash1 =3D os.path.join(rme_stack, 'images', 'SBSA_FLASH1.fd') + virtual =3D os.path.join(rme_stack, 'images', 'disks', 'virtual') + drive =3D os.path.join(rme_stack, 'out-br', 'images', 'rootfs.ext4= ') + + self.vm.add_args('-cpu', 'max,x-rme=3Don,pauth-impdef=3Don') + self.vm.add_args('-m', '2G') + self.vm.add_args('-M', 'sbsa-ref') + self.vm.add_args('-drive', f'file=3D{pflash0},format=3Draw,if=3Dpf= lash') + self.vm.add_args('-drive', f'file=3D{pflash1},format=3Draw,if=3Dpf= lash') + self.vm.add_args('-drive', f'file=3Dfat:rw:{virtual},format=3Draw') + self.vm.add_args('-drive', f'format=3Draw,if=3Dnone,file=3D{drive}= ,id=3Dhd0') + self.vm.add_args('-device', 'virtio-blk-pci,drive=3Dhd0') + self.vm.add_args('-device', 'virtio-9p-pci,fsdev=3Dshr0,mount_tag= =3Dshr0') + self.vm.add_args('-fsdev', f'local,security_model=3Dnone,path=3D{r= me_stack},id=3Dshr0') + self.vm.add_args('-device', 'virtio-net-pci,netdev=3Dnet0') + self.vm.add_args('-netdev', 'user,id=3Dnet0') + + 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__ =3D=3D '__main__': + QemuSystemTest.main() diff --git a/tests/functional/test_aarch64_rme_virt.py b/tests/functional/t= est_aarch64_rme_virt.py new file mode 100755 index 0000000000..42b9229b4c --- /dev/null +++ b/tests/functional/test_aarch64_rme_virt.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python3 +# +# Functional test that boots a Realms environment on virt machine and a ne= sted +# 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 + +def test_realms_guest(test_rme_instance): + + # Boot the (nested) guest VM + exec_command(test_rme_instance, + 'qemu-system-aarch64 -M virt,gic-version=3D3 ' + '-cpu host -enable-kvm -m 512M ' + '-M confidential-guest-support=3Drme0 ' + '-object rme-guest,id=3Drme0 ' + '-device virtio-net-pci,netdev=3Dnet0,romfile=3D ' + '-netdev user,id=3Dnet0 ' + '-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-25= 6"') + +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 =3D 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 supporti= ng it, + # and launching a nested VM using it. + def test_aarch64_rme_virt(self): + self.set_machine('virt') + self.vm.set_console() + self.require_accelerator('tcg') + + stack_path_tar_gz =3D self.ASSET_RME_STACK_VIRT.fetch() + self.archive_extract(stack_path_tar_gz, format=3D"tar") + + rme_stack =3D self.scratch_file('rme-stack-op-tee-4.2.0-cca-v4-qem= u_v8') + kernel =3D os.path.join(rme_stack, 'out', 'bin', 'Image') + bios =3D os.path.join(rme_stack, 'out', 'bin', 'flash.bin') + drive =3D os.path.join(rme_stack, 'out-br', 'images', 'rootfs.ext4= ') + + self.vm.add_args('-cpu', 'max,x-rme=3Don,pauth-impdef=3Don') + self.vm.add_args('-m', '2G') + self.vm.add_args('-M', 'virt,acpi=3Doff,' + 'virtualization=3Don,' + 'secure=3Don,' + 'gic-version=3D3') + self.vm.add_args('-bios', bios) + self.vm.add_args('-kernel', kernel) + self.vm.add_args('-drive', f'format=3Draw,if=3Dnone,file=3D{drive}= ,id=3Dhd0') + self.vm.add_args('-device', 'virtio-blk-pci,drive=3Dhd0') + self.vm.add_args('-device', 'virtio-9p-device,fsdev=3Dshr0,mount_t= ag=3Dshr0') + self.vm.add_args('-fsdev', f'local,security_model=3Dnone,path=3D{r= me_stack},id=3Dshr0') + self.vm.add_args('-device', 'virtio-net-pci,netdev=3Dnet0') + self.vm.add_args('-netdev', 'user,id=3Dnet0') + self.vm.add_args('-append', 'root=3D/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__ =3D=3D '__main__': + QemuSystemTest.main() --=20 2.39.5