Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp921722ybl; Fri, 10 Jan 2020 08:58:06 -0800 (PST) X-Google-Smtp-Source: APXvYqyLNUtO98zyQx0RTr0Q0TETXJzcd9KV287dg2Bc06Xsn7SU1k8pL4NsZSX1ZMVZz1dAKnBh X-Received: by 2002:aca:c786:: with SMTP id x128mr2815627oif.2.1578675486781; Fri, 10 Jan 2020 08:58:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578675486; cv=none; d=google.com; s=arc-20160816; b=DWDSysbwFIv74OhFy3EdLCG4om2nggByfsT2krJqHLSkI/AsY4tokKSKVNO287tSQ6 hXPCMA8M4c1+/JbBsT3eawNGJab8Zpw4sYhxabO4TiTf5BCL3W+4i8yEE9pznUol9woB 5+yl/nMHYP04f9LM16CjCcGv5XUTD/jMq9+U92tOThz8YBgM8R2gyxc5KQ8WyMlDpnFk gKNy9PPRwpcj2jG8ZchoNL8YVhgRvSAPyfq5o9UL/sg1ffuh4eXg4ZGZDkA1L489ie+W 2kXYDguxDdPazAqnSbHQQ4u5LNTS1wESCGPZwEaE2KCaDAn8FJRhL5ZyLlqJyEAnFTvp ItSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zZJrqJGae5XSZV4iV+rIs0ghcsM3dWoWu2RU5NgxQFE=; b=w+72obGNJ/UrZvL3lzHPzEzmDf7kSnP/lbCwjUCEgyAl8MfZkcr/UwH4cI6vWNemU1 DD/lvnLQmW4VXJfnTp4TXO0BpZq73p4+5/AvnNNUJKCUwlMCLlt2PMtqZuhNNuwFt20n LyY2FVW+9elgn+RCgPqOHoyiqP7EXuXp6/qTBv+FqKVYDSDjJt8sOucSe1RxA7gVj0JY Gzn6jdKcVT2hQA3j7JviopE/OKUjmiZbiSEx9z+8Z5zP9+l3YTwHkXqGOAg8sBk30I7L BYeK2njGk6Te4hj2hhAv2FNMLvXDnSheVfozDCsJa9YURGAbo8xiYVTI4L3ESiZDC3E9 P2tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=He2XFOmK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10si1689269oti.226.2020.01.10.08.57.55; Fri, 10 Jan 2020 08:58:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=He2XFOmK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728462AbgAJQ4v (ORCPT + 99 others); Fri, 10 Jan 2020 11:56:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:60112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728594AbgAJQ4u (ORCPT ); Fri, 10 Jan 2020 11:56:50 -0500 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D4BFA2072E; Fri, 10 Jan 2020 16:56:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578675409; bh=135J+SSbyQIAXby29osr73Ejb0gbQ2jsQHGnN98q/YM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=He2XFOmKXv4Q9/l2imLkHmPFwEHXREZbY98P5xTPghu6u6GNU03Tn8ZEUBLgd68m9 e1Ns8tF5aEwCFAjMmX5sgNlFsejRJbP65wBUi0Qq6z+yoLcoW7SIZmsxMjOh1MOcY/ DZSwnMe2a6deePG2j8EDW3ljbV4O6TbIKWC+QnXs= From: Will Deacon To: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, kernel-team@android.com, Will Deacon , Michael Ellerman , Peter Zijlstra , Linus Torvalds , Segher Boessenkool , Christian Borntraeger , Luc Van Oostenryck , Arnd Bergmann , Akinobu Mita Subject: [RFC PATCH 3/8] fault_inject: Don't rely on "return value" from WRITE_ONCE() Date: Fri, 10 Jan 2020 16:56:31 +0000 Message-Id: <20200110165636.28035-4-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200110165636.28035-1-will@kernel.org> References: <20200110165636.28035-1-will@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's a bit weird that WRITE_ONCE() evaluates to the value it stores and it's different to smp_store_release(), which can't be used this way. In preparation for preventing this in WRITE_ONCE(), change the fault injection code to use a local variable instead. Cc: Akinobu Mita Signed-off-by: Will Deacon --- lib/fault-inject.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/fault-inject.c b/lib/fault-inject.c index 8186ca84910b..ce12621b4275 100644 --- a/lib/fault-inject.c +++ b/lib/fault-inject.c @@ -106,7 +106,9 @@ bool should_fail(struct fault_attr *attr, ssize_t size) unsigned int fail_nth = READ_ONCE(current->fail_nth); if (fail_nth) { - if (!WRITE_ONCE(current->fail_nth, fail_nth - 1)) + fail_nth--; + WRITE_ONCE(current->fail_nth, fail_nth); + if (!fail_nth) goto fail; return false; -- 2.25.0.rc1.283.g88dfdc4193-goog