KVM Basic Principles and Architecture II - Basic Principles

  

KVM: Kernel-based Virtual Machine is an open source virtualization solution based on the Linux kernel. It has been incorporated into the kernel main branch maintenance since version 2.6.20. Initially only supported on CPUs supporting VMX or SVM on the X86 platform, it was later confirmed as a virtualization solution for the standard Linux kernel and gradually supported architectures such as S390, IA64 and PowerPC; KVM itself only provided partial virtualization functions (virtual CPU) And memory), with the help of the specially modified Qemu (Qemu-kvm) to provide complete platform virtualization capabilities.
KVM relies on the virtualization features of x86 hardware to provide a fully virtualized virtual machine. The basic idea is to add a virtual machine management module based on the Linux kernel and reuse the well-established and mature mechanisms and modules in the Linux kernel. For example, process scheduling, memory management, IO management, etc., make it a hypervisor that can support running virtual machines. Overall architecture as shown below:



KVM is hardware assisted virtualization technology (such as Intel VT-x) full virtualization solution, as shown above, described As follows:
ü VMM (ie KVM kernel) runs Ring0 in root mode;
ü User state process on host runs Ring3 in root mode;
ü Kernel in virtual machine Ring0 running in non-root mode;
ü User state process in virtual machine running Ring3 in non-root mode;
ü Qemu-kvm is an improved Qemu provided and maintained by KVM. For the KVM solution, the standard Qemu has been specifically modified to have better performance and is perfectly integrated with KVM;
ü A VM (virtual machine) is a traditional Linux process. The VM runs in the address space of the Qemu-KVM process;
ü VMM provides the /dev/kvm interface to the upper layer, /dev/kvm is a standard character device controlled by the ioctl interface; Qemu-kvm calls /dev The ioctl interface of the /kvm device controls the virtual machine, such as creating a virtual machine and creating a V. CPU, running virtual machines, etc.;
ü To improve IO performance in KVM virtual machines, KVM also provides Virtio drivers, which are equivalent to paravirtualized drivers in Xen environments.

2.2 KVM Runs view
KVM run substantially as shown below:

Process Description:
1, run through an ioctl system call Qemu-kvm user state operation /Dev/kvm character device, create VM and VCPU
2. Kernel KVM module is responsible for the creation of the relevant data structure, ie initialization, and then return to the user state
3. Qemu-kvm runs the VCPU through the ioctl call, ie the corresponding VM is scheduled. After running
4, the kernel performs related processing, executes the VMLAUNCH instruction, enters the Guest OS through VM-Entry, and the Guest OS runs in non-root mode.
5, Guest OS executes the corresponding virtual machine code, non-sensitive instructions can run directly on the physical CPU
6, when the Guest OS executes sensitive instructions, an external interrupt occurs, or the Guest OS has an internal exception. VM-Exit will be generated, and related information will be recorded in the VMCS structure.
7. VM-Exit will cause the CPU to return to the root mode. The VMM reads the VMCS structure to determine the cause of VM-Exit.
8. Operation or other peripheral instructions return to the user mode Qemu-kvm (ie Ring3 in root mode), and Qemu-kvm completes the simulation of the relevant instructions.
9, if not, then the VMM handles itself
10, after the processing is completed, the VM-entry is re-entered into the Guest OS.

2.3 KVM Kernel Module Composition
KVM is mainly composed of 3 kernel modules:
ü Kvm.ko
ü Kvm-intel.ko
ü Kvm-amd. Ko

Kvm.ko is the core public module of KVM, and kvm-intel.ko and kvm-amd.ko are separate modules for Intel and AMD platform architectures respectively. In the KVM core common module, it contains some code such as IOMMU, interrupt control, KVM arch, device management, etc. These codes constitute the core functions of virtual machine management. From the general information of these modules, it can be seen that KVM itself is not implemented. Virtualization of a complete PC system, but only to achieve some of the core CPU virtualization, memory virtualization and IO virtualization and other functions and provide the corresponding API to the upper layer, the rest of the virtualization and management work is mainly handed over to Qemu -kvm is responsible.



Copyright © Windows knowledge All Rights Reserved