diff mbox

[PULL,23/28] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct

Message ID 1412849855-12661-16-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Oct. 9, 2014, 10:17 a.m. UTC
From: Eduardo Habkost <ehabkost@redhat.com>

Now that we create an accel object before calling machine_init, we can
simply use the accel object to save all KVMState data, instead of
allocationg KVMState manually.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 kvm-all.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Comments

Cornelia Huck Oct. 10, 2014, 8:47 a.m. UTC | #1
On Thu,  9 Oct 2014 12:17:30 +0200
Paolo Bonzini <pbonzini@redhat.com> wrote:

> From: Eduardo Habkost <ehabkost@redhat.com>
> 
> Now that we create an accel object before calling machine_init, we can
> simply use the accel object to save all KVMState data, instead of
> allocationg KVMState manually.
> 
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  kvm-all.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)

This patch breaks compilation on s390 for me:

  CC    s390x-softmmu/kvm-all.o
/home/cohuck/git/qemu/kvm-all.c:110: error: redefinition of typedef ‘KVMState’
/home/cohuck/git/qemu/include/sysemu/kvm.h:161: error: previous declaration of ‘KVMState’ was here
Cornelia Huck Oct. 10, 2014, 9:11 a.m. UTC | #2
On Fri, 10 Oct 2014 10:47:09 +0200
Cornelia Huck <cornelia.huck@de.ibm.com> wrote:

> On Thu,  9 Oct 2014 12:17:30 +0200
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> > From: Eduardo Habkost <ehabkost@redhat.com>
> > 
> > Now that we create an accel object before calling machine_init, we can
> > simply use the accel object to save all KVMState data, instead of
> > allocationg KVMState manually.
> > 
> > Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > ---
> >  kvm-all.c | 13 +++++++++----
> >  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> This patch breaks compilation on s390 for me:
> 
>   CC    s390x-softmmu/kvm-all.o
> /home/cohuck/git/qemu/kvm-all.c:110: error: redefinition of typedef ‘KVMState’
> /home/cohuck/git/qemu/include/sysemu/kvm.h:161: error: previous declaration of ‘KVMState’ was here

Seems to be compiler version dependant. With the SLES11SP3 compiler
(calls itself 4.3.4), I get the failure above. With newer compilers
(4.6+), it builds fine.
Gonglei (Arei) Oct. 10, 2014, 9:19 a.m. UTC | #3
On 2014/10/10 16:47, Cornelia Huck wrote:

> On Thu,  9 Oct 2014 12:17:30 +0200
> Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
>> From: Eduardo Habkost <ehabkost@redhat.com>
>>
>> Now that we create an accel object before calling machine_init, we can
>> simply use the accel object to save all KVMState data, instead of
>> allocationg KVMState manually.
>>
>> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
>> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  kvm-all.c | 13 +++++++++----
>>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> This patch breaks compilation on s390 for me:
> 
>   CC    s390x-softmmu/kvm-all.o
> /home/cohuck/git/qemu/kvm-all.c:110: error: redefinition of typedef ‘KVMState’
> /home/cohuck/git/qemu/include/sysemu/kvm.h:161: error: previous declaration of ‘KVMState’ was here
> 
> 

I encountered this issue too [gcc version 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux) ]:

  CC    m68k-softmmu/cputlb.o
  CC    mips64-softmmu/memory.o
/home/qemu/kvm-all.c:110: error: redefinition of typedef 'KVMState'
/home/qemu/include/sysemu/kvm.h:161: error: previous declaration of 'KVMState' was here
  CC    arm-softmmu/memory.o
make[1]: *** [kvm-all.o] Error 1
make: *** [subdir-i386-softmmu] Error 2
make: *** Waiting for unfinished jobs....
  CC    mips64-softmmu/savevm.o
  CC    or32-softmmu/cputlb.o
  CC    microblaze-softmmu/cputlb.o
  CC    xtensaeb-softmmu/cputlb.o
  CC    mips64el-softmmu/savevm.o
  CC    ppcemb-softmmu/ioport.o
  CC    sh4-softmmu/savevm.o
  CC    ppc-softmmu/ioport.o
  CC    aarch64-softmmu/device_tree.o
  CC    mips-softmmu/savevm.o
  CC    cris-softmmu/cputlb.o
  CC    microblazeel-softmmu/cputlb.o
  CC    sparc-softmmu/cputlb.o
  CC    sh4eb-softmmu/cputlb.o
/home/qemu/kvm-all.c:110: error: redefinition of typedef 'KVMState'
/home/qemu/include/sysemu/kvm.h:161: error: previous declaration of 'KVMState' was here

Best regards,
-Gonglei
diff mbox

Patch

diff --git a/kvm-all.c b/kvm-all.c
index 0a9de92..e98a7c7 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -71,8 +71,10 @@  typedef struct KVMSlot
 
 typedef struct kvm_dirty_log KVMDirtyLog;
 
-struct KVMState
+typedef struct KVMState
 {
+    AccelState parent_obj;
+
     KVMSlot *slots;
     int nr_slots;
     int fd;
@@ -105,10 +107,13 @@  struct KVMState
     QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
     bool direct_msi;
 #endif
-};
+} KVMState;
 
 #define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
 
+#define KVM_STATE(obj) \
+    OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL)
+
 KVMState *kvm_state;
 bool kvm_kernel_irqchip;
 bool kvm_async_interrupts_allowed;
@@ -1401,7 +1406,7 @@  static int kvm_init(MachineState *ms)
     int i, type = 0;
     const char *kvm_type;
 
-    s = g_malloc0(sizeof(KVMState));
+    s = KVM_STATE(ms->accelerator);
 
     /*
      * On systems where the kernel can support different base page
@@ -1590,7 +1595,6 @@  err:
         close(s->fd);
     }
     g_free(s->slots);
-    g_free(s);
 
     return ret;
 }
@@ -2242,6 +2246,7 @@  static const TypeInfo kvm_accel_type = {
     .name = TYPE_KVM_ACCEL,
     .parent = TYPE_ACCEL,
     .class_init = kvm_accel_class_init,
+    .instance_size = sizeof(KVMState),
 };
 
 static void kvm_type_init(void)