简体   繁体   English

如何在kvm中完成设备仿真

[英]How is device emulation done in kvm

I know that the qemu-kvm does the device emulation stuff in KVM. 我知道qemu-kvm在KVM中执行设备仿真。 Is the qemu-kvm being executed in the userspace of the host? qemu-kvm是否在主机的用户空间中执行? So when a kick function is encountered, it exits the VM through a hypercall into the hypervisor, then the hypervisor hand over to qemu-kvm in host userspace. 因此,当遇到kick函数时,它通过超级调用退出VM进入虚拟机管理程序,然后管理程序移交给主机用户空间中的qemu-kvm。 Next after doing the needed things, the qemu-kvm transits to the hypervisor and then the hypervisor back to the VM. 在完成所需的操作之后,qemu-kvm将转换到管理程序,然后将管理程序转移回VM。 So it means there are two system calls one from VM-->Hypervisor and qemu-kvm-->Hypervisor? 所以这意味着有两个系统调用来自VM - > Hypervisor和qemu-kvm - > Hypervisor? Are these the steps that take place or i am wrong? 这些是发生的步骤还是我错了? If there is any documentation about these kind of stuff, please give me the link. 如果有关于这类东西的任何文件,请给我链接。 Thank you very much... 非常感谢你...

Thanks, Bala 谢谢,巴拉

kvm was started by an Israeli firm called qumranet . kvm由一家名为qumranet的以色列公司发起 These introductory papers are written by those guys and are recommended for reading: 这些介绍性论文由这些人撰写,建议阅读:

Kernel-based Virtual Machine Technology: http://www.fujitsu.com/downloads/MAG/vol47-3/paper18.pdf KVM: Kernel-based Virtualization Driver: http://www.linuxinsight.com/files/kvm_whitepaper.pdf 基于内核的虚拟机技术: http ://www.fujitsu.com/downloads/MAG/vol47-3/paper18.pdf KVM:基于内核的虚拟化驱动程序: http//www.linuxinsight.com/files/kvm_whitepaper。 PDF格式

KVM uses QEMU for I/O emulation which is explained in the paper. KVM使用QEMU进行I / O仿真,本文对此进行了解释。 It will help you to understand how a switch from guest to host mode works, the reasons behind the switch, how I/O emulation is done by qemu at userspace and how it switches back to the guest. 它将帮助您了解从guest虚拟机到主机模式的切换是如何工作的,切换背后的原因,qemu在用户空间如何完成I / O仿真以及如何切换回guest虚拟机。 These are excellent, brief papers. 这些是优秀的简短论文。

I am more familiar with KVM part working on x86 architecture, so try to explain this in KVM's x86 implementation. 我更熟悉从事x86架构的KVM部分,所以试着在KVM的x86实现中解释一下。

In x86 architecture, KVM leverages CPU's functionality to separate hypervisor and guest mode. 在x86架构中,KVM利用CPU的功能来分离管理程序和访客模式。 In Intel terms, they are VMX root and non-root modes respectively. 在英特尔术语中,它们分别是VMX根模式和非根模式。

VM entry (hypervisor -> VM) is fired by KVM with VMLAUNCH instruction with all guest-needed information filled in CPU's VMCS in kernel mode. VM条目(虚拟机管理程序 - > VM)由KVM使用VMLAUNCH指令触发,所有客户需要的信息在内核模式下填充在CPU的VMCS中。 Only a system call is invoked from qemu-kvm to kvm kernel module. 仅从qemu-kvm调用系统调用到kvm内核模块。

A VM exit happens while guest OS is handling something that out of its privilege, such as accessing a physical HW or an interrupt happened. 当guest虚拟机操作系统处理超出其权限的内容(例如访问物理硬件或发生中断)时,会发生VM退出。 After that, a VM entry is issued and CPU changes to non-root mode again to execute guest code. 之后,发出VM条目,CPU再次更改为非root模式以执行访客代码。 In summary, VM exit (VM -> hypervisor) is done by HW automatically, and the corresponding exit reason and information would be recored in VMCS. 总之,VM退出(VM - > hypervisor)由HW自动完成,相应的退出原因和信息将在VMCS中进行记录。 KVM then check VMCS to determine its next step. 然后KVM检查VMCS以确定其下一步。 There is no system call for VM -> hypervisor. 没有系统调用VM - > hypervisor。

Most device emulations are based in userspace where qemu-kvm can leverage the existing qemu's code. 大多数设备仿真都基于用户空间,qemu-kvm可以利用现有的qemu代码。 However some device passthrough technologies, such as Intel VT-d, allow guest to access hardware directly through IOMMU or others. 但是,某些设备直通技术(如Intel VT-d)允许访客通过IOMMU或其他方式直接访问硬件。 Which can bring more powerful performance especially on high speed networking devices. 这可以带来更强大的性能,特别是在高速网络设备上。

If you want to dig out the source code, I recommend to focus on CPU virtualization (Intel VT-x) first, which is located in linux/arch/x86/kvm/vmx.c . 如果你想挖出源代码,我建议首先关注CPU虚拟化(Intel VT-x),它位于linux/arch/x86/kvm/vmx.c Intel software developer guide also has comprehensive introduction to VT as well. 英特尔软件开发人员指南也全面介绍了VT。

I found this good. 我发现很好。 Atleast for the basics. 至少基础知识。 Hope it helps. 希望能帮助到你。

Is the qemu-kvm being executed in the userspace of the host? qemu-kvm是否在主机的用户空间中执行? yes, this is a performance bottleneck too and there are ways around it being developed. 是的,这也是一个性能瓶颈,并且有很多方法可以开发它。 Look at PCI SR-IOV NIC for network and NPIV for fibrechannel. 查看用于网络的PCI SR-IOV NIC和用于fibrechannel的NPIV。 They both are special hardware designed to subdivided I/O controllers so that KVM/qemu can attach the VM to a private channel on the controller. 它们都是专门用于细分I / O控制器的硬件,因此KVM / qemu可以将VM连接到控制器上的专用通道。

So it means there are two system calls one from VM-->Hypervisor and qemu-kvm-->Hypervisor? 所以这意味着有两个系统调用来自VM - > Hypervisor和qemu-kvm - > Hypervisor? I don't know for certain but I think there are device interrupts crossing user-kernel space boundaries not systems calls. 我不确定,但我认为有设备中断跨越用户内核空间边界而不是系统调用。

Perhaps this document will help you a bit: 也许这份文件会对你有所帮助:

http://www.linux-kvm.org/wiki/images/4/42/Kvm-device-assignment.pdf http://www.linux-kvm.org/wiki/images/4/42/Kvm-device-assignment.pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM