All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: Mohammed Gamal <m.gamal005@gmail.com>
Cc: avi@redhat.com, mtosatti@redhat.com, kvm@vger.kernel.org
Subject: Re: [RFC PATCH v2 2/4] x86: Add inject_realmode_interrupt() wrapper
Date: Sun, 15 Aug 2010 10:41:55 +0300	[thread overview]
Message-ID: <20100815074155.GQ10499@redhat.com> (raw)
In-Reply-To: <1281745181-4426-1-git-send-email-m.gamal005@gmail.com>

On Sat, Aug 14, 2010 at 03:19:39AM +0300, Mohammed Gamal wrote:
> This adds a wrapper function inject_realmode_interrupt() around the
> emulator function emulate_int_real() to allow real mode interrupt injection.
> 
> Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
> ---
>  arch/x86/kvm/x86.c |   33 +++++++++++++++++++++++++++++++++
>  arch/x86/kvm/x86.h |    1 +
>  2 files changed, 34 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 1722d37..d3ba1c3 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3936,6 +3936,39 @@ static void inject_emulated_exception(struct kvm_vcpu *vcpu)
>  		kvm_queue_exception(vcpu, ctxt->exception);
>  }
>  
> +int inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq)
> +{       
> +	struct decode_cache *c = &vcpu->arch.emulate_ctxt.decode;
> +	int cs_db, cs_l, ret;
> +	cache_all_regs(vcpu);
> +
> +	kvm_x86_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
> +
> +	vcpu->arch.emulate_ctxt.vcpu = vcpu;
> +	vcpu->arch.emulate_ctxt.eflags = kvm_x86_ops->get_rflags(vcpu);
> +	vcpu->arch.emulate_ctxt.eip = kvm_rip_read(vcpu);
> +	vcpu->arch.emulate_ctxt.mode =
> +		(!is_protmode(vcpu)) ? X86EMUL_MODE_REAL :
> +		(vcpu->arch.emulate_ctxt.eflags & X86_EFLAGS_VM)
> +		? X86EMUL_MODE_VM86 : cs_l
> +		? X86EMUL_MODE_PROT64 : cs_db
> +		? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16;
> +	memset(c, 0, sizeof(struct decode_cache));
> +	memcpy(c->regs, vcpu->arch.regs, sizeof c->regs);
> +
We have this code in 2 places already: kvm_task_switch() and emulate_instruction().
This will be the third one. Should be moved to separate function.

> +	ret = emulate_int_real(&vcpu->arch.emulate_ctxt, &emulate_ops, irq);
> +
> +	if (ret != X86EMUL_CONTINUE)
> +		return EMULATE_FAIL;
> +
> +	memcpy(vcpu->arch.regs, c->regs, sizeof c->regs);
> +	kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.eip);
> +	kvm_x86_ops->set_rflags(vcpu, vcpu->arch.emulate_ctxt.eflags);
> +
> +	return EMULATE_DONE;
> +}
> +EXPORT_SYMBOL_GPL(inject_realmode_interrupt);
> +
>  static int handle_emulation_failure(struct kvm_vcpu *vcpu)
>  {
>  	++vcpu->stat.insn_emulation_fail;
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index b7a4047..c6e8a4d 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -67,5 +67,6 @@ static inline int is_paging(struct kvm_vcpu *vcpu)
>  
>  void kvm_before_handle_nmi(struct kvm_vcpu *vcpu);
>  void kvm_after_handle_nmi(struct kvm_vcpu *vcpu);
> +int inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq);
>  
>  #endif
> -- 
> 1.7.0.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
			Gleb.

  parent reply	other threads:[~2010-08-15 16:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-14  0:19 [RFC PATCH v2 2/4] x86: Add inject_realmode_interrupt() wrapper Mohammed Gamal
2010-08-14  0:19 ` [RFC PATCH v2 3/4] VMX: Emulated real mode interrupt injection Mohammed Gamal
2010-08-14  0:19 ` [RFC PATCH v2 4/4] x86 emulator: Eagerly commit emulation ctxt eip in emulate_int_real() Mohammed Gamal
2010-08-15 12:42   ` Avi Kivity
2010-08-15  7:41 ` Gleb Natapov [this message]
2010-08-15 12:37 ` [RFC PATCH v2 2/4] x86: Add inject_realmode_interrupt() wrapper Avi Kivity

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=20100815074155.GQ10499@redhat.com \
    --to=gleb@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=m.gamal005@gmail.com \
    --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.