From mboxrd@z Thu Jan 1 00:00:00 1970 From: Zhengwang Ruan Subject: A question about how kvm switch context to guest Date: Tue, 03 Jul 2012 17:50:04 +0800 Message-ID: <4FF2C04C.2070206@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: kashyapc@fedoraproject.org Return-path: Received: from mail-yw0-f51.google.com ([209.85.213.51]:50031 "EHLO mail-yw0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752408Ab2GCJuD (ORCPT ); Tue, 3 Jul 2012 05:50:03 -0400 Received: by yhnn12 with SMTP id n12so7000338yhn.10 for ; Tue, 03 Jul 2012 02:50:02 -0700 (PDT) Sender: kvm-owner@vger.kernel.org List-ID: 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