Skip to content

Commit ab322c4

Browse files
committed
KVM: x86: Update number of entries for KVM_GET_CPUID2 on success, not failure
Update cpuid->nent if and only if kvm_vcpu_ioctl_get_cpuid2() succeeds. The sole caller copies @CpuID to userspace only on success, i.e. the existing code effectively does nothing. Arguably, KVM should report the number of entries when returning -E2BIG so that userspace doesn't have to guess the size, but all other similar KVM ioctls() don't report the size either, i.e. userspace is conditioned to guess. Suggested-by: Takahiro Itazuri <itazur@amazon.com> Link: https://lore.kernel.org/all/20230410141820.57328-1-itazur@amazon.com Link: https://lore.kernel.org/r/20230526210340.2799158-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 0d42522 commit ab322c4

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

arch/x86/kvm/cpuid.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -501,20 +501,15 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
501501
struct kvm_cpuid2 *cpuid,
502502
struct kvm_cpuid_entry2 __user *entries)
503503
{
504-
int r;
505-
506-
r = -E2BIG;
507504
if (cpuid->nent < vcpu->arch.cpuid_nent)
508-
goto out;
509-
r = -EFAULT;
505+
return -E2BIG;
506+
510507
if (copy_to_user(entries, vcpu->arch.cpuid_entries,
511508
vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
512-
goto out;
513-
return 0;
509+
return -EFAULT;
514510

515-
out:
516511
cpuid->nent = vcpu->arch.cpuid_nent;
517-
return r;
512+
return 0;
518513
}
519514

520515
/* Mask kvm_cpu_caps for @leaf with the raw CPUID capabilities of this CPU. */

0 commit comments

Comments
 (0)