Re: [PATCH v3 09/10] KVM: selftests: Support running stress save+restore and #PF test in L2

From: Sean Christopherson

Date: Fri Jul 24 2026 - 13:38:03 EST


On Mon, Jun 29, 2026, Yosry Ahmed wrote:
> +static bool parse_args_nested(int argc, char *argv[])
> +{
> + bool nested = false;
> + int opt;
> +
> + while ((opt = getopt(argc, argv, "n")) != -1) {

Since the test ends up taking args anyways, might as well have it take the number
of iterations too.

But, why make it an either-or? If nested is supported, run the test non-nested
and then run it nested. While I am sloooooowly working towards utilizing Vipin's
selftest runner, IMO this is still basic functionality that should be tested by
default, i.e. shouldn't require fancy opt-in.

> + switch (opt) {
> + case 'n':
> + nested = true;
> + break;
> + default:
> + printf("Usage: %s [-n]\n", argv[0]);
> + exit(1);
> + }
> + }
> +
> + return nested;
> +}
> +
> int main(int argc, char *argv[])
> {
> struct kvm_x86_state *state;
> @@ -136,12 +188,24 @@ int main(int argc, char *argv[])
> struct kvm_vm *vm;
> struct ucall uc;
> u64 *pgtable;
> + bool nested;
> gva_t gva;
> u64 pte;
>
> - vm = vm_create_with_one_vcpu(&vcpu, guest_access_memory);
> + nested = parse_args_nested(argc, argv);
> +
> + vm = vm_create_with_one_vcpu(&vcpu, nested ? l1_guest_code : guest_access_memory);
> vm_install_exception_handler(vm, PF_VECTOR, guest_pf_handler);
>
> + if (nested) {
> + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM) || kvm_cpu_has(X86_FEATURE_VMX));
> + if (kvm_cpu_has(X86_FEATURE_SVM))
> + vcpu_alloc_svm(vm, &gva);
> + else
> + vcpu_alloc_vmx(vm, &gva);
> + vcpu_args_set(vcpu, 1, gva);
> + }
> +
> pte_present_mask = PTE_PRESENT_MASK(&vm->mmu);
> pte_huge_mask = PTE_HUGE_MASK(&vm->mmu);
> sync_global_to_guest(vm, pte_present_mask);
> @@ -216,7 +280,7 @@ int main(int argc, char *argv[])
>
> sync_global_from_guest(vm, guest_faults);
> TEST_ASSERT(guest_faults > 0, "No guest page faults triggered");
> - pr_info("Guest page faults: %lu\n", guest_faults);
> + pr_info("Guest page faults%s: %lu\n", nested ? " (in L2)" : "", guest_faults);
>
> pthread_cancel(sigusr_thread);
> pthread_join(sigusr_thread, NULL);
> --
> 2.55.0.rc0.799.gd6f94ed593-goog
>