kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* A question about how kvm switch context to guest
@ 2012-07-03  9:50 Zhengwang Ruan
  2012-07-03 12:13 ` Avi Kivity
  0 siblings, 1 reply; 3+ messages in thread
From: Zhengwang Ruan @ 2012-07-03  9:50 UTC (permalink / raw)
  To: kashyapc; +Cc: kvm

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: A question about how kvm switch context to guest
  2012-07-03  9:50 A question about how kvm switch context to guest Zhengwang Ruan
@ 2012-07-03 12:13 ` Avi Kivity
  2012-07-04  8:47   ` Zhengwang Ruan
  0 siblings, 1 reply; 3+ messages in thread
From: Avi Kivity @ 2012-07-03 12:13 UTC (permalink / raw)
  To: Zhengwang Ruan; +Cc: kashyapc, kvm

On 07/03/2012 12:50 PM, Zhengwang Ruan wrote:
> 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?

You trimmed the bit that contains vmlaunch/vmresume.

 Why does kvm need to manually  switch context by filling
> registers using stored register copies?

Those registers don't get automatically switched by the hardware.

> 
> ===============
> 
> 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"
> 


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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: A question about how kvm switch context to guest
  2012-07-03 12:13 ` Avi Kivity
@ 2012-07-04  8:47   ` Zhengwang Ruan
  0 siblings, 0 replies; 3+ messages in thread
From: Zhengwang Ruan @ 2012-07-04  8:47 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kashyapc, kvm




-------- Original Message --------
From: Avi Kivity
Sent: 2012年07月04日 星期三 16时47分40秒
To: Zhengwang Ruan
Subject: Re: A question about how kvm switch context to guest
> On 07/03/2012 12:50 PM, Zhengwang Ruan wrote:
>> 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?
> You trimmed the bit that contains vmlaunch/vmresume.
>
>   Why does kvm need to manually  switch context by filling
>> registers using stored register copies?
> Those registers don't get automatically switched by the hardware.

Avi,

got it! thank you!

Regards,

Zhengwang
>
>> ===============
>>
>> 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"
>>
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-04  8:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-03  9:50 A question about how kvm switch context to guest Zhengwang Ruan
2012-07-03 12:13 ` Avi Kivity
2012-07-04  8:47   ` Zhengwang Ruan

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).