From patchwork Thu Jun 16 17:06:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 636592 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 3rVrB5051Zz9t0v for ; Fri, 17 Jun 2016 03:35:09 +1000 (AEST) Received: from localhost ([::1]:51235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDbC6-0007tB-Js for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2016 13:35:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDakV-0003uK-2J for qemu-devel@nongnu.org; Thu, 16 Jun 2016 13:06:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDakO-00054H-SP for qemu-devel@nongnu.org; Thu, 16 Jun 2016 13:06:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDakO-00054B-MM for qemu-devel@nongnu.org; Thu, 16 Jun 2016 13:06:28 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B1C83F731; Thu, 16 Jun 2016 17:06:28 +0000 (UTC) Received: from localhost (vpn1-7-187.gru2.redhat.com [10.97.7.187]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5GH6RPh012934; Thu, 16 Jun 2016 13:06:27 -0400 From: Eduardo Habkost To: qemu-devel@nongnu.org, Peter Maydell Date: Thu, 16 Jun 2016 14:06:17 -0300 Message-Id: <1466096778-13248-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1466096778-13248-1-git-send-email-ehabkost@redhat.com> References: <1466096778-13248-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 16 Jun 2016 17:06:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/2] qdev: Use GList for global properties X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marcel Apfelbaum , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" If the same GlobalProperty struct is registered twice, the list entry gets corrupted, making tqe_next points to itself, and qdev_prop_set_globals() gets stuck in a loop. The bug can be easily reproduced by running: $ qemu-system-x86_64 -rtc-td-hack -rtc-td-hack Change global_props to use GList instead of queue.h, making the code simpler and able to deal with properties being registered twice. Reviewed-by: Michael S. Tsirkin Signed-off-by: Eduardo Habkost --- hw/core/qdev-properties.c | 15 ++++++++------- include/hw/qdev-core.h | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 737d29c..e3b2184 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1020,12 +1020,11 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) *ptr = value; } -static QTAILQ_HEAD(, GlobalProperty) global_props = - QTAILQ_HEAD_INITIALIZER(global_props); +static GList *global_props; void qdev_prop_register_global(GlobalProperty *prop) { - QTAILQ_INSERT_TAIL(&global_props, prop, next); + global_props = g_list_append(global_props, prop); } void qdev_prop_register_global_list(GlobalProperty *props) @@ -1039,10 +1038,11 @@ void qdev_prop_register_global_list(GlobalProperty *props) int qdev_prop_check_globals(void) { - GlobalProperty *prop; + GList *l; int ret = 0; - QTAILQ_FOREACH(prop, &global_props, next) { + for (l = global_props; l; l = l->next) { + GlobalProperty *prop = l->data; ObjectClass *oc; DeviceClass *dc; if (prop->used) { @@ -1073,9 +1073,10 @@ int qdev_prop_check_globals(void) static void qdev_prop_set_globals_for_type(DeviceState *dev, const char *typename) { - GlobalProperty *prop; + GList *l; - QTAILQ_FOREACH(prop, &global_props, next) { + for (l = global_props; l; l = l->next) { + GlobalProperty *prop = l->data; Error *err = NULL; if (strcmp(typename, prop->driver) != 0) { diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 1ce02b2..24aa0a7 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -266,7 +266,6 @@ typedef struct GlobalProperty { const char *value; bool user_provided; bool used; - QTAILQ_ENTRY(GlobalProperty) next; } GlobalProperty; /*** Board API. This should go away once we have a machine config file. ***/