From patchwork Thu Feb 20 14:13:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 13984037 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 568191FC7C1 for ; Thu, 20 Feb 2025 14:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740060859; cv=none; b=CjXzr0YUFvMGRz9qufTrQkUWR0azic0spB6X5ge+jOd+WYo2ANOsQZExlsDA8jf7dDMDMpMZOjIfBCjf9W3x+xKGsScpmHONpzNvr6/+7RYc8Fm6xa+69RfaAMTDjabBsbh/7tN2yU2UC7SERwwvGLudXwS5/Tj28Jb8oA8u1+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740060859; c=relaxed/simple; bh=K6qrRVVzSh9sptw9wrOzAWWshx8blOFuK2k21pxl4MQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UmOYRkupo9snpj4j2wV0S10Q1Ag/PJEjiHsSuaaLfi2zEkWc/1PpRXzqiE4MbKAJri44hZjCRnCYU8UHBBEv6SR42NEmkqmwtT8o+1s+36T8r78ixqSQbqvZ0TdcbYCxRxO1wKd/TiBfOiSmKpWM3B343U1Reg4bf8OoYovLcFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D2E4E2BC0; Thu, 20 Feb 2025 06:14:35 -0800 (PST) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6AAE53F59E; Thu, 20 Feb 2025 06:14:16 -0800 (PST) From: Joey Gouly To: kvm@vger.kernel.org Cc: alexandru.elisei@arm.com, joey.gouly@arm.com, drjones@redhat.com, kvmarm@lists.linux.dev, Marc Zyngier , Oliver Upton Subject: [kvm-unit-tests PATCH v1 5/7] arm64: selftest: update test for running at EL2 Date: Thu, 20 Feb 2025 14:13:52 +0000 Message-Id: <20250220141354.2565567-6-joey.gouly@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250220141354.2565567-1-joey.gouly@arm.com> References: <20250220141354.2565567-1-joey.gouly@arm.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove some hard-coded assumptions that this test is running at EL1. Signed-off-by: Alexandru Elisei Signed-off-by: Joey Gouly --- arm/selftest.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/arm/selftest.c b/arm/selftest.c index 1553ed8e..eccdc3d4 100644 --- a/arm/selftest.c +++ b/arm/selftest.c @@ -232,6 +232,7 @@ static void user_psci_system_off(struct pt_regs *regs) __user_psci_system_off(); } #elif defined(__aarch64__) +static unsigned long expected_level; /* * Capture the current register state and execute an instruction @@ -276,8 +277,7 @@ static bool check_regs(struct pt_regs *regs) { unsigned i; - /* exception handlers should always run in EL1 */ - if (current_level() != CurrentEL_EL1) + if (current_level() != expected_level) return false; for (i = 0; i < ARRAY_SIZE(regs->regs); ++i) { @@ -301,7 +301,11 @@ static enum vector check_vector_prep(void) return EL0_SYNC_64; asm volatile("mrs %0, daif" : "=r" (daif) ::); - expected_regs.pstate = daif | PSR_MODE_EL1h; + expected_regs.pstate = daif; + if (current_level() == CurrentEL_EL1) + expected_regs.pstate |= PSR_MODE_EL1h; + else + expected_regs.pstate |= PSR_MODE_EL2h; return EL1H_SYNC; } @@ -317,8 +321,8 @@ static bool check_und(void) install_exception_handler(v, ESR_EL1_EC_UNKNOWN, unknown_handler); - /* try to read an el2 sysreg from el0/1 */ - test_exception("", "mrs x0, sctlr_el2", "", "x0"); + /* try to read an el3 sysreg from el0/1/2 */ + test_exception("", "mrs x0, sctlr_el3", "", "x0"); install_exception_handler(v, ESR_EL1_EC_UNKNOWN, NULL); @@ -429,6 +433,10 @@ int main(int argc, char **argv) if (argc < 2) report_abort("no test specified"); +#if defined(__aarch64__) + expected_level = current_level(); +#endif + report_prefix_push(argv[1]); if (strcmp(argv[1], "setup") == 0) {