English 中文(简体)
How is device emulation done in kvm
原标题:

I know that the qemu-kvm does the device emulation stuff in KVM. Is the qemu-kvm being executed in the userspace of the host? 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. Next after doing the needed things, the qemu-kvm transits to the hypervisor and then the hypervisor back to the VM. So it means there are two system calls one from VM-->Hypervisor and 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

问题回答

I am more familiar with KVM part working on x86 architecture, so try to explain this in KVM s x86 implementation.

In x86 architecture, KVM leverages CPU s functionality to separate hypervisor and guest mode. In Intel terms, they are VMX root and non-root modes respectively.

VM entry (hypervisor -> VM) is fired by KVM with VMLAUNCH instruction with all guest-needed information filled in CPU s VMCS in kernel mode. Only a system call is invoked from qemu-kvm to kvm kernel module.

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. After that, a VM entry is issued and CPU changes to non-root mode again to execute guest code. In summary, VM exit (VM -> hypervisor) is done by HW automatically, and the corresponding exit reason and information would be recored in VMCS. KVM then check VMCS to determine its next step. There is no system call for VM -> hypervisor.

Most device emulations are based in userspace where qemu-kvm can leverage the existing qemu s code. However some device passthrough technologies, such as Intel VT-d, allow guest to access hardware directly through IOMMU or others. 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. Intel software developer guide also has comprehensive introduction to VT as well.

kvm was started by an Israeli firm called 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

KVM uses QEMU for I/O emulation which is explained in the paper. 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. These are excellent, brief papers.

I found this good. Atleast for the basics. Hope it helps.

Is the qemu-kvm being executed in the userspace of the host? 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. 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.

So it means there are two system calls one from VM-->Hypervisor and 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





相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签