aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/emulate.c
diff options
context:
space:
mode:
authorNadav Amit <namit@cs.technion.ac.il>2014-12-10 04:19:04 -0500
committerPaolo Bonzini <pbonzini@redhat.com>2014-12-10 06:53:37 -0500
commit64a38292ed5f1e9d1bbc15b591cc3b57ce89473f (patch)
treed3be824a5fc8c034cea5aa3e157ebec6efeda7e7 /arch/x86/kvm/emulate.c
parentbc397a6c914c75d8ae21dad23eba9ae82e34dad3 (diff)
KVM: x86: Emulate should check #UD before #GP
Intel SDM table 6-2 ("Priority Among Simultaneous Exceptions and Interrupts") shows that faults from decoding the next instruction got higher priority than general protection. Moving the protected-mode check before the CPL check to avoid wrong exception on vm86 mode. Signed-off-by: Nadav Amit <namit@cs.technion.ac.il> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/emulate.c')
-rw-r--r--arch/x86/kvm/emulate.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index c1e71873e0c7..a8fcec6b7063 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -4801,6 +4801,12 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
4801 goto done; 4801 goto done;
4802 } 4802 }
4803 4803
4804 /* Instruction can only be executed in protected mode */
4805 if ((ctxt->d & Prot) && ctxt->mode < X86EMUL_MODE_PROT16) {
4806 rc = emulate_ud(ctxt);
4807 goto done;
4808 }
4809
4804 /* Privileged instruction can be executed only in CPL=0 */ 4810 /* Privileged instruction can be executed only in CPL=0 */
4805 if ((ctxt->d & Priv) && ops->cpl(ctxt)) { 4811 if ((ctxt->d & Priv) && ops->cpl(ctxt)) {
4806 if (ctxt->d & PrivUD) 4812 if (ctxt->d & PrivUD)
@@ -4810,12 +4816,6 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
4810 goto done; 4816 goto done;
4811 } 4817 }
4812 4818
4813 /* Instruction can only be executed in protected mode */
4814 if ((ctxt->d & Prot) && ctxt->mode < X86EMUL_MODE_PROT16) {
4815 rc = emulate_ud(ctxt);
4816 goto done;
4817 }
4818
4819 /* Do instruction specific permission checks */ 4819 /* Do instruction specific permission checks */
4820 if (ctxt->d & CheckPerm) { 4820 if (ctxt->d & CheckPerm) {
4821 rc = ctxt->check_perm(ctxt); 4821 rc = ctxt->check_perm(ctxt);