Skip to contentSkip to conversation

KVM: arm64: selftests: Check the pending SError state in external_aborts

PATCH Applied Fuad Tabba 4 participants 4 messages Oct 6 – Oct 7

Subsystems (3)
lore
Share & tools
lore

Fuad Tabba

author reviewer
#0 lore raw

PATCH v4 1/1 KVM: arm64: selftests: Check the pending SError state in external_aborts

None of the external abort tests look at the vCPU events once the guest is done, so an SError left pending after the guest took it, or dropped while the guest had it masked, goes unnoticed.

Read the vCPU events back at the end of every test that runs the guest. The SError must still be pending in the masked case, with the injected ESR when the vCPU has RAS, and no SError, injected or spurious, may be pending in any of the others.

---
The check that no SError is left pending after the guest took it is what fails without commit 3708f6342f01 ("KVM: arm64: Sync HCR_EL2.VSE back to the host vCPU under pKVM"), in kvmarm/next.

Changes since v3 [1]:
- Check the SError pending state at the end of every test that runs the guest, and assert it is still pending, with the injected ESR, in the masked case (Oliver [2]).

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

 .../selftests/kvm/arm64/external_aborts.c     | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/testing/selftests/kvm/arm64/external_aborts.c +20 -0
index 7836756a38a6c..1a858d0d82968 100644
@@ -75,6 +75,17 @@ static void vcpu_inject_serror(struct kvm_vcpu *vcpu)
 	vcpu_events_set(vcpu, &events);
 }
 
+static void vcpu_assert_serror_pending(struct kvm_vcpu *vcpu, bool pending)
+{
+	struct kvm_vcpu_events events;
+
+	vcpu_events_get(vcpu, &events);
+	TEST_ASSERT_EQ(events.exception.serror_pending, pending);
+
+	if (pending && vcpu_has_ras(vcpu))
+		TEST_ASSERT_EQ(events.exception.serror_esr, EXPECTED_SERROR_ISS);
+}
+
 static void __vcpu_run_expect(struct kvm_vcpu *vcpu, unsigned int cmd)
 {
 	struct ucall uc;
@@ -134,6 +145,7 @@ static void test_mmio_abort(void)
 
 	vcpu_inject_sea(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -162,6 +174,7 @@ static void test_mmio_nisv(void)
 
 	TEST_ASSERT(_vcpu_run(vcpu), "Expected nonzero return code from KVM_RUN");
 	TEST_ASSERT_EQ(errno, ENOSYS);
+	vcpu_assert_serror_pending(vcpu, false);
 
 	kvm_vm_free(vm);
 }
@@ -185,6 +198,7 @@ static void test_mmio_nisv_abort(void)
 
 	vcpu_inject_sea(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -212,6 +226,7 @@ static void test_serror_masked(void)
 
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, true);
 	kvm_vm_free(vm);
 }
 
@@ -247,6 +262,7 @@ static void test_serror(void)
 
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -288,6 +304,7 @@ static void test_s1ptw_abort(void)
 	*ptep |= bad_pa;
 
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -313,6 +330,7 @@ static void test_serror_emulated(void)
 	vcpu_run_expect_sync(vcpu);
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -356,6 +374,7 @@ static void test_mmio_ease(void)
 
 	vcpu_inject_sea(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 done:
 	kvm_vm_free(vm);
 }
@@ -395,6 +414,7 @@ static void test_serror_amo(void)
 	vcpu_run_expect_sync(vcpu);
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 

base-commit: fa22cd9947fc245d71bc40482f7f78eb0d5a4af0

Signature · 1 line
2.39.5
maintainer Reviewed-by on v4 1/1
#1 lore raw
Quoted 10 lines · Fuad Tabba

None of the external abort tests look at the vCPU events once the guest is done, so an SError left pending after the guest took it, or dropped while the guest had it masked, goes unnoticed.

Read the vCPU events back at the end of every test that runs the guest. The SError must still be pending in the masked case, with the injected ESR when the vCPU has RAS, and no SError, injected or spurious, may be pending in any of the others.

Thanks,
Oliver

Quoted 115 lines

---
The check that no SError is left pending after the guest took it is what fails without commit 3708f6342f01 ("KVM: arm64: Sync HCR_EL2.VSE back to the host vCPU under pKVM"), in kvmarm/next.

Changes since v3 [1]:
- Check the SError pending state at the end of every test that runs the guest, and assert it is still pending, with the injected ESR, in the masked case (Oliver [2]).

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

 .../selftests/kvm/arm64/external_aborts.c     | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/testing/selftests/kvm/arm64/external_aborts.c +20 -0
index 7836756a38a6c..1a858d0d82968 100644
@@ -75,6 +75,17 @@ static void vcpu_inject_serror(struct kvm_vcpu *vcpu)
 	vcpu_events_set(vcpu, &events);
 }
 
+static void vcpu_assert_serror_pending(struct kvm_vcpu *vcpu, bool pending)
+{
+	struct kvm_vcpu_events events;
+
+	vcpu_events_get(vcpu, &events);
+	TEST_ASSERT_EQ(events.exception.serror_pending, pending);
+
+	if (pending && vcpu_has_ras(vcpu))
+		TEST_ASSERT_EQ(events.exception.serror_esr, EXPECTED_SERROR_ISS);
+}
+
 static void __vcpu_run_expect(struct kvm_vcpu *vcpu, unsigned int cmd)
 {
 	struct ucall uc;
@@ -134,6 +145,7 @@ static void test_mmio_abort(void)
 
 	vcpu_inject_sea(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -162,6 +174,7 @@ static void test_mmio_nisv(void)
 
 	TEST_ASSERT(_vcpu_run(vcpu), "Expected nonzero return code from KVM_RUN");
 	TEST_ASSERT_EQ(errno, ENOSYS);
+	vcpu_assert_serror_pending(vcpu, false);
 
 	kvm_vm_free(vm);
 }
@@ -185,6 +198,7 @@ static void test_mmio_nisv_abort(void)
 
 	vcpu_inject_sea(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -212,6 +226,7 @@ static void test_serror_masked(void)
 
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, true);
 	kvm_vm_free(vm);
 }
 
