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

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