From: Mark Brown <broonie@kernel.org>
To: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Marc Zyngier <maz@kernel.org>,
Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Shuah Khan <shuah@kernel.org>, Oliver Upton <oupton@kernel.org>,
Fuad Tabba <fuad.tabba@linux.dev>
Cc: Peter Maydell <peter.maydell@linaro.org>,
Leonardo Bras <leo.bras@arm.com>,
Wei-Lin Chang <weilin.chang@arm.com>,
Yao Yuan <yaoyuan@linux.alibaba.com>,
linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org,
kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, Mark Brown <broonie@kernel.org>
Subject: [PATCH v22 16/16] KVM: selftests: arm64: Add GCS EXLOCK exception emulation test
Date: Mon, 30 Nov 2026 16:35:57 +0000 [thread overview]
Message-ID: <20261130-arm64-gcs-v22-16-80454edf47ea@kernel.org> (raw)
In-Reply-To: <20261130-arm64-gcs-v22-0-80454edf47ea@kernel.org>
When running in vEL2 ERET is emulated, this means that we must emulate
the behaviour of GCSCR_EL2.EXLOCKEN. As per DDI0487 R_WTXBY
PSTATE.EXLOCK is set to the value of GCSCR_ELx.EXLOCKEN when taking an
exception to the same exception level. As per DDI0487 R_TYTWB if on
exception return to the same EL, GCSCR_ELx.EXLOCKEN is 1 and
PSTATE.EXLOCK is not 1 then the exception return is illegal, and as per
the pseudocode for the registers writes to SPSR_ELx and ELR_ELx will
generate exceptions.
Add a test that validates that we set PSTATE.EXLOCK, checking that
behaviour is seen by vEL2 consistent with it being set.
We nest handling of two exceptions to allow us to both observe and
modify PSTATE.EXLOCK, checking that expected exceptions are generated
for ERET. In order to cover both hardware programming and emulation the
first exception is done with both UDF (for hardware) and HVC (for
emulation).
We also attempt to write to both SPSR_ELx and ELR_ELx, again using a UDF
or HVC handler to control PSTATE.EXLOCK. We do all this both with and
without having enabled EXLOCKEN, though only for code running at EL2 due
to framework limitations.
For completeness we also inject a range of exceptions with
GCSCR_ELx.EXLOCKEN set, ensuring that PSTATE.EXLOCK is set
appropriately.
Signed-off-by: Mark Brown <broonie@kernel.org>
---
tools/testing/selftests/kvm/Makefile.kvm | 1 +
tools/testing/selftests/kvm/arm64/gcs_exceptions.c | 500 +++++++++++++++++++++
2 files changed, 501 insertions(+)
diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
index 283c59d7649c..d6e7d049ff99 100644
--- a/tools/testing/selftests/kvm/Makefile.kvm
+++ b/tools/testing/selftests/kvm/Makefile.kvm
@@ -186,6 +186,7 @@ TEST_GEN_PROGS_arm64 += arm64/host_sve
TEST_GEN_PROGS_arm64 += arm64/hypercalls
TEST_GEN_PROGS_arm64 += arm64/nv_pre_fault_memory_test
TEST_GEN_PROGS_arm64 += arm64/external_aborts
+TEST_GEN_PROGS_arm64 += arm64/gcs_exceptions
TEST_GEN_PROGS_arm64 += arm64/mmio_sign_ext
TEST_GEN_PROGS_arm64 += arm64/page_fault_test
TEST_GEN_PROGS_arm64 += arm64/psci_test
diff --git a/tools/testing/selftests/kvm/arm64/gcs_exceptions.c b/tools/testing/selftests/kvm/arm64/gcs_exceptions.c
new file mode 100644
index 000000000000..bffd913e7530
--- /dev/null
+++ b/tools/testing/selftests/kvm/arm64/gcs_exceptions.c
@@ -0,0 +1,500 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Test KVM's handling of Guarded Control Stack exception state.
+ */
+
+#include "kvm_util.h"
+#include "processor.h"
+#include "test_util.h"
+#include "ucall.h"
+
+#include <asm/ptrace.h>
+#include <asm/sysreg.h>
+
+#define PSTATE_IL_BIT BIT(20)
+
+static void require_guest_gcs(struct kvm_vcpu *vcpu)
+{
+ u64 pfr1 = vcpu_get_reg(vcpu,
+ KVM_ARM64_SYS_REG(SYS_ID_AA64PFR1_EL1));
+
+ TEST_REQUIRE(SYS_FIELD_GET(ID_AA64PFR1_EL1, GCS, pfr1) >=
+ ID_AA64PFR1_EL1_GCS_IMP);
+}
+
+static bool expect_exlock;
+static unsigned int undef_count;
+static unsigned int hvc_count;
+static unsigned int illegal_count;
+static unsigned int gcs_count;
+static u64 handler_pstate;
+static u64 illegal_pstate;
+
+static u64 expected_illegal_pc;
+static enum udf_mode {
+ UDF_COLLECT, /* Initial UDF we collect PSTATE from */
+ UDF_VALIDATE, /* Secondary UDF that collects and validates */
+ UDF_REPAIR, /* UDF to clear EXLOCK */
+ UDF_ELR_EL1, /* Write to ELR_EL1 with EXLOCK */
+ UDF_ELR_EL2, /* Write to ELR_EL2 with EXLOCK */
+ UDF_SPSR_EL1, /* Write to SPSR_EL1 with EXLOCK */
+ UDF_SPSR_EL2, /* Write to SPSR_EL2 with EXLOCK */
+} udf_mode;
+
+/*
+ * A UDF at vEL2 is taken by the CPU without involving the host, the
+ * host only sees the ERET from the handler. A HVC traps to the host
+ * which then emulates taking the exception to vEL2, so it is KVM that
+ * has to set PSTATE.EXLOCK for the handler.
+ */
+static void take_exception(bool hvc)
+{
+ if (hvc)
+ asm volatile("hvc #0" ::: "memory");
+ else
+ asm volatile("udf #0" ::: "memory");
+}
+
+static void guest_exception_handler(struct ex_regs *regs)
+{
+ u64 esr = read_sysreg(esr_el2);
+ u64 val;
+
+ switch (ESR_ELx_EC(esr)) {
+ case ESR_ELx_EC_UNKNOWN:
+ undef_count++;
+
+ /* Just skip the instruction either way. */
+ GUEST_ASSERT_EQ(esr, ESR_ELx_IL);
+ regs->pc += 4;
+ break;
+
+ case ESR_ELx_EC_HVC64:
+ hvc_count++;
+
+ /* We return to the instruction after the HVC, don't skip. */
+ GUEST_ASSERT_EQ(esr, (ESR_ELx_EC_HVC64 << ESR_ELx_EC_SHIFT) |
+ ESR_ELx_IL);
+ break;
+
+ default:
+ GUEST_FAIL("Unexpected exception, ESR %#lx", esr);
+ }
+
+ switch (udf_mode) {
+ case UDF_COLLECT:
+ GUEST_ASSERT_EQ(read_sysreg_s(SYS_GCSCR_EL2) & GCSCR_ELx_EXLOCKEN,
+ expect_exlock ? GCSCR_ELx_EXLOCKEN : 0);
+
+ /*
+ * If we want the nested exception handler to change
+ * PSTATE it can't have EXLOCK set.
+ */
+ write_sysreg_s(0, SYS_GCSCR_EL2);
+ isb();
+
+ /*
+ * Take another exception without returning so we can
+ * collect the EXLOCK state we're seeing here and make
+ * our return illegal.
+ */
+ expected_illegal_pc = regs->pc;
+ udf_mode = UDF_VALIDATE;
+ asm volatile("udf #0" ::: "memory");
+
+ /* Reenable so PSTATE.EXLOCK is checked */
+ write_sysreg_s(expect_exlock ? GCSCR_ELx_EXLOCKEN : 0,
+ SYS_GCSCR_EL2);
+ isb();
+ break;
+
+ case UDF_VALIDATE:
+ GUEST_ASSERT_EQ(read_sysreg_s(SYS_GCSCR_EL2) & GCSCR_ELx_EXLOCKEN,
+ 0);
+
+ /* Validate the EXLOCK of the original exception. */
+ handler_pstate = regs->pstate;
+ GUEST_ASSERT_EQ(!!(regs->pstate & PSR_EXLOCK_BIT),
+ expect_exlock);
+
+ /* Clearing PSTATE.EXLOCK triggers an illegal ERET. */
+ regs->pstate &= ~PSR_EXLOCK_BIT;
+ break;
+
+ case UDF_REPAIR:
+ GUEST_ASSERT_EQ(read_sysreg_s(SYS_GCSCR_EL2) & GCSCR_ELx_EXLOCKEN,
+ 0);
+
+ /* Disable EXLOCK for the requesting context */
+ regs->pstate &= ~PSR_EXLOCK_BIT;
+ break;
+
+ case UDF_ELR_EL1:
+ GUEST_ASSERT_EQ(read_sysreg_s(SYS_GCSCR_EL2) & GCSCR_ELx_EXLOCKEN,
+ expect_exlock ? GCSCR_ELx_EXLOCKEN : 0);
+
+ asm volatile("mrs %0, elr_el1 \n\
+ msr elr_el1, %0"
+ : "=r"(val) :: "memory");
+ break;
+
+ case UDF_ELR_EL2:
+ GUEST_ASSERT_EQ(read_sysreg_s(SYS_GCSCR_EL2) & GCSCR_ELx_EXLOCKEN,
+ expect_exlock ? GCSCR_ELx_EXLOCKEN : 0);
+
+ asm volatile("mrs %0, elr_el2 \n\
+ msr elr_el2, %0"
+ : "=r"(val) :: "memory");
+ break;
+
+ case UDF_SPSR_EL1:
+ GUEST_ASSERT_EQ(read_sysreg_s(SYS_GCSCR_EL2) & GCSCR_ELx_EXLOCKEN,
+ expect_exlock ? GCSCR_ELx_EXLOCKEN : 0);
+
+ asm volatile("mrs %0, spsr_el1 \n\
+ msr spsr_el1, %0"
+ : "=r"(val) :: "memory");
+ break;
+
+ case UDF_SPSR_EL2:
+ GUEST_ASSERT_EQ(read_sysreg_s(SYS_GCSCR_EL2) & GCSCR_ELx_EXLOCKEN,
+ expect_exlock ? GCSCR_ELx_EXLOCKEN : 0);
+
+ asm volatile("mrs %0, spsr_el2 \n\
+ msr spsr_el2, %0"
+ : "=r"(val) :: "memory");
+ break;
+
+ default:
+ GUEST_FAIL("Invalid udf_mode");
+ }
+}
+
+static void guest_illegal_handler(struct ex_regs *regs)
+{
+ u64 esr = read_sysreg(esr_el2);
+
+ illegal_count++;
+ illegal_pstate = regs->pstate;
+
+ GUEST_ASSERT_EQ(ESR_ELx_EC(esr), ESR_ELx_EC_ILL);
+ GUEST_ASSERT(esr & ESR_ELx_IL);
+ GUEST_ASSERT(regs->pstate & PSTATE_IL_BIT);
+ GUEST_ASSERT(!(regs->pstate & PSR_EXLOCK_BIT));
+ GUEST_ASSERT_EQ(regs->pc, expected_illegal_pc);
+
+ /* Disable exception locking so we can repair the return state. */
+ write_sysreg_s(0, SYS_GCSCR_EL2);
+ isb();
+
+ /* We need our own EXLOCK clearing so we can repair the original */
+ udf_mode = UDF_REPAIR;
+ asm volatile("udf #0" ::: "memory");
+
+ /* Disable EXLOCK for the generating context, making things legal */
+ regs->pstate &= ~(PSTATE_IL_BIT | PSR_EXLOCK_BIT);
+}
+
+static void guest_gcs_handler(struct ex_regs *regs)
+{
+ u64 esr = read_sysreg(esr_el2);
+
+ gcs_count++;
+
+ GUEST_ASSERT_EQ(ESR_ELx_EC(esr), ESR_ELx_EC_GCS);
+ GUEST_ASSERT_EQ(FIELD_GET(ESR_ELx_ExType_MASK, esr),
+ ESR_ELx_ExType_EXLOCK);
+
+ /* Disabling EXLOCKEN makes sysreg writes legal. */
+ write_sysreg_s(0, SYS_GCSCR_EL2);
+ isb();
+}
+
+static noinline void test_exception(bool hvc, bool enable_exlock)
+{
+ unsigned int initial_undef = undef_count;
+ unsigned int initial_hvc = hvc_count;
+ unsigned int initial_illegal = illegal_count;
+ unsigned int initial_gcs = gcs_count;
+
+ expect_exlock = enable_exlock;
+ write_sysreg_s(enable_exlock ? GCSCR_ELx_EXLOCKEN : 0,
+ SYS_GCSCR_EL2);
+ isb();
+
+ udf_mode = UDF_COLLECT;
+ take_exception(hvc);
+
+ /* Leave GCS disabled even if a broken ERET skipped the ILL handler. */
+ write_sysreg_s(0, SYS_GCSCR_EL2);
+ isb();
+
+ /* The nested exceptions are always UDFs */
+ GUEST_ASSERT_EQ(hvc_count, initial_hvc + hvc);
+ GUEST_ASSERT_EQ(undef_count, initial_undef + !hvc + 1 + enable_exlock);
+ GUEST_ASSERT_EQ(illegal_count, initial_illegal + enable_exlock);
+ GUEST_ASSERT_EQ(!!(handler_pstate & PSR_EXLOCK_BIT), enable_exlock);
+ if (enable_exlock)
+ GUEST_ASSERT(illegal_pstate & PSTATE_IL_BIT);
+ GUEST_ASSERT_EQ(initial_gcs, gcs_count);
+}
+
+static noinline void test_sysreg(bool hvc, enum udf_mode reg,
+ bool enable_exlock)
+{
+ unsigned int initial_undef = undef_count;
+ unsigned int initial_hvc = hvc_count;
+ unsigned int initial_gcs = gcs_count;
+
+ expect_exlock = enable_exlock;
+
+ write_sysreg_s(enable_exlock ? GCSCR_ELx_EXLOCKEN : 0,
+ SYS_GCSCR_EL2);
+ isb();
+
+ udf_mode = reg;
+ take_exception(hvc);
+
+ /* Ensure EXLOCK is disabled */
+ write_sysreg_s(0, SYS_GCSCR_EL2);
+ isb();
+
+ GUEST_ASSERT_EQ(gcs_count, initial_gcs + expect_exlock);
+ GUEST_ASSERT_EQ(undef_count, initial_undef + !hvc);
+ GUEST_ASSERT_EQ(hvc_count, initial_hvc + hvc);
+}
+
+static void test_exceptions(bool hvc)
+{
+ /*
+ * Try straightforwardly generating an exception without and
+ * with EXLOCK.
+ */
+ test_exception(hvc, false);
+ test_sysreg(hvc, UDF_ELR_EL1, false);
+ test_sysreg(hvc, UDF_ELR_EL2, false);
+ test_sysreg(hvc, UDF_SPSR_EL1, false);
+ test_sysreg(hvc, UDF_SPSR_EL2, false);
+
+ test_exception(hvc, true);
+ test_sysreg(hvc, UDF_ELR_EL1, true);
+ test_sysreg(hvc, UDF_ELR_EL2, true);
+ test_sysreg(hvc, UDF_SPSR_EL1, true);
+ test_sysreg(hvc, UDF_SPSR_EL2, true);
+}
+
+static void guest_code(void)
+{
+ GUEST_ASSERT_EQ(get_current_el(), 2);
+
+ /* Exceptions taken to vEL2 by the CPU */
+ test_exceptions(false);
+
+ /* Exceptions injected into vEL2 by KVM */
+ test_exceptions(true);
+
+ GUEST_DONE();
+}
+
+static void test_exception_from_same_el(void)
+{
+ struct kvm_vcpu_init init;
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+ struct ucall uc;
+
+ vm = vm_create(1);
+ kvm_get_default_vcpu_target(vm, &init);
+ init.features[0] |= BIT(KVM_ARM_VCPU_HAS_EL2);
+ vcpu = aarch64_vcpu_add(vm, 0, &init, guest_code);
+ require_guest_gcs(vcpu);
+
+ vm_init_descriptor_tables(vm);
+ vcpu_init_descriptor_tables(vcpu);
+ vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT,
+ ESR_ELx_EC_UNKNOWN, guest_exception_handler);
+ vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT,
+ ESR_ELx_EC_HVC64, guest_exception_handler);
+ vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT,
+ ESR_ELx_EC_ILL, guest_illegal_handler);
+ vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT,
+ ESR_ELx_EC_GCS, guest_gcs_handler);
+ kvm_arch_vm_finalize_vcpus(vm);
+
+ vcpu_run(vcpu);
+ switch (get_ucall(vcpu, &uc)) {
+ case UCALL_DONE:
+ break;
+ case UCALL_ABORT:
+ REPORT_GUEST_ASSERT(uc);
+ break;
+ default:
+ TEST_FAIL("Unhandled ucall: %ld", uc.cmd);
+ }
+
+ kvm_vm_free(vm);
+}
+
+/*
+ * The host injects an external abort on an MMIO exit. When the
+ * exception is taken to the EL it came from PSTATE.EXLOCK should be set
+ * to the EXLOCKEN for that EL, when it is taken from a lower EL it
+ * should be cleared. Either way the old value should be preserved in
+ * the SPSR. Where only one of the ELs is involved the EXLOCKEN for
+ * the other is given the opposite value in order to check that the
+ * right one is used.
+ */
+static const struct inject_test {
+ const char *name;
+ u64 pstate;
+ bool tge;
+ u64 gcscr_el1;
+ u64 gcscr_el2;
+ unsigned int target_mode;
+ bool exlock;
+} inject_tests[] = {
+ {
+ .name = "EL2h to EL2 with EXLOCKEN",
+ .pstate = PSR_MODE_EL2h,
+ .tge = true,
+ .gcscr_el2 = GCSCR_ELx_EXLOCKEN,
+ .target_mode = PSR_MODE_EL2h,
+ .exlock = true,
+ },
+ {
+ .name = "EL2h to EL2 without EXLOCKEN",
+ .pstate = PSR_MODE_EL2h | PSR_EXLOCK_BIT,
+ .tge = true,
+ .gcscr_el1 = GCSCR_ELx_EXLOCKEN,
+ .target_mode = PSR_MODE_EL2h,
+ .exlock = false,
+ },
+ {
+ .name = "EL2t to EL2 with EXLOCKEN",
+ .pstate = PSR_MODE_EL2t,
+ .tge = true,
+ .gcscr_el2 = GCSCR_ELx_EXLOCKEN,
+ .target_mode = PSR_MODE_EL2h,
+ .exlock = true,
+ },
+ {
+ .name = "EL1h to EL1 with EXLOCKEN",
+ .pstate = PSR_MODE_EL1h,
+ .gcscr_el1 = GCSCR_ELx_EXLOCKEN,
+ .target_mode = PSR_MODE_EL1h,
+ .exlock = true,
+ },
+ {
+ .name = "EL1h to EL1 without EXLOCKEN",
+ .pstate = PSR_MODE_EL1h | PSR_EXLOCK_BIT,
+ .gcscr_el2 = GCSCR_ELx_EXLOCKEN,
+ .target_mode = PSR_MODE_EL1h,
+ .exlock = false,
+ },
+ {
+ .name = "EL0 to EL1",
+ .pstate = PSR_MODE_EL0t | PSR_EXLOCK_BIT,
+ .gcscr_el1 = GCSCR_ELx_EXLOCKEN,
+ .gcscr_el2 = GCSCR_ELx_EXLOCKEN,
+ .target_mode = PSR_MODE_EL1h,
+ .exlock = false,
+ },
+ {
+ .name = "EL0 to EL2",
+ .pstate = PSR_MODE_EL0t | PSR_EXLOCK_BIT,
+ .tge = true,
+ .gcscr_el1 = GCSCR_ELx_EXLOCKEN,
+ .gcscr_el2 = GCSCR_ELx_EXLOCKEN,
+ .target_mode = PSR_MODE_EL2h,
+ .exlock = false,
+ },
+};
+
+/* ldr x0, [x0] runs at any EL without a stack or BTI landing pad. */
+static const __le32 guest_mmio_read = cpu_to_le32(0xf9400000);
+
+static void test_injected_exception(const struct inject_test *test)
+{
+ struct kvm_vcpu_events events = {};
+ struct kvm_vcpu_init init;
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+ u64 hcr, pstate, spsr;
+ gpa_t fault_pc, mmio_gpa;
+
+ vm = vm_create(1);
+ kvm_get_default_vcpu_target(vm, &init);
+ init.features[0] |= BIT(KVM_ARM_VCPU_HAS_EL2);
+
+ /* Leave stage 1 disabled so every source EL can run the load by IPA. */
+ vcpu = __vm_vcpu_add(vm, 0);
+ vcpu_ioctl(vcpu, KVM_ARM_VCPU_INIT, &init);
+ require_guest_gcs(vcpu);
+ kvm_arch_vm_finalize_vcpus(vm);
+
+ /*
+ * With TGE set exceptions from EL0 go to vEL2, without it
+ * exceptions from EL0 and EL1 go to vEL1.
+ */
+ hcr = HCR_EL2_RW | HCR_EL2_E2H;
+ if (test->tge)
+ hcr |= HCR_EL2_TGE;
+ vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_HCR_EL2), hcr);
+
+ fault_pc = addr_gva2gpa(vm, (gva_t)&guest_mmio_read);
+ vcpu_set_reg(vcpu, ARM64_CORE_REG(regs.pc), fault_pc);
+
+ /* Use the unbacked ucall page, past the address reserved for ucalls. */
+ mmio_gpa = vm->ucall_mmio_addr + sizeof(u64);
+ vcpu_args_set(vcpu, 1, mmio_gpa);
+
+ vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_GCSCR_EL1), test->gcscr_el1);
+ vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_GCSCR_EL2), test->gcscr_el2);
+ vcpu_set_reg(vcpu, ARM64_CORE_REG(regs.pstate), test->pstate);
+
+ vcpu_run(vcpu);
+ TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_MMIO);
+ TEST_ASSERT_EQ(vcpu->run->mmio.phys_addr, mmio_gpa);
+ TEST_ASSERT_EQ(vcpu->run->mmio.len, sizeof(u64));
+ TEST_ASSERT(!vcpu->run->mmio.is_write, "%s: expected an MMIO read", test->name);
+ TEST_ASSERT_EQ(vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pc)), fault_pc);
+ pstate = vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pstate));
+ TEST_ASSERT((pstate & (PSR_MODE_MASK | PSR_EXLOCK_BIT)) == test->pstate,
+ "%s: unexpected PSTATE %#lx at MMIO exit", test->name, pstate);
+
+ events.exception.ext_dabt_pending = true;
+ vcpu_events_set(vcpu, &events);
+
+ pstate = vcpu_get_reg(vcpu, ARM64_CORE_REG(regs.pstate));
+ TEST_ASSERT((pstate & PSR_MODE_MASK) == test->target_mode,
+ "%s: exception taken to mode %#x, expected %#x",
+ test->name, (unsigned int)(pstate & PSR_MODE_MASK),
+ test->target_mode);
+ TEST_ASSERT(!!(pstate & PSR_EXLOCK_BIT) == test->exlock,
+ "%s: PSTATE.EXLOCK %s by the exception",
+ test->name, test->exlock ? "not set" : "not cleared");
+
+ if (test->target_mode == PSR_MODE_EL2h)
+ spsr = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_SPSR_EL2));
+ else
+ spsr = vcpu_get_reg(vcpu, ARM64_CORE_REG(spsr[KVM_SPSR_EL1]));
+ TEST_ASSERT((spsr & PSR_MODE_MASK) == (test->pstate & PSR_MODE_MASK),
+ "%s: source mode not preserved in SPSR", test->name);
+ TEST_ASSERT((spsr & PSR_EXLOCK_BIT) == (test->pstate & PSR_EXLOCK_BIT),
+ "%s: PSTATE.EXLOCK not preserved in SPSR", test->name);
+
+ kvm_vm_free(vm);
+}
+
+int main(void)
+{
+ int i;
+
+ TEST_REQUIRE(kvm_check_cap(KVM_CAP_ARM_EL2));
+ test_exception_from_same_el();
+ TEST_REQUIRE(kvm_check_cap(KVM_CAP_ARM_INJECT_EXT_DABT));
+ for (i = 0; i < ARRAY_SIZE(inject_tests); i++)
+ test_injected_exception(&inject_tests[i]);
+
+ return 0;
+}
--
2.47.3
prev parent reply other threads:[~2026-11-30 16:44 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 16:35 [PATCH v22 00/16] KVM: arm64: Provide guest support for GCS Mark Brown
2026-11-30 16:35 ` [PATCH v22 01/16] arm64/gcs: Ensure FGTs for EL1 GCS instructions are disabled Mark Brown
2026-11-30 16:35 ` [PATCH v22 02/16] KVM: arm64: Drop the SPSR_EL1 and ELR_EL1 trap accessors Mark Brown
2026-11-30 16:35 ` [PATCH v22 03/16] KVM: arm64: Manage GCS access and registers for guests Mark Brown
2026-11-30 16:49 ` Leonardo Bras
2026-11-30 16:59 ` Mark Brown
2026-11-30 16:35 ` [PATCH v22 04/16] KVM: arm64: Ensure GCS memory effects are visible Mark Brown
2026-11-30 16:35 ` [PATCH v22 05/16] KVM: arm64: Set PSTATE.EXLOCK when entering an exception Mark Brown
2026-11-30 16:35 ` [PATCH v22 06/16] KVM: arm64: Validate GCS exception lock when emulating ERET Mark Brown
2026-11-30 16:35 ` [PATCH v22 07/16] KVM: arm64: Forward GCS exceptions to nested guests Mark Brown
2026-11-30 16:35 ` [PATCH v22 08/16] KVM: arm64: Preserve ISS2.GCS when injecting a Data Abort Mark Brown
2026-11-30 16:35 ` [PATCH v22 09/16] KVM: arm64: Fully implement GCS in the stage-1 walker Mark Brown
2026-11-30 16:35 ` [PATCH v22 10/16] KVM: arm64: Allow GCS to be enabled for guests Mark Brown
2026-11-30 16:35 ` [PATCH v22 11/16] KVM: selftests: arm64: Check invalid feature combination handling Mark Brown
2026-11-30 16:35 ` [PATCH v22 12/16] KVM: selftests: arm64: Add GCS registers to get-reg-list Mark Brown
2026-11-30 16:35 ` [PATCH v22 13/16] KVM: selftests: arm64: Add GCS to set_id_regs Mark Brown
2026-11-30 16:35 ` [PATCH v22 14/16] KVM: selftests: arm64: Only restore SPSR_EL1 and ELR_EL1 if they change Mark Brown
2026-11-30 16:35 ` [PATCH v22 15/16] tools: Synchronise the kernel esr.h Mark Brown
2026-11-30 16:35 ` Mark Brown [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130-arm64-gcs-v22-16-80454edf47ea@kernel.org \
--to=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=leo.bras@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=peter.maydell@linaro.org \
--cc=shuah@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=weilin.chang@arm.com \
--cc=will@kernel.org \
--cc=yaoyuan@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®