KVM architecture and principles
1. KVM Architecture
The basic structure of kvm consists of two parts:
The kvm driver is now a linux kernel module. It is mainly responsible for creating virtual machines, allocating virtual memory, reading and writing VCPU registers, and running VCPU.
Another component is Qemu, which is used to simulate the user space components of virtual machines and provide I/O device models to access peripherals.
Figure 1 Basic kvm Structure
The basic structure of kvm is as follows. Kvm is a kernel module and is regarded as a standard linux Character Set device (/dev/kvm ). Qemu uses the libkvm application interface and fd to send the creation to the device driver through ioctl and run VM commands. The device-driven kvm will parse the command (the kvm_dev_ioctl function is in the kvm_main.c file), for example:
Figure 2 kvm_dev_ioctl Function
The kvm module makes the Linux host a virtual machine Monitor (VMM), and adds the customer mode based on the original two Linux execution modes. The customer mode has its own kernel mode and user mode. When running a virtual machine, the following three modes work:
Customer mode: Execute non-I/O customer code, and the virtual machine runs in this mode.
User Mode: indicates that the user executes the I/O command, and qemu runs in this mode.
Kernel Mode: implements the switching of the customer mode to process the exit from the customer mode (VM_EXIT) caused by I/O or other commands ). The kvm module works in this mode.
In the kvm model, each Gust OS is a standard linux Process and can be managed using the linux Process Management command.
Here, if qemu sends the KVM_CREATE_VM command through ioctl and creates a VM, qemu needs to send some commands to the VM, such as KVM_CREATE_VCPU. These commands are also sent through ioctl. the user program uses ioctl to send KVM_CREATE_VM and the returned value is the fd (kvm_vm) corresponding to the newly created VM ), fd is the file descriptor created to point to a specific Virtual Machine instance, and then uses this fd to send commands to the VM for access control. The function used by kvm to parse these commands is kvm_vm_ioctl.
2. How KVM works
Kvm basic working principle Overview:
User-mode qemu uses libkvm to enter the kernel mode through ioctl. The kvm module does not create virtual memory, and the virtual CPU then executes the VMLAUCH command to enter the customer mode. Load and execute Guest OS. If the Guest OS is interrupted externally or the shadow page table is missing, the execution of the Guest OS will be suspended, the customer mode will be exited for exception handling, and then the customer mode will be re-entered to execute the customer code. If an I/O event occurs or a signal arrives in the signal queue, it enters user mode for processing. (For example)
Figure 3 KVM working principle Flowchart
-------------------------------------- Split line --------------------------------------
RHEL6 KVM virtualization creates a bridge NIC-Bridge
RedHat Linux KVM Virtual Machine bridging
Installation/bridging settings of KVM in CentOS 5.6/virtual machine creation and operation
The/bin/qemu-KVM problem cannot be found when the kvm virtual machine is installed with libvirt In Ubuntu.
Install and configure the KVM Virtual Machine in RedHat6.5
-------------------------------------- Split line --------------------------------------
This article permanently updates the link address: