From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: [PATCH 5/9] Add VMLOAD and VMSAVE handlers v5 Date: Thu, 30 Oct 2008 13:06:11 -0500 Message-ID: <4909F793.4080404@codemonkey.ws> References: <1224522290-11740-1-git-send-email-agraf@suse.de> <1224522290-11740-2-git-send-email-agraf@suse.de> <1224522290-11740-3-git-send-email-agraf@suse.de> <1224522290-11740-4-git-send-email-agraf@suse.de> <1224522290-11740-5-git-send-email-agraf@suse.de> <1224522290-11740-6-git-send-email-agraf@suse.de> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, joro@8bytes.org, avi@redhat.com To: Alexander Graf Return-path: Received: from el-out-1112.google.com ([209.85.162.177]:45597 "EHLO el-out-1112.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753569AbYJ3SGQ (ORCPT ); Thu, 30 Oct 2008 14:06:16 -0400 Received: by el-out-1112.google.com with SMTP id z25so379569ele.1 for ; Thu, 30 Oct 2008 11:06:15 -0700 (PDT) In-Reply-To: <1224522290-11740-6-git-send-email-agraf@suse.de> Sender: kvm-owner@vger.kernel.org List-ID: Alexander Graf wrote: > This implements the VMLOAD and VMSAVE instructions, that usually surround > the VMRUN instructions. Both instructions load / restore the same elements, > so we only need to implement them once. > > v2 fixes CPL checking and replaces memcpy by assignments > v3 makes use of the new permission checking > > Signed-off-by: Alexander Graf > --- > arch/x86/kvm/svm.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 files changed, 58 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index eb301fe..10ad02b 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -1242,6 +1242,62 @@ static int nested_svm_do(struct vcpu_svm *svm, > return retval; > } > > +static int nested_svm_vmloadsave(struct vmcb *from_vmcb, struct vmcb *to_vmcb) > +{ > + to_vmcb->save.fs = from_vmcb->save.fs; > + to_vmcb->save.gs = from_vmcb->save.gs; > + to_vmcb->save.tr = from_vmcb->save.tr; > + to_vmcb->save.ldtr = from_vmcb->save.ldtr; > + to_vmcb->save.kernel_gs_base = from_vmcb->save.kernel_gs_base; > + to_vmcb->save.star = from_vmcb->save.star; > + to_vmcb->save.lstar = from_vmcb->save.lstar; > + to_vmcb->save.cstar = from_vmcb->save.cstar; > + to_vmcb->save.sfmask = from_vmcb->save.sfmask; > + to_vmcb->save.sysenter_cs = from_vmcb->save.sysenter_cs; > + to_vmcb->save.sysenter_esp = from_vmcb->save.sysenter_esp; > + to_vmcb->save.sysenter_eip = from_vmcb->save.sysenter_eip; > + > + return 1; > +} > + > +static int nested_svm_vmload(struct vcpu_svm *svm, void *nested_vmcb, > + void *arg2, void *opaque) > +{ > + return nested_svm_vmloadsave((struct vmcb *)nested_vmcb, svm->vmcb); > +} > + > +static int nested_svm_vmsave(struct vcpu_svm *svm, void *nested_vmcb, > + void *arg2, void *opaque) > +{ > + return nested_svm_vmloadsave(svm->vmcb, (struct vmcb *)nested_vmcb); > +} > + > +static int vmload_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) > +{ > + if (nested_svm_check_permissions(svm)) > + return 1; > + > + svm->next_rip = kvm_rip_read(&svm->vcpu) + 3; > + skip_emulated_instruction(&svm->vcpu); > + > + nested_svm_do(svm, svm->vmcb->save.rax, 0, NULL, nested_svm_vmload); > The whole trampoline thing seems awkward to me. I think it would be more reasonable to just open code this routine and use helper functions when appropriate. Regards, Anthony Liguori