When emulating a MOV DR, specifically a write to DR6 or DR7, treat a #DB due to DR7.GD (General Detect) as higher priority than a #GP due to an illegal value. While neither Intel's SDM nor AMD's APM says anything about the relative priority, empirical testing on Intel and AMD shows that the #DB has higher priority. And for VMX, where the instruction intercept has priority over *all* exceptions, KVM already treats the #DB as having higher priority. Cc: Maciej W. Rozycki Fixes: 3b88e41a4134 ("KVM: SVM: Add intercept check for accessing dr registers") Signed-off-by: Sean Christopherson --- arch/x86/kvm/emulate.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 75cd8b6136aa..4484c5fa19e3 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -3854,11 +3854,16 @@ static int check_dr_write(struct x86_emulate_ctxt *ctxt) { u64 new_val = ctxt->src.val64; int dr = ctxt->modrm_reg; + int rc; + + rc = check_dr_read(ctxt); + if (rc != X86EMUL_CONTINUE) + return rc; if ((dr == 6 || dr == 7) && (new_val & 0xffffffff00000000ULL)) return emulate_gp(ctxt, 0); - return check_dr_read(ctxt); + return X86EMUL_CONTINUE; } static int check_svme(struct x86_emulate_ctxt *ctxt) -- 2.54.0.1136.gdb2ca164c4-goog