DragonFlyBSD Kernel Audit
DF-1315 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c b/sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
--- a/sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
+++ b/sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c
@@ -1489,6 +1489,9 @@
 
 	x86_curthread_save_dbregs(cpudata->hstate.drs);
 
+	/* AMD SVM has no host-save-area for debug registers: save the
+	 * host DR7 unconditionally so it can be restored on #VMEXIT. */
+	cpudata->hstate.drs[NVMM_X64_DR_DR7] = x86_get_dr7();
 	x86_set_dr7(0);
 
 	x86_set_dr0(cpudata->drs[NVMM_X64_DR_DR0]);
@@ -1508,6 +1511,10 @@
 	cpudata->drs[NVMM_X64_DR_DR3] = x86_get_dr3();
 
 	x86_curthread_restore_dbregs(cpudata->hstate.drs);
+
+	/* Unconditionally restore host DR7: SVM does not swap it on
+	 * #VMEXIT, otherwise a guest-armed data breakpoint persists. */
+	x86_set_dr7(cpudata->hstate.drs[NVMM_X64_DR_DR7]);
 }
 
 static void