免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3951 | 回复: 2
打印 上一主题 下一主题

[虚拟化] KVM如何处理NMI [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-08-01 12:39 |只看该作者 |倒序浏览
本帖最后由 embeddedlwp 于 2014-04-11 11:56 编辑

handle_exception:
vmx-exit handler函数在处理NMI时,直接忽略掉。注释中指出,NMI在此之前由vmx_vcpu_run 函数处理掉。
  1. 4222 static int handle_exception(struct kvm_vcpu *vcpu)
  2. ....
  3. 4246
  4. 4247         if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR)
  5. 4248                 return 1;  /* already handled by vmx_vcpu_run() */**
复制代码
vmx_vcpu_run:
本函数在实现虚拟机的启动,同时后半部分代码作为vmx_exit返回时在host中的hander处理部分。NMI的处理就在后面的vmx_complete_atomic_exit中。
  1. 6133 static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
  2. ...
  3.              vmx_complete_atomic_exit(vmx);
  4. 6303         vmx_recover_nmi_blocking(vmx);
  5. 6304         vmx_complete_interrupts(vmx);
  6. 6305 }
复制代码
vmx_complete_atomic_exit:
在这个函数里面,遇到NMI时,直接调用
  1. int $2
复制代码
触发host中的NMI中断处理。请教各位
1、为什么要这么处理,而不直接将NMI注入到guest中进行处理呢?
2、代码没有找出host中 int $2对应的中断处理例程。哪位能帮忙指出下。
  1. 5963 static void vmx_complete_atomic_exit(struct vcpu_vmx *vmx)
  2.              ....
  3. 5967         if (!(vmx->exit_reason == EXIT_REASON_MCE_DURING_VMENTRY
  4. 5968               || vmx->exit_reason == EXIT_REASON_EXCEPTION_NMI))
  5. 5969                 return;
  6. 5970
  7. 5971         vmx->exit_intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
  8. 5972         exit_intr_info = vmx->exit_intr_info;
  9.              ...
  10. 5977
  11. 5978         /* We need to handle NMIs before interrupts are enabled */
  12. 5979         if ((exit_intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR &&
  13. 5980             (exit_intr_info & INTR_INFO_VALID_MASK)) {
  14. 5981                 kvm_before_handle_nmi(&vmx->vcpu);
  15. 5982                 asm("int $2");
  16. 5983                 kvm_after_handle_nmi(&vmx->vcpu);
  17. 5984         }
  18. 5985 }
复制代码

论坛徽章:
0
2 [报告]
发表于 2012-08-01 15:30 |只看该作者
自顶一下,求KVM高手。

论坛徽章:
0
3 [报告]
发表于 2012-08-02 12:55 |只看该作者
今天再阅读了KVM的代码能解开上面的疑团。
KVM工作结构为Linux作HOST,GUEST任意安装操作系统。
所以HOST直接使用当前Linux环境下的GDT、IDT等环境。
那样int 2,直接调用的是Linux下面的NMI ISR。

而Intel手册中提到,启用虚拟机时,如果NMI_EXITING位设置为1时,guest遇到NMI即VMX_EXIT到host,guest中的iret将对阻塞的NMI请求没有影响。


25.4 CHANGES TO INSTRUCTION BEHAVIOR IN VMX NON-ROOT OPERATION
IRET.Behavior of IRET with regard to NMI blocking (see Table 24-3) is
determined by the settings of the “NMI exiting” and “virtualNMIs” VM-execution
controls:
— If the “NMI exiting” VM-execution control is 0, IRET operates normally and
unblocks NMIs. (If the “NMI exiting” VM-execution control is 0, the “virtual
NMIs” control must be 0; see Section 26.2.1.1.)
— If the “NMI exiting” VM-execution control is 1, IRET does not affect blocking
of NMIs. If, in addition, the “virtual NMIs” VM-execution control is 1, the
logical processor tracks virtual-NMI blocking. In this case, IRET removes any
virtual-NMI blocking.
The unblocking of NMIs or virtual NMIs specified above occurs even if IRET
causes a fault
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP