From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WPdUM-00056f-4r for qemu-devel@nongnu.org; Mon, 17 Mar 2014 15:46:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WPdUG-0005ZJ-LZ for qemu-devel@nongnu.org; Mon, 17 Mar 2014 15:46:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41838) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WPdUG-0005Z4-0d for qemu-devel@nongnu.org; Mon, 17 Mar 2014 15:46:16 -0400 From: Eduardo Habkost Date: Mon, 17 Mar 2014 16:45:01 -0300 Message-Id: <1395085507-5544-5-git-send-email-ehabkost@redhat.com> In-Reply-To: <1395085507-5544-1-git-send-email-ehabkost@redhat.com> References: <1395085507-5544-1-git-send-email-ehabkost@redhat.com> Subject: [Qemu-devel] [PATCH qom-cpu v2 04/10] target-i386: Isolate KVM-specific code on CPU feature filtering logic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, =?UTF-8?q?Andreas=20F=C3=A4rber?= Cc: Igor Mammedov , Paolo Bonzini , Aurelien Jarno , Richard Henderson This will allow us to re-use the feature filtering logic (and the check/enforce flag logic) for TCG. Signed-off-by: Eduardo Habkost Reviewed-by: Richard Henderson --- target-i386/cpu.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 5b8e0de..4229e4d 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1807,26 +1807,29 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) return cpu_list; } +static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w) +{ + FeatureWordInfo *wi = &feature_word_info[w]; + assert(kvm_enabled()); + return kvm_arch_get_supported_cpuid(kvm_state, wi->cpuid_eax, + wi->cpuid_ecx, + wi->cpuid_reg); +} + /* Filters CPU feature words based on host availability of each feature * * Returns 0 if all flags are supported by the host, non-zero otherwise. * * This function may be called only if KVM is enabled. */ -static int filter_features_for_kvm(X86CPU *cpu) +static int x86_cpu_filter_features(X86CPU *cpu) { CPUX86State *env = &cpu->env; - KVMState *s = kvm_state; FeatureWord w; int rv = 0; - assert(kvm_enabled()); - for (w = 0; w < FEATURE_WORDS; w++) { - FeatureWordInfo *wi = &feature_word_info[w]; - uint32_t host_feat = kvm_arch_get_supported_cpuid(s, wi->cpuid_eax, - wi->cpuid_ecx, - wi->cpuid_reg); + uint32_t host_feat = x86_cpu_get_supported_feature_word(w); uint32_t requested_features = env->features[w]; env->features[w] &= host_feat; cpu->filtered_features[w] = requested_features & ~env->features[w]; @@ -2586,7 +2589,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) env->features[FEAT_8000_0001_ECX] &= TCG_EXT3_FEATURES; env->features[FEAT_SVM] &= TCG_SVM_FEATURES; } else { - if (filter_features_for_kvm(cpu) && cpu->enforce_cpuid) { + if (x86_cpu_filter_features(cpu) && cpu->enforce_cpuid) { error_setg(&local_err, "Host's CPU doesn't support requested features"); goto out; -- 1.8.5.3