All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/7] KVM: VMX: relax check for CS register in rmode_segment_valid()
Date: Sat, 22 Dec 2012 09:02:41 +0200	[thread overview]
Message-ID: <20121222070241.GT29007@redhat.com> (raw)
In-Reply-To: <20121221231715.GA30710@amt.cnet>

On Fri, Dec 21, 2012 at 09:17:16PM -0200, Marcelo Tosatti wrote:
> On Wed, Dec 12, 2012 at 07:10:50PM +0200, Gleb Natapov wrote:
> > rmode_segment_valid() checks if segment descriptor can be used to enter
> > vm86 mode. VMX spec mandates that in vm86 mode CS register will be of
> > type data, not code. Lets allow guest entry with vm86 mode if the only
> > problem with CS register is incorrect type. Otherwise entire real mode
> > will be emulated.
> > 
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
> > ---
> >  arch/x86/kvm/vmx.c |    2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> > index 4df3991..acbe86f 100644
> > --- a/arch/x86/kvm/vmx.c
> > +++ b/arch/x86/kvm/vmx.c
> > @@ -3383,6 +3383,8 @@ static bool rmode_segment_valid(struct kvm_vcpu *vcpu, int seg)
> >  	var.dpl = 0x3;
> >  	var.g = 0;
> >  	var.db = 0;
> > +	if (seg == VCPU_SREG_CS)
> > +		var.type = 0x3;
> >  	ar = vmx_segment_access_rights(&var);
> >  
> >  	if (var.base != (var.selector << 4))
> > -- 
> > 1.7.10.4
> 
> But with emulate_invalid_guest_state=1, segments are not fixed on 
> transition to real mode. So this patch can result in 
> invalid guest state entry failure.
> 
At the point of this patch emulate_invalid_guest_state=1 is broken and
sate is fixed unconditionally during the call to vmx_set_segment(). See
big switch at the end of the function there. Note that here
rmode_segment_valid() does not check register properly anyway. It ignores
db value and allow guest entry with limit > 0xffff.  My patches fixes
this. After the patches are applied rmode_segment_valid() still relax
dpl and CS.type check:

	var.dpl = 0x3;
  	if (seg == VCPU_SREG_CS)
   		var.type = 0x3;

but fix_rmode_seg() unconditionally does exactly same:

        var.dpl = 0x3;
        if (seg == VCPU_SREG_CS)
                var.type = 0x3;

> Does this defeat the purpose of emulate_invalid_guest_state=1?
No since changing dpl to 3 and segment register type to 3 does not
affect instruction execution in vm86 mode, so entering vcpu in vm86
mode or fully emulate all instruction will yield exactly same result
no matter what instructions are executed. If we do not relax this check
in rmode_segment_valid() all real mode will be fully emulated because
no guest ever configure CS register to data type and set DPL of all
segments to 3 before entering real mode.

--
			Gleb.

  reply	other threads:[~2012-12-22  7:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-12 17:10 [PATCH 0/7] Fix emulate_invalid_guest_state=0 part 2 Gleb Natapov
2012-12-12 17:10 ` [PATCH 1/7] KVM: VMX: cleanup rmode_segment_valid() Gleb Natapov
2012-12-12 17:10 ` [PATCH 2/7] KVM: VMX: relax check for CS register in rmode_segment_valid() Gleb Natapov
2012-12-21 23:17   ` Marcelo Tosatti
2012-12-22  7:02     ` Gleb Natapov [this message]
2012-12-22 14:55       ` Marcelo Tosatti
2012-12-22 14:58         ` Marcelo Tosatti
2012-12-12 17:10 ` [PATCH 3/7] KVM: VMX: return correct segment limit and flags for CS/SS registers in real mode Gleb Natapov
2012-12-12 17:10 ` [PATCH 4/7] KVM: VMX: use fix_rmode_seg() to fix all code/data segments Gleb Natapov
2012-12-12 17:10 ` [PATCH 5/7] KVM: VMX: remove redundant code from vmx_set_segment() Gleb Natapov
2012-12-12 17:10 ` [PATCH 6/7] KVM: VMX: clean-up vmx_set_segment() Gleb Natapov
2012-12-12 17:10 ` [PATCH 7/7] KVM: VMX: remove unneeded temporary variable from vmx_set_segment() Gleb Natapov
2012-12-21 23:55 ` [PATCH 0/7] Fix emulate_invalid_guest_state=0 part 2 Marcelo Tosatti
2012-12-22  7:05   ` Gleb Natapov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121222070241.GT29007@redhat.com \
    --to=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.