[kvm-unit-tests PATCH v6 09/14] arm64: selftest: update test for running at EL2
Joey Gouly
joey.gouly at arm.com
Fri Jan 23 08:50:48 PST 2026
From: Alexandru Elisei <alexandru.elisei at arm.com>
Remove some hard-coded assumptions that this test is running at EL1.
Signed-off-by: Alexandru Elisei <alexandru.elisei at arm.com>
Signed-off-by: Joey Gouly <joey.gouly at arm.com>
Acked-by: Marc Zyngier <maz at kernel.org>
Reviewed-by: Eric Auger <eric.auger at redhat.com>
---
arm/selftest.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/arm/selftest.c b/arm/selftest.c
index 1553ed8e..33f4cf42 100644
--- a/arm/selftest.c
+++ b/arm/selftest.c
@@ -106,6 +106,8 @@ static bool und_works;
static bool svc_works;
static bool pabt_works;
#if defined(__arm__)
+static void test_exception_prep(void) { }
+
/*
* Capture the current register state and execute an instruction
* that causes an exception. The test handler will check that its
@@ -232,6 +234,12 @@ static void user_psci_system_off(struct pt_regs *regs)
__user_psci_system_off();
}
#elif defined(__aarch64__)
+static unsigned long expected_level;
+
+static void test_exception_prep(void)
+{
+ expected_level = current_level();
+}
/*
* Capture the current register state and execute an instruction
@@ -276,8 +284,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 +308,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 +328,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);
@@ -426,6 +437,8 @@ int main(int argc, char **argv)
{
report_prefix_push("selftest");
+ test_exception_prep();
+
if (argc < 2)
report_abort("no test specified");
--
2.25.1
More information about the linux-arm-kernel
mailing list