How Does the CPU Virtualization Work?

There may be multitasking which allows one operating system and many programs run in a parallel. There may also be HyperThreading which imitates two CPUs in one physical CPU but these CPUs must be used together. Now, there is also the CPU virtualization. This technology allows one CPU to act as if there are many CPUs running in parallel. This allows the system to work on many operating systems at the same time. This is closely related to multitasking and HyperThreading but obviously, the virtualization is a more advanced technology.

CPU virtualization can only be done on processors with virtualization capability. This technology also has its set of extra instructions which is known as the Virtual Machine Extensions or the VMX. This provides 10 specific instructions to the CPU for virtualization. These are the VMPTRLD, VMCLEAR, VMPTRST, VMWRITE, VMREAD, VMLAUCH, VMCALL, VMXON, VMXOFF, and VMRESUME.

Aside from these instructions, CPU virtualization also has two models to be used when running. One is the root operation and the other is the non-root operation. Under the root operation, it is usually the virtualization controlling software that runs over it. Meanwhile, for the non-root operation, it is the virtual machine that runs over it. The operating system as well as software, called as “guest software,” can run on top of the virtual machine.

The VMXON instruction should be executed in order to enter the CPU virtualization mode. This will call the VMX software which will enter all the virtual machines through the VMLAUNCH instruction. Exiting these virtual machines can be done with the VMRESUME instruction. But if the VMX needs to shut down or exit the virtualization mode, it will have to call the VMXOFF instruction. That easy and the CPU virtualization can work efficiently.