Skip to content

Commit f9e4e0a

Browse files
committed
KVM: arm64: selftests: Test ESR propagation for vSError injection
Ensure that vSErrors taken in the guest have an appropriate ESR_ELx value for the expected exception. Additionally, switch the EASE test to install the SEA handler at the SError offset, as the ESR is still expected to match an SEA in that case. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent f6e2262 commit f9e4e0a

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

tools/testing/selftests/kvm/arm64/external_aborts.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include "processor.h"
88
#include "test_util.h"
99

10-
#define MMIO_ADDR 0x8000000ULL
10+
#define MMIO_ADDR 0x8000000ULL
11+
#define EXPECTED_SERROR_ISS (ESR_ELx_ISV | 0x1d1ed)
1112

1213
static u64 expected_abort_pc;
1314

@@ -49,11 +50,28 @@ static void vcpu_inject_sea(struct kvm_vcpu *vcpu)
4950
vcpu_events_set(vcpu, &events);
5051
}
5152

53+
static bool vcpu_has_ras(struct kvm_vcpu *vcpu)
54+
{
55+
u64 pfr0 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64PFR0_EL1));
56+
57+
return SYS_FIELD_GET(ID_AA64PFR0_EL1, RAS, pfr0);
58+
}
59+
60+
static bool guest_has_ras(void)
61+
{
62+
return SYS_FIELD_GET(ID_AA64PFR0_EL1, RAS, read_sysreg(id_aa64pfr0_el1));
63+
}
64+
5265
static void vcpu_inject_serror(struct kvm_vcpu *vcpu)
5366
{
5467
struct kvm_vcpu_events events = {};
5568

5669
events.exception.serror_pending = true;
70+
if (vcpu_has_ras(vcpu)) {
71+
events.exception.serror_has_esr = true;
72+
events.exception.serror_esr = EXPECTED_SERROR_ISS;
73+
}
74+
5775
vcpu_events_set(vcpu, &events);
5876
}
5977

@@ -199,6 +217,12 @@ static void test_serror_masked(void)
199217

200218
static void expect_serror_handler(struct ex_regs *regs)
201219
{
220+
u64 esr = read_sysreg(esr_el1);
221+
222+
GUEST_ASSERT_EQ(ESR_ELx_EC(esr), ESR_ELx_EC_SERROR);
223+
if (guest_has_ras())
224+
GUEST_ASSERT_EQ(ESR_ELx_ISS(esr), EXPECTED_SERROR_ISS);
225+
202226
GUEST_DONE();
203227
}
204228

@@ -277,7 +301,11 @@ static void test_mmio_ease(void)
277301
return;
278302
}
279303

280-
vm_install_exception_handler(vm, VECTOR_ERROR_CURRENT, expect_serror_handler);
304+
/*
305+
* SCTLR2_ELx.EASE changes the exception vector to the SError vector but
306+
* doesn't further modify the exception context (e.g. ESR_ELx, FAR_ELx).
307+
*/
308+
vm_install_exception_handler(vm, VECTOR_ERROR_CURRENT, expect_sea_handler);
281309

282310
vcpu_run(vcpu);
283311
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_MMIO);

0 commit comments

Comments
 (0)