之前在 文章 中描述了 7个ioctl,现在着重分析 其中5个,这5个与虚拟机CPU相关
KVM_CREATE_VM KVM_CREATE_VCPU KVM_ARM_VCPU_INIT KVM_SET_ONE_REG KVM_RUN vm entry vm exitKVM_RUN
- VM entry 的流程
kvm_vcpu_ioctl kvm_arch_vcpu_ioctl_run -1.kvm_call_hyp_ret(__kvm_vcpu_run_nvhe, vcpu); //kvm_call_hyp_ret即__kvm_call_hyp 0. __kvm_call_hyp 中的 hvc #0 1. arch/arm/kvm/hyp/hyp-entry.S 中的 __kvm_hyp_vector_ic_inv 中的 W(add) sp, sp, #1 2. b decode_vectors 3. vect_br 0, hyp_fiq 和 vect_br 1, hyp_irq 和 vect_br 2, hyp_hvc 4. hyp_hvc 5. blx lr @ Call the HYP function 6. __kvm_vcpu_run_nvhe 7. __guest_enter 8. eret // 进入 guest
- VM exit 的流程
1. 虚拟机执行敏感指令 2. __kvm_hyp_vector_ic_inv 中的 W(add) sp, sp, #1 3. b decode_vectors 4. vect_br 0, hyp_fiq 和 vect_br 1, hyp_irq 和 vect_br 2, hyp_hvc 5. hyp_hvc 6. bne guest_trap @ Not HVC instr. 7. mov r1, #ARM_EXCEPTION_HVC 和 b __guest_exit 8. abort_guest_exit_end: bx lr 9. arch/arm/kvm/hyp/switch.c 中的 __populate_fault_info 中的 u32 hsr = read_sysreg(HSR); // ??? 10. if (exit_code == ARM_EXCEPTION_HVC && !__populate_fault_info(vcpu)) goto again;



