Linux: Intel-Virtualization Technology(VT)下的中断

来源:互联网 发布:mac mini英雄联盟测评 编辑:程序博客网 时间:2024/05/29 08:32

这也是以前的一篇手记,由于涉及到公司的一些资料,摘录并整理。只是一个简单的流程说明,详细的知识点还请参考相关手册。


先来张图热个身。

这里写图片描述

在VT环境下,当中断产生时,有两种场景:在host上下文和guest上下文。 host收到中断后,可以自己处理,也可以将此中断重新路由给Guest;Guest上下文的中断,可以配置为直接路由给Guest,或配置为路由给host。所以需要host和guest间有统一的中断配置说明。

host下收到中断的情况:
如果中断是需要host处理,则host直接处理;如果此中断需要由guest处理,利用虚拟中断机制传递中断。
根据为Guest的vector设置VM-entry interruption-information field;则在vm-entry时,会触发对应的vector中断给guest。

VM-entry interruption-information field (32 bits)的结构描述如下:

这里写图片描述

VMX operation allows injecting interruptions to a guest virtual machine through the use of VM-entry interrupt-information field in VMCS. Injectable interruptions include external interrupts, NMI, processor exceptions, software generated interrupts, and software traps. If the interrupt-information field indicates a valid interrupt, exception or trap event upon the next VM entry; the processor will use the information in the field to vector a virtual interruption through the guest IDT after all guest state and MSRs are loaded. Delivery through the guest IDT emulates vectoring in non-VMX operation by doing the normal privilege checks and pushing appropriate entries to the guest stack (entries may include RFLAGS, EIP and exception error code). A VMM with host control of NMI and external interrupts can use the event-injection facility to
forward virtual interruptions to various guest virtual machines.

guest下收到中断的情况:
可通过exception bitmap和External-interrupt exiting来控制异常和中断的流向,见下面的描述。

The exception bitmap is a 32-bit field that contains one bit for each exception. When an exception occurs, its vector is used to select a bit in this field. If the bit is 1, the exception causes a VM exit. If the bit is 0, the exception is delivered normally through the IDT, using the descriptor corresponding to the exception’s vector.

External-interrupt exiting:If this control is 1, external interrupts cause VM exits. Otherwise, they are delivered normally through the guest interrupt-descriptor table (IDT). If this control is 1, the value of RFLAGS.IF does not affect interrupt blocking.

如果中断需要路由给host,则中断会触发vm-exit,退出的理由是:
External interrupt. An external interrupt arrived and the “external-interrupt exiting” VM-execution control was 1.

如果中断没有配置为退出vm,则直接路由给guest的IDT。

host和guest之间也可互相发送软中断,作为2者间信息交互的触发手段
host–>guest: 如前所述,利用VM-entry interruption-information field等控制位。
guest–>host: 利用vmcall


下图是当时画的中断重定向图。Line经由APIC重定向到IDT的vector;vector经由IDT重定向到不同的中断门;在经由中断门指向Linux的Irq号以及处理函数。

这里写图片描述

阅读全文
0 0
原创粉丝点击