linux 内核 kvm中的vcpu描述


此结构也是KVM架构层抽象出的虚拟CPU描述,这里跟前面的KVM结构一样,是内核对虚拟机一系列资源抽象后得到的数据描述。

include/linux/kvm_host.h
struct kvm_vcpu {
 struct kvm *kvm;所关联的虚拟机描述
#ifdef CONFIG_PREEMPT_NOTIFIERS
 struct preempt_notifier preempt_notifier;
#endif
 int cpu;
 int vcpu_id;虚拟CPU的id
 int srcu_idx;
 int mode;
 unsigned long requests;
 unsigned long guest_debug;
 int pre_pcpu;
 struct list_head blocked_vcpu_list;
 struct mutex mutex;
 struct kvm_run *run;
 int fpu_active;
 int guest_fpu_loaded, guest_xcr0_loaded;
 unsigned char fpu_counter;
 struct swait_queue_head wq;
 struct pid *pid;
 int sigset_active;
 sigset_t sigset;
 struct kvm_vcpu_stat stat;
 unsigned int halt_poll_ns;
 bool valid_wakeup;
#ifdef CONFIG_HAS_IOMEM
 int mmio_needed;
 int mmio_read_completed;
 int mmio_is_write;
 int mmio_cur_fragment;
 int mmio_nr_fragments;
 struct kvm_mmio_fragment mmio_fragments[KVM_MAX_MMIO_FRAGMENTS];
#endif
#ifdef CONFIG_KVM_ASYNC_PF
 struct {
  u32 queued;
  struct list_head queue;
  struct list_head done;
  spinlock_t lock;
 } async_pf;
#endif
#ifdef CONFIG_HAVE_KVM_CPU_RELAX_INTERCEPT
 struct {
  bool in_spin_loop;
  bool dy_eligible;
 } spin_loop;
#endif
 bool preempted;
 struct kvm_vcpu_arch arch;
 struct dentry *debugfs_dentry;
};
这里需要关注kvm_run结构,其跟具体支持虚拟化的host cpu密切相关。