@@ -247,6 +262,7 @@ static void test_serror(void)
 
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -288,6 +304,7 @@ static void test_s1ptw_abort(void)
 	*ptep |= bad_pa;
 
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -313,6 +330,7 @@ static void test_serror_emulated(void)
 	vcpu_run_expect_sync(vcpu);
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -356,6 +374,7 @@ static void test_mmio_ease(void)
 
 	vcpu_inject_sea(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 done:
 	kvm_vm_free(vm);
 }
@@ -395,6 +414,7 @@ static void test_serror_amo(void)
 	vcpu_run_expect_sync(vcpu);
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 

base-commit: fa22cd9947fc245d71bc40482f7f78eb0d5a4af0

Signature · 1 line
2.39.5
Tested-by on v4 1/1
#2 lore raw
In reply to Fuad Tabba
Quoted 9 lines · Fuad Tabba

None of the external abort tests look at the vCPU events once the guest is done, so an SError left pending after the guest took it, or dropped while the guest had it masked, goes unnoticed.

Read the vCPU events back at the end of every test that runs the guest. The SError must still be pending in the masked case, with the injected ESR when the vCPU has RAS, and no SError, injected or spurious, may be pending in any of the others.

Quoted 5 lines

---
The check that no SError is left pending after the guest took it is what fails without commit 3708f6342f01 ("KVM: arm64: Sync HCR_EL2.VSE back to the host vCPU under pKVM"), in kvmarm/next.

Applied this fix cleanly on today's kvmarm/next and did run extranl_aborts on a NVIDIA Grace system booted with the proper ACPI tables, the program finished quietly.

Thanks,
Itaru.

Quoted 111 lines

Changes since v3 [1]:
- Check the SError pending state at the end of every test that runs the guest, and assert it is still pending, with the injected ESR, in the masked case (Oliver [2]).

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

 .../selftests/kvm/arm64/external_aborts.c     | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/testing/selftests/kvm/arm64/external_aborts.c +20 -0
index 7836756a38a6c..1a858d0d82968 100644
@@ -75,6 +75,17 @@ static void vcpu_inject_serror(struct kvm_vcpu *vcpu)
 	vcpu_events_set(vcpu, &events);
 }
 
+static void vcpu_assert_serror_pending(struct kvm_vcpu *vcpu, bool pending)
+{
+	struct kvm_vcpu_events events;
+
+	vcpu_events_get(vcpu, &events);
+	TEST_ASSERT_EQ(events.exception.serror_pending, pending);
+
+	if (pending && vcpu_has_ras(vcpu))
+		TEST_ASSERT_EQ(events.exception.serror_esr, EXPECTED_SERROR_ISS);
+}
+
 static void __vcpu_run_expect(struct kvm_vcpu *vcpu, unsigned int cmd)
 {
 	struct ucall uc;
@@ -134,6 +145,7 @@ static void test_mmio_abort(void)
 
 	vcpu_inject_sea(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -162,6 +174,7 @@ static void test_mmio_nisv(void)
 
 	TEST_ASSERT(_vcpu_run(vcpu), "Expected nonzero return code from KVM_RUN");
 	TEST_ASSERT_EQ(errno, ENOSYS);
+	vcpu_assert_serror_pending(vcpu, false);
 
 	kvm_vm_free(vm);
 }
@@ -185,6 +198,7 @@ static void test_mmio_nisv_abort(void)
 
 	vcpu_inject_sea(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -212,6 +226,7 @@ static void test_serror_masked(void)
 
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, true);
 	kvm_vm_free(vm);
 }
 
@@ -247,6 +262,7 @@ static void test_serror(void)
 
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -288,6 +304,7 @@ static void test_s1ptw_abort(void)
 	*ptep |= bad_pa;
 
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -313,6 +330,7 @@ static void test_serror_emulated(void)
 	vcpu_run_expect_sync(vcpu);
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 
@@ -356,6 +374,7 @@ static void test_mmio_ease(void)
 
 	vcpu_inject_sea(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 done:
 	kvm_vm_free(vm);
 }
@@ -395,6 +414,7 @@ static void test_serror_amo(void)
 	vcpu_run_expect_sync(vcpu);
 	vcpu_inject_serror(vcpu);
 	vcpu_run_expect_done(vcpu);
+	vcpu_assert_serror_pending(vcpu, false);
 	kvm_vm_free(vm);
 }
 

base-commit: fa22cd9947fc245d71bc40482f7f78eb0d5a4af0

Signature · 1 line
2.39.5
maintainer Applied
#3 lore raw
In reply to Fuad Tabba
Quoted 10 lines · Fuad Tabba

None of the external abort tests look at the vCPU events once the guest is done, so an SError left pending after the guest took it, or dropped while the guest had it masked, goes unnoticed.

Read the vCPU events back at the end of every test that runs the guest. The SError must still be pending in the masked case, with the injected ESR when the vCPU has RAS, and no SError, injected or spurious, may be pending in any of the others.

[...]

Applied to next, thanks!

[1/1] KVM: arm64: selftests: Check the pending SError state in external_aborts

      commit: 49664cd0b1db434b6bbf9e37c84b3f448a545dc5

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.