From patchwork Fri Jan 10 13:17:37 2025 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: 856240 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:385:e875:8a9e with SMTP id k28csp222167wrc; Fri, 10 Jan 2025 05:22:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUyBSlVL1uEf1a+xqiLxLAPOICipNeclpYd0treCDFyXHuEaO/SeEaQxO7K0HEo9KTMEehdJg==@linaro.org X-Google-Smtp-Source: AGHT+IF/dSejrstX/tXMpQ/kt56PJr0Yihv325QbIooRyXbEQ4XLy+B6n/87bJZ4dyjCHM0J6Udz X-Received: by 2002:a05:6214:4890:b0:6d8:9f61:de6c with SMTP id 6a1803df08f44-6dfa3b00d2dmr102123506d6.18.1736515371796; Fri, 10 Jan 2025 05:22:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1736515371; cv=none; d=google.com; s=arc-20240605; b=OMKTDCZiG1Z02yTzKPgbwl6VEDB+nftXoEb8aZMlPyvMMPzieQyr/NxrIulDdB4FuG TZO8uLAXqmZTC1SGhHj0jlTMbXwegS1t8geGw4JbnHzm81jiRF+vpfTS+soFZM4xWZDo p4NlM+Pr5K7QdSy+zrfcKQos5rATw+QWrlbkaYdeV+gVVnGPXI5uUOX6nitGA5wBG1Kz 2NqqgsaAp3S2O4cYTHaIIbHqQoisg4zhFNVeG6dOtNU8JfRj5lwgYxLpv/K6XW/GziS6 e3QYEkfgJX8ohWK7K5kuxKACzvFtP6vL1G7fuO1aWjrs7dTJcDItuCNdAu3vo5Qsp6gh 9H/A== 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=h1+ncT0+NjyTIfU+zWqG1C1hi8VpphN9eqNJ4f1EMF4=; fh=uefP4hz+I/MFESHcQVo/G6nmPa6DsEeXx6z++BiOCEs=; b=NjTkUNtUJnJFVztlDpd9ETI++hzPZkOX/JCfzX9rlaOp7wBU8eYGx5zg4cOEpMv0Xu rSeKTqPWCzn1LsF+0DoO/IdmGUqLLjPOOp7377BK3HeF1nKuKgSg5Ekn9Q4h/TRWXW0V 1l+EfH6woXGzPQIWx6YYeiDlJkdmTja/Tymc+p83pxTgJHgzJMuVGjaOUah9epUSnEOs uaA4mxoT3MGPaFD8b2pT3zDPtW4LXCcP/S2DBDaHqmUfV36SFKyM8lrLu71rDNhUOGi6 ARN12z8of6R+90AKM3pHeWOtXUW453mCNXM+LNFAN5JSzKWHfE1FEfPPROz+vin7ZlFf KaiA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q3HdVd2w; 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 6a1803df08f44-6dfaded2f3asi20926696d6.285.2025.01.10.05.22.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Jan 2025 05:22:51 -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=Q3HdVd2w; 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 1tWEu2-0004mJ-6V; Fri, 10 Jan 2025 08:18:18 -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 1tWEtr-0004er-Dx for qemu-devel@nongnu.org; Fri, 10 Jan 2025 08:18:07 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tWEtp-0004jx-8G for qemu-devel@nongnu.org; Fri, 10 Jan 2025 08:18:07 -0500 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-436249df846so15245885e9.3 for ; Fri, 10 Jan 2025 05:18:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736515084; x=1737119884; 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=h1+ncT0+NjyTIfU+zWqG1C1hi8VpphN9eqNJ4f1EMF4=; b=Q3HdVd2w/1aptraEJMsKPygPlp+6beJIbht9Vwb+DAg0SnH1GWA78qZr5wf9xxPds/ F3u8I5lS0w/TrDMyvL3RLYCD7IWZnTcncAxQ+7Yd21xi9shlSbRODcjX0daV9dZ6WH8y cJoLX7n9f3tX+Bs/JNSsnZElqqjkCBw2PmkmW0S4W+SdeIQMfdMtk25otDnX5MVL9+Vv kFQo0HyWQDivsy9VfOSieFuBsHdcODlduz34okS/Bv4OV128Po4HCrjQmtApU5OEiIi0 whvzAHsR4fCHMyAtc90tkrZHvJGull4lq7ytJ2vKk0ac+7LT5tlIAiiyJlUfvcI3v7xi S+8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736515084; x=1737119884; 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=h1+ncT0+NjyTIfU+zWqG1C1hi8VpphN9eqNJ4f1EMF4=; b=w7fUDWhB42cPnGuijHbbgFjeBkz7SM8QXL9XIi7fY8uCfB/dQ9daWVml61AcXC1igs 9TQ6lFTRy4x9uWn49AY0qfGId7jYCcSGitDJQ/7R7wCpPL7qaVGGIT5lIE81elKeqhAF I/bLRkOoAIrv5GdCnueDPg1TfzdOODAW8Lb3pNP16AZBEKzcW+98/vlc/Fwm4HnDSER5 OZN+XJ6jgk2v9eyTwnyvu3B6tABvudALPxaXVo3lp34pWnt5Kt9WVf4yVqJNBYirOpVn ptOMlGu76htdgf+lVejFGqvfi6thxtNvDiScoj55GsbmFv9OsCX9tCmad+jNcu80XOPW Qz/g== X-Gm-Message-State: AOJu0YyT0myLslaAUBu2Pp3kNAbEZtcQ8hEeWnHAzDXp+ghkpRpo9xrQ fEM7OT8TUigc+kWjpVrydGWLkQ058/p2/1wOff+vwb4Lwfk6PtBxbMkEmLZHaZA= X-Gm-Gg: ASbGncv863tWWwdruvW84ftX7XgT3/dZRRMgqZCEfGnCFsJK3EdCRogxhydakU6m+OX A/jua7cYqoYXk1vYjEj0mIypPg0XNHVHdlqTWd0vlzvX/LV1CKq/v5Vx1BJD30Zb+K8VdiXcFeU 0dH742KK1JzH9Mh/DjaYLPnWoRUH2kGg527gaAgMunf3/2KXfY0ftpX49YX8u+PrdwN+c3rMMja Ep9YurlqbsFqK/tZHjZ2I49Ql4WNIZ2WAitauO8h5UW6HMdweWSSD0= X-Received: by 2002:a05:600c:5115:b0:434:feb1:adae with SMTP id 5b1f17b1804b1-436e266e823mr94073365e9.3.1736515083724; Fri, 10 Jan 2025 05:18:03 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436e9e03f54sm52171175e9.21.2025.01.10.05.17.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 05:18:02 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 7A424606A6; Fri, 10 Jan 2025 13:17:55 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Thomas Huth Subject: [PULL 15/32] tests/functional/aarch64: add tests for FEAT_RME Date: Fri, 10 Jan 2025 13:17:37 +0000 Message-Id: <20250110131754.2769814-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250110131754.2769814-1-alex.bennee@linaro.org> References: <20250110131754.2769814-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x331.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=ham 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: <20241220165212.3653495-1-pierrick.bouvier@linaro.org> [AJB: tweak ordering of setup, strip changelog from commit] Signed-off-by: Alex Bennée Tested-by: Thomas Huth Message-Id: <20250108121054.1126164-16-alex.bennee@linaro.org> 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 = { '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 = [ '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..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 = 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): + self.set_machine('sbsa-ref') + self.require_accelerator('tcg') + + self.vm.set_console() + + stack_path_tar_gz = self.ASSET_RME_STACK_SBSA.fetch() + self.archive_extract(stack_path_tar_gz, format="tar") + + rme_stack = self.scratch_file('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..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 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 + +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): + self.set_machine('virt') + self.vm.set_console() + self.require_accelerator('tcg') + + stack_path_tar_gz = self.ASSET_RME_STACK_VIRT.fetch() + self.archive_extract(stack_path_tar_gz, format="tar") + + rme_stack = self.scratch_file('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()