From nobody Sat Sep 6 17:16:34 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=reject dis=none) header.from=rsg.ci.i.u-tokyo.ac.jp Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757126601314426.99185116559397; Fri, 5 Sep 2025 19:43:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uuirX-0001VP-Mj; Fri, 05 Sep 2025 22:41:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuirT-0001Sw-HE; Fri, 05 Sep 2025 22:41:07 -0400 Received: from www3579.sakura.ne.jp ([49.212.243.89]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuirE-0005hJ-0z; Fri, 05 Sep 2025 22:41:07 -0400 Received: from [10.40.4.92] (93-51-222-138.ip268.fastwebnet.it [93.51.222.138]) (authenticated bits=0) by www3579.sakura.ne.jp (8.16.1/8.16.1) with ESMTPSA id 5862dKwa051529 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 6 Sep 2025 11:39:37 +0900 (JST) (envelope-from odaki@rsg.ci.i.u-tokyo.ac.jp) DKIM-Signature: a=rsa-sha256; bh=0Wmecb1gZcgzIN0AvJLb87Mi6Fw68Dtp7HJg/gw6MA8=; c=relaxed/relaxed; d=rsg.ci.i.u-tokyo.ac.jp; h=From:Date:Subject:Message-Id:To; s=rs20250326; t=1757126387; v=1; b=etjyPR3my23ArPJxSoWy39JBX4jZVpZJUtMMBy8EjJ6GQioXfkvarpAoPRvQGdnX 8Ei/TWA/xCh3NdIN5ih+dBjJPIM3qpoK2udM+qhMMCAeKeYhcioJB1Yke1yVZEDS eulwEDKtTnj5RxHV/6mG/FLC5HeOPLAOcji6SuKhHvJ6uv1VGz/zPewDXA59DytL wVoLEfwe/gU7vSVNbp/M/kp2v1mTJzNbeOj08CqDfpvTKHgXdJTqBb+B/OenjNx0 kQeebQZ4GHmkvkkMD52Od58z34PNG2B6D8EADn8lGd7GcKf76XcCtehWpAYqAo3i RYJj0GS15GU1gdBDFAATVg== From: Akihiko Odaki Date: Sat, 06 Sep 2025 04:39:04 +0200 Subject: [PATCH v2 1/3] qom: Do not finalize twice MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250906-mr-v2-1-2820f5a3d282@rsg.ci.i.u-tokyo.ac.jp> References: <20250906-mr-v2-0-2820f5a3d282@rsg.ci.i.u-tokyo.ac.jp> In-Reply-To: <20250906-mr-v2-0-2820f5a3d282@rsg.ci.i.u-tokyo.ac.jp> To: qemu-devel@nongnu.org Cc: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Peter Xu , David Hildenbrand , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , Helge Deller , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , "Michael S. Tsirkin" , Gerd Hoffmann , John Snow , qemu-block@nongnu.org, Keith Busch , Klaus Jensen , Jesper Devantier , Marcel Apfelbaum , Nicholas Piggin , qemu-ppc@nongnu.org, John Levon , Thanos Makatos , Yanan Wang , BALATON Zoltan , Jiaxun Yang , Daniel Henrique Barboza , David Gibson , Harsh Prateek Bora , Alexey Kardashevskiy , =?utf-8?q?Alex_Benn=C3=A9e?= , Fabiano Rosas , Thomas Huth , Laurent Vivier , Peter Maydell , Dmitry Osipenko , Akihiko Odaki X-Mailer: b4 0.15-dev-179e8 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=49.212.243.89; envelope-from=odaki@rsg.ci.i.u-tokyo.ac.jp; helo=www3579.sakura.ne.jp X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1757126603132124100 The next change adds code to retain references from an object to the parent when it is being unparented to ensure that the parent outlive them. This change handles the following scenario with the code: 1. The parent starts being finalized without unparenting. 2. Unparenting happens during finalization. 3. The child retains the reference to the parent. 4. The child gets finalized, and releases the reference. In this scenario, the reference counter of the parent reaches to zero, gets incremented, and gets decremented to reach to zero again. This change ensures that finalization will be triggered again in the scenario. Note that the reference counter needs to reach to zero again before finalization ends; otherwise the object will be "resurrected", which is not clearly defined and prohibited with an existing assertion. One thing that looks concerning with this change is that it adds a bool to Object. This is not a problem in the most situations where the host uses 64-bit addressing because the member is added to a gap needed for alignment, and possible double-free scenarios handled with this change are more serious than the extra memory usage for 32-bit hosts. Signed-off-by: Akihiko Odaki --- include/qom/object.h | 1 + qom/object.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index 26df6137b911..7f7b1ffea8fe 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -158,6 +158,7 @@ struct Object ObjectFree *free; GHashTable *properties; uint32_t ref; + bool finalizing; Object *parent; }; =20 diff --git a/qom/object.c b/qom/object.c index 1856bb36c74c..b766b2e9baa7 100644 --- a/qom/object.c +++ b/qom/object.c @@ -725,6 +725,11 @@ static void object_finalize(void *data) Object *obj =3D data; TypeImpl *ti =3D obj->class->type; =20 + if (obj->finalizing) { + return; + } + + obj->finalizing =3D true; object_property_del_all(obj); object_deinit(obj, ti); =20 --=20 2.51.0