Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp779404ybl; Thu, 23 Jan 2020 07:36:23 -0800 (PST) X-Google-Smtp-Source: APXvYqzxwFXVBr0tVQ2W7o47it0YBKJISD9ajIUZG6HB6o5pOsGW2sTIVrzehMbLIzpxfZO8CX2V X-Received: by 2002:aca:5f87:: with SMTP id t129mr11156511oib.36.1579793782954; Thu, 23 Jan 2020 07:36:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579793782; cv=none; d=google.com; s=arc-20160816; b=dhXeRqXira8Xo/X4s6Arl73sTjIw35jM6NWD/HNNqmN4k0uUop8eWIGMLRaQfvwc0+ zp327kWM8zpMsh8PzX0Sd/mSOdYvbKdJn6sb7+ySYCQPzBFh45dWn4DIRpWdvN0oo1lv SdVbloQlqnMP0JSRH1RLOOH3NxNkh5GswEaVJnECntqsYWZP+fHhGQ/CNfWkKdLJ028c Uz1Cil2O5PdO+1W6pVrRLw/ZLhg07cRHasAZUxvOidvyycOaB6dg/AI5k8J2g9sFXKXF Y1D7n//y+tLbJ/KWg54AwWiZU12jfezF/mt24cjW5/G/5RNo+9QydaMza9rvH/QQq+vh rHHg== 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=MJazz31Rj3wSKzWJMwtILsGUZWVKP7FmvpQ+iviOzig=; b=tft31/9Ij5SMOl0zuWYaMv8f/7eGxMZz6REkgd/14BQF+/SsewdnrdqaIhbjOud92G /6D699/vxzxSxKPYwLG/FkydVgyOx8OqPy5rtxVsda+mXhIsHg+rojFAhAV3AAHDV+LT i5qmeNf2f8evz2fc03WIU+B2QxCZzlBJnV27wpj/OsEF2VZpcuSKrxTBZhYMSNCJbYak TnuJwkb0WS2yOcU7ZdH9U1UVtfMCbdczPrfkrTjTVA+JFoQdkWy9NQZ0mFRwmu4a9LxV 2BVR2BOLxuXsKe2xWh3wZhIZTc5l8SUPUl3FwGuLklN2Ja7JmjSXFPqRvaLM7MMfEVbM UT/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ss67dAAO; 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 i20si1248601otk.270.2020.01.23.07.36.10; Thu, 23 Jan 2020 07:36:22 -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=Ss67dAAO; 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 S1728992AbgAWPeC (ORCPT + 99 others); Thu, 23 Jan 2020 10:34:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:51640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbgAWPeA (ORCPT ); Thu, 23 Jan 2020 10:34:00 -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 9210720684; Thu, 23 Jan 2020 15:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579793640; bh=h5auAc194P3VII8mHQgj1IfjCspjOIf9RyAgRwfabPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ss67dAAOtvy22KIhAjhOBbyGg+Tw748SW/UJMDq2y7trHkfcNalTtYkIjPMPBxT4m 8TUAMTGTZJUX8yGmCG74zSxEJYGVHBwNwTti8jZkZc7+aLr4+3FHG0VcjeRtp+N62r j89mILXS7z5C1jdTv6zk0jPpw/a3tRKLgeG0sacE= 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 , Peter Oberparleiter , Masahiro Yamada , Nick Desaulniers , Akinobu Mita Subject: [PATCH v2 03/10] fault_inject: Don't rely on "return value" from WRITE_ONCE() Date: Thu, 23 Jan 2020 15:33:34 +0000 Message-Id: <20200123153341.19947-4-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200123153341.19947-1-will@kernel.org> References: <20200123153341.19947-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.341.g760bfbb309-goog