kvm-owner@xxxxxxxxxxxxxxx wrote on 07/06/2012 03:12:55: > From: sheng qiu <herbert1984106@xxxxxxxxx> > To: kvm <kvm@xxxxxxxxxxxxxxx>, > Date: 07/06/2012 03:13 > Subject: KVM handling external interrupts > Sent by: kvm-owner@xxxxxxxxxxxxxxx > > 1> as we know, normally the external interrupt will cause VMexit and > the hypervisor will inject a virtual interrupt if it is for guest. > Then which irq will be injected (i mean the interrupt vector for > indexing the guest IDT)? How does the KVM get to know about this > (associate a host IRQ with a guest virtual IRQ)? For emulated/para-virtual devices: There is no direct 1-to-1 relation between a "physical" irq that caused an exit and a "virtual irq" injected to the guest. QEMU is responsible for emulating virtual devices, and will inject a virtual interrupt (via KVM) when the virtual hardware emulation (software) does so. Physical interrupts are always handled by the host linux kernel whenever they caused and exit (arrived in guest mode) or not (arrived in root mode). So, physical interrupts are always consumed by the host. For example, interrupts in the host might trigger some I/O callback or release a thread blocked due to sync I/O in QEMU but QEMU does not map physical interrupts to virtual interrupts. Then, depending on how QEMU emulates the virtual devices, it may device to inject a virtual interrupt after it finished handling an I/O operation (e.g. callback called) > 2> if for assigned device to the guest, the hypervisor will deliver > that IRQ to the guest. by tracing the code, i found the host IRQ is > different with the guest's (i mean the interrupt vector). how the KVM > configure which interrupt vector the guest should use? For device assignment: In this case you do have a 1-to-1 mapping between physical and virtual interrupts but they do NOT necessary use the same vector. The linux host kernel assigns a "physical vector". The guest OS assigns a "virtual vector". KVM knows the "virtual vector" the guest is using and then injects a corresponding virtual interrupt each time a physical interrupts arrives. In other words, KVM does a simple physical to virtual conversion of the vector number. > > 3> if we configure not exit on external interrupt by setting some > field in VMCS, what will happen during the physical interrupts? will > the CPU use the guest IDT for response interrupt? If so, can KVM > redirect the CPU to use another IDT for guest (assuming modifying the > IDTR)? Yes, that's exactly something we already did in a research project. You can read our paper published in ASPLOS 2012: ELI: Bare-metal performance for I/O virtualization ( http://dl.acm.org/citation.cfm?id=2151020&dl=ACM&coll=DL&CFID=86701665&CFTOKEN=26302003 ) Note this is not so simple, there are many other issues you should consider. > 4> where is the guest IDT located? it this configured by the qemu > while initializing the vcpu and registers (include the IDTR)? The guest IDT is located in the guest address space and the guest setup the IDTR (pointer to the IDT) register. KVM is not involved. In other words, KVM does not touch/modify the IDT content or the IDTR. KVM simple uses the hardware support in the processor to virtualize the IDTR register (GUEST_IDTR). Offcourse, you can modify the logic and let KVM change the IDTR/IDT as we did. Regards, Abel Gordon IBM Research - Haifa -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html