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: 60700 Delivered-To: patch@linaro.org Received: by 10.55.15.231 with SMTP id 100csp302582qkp; Thu, 28 Jan 2016 02:16:15 -0800 (PST) X-Received: by 10.140.106.69 with SMTP id d63mr2354658qgf.88.1453976174786; Thu, 28 Jan 2016 02:16:14 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 16si8940115qky.109.2016.01.28.02.16.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Jan 2016 02:16:14 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dkim=fail header.i=@linaro.org Received: from localhost ([::1]:55059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aOjcc-0008Vc-CS for patch@linaro.org; Thu, 28 Jan 2016 05:16:14 -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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 --- async.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.7.0 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); }