From 1f077338d1cd57fd3c2d6dfe193be58cd1d04fee Mon Sep 17 00:00:00 2001 From: Sean Christopherson Date: Fri, 12 Jun 2026 16:01:11 -0700 Subject: [PATCH] KVM: x86: Use kvm_dr{6,7}_valid() to check DR{4,5,6,7} write values in emulator Use kvm_dr{6,7}_valid() to validate the incoming DR{4,5,6,7} value in the emulator instead of open coding an equivalent check. In the unlikely event that the behavior of DR6/7 (and their aliases) changes in the future, using common helpers will hopefully make it less likely the emulator logic will be overlooked. No functional change intended. Reviewed-by: Jim Mattson Link: https://patch.msgid.link/20260612230113.684301-7-seanjc@google.com Signed-off-by: Sean Christopherson --- arch/x86/kvm/emulate.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index b4dc57fe0bc9..b1799ed01939 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -3869,10 +3869,13 @@ static int check_dr_write(struct x86_emulate_ctxt *ctxt) switch (ctxt->modrm_reg) { case 4: - case 5: case 6: + if (!kvm_dr6_valid(new_val)) + return emulate_gp(ctxt, 0); + break; + case 5: case 7: - if (new_val & 0xffffffff00000000ULL) + if (!kvm_dr7_valid(new_val)) return emulate_gp(ctxt, 0); break; default: