VM-EXIT(EPT Violation)调用链

本文详细剖析了EPT Violation导致的vm-exit过程,从vcpu_run()开始,经过kvm_x86_handle_exit()、vmx_handle_exit()等函数,直至页面分配的核心函数alloc_pages()。通过对调用链的跟踪,揭示了虚拟化环境中处理EPT违规的内部机制。

针对由EPT Violation引起的vm-exit分析其调用链(一直找到了分配页面的核心函数)

// linux v5.17.8

vcpu_run()
    vcpu_enter_guest()
        static_call(kvm_x86_handle_exit)(vcpu, exit_fastpath);struct kvm_x86_ops{ 
                    ...
                    int (*handle_exit)(struct kvm_vcpu *vcpu, enum exit_fastpath_completion exit_fastpath);
                    ...
                } // in /arch/x86/include/asm/kvm-x86-ops.h use marco KVM_X86_OP or KVM_X86_OP_NULL to generate static_call()
                  // in /arch/x86/kvm/x86.c  #define KVM_X86_OP NULL KVM_X86_OP
                  //     #define KVM_X86_OP(func)                                             \
                  //         DEFINE_STATIC_CALL_NULL(kvm_x86_##func, *(((struct kvm_x86_ops *)0)->func));
    // function relocate in arch/x86/kvm/vmx/vmx.c
    static struct kvm_x86_ops vmx_x86_ops __initdata = {
        .name = "kvm_intel",
        ...
        .handle_exit = vmx_handle_exit,
        ...                       |
    }                             |
    vmx_handle_exit() ← —— —— —— -
        __vmx_handle_exit()
            kvm_vmx_exit_handlers[exit_handler_index](vcpu)
            // table defined in /arch/x86/kvm/vmx/vmx.c
            static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { 
                ...
                [EXIT_REASON_EPT_VIOLATION] = handle_ept_violation,          
                ...                                    |
            }                                          | 
    /* exit caused by ept violation */                 |   
    handle_ept_violation() ← —— —— —— —— —— —— —— —— ——  
        kvm_mmu_page_fault()
            kvm_mmu_do_page_fault()
                kvm_tdp_page_fault()
                    direct_page_fault()
                        kvm_tdp_mmu_map()
                            alloc_tdp_mmu_page()
                                kvm_mmu_memory_cache_alloc()
                                    mmu_memory_cache_alloc_obj()
                                        __get_free_page()
                                            __get_free_pages()
                                                alloc_pages()
                                                    alloc_pages_node()
                                                        __alloc_pages_node()
                                                            __alloc_pages()
                                                                ...

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值