From nobody Mon Apr 29 06:41:13 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506567712211544.1996028732839; Wed, 27 Sep 2017 20:01:52 -0700 (PDT) Received: from localhost ([::1]:57143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxP58-0006vX-DZ for importer@patchew.org; Wed, 27 Sep 2017 23:01:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxP3v-0006Gb-Db for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxP3t-00022b-OR for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45638) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxP3t-00020f-7z for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:29 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1238D20CDFC; Thu, 28 Sep 2017 03:00:28 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-247.nay.redhat.com [10.66.14.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id A953471C34; Thu, 28 Sep 2017 03:00:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1238D20CDFC Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 28 Sep 2017 10:59:54 +0800 Message-Id: <20170928025958.1420-2-peterx@redhat.com> In-Reply-To: <20170928025958.1420-1-peterx@redhat.com> References: <20170928025958.1420-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 28 Sep 2017 03:00:28 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 1/5] qom: provide root container for internal objs 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: Fam Zheng , Manos Pitsidianakis , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We have object_get_objects_root() to keep user created objects, however no place for objects that will be used internally. Create such a container for internal objects. CC: Andreas F=C3=A4rber CC: Markus Armbruster CC: Paolo Bonzini Suggested-by: Daniel P. Berrange Signed-off-by: Peter Xu Reviewed-by: Fam Zheng --- include/qom/object.h | 11 +++++++++++ qom/object.c | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index f3e5cff37a..e0d9824415 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1214,6 +1214,17 @@ Object *object_get_root(void); Object *object_get_objects_root(void); =20 /** + * object_get_internal_root: + * + * Get the container object that holds internally used object + * instances. Any object which is put into this container must not be + * user visible, and it will not be exposed in the QOM tree. + * + * Returns: the internal object container + */ +Object *object_get_internal_root(void); + +/** * object_get_canonical_path_component: * * Returns: The final component in the object's canonical path. The canon= ical diff --git a/qom/object.c b/qom/object.c index 3e18537e9b..6a7bd9257b 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1370,6 +1370,17 @@ Object *object_get_objects_root(void) return container_get(object_get_root(), "/objects"); } =20 +Object *object_get_internal_root(void) +{ + static Object *internal_root; + + if (!internal_root) { + internal_root =3D object_new("container"); + } + + return internal_root; +} + static void object_get_child_property(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) --=20 2.13.5 From nobody Mon Apr 29 06:41:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506567808258929.2585390402414; Wed, 27 Sep 2017 20:03:28 -0700 (PDT) Received: from localhost ([::1]:57148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxP6h-00088n-I5 for importer@patchew.org; Wed, 27 Sep 2017 23:03:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxP3x-0006HA-PA for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxP3w-00028n-Tx for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33036) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxP3w-00026v-Fm for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 698D2D0DEA; Thu, 28 Sep 2017 03:00:31 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-247.nay.redhat.com [10.66.14.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8148B71C34; Thu, 28 Sep 2017 03:00:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 698D2D0DEA Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 28 Sep 2017 10:59:55 +0800 Message-Id: <20170928025958.1420-3-peterx@redhat.com> In-Reply-To: <20170928025958.1420-1-peterx@redhat.com> References: <20170928025958.1420-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 28 Sep 2017 03:00:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 2/5] iothread: provide helpers for internal use 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: Fam Zheng , Manos Pitsidianakis , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" IOThread is a general framework that contains IO loop environment and a real thread behind. It's also good to be used internally inside qemu. Provide some helpers for it to create iothreads to be used internally. Put all the internal used iothreads into the internal object container. Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu --- include/sysemu/iothread.h | 8 ++++++++ iothread.c | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h index d2985b30ba..b07663f0a1 100644 --- a/include/sysemu/iothread.h +++ b/include/sysemu/iothread.h @@ -46,4 +46,12 @@ AioContext *iothread_get_aio_context(IOThread *iothread); void iothread_stop_all(void); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 +/* + * Helpers used to allocate iothreads for internal use. These + * iothreads will not be seen by monitor clients when query using + * "query-iothreads". + */ +IOThread *iothread_create(const char *id, Error **errp); +void iothread_destroy(IOThread *iothread); + #endif /* IOTHREAD_H */ diff --git a/iothread.c b/iothread.c index 44c8944dc4..33f996e561 100644 --- a/iothread.c +++ b/iothread.c @@ -354,3 +354,19 @@ GMainContext *iothread_get_g_main_context(IOThread *io= thread) =20 return iothread->worker_context; } + +IOThread *iothread_create(const char *id, Error **errp) +{ + Object *obj; + + obj =3D object_new_with_props(TYPE_IOTHREAD, + object_get_internal_root(), + id, errp, NULL); + + return IOTHREAD(obj); +} + +void iothread_destroy(IOThread *iothread) +{ + object_unparent(OBJECT(iothread)); +} --=20 2.13.5 From nobody Mon Apr 29 06:41:13 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506567902757623.4038999552342; Wed, 27 Sep 2017 20:05:02 -0700 (PDT) Received: from localhost ([::1]:57155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxP8I-00011m-5n for importer@patchew.org; Wed, 27 Sep 2017 23:05:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxP41-0006Jy-LR for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxP40-0002F0-6l for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33098) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxP3z-0002D4-Pz for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:36 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0C2AD0DE5; Thu, 28 Sep 2017 03:00:34 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-247.nay.redhat.com [10.66.14.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id D820598162; Thu, 28 Sep 2017 03:00:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B0C2AD0DE5 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 28 Sep 2017 10:59:56 +0800 Message-Id: <20170928025958.1420-4-peterx@redhat.com> In-Reply-To: <20170928025958.1420-1-peterx@redhat.com> References: <20170928025958.1420-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 28 Sep 2017 03:00:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 3/5] iothread: export iothread_stop() 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: Fam Zheng , Manos Pitsidianakis , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" So that internal iothread users can explicitly stop one iothread without destroying it. Since at it, fix iothread_stop() to allow it to be called multiple times. Before this patch we may call iothread_stop() more than once on single iothread, while that may not be correct since qemu_thread_join() is not allowed to run twice. From manual of pthread_join(): Joining with a thread that has previously been joined results in undefined behavior. Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu --- include/sysemu/iothread.h | 1 + iothread.c | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h index b07663f0a1..110329b2b4 100644 --- a/include/sysemu/iothread.h +++ b/include/sysemu/iothread.h @@ -52,6 +52,7 @@ GMainContext *iothread_get_g_main_context(IOThread *iothr= ead); * "query-iothreads". */ IOThread *iothread_create(const char *id, Error **errp); +void iothread_stop(IOThread *iothread); void iothread_destroy(IOThread *iothread); =20 #endif /* IOTHREAD_H */ diff --git a/iothread.c b/iothread.c index 33f996e561..b3c092b2d7 100644 --- a/iothread.c +++ b/iothread.c @@ -80,13 +80,10 @@ static void *iothread_run(void *opaque) return NULL; } =20 -static int iothread_stop(Object *object, void *opaque) +void iothread_stop(IOThread *iothread) { - IOThread *iothread; - - iothread =3D (IOThread *)object_dynamic_cast(object, TYPE_IOTHREAD); - if (!iothread || !iothread->ctx) { - return 0; + if (!iothread->ctx || iothread->stopping) { + return; } iothread->stopping =3D true; aio_notify(iothread->ctx); @@ -94,6 +91,17 @@ static int iothread_stop(Object *object, void *opaque) g_main_loop_quit(iothread->main_loop); } qemu_thread_join(&iothread->thread); +} + +static int iothread_stop_iter(Object *object, void *opaque) +{ + IOThread *iothread; + + iothread =3D (IOThread *)object_dynamic_cast(object, TYPE_IOTHREAD); + if (!iothread) { + return 0; + } + iothread_stop(iothread); return 0; } =20 @@ -108,7 +116,7 @@ static void iothread_instance_finalize(Object *obj) { IOThread *iothread =3D IOTHREAD(obj); =20 - iothread_stop(obj, NULL); + iothread_stop(iothread); qemu_cond_destroy(&iothread->init_done_cond); qemu_mutex_destroy(&iothread->init_done_lock); if (!iothread->ctx) { @@ -328,7 +336,7 @@ void iothread_stop_all(void) aio_context_release(ctx); } =20 - object_child_foreach(container, iothread_stop, NULL); + object_child_foreach(container, iothread_stop_iter, NULL); } =20 static gpointer iothread_g_main_context_init(gpointer opaque) --=20 2.13.5 From nobody Mon Apr 29 06:41:13 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506567844055721.6743787451253; Wed, 27 Sep 2017 20:04:04 -0700 (PDT) Received: from localhost ([::1]:57149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxP7L-00008S-CN for importer@patchew.org; Wed, 27 Sep 2017 23:04:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44812) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxP4I-0006TU-KU for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxP4D-0002Ik-Qd for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60922) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxP4D-0002Ic-LQ for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 98AED14C5B1; Thu, 28 Sep 2017 03:00:48 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-247.nay.redhat.com [10.66.14.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BA8D9816D; Thu, 28 Sep 2017 03:00:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 98AED14C5B1 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 28 Sep 2017 10:59:57 +0800 Message-Id: <20170928025958.1420-5-peterx@redhat.com> In-Reply-To: <20170928025958.1420-1-peterx@redhat.com> References: <20170928025958.1420-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 28 Sep 2017 03:00:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 4/5] iothread: delay the context release to finalize 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: Fam Zheng , Manos Pitsidianakis , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When gcontext is used with iothread, the context will be destroyed during iothread_stop(). That's not good since sometimes we would like to keep the resources until iothread is destroyed, but we may want to stop the thread before that point. Delay the destruction of gcontext to iothread finalize. Then we can do: iothread_stop(thread); some_cleanup_on_resources(); iothread_destroy(thread); We may need this patch if we want to run chardev IOs in iothreads and hopefully clean them up correctly. For more specific information, please see 2b316774f6 ("qemu-char: do not operate on sources from finalize callbacks"). Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu --- iothread.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iothread.c b/iothread.c index b3c092b2d7..27a4288578 100644 --- a/iothread.c +++ b/iothread.c @@ -71,8 +71,6 @@ static void *iothread_run(void *opaque) g_main_loop_unref(loop); =20 g_main_context_pop_thread_default(iothread->worker_context); - g_main_context_unref(iothread->worker_context); - iothread->worker_context =3D NULL; } } =20 @@ -117,6 +115,10 @@ static void iothread_instance_finalize(Object *obj) IOThread *iothread =3D IOTHREAD(obj); =20 iothread_stop(iothread); + if (iothread->worker_context) { + g_main_context_unref(iothread->worker_context); + iothread->worker_context =3D NULL; + } qemu_cond_destroy(&iothread->init_done_cond); qemu_mutex_destroy(&iothread->init_done_lock); if (!iothread->ctx) { --=20 2.13.5 From nobody Mon Apr 29 06:41:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506567965810992.4325535481637; Wed, 27 Sep 2017 20:06:05 -0700 (PDT) Received: from localhost ([::1]:57163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxP9I-0001eI-VY for importer@patchew.org; Wed, 27 Sep 2017 23:06:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dxP4M-0006Wb-Br for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dxP4L-0002Qo-Mw for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dxP4L-0002QQ-IA for qemu-devel@nongnu.org; Wed, 27 Sep 2017 23:00:57 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89BFE2064A6; Thu, 28 Sep 2017 03:00:56 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-247.nay.redhat.com [10.66.14.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 123FE71C34; Thu, 28 Sep 2017 03:00:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 89BFE2064A6 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 28 Sep 2017 10:59:58 +0800 Message-Id: <20170928025958.1420-6-peterx@redhat.com> In-Reply-To: <20170928025958.1420-1-peterx@redhat.com> References: <20170928025958.1420-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 28 Sep 2017 03:00:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 5/5] aio: fix assert when remove poll during destroy 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: Fam Zheng , Manos Pitsidianakis , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi After iothread is enabled internally inside QEMU with GMainContext, we may encounter this warning when destroying the iothread: (qemu-system-x86_64:19925): GLib-CRITICAL **: g_source_remove_poll: assertion '!SOURCE_DESTROYED (source)' failed The problem is that g_source_remove_poll() does not allow to remove one source from array if the source is detached from its owner context. (peterx: which IMHO does not make much sense) Fix it on QEMU side by avoid calling g_source_remove_poll() if we know the object is during destruction, and we won't leak anything after all since the array will be gone soon cleanly even with that fd. Signed-off-by: Stefan Hajnoczi [peterx: write the commit message] Signed-off-by: Peter Xu Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi --- util/aio-posix.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index 2d51239ec6..5946ac09f0 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -223,7 +223,14 @@ void aio_set_fd_handler(AioContext *ctx, return; } =20 - g_source_remove_poll(&ctx->source, &node->pfd); + /* If the GSource is in the process of being destroyed then + * g_source_remove_poll() causes an assertion failure. Skip + * removal in that case, because glib cleans up its state during + * destruction anyway. + */ + if (!g_source_is_destroyed(&ctx->source)) { + g_source_remove_poll(&ctx->source, &node->pfd); + } =20 /* If the lock is held, just mark the node as deleted */ if (qemu_lockcnt_count(&ctx->list_lock)) { --=20 2.13.5