yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From 2f85f6c61990fd4d46e4980128ee8ba2d3cfaa37 Mon Sep 17 00:00:00 2001
9ae3a8
From: Vadim Rozenfeld <vrozenfe@redhat.com>
9ae3a8
Date: Mon, 3 Mar 2014 12:09:14 +0100
9ae3a8
Subject: [PATCH 02/12] kvm: Fix uninitialized cpuid_data
9ae3a8
9ae3a8
RH-Author: Vadim Rozenfeld <vrozenfe@redhat.com>
9ae3a8
Message-id: <1393848564-10511-3-git-send-email-vrozenfe@redhat.com>
9ae3a8
Patchwork-id: 57958
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm v4 PATCH 02/12] kvm: Fix uninitialized cpuid_data
9ae3a8
Bugzilla: 1057173
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
9ae3a8
RH-Acked-by: Juan Quintela <quintela@redhat.com>
9ae3a8
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
9ae3a8
9ae3a8
From: Stefan Weil <sw@weilnetz.de>
9ae3a8
9ae3a8
This error was reported by valgrind when running qemu-system-x86_64
9ae3a8
with kvm:
9ae3a8
9ae3a8
==975== Conditional jump or move depends on uninitialised value(s)
9ae3a8
==975==    at 0x521C38: cpuid_find_entry (kvm.c:176)
9ae3a8
==975==    by 0x5235BA: kvm_arch_init_vcpu (kvm.c:686)
9ae3a8
==975==    by 0x4D5175: kvm_init_vcpu (kvm-all.c:267)
9ae3a8
==975==    by 0x45035B: qemu_kvm_cpu_thread_fn (cpus.c:858)
9ae3a8
==975==    by 0xD361E0D: start_thread (pthread_create.c:311)
9ae3a8
==975==    by 0xD65E9EC: clone (clone.S:113)
9ae3a8
==975==  Uninitialised value was created by a stack allocation
9ae3a8
==975==    at 0x5226E4: kvm_arch_init_vcpu (kvm.c:446)
9ae3a8
9ae3a8
Instead of adding more memset calls for parts of cpuid_data, the existing
9ae3a8
calls were removed and cpuid_data is now initialized completely in one
9ae3a8
call.
9ae3a8
9ae3a8
Signed-off-by: Stefan Weil <sw@weilnetz.de>
9ae3a8
Signed-off-by: Gleb Natapov <gleb@redhat.com>
9ae3a8
(cherry picked from commit ef4cbe14342c1f63b3c754e306218f004f4e26c4)
9ae3a8
---
9ae3a8
 target-i386/kvm.c | 9 ++-------
9ae3a8
 1 file changed, 2 insertions(+), 7 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 target-i386/kvm.c |    9 ++-------
9ae3a8
 1 files changed, 2 insertions(+), 7 deletions(-)
9ae3a8
9ae3a8
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
9ae3a8
index c7fabd7..3a9e376 100644
9ae3a8
--- a/target-i386/kvm.c
9ae3a8
+++ b/target-i386/kvm.c
9ae3a8
@@ -453,11 +453,12 @@ int kvm_arch_init_vcpu(CPUState *cs)
9ae3a8
     uint32_t signature[3];
9ae3a8
     int r;
9ae3a8
 
9ae3a8
+    memset(&cpuid_data, 0, sizeof(cpuid_data));
9ae3a8
+
9ae3a8
     cpuid_i = 0;
9ae3a8
 
9ae3a8
     /* Paravirtualization CPUIDs */
9ae3a8
     c = &cpuid_data.entries[cpuid_i++];
9ae3a8
-    memset(c, 0, sizeof(*c));
9ae3a8
     c->function = KVM_CPUID_SIGNATURE;
9ae3a8
     if (!hyperv_enabled(cpu)) {
9ae3a8
         memcpy(signature, "KVMKVMKVM\0\0\0", 12);
9ae3a8
@@ -471,7 +472,6 @@ int kvm_arch_init_vcpu(CPUState *cs)
9ae3a8
     c->edx = signature[2];
9ae3a8
 
9ae3a8
     c = &cpuid_data.entries[cpuid_i++];
9ae3a8
-    memset(c, 0, sizeof(*c));
9ae3a8
     c->function = KVM_CPUID_FEATURES;
9ae3a8
     c->eax = env->features[FEAT_KVM];
9ae3a8
 
9ae3a8
@@ -480,13 +480,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
9ae3a8
         c->eax = signature[0];
9ae3a8
 
9ae3a8
         c = &cpuid_data.entries[cpuid_i++];
9ae3a8
-        memset(c, 0, sizeof(*c));
9ae3a8
         c->function = HYPERV_CPUID_VERSION;
9ae3a8
         c->eax = 0x00001bbc;
9ae3a8
         c->ebx = 0x00060001;
9ae3a8
 
9ae3a8
         c = &cpuid_data.entries[cpuid_i++];
9ae3a8
-        memset(c, 0, sizeof(*c));
9ae3a8
         c->function = HYPERV_CPUID_FEATURES;
9ae3a8
         if (cpu->hyperv_relaxed_timing) {
9ae3a8
             c->eax |= HV_X64_MSR_HYPERCALL_AVAILABLE;
9ae3a8
@@ -497,7 +495,6 @@ int kvm_arch_init_vcpu(CPUState *cs)
9ae3a8
         }
9ae3a8
 
9ae3a8
         c = &cpuid_data.entries[cpuid_i++];
9ae3a8
-        memset(c, 0, sizeof(*c));
9ae3a8
         c->function = HYPERV_CPUID_ENLIGHTMENT_INFO;
9ae3a8
         if (cpu->hyperv_relaxed_timing) {
9ae3a8
             c->eax |= HV_X64_RELAXED_TIMING_RECOMMENDED;
9ae3a8
@@ -508,13 +505,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
9ae3a8
         c->ebx = cpu->hyperv_spinlock_attempts;
9ae3a8
 
9ae3a8
         c = &cpuid_data.entries[cpuid_i++];
9ae3a8
-        memset(c, 0, sizeof(*c));
9ae3a8
         c->function = HYPERV_CPUID_IMPLEMENT_LIMITS;
9ae3a8
         c->eax = 0x40;
9ae3a8
         c->ebx = 0x40;
9ae3a8
 
9ae3a8
         c = &cpuid_data.entries[cpuid_i++];
9ae3a8
-        memset(c, 0, sizeof(*c));
9ae3a8
         c->function = KVM_CPUID_SIGNATURE_NEXT;
9ae3a8
         memcpy(signature, "KVMKVMKVM\0\0\0", 12);
9ae3a8
         c->eax = 0;
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8