public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Hollis Blanchard <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	kvm-ppc-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: [PATCH 2 of 2] RFC: Create kvm_arch_vcpu_create()
Date: Wed, 31 Oct 2007 17:57:29 -0500	[thread overview]
Message-ID: <56775a77643bc9979cf7.1193871449@basalt> (raw)
In-Reply-To: <patchbomb.1193871447@basalt>

3 files changed, 43 insertions(+), 20 deletions(-)
drivers/kvm/kvm.h      |    3 +++
drivers/kvm/kvm_main.c |   24 ++++--------------------
drivers/kvm/x86.c      |   36 ++++++++++++++++++++++++++++++++++++


Create kvm_arch_vcpu_create(), moving more x86 code out of kvm_main.c.

Old code flow (from patch 1):
	kvm_vm_ioctl_create_vcpu()
	kvm_x86_ops->vcpu_create()
	kvm_x86_vcpu_init()
	kvm_vcpu_init()

New code flow:
	kvm_vm_ioctl_create_vcpu()
	kvm_arch_vcpu_create()
	kvm_x86_ops->vcpu_create()
	kvm_x86_vcpu_init()
	kvm_vcpu_init()

Only build-tested, and the error-handling paths are a little tricky! Comments?

Signed-off-by: Hollis Blanchard <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -490,6 +490,9 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu,
 int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);
 void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
 
+struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, int n);
+void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu);
+
 int kvm_x86_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);
 void kvm_x86_vcpu_uninit(struct kvm_vcpu *vcpu);
 
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -852,28 +852,17 @@ static int kvm_vm_ioctl_create_vcpu(stru
 	if (!valid_vcpu(n))
 		return -EINVAL;
 
-	vcpu = kvm_x86_ops->vcpu_create(kvm, n);
+	vcpu = kvm_arch_vcpu_create(kvm, n);
 	if (IS_ERR(vcpu))
 		return PTR_ERR(vcpu);
 
 	preempt_notifier_init(&vcpu->preempt_notifier, &kvm_preempt_ops);
-
-	/* We do fxsave: this must be aligned. */
-	BUG_ON((unsigned long)&vcpu->host_fx_image & 0xF);
-
-	vcpu_load(vcpu);
-	r = kvm_x86_ops->vcpu_reset(vcpu);
-	if (r == 0)
-		r = kvm_mmu_setup(vcpu);
-	vcpu_put(vcpu);
-	if (r < 0)
-		goto free_vcpu;
 
 	mutex_lock(&kvm->lock);
 	if (kvm->vcpus[n]) {
 		r = -EEXIST;
 		mutex_unlock(&kvm->lock);
-		goto mmu_unload;
+		goto destroy_vcpu;
 	}
 	kvm->vcpus[n] = vcpu;
 	mutex_unlock(&kvm->lock);
@@ -889,13 +878,8 @@ unlink:
 	kvm->vcpus[n] = NULL;
 	mutex_unlock(&kvm->lock);
 
-mmu_unload:
-	vcpu_load(vcpu);
-	kvm_mmu_unload(vcpu);
-	vcpu_put(vcpu);
-
-free_vcpu:
-	kvm_x86_ops->vcpu_free(vcpu);
+destroy_vcpu:
+	kvm_arch_vcpu_destroy(vcpu);
 	return r;
 }
 
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -2377,3 +2377,39 @@ void kvm_x86_vcpu_uninit(struct kvm_vcpu
 	free_page((unsigned long)vcpu->pio_data);
 }
 EXPORT_SYMBOL_GPL(kvm_x86_vcpu_uninit);
+
+struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, int n)
+{
+	struct kvm_vcpu *vcpu;
+	int r;
+
+	vcpu = kvm_x86_ops->vcpu_create(kvm, n);
+	if (IS_ERR(vcpu))
+		return vcpu;
+
+	/* We do fxsave: this must be aligned. */
+	BUG_ON((unsigned long)&vcpu->host_fx_image & 0xF);
+
+	vcpu_load(vcpu);
+	r = kvm_x86_ops->vcpu_reset(vcpu);
+	if (r == 0)
+		r = kvm_mmu_setup(vcpu);
+	vcpu_put(vcpu);
+	if (r < 0)
+		goto free_vcpu;
+
+	return vcpu;
+
+free_vcpu:
+	kvm_x86_ops->vcpu_free(vcpu);
+	return ERR_PTR(r);
+}
+
+void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
+{
+	vcpu_load(vcpu);
+	kvm_mmu_unload(vcpu);
+	vcpu_put(vcpu);
+
+	kvm_x86_ops->vcpu_free(vcpu);
+}

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

  parent reply	other threads:[~2007-10-31 22:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-31 22:57 [PATCH 0 of 2] Refactor vcpu creation path Hollis Blanchard
2007-10-31 22:57 ` [PATCH 1 of 2] RFC: Create kvm_x86_vcpu_init() Hollis Blanchard
2007-10-31 22:57 ` Hollis Blanchard [this message]
2007-11-01 13:20 ` [PATCH 0 of 2] Refactor vcpu creation path 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=56775a77643bc9979cf7.1193871449@basalt \
    --to=hollisb-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=kvm-ppc-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox