Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp716630ybz; Wed, 15 Apr 2020 17:23:11 -0700 (PDT) X-Google-Smtp-Source: APiQypJYFmXm1Nhx+7gCanrMjnJRT1CizDx44hmGYofCYX4IWfUF0lPJZj6RFKf5WlQqp+WP+wGy X-Received: by 2002:a17:906:c82b:: with SMTP id dd11mr7113381ejb.216.1586996591150; Wed, 15 Apr 2020 17:23:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586996591; cv=none; d=google.com; s=arc-20160816; b=jgK48PLgUkTHfyHLC26cpHSfgd4DZNHprVWWm2D6pWoV1njoSgwXrINd6AutXvve9L 2PtKO6r9ChZuBZu1CZBjaLIWqmxBY5pP5ijYKWWVHYlsHUzmR/agACUIQKt7wWGEDqUO risEmEoYpKXssC3vAr4p5RccKKDuUlLHcZvmqS3RIcRxkmJoAoDXKMc4x1VIt3I/STme WoxKOFV8Ev9Pw5nAJAt/Zq/BE4dsYrrTF1rY1iLYzVjH6pdeeirL8z0VhYN4LOhZnVK0 diSyGbiMv8DC81lYUUvVG1URSrPuuHdxmNLJ5C+H/1CrqR8sRqppRm7LS8+owDFVh/w2 YC0g== 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=EJ4RHitoaEr+FCikNV2wd3JgeGJVbH7510IEI/d2UlI=; b=BsKl1KpcsSsKz2InEho/zIkgR6uhp+OUnHgR0ZxhXVvrAje2SrAzZakZd2u4VDoK5v FziI7Cr2pXGXqm6leyKOURqYOEyQh/F8qzUexfNaEOdNlOvp6M9vImdczoovbcujgiCN eDMBuOy9zhcHLd0lt9rEr7eIcWA/1Egbs1r3KKEQUkVPns+ArAy1jXp/0/urr5psE/Gk aeww7pfi0+UwvIE3R3Z7GulC2jHOtv/Wi3Q7Qg2WTnfIU+u76qZZYDFqEcr54F9HF0B+ BA7RgHvddMxKFV+sfND1+Ku9aNolqjh0G+u0pqDF5TYjdw/zXBNdD93oq3Fqk+blTUFM qrtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vE6Qg9+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id bi9si11509332edb.478.2020.04.15.17.22.47; Wed, 15 Apr 2020 17:23:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vE6Qg9+U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2410532AbgDOQxT (ORCPT + 99 others); Wed, 15 Apr 2020 12:53:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:54892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2410496AbgDOQxA (ORCPT ); Wed, 15 Apr 2020 12:53:00 -0400 Received: from localhost.localdomain (unknown [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 1CE4820857; Wed, 15 Apr 2020 16:52:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586969580; bh=XpbKApHWYMc5/QzVBiMD1ies30gMGiNifJYoWGWxCgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vE6Qg9+U9QSoa/pH3npc1gJMA7o/Z0/taFmWB2Xwep44SEXhrR+m9/SJr/xickOPs NHdHB7hnR8Ur/oxMG7SK18wPe3l8IJf1aZIOUDRINncA8smrujVm0IIk4Hj11Xcgpt rrAo42qgZo/WQT3OrkNrZ0d//yzMVHBBGgYGyxXA= 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 v3 04/12] fault_inject: Don't rely on "return value" from WRITE_ONCE() Date: Wed, 15 Apr 2020 17:52:10 +0100 Message-Id: <20200415165218.20251-5-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415165218.20251-1-will@kernel.org> References: <20200415165218.20251-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.26.0.110.g2183baf09c-goog