Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH 1/2] KVM: nSVM: Restore L1's debug registers on nested VM-Exit
@ 2026-08-27  5:35 Hao Zhang
  2026-08-27  5:38 ` [PATCH 2/2] selftests: kvm: Add regression test for nSVM debug register state Hao Zhang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Hao Zhang @ 2026-08-27  5:35 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: Paolo Bonzini, kvm

From: Hao Zhang <zhanghao1@kylinos.cn>

Restore L1's DR6 and DR7 when emulating a nested VM-Exit from L2 to L1.
KVM loads L2's debug register state from vmcb12 on nested VMRUN, but
currently restores DR7 to its reset value and leaves DR6 untouched when
switching back to vmcb01.  As a result, L1 can observe stale L2 DR6 state
and lose its DR7 state after an L2 VM-Exit.

Restore both registers from vmcb01, matching the rest of the L1 processor
state restored on nested VM-Exit.

Fixes: 4995a3685f1b ("KVM: SVM: Use a separate vmcb for the nested L2 guest")
Signed-off-by: Hao Zhang <zhanghao1@kylinos.cn>
---
 arch/x86/kvm/svm/nested.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 73f37b050d0a..e7975ac7bfca 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1427,7 +1427,8 @@ void nested_svm_vmexit(struct vcpu_svm *svm)
 	kvm_rsp_write(vcpu, vmcb01->save.rsp);
 	kvm_rip_write(vcpu, vmcb01->save.rip);
 
-	svm->vcpu.arch.dr7 = DR7_FIXED_1;
+	svm->vcpu.arch.dr6 = vmcb01->save.dr6;
+	svm->vcpu.arch.dr7 = vmcb01->save.dr7;
 	kvm_update_dr7(&svm->vcpu);
 
 	nested_svm_transition_tlb_flush(vcpu);

base-commit: 45c13f3f9e3bb15fd89ff2864c6f627a3b4b4229
-- 
2.15.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-28  1:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-27  5:35 [PATCH 1/2] KVM: nSVM: Restore L1's debug registers on nested VM-Exit Hao Zhang
2026-08-27  5:38 ` [PATCH 2/2] selftests: kvm: Add regression test for nSVM debug register state Hao Zhang
2026-08-27  5:52 ` [PATCH 1/2] KVM: nSVM: Restore L1's debug registers on nested VM-Exit sashiko-bot
2026-08-27 13:43 ` Sean Christopherson
2026-08-28  1:11   ` Hao Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox