git: e52e4f8a71f9 - main - vmm: Avoid redundant Intel DEBUGCTL writes
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 17 Nov 2026 21:32:12 UTC
The branch main has been updated by hayzam:
URL: https://cgit.FreeBSD.org/src/commit/?id=e52e4f8a71f9d0c80be0d0adb687437667723185
commit e52e4f8a71f9d0c80be0d0adb687437667723185
Author: Hayzam Sherif <hayzam@FreeBSD.org>
AuthorDate: 2026-11-17 20:58:09 +0000
Commit: Hayzam Sherif <hayzam@FreeBSD.org>
CommitDate: 2026-11-17 21:29:49 +0000
vmm: Avoid redundant Intel DEBUGCTL writes
Skip clearing and restoring IA32_DEBUGCTL when the saved host value
is zero.
VM exit clears the register. If VM entry fails, the entry path has
already cleared any nonzero host value, so restoring zero is also
unnecessary in that case. Preserve the existing writes for nonzero
host state.
Avoiding these writes can also avoid intercepted MSR accesses when
bhyve runs under another hypervisor.
Reviewed by: markj, bnovkov
Approved by: markj (mentor)
Sponsored by: Alchemilla Ventures Private Limited
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D61219
---
sys/amd64/vmm/intel/vmx.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/sys/amd64/vmm/intel/vmx.c b/sys/amd64/vmm/intel/vmx.c
index 0b9a4eea3ebb..4ad17861a437 100644
--- a/sys/amd64/vmm/intel/vmx.c
+++ b/sys/amd64/vmm/intel/vmx.c
@@ -2959,7 +2959,8 @@ vmx_dr_enter_guest(struct vmxctx *vmxctx)
* guest DR7 and DEBUGCTL are saved/restored in the VMCS.
*/
load_dr7(0);
- wrmsr(MSR_DEBUGCTLMSR, 0);
+ if (vmxctx->host_debugctl != 0)
+ wrmsr(MSR_DEBUGCTLMSR, 0);
/*
* Disable single stepping the kernel to avoid corrupting the
@@ -3006,7 +3007,9 @@ vmx_dr_leave_guest(struct vmxctx *vmxctx)
load_dr2(vmxctx->host_dr2);
load_dr3(vmxctx->host_dr3);
load_dr6(vmxctx->host_dr6);
- wrmsr(MSR_DEBUGCTLMSR, vmxctx->host_debugctl);
+ /* VM-exit clears DEBUGCTL; a failed entry also leaves it cleared. */
+ if (vmxctx->host_debugctl != 0)
+ wrmsr(MSR_DEBUGCTLMSR, vmxctx->host_debugctl);
load_dr7(vmxctx->host_dr7);
write_rflags(read_rflags() | vmxctx->host_tf);
}