From nobody Sun Sep 28 15:29:10 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1758794098; cv=none; d=zohomail.com; s=zohoarc; b=ItfliiyKC4hKWxp7hxvMrVfxZTyO0WfsGAL0ywfV8iFuBqIYrS1/vpn6PtabL7rOWLFthdy1NAa7CYBo8sDfEPp4/kV46zTTR9Nc4uPiAYEu+921ycGsNeI3YKYQ8iGG+lNUkXsBMkMXIr2UM/Yvfo52utGptz8+Py0nR0cvD14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758794098; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=fcI0f/40UM6S++W5fRjwKPKMY6j7Dg0M4zkV/J73zRo=; b=SEFgtG58fecCxrzau4EXo3UH6eJZZkF5EejCLauZm6cPvclAVcRySWjFyxIDY0iUNW+LTK1N2X/vhHHUqraBSbtHVDH/2RYRSO09qIWTKtNsSbUhpI22nHoxqQn4f9CzBZXDDx3z4nRbvNHPQUy9hW2glAamAGrX7ujCa8iE6F8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1758794098185176.32293862170707; Thu, 25 Sep 2025 02:54:58 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 4C5AF417D6; Thu, 25 Sep 2025 05:54:57 -0400 (EDT) Received: from [172.19.199.14] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 0EBF843F6B; Thu, 25 Sep 2025 05:48:33 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id CB25E41846; Thu, 25 Sep 2025 05:48:18 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 564CC43F09 for ; Thu, 25 Sep 2025 05:45:07 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-119-3rXXKG-zM16ZeMJFCJGGcQ-1; Thu, 25 Sep 2025 05:45:03 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3210C18004D4; Thu, 25 Sep 2025 09:45:01 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.163]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0C6C330002D0; Thu, 25 Sep 2025 09:44:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758793506; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fcI0f/40UM6S++W5fRjwKPKMY6j7Dg0M4zkV/J73zRo=; b=c3nsm6360n5aSNikdpnCp360cC4qFug9LYqfecy/MG/SNpDawr2Mq1EDHY1wq0amN3qxv7 S63IeMt7W10eiIba0JkyeefG/b43wy3Wfid5rXyFPvZzseLi6NqH+j4bUYK7dXhZn6XqqQ bXM2xelPCMMbofUcTmsRDhj3hfoBLac= X-MC-Unique: 3rXXKG-zM16ZeMJFCJGGcQ-1 X-Mimecast-MFC-AGG-ID: 3rXXKG-zM16ZeMJFCJGGcQ_1758793501 To: qemu-devel@nongnu.org Subject: [PATCH v4 02/23] monitor: initialize global data from a constructor Date: Thu, 25 Sep 2025 10:44:20 +0100 Message-ID: <20250925094441.1651372-3-berrange@redhat.com> In-Reply-To: <20250925094441.1651372-1-berrange@redhat.com> References: <20250925094441.1651372-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Message-ID-Hash: M7OWBNV6KVK2B3Z5MKX2PB4PDZLGYDDF X-Message-ID-Hash: M7OWBNV6KVK2B3Z5MKX2PB4PDZLGYDDF X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Hanna Reitz , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , qemu-rust@nongnu.org, Richard Henderson , Markus Armbruster , Christian Schoenebeck , qemu-block@nongnu.org, Stefan Weil , "Dr. David Alan Gilbert" , Manos Pitsidianakis , Gerd Hoffmann , devel@lists.libvirt.org, Paolo Bonzini X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9_via_Devel?= Reply-To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1758794099764116600 Some monitor functions, most notably, monitor_cur() rely on global data being initialized by 'monitor_init_globals()'. The latter is called relatively late in startup. If code triggers error_report() before monitor_init_globals() is called, QEMU will abort when accessing the uninitialized monitor mutex. The critical monitor global data must be initialized from a constructor function, to improve the guarantee that it is done before any possible calls to monitor_cur(). Not only that, but the constructor must be marked to run before the default constructor in case any of them trigger error reporting. Note in particular that the RCU constructor will spawn a background thread so we might even have non-constructor QEMU code running concurrently with other constructors. As a general note, constructors should be extrememly careful about what QEMU code they invoke, as it cannot be guaranteed that the process is fully initialized and so not all normal QEMU API rules apply. Reviewed-by: Richard Henderson Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Markus Armbruster Fixes: e69ee454b5f9 (monitor: Make current monitor a per-coroutine property) Signed-off-by: Daniel P. Berrang=C3=A9 --- monitor/monitor.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index c5a5d30877..da54e1b1ce 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -704,18 +704,22 @@ void monitor_cleanup(void) } } =20 -static void monitor_qapi_event_init(void) +/* + * Initialize static vars that have no deps on external + * module initialization, and are required for external + * functions to call things like monitor_cur() + */ +static void __attribute__((__constructor__(QEMU_CONSTRUCTOR_EARLY))) +monitor_init_static(void) { + qemu_mutex_init(&monitor_lock); + coroutine_mon =3D g_hash_table_new(NULL, NULL); monitor_qapi_event_state =3D g_hash_table_new(qapi_event_throttle_hash, qapi_event_throttle_equal); } =20 void monitor_init_globals(void) { - monitor_qapi_event_init(); - qemu_mutex_init(&monitor_lock); - coroutine_mon =3D g_hash_table_new(NULL, NULL); - /* * The dispatcher BH must run in the main loop thread, since we * have commands assuming that context. It would be nice to get --=20 2.50.1