kvm这个结构体包含了vCPU,内存,APIC,IRQ,MMU,Event事件管理等信息。该结构体中的信息主要在kvm虚拟机内部使用,用于跟踪虚拟机的状态。
对于一个kvm,就对应一个线程。
Kvm完全利用了硬件虚拟化技术,通过cat /proc/cpuinfo 查看信息,如果是intel处理器,那么就加载kvm-intel.ko
用户态创建一个虚拟机就是通过ioctl向/dev/kvm字符设备进行设置和管理kvm的。
-
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;就是KVM虚拟机中的页表、MMU等运行时状态信息。
kvm_x86_ops 结构体中的所有成员都是函数指针,在kvm-intel.ko 和 kvm-amd.ko这两个不同的模块中,针对各自体系做不同的函数。KVM子系统代码将通过该结构体函数进行实际的硬件操作。
针对kvm的fd,通过KVM_CREATE_VCPU指令字可以创建KVM的vCPU,并且获得该vcpu_fd,vcpu_fd的操作主要包含在kvm_vcpu_fops中,kvm_vcpu_fops的实现方法如下:
-
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,
-
};
阅读(5142) | 评论(1) | 转发(1) |