From mboxrd@z Thu Jan 1 00:00:00 1970 From: Zhengwang Ruan Subject: Re: A question about how kvm switch context to guest Date: Wed, 04 Jul 2012 16:47:57 +0800 Message-ID: <4FF4033D.2040908@gmail.com> References: <4FF2C04C.2070206@gmail.com> <4FF2E1FD.1090506@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kashyapc@fedoraproject.org, kvm@vger.kernel.org To: Avi Kivity Return-path: Received: from mail-pb0-f46.google.com ([209.85.160.46]:59613 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750770Ab2GDIry (ORCPT ); Wed, 4 Jul 2012 04:47:54 -0400 Received: by pbbrp8 with SMTP id rp8so10710581pbb.19 for ; Wed, 04 Jul 2012 01:47:53 -0700 (PDT) In-Reply-To: <4FF2E1FD.1090506@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: -------- Original Message -------- =46rom: Avi Kivity Sent: 2012=E5=B9=B407=E6=9C=8804=E6=97=A5 =E6=98=9F=E6=9C=9F=E4=B8=89 1= 6=E6=97=B647=E5=88=8640=E7=A7=92 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 launc= h 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 > >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> >> 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" >> >