From nobody Wed Nov 5 16:53:37 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536353251521827.2395726317691; Fri, 7 Sep 2018 13:47:31 -0700 (PDT) Received: from localhost ([::1]:40202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyNf8-0000oE-HI for importer@patchew.org; Fri, 07 Sep 2018 16:47:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fyNdP-0008QT-NS for qemu-devel@nongnu.org; Fri, 07 Sep 2018 16:45:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fyNdE-0000Bb-QU for qemu-devel@nongnu.org; Fri, 07 Sep 2018 16:45:39 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37632 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fyNdE-00005I-Aa for qemu-devel@nongnu.org; Fri, 07 Sep 2018 16:45:32 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w87KiJq4039121 for ; Fri, 7 Sep 2018 16:45:30 -0400 Received: from e15.ny.us.ibm.com (e15.ny.us.ibm.com [129.33.205.205]) by mx0a-001b2d01.pphosted.com with ESMTP id 2mbyepacuu-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 07 Sep 2018 16:45:30 -0400 Received: from localhost by e15.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 7 Sep 2018 16:45:29 -0400 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e15.ny.us.ibm.com (146.89.104.202) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 7 Sep 2018 16:45:27 -0400 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w87KjRxj23396528 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 7 Sep 2018 20:45:27 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5BC99112063; Fri, 7 Sep 2018 16:44:58 -0400 (EDT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 45289112062; Fri, 7 Sep 2018 16:44:58 -0400 (EDT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Fri, 7 Sep 2018 16:44:58 -0400 (EDT) From: Stefan Berger To: qemu-devel@nongnu.org Date: Fri, 7 Sep 2018 16:45:24 -0400 X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180907204524.2275697-1-stefanb@linux.vnet.ibm.com> References: <20180907204524.2275697-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18090720-0068-0000-0000-0000033746C6 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009679; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01085006; UDB=6.00560063; IPR=6.00865007; MB=3.00023169; MTD=3.00000008; XFM=3.00000015; UTC=2018-09-07 20:45:29 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18090720-0069-0000-0000-000045A8649E Message-Id: <20180907204524.2275697-2-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-09-07_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809070205 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0a-001b2d01.pphosted.com id w87KiJq4039121 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL v1 1/1] tests: Fix signalling race condition in TPM tests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, marcandre.lureau@gmail.com, Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch fixes a race condition and test failure where the main process waits for the signal of a thread but the thread already sent that signal via a condition. Since these signals are non-sticky, we need to introduce a separate variable to make this signal sticky. Signed-off-by: Stefan Berger Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/tpm-crb-test.c | 1 + tests/tpm-emu.c | 11 ++++++++++- tests/tpm-emu.h | 1 + tests/tpm-tis-test.c | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/tpm-crb-test.c b/tests/tpm-crb-test.c index d8f9569203..6fde579bab 100644 --- a/tests/tpm-crb-test.c +++ b/tests/tpm-crb-test.c @@ -151,6 +151,7 @@ int main(int argc, char **argv) test.addr->u.q_unix.path =3D g_build_filename(tmp_path, "sock", NULL); g_mutex_init(&test.data_mutex); g_cond_init(&test.data_cond); + test.data_cond_signal =3D false; =20 thread =3D g_thread_new(NULL, tpm_emu_ctrl_thread, &test); tpm_emu_test_wait_cond(&test); diff --git a/tests/tpm-emu.c b/tests/tpm-emu.c index 8c2bd53cad..125e697181 100644 --- a/tests/tpm-emu.c +++ b/tests/tpm-emu.c @@ -23,9 +23,14 @@ void tpm_emu_test_wait_cond(TestState *s) gint64 end_time =3D g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; =20 g_mutex_lock(&s->data_mutex); - if (!g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) { + + if (!s->data_cond_signal && + !g_cond_wait_until(&s->data_cond, &s->data_mutex, end_time)) { g_assert_not_reached(); } + + s->data_cond_signal =3D false; + g_mutex_unlock(&s->data_mutex); } =20 @@ -72,6 +77,10 @@ void *tpm_emu_ctrl_thread(void *data) QIOChannel *ioc; =20 qio_channel_socket_listen_sync(lioc, s->addr, &error_abort); + + g_mutex_lock(&s->data_mutex); + s->data_cond_signal =3D true; + g_mutex_unlock(&s->data_mutex); g_cond_signal(&s->data_cond); =20 qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN); diff --git a/tests/tpm-emu.h b/tests/tpm-emu.h index 08f902485e..8eb802a79e 100644 --- a/tests/tpm-emu.h +++ b/tests/tpm-emu.h @@ -26,6 +26,7 @@ struct tpm_hdr { typedef struct TestState { GMutex data_mutex; GCond data_cond; + bool data_cond_signal; SocketAddress *addr; QIOChannel *tpm_ioc; GThread *emu_tpm_thread; diff --git a/tests/tpm-tis-test.c b/tests/tpm-tis-test.c index 14754d9706..c8ec14888f 100644 --- a/tests/tpm-tis-test.c +++ b/tests/tpm-tis-test.c @@ -446,6 +446,7 @@ int main(int argc, char **argv) test.addr->u.q_unix.path =3D g_build_filename(tmp_path, "sock", NULL); g_mutex_init(&test.data_mutex); g_cond_init(&test.data_cond); + test.data_cond_signal =3D false; =20 thread =3D g_thread_new(NULL, tpm_emu_ctrl_thread, &test); tpm_emu_test_wait_cond(&test); --=20 2.14.4