Re: [PATCH] kvm: x86: Update KVM_GET_CPUID2 to return valid entry count

From: Takahiro Itazuri
Date: Mon Apr 10 2023 - 14:39:16 EST


Date: Mon, 10 Apr 2023 08:47:05 -0700
From: Sean Christopherson <seanjc@xxxxxxxxxx>
> Capitalize KVM please, i.e. "KVM: x86:".

Will fix. Thanks!

> I think we should break from the (IMO) somewhat funky KVM ioctl() pattern of
>
> r = <errno>
> if (try something and it fails)
> goto out;
>
> and instead set "r" in the error paths. That avoids the need for a scratch "nent",
> and IMO makes this much more straightforward.
>
> int r = 0;
>
> if (cpuid->nent < vcpu->arch.cpuid_nent)
> r = -E2BIG;
> else if (copy_to_user(entries, vcpu->arch.cpuid_entries,
> vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
> r = -EFAULT;
>
> /*
> * Update "nent" even on failure, e.g. so that userspace can fix an
> * -E2BIG issue by allocating a larger array.
> */
> cpuid->nent = vcpu->arch.cpuid_nent;
> return r;

Looks better to me! Will fix this too!.

Best regards,
Takahiro Itazuri