From patchwork Wed Jul 9 22:04:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 368446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 87B9C140078 for ; Thu, 10 Jul 2014 14:22:20 +1000 (EST) Received: from localhost ([::1]:34113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X507e-0003aw-Ep for incoming@patchwork.ozlabs.org; Wed, 09 Jul 2014 18:13:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58924) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4zzP-00084o-Fg for qemu-devel@nongnu.org; Wed, 09 Jul 2014 18:05:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X4zzJ-0000AJ-9I for qemu-devel@nongnu.org; Wed, 09 Jul 2014 18:05:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37730) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4zzJ-0000A5-1m for qemu-devel@nongnu.org; Wed, 09 Jul 2014 18:05:17 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s69M5GMh010289 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 9 Jul 2014 18:05:16 -0400 Received: from localhost (ovpn-113-143.phx2.redhat.com [10.3.113.143]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s69M5FVV030062; Wed, 9 Jul 2014 18:05:16 -0400 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 9 Jul 2014 19:04:14 -0300 Message-Id: <1404943462-711-18-git-send-email-ehabkost@redhat.com> In-Reply-To: <1404943462-711-1-git-send-email-ehabkost@redhat.com> References: <1404943462-711-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 17/25] kvm: Make KVMState be the TYPE_KVM_ACCEL instance struct X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Now that we create an accel object before calling machine_init, we can simply use the object to save all KVMState data. Signed-off-by: Eduardo Habkost --- kvm-all.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index fdb2fb5..9185a62 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -75,8 +75,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; @@ -109,10 +111,13 @@ struct KVMState QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE]; bool direct_msi; #endif -}; +} KVMState; #define TYPE_KVM_ACCEL "kvm-accel" +#define KVM_STATE(obj) \ + OBJECT_CHECK(KVMState, (obj), TYPE_KVM_ACCEL) + KVMState *kvm_state; bool kvm_kernel_irqchip; bool kvm_async_interrupts_allowed; @@ -1392,7 +1397,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 @@ -1581,7 +1586,6 @@ err: close(s->fd); } g_free(s->slots); - g_free(s); return ret; } @@ -2217,6 +2221,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)