From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eduardo Habkost Subject: [PATCH 06/15] i386: kvm: extract try_get_cpuid() loop to get_supported_cpuid() function Date: Thu, 4 Oct 2012 17:48:58 -0300 Message-ID: <1349383747-19383-7-git-send-email-ehabkost@redhat.com> References: <1349383747-19383-1-git-send-email-ehabkost@redhat.com> Cc: kvm@vger.kernel.org, Igor Mammedov , Avi Kivity , Gleb Natapov , Marcelo Tosatti , =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:7255 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757270Ab2JDUsP (ORCPT ); Thu, 4 Oct 2012 16:48:15 -0400 In-Reply-To: <1349383747-19383-1-git-send-email-ehabkost@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: No behavior change, just code movement. Signed-off-by: Eduardo Habkost --- target-i386/kvm.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 3519028..7115921 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -98,6 +98,19 @@ static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max) return cpuid; } +/* Run KVM_GET_SUPPORTED_CPUID ioctl(), allocating a buffer large enough + * for all entries. + */ +static struct kvm_cpuid2 *get_supported_cpuid(KVMState *s) +{ + struct kvm_cpuid2 *cpuid; + int max = 1; + while ((cpuid = try_get_cpuid(s, max)) == NULL) { + max *= 2; + } + return cpuid; +} + struct kvm_para_features { int cap; int feature; @@ -166,15 +179,11 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, uint32_t index, int reg) { struct kvm_cpuid2 *cpuid; - int max; uint32_t ret = 0; uint32_t cpuid_1_edx; bool found = false; - max = 1; - while ((cpuid = try_get_cpuid(s, max)) == NULL) { - max *= 2; - } + cpuid = get_supported_cpuid(s); struct kvm_cpuid_entry2 *entry = cpuid_find_entry(cpuid, function, index); if (entry) { -- 1.7.11.4