KVM: X86: eliminate some meaningless code
Quoted 11 lines · Sean Christopherson
Quoted 8 lines · linmiaohe
From: Miaohe Lin <[email protected]>
When
kvm_vcpu_ioctl_get_cpuid2()fails, we setcpuid->nentto the value ofvcpu->arch.cpuid_nent. But this is in vain ascpuid->nentis notvcpu->copiedto
userspace bycopy_to_user()from call site. Get rid of this meaningless assignment and further cleanup the var r and out jump label.Ha, took me a while to see that.
Sorry about it. I'am not good at it. :(
Quoted 12 lines
Review
Quoted 5 lines
On the other hand, when
kvm_vcpu_ioctl_get_cpuid2()succeeds, we do(quoted diff) +0
-2vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2))) - goto out; - return 0;Hmm, so this
ioctl()is straight up broken.cpuid->nentshould be updated on success so that userspace knows how many entries were retrieved, i.e. the code should look something like below, withkvm_arch_vcpu_ioctl()unchanged.I'm guessing no VMM actually uses this
ioctl(), e.g. neither Qemu or CrosVM use it, which is why the broken behavior has gone unnoticed. Don't suppose you'd want to write a selftest to hammer KVM_{SET,GET}_CPUID2?int kvm_vcpu_ioctl_get_cpuid2(struct
kvm_vcpu*vcpu,
Quoted 14 lines
struct kvm_cpuid2 *cpuid,
struct kvm_cpuid_entry2 __user *entries) {
if (cpuid->nent < vcpu->arch.cpuid_nent)
return -E2BIG;
if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
return -EFAULT;
cpuid->nent = vcpu->arch.cpuid_nent;
return 0;
}I searched KVM_GET_CPUID2 from Qemu, it's not used. So maybe we could just drop KVM_GET_CPUID2 altogether as suggested by Paolo. Thanks for your review.