linux/tools/testing/selftests/kvm/lib/vmx.c
/*
 * Initialize the host state fields based on the current host state, with
 * the exception of HOST_RSP and HOST_RIP, which should be set by vmlaunch
 * or vmresume.
 */
Initialize the host state fields based on the current host state, with
the exception of HOST_RSP and HOST_RIP, which should be set by vmlaunch
or vmresume.
Initialize the host state fields based on the current host state with the exception of HOST_RSP and HOST_RIP which should be set by vmlaunch or vmresume .
static inline void init_vmcs_host_state(void)
{
	uint32_t exit_controls = vmreadz(VM_EXIT_CONTROLS);
	vmwrite(HOST_ES_SELECTOR, get_es());
	vmwrite(HOST_CS_SELECTOR, get_cs());
	vmwrite(HOST_SS_SELECTOR, get_ss());
	vmwrite(HOST_DS_SELECTOR, get_ds());
	vmwrite(HOST_FS_SELECTOR, get_fs());
	vmwrite(HOST_GS_SELECTOR, get_gs());
	vmwrite(HOST_TR_SELECTOR, get_tr());
	if (exit_controls & VM_EXIT_LOAD_IA32_PAT)
		vmwrite(HOST_IA32_PAT, rdmsr(MSR_IA32_CR_PAT));
	if (exit_controls & VM_EXIT_LOAD_IA32_EFER)
		vmwrite(HOST_IA32_EFER, rdmsr(MSR_EFER));
	if (exit_controls & VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL)
		vmwrite(HOST_IA32_PERF_GLOBAL_CTRL,
			rdmsr(MSR_CORE_PERF_GLOBAL_CTRL));
	vmwrite(HOST_IA32_SYSENTER_CS, rdmsr(MSR_IA32_SYSENTER_CS));
	vmwrite(HOST_CR0, get_cr0());
	vmwrite(HOST_CR3, get_cr3());
	vmwrite(HOST_CR4, get_cr4());
	vmwrite(HOST_FS_BASE, rdmsr(MSR_FS_BASE));
	vmwrite(HOST_GS_BASE, rdmsr(MSR_GS_BASE));
	vmwrite(HOST_TR_BASE,
		get_desc64_base((struct desc64 *)(get_gdt_base() + get_tr())));
	vmwrite(HOST_GDTR_BASE, get_gdt_base());
	vmwrite(HOST_IDTR_BASE, get_idt_base());
	vmwrite(HOST_IA32_SYSENTER_ESP, rdmsr(MSR_IA32_SYSENTER_ESP));
	vmwrite(HOST_IA32_SYSENTER_EIP, rdmsr(MSR_IA32_SYSENTER_EIP));
}
static inline void init_vmcs_host_state ( void ) { uint32_t exit_controls = vmreadz ( VM_EXIT_CONTROLS ) ; vmwrite ( HOST_ES_SELECTOR , get_es ( ) ) ; vmwrite ( HOST_CS_SELECTOR , get_cs ( ) ) ; vmwrite ( HOST_SS_SELECTOR , get_ss ( ) ) ; vmwrite ( HOST_DS_SELECTOR , get_ds ( ) ) ; vmwrite ( HOST_FS_SELECTOR , get_fs ( ) ) ; vmwrite ( HOST_GS_SELECTOR , get_gs ( ) ) ; vmwrite ( HOST_TR_SELECTOR , get_tr ( ) ) ; if ( exit_controls & VM_EXIT_LOAD_IA32_PAT ) vmwrite ( HOST_IA32_PAT , rdmsr ( MSR_IA32_CR_PAT ) ) ; if ( exit_controls & VM_EXIT_LOAD_IA32_EFER ) vmwrite ( HOST_IA32_EFER , rdmsr ( MSR_EFER ) ) ; if ( exit_controls & VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL ) vmwrite ( HOST_IA32_PERF_GLOBAL_CTRL , rdmsr ( MSR_CORE_PERF_GLOBAL_CTRL ) ) ; vmwrite ( HOST_IA32_SYSENTER_CS , rdmsr ( MSR_IA32_SYSENTER_CS ) ) ; vmwrite ( HOST_CR0 , get_cr0 ( ) ) ; vmwrite ( HOST_CR3 , get_cr3 ( ) ) ; vmwrite ( HOST_CR4 , get_cr4 ( ) ) ; vmwrite ( HOST_FS_BASE , rdmsr ( MSR_FS_BASE ) ) ; vmwrite ( HOST_GS_BASE , rdmsr ( MSR_GS_BASE ) ) ; vmwrite ( HOST_TR_BASE , get_desc64_base ( ( struct desc64 * ) ( get_gdt_base ( ) + get_tr ( ) ) ) ) ; vmwrite ( HOST_GDTR_BASE , get_gdt_base ( ) ) ; vmwrite ( HOST_IDTR_BASE , get_idt_base ( ) ) ; vmwrite ( HOST_IA32_SYSENTER_ESP , rdmsr ( MSR_IA32_SYSENTER_ESP ) ) ; vmwrite ( HOST_IA32_SYSENTER_EIP , rdmsr ( MSR_IA32_SYSENTER_EIP ) ) ; }
Initialize the host state fields based on the current host state, with
 the exception of HOST_RSP and HOST_RIP, which should be set by vmlaunch
 or vmresume.
Initialize the host state fields based on the current host state with the exception of HOST_RSP and HOST_RIP which should be set by vmlaunch or vmresume .