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

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