Patchwork [qom-cpu,01/10] target-i386: Simplify reporting of unavailable features

login
register
mail settings
Submitter Eduardo Habkost
Date Feb. 28, 2014, 8:21 p.m.
Message ID <1393618913-12411-2-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/325334/
State New
Headers show

Comments

Eduardo Habkost - Feb. 28, 2014, 8:21 p.m.
Instead of checking and calling unavailable_host_feature() once for each
bit, simply call the function (now renamed to
report_unavailable_features()) once for each feature word.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 target-i386/cpu.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 9ff1062..d62be53 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1172,11 +1172,11 @@  static void kvm_cpu_fill_host(X86CPUDefinition *x86_cpu_def)
     }
 }
 
-static int unavailable_host_feature(FeatureWordInfo *f, uint32_t mask)
+static int report_unavailable_features(FeatureWordInfo *f, uint32_t mask)
 {
     int i;
 
-    for (i = 0; i < 32; ++i)
+    for (i = 0; i < 32; ++i) {
         if (1 << i & mask) {
             const char *reg = get_register_name_32(f->cpuid_reg);
             assert(reg);
@@ -1185,8 +1185,8 @@  static int unavailable_host_feature(FeatureWordInfo *f, uint32_t mask)
                 f->cpuid_eax, reg,
                 f->feat_names[i] ? "." : "",
                 f->feat_names[i] ? f->feat_names[i] : "", i);
-            break;
         }
+    }
     return 0;
 }
 
@@ -1210,12 +1210,10 @@  static int kvm_check_features_against_host(KVMState *s, X86CPU *cpu)
         uint32_t host_feat = kvm_arch_get_supported_cpuid(s, wi->cpuid_eax,
                                                              wi->cpuid_ecx,
                                                              wi->cpuid_reg);
-        uint32_t mask;
-        for (mask = 1; mask; mask <<= 1) {
-            if (guest_feat & mask && !(host_feat & mask)) {
-                unavailable_host_feature(wi, mask);
-                rv = 1;
-            }
+        uint32_t unavailable_features = guest_feat & ~host_feat;
+        if (unavailable_features) {
+            report_unavailable_features(wi, unavailable_features);
+            rv = 1;
         }
     }
     return rv;