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 3 of 3] [POWERPC] Implement an ioctl that creates a vcpu of a	particular type
Date: Mon, 04 Feb 2008 23:34:34 -0600	[thread overview]
Message-ID: <e6e0239e8df55c6af4e0.1202189674@basalt> (raw)
In-Reply-To: <patchbomb.1202189671@basalt>

# HG changeset patch
# User Hollis Blanchard <hollisb-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
# Date 1202189668 21600
# Node ID e6e0239e8df55c6af4e0b2959350215aaa119254
# Parent  7dd50dab9096c8e0125792e3f48083c3f47fceab
The ioctl accepts a core name as input and calls kvm_vm_ioctl_create_vcpu()
with the corresponding "guest operations" structure. That structure, which
will be extended with additional core-specific function pointers, is saved into
the new vcpu by kvm_arch_vcpu_create().

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

---
3 files changed, 87 insertions(+), 3 deletions(-)
arch/powerpc/kvm/powerpc.c     |   77 ++++++++++++++++++++++++++++++++++++++--
include/asm-powerpc/kvm_host.h |    5 ++
include/linux/kvm.h            |    8 ++++


diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -460,13 +460,22 @@ int kvm_arch_set_memory_region(struct kv
 	return 0;
 }
 
+/* XXX Make modules register kvmppc_core_spec pointers at init. */
+static struct kvmppc_core_spec kvmppc_supported_guests[] = {
+	{
+		.name = "ppc440",
+		.vcpu_size = sizeof(struct kvm_vcpu),
+	},
+};
+
 struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id,
                                       void *opaque)
 {
+	struct kvmppc_core_spec *s = opaque;
 	struct kvm_vcpu *vcpu;
 	int err;
 
-	vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
+	vcpu = vmalloc(s->vcpu_size);
 	if (!vcpu) {
 		err = -ENOMEM;
 		goto out;
@@ -479,7 +488,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(st
 	return vcpu;
 
 free_vcpu:
-	kmem_cache_free(kvm_vcpu_cache, vcpu);
+	vfree(vcpu);
 out:
 	return ERR_PTR(err);
 }
@@ -487,7 +496,7 @@ void kvm_arch_vcpu_free(struct kvm_vcpu 
 void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu)
 {
 	kvm_vcpu_uninit(vcpu);
-	kmem_cache_free(kvm_vcpu_cache, vcpu);
+	vfree(vcpu);
 }
 
 void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
@@ -800,12 +809,74 @@ int kvm_vm_ioctl_get_dirty_log(struct kv
 	return -ENOTSUPP;
 }
 
+static struct kvmppc_core_spec *kvmppc_guest_type(char *coretype)
+{
+	struct kvmppc_core_spec *c = kvmppc_supported_guests;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(kvmppc_supported_guests); i++,c++)
+		if (strcmp(c->name, coretype))
+			return c;
+
+	return 0;
+}
+
+static long kvmppc_arch_vcpu_create_type(struct kvm *kvm,
+                                  struct kvm_vcpu_create_type __user *user_type)
+{
+	struct kvm_vcpu_create_type type;
+	struct kvmppc_core_spec *s;
+	char *coretype;
+	long r;
+
+	if (copy_from_user(&type, user_type, sizeof(type))) {
+		r = -EFAULT;
+		goto out;
+	}
+
+	if (type.typelen > 32) {
+		r = -E2BIG;
+		goto out;
+	}
+
+	coretype = vmalloc(type.typelen);
+	if (!coretype) {
+		r = -ENOMEM;
+		goto out;
+	}
+
+	if (copy_from_user(coretype, type.type, type.typelen)) {
+		r = -EFAULT;
+		goto out_free;
+	}
+	coretype[type.typelen-1] = '\0';
+
+	s = kvmppc_guest_type(coretype);
+	if (!s) {
+		r = -ENOTSUPP;
+		goto out_free;
+	}
+
+	r = kvm_vm_ioctl_create_vcpu(kvm, type.id, s);
+
+out_free:
+	vfree(coretype);
+out:
+	return r;
+}
+
 long kvm_arch_vm_ioctl(struct file *filp,
                        unsigned int ioctl, unsigned long arg)
 {
+	struct kvm *kvm = filp->private_data;
+	void __user *argp = (void __user *)arg;
 	long r;
 
 	switch (ioctl) {
+	case KVM_CREATE_VCPU_TYPE: {
+		r = kvmppc_arch_vcpu_create_type(kvm, argp);
+		break;
+	}
 	default:
 		r = -EINVAL;
 	}
diff --git a/include/asm-powerpc/kvm_host.h b/include/asm-powerpc/kvm_host.h
--- a/include/asm-powerpc/kvm_host.h
+++ b/include/asm-powerpc/kvm_host.h
@@ -49,6 +49,11 @@ struct tlbe {
 };
 
 struct kvm_arch {
+};
+
+struct kvmppc_core_spec {
+	const char *name;
+	unsigned int vcpu_size;
 };
 
 struct kvm_vcpu_arch {
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -211,6 +211,12 @@ struct kvm_vapic_addr {
 	__u64 vapic_addr;
 };
 
+struct kvm_vcpu_create_type {
+	__u32 id;
+	__u32 typelen;
+	char type[0];
+};
+
 #define KVMIO 0xAE
 
 /*
@@ -257,6 +263,8 @@ struct kvm_vapic_addr {
 #define KVM_GET_DIRTY_LOG         _IOW(KVMIO, 0x42, struct kvm_dirty_log)
 #define KVM_SET_MEMORY_ALIAS      _IOW(KVMIO, 0x43, struct kvm_memory_alias)
 #define KVM_GET_SUPPORTED_CPUID   _IOWR(KVMIO, 0x48, struct kvm_cpuid2)
+#define KVM_CREATE_VCPU_TYPE      _IOW(KVMIO,  0x49, struct kvm_vcpu_create_type)
+
 /* Device model IOC */
 #define KVM_CREATE_IRQCHIP	  _IO(KVMIO,  0x60)
 #define KVM_IRQ_LINE		  _IOW(KVMIO, 0x61, struct kvm_irq_level)

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

  parent reply	other threads:[~2008-02-05  5:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-05  5:34 [PATCH 0 of 3] RFC: creating a particular vcpu type Hollis Blanchard
2008-02-05  5:34 ` [PATCH 1 of 3] Pass an opaque parameter through kvm_vm_ioctl_vcpu_create() to kvm_arch_vcpu_create() Hollis Blanchard
2008-02-05  5:34 ` [PATCH 2 of 3] Export kvm_vm_ioctl_create_vcpu() to be called from architecture modules Hollis Blanchard
2008-02-05  5:34 ` Hollis Blanchard [this message]
2008-02-05 12:52   ` [PATCH 3 of 3] [POWERPC] Implement an ioctl that creates a vcpu of a particular type Christian Ehrhardt
     [not found]     ` <47A85C09.5070609-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2008-02-05 13:41       ` Carsten Otte
     [not found]         ` <47A86794.4020408-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2008-02-05 14:03           ` Carsten Otte
2008-02-05 15:13       ` Hollis Blanchard
2008-02-05 16:44 ` [PATCH 0 of 3] RFC: creating a particular vcpu type Anthony Liguori
     [not found]   ` <47A89285.40802-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-02-05 17:53     ` Hollis Blanchard
2008-02-05 18:05       ` Anthony Liguori
     [not found]         ` <47A8A582.5060502-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-02-05 19:23           ` Hollis Blanchard
2008-02-05 19:32             ` Anthony Liguori
2008-02-11  8:23               ` 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=e6e0239e8df55c6af4e0.1202189674@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