public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@qumranet.com>
To: Zhao Forrest <forrest.zhao@gmail.com>
Cc: kvm-devel@lists.sourceforge.net
Subject: Re: KVM architecture docs
Date: Tue, 04 Mar 2008 10:25:13 +0200	[thread overview]
Message-ID: <47CD0769.6020104@qumranet.com> (raw)
In-Reply-To: <ac8af0be0803032012h5f464604gb7420c80ece925ea@mail.gmail.com>

Zhao Forrest wrote:
>> http://ols.108.redhat.com/2007/Reprints/kivity-Reprint.pdf
>>
>>     
> Hi Avi,
>
> I have a question about KVM architecture after reading your paper.
> It reads:
> ......
> At the kernel level, the kernel causes the hardware
> to enter guest mode. If the processor exits guest
> mode due to an event such as an external interrupt
> or a shadow page table fault, the kernel performs
> the necessary handling and resumes guest execution.
> If the exit reason is due to an I/O instruction
> or a signal queued to the process, then the kernel
> exits to userspace.
> ......
> After reading your paper my understanding of KVM architecture is that
> for a particular VM the user mode(QEMU), kernel mode and guest mode share
> the same process context from host linux kernel's point of view, right?
>   

Correct.  Virtual machine == process, virtual cpu == thread.

> If this is the case, see the below example:
> 1 physical NIC interrupt is received on physical CPU 0 and host kernel
> determines that this is a network packet targeted to the emulated NIC
> for a VM
> 2 at the same time this VM is running in guest mode on physical CPU 1
> My question is: at this time can host kernel *actively* interrupt VM
> and make it run in user mode to handle the incoming network data
> packet in QEMU? Or host kernel has to wait for
> VM(because of external interrupt or shadow page table fault or I/O
> instruction) to quit guest mode and wait for VM to voluntarily detect
> that incoming network packet is pending and switch to user space?
>   

The incoming packet is processed by the host ethernet stack; it is 
forwarded to the bridge, which forwards it to the tap.  When the tap 
queues the packet, it sends a signal to qemu (since the tap file 
descriptor has a signal associated).  When the kernel delivers the 
signal, it notices the qemu thread is running on cpu 1, so it sends an 
inter-processor interrupt to cpu 1.  The interrupt causes the processor 
to leave guest mode and exit to the hypervisor, which notices that a 
signal is pending, so it exits to qemu which dequeues the packet and 
notifies the guest (if necessary) by injecting an interrupt.

Note that most of this path (including the IPI) is regular Linux code, 
not kvm related, and would happen for any other application in the same way.

> A further question is, how a VM detect the incoming pending network
> packet? In kernel space or in user space?
>   

Are you talking about the host or guest?  If the host, the packet is 
received by the kernel, and further processing is done in userspace.

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

  reply	other threads:[~2008-03-04  8:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-03 15:51 KVM architecture docs Alessandro Sardo
2008-03-03 18:23 ` Avi Kivity
2008-03-04  4:12   ` Zhao Forrest
2008-03-04  8:25     ` Avi Kivity [this message]
2008-03-04  9:02       ` Zhao Forrest
2008-03-04  9:21         ` Avi Kivity
2008-03-04 14:17           ` Javier Guerra
2008-03-04 15:08             ` Avi Kivity
2008-03-05  4:06               ` Zhao Forrest
2008-03-05  5:19                 ` Avi Kivity
2008-03-05  6:05                   ` Zhao Forrest
2008-03-05  6:10                     ` Avi Kivity
2008-03-05  6:38                     ` Avi Kivity
2008-03-05  6:51                   ` Zhao Forrest
2008-03-05  6:58                     ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47CD0769.6020104@qumranet.com \
    --to=avi@qumranet.com \
    --cc=forrest.zhao@gmail.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox