From: Paolo Bonzini <pbonzini@redhat.com>
To: Sean Christopherson <seanjc@google.com>,
Valeriy Vdovin <valeriy.vdovin@virtuozzo.com>
Cc: linux-kernel@vger.kernel.org, Denis Lunev <den@openvz.org>,
Jonathan Corbet <corbet@lwn.net>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Shuah Khan <shuah@kernel.org>,
Aaron Lewis <aaronlewis@google.com>,
Alexander Graf <graf@amazon.com>,
Andrew Jones <drjones@redhat.com>,
Oliver Upton <oupton@google.com>,
Like Xu <like.xu@linux.intel.com>,
kvm@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v4] KVM: x86: Fix KVM_GET_CPUID2 ioctl to return cpuid entries count
Date: Mon, 3 May 2021 16:54:26 +0200 [thread overview]
Message-ID: <0d68dbc3-8462-7763-fbad-f3b895fcf6e6@redhat.com> (raw)
In-Reply-To: <YIoFFl72VSeuhCRt@google.com>
On 29/04/21 03:00, Sean Christopherson wrote:
> On Wed, Apr 28, 2021, Valeriy Vdovin wrote:
>> It's very explicit by the code that it was designed to receive some
>> small number of entries to return E2BIG along with the corrected number.
>
> LOL, saying KVM_GET_CPUID2 was "designed" is definitely giving the KVM
> forefathers the benefit of the doubt.
I was going to make a different joke, i.e. that KVM_GET_CPUID2 was
indeed designed the way Valeriy described, but that design was forgotten
soon after.
Really, this ioctl has been such a trainwreck that I think the only good
solution here is to drop it.
Paolo
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index efc7a82ab140..3f941b1f4e78 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -4773,14 +4773,17 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
>> r = -EFAULT;
>> if (copy_from_user(&cpuid, cpuid_arg, sizeof(cpuid)))
>> goto out;
>> +
>> r = kvm_vcpu_ioctl_get_cpuid2(vcpu, &cpuid,
>> cpuid_arg->entries);
>> - if (r)
>> +
>> + if (r && r != -E2BIG)
>> goto out;
>> - r = -EFAULT;
>> - if (copy_to_user(cpuid_arg, &cpuid, sizeof(cpuid)))
>> +
>> + if (copy_to_user(cpuid_arg, &cpuid, sizeof(cpuid))) {
>> + r = -EFAULT;
>> goto out;
>
> As I pointed out[*], copying the number of entries but not the entries themselves
> is wrong. All of my feedback on v1 still stands.
>
> [*] https://lkml.kernel.org/r/YIl4M/GgaYvwNuXv@google.com
>
>> - r = 0;
>> + }
>> break;
>> }
>> case KVM_GET_MSRS: {
>
next prev parent reply other threads:[~2021-05-03 14:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-28 17:27 [PATCH v4] KVM: x86: Fix KVM_GET_CPUID2 ioctl to return cpuid entries count Valeriy Vdovin
2021-04-29 1:00 ` Sean Christopherson
2021-05-03 14:54 ` Paolo Bonzini [this message]
2021-05-03 19:18 ` Denis V. Lunev
2021-05-04 7:23 ` Paolo Bonzini
2021-05-04 8:15 ` Denis V. Lunev
2021-05-04 8:21 ` Paolo Bonzini
2021-05-04 9:26 ` Alexander Graf
2021-05-04 9:50 ` Paolo Bonzini
2021-05-04 16:52 ` Jim Mattson
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=0d68dbc3-8462-7763-fbad-f3b895fcf6e6@redhat.com \
--to=pbonzini@redhat.com \
--cc=aaronlewis@google.com \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=den@openvz.org \
--cc=drjones@redhat.com \
--cc=graf@amazon.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=like.xu@linux.intel.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=oupton@google.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=valeriy.vdovin@virtuozzo.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.