From: Joerg Roedel Date: Mon, 4 Apr 2011 10:39:26 +0000 (+0200) Subject: KVM: x86 emulator: Add flag to check for protected mode instructions X-Git-Tag: MMI-PSA29.97-13-9~19664^2~104 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8ea7d6aef84e278fcb121acff1bd4c3edaa95b8b;p=GitHub%2FMotorolaMobilityLLC%2Fkernel-slsi.git 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 Signed-off-by: Avi Kivity --- diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h index 460c2d8964b7..cab841a034f9 100644 --- a/arch/x86/include/asm/kvm_emulate.h +++ b/arch/x86/include/asm/kvm_emulate.h @@ -274,6 +274,10 @@ struct x86_emulate_ctxt { #define X86EMUL_MODE_PROT32 4 /* 32-bit protected mode. */ #define X86EMUL_MODE_PROT64 8 /* 64-bit (long) mode. */ +/* any protected mode */ +#define X86EMUL_MODE_PROT (X86EMUL_MODE_PROT16|X86EMUL_MODE_PROT32| \ + X86EMUL_MODE_PROT64) + enum x86_intercept_stage { X86_ICPT_PRE_EXCEPT, X86_ICPT_POST_EXCEPT, diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 4822824b608b..3f32a6699fbd 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -78,6 +78,7 @@ #define Prefix (1<<16) /* Instruction varies with 66/f2/f3 prefix */ #define Sse (1<<17) /* SSE Vector instruction */ /* Misc flags */ +#define Prot (1<<21) /* instruction generates #UD if not in prot-mode */ #define VendorSpecific (1<<22) /* Vendor specific instruction */ #define NoAccess (1<<23) /* Don't access memory (lea/invlpg/verr etc) */ #define Op3264 (1<<24) /* Operand is 64b in long mode, 32b otherwise */ @@ -3143,6 +3144,12 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt) goto done; } + /* Instruction can only be executed in protected mode */ + if ((c->d & Prot) && !(ctxt->mode & X86EMUL_MODE_PROT)) { + rc = emulate_ud(ctxt); + goto done; + } + /* Do instruction specific permission checks */ if (c->check_perm) { rc = c->check_perm(ctxt);