Re: A question about how kvm switch context to guest
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 %%Rdx; push %%Rbp; push %%Rcx \n\t /* placeholder for guest rcx */ push %%Rcx \n\t cmp %%Rsp, %c[host_rsp](%0) \n\t je 1f \n\t mov %%Rsp, %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), %%Rax \n\t mov %%cr2, %%Rdx \n\t cmp %%Rax, %%Rdx \n\t je 2f \n\t mov %%Rax, %%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), %%Rax \n\t mov %c[rbx](%0), %%Rbx \n\t mov %c[rdx](%0), %%Rdx \n\t mov %c[rsi](%0), %%Rsi \n\t mov %c[rdi](%0), %%Rdi \n\t mov %c[rbp](%0), %%Rbp \n\t -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
A question about how kvm switch context to guest
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 %%Rdx; push %%Rbp; push %%Rcx \n\t /* placeholder for guest rcx */ push %%Rcx \n\t cmp %%Rsp, %c[host_rsp](%0) \n\t je 1f \n\t mov %%Rsp, %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), %%Rax \n\t mov %%cr2, %%Rdx \n\t cmp %%Rax, %%Rdx \n\t je 2f \n\t mov %%Rax, %%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), %%Rax \n\t mov %c[rbx](%0), %%Rbx \n\t mov %c[rdx](%0), %%Rdx \n\t mov %c[rsi](%0), %%Rsi \n\t mov %c[rdi](%0), %%Rdi \n\t mov %c[rbp](%0), %%Rbp \n\t Thanks, Zhengwang -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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. === asm( /* Store host registers */ push %%Rdx; push %%Rbp; push %%Rcx \n\t /* placeholder for guest rcx */ push %%Rcx \n\t cmp %%Rsp, %c[host_rsp](%0) \n\t je 1f \n\t mov %%Rsp, %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), %%Rax \n\t mov %%cr2, %%Rdx \n\t cmp %%Rax, %%Rdx \n\t je 2f \n\t mov %%Rax, %%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), %%Rax \n\t mov %c[rbx](%0), %%Rbx \n\t mov %c[rdx](%0), %%Rdx \n\t mov %c[rsi](%0), %%Rsi \n\t mov %c[rdi](%0), %%Rdi \n\t mov %c[rbp](%0), %%Rbp \n\t -- error compiling committee.c: too many arguments to function -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html