public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Amit Shah <amit.shah-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Subject: Re: [PATCH] Refactor hypercall infrastructure (v2)
Date: Sun, 2 Dec 2007 19:17:28 +0530	[thread overview]
Message-ID: <200712021917.28706.amit.shah@qumranet.com> (raw)
In-Reply-To: <11898788932902-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

* Anthony Liguori wrote:
> This patch refactors the current hypercall infrastructure to better support
> live migration and SMP.  It eliminates the hypercall page by trapping the
> UD exception that would occur if you used the wrong hypercall instruction
> for the underlying architecture and replacing it with the right one lazily.

This doesn't work right for SVM. It keeps looping indefinitely; on a kvm_stat 
run, I get about 230,000 light vm exits per second, with the hypercall never 
returning to the guest.

...

> diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
> index 729f1cd..d09a9f5 100644
> --- a/drivers/kvm/svm.c
> +++ b/drivers/kvm/svm.c
> @@ -476,7 +476,8 @@ static void init_vmcb(struct vmcb *vmcb)
>  					INTERCEPT_DR5_MASK |
>  					INTERCEPT_DR7_MASK;
>
> -	control->intercept_exceptions = 1 << PF_VECTOR;
> +	control->intercept_exceptions = (1 << PF_VECTOR) |
> +					(1 << UD_VECTOR);
>
>
>  	control->intercept = 	(1ULL << INTERCEPT_INTR) |
> @@ -970,6 +971,17 @@ static int pf_interception(struct vcpu_svm *svm,
> struct kvm_run *kvm_run) return 0;
>  }
>
> +static int ud_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
> +{
> +	int er;
> +
> +	er = emulate_instruction(&svm->vcpu, kvm_run, 0, 0);
> +	if (er != EMULATE_DONE)
> +		inject_ud(&svm->vcpu);
> +
> +	return 1;
> +}
> +
>  static int nm_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
>  {
>  	svm->vmcb->control.intercept_exceptions &= ~(1 << NM_VECTOR);
> @@ -1036,7 +1048,8 @@ static int vmmcall_interception(struct vcpu_svm *svm,
> struct kvm_run *kvm_run) {
>  	svm->next_rip = svm->vmcb->save.rip + 3;
>  	skip_emulated_instruction(&svm->vcpu);
> -	return kvm_hypercall(&svm->vcpu, kvm_run);
> +	kvm_emulate_hypercall(&svm->vcpu);
> +	return 1;
>  }
>
>  static int invalid_op_interception(struct vcpu_svm *svm,
> @@ -1232,6 +1245,7 @@ static int (*svm_exit_handlers[])(struct vcpu_svm
> *svm, [SVM_EXIT_WRITE_DR3]			= emulate_on_interception,
>  	[SVM_EXIT_WRITE_DR5]			= emulate_on_interception,
>  	[SVM_EXIT_WRITE_DR7]			= emulate_on_interception,
> +	[SVM_EXIT_EXCP_BASE + UD_VECTOR]	= ud_interception,
>  	[SVM_EXIT_EXCP_BASE + PF_VECTOR] 	= pf_interception,
>  	[SVM_EXIT_EXCP_BASE + NM_VECTOR] 	= nm_interception,
>  	[SVM_EXIT_INTR] 			= nop_on_interception,
> @@ -1664,7 +1678,6 @@ svm_patch_hypercall(struct kvm_vcpu *vcpu, unsigned
> char *hypercall) hypercall[0] = 0x0f;
>  	hypercall[1] = 0x01;
>  	hypercall[2] = 0xd9;
> -	hypercall[3] = 0xc3;
>  }

...

> +/* This instruction is vmcall.  On non-VT architectures, it will generate
> a + * trap that we will then rewrite to the appropriate instruction. */
> -#define __NR_hypercalls			0
> +#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"

.. which never happens.

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4

  parent reply	other threads:[~2007-12-02 13:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-15 17:54 [PATCH] Refactor hypercall infrastructure (v2) Anthony Liguori
     [not found] ` <11898788932902-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-09-15 17:54   ` [PATCH] Add the paravirtualization CPUID entry to QEMU (v2) Anthony Liguori
2007-09-16  9:08   ` [PATCH] Refactor hypercall infrastructure (v2) Avi Kivity
2007-12-02 13:47   ` Amit Shah [this message]
     [not found]     ` <200712021917.28706.amit.shah-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-02 14:32       ` Avi Kivity
2007-12-02 23:03       ` Anthony Liguori
     [not found]         ` <475339A6.9020207-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-12-03  8:46           ` Amit Shah
     [not found]             ` <200712031416.51710.amit.shah-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-03  9:00               ` Avi Kivity
     [not found]                 ` <4753C59A.4030206-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-03 11:30                   ` Amit Shah

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=200712021917.28706.amit.shah@qumranet.com \
    --to=amit.shah-atkuwr5tajbwk0htik3j/w@public.gmane.org \
    --cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox