From patchwork Mon Apr 28 12:59:12 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: 885471 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp5163727wrs; Mon, 28 Apr 2025 06:00:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV1spMg68AHPu9KL6F6EIRKhGM05l9wCjYZQg6Bw1q0GMhBsdSRap4lOqp0CYFEqva4J10LOQ==@linaro.org X-Google-Smtp-Source: AGHT+IHLVQN5Uq+/GOIuTL4ErCtsDwxS6Ji6JSOIbjYNaqynsXeI4eY/86m6iX0Mspx7Nt9JZhGv X-Received: by 2002:a05:6214:d8e:b0:6e1:a4ed:4b0c with SMTP id 6a1803df08f44-6f4cbcd4276mr194750166d6.26.1745845201949; Mon, 28 Apr 2025 06:00:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1745845201; cv=none; d=google.com; s=arc-20240605; b=Z1dujKtfkti5+YMKeMrvtyEm1FpaN78zndnsDIJJOW1ergrb1OGAba6bawNEEWA4rv +fxN0DrPMk0rAsQ0yqFJHx/RutrqkbQEaBoWvam9cECnjhGGBo/RdvORRGQUxwhQ3OrR sbZcUiZj9iFNvLHe5K2GJFjR5Bu4UffOkhwxZ0ZrPZ7yG5GCAN0/+27avBQkoJ9x0L8e yPIRUnaIQldUfNhq01quzp3uycxKIViYnw9YJ/r2/ZGOAWJ6XaUiNzWa7V/BVln9xFvt LXiIhUtYk1gx9EPdRPeWzlpupPfxT/ZeIjgpaU+epYHjKm19H/NfDKyvZswL94AWg4gU ekVg== 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=Qc7SHqkPGeFwD7OQUk3puk/Z8FG2BzOSogWjxrnjPA8=; fh=WQdx5IuKOW47fPFin68RJHgHrvEuRrLEbIlw7SaShRo=; b=RUJawBHNzgJG7UEg4Q85mrJvabc+f9zW+9x8YbikR7yRRhVvXPGqZC5VCXNZu1fYaa 1+45a72nvU49ccB6TZC1X3KjH3o8CcCenYpoNqeMHCMKRDz4wcVmkn8VGYU8FrAgFlR9 OtXGUt2KMd7tkVqhs9u5c37k6K99esqM/WlwL+5uHD6TDmE7o3L50eSFu2VDt7ia5PJF BDhapLUt0JxHfGlsFsonZX/qqtz+V6dEMNl86QvMRzxYO6JuHyAXt4V3aRRAya7R9TXW PM5r1cxN9UIMpje9R0/u7XsbzmIzfsFV+EhWAj1uHbRHCqLfjsLo9cMhy+8n1h8cksGv puyg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d+g609W2; 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-6f4c76423fasi86410726d6.169.2025.04.28.06.00.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Apr 2025 06:00:01 -0700 (PDT) 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=d+g609W2; 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 1u9O5O-0008DP-I7; Mon, 28 Apr 2025 08:59:50 -0400 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 1u9O52-0007tf-C9 for qemu-devel@nongnu.org; Mon, 28 Apr 2025 08:59:30 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u9O4x-00036m-Rn for qemu-devel@nongnu.org; Mon, 28 Apr 2025 08:59:27 -0400 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-5e5deb6482cso10136939a12.1 for ; Mon, 28 Apr 2025 05:59:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745845162; x=1746449962; 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=Qc7SHqkPGeFwD7OQUk3puk/Z8FG2BzOSogWjxrnjPA8=; b=d+g609W23dZf8fHRhusj8Fq3akM6BdgiY+PQ9nONOXDBWULwvLDmZpFAXx8tHD50yB LoeGkH7Vcxd9Fn8IQMm0ZtwcaWOsmBkIwz6ar4G++lmEwT7HCbF6Yl9PlR2fqavD9VwF KIAWRVYi5jQaqVs+V5ndIcd4sMsXfQGb9pLYw8sYc4wwu4Ja8LJYqK4MnmRLJ+Fla+sU M/+JQGuXB0HazwsmVeRmz88hkk3y9XxmR51ylPEovGHtkyl3JhPitV+J+O6Rer/zAHbs Kf2IJJ+tTBAmuuFVVZfjv3tJ0PF/uwzsX0sF/+JY4gklFLm3zbxmJ2hE1eYsO2Xv4rlQ WmNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745845162; x=1746449962; 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=Qc7SHqkPGeFwD7OQUk3puk/Z8FG2BzOSogWjxrnjPA8=; b=lwqCdmHBclPxxwH+5Tjl+5LJ84F7/5wIQXvEi2koxUAMBFIf1wC/NgparJYO3oGPN8 lTt5qQaGb3SntnUNQsGFRtNsk1Bb6gkV2/bkapfQlkXaCZfFTTjwZbJblLC4dT5vjZob CKf8K4Gc1kVQNGT2ES0XyPSIV/9XIP0PeiHeJLvUP7LMPiZX6qgYDJit/L9DDEpw0auG 4G6uUVQQ5BD/J0eUxuuqJx8bmbNY3y/Nm8wMZfy4tK1XXvxsW2+JbCs4WGaX/Dldbj+m uENTSvPO9barH4o9CJdilvQiAG3m6tNuFd7O3M0qCRFsIQTeNZfEMSs1zKMUnPiUwxM4 QiUw== X-Gm-Message-State: AOJu0YzjZVYFuVR+g1vDM7GIMnrmlwkW0pIenR+Af95SHIWejDxD5hlG oBYQSxUdYTczrrNQZKyBudhibswE6WOt8NtVZy3UcL1KCg6hbq0RP21wBxbE2z4= X-Gm-Gg: ASbGnctHB6EjrBXgBdduEP60tgdTG2TwfKK1vofL0pO2EIOywsyXsO27vtjlcrbfRWo kj/4upQOHaAW37BwyNY6g6L10OzOmJ0VruMTz+Ht+EXn4+RfO8dNbHNzPyd0Rl9Ao0Oszb1Vv/f MKoYRPaPYM/H7oqV7MMKhTPNZySRqmtRJBvJZ9y9Fv6lr7Zrf4Rfh/RH0zOOFiZb0qKsTnVY2ga SmGlRJXLuo/6xVLhoZ7QuR2un/TK/drj8oDeVpx/vCUdZWiJ2HW8CQAk7ukF2mbzKn3pTT+z8i7 q8ei9YPtVJR97dtx/Ti8rgnoRbe00Zz9hrv9Qfz8JWQ= X-Received: by 2002:a17:907:3da0:b0:acb:a7cc:4102 with SMTP id a640c23a62f3a-ace5a124bfbmr1411844266b.4.1745845162079; Mon, 28 Apr 2025 05:59:22 -0700 (PDT) Received: from draig.lan ([185.126.160.109]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ace6e5959basm617760466b.82.2025.04.28.05.59.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Apr 2025 05:59:19 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 8662C5FAE8; Mon, 28 Apr 2025 13:59:18 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Thomas Huth , Alexandre Iooss , "Michael S. Tsirkin" , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , David Hildenbrand , Pierrick Bouvier , qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Xu , Peter Maydell , Mahmoud Mandour , Julian Armistead , Jim MacArthur Subject: [PATCH 3/9] tests/tcg: make aarch64 boot.S handle different starting modes Date: Mon, 28 Apr 2025 13:59:12 +0100 Message-Id: <20250428125918.449346-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250428125918.449346-1-alex.bennee@linaro.org> References: <20250428125918.449346-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=alex.bennee@linaro.org; helo=mail-ed1-x52c.google.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 Currently the boot.S code assumes everything starts at EL1. This will break things like the memory test which will barf on unaligned memory access when run at a higher level. Adapt the boot code to do some basic verification of the starting mode and the minimal configuration to move to the lower exception levels. With this we can run the memory test with: -M virt,secure=on -M virt,secure=on,virtualization=on -M virt,virtualisation=on If a test needs to be at a particular EL it can use the semihosting command line to indicate the level we should execute in. Cc: Julian Armistead Cc: Jim MacArthur Signed-off-by: Alex Bennée Reviewed-by: Manos Pitsidianakis --- v2 - allow tests to control the final EL we end up at --- tests/tcg/aarch64/Makefile.softmmu-target | 3 +- tests/tcg/aarch64/system/boot.S | 127 +++++++++++++++++++++- 2 files changed, 128 insertions(+), 2 deletions(-) diff --git a/tests/tcg/aarch64/Makefile.softmmu-target b/tests/tcg/aarch64/Makefile.softmmu-target index 9c52475b7a..f7a7d2b800 100644 --- a/tests/tcg/aarch64/Makefile.softmmu-target +++ b/tests/tcg/aarch64/Makefile.softmmu-target @@ -68,7 +68,8 @@ run-plugin-semiconsole-with-%: semiconsole # vtimer test needs EL2 QEMU_EL2_MACHINE=-machine virt,virtualization=on,gic-version=2 -cpu cortex-a57 -smp 4 -run-vtimer: QEMU_OPTS=$(QEMU_EL2_MACHINE) $(QEMU_BASE_ARGS) -kernel +QEMU_EL2_BASE_ARGS=-semihosting-config enable=on,target=native,chardev=output,arg="2" +run-vtimer: QEMU_OPTS=$(QEMU_EL2_MACHINE) $(QEMU_EL2_BASE_ARGS) -kernel # Simple Record/Replay Test .PHONY: memory-record diff --git a/tests/tcg/aarch64/system/boot.S b/tests/tcg/aarch64/system/boot.S index a5df9c173d..19b18bdeec 100644 --- a/tests/tcg/aarch64/system/boot.S +++ b/tests/tcg/aarch64/system/boot.S @@ -16,6 +16,7 @@ #define semihosting_call hlt 0xf000 #define SYS_WRITEC 0x03 /* character to debug channel */ #define SYS_WRITE0 0x04 /* string to debug channel */ +#define SYS_GET_CMDLINE 0x15 /* get command line */ #define SYS_EXIT 0x18 .align 12 @@ -81,10 +82,129 @@ lower_a32_serror: .error: .string "Terminated by exception.\n" + .align 8 +.get_cmd: + .quad cmdline + .quad 128 + .text .align 4 .global __start __start: + /* + * The test can set the semihosting command line to the target + * EL needed for the test. Keep that in w11. + */ + mov x0, SYS_GET_CMDLINE + adr x1, .get_cmd + semihosting_call + adrp x10, cmdline + add x10, x10, :lo12:cmdline + ldrb w11, [x10] + cbz w11, 1f + sub w11, w11, #'0' +1: + + /* Determine current Exception Level */ + mrs x0, CurrentEL + lsr x0, x0, #2 /* CurrentEL[3:2] contains the current EL */ + + /* Branch based on current EL */ + cmp x0, #3 + b.eq setup_el3 + cmp x0, #2 + b.eq setup_el2 + cmp x0, #1 + b.eq at_testel /* Already at EL1, skip transition */ + /* Should not be at EL0 - error out */ + b curr_sp0_sync + +setup_el3: + /* Ensure we trap if we get anything wrong */ + adr x0, vector_table + msr vbar_el3, x0 + + /* Does the test want to be at EL3? */ + cmp w11, #3 + beq at_testel + + /* Configure EL3 to for lower states (EL2 or EL1) */ + mrs x0, scr_el3 + orr x0, x0, #(1 << 10) /* RW = 1: EL2/EL1 execution state is AArch64 */ + orr x0, x0, #(1 << 0) /* NS = 1: Non-secure state */ + msr scr_el3, x0 + + /* + * We need to check if EL2 is actually enabled via ID_AA64PFR0_EL1, + * otherwise we should just jump straight to EL1. + */ + mrs x0, id_aa64pfr0_el1 + ubfx x0, x0, #8, #4 /* Extract EL2 field (bits 11:8) */ + cbz x0, el2_not_present /* If field is 0 no EL2 */ + + + /* Prepare SPSR for exception return to EL2 */ + mov x0, #0x3c9 /* DAIF bits and EL2h mode (9) */ + msr spsr_el3, x0 + + /* Set EL2 entry point */ + adr x0, setup_el2 + msr elr_el3, x0 + + /* Return to EL2 */ + eret + nop + +el2_not_present: + /* Initialize SCTLR_EL1 with reset value */ + msr sctlr_el1, xzr + + /* Set EL1 entry point */ + adr x0, at_testel + msr elr_el3, x0 + + /* Prepare SPSR for exception return to EL1h with interrupts masked */ + mov x0, #0x3c5 /* DAIF bits and EL1h mode (5) */ + msr spsr_el3, x0 + + isb /* Synchronization barrier */ + eret /* Jump to EL1 */ + +setup_el2: + /* Ensure we trap if we get anything wrong */ + adr x0, vector_table + msr vbar_el2, x0 + + /* Does the test want to be at EL2? */ + cmp w11, #2 + beq at_testel + + /* Configure EL2 to allow transition to EL1 */ + mrs x0, hcr_el2 + orr x0, x0, #(1 << 31) /* RW = 1: EL1 execution state is AArch64 */ + msr hcr_el2, x0 + + /* Initialize SCTLR_EL1 with reset value */ + msr sctlr_el1, xzr + + /* Set EL1 entry point */ + adr x0, at_testel + msr elr_el2, x0 + + /* Prepare SPSR for exception return to EL1 */ + mov x0, #(0x5 << 0) /* EL1h (SPx), with interrupts disabled */ + msr spsr_el2, x0 + + /* Return to EL1 */ + eret + + nop + + /* + * At the target EL for the test, usually EL1. Note we still + * set everything up as if we were at EL1. + */ +at_testel: /* Installs a table of exception vectors to catch and handle all exceptions by terminating the process with a diagnostic. */ adr x0, vector_table @@ -100,7 +220,7 @@ __start: * maps RAM to the first Gb. The stage2 tables have two 2mb * translation block entries covering a series of adjacent * 4k pages. - */ + */ /* Stage 1 entry: indexed by IA[38:30] */ adr x1, . /* phys address */ @@ -233,6 +353,11 @@ __sys_outc: ret .data + + .align 8 +cmdline: + .space 128, 0 + .align 12 /* Translation table