Re: [PATCH v2 07/10] KVM: selftests: Add basic stress test for save+restore and #PF handling

From: Yosry Ahmed

Date: Fri Jun 05 2026 - 12:40:33 EST


> + while (count++ < NR_ITERATIONS) {
> + r = __vcpu_run(vcpu);
> + TEST_ASSERT(!r, "vcpu_run failed");
> + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
> +
> + get_ucall(vcpu, &uc);
> + if (uc.cmd == UCALL_ABORT) {
> + REPORT_GUEST_ASSERT(uc);
> + break;
> + }
> + TEST_ASSERT_EQ(uc.cmd, UCALL_SYNC);
> + TEST_ASSERT_EQ(uc.args[1], count - 1);

This is off-by-one, it should be 'count', otherwise the assertion
always fails. I made changes between versions and did not run the test
in between changes. The assertion goes away in the next patch so I
didn't notice.

> +
> + state = vcpu_save_state(vcpu);
> +
> + kvm_vm_release(vm);
> + vcpu = vm_recreate_with_one_vcpu(vm);
> + vcpu_load_state(vcpu, state);
> + kvm_x86_state_cleanup(state);
> +
> + PRINT_ITER("Save+restore iterations: ", count);
> + }
> +
> + sync_global_from_guest(vm, guest_faults);
> + pr_info("Guest page faults: %lu\n", guest_faults);
> +
> + kvm_vm_free(vm);
> + return 0;
> +}
> --
> 2.54.0.1032.g2f8565e1d1-goog
>