The KVM structure contains information such as Vcpus, memory, and Apic,irq,mmu,event event management. The information in this structure is primarily used inside a KVM virtual machine to track the state of a virtual machine.
For a KVM, it corresponds to a thread.
KVM takes full advantage of hardware virtualization technology to view information via Cat/proc/cpuinfo, and if it is an Intel processor, load Kvm-intel.ko
The user state creates a virtual machine that is set up and managed by the IOCTL to the/DEV/KVM character device.
struct KVM {
spinlock_t Mmu_lock;
spinlock_t Requests_lock;
struct Rw_semaphore slots_lock;
struct Mm_struct *mm; /* Userspace tied to this VM */
int nmemslots;
struct Kvm_memory_slot memslots[kvm_memory_slots +
Kvm_private_mem_slots];
#ifdef config_kvm_apic_architecture
U32 bsp_vcpu_id;
struct KVM_VCPU *bsp_vcpu;
#endif
struct KVM_VCPU *vcpus[kvm_max_vcpus];
atomic_t Online_vcpus;
struct List_head vm_list;
struct mutex lock;
struct Kvm_io_bus Mmio_bus;
struct Kvm_io_bus Pio_bus;
#ifdef CONFIG_HAVE_KVM_EVENTFD
struct {
spinlock_t lock;
struct List_head items;
} Irqfds;
struct List_head Ioeventfds;
#endif
struct KVM_VM_STAT stat;
struct Kvm_arch arch;
atomic_t Users_count;
#ifdef Kvm_coalesced_mmio_page_offset
struct Kvm_coalesced_mmio_dev *coalesced_mmio_dev;
struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
#endif
struct Mutex irq_lock;
#ifdef config_have_kvm_irqchip
struct List_head irq_routing; /* of Kvm_kernel_irq_routing_entry * *
struct Hlist_head mask_notifier_list;
#endif
#ifdef Kvm_arch_want_mmu_notifier
struct Mmu_notifier mmu_notifier;
unsigned long mmu_notifier_seq;
Long Mmu_notifier_count;
#endif
};
struct Kvm_vm_stat stat; is the run-time state information of the page table, the MMU, and so on in the KVM virtual machine.
All members in the Kvm_x86_ops struct are function pointers, and in the two different modules of the Kvm-intel.ko and Kvm-amd.ko, different functions are made for the respective systems. The KVM subsystem code will perform the actual hardware operation through the struct function.
For KVM FD, the KVM_CREATE_VCPU command Word can be used to create the KVM Vcpus, and the operation to obtain the VCPU_FD,VCPU_FD is mainly included in Kvm_vcpu_fops, Kvm_vcpu_fops implementation is as follows:
static struct File_operations Kvm_vcpu_fops = {
. Release = Kvm_vcpu_release,
. Unlocked_ioctl = Kvm_vcpu_ioctl,
. Compat_ioctl = Kvm_vcpu_ioctl,
. mmap = Kvm_vcpu_mmap,
};
The principle of KVM virtualization