Skip to content

Commit d3fe959

Browse files
committed
KVM: x86: add Align16 instruction flag
Needed for FXSAVE and FXRSTOR. Signed-off-by: Radim Krčmář <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 6951519 commit d3fe959

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

arch/x86/kvm/emulate.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
#define NearBranch ((u64)1 << 52) /* Near branches */
172172
#define No16 ((u64)1 << 53) /* No 16 bit operand */
173173
#define IncSP ((u64)1 << 54) /* SP is incremented before ModRM calc */
174+
#define Aligned16 ((u64)1 << 55) /* Aligned to 16 byte boundary (e.g. FXSAVE) */
174175

175176
#define DstXacc (DstAccLo | SrcAccHi | SrcWrite)
176177

@@ -632,21 +633,24 @@ static void set_segment_selector(struct x86_emulate_ctxt *ctxt, u16 selector,
632633
* depending on whether they're AVX encoded or not.
633634
*
634635
* Also included is CMPXCHG16B which is not a vector instruction, yet it is
635-
* subject to the same check.
636+
* subject to the same check. FXSAVE and FXRSTOR are checked here too as their
637+
* 512 bytes of data must be aligned to a 16 byte boundary.
636638
*/
637-
static bool insn_aligned(struct x86_emulate_ctxt *ctxt, unsigned size)
639+
static unsigned insn_alignment(struct x86_emulate_ctxt *ctxt, unsigned size)
638640
{
639641
if (likely(size < 16))
640-
return false;
642+
return 1;
641643

642644
if (ctxt->d & Aligned)
643-
return true;
645+
return size;
644646
else if (ctxt->d & Unaligned)
645-
return false;
647+
return 1;
646648
else if (ctxt->d & Avx)
647-
return false;
649+
return 1;
650+
else if (ctxt->d & Aligned16)
651+
return 16;
648652
else
649-
return true;
653+
return size;
650654
}
651655

652656
static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
@@ -704,7 +708,7 @@ static __always_inline int __linearize(struct x86_emulate_ctxt *ctxt,
704708
}
705709
break;
706710
}
707-
if (insn_aligned(ctxt, size) && ((la & (size - 1)) != 0))
711+
if (la & (insn_alignment(ctxt, size) - 1))
708712
return emulate_gp(ctxt, 0);
709713
return X86EMUL_CONTINUE;
710714
bad:

0 commit comments

Comments
 (0)