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

Chao Gao
2025-09-15T08:23:13Z

>+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()).