From patchwork Thu Aug 11 15:14:06 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: 596651 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp835022maz; Thu, 11 Aug 2022 08:21:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR6CNZdIfq5Cg2pC+W8Z23rT+Nwarb7rJ8tNnyHOftqfnZvtiYgHopXWR5XxYlmRBz/6diUH X-Received: by 2002:a05:622a:54f:b0:339:30c8:7ffe with SMTP id m15-20020a05622a054f00b0033930c87ffemr29261904qtx.98.1660231268708; Thu, 11 Aug 2022 08:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660231268; cv=none; d=google.com; s=arc-20160816; b=q7ClSMZsL70faWE7k7wBHvA7OXfywcuzYfyzGI/uMk0Ka8zwZBunNPH77Kfi/W+DBj F3bq70TGEyxUX5o8DFced8k3+R54Lc/eqVMzBToi4etNyzQHovssIKICbgh8ZUNnUrTf e3DtyhVMnDAC2d1WfILzvf0PCKqc+ycNMzGSLHo5yeDCe41qk5H5bhF6apK/vydPPCse FGCxTWMTy4DCD5d54+i+aCpif12IN4UmRA5u1rC5PcDKI7jxQ7Uwxm+WhEB3YlY35S7G Ev7F9AVsLtGkoofUe7qufIv3qa5xcuM00Shsuw0Qdhy2B/mrgVPgWLrZ0Gbg0rnBsLfS FXfQ== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dE/aepTkeWyaKeW9DSbNNJCa9P7NbA+RgibPE9dQEzk=; b=sNsK+PQ9keZvAhw4pHc+/CgtwEW2EqA9uq2YKJn2c0v0VxmJEbu225H8Fa8yT+yJuk cakvUNoRIOLxeC/IcDYdT8ObmdgWO79bP56ylpt9IJ38qYxolH+jWPzBa34j/ZVmAFQT mo3iA/x/5gL546Jr7bKkq3UxdfRsv923ctUo381kF8qQO7PaKt6X99+nTXyJHdPCiT+a d1ta7zW5tmVpI9o0O6AfRm4IISKNQ4J9w2ujd7ueLHKY1ssVfMWbK3dsWqViWYv88gig +8tV5jC0OeO8NvX6xVySDoDofLwyu+z1v8aM8RoUhmwFW7nLesbeIeUIkLrvibLJQzkL 7feg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aNDdNq8S; 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 x9-20020ac85389000000b00341dfb7f6a3si1445463qtp.746.2022.08.11.08.21.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Aug 2022 08:21:08 -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=aNDdNq8S; 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]:42180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oM9zg-0002bL-9B for patch@linaro.org; Thu, 11 Aug 2022 11:21:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oM9tA-0005AA-0A for qemu-devel@nongnu.org; Thu, 11 Aug 2022 11:14:25 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:43704) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oM9t4-0005fm-1k for qemu-devel@nongnu.org; Thu, 11 Aug 2022 11:14:23 -0400 Received: by mail-wr1-x432.google.com with SMTP id n4so19933084wrp.10 for ; Thu, 11 Aug 2022 08:14:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=dE/aepTkeWyaKeW9DSbNNJCa9P7NbA+RgibPE9dQEzk=; b=aNDdNq8Sh2QFpX9tlIcaBhxLbmprD1gOwaBknKuG7qMqRK5ljpjnHxFhiDn/Ia2FEh tUyGUpSHKsB2VoBTNygKFhcRW2srWNFX8idwYPJODfyLg96dgxQa+xZmwnSjy532QXRa zDRGhRhzGWLgzizjgXLbchfoo6qiwxf8INUsPe9EY0mpOlKyXG4gzl98vsLuQbFUhC9m 3hjkAGP0bV86jpDxn4tDEWSHj1k1PYO6cLGTS3ESNpOXbG4KnWPTnNSZn7zytNrOUU/i d5P+rH7aRWaeNVpGsAy9LmxJAXKjaZ8rjTCNKMvM1nu2G7SwsucBD1CQLtx9M30dzThH lbkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=dE/aepTkeWyaKeW9DSbNNJCa9P7NbA+RgibPE9dQEzk=; b=vtoRe+RY94W/gTe5CTxWlqqQu698UI04apSp6xf2p5xt+NpS11mok/XrQoFnYYa6fx foJI577iJ20Eu6JkXNG2bp22dwbqs0FrqsyBYfB7SIkTS186HfnxZ7I64DgmCljKwV4e BU19N+x6Df6ghS+7VKON7tnmnHEeAACc4IZ0LUf5KyB2Wv00ulH9vLPqy3ZrJfH+4LzH kfXkdelUn9zuGVv5tzO/E/VLd3pHbe5UF7PqGJx2hc7eqLbdLImG94X2jupyx+RxMfXD aF1eQ8JSAyX3oIKlbkCILa2gv4Pyjy+EedgrFT1l6y/SWIq9QaPkOt3WrYtGlDZyA5XN ujcA== X-Gm-Message-State: ACgBeo2cXNMAuJjBF9iONFc+WiW0p3Np/k4DQGIEGnW6E7TBd+BtIzS3 H1sELSu+5xnyMwR7NqIp0Yr2a2NZ8Az+Qw== X-Received: by 2002:adf:f7c7:0:b0:21e:fc10:b81b with SMTP id a7-20020adff7c7000000b0021efc10b81bmr21128175wrq.51.1660230855771; Thu, 11 Aug 2022 08:14:15 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id e10-20020a05600c4e4a00b003a5c064717csm2454994wmq.22.2022.08.11.08.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Aug 2022 08:14:13 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5AD8D1FFB8; Thu, 11 Aug 2022 16:14:13 +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 v1 1/8] linux-user: un-parent OBJECT(cpu) when closing thread Date: Thu, 11 Aug 2022 16:14:06 +0100 Message-Id: <20220811151413.3350684-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220811151413.3350684-1-alex.bennee@linaro.org> References: <20220811151413.3350684-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x432.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 f409121202..bfdd60136b 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8594,7 +8594,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 @@ -8604,11 +8610,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();