[PATCH 4/9] remove opaque field from kvm_context

Glauber Costa
2009-07-29T17:49:23Z

use vcpu->env whenever possible. It does lead to some strange things like
kvm_arch_pre_kvm_run(env, env), but I'm not fixing it here so as to not
mix things up.

Will do that in a separate patch in the future.

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
qemu-kvm.c | 36 +++++++++++++++---------------------
qemu-kvm.h | 1 -
2 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/qemu-kvm.c b/qemu-kvm.c
index ba937ca..47846b3 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -376,7 +376,6 @@ int kvm_init(int smp_cpus)

kvm_state->fd = fd;
kvm_state->vmfd = -1;
- kvm_context->opaque = cpu_single_env;
kvm_context->dirty_pages_log_all = 0;
kvm_context->no_irqchip_creation = 0;
kvm_context->no_pit_creation = 0;
@@ -754,7 +753,6 @@ int kvm_set_irqchip(kvm_context_t kvm, struct kvm_irqchip *chip)
static int handle_io(kvm_vcpu_context_t vcpu)
{
struct kvm_run *run = vcpu->run;
- kvm_context_t kvm = vcpu->kvm;
uint16_t addr = run->io.port;
int i;
void *p = (void *)run + run->io.data_offset;
@@ -764,13 +762,13 @@ static int handle_io(kvm_vcpu_context_t vcpu)
case KVM_EXIT_IO_IN:
switch (run->io.size) {
case 1:
- *(uint8_t *)p = cpu_inb(kvm->opaque, addr);
+ *(uint8_t *)p = cpu_inb(vcpu->env, addr);
break;
case 2:
- *(uint16_t *)p = cpu_inw(kvm->opaque, addr);
+ *(uint16_t *)p = cpu_inw(vcpu->env, addr);
break;
case 4:
- *(uint32_t *)p = cpu_inl(kvm->opaque, addr);
+ *(uint32_t *)p = cpu_inl(vcpu->env, addr);
break;
default:
fprintf(stderr, "bad I/O size %d\n", run->io.size);
@@ -780,13 +778,13 @@ static int handle_io(kvm_vcpu_context_t vcpu)
case KVM_EXIT_IO_OUT:
switch (run->io.size) {
case 1:
- cpu_outb(kvm->opaque, addr, *(uint8_t *)p);
+ cpu_outb(vcpu->env, addr, *(uint8_t *)p);
break;
case 2:
- cpu_outw(kvm->opaque, addr, *(uint16_t *)p);
+ cpu_outw(vcpu->env, addr, *(uint16_t *)p);
break;
case 4:
- cpu_outl(kvm->opaque, addr, *(uint32_t *)p);
+ cpu_outl(vcpu->env, addr, *(uint32_t *)p);
break;
default:
fprintf(stderr, "bad I/O size %d\n", run->io.size);
@@ -808,9 +806,8 @@ int handle_debug(kvm_vcpu_context_t vcpu, void *env)
{
#ifdef KVM_CAP_SET_GUEST_DEBUG
struct kvm_run *run = vcpu->run;
- kvm_context_t kvm = vcpu->kvm;

- return kvm_debug(kvm->opaque, env, &run->debug.arch);
+ return kvm_debug(vcpu->env, env, &run->debug.arch);
#else
return 0;
#endif
@@ -888,7 +885,7 @@ int handle_io_window(kvm_context_t kvm)

int handle_halt(kvm_vcpu_context_t vcpu)
{
- return kvm_arch_halt(vcpu->kvm->opaque, vcpu);
+ return kvm_arch_halt(vcpu->env, vcpu);
}

int handle_shutdown(kvm_context_t kvm, CPUState *env)
@@ -900,22 +897,15 @@ int handle_shutdown(kvm_context_t kvm, CPUState *env)
return 1;
}

-static inline void push_nmi(kvm_context_t kvm)
-{
-#ifdef KVM_CAP_USER_NMI
- kvm_arch_push_nmi(kvm->opaque);
-#endif /* KVM_CAP_USER_NMI */
-}
-
void post_kvm_run(kvm_context_t kvm, CPUState *env)
{
pthread_mutex_lock(&qemu_mutex);
- kvm_arch_post_kvm_run(kvm->opaque, env);
+ kvm_arch_post_kvm_run(env, env);
}

int pre_kvm_run(kvm_context_t kvm, CPUState *env)
{
- kvm_arch_pre_kvm_run(kvm->opaque, env);
+ kvm_arch_pre_kvm_run(env, env);

pthread_mutex_unlock(&qemu_mutex);
return 0;
@@ -939,7 +929,11 @@ int kvm_run(kvm_vcpu_context_t vcpu, void *env)
kvm_context_t kvm = vcpu->kvm;

again:
- push_nmi(kvm);
+
+#ifdef KVM_CAP_USER_NMI
+ kvm_arch_push_nmi(vcpu->env);
+#endif /* KVM_CAP_USER_NMI */
+
#if !defined(__s390__)
if (!kvm_state->irqchip_in_kernel)
run->request_interrupt_window = kvm_arch_try_push_interrupts(env);
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 440afba..3f14f13 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -52,7 +52,6 @@ extern int kvm_abi;
*/

struct kvm_context {
- void *opaque;
/// is dirty pages logging enabled for all regions or not
int dirty_pages_log_all;
/// do not create in-kernel irqchip if set
--
1.6.2.2