Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Sean Christopherson <seanjc@google.com>

+17 -2
+17 -2
tools/testing/selftests/kvm/guest_print_test.c
··· 107 107 expected_assert_msg, &assert_msg[offset]); 108 108 } 109 109 110 + /* 111 + * Open code vcpu_run(), sans the UCALL_ABORT handling, so that intentional 112 + * guest asserts guest can be verified instead of being reported as failures. 113 + */ 114 + static void do_vcpu_run(struct kvm_vcpu *vcpu) 115 + { 116 + int r; 117 + 118 + do { 119 + r = __vcpu_run(vcpu); 120 + } while (r == -1 && errno == EINTR); 121 + 122 + TEST_ASSERT(!r, KVM_IOCTL_ERROR(KVM_RUN, r)); 123 + } 124 + 110 125 static void run_test(struct kvm_vcpu *vcpu, const char *expected_printf, 111 126 const char *expected_assert) 112 127 { ··· 129 114 struct ucall uc; 130 115 131 116 while (1) { 132 - vcpu_run(vcpu); 117 + do_vcpu_run(vcpu); 133 118 134 119 TEST_ASSERT(run->exit_reason == UCALL_EXIT_REASON, 135 120 "Unexpected exit reason: %u (%s),", ··· 174 159 175 160 vm = vm_create_with_one_vcpu(&vcpu, guest_code_limits); 176 161 run = vcpu->run; 177 - vcpu_run(vcpu); 162 + do_vcpu_run(vcpu); 178 163 179 164 TEST_ASSERT(run->exit_reason == UCALL_EXIT_REASON, 180 165 "Unexpected exit reason: %u (%s),",