Skip to content

Commit 8ea7d6a

Browse files
joergroedelavikivity
authored andcommitted
KVM: x86 emulator: Add flag to check for protected mode instructions
This patch adds a flag for the opcoded to tag instruction which are only recognized in protected mode. The necessary check is added too. Signed-off-by: Joerg Roedel <[email protected]> Signed-off-by: Avi Kivity <[email protected]>
1 parent d09beab commit 8ea7d6a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

arch/x86/include/asm/kvm_emulate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ struct x86_emulate_ctxt {
274274
#define X86EMUL_MODE_PROT32 4 /* 32-bit protected mode. */
275275
#define X86EMUL_MODE_PROT64 8 /* 64-bit (long) mode. */
276276

277+
/* any protected mode */
278+
#define X86EMUL_MODE_PROT (X86EMUL_MODE_PROT16|X86EMUL_MODE_PROT32| \
279+
X86EMUL_MODE_PROT64)
280+
277281
enum x86_intercept_stage {
278282
X86_ICPT_PRE_EXCEPT,
279283
X86_ICPT_POST_EXCEPT,

arch/x86/kvm/emulate.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#define Prefix (1<<16) /* Instruction varies with 66/f2/f3 prefix */
7979
#define Sse (1<<17) /* SSE Vector instruction */
8080
/* Misc flags */
81+
#define Prot (1<<21) /* instruction generates #UD if not in prot-mode */
8182
#define VendorSpecific (1<<22) /* Vendor specific instruction */
8283
#define NoAccess (1<<23) /* Don't access memory (lea/invlpg/verr etc) */
8384
#define Op3264 (1<<24) /* Operand is 64b in long mode, 32b otherwise */
@@ -3143,6 +3144,12 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
31433144
goto done;
31443145
}
31453146

3147+
/* Instruction can only be executed in protected mode */
3148+
if ((c->d & Prot) && !(ctxt->mode & X86EMUL_MODE_PROT)) {
3149+
rc = emulate_ud(ctxt);
3150+
goto done;
3151+
}
3152+
31463153
/* Do instruction specific permission checks */
31473154
if (c->check_perm) {
31483155
rc = c->check_perm(ctxt);

0 commit comments

Comments
 (0)