From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Roman Kagan <rkagan@virtuozzo.com>
Cc: "Daniel P . Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Marcelo Tosatti" <mtosatti@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Richard Henderson" <rth@twiddle.net>
Subject: Re: [Qemu-devel] [PATCH v2 2/9] i386/kvm: add support for KVM_GET_SUPPORTED_HV_CPUID
Date: Fri, 31 May 2019 11:22:57 +0200 [thread overview]
Message-ID: <87a7f3kmfi.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <20190530175511.GA13965@rkaganb.sw.ru>
Roman Kagan <rkagan@virtuozzo.com> writes:
> On Mon, May 27, 2019 at 06:39:53PM +0200, Vitaly Kuznetsov wrote:
>> Roman Kagan <rkagan@virtuozzo.com> writes:
>> > On Fri, May 17, 2019 at 04:19:17PM +0200, Vitaly Kuznetsov wrote:
>> >> +static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max)
>> >> +{
>> >> + struct kvm_cpuid2 *cpuid;
>> >> + int r, size;
>> >> +
>> >> + size = sizeof(*cpuid) + max * sizeof(*cpuid->entries);
>> >> + cpuid = g_malloc0(size);
>> >> + cpuid->nent = max;
>> >> +
>> >> + r = kvm_vcpu_ioctl(cs, KVM_GET_SUPPORTED_HV_CPUID, cpuid);
>> >> + if (r == 0 && cpuid->nent >= max) {
>> >> + r = -E2BIG;
>> >> + }
>> >> + if (r < 0) {
>> >> + if (r == -E2BIG) {
>> >> + g_free(cpuid);
>> >> + return NULL;
>> >> + } else {
>> >> + fprintf(stderr, "KVM_GET_SUPPORTED_HV_CPUID failed: %s\n",
>> >> + strerror(-r));
>> >> + exit(1);
>> >> + }
>> >> + }
>> >> + return cpuid;
>> >> +}
>> >> +
>> >> +/*
>> >> + * Run KVM_GET_SUPPORTED_HV_CPUID ioctl(), allocating a buffer large enough
>> >> + * for all entries.
>> >> + */
>> >> +static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUState *cs)
>> >> +{
>> >> + struct kvm_cpuid2 *cpuid;
>> >> + int max = 7; /* 0x40000000..0x40000005, 0x4000000A */
>> >> +
>> >> + /*
>> >> + * When the buffer is too small, KVM_GET_SUPPORTED_HV_CPUID fails with
>> >> + * -E2BIG, however, it doesn't report back the right size. Keep increasing
>> >> + * it and re-trying until we succeed.
>> >> + */
>> >
>> > I'm still missing the idea of reiterating more than once: the ioctl
>> > returns the actual size of the array.
>>
>> Hm, I think I checked that and it doesn't seem to be the case.
>>
>> The code in kvm_vcpu_ioctl_get_hv_cpuid():
>>
>> if (cpuid->nent < nent)
>> return -E2BIG;
>>
>> if (cpuid->nent > nent)
>> cpuid->nent = nent;
>>
>> (I think I even ran a test after your comment on v1 and it it
>> confirmed nent is not set on E2BIG). Am I missing something obvious?
>
> Indeed, I saw kvm_vcpu_ioctl_get_cpuid2() always setting ->nent on
> return and assumed so did kvm_vcpu_ioctl_get_hv_cpuid(). I stand
> corrected, please disregard this comment.
No problem at all!
> (What was the reason for not following this pattern in
> kvm_vcpu_ioctl_get_hv_cpuid BTW?)
The opportunity to set nent in E2BIG case was probabbly overlooked. I
was looking at QEMU's get_supported_cpuid() implementation which
iterates trying to find the right number and used this as a pattern.
While setting nent in E2BIG case seems to be very convenient, this is an
unobvious side-effect: usually, where the return value indicates an
error we don't inspect the payload. I'm, however, not at all against
changing kvm_vcpu_ioctl_get_hv_cpuid(). Unfortunately, this won't help
QEMU and we'll still have to iterate to support legacy kernels.
--
Vitaly
next prev parent reply other threads:[~2019-05-31 9:24 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-17 14:19 [Qemu-devel] [PATCH v2 0/9] i386/kvm/hyper-v: refactor and implement 'hv-stimer-direct' and 'hv-passthrough' enlightenments Vitaly Kuznetsov
2019-05-17 14:19 ` [Qemu-devel] [PATCH v2 1/9] i386/kvm: convert hyperv enlightenments properties from bools to bits Vitaly Kuznetsov
2019-05-27 15:46 ` Roman Kagan
2019-05-17 14:19 ` [Qemu-devel] [PATCH v2 2/9] i386/kvm: add support for KVM_GET_SUPPORTED_HV_CPUID Vitaly Kuznetsov
2019-05-27 15:52 ` Roman Kagan
2019-05-27 16:39 ` Vitaly Kuznetsov
2019-05-30 17:55 ` Roman Kagan
2019-05-31 9:22 ` Vitaly Kuznetsov [this message]
2019-05-17 14:19 ` [Qemu-devel] [PATCH v2 3/9] i386/kvm: move Hyper-V CPUID filling to hyperv_handle_properties() Vitaly Kuznetsov
2019-05-17 14:19 ` [Qemu-devel] [PATCH v2 4/9] i386/kvm: document existing Hyper-V enlightenments Vitaly Kuznetsov
2019-05-17 14:19 ` [Qemu-devel] [PATCH v2 5/9] i386/kvm: implement 'hv-passthrough' mode Vitaly Kuznetsov
2019-05-17 14:19 ` [Qemu-devel] [PATCH v2 6/9] i386/kvm: hv-stimer requires hv-time and hv-synic Vitaly Kuznetsov
2019-05-17 14:19 ` [Qemu-devel] [PATCH v2 7/9] i386/kvm: hv-tlbflush/ipi require hv-vpindex Vitaly Kuznetsov
2019-05-17 14:19 ` [Qemu-devel] [PATCH v2 8/9] i386/kvm: hv-evmcs requires hv-vapic Vitaly Kuznetsov
2019-05-17 14:19 ` [Qemu-devel] [PATCH v2 9/9] i386/kvm: add support for Direct Mode for Hyper-V synthetic timers Vitaly Kuznetsov
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=87a7f3kmfi.fsf@vitty.brq.redhat.com \
--to=vkuznets@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=ehabkost@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rkagan@virtuozzo.com \
--cc=rth@twiddle.net \
/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).