From patchwork Fri Sep 28 10:47:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 10619595 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECF1415A6 for ; Fri, 28 Sep 2018 10:50:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E15AA2B177 for ; Fri, 28 Sep 2018 10:50:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4F1C2B014; Fri, 28 Sep 2018 10:50:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3FD922A5EE for ; Fri, 28 Sep 2018 10:50:29 +0000 (UTC) Received: from localhost ([::1]:42627 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5qLs-0003m7-Tu for patchwork-qemu-devel@patchwork.kernel.org; Fri, 28 Sep 2018 06:50:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5qKL-0002hj-Jt for qemu-devel@nongnu.org; Fri, 28 Sep 2018 06:48:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5qKJ-0005cq-VK for qemu-devel@nongnu.org; Fri, 28 Sep 2018 06:48:53 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:59580 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 1g5qKJ-0005MD-5q for qemu-devel@nongnu.org; Fri, 28 Sep 2018 06:48:51 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8SAeZb7134396 for ; Fri, 28 Sep 2018 06:48:22 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0b-001b2d01.pphosted.com with ESMTP id 2msgx6d36f-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 28 Sep 2018 06:48:21 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 28 Sep 2018 04:48:21 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 28 Sep 2018 04:48:18 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w8SAmHJo24641618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 28 Sep 2018 03:48:17 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A14A4BE04F; Fri, 28 Sep 2018 04:48:17 -0600 (MDT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 45257BE053; Fri, 28 Sep 2018 04:48:17 -0600 (MDT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 28 Sep 2018 04:48:17 -0600 (MDT) From: Stefan Berger To: qemu-stable@nongnu.org, mdroth@linux.vnet.ibm.com Date: Fri, 28 Sep 2018 06:47:39 -0400 X-Mailer: git-send-email 2.14.4 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18092810-0012-0000-0000-000016BD72A2 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009785; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000267; SDB=6.01094832; UDB=6.00565980; IPR=6.00874868; MB=3.00023540; MTD=3.00000008; XFM=3.00000015; UTC=2018-09-28 10:48:19 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18092810-0013-0000-0000-0000549007D1 Message-Id: <20180928104739.2941618-1-stefanb@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-09-28_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1809280109 X-MIME-Autoconverted: from 8bit to quoted-printable by mx0b-001b2d01.pphosted.com id w8SAeZb7134396 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH] 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: qemu-devel@nongnu.org, Stefan Berger Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Hi Michael, please apply the below patch to the 2.12 stable tree. It is a backport of commit 2271b75fa9019 from master. For a 3.0 stable branch 'git cherry-pick 2271b75fa9019' should work. Regards, Stefan 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é 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 = g_build_filename(tmp_path, "sock", NULL); g_mutex_init(&test.data_mutex); g_cond_init(&test.data_cond); + test.data_cond_signal = false; thread = 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 = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; 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 = false; + g_mutex_unlock(&s->data_mutex); } @@ -72,6 +77,10 @@ void *tpm_emu_ctrl_thread(void *data) QIOChannel *ioc; qio_channel_socket_listen_sync(lioc, s->addr, &error_abort); + + g_mutex_lock(&s->data_mutex); + s->data_cond_signal = true; + g_mutex_unlock(&s->data_mutex); g_cond_signal(&s->data_cond); qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN); diff --git a/tests/tpm-emu.h b/tests/tpm-emu.h index ef4bfa8800..09fcf72bde 100644 --- a/tests/tpm-emu.h +++ b/tests/tpm-emu.h @@ -26,6 +26,7 @@ struct tpm_hdr { typedef struct TestState { CompatGMutex data_mutex; CompatGCond 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 = g_build_filename(tmp_path, "sock", NULL); g_mutex_init(&test.data_mutex); g_cond_init(&test.data_cond); + test.data_cond_signal = false; thread = g_thread_new(NULL, tpm_emu_ctrl_thread, &test); tpm_emu_test_wait_cond(&test);