9ae3a8
From 2feb6c83f5f22cb4b5060d8224f42d25dcb21fe7 Mon Sep 17 00:00:00 2001
9ae3a8
From: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Date: Fri, 7 Nov 2014 17:17:48 +0100
9ae3a8
Subject: [PATCH 01/41] dump: RHEL-specific fix for CPUState bug introduced by
9ae3a8
 upstream c72bf4682
9ae3a8
MIME-Version: 1.0
9ae3a8
Content-Type: text/plain; charset=UTF-8
9ae3a8
Content-Transfer-Encoding: 8bit
9ae3a8
9ae3a8
Message-id: <1415380693-16593-2-git-send-email-lersek@redhat.com>
9ae3a8
Patchwork-id: 62187
9ae3a8
O-Subject: [RHEL-7.1 qemu-kvm PATCH 01/26] dump: RHEL-specific fix for CPUState bug introduced by upstream c72bf4682
9ae3a8
Bugzilla: 1161563
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
RH-Acked-by: dgibson <dgibson@redhat.com>
9ae3a8
9ae3a8
In qemu-kvm-1.5.3-77.el7, the write_elf64_notes() and write_elf32_notes()
9ae3a8
functions are broken due to upstream commit c72bf4682.
9ae3a8
9ae3a8
    commit c72bf468259935a80ea185f2cbe807c3da9c1bbd
9ae3a8
    Author: Jens Freimann <jfrei@linux.vnet.ibm.com>
9ae3a8
    Date:   Fri Apr 19 16:45:06 2013 +0200
9ae3a8
9ae3a8
        cpu: Move cpu_write_elfXX_note() functions to CPUState
9ae3a8
9ae3a8
        Convert cpu_write_elfXX_note() functions to CPUClass methods and
9ae3a8
        pass CPUState as argument. Update target-i386 accordingly.
9ae3a8
9ae3a8
        Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
9ae3a8
        [AF: Retain stubs as CPUClass' default method implementation;
9ae3a8
         style changes]
9ae3a8
        Signed-off-by: Andreas Färber <afaerber@suse.de>
9ae3a8
9ae3a8
This commit changed the signature of the following functions so that they
9ae3a8
take CPUState rather than CPUArchState:
9ae3a8
- cpu_write_elf64_note()
9ae3a8
- cpu_write_elf64_qemunote()
9ae3a8
- cpu_write_elf32_note()
9ae3a8
- cpu_write_elf32_qemunote()
9ae3a8
9ae3a8
The callers of these functions, write_elf64_notes() and
9ae3a8
write_elf32_notes(), each iterate over CPUArchState objects (starting from
9ae3a8
"first_cpu") *twice*, the first loop calling cpu_write_elfXX_note(), the
9ae3a8
second loop calling cpu_write_elfXX_qemunote(). The loop variable is
9ae3a8
called "env". When calling the above functions after c72bf468, "env" (of
9ae3a8
type CPUArchState) needs to be converted to CPUState, with the
9ae3a8
ENV_GET_CPU() macro.
9ae3a8
9ae3a8
Now, even before c72bf468, the *first* loop in each of both callers used
9ae3a8
to do the conversion already, because cpu_write_elfXX_note() needs a CPU
9ae3a8
index, and that's only reachable via cpu_index(ENV_GET_CPU(env)).
9ae3a8
Therefore the first loop in each caller already set the "cpu" local
9ae3a8
variable correctly, for each "env" in question.
9ae3a8
9ae3a8
However, the *second* loop in each caller had never done that, because
9ae3a8
cpu_write_elfXX_qemunote() had never needed a CPUState for anything.
9ae3a8
9ae3a8
Upstream commit c72bf4682 simply replaced "env" with "cpu" in both loop
9ae3a8
bodies (in both callers). This was correct for the first loops (because
9ae3a8
they already had set "cpu" correctly), but the commit missed to add
9ae3a8
9ae3a8
    cpu = ENV_GET_CPU(env);
9ae3a8
9ae3a8
to the second loops. Hence cpu_write_elfXX_qemunote() is always called
9ae3a8
with the last "cpu" value inherited from the first loop! (Which is why the
9ae3a8
bug is invisible for single-VCPU guests.)
9ae3a8
9ae3a8
Add the missing assignments.
9ae3a8
9ae3a8
For upstream, this was silently fixed in
9ae3a8
9ae3a8
    commit 182735efaf956ccab50b6d74a4fed163e0f35660
9ae3a8
    Author: Andreas Färber <afaerber@suse.de>
9ae3a8
    Date:   Wed May 29 22:29:20 2013 +0200
9ae3a8
9ae3a8
        cpu: Make first_cpu and next_cpu CPUState
9ae3a8
9ae3a8
        Move next_cpu from CPU_COMMON to CPUState.
9ae3a8
        Move first_cpu variable to qom/cpu.h.
9ae3a8
9ae3a8
        gdbstub needs to use CPUState::env_ptr for now.
9ae3a8
        cpu_copy() no longer needs to save and restore cpu_next.
9ae3a8
9ae3a8
        Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
        [AF: Rebased, simplified cpu_copy()]
9ae3a8
        Signed-off-by: Andreas Färber <afaerber@suse.de>
9ae3a8
9ae3a8
because it obviated and eliminated the
9ae3a8
9ae3a8
    cpu = ENV_GET_CPU(env);
9ae3a8
9ae3a8
conversions completely. The bug-introducing commit c72bf4682 had been
9ae3a8
released in v1.5.0 (and it persisted even into 1.5.3, which is why we have
9ae3a8
it in RHEL). The silent / unintended fix (182735ef) is part of v1.6.0 (and
9ae3a8
we never backported that commit to RHEL-7.0).
9ae3a8
9ae3a8
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 dump.c | 2 ++
9ae3a8
 1 file changed, 2 insertions(+)
9ae3a8
9ae3a8
diff --git a/dump.c b/dump.c
9ae3a8
index b203a8d..a2b6e45 100644
9ae3a8
--- a/dump.c
9ae3a8
+++ b/dump.c
9ae3a8
@@ -289,6 +289,7 @@ static int write_elf64_notes(DumpState *s)
9ae3a8
     }
9ae3a8
 
9ae3a8
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
9ae3a8
+        cpu = ENV_GET_CPU(env);
9ae3a8
         ret = cpu_write_elf64_qemunote(fd_write_vmcore, cpu, s);
9ae3a8
         if (ret < 0) {
9ae3a8
             dump_error(s, "dump: failed to write CPU status.\n");
9ae3a8
@@ -341,6 +342,7 @@ static int write_elf32_notes(DumpState *s)
9ae3a8
     }
9ae3a8
 
9ae3a8
     for (env = first_cpu; env != NULL; env = env->next_cpu) {
9ae3a8
+        cpu = ENV_GET_CPU(env);
9ae3a8
         ret = cpu_write_elf32_qemunote(fd_write_vmcore, cpu, s);
9ae3a8
         if (ret < 0) {
9ae3a8
             dump_error(s, "dump: failed to write CPU status.\n");
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8