[PATCH v2 6/6] KVM: x86: Read CR4.DE in emulator if and only if accessing DR4 or DR5
From: Sean Christopherson
Date: Wed Jun 03 2026 - 19:13:47 EST
Micro-optimize emulation of MOV DR instructions by checking CR4.DE if and
only if DR4 or DR5 is being accessed.
No functional change intended.
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/kvm/emulate.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 9d345ad25ac0..37f3cee4358b 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -3839,13 +3839,11 @@ static int check_cr_access(struct x86_emulate_ctxt *ctxt)
static int check_dr_read(struct x86_emulate_ctxt *ctxt)
{
int dr = ctxt->modrm_reg;
- u64 cr4;
if (dr > 7)
return emulate_ud(ctxt);
- cr4 = ctxt->ops->get_cr(ctxt, 4);
- if ((cr4 & X86_CR4_DE) && (dr == 4 || dr == 5))
+ if ((dr == 4 || dr == 5) && (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_DE))
return emulate_ud(ctxt);
if (ctxt->ops->get_effective_dr7(ctxt) & DR7_GD)
--
2.54.0.1032.g2f8565e1d1-goog