kvm.h

来自「linux 内核源代码」· C头文件 代码 · 共 797 行 · 第 1/2 页

H
797
字号
struct kvm {	struct mutex lock; /* protects everything except vcpus */	int naliases;	struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS];	int nmemslots;	struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS];	/*	 * Hash table of struct kvm_mmu_page.	 */	struct list_head active_mmu_pages;	int n_free_mmu_pages;	struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];	struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];	unsigned long rmap_overflow;	struct list_head vm_list;	struct file *filp;	struct kvm_io_bus mmio_bus;	struct kvm_io_bus pio_bus;	struct kvm_pic *vpic;	struct kvm_ioapic *vioapic;	int round_robin_prev_vcpu;};static inline struct kvm_pic *pic_irqchip(struct kvm *kvm){	return kvm->vpic;}static inline struct kvm_ioapic *ioapic_irqchip(struct kvm *kvm){	return kvm->vioapic;}static inline int irqchip_in_kernel(struct kvm *kvm){	return pic_irqchip(kvm) != 0;}struct descriptor_table {	u16 limit;	unsigned long base;} __attribute__((packed));struct kvm_x86_ops {	int (*cpu_has_kvm_support)(void);          /* __init */	int (*disabled_by_bios)(void);             /* __init */	void (*hardware_enable)(void *dummy);      /* __init */	void (*hardware_disable)(void *dummy);	void (*check_processor_compatibility)(void *rtn);	int (*hardware_setup)(void);               /* __init */	void (*hardware_unsetup)(void);            /* __exit */	/* Create, but do not attach this VCPU */	struct kvm_vcpu *(*vcpu_create)(struct kvm *kvm, unsigned id);	void (*vcpu_free)(struct kvm_vcpu *vcpu);	void (*vcpu_reset)(struct kvm_vcpu *vcpu);	void (*prepare_guest_switch)(struct kvm_vcpu *vcpu);	void (*vcpu_load)(struct kvm_vcpu *vcpu, int cpu);	void (*vcpu_put)(struct kvm_vcpu *vcpu);	void (*vcpu_decache)(struct kvm_vcpu *vcpu);	int (*set_guest_debug)(struct kvm_vcpu *vcpu,			       struct kvm_debug_guest *dbg);	void (*guest_debug_pre)(struct kvm_vcpu *vcpu);	int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);	int (*set_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);	u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg);	void (*get_segment)(struct kvm_vcpu *vcpu,			    struct kvm_segment *var, int seg);	void (*set_segment)(struct kvm_vcpu *vcpu,			    struct kvm_segment *var, int seg);	void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);	void (*decache_cr4_guest_bits)(struct kvm_vcpu *vcpu);	void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0);	void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);	void (*set_cr4)(struct kvm_vcpu *vcpu, unsigned long cr4);	void (*set_efer)(struct kvm_vcpu *vcpu, u64 efer);	void (*get_idt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);	void (*set_idt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);	void (*get_gdt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);	void (*set_gdt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);	unsigned long (*get_dr)(struct kvm_vcpu *vcpu, int dr);	void (*set_dr)(struct kvm_vcpu *vcpu, int dr, unsigned long value,		       int *exception);	void (*cache_regs)(struct kvm_vcpu *vcpu);	void (*decache_regs)(struct kvm_vcpu *vcpu);	unsigned long (*get_rflags)(struct kvm_vcpu *vcpu);	void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags);	void (*tlb_flush)(struct kvm_vcpu *vcpu);	void (*inject_page_fault)(struct kvm_vcpu *vcpu,				  unsigned long addr, u32 err_code);	void (*inject_gp)(struct kvm_vcpu *vcpu, unsigned err_code);	void (*run)(struct kvm_vcpu *vcpu, struct kvm_run *run);	int (*handle_exit)(struct kvm_run *run, struct kvm_vcpu *vcpu);	void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);	void (*patch_hypercall)(struct kvm_vcpu *vcpu,				unsigned char *hypercall_addr);	int (*get_irq)(struct kvm_vcpu *vcpu);	void (*set_irq)(struct kvm_vcpu *vcpu, int vec);	void (*inject_pending_irq)(struct kvm_vcpu *vcpu);	void (*inject_pending_vectors)(struct kvm_vcpu *vcpu,				       struct kvm_run *run);};extern struct kvm_x86_ops *kvm_x86_ops;/* The guest did something we don't support. */#define pr_unimpl(vcpu, fmt, ...)					\ do {									\	if (printk_ratelimit())						\		printk(KERN_ERR "kvm: %i: cpu%i " fmt,			\		       current->tgid, (vcpu)->vcpu_id , ## __VA_ARGS__); \ } while(0)#define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt)#define vcpu_printf(vcpu, fmt...) kvm_printf(vcpu->kvm, fmt)int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);int kvm_init_x86(struct kvm_x86_ops *ops, unsigned int vcpu_size,		  struct module *module);void kvm_exit_x86(void);int kvm_mmu_module_init(void);void kvm_mmu_module_exit(void);void kvm_mmu_destroy(struct kvm_vcpu *vcpu);int kvm_mmu_create(struct kvm_vcpu *vcpu);int kvm_mmu_setup(struct kvm_vcpu *vcpu);int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot);void kvm_mmu_zap_all(struct kvm *kvm);hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa);#define HPA_MSB ((sizeof(hpa_t) * 8) - 1)#define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB)static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; }hpa_t gva_to_hpa(struct kvm_vcpu *vcpu, gva_t gva);struct page *gva_to_page(struct kvm_vcpu *vcpu, gva_t gva);extern hpa_t bad_page_address;struct page *gfn_to_page(struct kvm *kvm, gfn_t gfn);struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);void mark_page_dirty(struct kvm *kvm, gfn_t gfn);enum emulation_result {	EMULATE_DONE,       /* no further processing */	EMULATE_DO_MMIO,      /* kvm_run filled with mmio request */	EMULATE_FAIL,         /* can't emulate this instruction */};int emulate_instruction(struct kvm_vcpu *vcpu, struct kvm_run *run,			unsigned long cr2, u16 error_code);void kvm_report_emulation_failure(struct kvm_vcpu *cvpu, const char *context);void realmode_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw,		   unsigned long *rflags);unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr);void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long value,		     unsigned long *rflags);int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data);int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);struct x86_emulate_ctxt;int kvm_emulate_pio (struct kvm_vcpu *vcpu, struct kvm_run *run, int in,		     int size, unsigned port);int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,			   int size, unsigned long count, int down,			    gva_t address, int rep, unsigned port);void kvm_emulate_cpuid(struct kvm_vcpu *vcpu);int kvm_emulate_halt(struct kvm_vcpu *vcpu);int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address);int emulate_clts(struct kvm_vcpu *vcpu);int emulator_get_dr(struct x86_emulate_ctxt* ctxt, int dr,		    unsigned long *dest);int emulator_set_dr(struct x86_emulate_ctxt *ctxt, int dr,		    unsigned long value);void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr0);void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr0);void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr0);unsigned long get_cr8(struct kvm_vcpu *vcpu);void lmsw(struct kvm_vcpu *vcpu, unsigned long msw);void kvm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l);int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data);void fx_init(struct kvm_vcpu *vcpu);void kvm_resched(struct kvm_vcpu *vcpu);void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);void kvm_flush_remote_tlbs(struct kvm *kvm);int emulator_read_std(unsigned long addr,                      void *val,		      unsigned int bytes,		      struct kvm_vcpu *vcpu);int emulator_write_emulated(unsigned long addr,			    const void *val,			    unsigned int bytes,			    struct kvm_vcpu *vcpu);unsigned long segment_base(u16 selector);void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,		       const u8 *new, int bytes);int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);int kvm_mmu_load(struct kvm_vcpu *vcpu);void kvm_mmu_unload(struct kvm_vcpu *vcpu);int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);static inline void kvm_guest_enter(void){	current->flags |= PF_VCPU;}static inline void kvm_guest_exit(void){	current->flags &= ~PF_VCPU;}static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva,				     u32 error_code){	return vcpu->mmu.page_fault(vcpu, gva, error_code);}static inline void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu){	if (unlikely(vcpu->kvm->n_free_mmu_pages < KVM_MIN_FREE_MMU_PAGES))		__kvm_mmu_free_some_pages(vcpu);}static inline int kvm_mmu_reload(struct kvm_vcpu *vcpu){	if (likely(vcpu->mmu.root_hpa != INVALID_PAGE))		return 0;	return kvm_mmu_load(vcpu);}static inline int is_long_mode(struct kvm_vcpu *vcpu){#ifdef CONFIG_X86_64	return vcpu->shadow_efer & EFER_LME;#else	return 0;#endif}static inline int is_pae(struct kvm_vcpu *vcpu){	return vcpu->cr4 & X86_CR4_PAE;}static inline int is_pse(struct kvm_vcpu *vcpu){	return vcpu->cr4 & X86_CR4_PSE;}static inline int is_paging(struct kvm_vcpu *vcpu){	return vcpu->cr0 & X86_CR0_PG;}static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot){	return slot - kvm->memslots;}static inline struct kvm_mmu_page *page_header(hpa_t shadow_page){	struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT);	return (struct kvm_mmu_page *)page_private(page);}static inline u16 read_fs(void){	u16 seg;	asm ("mov %%fs, %0" : "=g"(seg));	return seg;}static inline u16 read_gs(void){	u16 seg;	asm ("mov %%gs, %0" : "=g"(seg));	return seg;}static inline u16 read_ldt(void){	u16 ldt;	asm ("sldt %0" : "=g"(ldt));	return ldt;}static inline void load_fs(u16 sel){	asm ("mov %0, %%fs" : : "rm"(sel));}static inline void load_gs(u16 sel){	asm ("mov %0, %%gs" : : "rm"(sel));}#ifndef load_ldtstatic inline void load_ldt(u16 sel){	asm ("lldt %0" : : "rm"(sel));}#endifstatic inline void get_idt(struct descriptor_table *table){	asm ("sidt %0" : "=m"(*table));}static inline void get_gdt(struct descriptor_table *table){	asm ("sgdt %0" : "=m"(*table));}static inline unsigned long read_tr_base(void){	u16 tr;	asm ("str %0" : "=g"(tr));	return segment_base(tr);}#ifdef CONFIG_X86_64static inline unsigned long read_msr(unsigned long msr){	u64 value;	rdmsrl(msr, value);	return value;}#endifstatic inline void fx_save(struct i387_fxsave_struct *image){	asm ("fxsave (%0)":: "r" (image));}static inline void fx_restore(struct i387_fxsave_struct *image){	asm ("fxrstor (%0)":: "r" (image));}static inline void fpu_init(void){	asm ("finit");}static inline u32 get_rdx_init_val(void){	return 0x600; /* P6 family */}#define ASM_VMX_VMCLEAR_RAX       ".byte 0x66, 0x0f, 0xc7, 0x30"#define ASM_VMX_VMLAUNCH          ".byte 0x0f, 0x01, 0xc2"#define ASM_VMX_VMRESUME          ".byte 0x0f, 0x01, 0xc3"#define ASM_VMX_VMPTRLD_RAX       ".byte 0x0f, 0xc7, 0x30"#define ASM_VMX_VMREAD_RDX_RAX    ".byte 0x0f, 0x78, 0xd0"#define ASM_VMX_VMWRITE_RAX_RDX   ".byte 0x0f, 0x79, 0xd0"#define ASM_VMX_VMWRITE_RSP_RDX   ".byte 0x0f, 0x79, 0xd4"#define ASM_VMX_VMXOFF            ".byte 0x0f, 0x01, 0xc4"#define ASM_VMX_VMXON_RAX         ".byte 0xf3, 0x0f, 0xc7, 0x30"#define MSR_IA32_TIME_STAMP_COUNTER		0x010#define TSS_IOPB_BASE_OFFSET 0x66#define TSS_BASE_SIZE 0x68#define TSS_IOPB_SIZE (65536 / 8)#define TSS_REDIRECTION_SIZE (256 / 8)#define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1)#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?