1. Overview of EPT
CPU will use both guest page table and extended page table. The address of EPT is set by the function vmx_set_cr3.
1753 static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
1754 {
1755 unsigned long guest_cr3;
1756 u64 eptp;
1757
1758 guest_cr3 = cr3;
1759 if (enable_ept) {
1760 eptp = construct_eptp(cr3);
1761 vmcs_write64(EPT_POINTER, eptp);
1762 guest_cr3 = is_paging(vcpu) ? vcpu->arch.cr3 :
1763 VMX_EPT_IDENTITY_PAGETABLE_ADDR;
1764 }
1765
1766 vmx_flush_tlb(vcpu);
1767 vmcs_writel(GUEST_CR3, guest_cr3);
1768 if (vcpu->arch.cr0 & X86_CR0_PE)
1769 vmx_fpu_deactivate(vcpu);
1770 }
EPT (optionally) activated on VM entry
– When EPT active, EPT base pointer (loaded on VM entry from VMCS) points to extended page tables
– EPT deactivated on VM exit
3947 static struct kvm_x86_ops vmx_x86_ops = {
3975 .set_cr3 = vmx_set_cr3,
.....
}
在函数 kvm_vcpu_ioctl 中
static long kvm_vcpu_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
case KVM_RUN:
r = -EINVAL;
if (arg)
goto out;
r = kvm_ar