From patchwork Thu Jan 28 10:15:18 2016 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: 8148351 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 54F6ABEEE5 for ; Thu, 28 Jan 2016 10:15:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A612920251 for ; Thu, 28 Jan 2016 10:15:46 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 756812034C for ; Thu, 28 Jan 2016 10:15:41 +0000 (UTC) Received: from localhost ([::1]:55055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOjc4-0007dv-OW for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Jan 2016 05:15:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOjbs-0007bA-E6 for qemu-devel@nongnu.org; Thu, 28 Jan 2016 05:15:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aOjbq-0001XQ-OI for qemu-devel@nongnu.org; Thu, 28 Jan 2016 05:15:28 -0500 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:38842) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOjbq-0001Ww-Gt for qemu-devel@nongnu.org; Thu, 28 Jan 2016 05:15:26 -0500 Received: by mail-wm0-x231.google.com with SMTP id p63so17347937wmp.1 for ; Thu, 28 Jan 2016 02:15:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=r5FaTekJxMf/hAC4rPSkPpARQrc3wwjBDs/yb2Jt4+0=; b=AjpmjXAKMXtCWbN1t0LSXT7Eke6/fDknFaqglt1c0JhDYy13WJbXq/QbfqD9CMaoMz /fs8koKExyLtesEqfRJvJGPRJmMF74OxjVIy+IYkcuGYtmcOkCcQsItmyyAbkftDW2Z0 VIAxBCaQxa4stuFX0D0yaykpi8Kdxlc3jUBSI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=r5FaTekJxMf/hAC4rPSkPpARQrc3wwjBDs/yb2Jt4+0=; b=Ow9MZvoTUkicYywD9sRgp4N3CiYLz4lHCQGW3lG6M3uOYgcfAoeIV5GY+0csIZKlFV 8YWyx8ywpi251/vm7ArpX6DM5o6qqmMKMZNAKTmhfTNwJ2bVsGCsgZeaLcVD+rYEsjyl c7vv4qfjI8kkzzgk2xIZxDBn1Z3xhz/zJ1AK6TcPuwOuMKapMPX5TU5HjdZ7p2ac0Rt5 if6WAovwJ9L80JhEcQvQK07Gu/uaHeF3XpD6dl39tD7LToyZ0TdbQyrerRydWGKFqF+K Z9THXx6yGzRYTo/sCeZfhd3Iuta75/2+ol/2E/gHIdTirdc+8ivetYs03XineKnpBDgp bN/w== X-Gm-Message-State: AG10YOQtEK37PX2dXwn5P63UYuIW1HMkLlAuNVu+XV43qCUMMxLwtE9S1RMMx0uFe+aVvzov X-Received: by 10.28.129.139 with SMTP id c133mr2211354wmd.30.1453976125946; Thu, 28 Jan 2016 02:15:25 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t76sm2135910wmd.13.2016.01.28.02.15.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jan 2016 02:15:24 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id BC1A53E07FA; Thu, 28 Jan 2016 10:15:22 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 28 Jan 2016 10:15:18 +0000 Message-Id: <1453976119-24372-5-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1453976119-24372-1-git-send-email-alex.bennee@linaro.org> References: <1453976119-24372-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::231 Cc: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, "open list:Block I/O path" , mark.burton@greensocs.com, a.rigo@virtualopensystems.com, stefanha@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH v1 4/5] async.c: various atomic fixes for tsan X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Running "make check" under ThreadSanitizer pointed to a number of potential races. - use atomic_mb_read to check bh->schedule - use atomic_set/read primitives to manipulate bh->idle The bh->idle changes are mostly for the benefit of explicit marking for tsan but the code in non-sanitised builds should be the same. Signed-off-by: Alex Bennée Acked-by: Paolo Bonzini --- async.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/async.c b/async.c index e106072..a9cb9c3 100644 --- a/async.c +++ b/async.c @@ -85,10 +85,10 @@ int aio_bh_poll(AioContext *ctx) */ if (!bh->deleted && atomic_xchg(&bh->scheduled, 0)) { /* Idle BHs and the notify BH don't count as progress */ - if (!bh->idle && bh != ctx->notify_dummy_bh) { + if (!atomic_read(&bh->idle) && bh != ctx->notify_dummy_bh) { ret = 1; } - bh->idle = 0; + atomic_set(&bh->idle, 0); aio_bh_call(bh); } } @@ -128,7 +128,7 @@ void qemu_bh_schedule(QEMUBH *bh) AioContext *ctx; ctx = bh->ctx; - bh->idle = 0; + atomic_set(&bh->idle, 0); /* The memory barrier implicit in atomic_xchg makes sure that: * 1. idle & any writes needed by the callback are done before the * locations are read in the aio_bh_poll. @@ -165,8 +165,8 @@ aio_compute_timeout(AioContext *ctx) QEMUBH *bh; for (bh = ctx->first_bh; bh; bh = bh->next) { - if (!bh->deleted && bh->scheduled) { - if (bh->idle) { + if (!bh->deleted && atomic_mb_read(&bh->scheduled)) { + if (atomic_read(&bh->idle)) { /* idle bottom halves will be polled at least * every 10ms */ timeout = 10000000; @@ -286,7 +286,7 @@ void aio_notify(AioContext *ctx) * with atomic_or in aio_ctx_prepare or atomic_add in aio_poll. */ smp_mb(); - if (ctx->notify_me) { + if (atomic_read(&ctx->notify_me)) { event_notifier_set(&ctx->notifier); atomic_mb_set(&ctx->notified, true); }