yeahuh / rpms / qemu-kvm

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