]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Fix a long standing bug in VMXCTX_GUEST_RESTORE().
authorneel <neel@FreeBSD.org>
Fri, 20 May 2011 03:23:09 +0000 (03:23 +0000)
committerneel <neel@FreeBSD.org>
Fri, 20 May 2011 03:23:09 +0000 (03:23 +0000)
commit3930d0afcfdc805e3c97fcc29a2c1ffbd8b31c7c
tree773425d0412679af964bac480ea9592e3a78da5f
parente24f5ed9f2b1a7f169a57fcc109ed55bd5ef8954
Fix a long standing bug in VMXCTX_GUEST_RESTORE().

There was an assumption by the "callers" of this macro that on "return" the
%rsp will be pointing to the 'vmxctx'. The macro was not doing this and thus
when trying to restore host state on an error from "vmlaunch" or "vmresume"
we were treating the memory locations on the host stack as 'struct vmxctx'.
This led to all sorts of weird bugs like double faults or invalid instruction
faults.

This bug is exposed by the -O2 option used to compile the kernel module. With
the -O2 flag the compiler will optimize the following piece of code:

int loopstart = 1;
...
if (loopstart) {
loopstart = 0;
vmx_launch();
} else
vmx_resume();

into this:

vmx_launch();

Since vmx_launch() and vmx_resume() are declared to be __dead2 functions the
compiler is free to do this. The compiler has no way to know that the
functions return indirectly through vmx_setjmp(). This optimization in turn
leads us to trigger the bug in VMXCTX_GUEST_RESTORE().

With this change we can boot a 8.1 guest on a 9.0 host.

Reported by: jhb@
sys/amd64/vmm/intel/vmx.c
sys/amd64/vmm/intel/vmx.h
sys/amd64/vmm/intel/vmx_genassym.c
sys/amd64/vmm/intel/vmx_support.S