render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 7f9ba4690a2d5353e0b66686ce2569a795e225c4 Mon Sep 17 00:00:00 2001
Message-Id: <7f9ba4690a2d5353e0b66686ce2569a795e225c4.1383922566.git.jdenemar@redhat.com>
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Fri, 8 Nov 2013 12:33:21 +0100
Subject: [PATCH] Ensure 'arch' is always set in cpuArchNodeData

https://bugzilla.redhat.com/show_bug.cgi?id=1008989

The s390, ppc and arm CPU drivers never set the 'arch' field
in their impl of cpuArchNodeData. This leads to error messages
being reported from cpuDataFree later, due to trying to use
VIR_ARCH_NONE.

 #0  virRaiseErrorFull (filename=filename@entry=0x76f94434 "cpu/cpu.c", funcname=funcname@entry=0x76f942dc <__FUNCTION__.18096> "cpuGetSubDriver", linenr=linenr@entry=58,
     domain=domain@entry=31, code=code@entry=1, level=level@entry=VIR_ERR_ERROR, str1=0x76f70e18 "internal error: %s",
     str2=str2@entry=0x7155f2ec "undefined hardware architecture", str3=str3@entry=0x0, int1=int1@entry=-1, int2=int2@entry=-1, fmt=0x76f70e18 "internal error: %s")
     at util/virerror.c:646
 #1  0x76e682ea in virReportErrorHelper (domcode=domcode@entry=31, errorcode=errorcode@entry=1, filename=0x76f94434 "cpu/cpu.c",
     funcname=0x76f942dc <__FUNCTION__.18096> "cpuGetSubDriver", linenr=linenr@entry=58, fmt=0x76f7e7e4 "%s") at util/virerror.c:1292
 #2  0x76ed82d4 in cpuGetSubDriver (arch=<optimized out>) at cpu/cpu.c:57
 #3  cpuGetSubDriver (arch=VIR_ARCH_NONE) at cpu/cpu.c:51
 #4  0x76ed8818 in cpuDataFree (data=data@entry=0x70c22d78) at cpu/cpu.c:216
 #5  0x716aaec0 in virQEMUCapsInitCPU (arch=VIR_ARCH_ARMV7L, caps=0x70c29a08) at qemu/qemu_capabilities.c:867

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 66ec11ade4664c85a158a2c309517baa8b5b048f)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/cpu/cpu.c         |  2 +-
 src/cpu/cpu.h         |  2 +-
 src/cpu/cpu_arm.c     |  8 ++++++--
 src/cpu/cpu_powerpc.c | 12 +++++-------
 src/cpu/cpu_s390.c    |  4 +++-
 src/cpu/cpu_x86.c     |  4 ++--
 6 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 7989b45..2660761 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -244,7 +244,7 @@ cpuNodeData(virArch arch)
         return NULL;
     }
 
-    return driver->nodeData();
+    return driver->nodeData(arch);
 }
 
 
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index ad6ccfb..f016e2f 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -69,7 +69,7 @@ typedef void
 (*cpuArchDataFree)  (virCPUDataPtr data);
 
 typedef virCPUDataPtr
-(*cpuArchNodeData)  (void);
+(*cpuArchNodeData)  (virArch arch);
 
 typedef virCPUCompareResult
 (*cpuArchGuestData) (virCPUDefPtr host,
diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
index 25e25ba..c7dbffc 100644
--- a/src/cpu/cpu_arm.c
+++ b/src/cpu/cpu_arm.c
@@ -31,11 +31,15 @@
 static const virArch archs[] = { VIR_ARCH_ARMV7L };
 
 static virCPUDataPtr
-ArmNodeData(void)
+ArmNodeData(virArch arch)
 {
     virCPUDataPtr data;
 
-    ignore_value(VIR_ALLOC(data));
+    if (VIR_ALLOC(data) < 0)
+        return NULL;
+
+    data->arch = arch;
+
     return data;
 }
 
diff --git a/src/cpu/cpu_powerpc.c b/src/cpu/cpu_powerpc.c
index 55a4153..be07af1 100644
--- a/src/cpu/cpu_powerpc.c
+++ b/src/cpu/cpu_powerpc.c
@@ -350,21 +350,23 @@ ppcDataFree(virCPUDataPtr data)
     VIR_FREE(data);
 }
 
-#if defined(__powerpc__) || defined(__powerpc64__)
 static virCPUDataPtr
-ppcNodeData(void)
+ppcNodeData(virArch arch)
 {
     virCPUDataPtr cpuData;
 
     if (VIR_ALLOC(cpuData) < 0)
         return NULL;
 
+    cpuData->arch = arch;
+
+#if defined(__powerpc__) || defined(__powerpc64__)
     asm("mfpvr %0"
         : "=r" (cpuData->data.ppc.pvr));
+#endif
 
     return cpuData;
 }
-#endif
 
 static int
 ppcUpdate(virCPUDefPtr guest ATTRIBUTE_UNUSED,
@@ -468,11 +470,7 @@ struct cpuArchDriver cpuDriverPowerPC = {
     .decode     = ppcDecode,
     .encode     = NULL,
     .free       = ppcDataFree,
-#if defined(__powerpc__) || defined(__powerpc64__)
     .nodeData   = ppcNodeData,
-#else
-    .nodeData   = NULL,
-#endif
     .guestData  = NULL,
     .baseline   = ppcBaseline,
     .update     = ppcUpdate,
diff --git a/src/cpu/cpu_s390.c b/src/cpu/cpu_s390.c
index cbfae42..e0d3174 100644
--- a/src/cpu/cpu_s390.c
+++ b/src/cpu/cpu_s390.c
@@ -32,13 +32,15 @@
 static const virArch archs[] = { VIR_ARCH_S390, VIR_ARCH_S390X };
 
 static virCPUDataPtr
-s390NodeData(void)
+s390NodeData(virArch arch)
 {
     virCPUDataPtr data;
 
     if (VIR_ALLOC(data) < 0)
         return NULL;
 
+    data->arch = arch;
+
     return data;
 }
 
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 083cfee..e8e1990 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -1731,7 +1731,7 @@ cpuidSet(uint32_t base, virCPUx86CPUID **set)
 
 
 static virCPUDataPtr
-x86NodeData(void)
+x86NodeData(virArch arch)
 {
     virCPUDataPtr cpuData = NULL;
     virCPUx86Data *data;
@@ -1748,7 +1748,7 @@ x86NodeData(void)
         goto error;
     data->extended_len = ret;
 
-    if (!(cpuData = x86MakeCPUData(virArchFromHost(), &data)))
+    if (!(cpuData = x86MakeCPUData(arch, &data)))
         goto error;
 
     return cpuData;
-- 
1.8.4.2