From nobody Sat Apr 27 13:46:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599577950; cv=none; d=zohomail.com; s=zohoarc; b=DA2IUziYOI0XGB70JLiID3k6gqRbkiugeXd4yhv/xfVuZjydjj6/Z8xrWThson2+FFcUlCgG0kmgW4D4ltTFXLKd4+Nhz5JNV6213b8KwE5t5DyrHyL9nDfkxpzgSRvaJ4pL4puNZw/9ScXjqdaXYaJxAdWhOHRjEexMropNgp8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599577950; h=Content-Type:Content-Transfer-Encoding:Cc: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=NnBwIumxkiQ9pXVAp8TmFXF/H8dsT5OnHNvh40zg8GM=; b=ECbq0P0gf6/NdMurCKQr8n69L8qVYIvLe77eTTQmmwSaTt4aCJm//+Ugm9DzTd7d6N6t/M8hssF3C/TtNFJr3lXEKCULC10N0oH2G6ibr1VAVJFEruFRflAqvrQ/xtuw1p+PrLZEaqT/NneRMCJNIcjk8+/pGhM5Do7IH4Qqxr4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599577950896104.22791407669979; Tue, 8 Sep 2020 08:12:30 -0700 (PDT) Received: from localhost ([::1]:58700 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFfIJ-00037J-4R for importer@patchew.org; Tue, 08 Sep 2020 11:12:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFfHC-0001yz-GR; Tue, 08 Sep 2020 11:11:18 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:36303) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kFfHA-0005jm-Qm; Tue, 08 Sep 2020 11:11:18 -0400 Received: by mail-pg1-x541.google.com with SMTP id m8so4956184pgi.3; Tue, 08 Sep 2020 08:11:16 -0700 (PDT) Received: from localhost.localdomain ([222.95.248.6]) by smtp.googlemail.com with ESMTPSA id k5sm29436469pjl.3.2020.09.08.08.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 08:11:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NnBwIumxkiQ9pXVAp8TmFXF/H8dsT5OnHNvh40zg8GM=; b=aUTqAVf0xcnhLm5LdCw/3Yl8J3FZAYlcM1wHA4Ly20G9WlSmMpddUMWzi/yQp0AabM aBGYTD0GO/3v+cUTVIslTQKGH1we0e+TJCqIxODSAg+DIaS+dSgwxqgtQcaadZTuZgkB evwWPAuXc18otDjIFOgTxyLS/i+yVmD6+YZx18PNTxjcXQ4XyHO3i6gLnt97duxru96c jMfYAULc3IxLhDfCKrJPHT3TDPSpPvmtNwlibOGv3tS6i2SLOB5pN/KBdWaEfhYLzADr Fm6IPigLmTsK8ehQPyO8k8SydD/0KozCRJJ4kjx7d3KWctmabpAcyVtxMZTDcbtbNpZS f20A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NnBwIumxkiQ9pXVAp8TmFXF/H8dsT5OnHNvh40zg8GM=; b=Ntf//RVYoBbgN1G5UmdYGoNDK2epLCyi0PBRfca12xNteF3zQHWcZTISm9BTfA34B5 CMZ4yGaZBCWSROvwsl/y7Pf1DPLOwCSsXaGCTTDW5GnZY4rwHLhuZFGjVh0uST4CnFIG ErX3qBjR5C2lfK8+DDBgdrEyyBnXUkiEfUtE/TO9SGXFED6QWoNOlpGKsvsAH7PLYGgB TBT8DkLTwAp0Rj0PgB7lCILbW6Pp+8ZiWu7bLUEHsK81Af53acCNAMzwhPx0Fe9CQ6Dw HK6tSOwVtP3KruT+6u8N3ihuEz+jeojYXim4hNMLJCb6RJVRdleHtN46gtuwBE830Zau O5TQ== X-Gm-Message-State: AOAM530TM4KNBn1o1QdBGedki9TzcWyX1ruAp3/HZhHhAyIu4jaKkHc7 kHasVlaJ4UBtx2X9sbpT0htDlEhxA9vdtwrl X-Google-Smtp-Source: ABdhPJxAoU7RoiC4IFWY2lz92+ZxMDnoiscX+pYeT3t9AVEWdT0UeLYPG+FZiRILbbQjtLoIjGT04g== X-Received: by 2002:a17:902:8c94:: with SMTP id t20mr23805794plo.76.1599577874581; Tue, 08 Sep 2020 08:11:14 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org Subject: [PATCH v4 1/2] logging: Fixes memory leak in test-logging.c Date: Tue, 8 Sep 2020 23:10:51 +0800 Message-Id: <20200908151052.713-2-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20200908151052.713-1-luoyonggang@gmail.com> References: <20200908151052.713-1-luoyonggang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::541; envelope-from=luoyonggang@gmail.com; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juan Quintela , QEMU Trivial , Daniel Brodsky , Yonggang Luo , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) g_dir_make_tmp Returns the actual name used. This string should be freed with g_free() when not needed any longer and is is in the GLib file name encoding. In case of errors, NULL is returned and error will be set. Use g_autofree to free it properly Signed-off-by: Yonggang Luo Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/test-logging.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-logging.c b/tests/test-logging.c index 8a1161de1d..957f6c08cd 100644 --- a/tests/test-logging.c +++ b/tests/test-logging.c @@ -196,7 +196,7 @@ static void rmdir_full(gchar const *root) =20 int main(int argc, char **argv) { - gchar *tmp_path =3D g_dir_make_tmp("qemu-test-logging.XXXXXX", NULL); + g_autofree gchar *tmp_path =3D g_dir_make_tmp("qemu-test-logging.XXXXX= X", NULL); int rc; =20 g_test_init(&argc, &argv, NULL); --=20 2.28.0.windows.1 From nobody Sat Apr 27 13:46:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1599578015; cv=none; d=zohomail.com; s=zohoarc; b=I1Wd5TRYjLXiVtC78XShnCSCpnI+Ubz4WNXi5FQwT9jh0b+SUlbsNd/1D+IwhHctkjarxplvWM3N95eeHTYVvheTXJcsTWcSxoViW/x+81cqxcwCOrm35tKrgp/U1rzm0C4P0W+coVrDg2unNY++Mz9Kk04jkWGtF11Na8f+HPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599578015; h=Content-Transfer-Encoding:Cc: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=Mis/yrVWeY+EL6B3pLHydPEbEg8SDdnmsH3w5+AQmwk=; b=Y8NZuRmOSBG/5uaZ6BhuUo1pJykGEffRFLrgUnyn1CTxJpMSAgotsZIIzRlGCIoaxDIDE7wwIToC6ijok5Zh/NHnopuxXIs9KQ299o3kzNaciNzTVLvJdQmDco5f718tjyxCeUv/+RHHDd9QGnMf6la2LdHFGrDTZoVnRmOfA6A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15995780159071021.0274309489055; Tue, 8 Sep 2020 08:13:35 -0700 (PDT) Received: from localhost ([::1]:33960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFfJO-0004a8-Dj for importer@patchew.org; Tue, 08 Sep 2020 11:13:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFfHG-00029x-5o; Tue, 08 Sep 2020 11:11:22 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:36305) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kFfHE-0005k8-Hj; Tue, 08 Sep 2020 11:11:21 -0400 Received: by mail-pg1-x542.google.com with SMTP id m8so4956311pgi.3; Tue, 08 Sep 2020 08:11:19 -0700 (PDT) Received: from localhost.localdomain ([222.95.248.6]) by smtp.googlemail.com with ESMTPSA id k5sm29436469pjl.3.2020.09.08.08.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 08:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Mis/yrVWeY+EL6B3pLHydPEbEg8SDdnmsH3w5+AQmwk=; b=TQLmKAz9nd909OiIlWTMWjeD3By3G6qIuSvgdzpd+FhPl9Omo6vpX6cNJ2LIwZmjUu ByKPJyGP+wyJg8yFQp1D6U78sb4Oa0heoygICrSv1/qXbd37F/eRZMKi7pg5jVPYntvs 0OpD/Ufnr9vACL5a8TseT5Hr7juVW18BFhHZDzG7s4O0gss8tZTIPMC8rAv2VthVrRAb T9qWMg4veqOAMB7qHKmD2Gw+RRP3GfThqSIG9czLACmKJYuZ0tig1RhWfdfjGO7UVvP1 aGfc4lJL4QIZIc5bhB9ijHqWZN8Ay3TNPUdXxMfuDGZ3kd6XpcTMB4UuRf7PJF3u1Ico ZbKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mis/yrVWeY+EL6B3pLHydPEbEg8SDdnmsH3w5+AQmwk=; b=a4+hCwU0FVBDKV8yidqLk0MfyuT+yVvAduMB4I9lRWKKukOz3XBUG2y6ly2w2LKs3f tVeeQcS7Lc/usWXJSNODzaFPaDyjTwSs5TWTVhYvI67B4N66qrYSeVYD3URT6bYGjXK8 /k6858hOLG9om+hEgwVM4tjsdjy+ocXthT4duYTVrMe5l4yShlP4ArwABOxG50tykRfj Ascb2fhAPcKca7oIVNBxlQFEn+yM21ythpb5nVKGEF3PGhjMQvGAl4dUYs0FkhscHs85 BfkX7ipbUI8nwCeQIyVV5ySlMFoak4Uy3iWX8yo5sVQkwOkH9qEHCYO1ENv+HVpIkaWV fPlQ== X-Gm-Message-State: AOAM530vSaMgfVru1dMy6lHKNNtvuZq+0scqVXQOfMXC7b25kHg1OYtt lyLgt8eJIB0V1Ykup7bgC53EGjoukKSRNihS X-Google-Smtp-Source: ABdhPJwfHRUKwTnv3oFRniD03ux2+ImjTaO0O80Wy/6KoeTFX+uiPkljIZAF5iD+QQs7/JCnFIO0Gw== X-Received: by 2002:a17:902:b192:b029:d0:cbe1:e7a1 with SMTP id s18-20020a170902b192b02900d0cbe1e7a1mr1188763plr.18.1599577878343; Tue, 08 Sep 2020 08:11:18 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org Subject: [PATCH v4 2/2] rcu: add uninit destructor for rcu Date: Tue, 8 Sep 2020 23:10:52 +0800 Message-Id: <20200908151052.713-3-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20200908151052.713-1-luoyonggang@gmail.com> References: <20200908151052.713-1-luoyonggang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::542; envelope-from=luoyonggang@gmail.com; helo=mail-pg1-x542.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: QEMU Trivial , Daniel Brodsky , Yonggang Luo , Stefan Hajnoczi , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is necessary if the pending rcu calls are closing and removing temp files. This also provide a function void rcu_wait_finished(void); to fixes test-logging.c test failure on msys2/mingw. On windows if the file doesn't closed, you can not remove it. Signed-off-by: Yonggang Luo --- include/qemu/rcu.h | 5 +++++ tests/test-logging.c | 2 ++ util/rcu.c | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h index 570aa603eb..dd0a92c1d0 100644 --- a/include/qemu/rcu.h +++ b/include/qemu/rcu.h @@ -124,6 +124,11 @@ extern void rcu_unregister_thread(void); extern void rcu_enable_atfork(void); extern void rcu_disable_atfork(void); =20 +/* + * Wait all rcu call executed and exit the rcu thread. + */ +extern void rcu_wait_finished(void); + struct rcu_head; typedef void RCUCBFunc(struct rcu_head *head); =20 diff --git a/tests/test-logging.c b/tests/test-logging.c index 957f6c08cd..7a5b59f4a5 100644 --- a/tests/test-logging.c +++ b/tests/test-logging.c @@ -210,6 +210,8 @@ int main(int argc, char **argv) tmp_path, test_logfile_lock); =20 rc =3D g_test_run(); + qemu_log_close(); + rcu_wait_finished(); =20 rmdir_full(tmp_path); g_free(tmp_path); diff --git a/util/rcu.c b/util/rcu.c index 60a37f72c3..43367988b9 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -308,10 +308,20 @@ void rcu_unregister_thread(void) qemu_mutex_unlock(&rcu_registry_lock); } =20 +typedef struct QemuRcuMessage { + struct rcu_head rcu; + void *message; +} QemuRcuMessage; + +static int rcu_thread_exit_called =3D 0; +static int rcu_thread_exited =3D 0; +static QemuRcuMessage rcu_thread_message; + static void rcu_init_complete(void) { QemuThread thread; - + atomic_mb_set(&rcu_thread_exit_called, 0); + atomic_mb_set(&rcu_thread_exited, 0); qemu_mutex_init(&rcu_registry_lock); qemu_mutex_init(&rcu_sync_lock); qemu_event_init(&rcu_gp_event, true); @@ -327,6 +337,26 @@ static void rcu_init_complete(void) rcu_register_thread(); } =20 +static void rcu_thread_exit(QemuRcuMessage *param) +{ + atomic_mb_set((int*)param->message, 1); + qemu_thread_exit(NULL); +} + +void rcu_wait_finished(void) +{ + if (atomic_xchg(&rcu_thread_exit_called, 1) =3D=3D 0) + { + rcu_thread_message.message =3D &rcu_thread_exited; + call_rcu(&rcu_thread_message, rcu_thread_exit, rcu); + } + + while (atomic_mb_read(&rcu_thread_exited) =3D=3D 0) + { + g_usleep(10000); + } +} + static int atfork_depth =3D 1; =20 void rcu_enable_atfork(void) @@ -379,3 +409,8 @@ static void __attribute__((__constructor__)) rcu_init(v= oid) #endif rcu_init_complete(); } + +static void __attribute__((__destructor__)) rcu_uninit(void) +{ + rcu_wait_finished(); +} --=20 2.28.0.windows.1