From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH] kvm-unit-tests: VMX: Separate host and guest rflags Date: Wed, 07 Aug 2013 17:37:16 +0200 Message-ID: <520269AC.8020103@redhat.com> References: <1375706605-14980-1-git-send-email-yzt356@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, jan.kiszka@web.de, gleb@redhat.com To: kvm@vger.kernel.org Return-path: Received: from plane.gmane.org ([80.91.229.3]:49654 "EHLO plane.gmane.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756720Ab3HGPhc (ORCPT ); Wed, 7 Aug 2013 11:37:32 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1V75nn-0002HV-P5 for kvm@vger.kernel.org; Wed, 07 Aug 2013 17:37:31 +0200 Received: from net-2-39-8-162.cust.dsl.vodafone.it ([2.39.8.162]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 07 Aug 2013 17:37:31 +0200 Received: from pbonzini by net-2-39-8-162.cust.dsl.vodafone.it with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 07 Aug 2013 17:37:31 +0200 In-Reply-To: <1375706605-14980-1-git-send-email-yzt356@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On 08/05/2013 02:43 PM, Arthur Chunqi Li wrote: > Separate host_rflags and guest_rflags (regs.rflags used for guest). > Fix bug of set/get guest rflags when vmenter/vmexit. > > Signed-off-by: Arthur Chunqi Li Applied, thanks. Not putting it on the stack is fine, but please do a followup patch to define vmx.c-private variables as "static" (as soon as I push the patches to kernel.org). Paolo > --- > x86/vmx.c | 11 +++++++---- > x86/vmx.h | 4 ++-- > 2 files changed, 9 insertions(+), 6 deletions(-) > > diff --git a/x86/vmx.c b/x86/vmx.c > index 7467927..7b28aca 100644 > --- a/x86/vmx.c > +++ b/x86/vmx.c > @@ -19,6 +19,7 @@ struct regs regs; > struct vmx_test *current; > u64 hypercall_field = 0; > bool launched; > +u64 host_rflags; > > extern u64 gdt64_desc[]; > extern u64 idt_descr[]; > @@ -440,12 +441,14 @@ static int exit_handler() > int ret; > > current->exits++; > + regs.rflags = vmcs_read(GUEST_RFLAGS); > current->guest_regs = regs; > if (is_hypercall()) > ret = handle_hypercall(); > else > ret = current->exit_handler(); > regs = current->guest_regs; > + vmcs_write(GUEST_RFLAGS, regs.rflags); > switch (ret) { > case VMX_TEST_VMEXIT: > case VMX_TEST_RESUME: > @@ -505,15 +508,15 @@ static int vmx_run() > return 0; > case VMX_TEST_LAUNCH_ERR: > printf("%s : vmlaunch failed.\n", __func__); > - if ((!(regs.rflags & X86_EFLAGS_CF) && !(regs.rflags & X86_EFLAGS_ZF)) > - || ((regs.rflags & X86_EFLAGS_CF) && (regs.rflags & X86_EFLAGS_ZF))) > + if ((!(host_rflags & X86_EFLAGS_CF) && !(host_rflags & X86_EFLAGS_ZF)) > + || ((host_rflags & X86_EFLAGS_CF) && (host_rflags & X86_EFLAGS_ZF))) > printf("\tvmlaunch set wrong flags\n"); > report("test vmlaunch", 0); > break; > case VMX_TEST_RESUME_ERR: > printf("%s : vmresume failed.\n", __func__); > - if ((!(regs.rflags & X86_EFLAGS_CF) && !(regs.rflags & X86_EFLAGS_ZF)) > - || ((regs.rflags & X86_EFLAGS_CF) && (regs.rflags & X86_EFLAGS_ZF))) > + if ((!(host_rflags & X86_EFLAGS_CF) && !(host_rflags & X86_EFLAGS_ZF)) > + || ((host_rflags & X86_EFLAGS_CF) && (host_rflags & X86_EFLAGS_ZF))) > printf("\tvmresume set wrong flags\n"); > report("test vmresume", 0); > break; > diff --git a/x86/vmx.h b/x86/vmx.h > index 1fb9738..d4f979c 100644 > --- a/x86/vmx.h > +++ b/x86/vmx.h > @@ -403,10 +403,10 @@ enum Ctrl1 { > > #define SAVE_RFLAGS \ > "pushf\n\t" \ > - "pop regs+0x80\n\t" > + "pop host_rflags\n\t" > > #define LOAD_RFLAGS \ > - "push regs+0x80\n\t" \ > + "push host_rflags\n\t" \ > "popf\n\t" > > #define VMX_IO_SIZE_MASK 0x7 >