From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gleb Natapov Subject: Re: [PATCH v2 3/3] KVM: x86 emulator: Allow PM/VM86 switch during task switch Date: Mon, 30 Jan 2012 12:56:58 +0200 Message-ID: <20120130105658.GD23536@redhat.com> References: <1327692216-20450-1-git-send-email-kwolf@redhat.com> <1327692216-20450-4-git-send-email-kwolf@redhat.com> <4F266FCB.3000102@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Kevin Wolf , kvm@vger.kernel.org, joerg.roedel@amd.com, yoshikawa.takuya@oss.ntt.co.jp, mtosatti@redhat.com To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:27939 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751794Ab2A3K5D (ORCPT ); Mon, 30 Jan 2012 05:57:03 -0500 Content-Disposition: inline In-Reply-To: <4F266FCB.3000102@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Jan 30, 2012 at 12:24:11PM +0200, Avi Kivity wrote: > > + > > ctxt->ops->set_segment(ctxt, selector, &desc, base3, seg); > > } > > > > @@ -2273,6 +2281,24 @@ static int load_state_from_tss32(struct x86_emulate_ctxt *ctxt, > > return emulate_gp(ctxt, 0); > > ctxt->_eip = tss->eip; > > ctxt->eflags = tss->eflags | 2; > > + > > + /* > > + * If we're switching between Protected Mode and VM86, we need to make > > + * sure to update the mode before loading the segment descriptors so > > + * that the selectors are interpreted correctly. > > + * > > + * Need to get it to the vcpu struct immediately because it influences > > + * the CPL which is checked at least when loading the segment > > + * descriptors and when pushing an error code to the new kernel stack. > > + */ > > + if (ctxt->eflags & X86_EFLAGS_VM) > > + ctxt->mode = X86EMUL_MODE_VM86; > > + else > > + ctxt->mode = X86EMUL_MODE_PROT32; > > + > > Shouldn't this be done after the set_segment_selector() block? My > interpretation of the SDM is that if a fault happens while loading > descriptors the fault happens with old segment cache, that is, it needs > to be interpreted according to the old mode. > No, spec says: Any errors associated with this loading and qualification occur in the context of the new task. -- Gleb.