Skip to content

Commit 68efa76

Browse files
anadavbonzini
authored andcommitted
KVM: x86: Emulator support for #UD on CPL>0
Certain instructions (e.g., mwait and monitor) cause a #UD exception when they are executed in user mode. This is in contrast to the regular privileged instructions which cause #GP. In order not to mess with SVM interception of mwait and monitor which assumes privilege level assertions take place before interception, a flag has been added. Signed-off-by: Nadav Amit <namit@cs.technion.ac.il> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 10e38fc commit 68efa76

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎arch/x86/kvm/emulate.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
#define Intercept ((u64)1 << 48) /* Has valid intercept field */
166166
#define CheckPerm ((u64)1 << 49) /* Has valid check_perm field */
167167
#define NoBigReal ((u64)1 << 50) /* No big real mode */
168+
#define PrivUD ((u64)1 << 51) /* #UD instead of #GP on CPL > 0 */
168169

169170
#define DstXacc (DstAccLo | SrcAccHi | SrcWrite)
170171

@@ -4608,7 +4609,10 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt)
46084609

46094610
/* Privileged instruction can be executed only in CPL=0 */
46104611
if ((ctxt->d & Priv) && ops->cpl(ctxt)) {
4611-
rc = emulate_gp(ctxt, 0);
4612+
if (ctxt->d & PrivUD)
4613+
rc = emulate_ud(ctxt);
4614+
else
4615+
rc = emulate_gp(ctxt, 0);
46124616
goto done;
46134617
}
46144618

0 commit comments

Comments
 (0)