All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sheng Yang <sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
To: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH 2/2] KVM: x86 emulator: Discard CR2 in x86 emulator
Date: Fri, 16 Nov 2007 10:28:09 +0800	[thread overview]
Message-ID: <200711161028.09501.sheng.yang@intel.com> (raw)
In-Reply-To: <473C1C38.4000700-atKUWr5tajBWk0Htik3J/w@public.gmane.org>

On Thursday 15 November 2007 18:15:20 Avi Kivity wrote:
> Sheng Yang wrote:
> > From 9cd9d5cde7341d5e9de41b1070cea7a98e7d8cc9 Mon Sep 17 00:00:00 2001
> > From: Sheng Yang <sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> > Date: Thu, 15 Nov 2007 15:11:58 +0800
> > Subject: [PATCH 2/2] KVM: x86 emulator: Discard CR2 in x86 emulator
> >
> > For CR2 is unreliable and unavailable in many condition, this patch
> > completely decode memory operand instead of using CR2 in x86 emulator.
>
> One of my innermost wishes...
>
> > diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
> > index aa6c3d8..85a0776 100644
> > --- a/drivers/kvm/x86.c
> > +++ b/drivers/kvm/x86.c
> > @@ -1293,7 +1293,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
> >
> >  		vcpu->emulate_ctxt.vcpu = vcpu;
> >  		vcpu->emulate_ctxt.eflags = kvm_x86_ops->get_rflags(vcpu);
> > -		vcpu->emulate_ctxt.cr2 = cr2;
> > +		vcpu->emulate_ctxt.memop = 0;
>
> We have c->modrm_ea which can be used for the memory operand.

I don't think using the name modrm_ea is good for explicit encoding, so I add 
this. But I am think of is it better to be in decode_cache?

>
> > diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
> > index c020010..95536a8 100644
> > --- a/drivers/kvm/x86_emulate.c
> > +++ b/drivers/kvm/x86_emulate.c
> > @@ -880,6 +880,8 @@ done_prefixes:
> >  			break;
> >  		}
> >  		c->src.type = OP_MEM;
> > +		ctxt->memop = insn_fetch(u32, c->src.bytes, c->eip);
> > +		c->eip -= c->src.bytes; /* keep the page fault ip */
>
> I don't understand this.  In the cases where the memory operand address
> is encoded in the instruction, we fetch it explicity.  When it isn't,
> this is broken.

But we mark implicit encoding instructions as "ImplicitOps", so only explicit 
ones should get here. And my former patch deal with the implicit ones, and 
modrm_ea has priority to memop, so I think it's OK.

Maybe add  a judgment of modrm_ea here is better.

>
> >  		break;
> >  	case SrcImm:
> >  		c->src.type = OP_IMM;
> > @@ -918,14 +920,18 @@ done_prefixes:
> >  			 c->twobyte && (c->b == 0xb6 || c->b == 0xb7));
> >  		break;
> >  	case DstMem:
> > +		c->dst.bytes = (c->d & ByteOp) ? 1 : c->op_bytes;
>
> This seems unrelated; needs a separate patch.  Please check that movzx
> and movsx aren't affected by this.

I need this for following insn_fetch(). And movzx/movsx is marked as DstReg, 
so they won't get here.

>
> >  		/*
> >  		 * For instructions with a ModR/M byte, switch to register
> >  		 * access if Mod = 3.
> >  		 */
> > -		if ((c->d & ModRM) && c->modrm_mod == 3)
> > +		if ((c->d & ModRM) && c->modrm_mod == 3) {
> >  			c->dst.type = OP_REG;
> > -		else
> > -			c->dst.type = OP_MEM;
> > +			break;
> > +		}
> > +		c->dst.type = OP_MEM;
> > +		ctxt->memop = insn_fetch(u32, c->dst.bytes, c->eip);
> > +		c->eip -= c->dst.bytes; /* keep the page fault ip */
>
> Ditto.



-- 
Thanks
Yang, Sheng

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

  parent reply	other threads:[~2007-11-16  2:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-15  7:32 [PATCH 2/2] KVM: x86 emulator: Discard CR2 in x86 emulator Sheng Yang
     [not found] ` <200711151532.20558.sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2007-11-15 10:15   ` Avi Kivity
     [not found]     ` <473C1C38.4000700-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-16  2:28       ` Sheng Yang [this message]
     [not found]         ` <200711161028.09501.sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2007-11-16  6:41           ` Avi Kivity
     [not found]             ` <473D3BAE.1050207-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-11-16  7:37               ` Sheng Yang

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=200711161028.09501.sheng.yang@intel.com \
    --to=sheng.yang-ral2jqcrhueavxtiumwx3w@public.gmane.org \
    --cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /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.