Sunday, December 21, 2014

CPU Virtualization Deep Drive

Understand CPU Virtualization:

At this time most modern CPU architectures support different levels of privilege, called rings. Ring 0 has the highest privilege; processes running in this ring are referred to as running in supervisor or kernel mode. Processes running in higher rings are referred to as running in user mode. The higher the number of the ring, the less privilege a process running in this ring has. An x86-based CPU supports four levels of privilege, but in practice only rings 0 and 3 are used. In Linux and Windows, the operating system kernel and hardware drivers run in Ring 0, and user processes run in Ring 3. Only processes in Ring 0 can access hardware. If a process in a higher ring needs to access hardware, such as the hard disk, it has to use the APIs of the kernel.

Here is the demonstration of CPU Rings with Native Operating System:

When we will use Xen, the Xen Hypervisor runs in Ring 0, and the operating system kernel is moved to Ring 1. This is the reason why the operating system has to be modified to run para-virtualized—the kernel has to “know” that it is running in Ring 1 instead of Ring 0. 

Here is the demonstration of CPU Rings with Xen Hypervisor:
When we will have "VT-enabled hardware" allows the Hypervisor to emulate a Ring 0 for the operating system kernel, allowing it to run unmodified:

Here is the damonstration of CPU Rings and VT-Enabled Hardware:


That is done about CPU Virtualization: