From nobody Fri May 3 12:39:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614851379; cv=none; d=zohomail.com; s=zohoarc; b=Tfqjz6sv4r0KaOz0vd8GvRtZs46ik1Lo2P/pbqV+H4p3YKsLOxxMAgWYv+HKmZ/iI9H/d9EjyTgeJCVucD6G7X0f0ikkfpDEK2mlbLxFmGX173fo+9tiNMP2U07JTlk+6AuDuUUxnE44wUShJi7sBuWPMnwuf/G2s3b7YgQidjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614851379; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FbsMVR5q44kPDsIv9TdlHZk4i6m/XQRuVq8r6GVNSs4=; b=SGR9lKp1SYh02XIfmfAzBmlbE7srz6zX3WM0nZTNeZ8gftNGGh1eP0xwJwohFMLZoATlGQO15nXFd/w0U/70adteG3RWd8wH1jafHPMokg2Ji3K1p5C//2VfH8hZld3C+zMvd2/BlX7BQrvL0dOCnQZzkNYis3MSR2eE3wqbEM8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 16148513799451011.5827533120469; Thu, 4 Mar 2021 01:49:39 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-355-SiILJzhEMWGcEN_yfng2kg-1; Thu, 04 Mar 2021 04:48:39 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2C9E80434D; Thu, 4 Mar 2021 09:48:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99E2F100EADF; Thu, 4 Mar 2021 09:48:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5FF4F1809C8B; Thu, 4 Mar 2021 09:48:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1249mD3W011556 for ; Thu, 4 Mar 2021 04:48:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8D28C138E8; Thu, 4 Mar 2021 09:48:13 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.194.80]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5DF621378D; Thu, 4 Mar 2021 09:48:13 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id 01BB0C2008E; Thu, 4 Mar 2021 10:48:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614851379; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FbsMVR5q44kPDsIv9TdlHZk4i6m/XQRuVq8r6GVNSs4=; b=fNyWD59qwOU6R4AVLO+rigdYTXyajo9R+9/zUlYwuWxgWz85slOTx7UmenOFap/2h2QZcW 7aOjGIgkAOXDwIjGXMgY3G1zunqx9lWnOowQjZJkyHOUfQbHdBR596KMNjB+crooMoMeOB LQIxeaRjhRepNgbvMngk8XedHSjdh7A= X-MC-Unique: SiILJzhEMWGcEN_yfng2kg-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH 1/2] util: Move glib event loop workaround to glibcompat Date: Thu, 4 Mar 2021 10:48:10 +0100 Message-Id: <6f787aa297c9a02479afa0c1470607ce3f33f92a.1614851225.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This way it can be used from other places as well. Signed-off-by: Martin Kletzander Reviewed-by: Daniel P. Berrang=C3=A9 --- src/util/glibcompat.c | 35 +++++++++++++++++++++++++++++++++++ src/util/glibcompat.h | 11 +++++++++++ src/util/vireventglib.c | 30 ------------------------------ 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/util/glibcompat.c b/src/util/glibcompat.c index 9f0f7f015cad..76fda18a62d8 100644 --- a/src/util/glibcompat.c +++ b/src/util/glibcompat.c @@ -211,3 +211,38 @@ vir_g_strdup_vprintf(const char *msg, va_list args) abort(); return ret; } + + +/* + * If the last reference to a GSource is released in a non-main + * thread we're exposed to a race condition that causes a + * crash: + * + * https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1358 + * + * Thus we're using an idle func to release our ref... + * + * ...but this imposes a significant performance penalty on + * I/O intensive workloads which are sensitive to the iterations + * of the event loop, so avoid the workaround if we know we have + * new enough glib. + * + * The function below is used from a header file definition. + * + * Drop when min glib >=3D 2.64.0 + */ +#if GLIB_CHECK_VERSION(2, 64, 0) +# define g_vir_source_unref_safe(source) g_source_unref(source) +#else +# define g_vir_source_unref_safe(source) g_idle_add(virEventGLibSourceUnre= fIdle, source) + +gboolean +virEventGLibSourceUnrefIdle(gpointer data) +{ + GSource *src =3D data; + + g_source_unref(src); + + return FALSE; +} +#endif diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h index 6463c4179a7e..9c528432742b 100644 --- a/src/util/glibcompat.h +++ b/src/util/glibcompat.h @@ -84,3 +84,14 @@ char *vir_g_strdup_vprintf(const char *msg, va_list args) #define g_canonicalize_filename vir_g_canonicalize_filename #undef g_fsync #define g_fsync vir_g_fsync + +/* Drop when min glib >=3D 2.64.0 */ +#if GLIB_CHECK_VERSION(2, 64, 0) +# define g_vir_source_unref_safe(source) g_source_unref(source) +#else +# define g_vir_source_unref_safe(source) g_idle_add(virEventGLibSourceUnre= fIdle, source) + +gboolean +virEventGLibSourceUnrefIdle(gpointer data); + +#endif diff --git a/src/util/vireventglib.c b/src/util/vireventglib.c index 193b3bfde240..88e3ec6d5dbb 100644 --- a/src/util/vireventglib.c +++ b/src/util/vireventglib.c @@ -185,36 +185,6 @@ virEventGLibHandleFind(int watch) return NULL; } =20 -/* - * If the last reference to a GSource is released in a non-main - * thread we're exposed to a race condition that causes a - * crash: - * - * https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1358 - * - * Thus we're using an idle func to release our ref... - * - * ...but this imposes a significant performance penalty on - * I/O intensive workloads which are sensitive to the iterations - * of the event loop, so avoid the workaround if we know we have - * new enough glib. - */ -#if GLIB_CHECK_VERSION(2, 64, 0) -# define g_vir_source_unref_safe(source) g_source_unref(source) -#else -# define g_vir_source_unref_safe(source) g_idle_add(virEventGLibSourceUnre= fIdle, source) - -static gboolean -virEventGLibSourceUnrefIdle(gpointer data) -{ - GSource *src =3D data; - - g_source_unref(src); - - return FALSE; -} -#endif - =20 static void virEventGLibHandleUpdate(int watch, --=20 2.30.1 From nobody Fri May 3 12:39:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614851310; cv=none; d=zohomail.com; s=zohoarc; b=E+FJ3+flL3ir7qnL6Gd8k8xxA2E1A8CKsCPDxkbMSZaR9f+ExX5UBJ5IG8x1YLSfVzKUwt9YF5y5dd1pRlhK/SXPQSTcXR+oxxYcI6GqCtuWEqwnp0UWCI8OhMXNPeO+ZMgH/UPUGlmjo/HVdfb0foqDJG5dwRHcHzrT/gwzuIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614851310; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SbMaxApRMwt9yhDjVpOi9d/xgBN4wlmHatg+4OqsWNk=; b=hH/iEI5ie/XnFz+AU93wR4FtOarI3ozhcHBkvkUHHperRtasIdwENsG5+oOJveAidVNaGasgSvI/5uT/u43qfi5FvCDiLpiEkFCyttaIYBxMjtxbL8xLJRI79Ar1PPl9VQN/c1hkArnAShP6fJTQDPYX2xblSoGoYa4RwBK09MY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1614851310319875.6838115837464; Thu, 4 Mar 2021 01:48:30 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-79-8ERqxNqvMCyMyi1dUAK05Q-1; Thu, 04 Mar 2021 04:48:24 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2CDE1005D4D; Thu, 4 Mar 2021 09:48:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8BD7610023B2; Thu, 4 Mar 2021 09:48:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 69EC24BB40; Thu, 4 Mar 2021 09:48:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1249mD86011555 for ; Thu, 4 Mar 2021 04:48:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8DACE2C6FA; Thu, 4 Mar 2021 09:48:13 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.194.80]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5E59C5C1C2; Thu, 4 Mar 2021 09:48:13 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id 0CE4CC20092; Thu, 4 Mar 2021 10:48:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614851308; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=SbMaxApRMwt9yhDjVpOi9d/xgBN4wlmHatg+4OqsWNk=; b=AkNnEPG7CqTI/pxUi9Njfy4vjKWMj+aXJ+orVK+IG4ycFKFK/0sVKGtPfll11oEYjN6NhK Abx5mNDgNoUYmsh6b8vkCoP9TssDAznxTqPLErZlKI8LkN8EYH6fx9hPmclO+NeXYvJE8a YyxqiYihmVAJzCEaWjPUr+tqnCkQ82U= X-MC-Unique: 8ERqxNqvMCyMyi1dUAK05Q-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] glib: Use safe glib event workaround in other event loops Date: Thu, 4 Mar 2021 10:48:11 +0100 Message-Id: <13c264bf81776757c56fbce62bd3f2c1d7a83517.1614851225.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Similarly to the crash workaround: commit 0db4743645b7a0611a3c0687f834205c9956f7fc Author: Daniel P. Berrang=C3=A9 Date: Tue Jul 28 16:52:47 2020 +0100 util: avoid crash due to race in glib event loop code we need to do this in the other event loop as crash in that one was also reported: https://bugzilla.redhat.com/show_bug.cgi?id=3D1931331 Signed-off-by: Martin Kletzander Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_agent.c | 2 +- src/qemu/qemu_monitor.c | 2 +- src/util/vireventthread.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 9a74b802b89d..8b880d0d157c 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -533,7 +533,7 @@ qemuAgentUnregister(qemuAgentPtr agent) { if (agent->watch) { g_source_destroy(agent->watch); - g_source_unref(agent->watch); + g_vir_source_unref_safe(agent->watch); agent->watch =3D NULL; } } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 73f337a6be53..b4f2641504f8 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -862,7 +862,7 @@ qemuMonitorUnregister(qemuMonitorPtr mon) { if (mon->watch) { g_source_destroy(mon->watch); - g_source_unref(mon->watch); + g_vir_source_unref_safe(mon->watch); mon->watch =3D NULL; } } diff --git a/src/util/vireventthread.c b/src/util/vireventthread.c index 8342f420f666..e9d18d3acf2f 100644 --- a/src/util/vireventthread.c +++ b/src/util/vireventthread.c @@ -123,7 +123,7 @@ virEventThreadWorker(void *opaque) =20 g_main_loop_run(data->loop); =20 - g_source_unref(running); + g_vir_source_unref_safe(running); virEventThreadDataFree(data); =20 return NULL; --=20 2.30.1