From patchwork Wed Dec 18 16:20:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 851718 Delivered-To: patch@linaro.org Received: by 2002:a5d:4888:0:b0:385:e875:8a9e with SMTP id g8csp1014293wrq; Wed, 18 Dec 2024 08:22:45 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVFyINmbaEbx/YwL3lXiAGQwFUI1zZD1leQzkOkHSPtcAYkDK9OuI4NmLXVNuzJYS2U4/h3Vw==@linaro.org X-Google-Smtp-Source: AGHT+IG09ACDxRAuhHSEv8Waq+kT0Yx2PfQREEqx+t1GJaH2hMJGudQL+JLT1TKZkVA2MGD8F+df X-Received: by 2002:a05:6122:2513:b0:516:157c:a72e with SMTP id 71dfb90a1353d-51b6473231bmr23316e0c.3.1734538965148; Wed, 18 Dec 2024 08:22:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1734538965; cv=none; d=google.com; s=arc-20240605; b=ZOb1PXUQ/2Oq90nErrAaRcOX2SeNoS8Ghf8ghlnp/F1ZnA3F/atn+UuBPvL+6DFme2 El72qzzn+NFIVvJDdAFCD1iCwY5qqd0mG5DcCDr55SUalQ+73FbptWo21SJq/EBoG6cC XpsZqHFefGxGFzM5CKsU1bK9pxoqeub/30i+CZ7w0QGFAUGyLoQfmuMBCNdLag4BRP+5 ilAthQLK72VXWpxPyJcYPi7SehIzPdbhFEN3nI/VDniMcx2UuLqC2UqLR7H2HmKP14LA Tu6Bv3to+nHLsioovE+ttI7ESp+HDpGnO5e/smgoM4q+4UT4NNoS0WHFNG6w7CMq557f Iyuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DujG+efmgmUcw3r1Pu7h+rX1aDG55V3IqYFhV9c3f8g=; fh=DXwP5MNoaO49OyrZ8Tn10KeZlZmx6EvhteiJuCMvbMw=; b=HPqniWSCsRWoCX4o3y7ih+CvJ88vQ21E6gr/n5NI9u3qKjl+ZcYRu2/M4be8r/MXmO eMX5WlOBiHShdLnSd4R4nsqKoyywK/soYJWjZ5XLfnjVpdCPygaldMkb93gJms/5wxbH WWxLVTuF5TUtlrb7C3LGXV3NDj0kJ7VsxHmg3VhqDhMJTL1z+hg6CjT1Zpe2u81IShFb UyXuM/by0BISJ01avp4HlmjkesP4x7XrD5fXRL5Ez9JLdfj/+LvZegr+4JqNG6rtTZu4 U63hV9kS7zEbMhzzDnu8foqYKa+NbrQgUDftW6yF0+/6rs8hhM1zsaYa/qIZB0Ax0JhJ +Tmg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Dv3Sp/UW"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 71dfb90a1353d-519eb790bfesi3584664e0c.199.2024.12.18.08.22.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Dec 2024 08:22:45 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Dv3Sp/UW"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNwoS-0008TO-NN; Wed, 18 Dec 2024 11:22:16 -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 1tNwnl-0007XV-72 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 11:21:35 -0500 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tNwnS-0006o2-82 for qemu-devel@nongnu.org; Wed, 18 Dec 2024 11:21:29 -0500 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5d3e9a88793so11077456a12.1 for ; Wed, 18 Dec 2024 08:21:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1734538873; x=1735143673; 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=DujG+efmgmUcw3r1Pu7h+rX1aDG55V3IqYFhV9c3f8g=; b=Dv3Sp/UWxPNYOPbOAU365zZS4afdGT8khNDFZ0+akGUz4JS7AX4NwMItdLh30EGvR3 GZT6gp/YSc3PL8tPrlCc00xiKVu/hqH3MyX1qVxrLmtgQRKJ0x47vd5A7ZXFha0CHEzW kkUyd5yRm497t3fyNcvrf4KmNvMJq736OZXVCh0owonuOEA8u/VUhl9BOXWpQrxVtDfO LmtW4xQO46vu1RDUpWKDAPgW81Ioi5EluzQw6rJhZ5WTvjUXF+JIlZzfl0ZEm2fbWIZt naN8VuW3KWWMMzoIIG2fDoA5ttNXWruAcWrkJ6GB17RTTmlNTSggv4Qr/MKwBhbDZS9A 08XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734538873; x=1735143673; 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=DujG+efmgmUcw3r1Pu7h+rX1aDG55V3IqYFhV9c3f8g=; b=UepvANt31Uh2/mAVTwxVUNBGEsemseY9VRcS9p5g70mRqlLbB4USGwn1DSvRaKP8/X lsKegukE8gpcbRpmXubDT5Lqebu7QsOlYEGrkidhvqp080FJXQiwktY+npO2CR19jcEN O6G+hZmW0uSdbp52hV4QO05TLZ3MnbchoReEbU+DQVQks5lkntbIHHtkeu/C83D5W/ZO iDrnlWqMV5Gt4bNeU9qOhfaq1vnO2VYA35y03M59k47wYDZMkRW0VcVDHgAkEf9EXDHg zQeiTraDkXW7fW0OqXaZP19+j4CQy30pOp6jAirexu3UZlBx2ZdiVBFTD4eh25xUm4kb vJ9Q== X-Gm-Message-State: AOJu0YwzF6eu6WjSEYMs3/VTFMzzWs96BxPzITzzk4vW6HOdKe9tvwHK 5pXC2+DLr33ScmFewq4Ig7dppJbPWv6mlrbnPPOAxhboVRui6ONgxB/jzdDdJYw= X-Gm-Gg: ASbGncuJWXtqybqgQHvG9iQrBHY0Y8NG7fMlptnO2SULZSGSoU19lJCY6h6QA+NUrqO sITS1Eesih4COc0TGmRlZj/Hxy5xxAX1woY6Tk/d/QVpC8ZfYJlq/jnVjr9cp/kaAGi2EEKf5Bt lNfj2HRO8EyI7xneV/c80LJ7mIvtrpKnRF0sJ9P2Pl/e8E63qGMUE+hs2pQNgY6cxMiXspSTFOy Y9tD6ua4K0THMyXIwKbxseESeDQ5P8FF/mFDZJq99c7HT/A9M7T2aw= X-Received: by 2002:a05:6402:5418:b0:5d3:c4a8:d259 with SMTP id 4fb4d7f45d1cf-5d7ee3cc788mr3062592a12.19.1734538872623; Wed, 18 Dec 2024 08:21:12 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5d652ad1717sm5589170a12.21.2024.12.18.08.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Dec 2024 08:21:11 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 91EDD6003A; Wed, 18 Dec 2024 16:21:05 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Ed Maste , Eric Farman , Thomas Huth , Li-Wen Hsu , Daniel Henrique Barboza , Aurelien Jarno , Fabiano Rosas , Radoslaw Biernacki , Mark Cave-Ayland , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Philippe_Mathi?= =?utf-8?q?eu-Daud=C3=A9?= , qemu-riscv@nongnu.org, Nicholas Piggin , Joel Stanley , Beraldo Leal , Markus Armbruster , Jiaxun Yang , Weiwei Li , Peter Maydell , Cleber Rosa , Leif Lindholm , Christian Borntraeger , John Snow , Marcel Apfelbaum , Palmer Dabbelt , Bin Meng , Daniel Henrique Barboza , Paolo Bonzini , Liu Zhiwei , Wainer dos Santos Moschetta , Laurent Vivier , Pavel Dovgalyuk , Richard Henderson , Marcin Juszkiewicz , Halil Pasic , qemu-arm@nongnu.org, Harsh Prateek Bora , qemu-ppc@nongnu.org, Bernhard Beschow , "Michael S. Tsirkin" , qemu-s390x@nongnu.org, Laurent Vivier , Alistair Francis , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier Subject: [PATCH v2 15/27] tests/functional/aarch64: add tests for FEAT_RME Date: Wed, 18 Dec 2024 16:20:51 +0000 Message-Id: <20241218162104.3493551-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241218162104.3493551-1-alex.bennee@linaro.org> References: <20241218162104.3493551-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::531; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x531.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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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: <20241203213629.2482806-1-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- v2 - remove version log from main commit --- 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 0e1bfb8c44..b49c486115 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' : 1200, + 'aarch64_rme_sbsaref' : 1200, 'aarch64_sbsaref_alpine' : 720, 'aarch64_sbsaref_freebsd' : 720, 'aarch64_tuxrun' : 240, @@ -58,6 +60,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 0000000000..c136b5ce17 --- /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,pauth-impdef=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 0000000000..39e4e4adb5 --- /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,pauth-impdef=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()