Instruction caching for bhyve
by Mihai Carabas for FreeBSD
The Virtual Machine Monitor (VMM) must emulate all guest accesses to APIC control registers which requires VM exits and VM entries. In order to emulate, one needs to fetch and decode the instruction which are very expensive operations. Instead of doing this at each VMexit, one can cache the instruction. However when using the cached instruction from a particular instruction pointer, you must guarantee that the guest won't modify that instruction in memory.