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 14:04:31 +0200 Message-ID: <20120130120431.GF23536@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> <20120130105658.GD23536@redhat.com> <4F2686C6.6050100@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]:37574 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752520Ab2A3MEf (ORCPT ); Mon, 30 Jan 2012 07:04:35 -0500 Content-Disposition: inline In-Reply-To: <4F2686C6.6050100@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Jan 30, 2012 at 02:02:14PM +0200, Avi Kivity wrote: > On 01/30/2012 12:56 PM, Gleb Natapov wrote: > > 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. > > There aren't any possible errors until that point. But we don't want > set_segment_selector() to use the new mode, it just changes the segment > selectors, nothing else. > I agree with that set_segment_selector() part, but load_segment_descriptor() happens on a new task. -- Gleb.