Blame SOURCES/0033-target-i386-sanitize-x86-MSR_PAT-loaded-from-another.patch

383d26
From ebba9a277c36df319d1ec59f25d8b8d596fb8ab4 Mon Sep 17 00:00:00 2001
383d26
From: Wei Huang <wei@redhat.com>
383d26
Date: Wed, 17 Jan 2018 22:13:23 +0100
383d26
Subject: target-i386: sanitize x86 MSR_PAT loaded from another source
383d26
383d26
RH-Author: Wei Huang <wei@redhat.com>
383d26
Message-id: <20180117221323.1008-1-wei@redhat.com>
383d26
Patchwork-id: 78659
383d26
O-Subject: [RHEL-7.5 qemu-kvm-rhev PATCH 1/1] target-i386: sanitize x86 MSR_PAT loaded from another source
383d26
Bugzilla: 1529461
383d26
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
383d26
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
383d26
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
383d26
The RHEL 7 downstream commit a94f33258 honors guest VM's writes of MSR_PAT
383d26
for SVM machines. But this cause a problem when an x86 VM is migrated from
383d26
an old host, such as RHEL 6.9. This is because older system doesn't save
383d26
the guest's PAT field during migration; Instead 0x0 is saved and migrated.
383d26
At the destination, it will use 0x0 as guest PAT because of a94f33258.
383d26
This causes the guest VM's performance to drop significatly.
383d26
383d26
This patch solves the problem by sanitizing the PAT field. If it is zero,
383d26
we use the default MSR_PAT value (0x0007040600070406ULL) to prevent
383d26
performance drop. This solution should work with different types of
383d26
(old or new) VM sources.
383d26
383d26
Signed-off-by: Wei Huang <wei@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
(cherry picked from commit 09fbed03321a5b7a2ecd55ba37bed53db552b0b9)
383d26
(cherry picked from commit e883fc66d38107233b26acc588fb7af9a2afc8a2)
383d26
(cherry picked from commit afd4296db6ae47e5f073a4dd07ea256b660f60de)
383d26
---
383d26
 target/i386/cpu.c     | 2 +-
383d26
 target/i386/cpu.h     | 1 +
383d26
 target/i386/machine.c | 3 +++
383d26
 3 files changed, 5 insertions(+), 1 deletion(-)
383d26
383d26
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
383d26
index a9db495..0fc7fb0 100644
383d26
--- a/target/i386/cpu.c
383d26
+++ b/target/i386/cpu.c
383d26
@@ -3785,7 +3785,7 @@ static void x86_cpu_reset(CPUState *s)
383d26
     /* All units are in INIT state.  */
383d26
     env->xstate_bv = 0;
383d26
 
383d26
-    env->pat = 0x0007040600070406ULL;
383d26
+    env->pat = MSR_PAT_DEFAULT;
383d26
     env->msr_ia32_misc_enable = MSR_IA32_MISC_ENABLE_DEFAULT;
383d26
 
383d26
     memset(env->dr, 0, sizeof(env->dr));
383d26
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
383d26
index 1b219fa..0c7a3d6 100644
383d26
--- a/target/i386/cpu.h
383d26
+++ b/target/i386/cpu.h
383d26
@@ -401,6 +401,7 @@ typedef enum X86Seg {
383d26
 #define MSR_MTRRfix4K_F8000             0x26f
383d26
 
383d26
 #define MSR_PAT                         0x277
383d26
+#define MSR_PAT_DEFAULT                 0x0007040600070406ULL
383d26
 
383d26
 #define MSR_MTRRdefType                 0x2ff
383d26
 
383d26
diff --git a/target/i386/machine.c b/target/i386/machine.c
383d26
index c9a3b5c..f86abe7 100644
383d26
--- a/target/i386/machine.c
383d26
+++ b/target/i386/machine.c
383d26
@@ -277,6 +277,9 @@ static int cpu_post_load(void *opaque, int version_id)
383d26
     env->hflags &= ~HF_CPL_MASK;
383d26
     env->hflags |= (env->segs[R_SS].flags >> DESC_DPL_SHIFT) & HF_CPL_MASK;
383d26
 
383d26
+    if (!(env->pat))
383d26
+        env->pat = MSR_PAT_DEFAULT;
383d26
+
383d26
     env->fpstt = (env->fpus_vmstate >> 11) & 7;
383d26
     env->fpus = env->fpus_vmstate & ~0x3800;
383d26
     env->fptag_vmstate ^= 0xff;
383d26
-- 
383d26
1.8.3.1
383d26