From patchwork Wed Aug 3 13:05:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 595100 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp407331maz; Wed, 3 Aug 2022 06:11:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ALCOFdNFSB9VNK/SgpqA6LNE9OYFW7RliD1orpTlfnATJa+rx5Sw/HGxVCO+ufd7lJ+Dl X-Received: by 2002:ad4:5962:0:b0:473:5996:2a13 with SMTP id eq2-20020ad45962000000b0047359962a13mr21234482qvb.37.1659532296178; Wed, 03 Aug 2022 06:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659532296; cv=none; d=google.com; s=arc-20160816; b=KoDUfL/OJBzJ1KSGSe6EyO8zw4U6SQRO9V96zbodunPN0bdLaIgOMPCYbEeVs3/l5N l9pKHVAVpUSRrceKWp7+ilnRLDIjgseiz/Tvm+yYYCpn/ez5JsIjTHqZYQbAz5mCWXs0 d9TQ83iRjSUKfwOxibu5XDnfIGqMpAoxGjeZc55fKHEG9qeFuv9uYbvf2/4mhbvk8C0y 0/OnQoO3gyzBtIbzTTXEXAprBPbAPcBJmZqrJQTgTKja+FS0oeU9Ysq47857RJfEu6H1 0fugKEF5vQHZrbyae3OCEY/F2p7e34BXr9siemUZjjNULmgU4zGRayCU8KExskC/Fwj6 zlCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=vSv3Q3J2ovOGmUs7rN9jQ+/fiC+eBHfeJiLpvH4nmoM=; b=ehvHXxc8GAkyRAwsedRJIakFo7QffSFJ6zxNvuz+lmdhXLgCOnw9WZANG4D+WxhFWR Dm4oSWWj2OVAYmRUkKBQ8b1h5pUlutA6Z8uXYag+FKKEnzhs6X82EtdmRBrL4eKHZruQ PF/NTC1bDejrc8zJuufgLBxvR84qAb2x25/QDGgszilNY2N+jpzez3DOZ0bcjeS4vz42 Axc2mTHSBAEjjtSxIXcz8sWvPb6MI4yAdjY1rYUcqcGndUu/W9wRFvxcESrOJoLGq7qR P4PinSsZgMJRxKi+OgYnTkhscDmBDQK83Glx/wMD90H7S+F7Zr5dtqwadoP4sQMJkzVD vDOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p9yzy0D6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d18-20020a05620a241200b006b671201223si11586349qkn.619.2022.08.03.06.11.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Aug 2022 06:11:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p9yzy0D6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJE9v-0007mX-NS for patch@linaro.org; Wed, 03 Aug 2022 09:11:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJE4L-0002j4-Pt for qemu-devel@nongnu.org; Wed, 03 Aug 2022 09:05:50 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:46002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJE4J-0003KO-9F for qemu-devel@nongnu.org; Wed, 03 Aug 2022 09:05:49 -0400 Received: by mail-wm1-x32b.google.com with SMTP id u14-20020a05600c00ce00b003a323062569so846558wmm.4 for ; Wed, 03 Aug 2022 06:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=vSv3Q3J2ovOGmUs7rN9jQ+/fiC+eBHfeJiLpvH4nmoM=; b=p9yzy0D6xEcgAWOPiPtn/2uJ4VDvigj1jz1Gbn3JeHm+PhXKnbkS1t6gsVdEmMlY5q oOewIKqzxIP1BiCNClXBlol0lTSLwBxEZM1uqSuVSKFzCxNoMkLpG0LQMJKwzciZDfdU wlXtuFH6wGozJoTvhDfFAlnGaIDhUJw5EgTRKFnFVpRq2wd7Lplh/WADgMiSWK8SLAK5 96gqxx2N8EP3ORWADw00tx1UecdYo7mkB1jP28EnZfEe7wBN/TmkWedtM8c0IXB/icJ9 NeAtC1b4VCwyg/Bl37J4VhRs/MBiTqm3NtqP+sq25Zws37N5HpYawDQ20z1B3ScLOFh/ oG3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=vSv3Q3J2ovOGmUs7rN9jQ+/fiC+eBHfeJiLpvH4nmoM=; b=ZKzJw8gjQwGGahj1WBo4RhYnKs3OT20HW7FnpZfVVvO2yGhecwaYF8PeLZr+rA4wl2 /TwSQSkLfyd7krRr3+YjD9+OPsuAkYN++o76tpAQ6ghMkKeKrilY/XdNqgha6b2YmHKe R6mGDyrvjDM1HaRMyZEWmmO6NOxMn/Z+ZY9ehScPbq2CX49QjqzHUNXK76eQPde0rVs9 nzT0Pga0hBmNo7ebHQLqxsu2zoDWY537aKWxQvpImBUgbm9Gqr/lumZ9zStaNFNc8Lwz UH81AVxhIpwGd6qBhoBXLJLianDHTTaZpsOmPmrgWzJ+fcTQTd1wpo8dbB3761zclbqR iIdQ== X-Gm-Message-State: ACgBeo11KY5KxnMAZEMjQjsmBgcYbaO5zbE2HutQ0j37dY0xDq2t6fm0 7BuoSAcwcOedH5ezyR7cBq+a7Q== X-Received: by 2002:a7b:c391:0:b0:3a3:2f22:7bf6 with SMTP id s17-20020a7bc391000000b003a32f227bf6mr2820092wmj.96.1659531945270; Wed, 03 Aug 2022 06:05:45 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id g2-20020a5d64e2000000b0021b970a68f9sm1565558wri.26.2022.08.03.06.05.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 06:05:44 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 843161FFB7; Wed, 3 Aug 2022 14:05:43 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier Subject: [PATCH v2] linux-user: un-parent OBJECT(cpu) when closing thread Date: Wed, 3 Aug 2022 14:05:37 +0100 Message-Id: <20220803130537.763666-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" While forcing the CPU to unrealize by hand does trigger the clean-up code we never fully free resources because refcount never reaches zero. This is because QOM automatically added objects without an explicit parent to /unattached/, incrementing the refcount. Instead of manually triggering unrealization just unparent the object and let the device machinery deal with that for us. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/866 Signed-off-by: Alex Bennée Reviewed-by: Laurent Vivier Message-Id: <20220610143855.1211000-1-alex.bennee@linaro.org> --- v2 - move clearing of child_tidptr to before we finalise the CPU object. While ts itself can be cleared g2h needs the current CPU to resolve the address. --- linux-user/syscall.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b27a6552aa..85b9ff2fa6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8570,7 +8570,13 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, if (CPU_NEXT(first_cpu)) { TaskState *ts = cpu->opaque; - object_property_set_bool(OBJECT(cpu), "realized", false, NULL); + if (ts->child_tidptr) { + put_user_u32(0, ts->child_tidptr); + do_sys_futex(g2h(cpu, ts->child_tidptr), + FUTEX_WAKE, INT_MAX, NULL, NULL, 0); + } + + object_unparent(OBJECT(cpu)); object_unref(OBJECT(cpu)); /* * At this point the CPU should be unrealized and removed @@ -8580,11 +8586,6 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, pthread_mutex_unlock(&clone_lock); - if (ts->child_tidptr) { - put_user_u32(0, ts->child_tidptr); - do_sys_futex(g2h(cpu, ts->child_tidptr), - FUTEX_WAKE, INT_MAX, NULL, NULL, 0); - } thread_cpu = NULL; g_free(ts); rcu_unregister_thread();