Re: [PATCH v4 12/12] KVM: selftests: Trigger L2->L1 exits stress save+restore and #PF test

Yosry Ahmed <[email protected]>
Newsgroups dev.linux.lists.sashiko-reviews,org.kernel.vger.kvm
Message-ID <CAO9r8zMbokukK-atix85WH-SkUtt9=qL9tjJf4y7c_dcwkQJyQ@mail.gmail.com>
On Mon, Jul 27, 2026 at 5:09 PM <[email protected]> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] The test unconditionally enables `KVM_CAP_EXCEPTION_PAYLOAD` in `run_test()`, causing the test to crash on older kernels before reaching the capability check in `main()`.
> --
>
> --- Patch [12]: [PATCH v4 12/12] KVM: selftests: Trigger L2->L1 exits stress save+restore and #PF test ---
> commit 30592840747b18628e46af30e613a95b722da3cc
> Author: Yosry Ahmed <[email protected]>
>
> KVM: selftests: Trigger L2->L1 exits stress save+restore and #PF test
>
> This commit extends the testing coverage in L2 by forcing a nested VM-Exit
> from L2 to L1 right after restore on every other iteration. To force the
> nested VM-Exit, it injects a #UD into the saved vCPU state and intercepts
> #UD from L1.
>
> > diff --git a/tools/testing/selftests/kvm/x86/save_restore_pf_stress_test.c b/tools/testing/selftests/kvm/x86/save_restore_pf_stress_test.c
> > index 0e5ddeb5af444..ba1d723001e94 100644
> > --- a/tools/testing/selftests/kvm/x86/save_restore_pf_stress_test.c
> > +++ b/tools/testing/selftests/kvm/x86/save_restore_pf_stress_test.c
> [ ... ]
> > @@ -156,6 +178,7 @@ static void run_test(bool nested)
> >
> >       vm = vm_create_with_one_vcpu(&vcpu, nested ? l1_guest_code : guest_access_memory);
> >       vm_install_exception_handler(vm, PF_VECTOR, guest_pf_handler);
> > +     vm_enable_cap(vm, KVM_CAP_EXCEPTION_PAYLOAD, -2ul);
> >
> >       if (nested) {
> >               if (kvm_cpu_has(X86_FEATURE_SVM))
> [ ... ]
> > @@ -247,7 +278,9 @@ int main(int argc, char *argv[])
> >       pr_info("Running save+restore stress test...\n");
> >       run_test(/*nested=*/false);
> >
> > -     if (!kvm_cpu_has(X86_FEATURE_SVM) && !kvm_cpu_has(X86_FEATURE_VMX)) {
> > +     if (!kvm_has_cap(KVM_CAP_EXCEPTION_PAYLOAD) ||
> > +         !kvm_has_cap(KVM_CAP_NESTED_STATE) ||
> > +         (!kvm_cpu_has(X86_FEATURE_SVM) && !kvm_cpu_has(X86_FEATURE_VMX))) {
>
> [Severity: Medium]
> Will this test crash on older kernels that lack KVM_CAP_EXCEPTION_PAYLOAD?
>
> Because run_test(false) is called before this capability check in main(),
> run_test() will unconditionally call vm_enable_cap() for
> KVM_CAP_EXCEPTION_PAYLOAD.
>
> Could this prevent the test from gracefully skipping on environments without
> this capability?

Oh I missed this. Yeah we need to make enabling the CAP conditional on
nested=true.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.