From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org
Cc: Sean Christopherson <seanjc@google.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>,
Igor Mammedov <imammedo@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/4] KVM: x86: Partially allow KVM_SET_CPUID{,2} after KVM_RUN
Date: Tue, 18 Jan 2022 09:40:53 +0100 [thread overview]
Message-ID: <87pmopl9m2.fsf@redhat.com> (raw)
In-Reply-To: <c427371c-474e-1233-4e57-66210bfc5687@redhat.com>
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 1/17/22 16:05, Vitaly Kuznetsov wrote:
>>
>> +/* Check whether the supplied CPUID data is equal to what is already set for the vCPU. */
>> +static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2,
>> + int nent)
>> +{
>> + struct kvm_cpuid_entry2 *best;
>> + int i;
>> +
>> + for (i = 0; i < nent; i++) {
>> + best = kvm_find_cpuid_entry(vcpu, e2[i].function, e2[i].index);
>> + if (!best)
>> + return -EINVAL;
>> +
>> + if (e2[i].eax != best->eax || e2[i].ebx != best->ebx ||
>> + e2[i].ecx != best->ecx || e2[i].edx != best->edx)
>> + return -EINVAL;
>> + }
>> +
>> + return 0;
>> +}
>
> What about this alternative implementation:
>
> /* Check whether the supplied CPUID data is equal to what is already set for the vCPU. */
> static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2,
> int nent)
> {
> struct kvm_cpuid_entry2 *orig;
> int i;
>
> if (nent != vcpu->arch.cpuid_nent)
> return -EINVAL;
>
> for (i = 0; i < nent; i++) {
> orig = &vcpu->arch.cpuid_entries[i];
> if (e2[i].function != orig->function ||
> e2[i].index != orig->index ||
> e2[i].eax != orig->eax || e2[i].ebx != orig->ebx ||
> e2[i].ecx != orig->ecx || e2[i].edx != orig->edx)
> return -EINVAL;
> }
>
> return 0;
> }
>
> avoiding the repeated calls to kvm_find_cpuid_entry?
>
My version is a bit more permissive as it allows supplying CPUID entries
in any order, not necessarily matching the original. I *guess* this
doesn't matter much for the QEMU problem we're trying to workaround,
I'll have to check.
--
Vitaly
next prev parent reply other threads:[~2022-01-18 8:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-17 15:05 [PATCH v2 0/4] KVM: x86: Partially allow KVM_SET_CPUID{,2} after KVM_RUN for CPU hotplug Vitaly Kuznetsov
2022-01-17 15:05 ` [PATCH v2 1/4] KVM: x86: Do runtime CPUID update before updating vcpu->arch.cpuid_entries Vitaly Kuznetsov
2022-01-17 15:05 ` [PATCH v2 2/4] KVM: x86: Partially allow KVM_SET_CPUID{,2} after KVM_RUN Vitaly Kuznetsov
2022-01-17 17:30 ` Paolo Bonzini
2022-01-18 8:40 ` Vitaly Kuznetsov [this message]
2022-01-18 14:37 ` Vitaly Kuznetsov
2022-01-17 15:05 ` [PATCH v2 3/4] KVM: selftests: Rename 'get_cpuid_test' to 'cpuid_test' Vitaly Kuznetsov
2022-01-17 15:05 ` [PATCH v2 4/4] KVM: selftests: Test KVM_SET_CPUID2 after KVM_RUN Vitaly Kuznetsov
2022-01-18 14:35 ` [PATCH v2 0/4] KVM: x86: Partially allow KVM_SET_CPUID{,2} after KVM_RUN for CPU hotplug Igor Mammedov
2022-01-18 16:17 ` Paolo Bonzini
2022-01-18 16:53 ` Sean Christopherson
2022-01-18 17:12 ` Paolo Bonzini
2022-01-18 16:34 ` Vitaly Kuznetsov
2022-01-19 7:59 ` Igor Mammedov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pmopl9m2.fsf@redhat.com \
--to=vkuznets@redhat.com \
--cc=imammedo@redhat.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=wanpengli@tencent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).