kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhengwang Ruan <ruan.zhengwang@gmail.com>
To: kashyapc@fedoraproject.org
Cc: kvm@vger.kernel.org
Subject: A question about how kvm switch context to guest
Date: Tue, 03 Jul 2012 17:50:04 +0800	[thread overview]
Message-ID: <4FF2C04C.2070206@gmail.com> (raw)

Hi kashyapc & all,

I see a piece of code in vmx_vcpu_run as below, is it used to switch 
context to a guest? Kvm don't used "vmlaunch" or "vmresume" to launch or 
resume a guest? Why does kvm need to manually  switch context by filling 
registers using stored register copies?

===============

asm(
         /* Store host registers */
         "push %%"R"dx; push %%"R"bp;"
         "push %%"R"cx \n\t" /* placeholder for guest rcx */
         "push %%"R"cx \n\t"
         "cmp %%"R"sp, %c[host_rsp](%0) \n\t"
         "je 1f \n\t"
         "mov %%"R"sp, %c[host_rsp](%0) \n\t"
         __ex(ASM_VMX_VMWRITE_RSP_RDX) "\n\t"
         "1: \n\t"
         /* Reload cr2 if changed */
         "mov %c[cr2](%0), %%"R"ax \n\t"
         "mov %%cr2, %%"R"dx \n\t"
         "cmp %%"R"ax, %%"R"dx \n\t"
         "je 2f \n\t"
         "mov %%"R"ax, %%cr2 \n\t"
         "2: \n\t"
         /* Check if vmlaunch of vmresume is needed */
         "cmpl $0, %c[launched](%0) \n\t"
         /* Load guest registers.  Don't clobber flags. */
         "mov %c[rax](%0), %%"R"ax \n\t"
         "mov %c[rbx](%0), %%"R"bx \n\t"
         "mov %c[rdx](%0), %%"R"dx \n\t"
         "mov %c[rsi](%0), %%"R"si \n\t"
         "mov %c[rdi](%0), %%"R"di \n\t"
         "mov %c[rbp](%0), %%"R"bp \n\t"

========

Thanks,

Zhengwang


             reply	other threads:[~2012-07-03  9:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-03  9:50 Zhengwang Ruan [this message]
2012-07-03 12:13 ` A question about how kvm switch context to guest Avi Kivity
2012-07-04  8:47   ` Zhengwang Ruan

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=4FF2C04C.2070206@gmail.com \
    --to=ruan.zhengwang@gmail.com \
    --cc=kashyapc@fedoraproject.org \
    --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;
as well as URLs for NNTP newsgroup(s).