thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
9ae3a8
From 2f6d988d14532616d1f1f476b438b4e3295329f1 Mon Sep 17 00:00:00 2001
9ae3a8
From: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
Date: Fri, 10 Apr 2015 16:45:59 +0200
9ae3a8
Subject: [PATCH 13/14] x86: Clear MTRRs on vCPU reset
9ae3a8
9ae3a8
Message-id: <20150410164559.16166.37319.stgit@gimli.home>
9ae3a8
Patchwork-id: 64799
9ae3a8
O-Subject: [RHEL7.2 qemu-kvm PATCH 3/3] x86: Clear MTRRs on vCPU reset
9ae3a8
Bugzilla: 1210510
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
9ae3a8
Upstream: 9db2efd95e13330075bff027cd682a063d725332
9ae3a8
9ae3a8
The SDM specifies (June 2014 Vol3 11.11.5):
9ae3a8
9ae3a8
    On a hardware reset, the P6 and more recent processors clear the
9ae3a8
    valid flags in variable-range MTRRs and clear the E flag in the
9ae3a8
    IA32_MTRR_DEF_TYPE MSR to disable all MTRRs. All other bits in the
9ae3a8
    MTRRs are undefined.
9ae3a8
9ae3a8
We currently do none of that, so whatever MTRR settings you had prior
9ae3a8
to reset is what you have after reset.  Usually this doesn't matter
9ae3a8
because KVM often ignores the guest mappings and uses write-back
9ae3a8
anyway.  However, if you have an assigned device and an IOMMU that
9ae3a8
allows NoSnoop for that device, KVM defers to the guest memory
9ae3a8
mappings which are now stale after reset.  The result is that OVMF
9ae3a8
rebooting on such a configuration takes a full minute to LZMA
9ae3a8
decompress the firmware volume, a process that is nearly instant on
9ae3a8
the initial boot.
9ae3a8
9ae3a8
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Cc: qemu-stable@nongnu.org
9ae3a8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 target-i386/cpu.c | 10 ++++++++++
9ae3a8
 1 file changed, 10 insertions(+)
9ae3a8
9ae3a8
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
9ae3a8
index 1507530..b76719d 100644
9ae3a8
--- a/target-i386/cpu.c
9ae3a8
+++ b/target-i386/cpu.c
9ae3a8
@@ -2398,6 +2398,16 @@ static void x86_cpu_reset(CPUState *s)
9ae3a8
     cpu_breakpoint_remove_all(env, BP_CPU);
9ae3a8
     cpu_watchpoint_remove_all(env, BP_CPU);
9ae3a8
 
9ae3a8
+    /*
9ae3a8
+     * SDM 11.11.5 requires:
9ae3a8
+     *  - IA32_MTRR_DEF_TYPE MSR.E = 0
9ae3a8
+     *  - IA32_MTRR_PHYSMASKn.V = 0
9ae3a8
+     * All other bits are undefined.  For simplification, zero it all.
9ae3a8
+     */
9ae3a8
+    env->mtrr_deftype = 0;
9ae3a8
+    memset(env->mtrr_var, 0, sizeof(env->mtrr_var));
9ae3a8
+    memset(env->mtrr_fixed, 0, sizeof(env->mtrr_fixed));
9ae3a8
+
9ae3a8
 #if !defined(CONFIG_USER_ONLY)
9ae3a8
     /* We hard-wire the BSP to the first CPU. */
9ae3a8
     if (s->cpu_index == 0) {
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8