]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit - sys/amd64/vmm/amd/svm.c
Clear the upper 32-bits of registers in x86_emulate_cpuid().
authorJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Oct 2020 16:45:11 +0000 (16:45 +0000)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Oct 2020 16:45:11 +0000 (16:45 +0000)
commita3f2a9c57eb78f68bc6bba7b0f8f0f35bea3c93b
tree2a6e26da2abaaca185e2f5c1f88ff898896fb63d
parentc9d175ea908f26e19afd4e1168c61f4f2a54c998
Clear the upper 32-bits of registers in x86_emulate_cpuid().

Per the Intel manuals, CPUID is supposed to unconditionally zero the
upper 32 bits of the involved (rax/rbx/rcx/rdx) registers.
Previously, the emulation would cast pointers to the 64-bit register
values down to `uint32_t`, which while properly manipulating the lower
bits, would leave any garbage in the upper bits uncleared.  While no
existing guest OSes seem to stumble over this in practice, the bhyve
emulation should match x86 expectations.

This was discovered through alignment warnings emitted by gcc9, while
testing it against SmartOS/bhyve.

SmartOS bug: https://smartos.org/bugview/OS-8168
Submitted by: Patrick Mooney
Reviewed by: rgrimes
Differential Revision: https://reviews.freebsd.org/D24727
sys/amd64/vmm/amd/svm.c
sys/amd64/vmm/intel/vmx.c
sys/amd64/vmm/x86.c
sys/amd64/vmm/x86.h