]> www.infradead.org Git - linux.git/commitdiff
KVM: selftests: Open code vcpu_run() equivalent in guest_printf test
authorSean Christopherson <seanjc@google.com>
Fri, 19 Jul 2024 23:51:01 +0000 (16:51 -0700)
committerSean Christopherson <seanjc@google.com>
Thu, 29 Aug 2024 23:25:06 +0000 (16:25 -0700)
Open code a version of vcpu_run() in the guest_printf test in anticipation
of adding UCALL_ABORT handling to _vcpu_run().  The guest_printf test
intentionally generates asserts to verify the output, and thus needs to
bypass common assert handling.

Open code a helper in the guest_printf test, as it's not expected that any
other test would want to skip _only_ the UCALL_ABORT handling.

Link: https://lore.kernel.org/r/20240719235107.3023592-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/guest_print_test.c

index 8092c2d0f5d688484f94df319f99bae92faeda81..bcf582852db9971a22d5c701e93f90b57fea6097 100644 (file)
@@ -107,6 +107,21 @@ static void ucall_abort(const char *assert_msg, const char *expected_assert_msg)
                    expected_assert_msg, &assert_msg[offset]);
 }
 
+/*
+ * Open code vcpu_run(), sans the UCALL_ABORT handling, so that intentional
+ * guest asserts guest can be verified instead of being reported as failures.
+ */
+static void do_vcpu_run(struct kvm_vcpu *vcpu)
+{
+       int r;
+
+       do {
+               r = __vcpu_run(vcpu);
+       } while (r == -1 && errno == EINTR);
+
+       TEST_ASSERT(!r, KVM_IOCTL_ERROR(KVM_RUN, r));
+}
+
 static void run_test(struct kvm_vcpu *vcpu, const char *expected_printf,
                     const char *expected_assert)
 {
@@ -114,7 +129,7 @@ static void run_test(struct kvm_vcpu *vcpu, const char *expected_printf,
        struct ucall uc;
 
        while (1) {
-               vcpu_run(vcpu);
+               do_vcpu_run(vcpu);
 
                TEST_ASSERT(run->exit_reason == UCALL_EXIT_REASON,
                            "Unexpected exit reason: %u (%s),",
@@ -159,7 +174,7 @@ static void test_limits(void)
 
        vm = vm_create_with_one_vcpu(&vcpu, guest_code_limits);
        run = vcpu->run;
-       vcpu_run(vcpu);
+       do_vcpu_run(vcpu);
 
        TEST_ASSERT(run->exit_reason == UCALL_EXIT_REASON,
                    "Unexpected exit reason: %u (%s),",