]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.44/kvm-x86-add-align16-instruction-flag.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.44 / kvm-x86-add-align16-instruction-flag.patch
1 From d3fe959f81024072068e9ed86b39c2acfd7462a9 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= <rkrcmar@redhat.com>
3 Date: Tue, 8 Nov 2016 20:54:16 +0100
4 Subject: KVM: x86: add Align16 instruction flag
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 From: Radim Krčmář <rkrcmar@redhat.com>
10
11 commit d3fe959f81024072068e9ed86b39c2acfd7462a9 upstream.
12
13 Needed for FXSAVE and FXRSTOR.
14
15 Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
16 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
18
19 ---
20 arch/x86/kvm/emulate.c | 20 ++++++++++++--------
21 1 file changed, 12 insertions(+), 8 deletions(-)
22
23 --- a/arch/x86/kvm/emulate.c
24 +++ b/arch/x86/kvm/emulate.c
25 @@ -172,6 +172,7 @@
26 #define NearBranch ((u64)1 << 52) /* Near branches */
27 #define No16 ((u64)1 << 53) /* No 16 bit operand */
28 #define IncSP ((u64)1 << 54) /* SP is incremented before ModRM calc */
29 +#define Aligned16 ((u64)1 << 55) /* Aligned to 16 byte boundary (e.g. FXSAVE) */
30
31 #define DstXacc (DstAccLo | SrcAccHi | SrcWrite)
32
33 @@ -620,21 +621,24 @@ static void set_segment_selector(struct
34 * depending on whether they're AVX encoded or not.
35 *
36 * Also included is CMPXCHG16B which is not a vector instruction, yet it is
37 - * subject to the same check.
38 + * subject to the same check. FXSAVE and FXRSTOR are checked here too as their
39 + * 512 bytes of data must be aligned to a 16 byte boundary.
40 */
41 -static bool insn_aligned(struct x86_emulate_ctxt *ctxt, unsigned size)
42 +static unsigned insn_alignment(struct x86_emulate_ctxt *ctxt, unsigned size)
43 {
44 if (likely(size < 16))
45 - return false;
46 + return 1;
47
48 if (ctxt->d & Aligned)
49 - return true;
50 + return size;
51 else if (ctxt->d & Unaligned)
52 - return false;
53 + return 1;
54 else if (ctxt->d & Avx)
55 - return false;
56 + return 1;
57 + else if (ctxt->d & Aligned16)
58 + return 16;
59 else
60 - return true;
61 + return size;
62 }
63
64 static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
65 @@ -692,7 +696,7 @@ static __always_inline int __linearize(s
66 }
67 break;
68 }
69 - if (insn_aligned(ctxt, size) && ((la & (size - 1)) != 0))
70 + if (la & (insn_alignment(ctxt, size) - 1))
71 return emulate_gp(ctxt, 0);
72 return X86EMUL_CONTINUE;
73 bad: