From nobody Thu May 2 05:21:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559209243; cv=none; d=zoho.com; s=zohoarc; b=D3zS/KbSrHvnWEe/EseuTB8gSW1HN7zsjhBCG5KbmEdtGrVpG6ToI3MB3YXMvU7JrR4Y8aec5N23dIRyGj5OVMG0sv6s7YLICZMH8VR8yEMHGVX/N+aSDIZfjKUmRjsIownNBAgD9EfTKere5qo3p/Jv/E9V5q0Oc3QgJvQboSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559209243; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=jyOl8kxY6njSrmVicOrOgAkLBILhJQw7Ln6V97KcQaM=; b=JA40WBG4YtqI6o8Re80t9AC8CRXqKosb+Pn7wHE4hZaSQ5BkKR+fDNT02OR3naupRinhynVdA8hL4l5OtDVHs42HIQl2xNBFZTZlsY79BacyLf0rAXYZb0WWE22XNLA7CFIemm927Tkl4xedmjNa27CY2XTUE0TEopqZ8ST3br0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1559209243773680.7900978560183; Thu, 30 May 2019 02:40:43 -0700 (PDT) Received: from localhost ([127.0.0.1]:50063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHY4-0000LE-Mt for importer@patchew.org; Thu, 30 May 2019 05:40:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWHS3-0004HR-NK for qemu-devel@nongnu.org; Thu, 30 May 2019 05:34:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWHS2-0008Vf-L3 for qemu-devel@nongnu.org; Thu, 30 May 2019 05:34:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49734) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWHS0-0008KB-Aj; Thu, 30 May 2019 05:34:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A33B43082263; Thu, 30 May 2019 09:34:19 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-57.ams2.redhat.com [10.36.112.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2C165D704; Thu, 30 May 2019 09:34:18 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 30 May 2019 11:34:17 +0200 Message-Id: <20190530093417.23370-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 30 May 2019 09:34:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH resend] test-thread-pool: be more reliable 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-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" There is a rare race between the atomic_cmpxchg and bdrv_aio_cancel/bdrv_aio_cancel_async invocations. Detect it, the only sensible we can do about it is to exit long_cb immediately. Signed-off-by: Paolo Bonzini --- tests/test-thread-pool.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/tests/test-thread-pool.c b/tests/test-thread-pool.c index 9cdccb3a47..0b675923f6 100644 --- a/tests/test-thread-pool.c +++ b/tests/test-thread-pool.c @@ -27,9 +27,10 @@ static int worker_cb(void *opaque) static int long_cb(void *opaque) { WorkerTestData *data =3D opaque; - atomic_inc(&data->n); - g_usleep(2000000); - atomic_inc(&data->n); + if (atomic_cmpxchg(&data->n, 0, 1) =3D=3D 0) { + g_usleep(2000000); + atomic_or(&data->n, 2); + } return 0; } =20 @@ -171,7 +172,7 @@ static void do_test_cancel(bool sync) /* Cancel the jobs that haven't been started yet. */ num_canceled =3D 0; for (i =3D 0; i < 100; i++) { - if (atomic_cmpxchg(&data[i].n, 0, 3) =3D=3D 0) { + if (atomic_cmpxchg(&data[i].n, 0, 4) =3D=3D 0) { data[i].ret =3D -ECANCELED; if (sync) { bdrv_aio_cancel(data[i].aiocb); @@ -185,7 +186,7 @@ static void do_test_cancel(bool sync) g_assert_cmpint(num_canceled, <, 100); =20 for (i =3D 0; i < 100; i++) { - if (data[i].aiocb && data[i].n !=3D 3) { + if (data[i].aiocb && atomic_read(&data[i].n) < 4) { if (sync) { /* Canceling the others will be a blocking operation. */ bdrv_aio_cancel(data[i].aiocb); @@ -201,13 +202,22 @@ static void do_test_cancel(bool sync) } g_assert_cmpint(active, =3D=3D, 0); for (i =3D 0; i < 100; i++) { - if (data[i].n =3D=3D 3) { + g_assert(data[i].aiocb =3D=3D NULL); + switch (data[i].n) { + case 0: + fprintf(stderr, "Callback not canceled but never started?\n"); + abort(); + case 3: + /* Couldn't be canceled asynchronously, must have completed. = */ + g_assert_cmpint(data[i].ret, =3D=3D, 0); + break; + case 4: + /* Could be canceled asynchronously, never started. */ g_assert_cmpint(data[i].ret, =3D=3D, -ECANCELED); - g_assert(data[i].aiocb =3D=3D NULL); - } else { - g_assert_cmpint(data[i].n, =3D=3D, 2); - g_assert(data[i].ret =3D=3D 0 || data[i].ret =3D=3D -ECANCELED= ); - g_assert(data[i].aiocb =3D=3D NULL); + break; + default: + fprintf(stderr, "Callback aborted while running?\n"); + abort(); } } } --=20 2.21.0