Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Liang YANG <brinewsor@gmail.com>
Cc: Alexander Graf <agraf@suse.de>, Kurt Kiefer <kekiefer@gmail.com>,
	kvm <kvm@vger.kernel.org>
Subject: Re: A puzzle on the interrupt disposal of KVM?
Date: Thu, 26 Nov 2009 10:06:21 +0200	[thread overview]
Message-ID: <20091126080621.GX2999@redhat.com> (raw)
In-Reply-To: <3a240e800911252314w6f8fda7cn4116be42d58bd63b@mail.gmail.com>

On Thu, Nov 26, 2009 at 03:14:04PM +0800, Liang YANG wrote:
> I think Kurt have a clear view on interrupt deliver routine.
> Maybe when a outer physical interrupt yield durning the guest running
> on cpu, this interrupt cause the guest exit
> and eventually delived to the host to be disposed. Is that right ?
> 
Correct.

> Thanks for everybody's reply.
> 
> On Tue, Nov 24, 2009 at 4:49 PM, Alexander Graf <agraf@suse.de> wrote:
> >
> > On 24.11.2009, at 09:03, Kurt Kiefer wrote:
> >
> >> I've been studying interrupt delivery in KVM myself lately. I hope I can explain what I've found, but, as I'm pretty new to this, please take my answer with a grain of salt (as I could be wrong). I would really appreciate if someone could correct me here if I am wrong or provide more details!
> >>
> >> Interrupts from the guest might be delivered via the ioctl KVM_INTERRUPT only when the KVM kmod can do interrupt routing. However, the default setup for KVM these days implements the interrupt controller in the kernel, so this ioctl is unused, and thus, vmx_inject_irq is not directly triggered from userspace. The call to vmx_inject_irq is made upon re-entry to the guest after I.E. the local APIC in the kmod flags that it needs service.
> >>
> >> To use the example of a PS2 keyboard press, the control flow works like this:
> >>
> >> 1. Userspace writes to appropriate locations as defined by the i8042 emulator
> >> 2. Userspace calls vm ioctl KVM_IRQ_LINE (IRQ=1, Level=1)
> >> 3. Control in the kmod eventually makes a call to kvm_apic_set_irq
> >> 4. In the local APIC, __apic_accept_irq does a part in setting up the need for service
> >> 5. Upon guest entry (vcpu_enter_guest), if there is no nmi and kvm_apic_has_interrupt, the host will call inject_pending_irq
> >> 6. inject_pending_irq calls vmx_inject_irq
> >>
> >> In attempting to answer the second part of your question, I realize this point isn't 100% clear to me either. It would seem the point at which the interrupt is delivered to KVM is always the point at which the guest VCPU is entered. Obviously, if you have a multi-cpu setup the calls to set up the local apic can be done in parallel to running the guest, but interrupt delivery won't happen until the vcpu is re-entered. This seems to mean that interrupts are only delivered when the guest is scheduled out and back in by the kernel. Is this right, guys?
> >
> > It means that interrupts are delivered on guest entries. That doesn't mean you have to exit the vcpu thread. You can just as well still be in the vcpu run loop.
> >
> > So if you for example get a #PF in the guest that is trapped by the host because of shadow paging, KVM will check for pending irqs again.
> >
> > Alex
> 
> 
> 
> -- 
> BestRegards.
> YangLiang
> _____________________________________________
>  Master Candidate.
>  Department of Computer Science .
>  School of Electronics Engineering & Computer Science .
> _____________________________________________
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
			Gleb.

      reply	other threads:[~2009-11-26  8:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-24  0:49 A puzzle on the interrupt disposal of KVM? Liang YANG
2009-11-24  7:05 ` Gleb Natapov
2009-11-24  8:03 ` Kurt Kiefer
2009-11-24  8:49   ` Alexander Graf
2009-11-26  7:14     ` Liang YANG
2009-11-26  8:06       ` Gleb Natapov [this message]

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=20091126080621.GX2999@redhat.com \
    --to=gleb@redhat.com \
    --cc=agraf@suse.de \
    --cc=brinewsor@gmail.com \
    --cc=kekiefer@gmail.com \
    --cc=kvm@vger.kernel.org \
    /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