diff mbox

[6/8] provide env->kvm_fd

Message ID 1247058542-31211-7-git-send-email-glommer@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Glauber Costa July 8, 2009, 1:09 p.m. UTC
qemu upstream puts kvm information on env. Do that too, since it will
allow us to use CPUState in cpu-specific functions, instead of kvm-specific
types.

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 kvm-all.c    |   12 ++++++++----
 libkvm-all.h |   12 ------------
 2 files changed, 8 insertions(+), 16 deletions(-)

Comments

Gleb Natapov July 8, 2009, 1:32 p.m. UTC | #1
On Wed, Jul 08, 2009 at 09:09:00AM -0400, Glauber Costa wrote:
> qemu upstream puts kvm information on env. Do that too, since it will
> allow us to use CPUState in cpu-specific functions, instead of kvm-specific
> types.
> 
> Signed-off-by: Glauber Costa <glommer@redhat.com>
> ---
>  kvm-all.c    |   12 ++++++++----
>  libkvm-all.h |   12 ------------
>  2 files changed, 8 insertions(+), 16 deletions(-)
> 
> diff --git a/kvm-all.c b/kvm-all.c
> index 15bd429..b404f76 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -1519,21 +1519,25 @@ void kvm_disable_pit_creation(kvm_context_t kvm)
>  	kvm->no_pit_creation = 1;
>  }
>  
> -kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, int id)
> +static kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, CPUState *env)
>  {
>  	long mmap_size;
>  	int r;
>  	kvm_vcpu_context_t vcpu_ctx = qemu_malloc(sizeof(struct kvm_vcpu_context));
>  
>  	vcpu_ctx->kvm = kvm;
> -	vcpu_ctx->id = id;
> +	vcpu_ctx->id = env->cpu_index;
>  
> -	r = ioctl(kvm->vm_fd, KVM_CREATE_VCPU, id);
> +	r = ioctl(kvm->vm_fd, KVM_CREATE_VCPU, env->cpu_index);
This just reverts all my work to separate apic_id from env->cpu_index.
We want to bring good things from qemu-kvm to upstream not bad things
from upstream to qemu-kvm :) If anything you should use env->cpuid_apic_id
instead of env->cpu_index here.


--
			Gleb.
--
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 Natapov July 8, 2009, 1:38 p.m. UTC | #2
On Wed, Jul 08, 2009 at 10:44:01AM -0300, Glauber Costa wrote:
> On Wed, Jul 08, 2009 at 04:32:37PM +0300, Gleb Natapov wrote:
> > On Wed, Jul 08, 2009 at 09:09:00AM -0400, Glauber Costa wrote:
> > > qemu upstream puts kvm information on env. Do that too, since it will
> > > allow us to use CPUState in cpu-specific functions, instead of kvm-specific
> > > types.
> > > 
> > > Signed-off-by: Glauber Costa <glommer@redhat.com>
> > > ---
> > >  kvm-all.c    |   12 ++++++++----
> > >  libkvm-all.h |   12 ------------
> > >  2 files changed, 8 insertions(+), 16 deletions(-)
> > > 
> > > diff --git a/kvm-all.c b/kvm-all.c
> > > index 15bd429..b404f76 100644
> > > --- a/kvm-all.c
> > > +++ b/kvm-all.c
> > > @@ -1519,21 +1519,25 @@ void kvm_disable_pit_creation(kvm_context_t kvm)
> > >  	kvm->no_pit_creation = 1;
> > >  }
> > >  
> > > -kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, int id)
> > > +static kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, CPUState *env)
> > >  {
> > >  	long mmap_size;
> > >  	int r;
> > >  	kvm_vcpu_context_t vcpu_ctx = qemu_malloc(sizeof(struct kvm_vcpu_context));
> > >  
> > >  	vcpu_ctx->kvm = kvm;
> > > -	vcpu_ctx->id = id;
> > > +	vcpu_ctx->id = env->cpu_index;
> > >  
> > > -	r = ioctl(kvm->vm_fd, KVM_CREATE_VCPU, id);
> > > +	r = ioctl(kvm->vm_fd, KVM_CREATE_VCPU, env->cpu_index);
> > This just reverts all my work to separate apic_id from env->cpu_index.
> > We want to bring good things from qemu-kvm to upstream not bad things
> > from upstream to qemu-kvm :) If anything you should use env->cpuid_apic_id
> > instead of env->cpu_index here.
> cpuid_apic_id is fine.
> my bad here.
Actually I prefer to use id here and pass env->cpuid_apic_id to the
function.

--
			Gleb.
