Re: [PATCH v15 35/41] KVM: selftests: Add an MSR test to exercise guest/host and read/write

Sean Christopherson
2025-09-15T17:00:43Z

On Mon, Sep 15, 2025, Chao Gao wrote:
> >+static void __vcpus_run(struct kvm_vcpu **vcpus, const int NR_VCPUS)
> >+{
> >+ int i;
> >+
> >+ for (i = 0; i < NR_VCPUS; i++)
> >+ do_vcpu_run(vcpus[i]);
> >+}
> >+
> >+static void vcpus_run(struct kvm_vcpu **vcpus, const int NR_VCPUS)
> >+{
> >+ __vcpus_run(vcpus, NR_VCPUS);
> >+ __vcpus_run(vcpus, NR_VCPUS);
>
> ...
>
> >+ for (idx = 0; idx < ARRAY_SIZE(__msrs); idx++) {
> >+ sync_global_to_guest(vm, idx);
> >+
> >+ vcpus_run(vcpus, NR_VCPUS);
> >+ vcpus_run(vcpus, NR_VCPUS);
>
> We enter each vCPU 4 times for each MSR here. If I count correctly, only two of
> them are needed as the guest code syncs with the host twice for each MSR (one in
> guest_test_{un,}supported_msr(), the other at the end of guest_main()).

I'm 99% certain you're correct and that the second run is unnecessary. I suspect
this is leftover crud from an earlier incarnation of the test that used a separate
VM for the "unsupported" features case (before I realized that the test could
abuse and test the fact that KVM doesn't require homogeneous vCPU models).

I'll triple check and post a fixup.

Thanks!