freebsd-nq/sys/amd64/vmm/amd
John Baldwin 65eefbe422 Save and restore guest debug registers.
Currently most of the debug registers are not saved and restored
during VM transitions allowing guest and host debug register values to
leak into the opposite context.  One result is that hardware
watchpoints do not work reliably within a guest under VT-x.

Due to differences in SVM and VT-x, slightly different approaches are
used.

For VT-x:

- Enable debug register save/restore for VM entry/exit in the VMCS for
  DR7 and MSR_DEBUGCTL.
- Explicitly save DR0-3,6 of the guest.
- Explicitly save DR0-3,6-7, MSR_DEBUGCTL, and the trap flag from
  %rflags for the host.  Note that because DR6 is "software" managed
  and not stored in the VMCS a kernel debugger which single steps
  through VM entry could corrupt the guest DR6 (since a single step
  trap taken after loading the guest DR6 could alter the DR6
  register).  To avoid this, explicitly disable single-stepping via
  the trace flag before loading the guest DR6.  A determined debugger
  could still defeat this by setting a breakpoint after the guest DR6
  was loaded and then single-stepping.

For SVM:
- Enable debug register caching in the VMCB for DR6/DR7.
- Explicitly save DR0-3 of the guest.
- Explicitly save DR0-3,6-7, and MSR_DEBUGCTL for the host.  Since SVM
  saves the guest DR6 in the VMCB, the race with single-stepping
  described for VT-x does not exist.

For both platforms, expose all of the guest DRx values via --get-drX
and --set-drX flags to bhyvectl.

Discussed with:	avg, grehan
Tested by:	avg (SVM), myself (VT-x)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D13229
2018-01-17 23:11:25 +00:00
..
amdv.c sys/amd64: further adoption of SPDX licensing ID tags. 2017-11-27 15:03:07 +00:00
amdvi_hw.c amd-vi: set iommu msi configuration using pci_enable_msi method 2017-12-04 17:10:52 +00:00
amdvi_priv.h amd-vi: fix up r326152, the new width requires a wider type 2017-11-24 11:25:06 +00:00
ivrs_drv.c vmm/amd: add ivhd device with a higher order 2017-12-04 17:08:03 +00:00
npt.c As <machine/pmap.h> is included from <vm/pmap.h>, there is no need to 2016-02-22 09:02:20 +00:00
npt.h
svm_genassym.c
svm_msr.c Allow guest writes to AMD microcode update[0xc0010020] MSR without updating actual hardware MSR. This allows guest microcode update to go through which otherwise failing because wrmsr() was returning EINVAL. 2016-04-11 05:09:43 +00:00
svm_msr.h
svm_softc.h vmm/svm: contigmalloc of the whole svm_softc is excessive 2018-01-09 14:22:18 +00:00
svm_support.S Provide some mitigation against CVE-2017-5715 by clearing registers 2018-01-15 18:37:03 +00:00
svm.c Save and restore guest debug registers. 2018-01-17 23:11:25 +00:00
svm.h Save and restore guest debug registers. 2018-01-17 23:11:25 +00:00
vmcb.c Save and restore guest debug registers. 2018-01-17 23:11:25 +00:00
vmcb.h Fix a couple of comments in AMD Virtual Machine Control Block structure 2018-01-05 19:15:24 +00:00