--
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
Glauber Costa July 8, 2009, 1:44 p.m. UTC | #3
On Wed, Jul 08, 2009 at 04:32:37PM +0300, Gleb Natapov wrote:
> On Wed, Jul 08, 2009 at 09:09:00AM -0400, Glauber Costa wrote:
> > qemu upstream puts kvm information on env. Do that too, since it will
> > allow us to use CPUState in cpu-specific functions, instead of kvm-specific
> > types.
> > 
> > Signed-off-by: Glauber Costa <glommer@redhat.com>
> > ---
> >  kvm-all.c    |   12 ++++++++----
> >  libkvm-all.h |   12 ------------
> >  2 files changed, 8 insertions(+), 16 deletions(-)
> > 
> > diff --git a/kvm-all.c b/kvm-all.c
> > index 15bd429..b404f76 100644
> > --- a/kvm-all.c
> > +++ b/kvm-all.c
> > @@ -1519,21 +1519,25 @@ void kvm_disable_pit_creation(kvm_context_t kvm)
> >  	kvm->no_pit_creation = 1;
> >  }
> >  
> > -kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, int id)
> > +static kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, CPUState *env)
> >  {
> >  	long mmap_size;
> >  	int r;
> >  	kvm_vcpu_context_t vcpu_ctx = qemu_malloc(sizeof(struct kvm_vcpu_context));
> >  
> >  	vcpu_ctx->kvm = kvm;
> > -	vcpu_ctx->id = id;
> > +	vcpu_ctx->id = env->cpu_index;
> >  
> > -	r = ioctl(kvm->vm_fd, KVM_CREATE_VCPU, id);
> > +	r = ioctl(kvm->vm_fd, KVM_CREATE_VCPU, env->cpu_index);
> This just reverts all my work to separate apic_id from env->cpu_index.
> We want to bring good things from qemu-kvm to upstream not bad things
> from upstream to qemu-kvm :) If anything you should use env->cpuid_apic_id
> instead of env->cpu_index here.
cpuid_apic_id is fine.
my bad here.

--
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
diff mbox

Patch

diff --git a/kvm-all.c b/kvm-all.c
index 15bd429..b404f76 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1519,21 +1519,25 @@  void kvm_disable_pit_creation(kvm_context_t kvm)
 	kvm->no_pit_creation = 1;
 }
 
-kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, int id)
+static kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, CPUState *env)
 {
 	long mmap_size;
 	int r;
 	kvm_vcpu_context_t vcpu_ctx = qemu_malloc(sizeof(struct kvm_vcpu_context));
 
 	vcpu_ctx->kvm = kvm;
-	vcpu_ctx->id = id;
+	vcpu_ctx->id = env->cpu_index;
 
-	r = ioctl(kvm->vm_fd, KVM_CREATE_VCPU, id);
+	r = ioctl(kvm->vm_fd, KVM_CREATE_VCPU, env->cpu_index);
 	if (r == -1) {
 		fprintf(stderr, "kvm_create_vcpu: %m\n");
 		goto err;
 	}
 	vcpu_ctx->fd = r;
+
+    env->kvm_fd = r;
+    env->kvm_state = kvm_state;
+
 	mmap_size = ioctl(kvm->fd, KVM_GET_VCPU_MMAP_SIZE, 0);
 	if (mmap_size == -1) {
 		fprintf(stderr, "get vcpu mmap size: %m\n");
@@ -3029,7 +3033,7 @@  static void *ap_main_loop(void *_env)
     env->thread_id = kvm_get_thread_id();
     sigfillset(&signals);
     sigprocmask(SIG_BLOCK, &signals, NULL);
-    env->kvm_cpu_state.vcpu_ctx = kvm_create_vcpu(kvm_context, env->cpu_index);
+    env->kvm_cpu_state.vcpu_ctx = kvm_create_vcpu(kvm_context, env);
 
 #ifdef USE_KVM_DEVICE_ASSIGNMENT
     /* do ioperm for io ports of assigned devices */
diff --git a/libkvm-all.h b/libkvm-all.h
index 7857532..9c018eb 100644
--- a/libkvm-all.h
+++ b/libkvm-all.h
@@ -234,18 +234,6 @@  int kvm_check_extension(kvm_context_t kvm, int ext);
 void kvm_create_irqchip(kvm_context_t kvm);
 
 /*!
- * \brief Create a new virtual cpu
- *
- * This creates a new virtual cpu (the first vcpu is created by kvm_create()).
- * Should be called from a thread dedicated to the vcpu.
- *
- * \param kvm kvm context
- * \param slot vcpu number (> 0)
- * \return 0 on success, -errno on failure
- */
-kvm_vcpu_context_t kvm_create_vcpu(kvm_context_t kvm, int id);
-
-/*!
  * \brief Start the VCPU
  *
  * This starts the VCPU and virtualization is started.\n