Commit d1c2cdca authored by Sean Christopherson's avatar Sean Christopherson
Browse files

KVM: selftests: Open code vcpu_run() equivalent in guest_printf test

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: default avatarSean Christopherson <seanjc@google.com>
parent 73b42dc6
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -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),",