From patchwork Mon Oct 23 21:07:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 116865 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5082222qgn; Mon, 23 Oct 2017 14:07:51 -0700 (PDT) X-Google-Smtp-Source: ABhQp+StVaRKEmp9m4iUEsq1rajLS5oVOP1fzcDA4G5LSLpuLCPXmud3NBSEWYQyOjgdWbV6ei97 X-Received: by 10.99.163.97 with SMTP id v33mr12626438pgn.206.1508792870879; Mon, 23 Oct 2017 14:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508792870; cv=none; d=google.com; s=arc-20160816; b=fRxzKisJUeQCdnoXGA2EsuWD+RXO8xbkSRSpOMAhL5zEBT3r6FfXXBNwKuvw0+3FzF C+MK3iDQGS7r0ns8hZQW9B4DuXpo1vNj6V7A8xDuXKKdSO+kWQQ0KZAXL14xiQANVWUi MOw90RHDv48OwJUnSY4LErovuLfvXbbva4sT71akh4gznm+t/9Sxttsg0lOHRol/dFLy 65bdrMm0rLaSIRuW7B7H3hI9GAbVnOEE6YrYQjurABeEjvJawFQ4BNoLnUYdgziLQ3Wm UahwaQDfCFdcAj3PqwsgIUsJy50v/NFdHAeNXasob4pETPrAnEEYDZVUCfnsMxpRF4NI f5ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=tqNtfuA+E7uwiFAni1BoZuZXjwj3UW+f8UhkrEn73q0=; b=ZeeU3NUlMedm7NzAAL2IJEFiD+dELlxG1ezFqBj9FgX5p0+FmuKBg/9lKQmrkb8wPx Yuw78ufUnZ6D5bAT1AP4WH6UAIxxamwhaUGZDlQ0WF30nv1V3CzSj9ktRaTLVqSJ7BSZ HCdZpwoEy6UESLOQby56iWxgXHGowd+bL8py1f5Oy0QG1nSvh87G2WBKXiTevoQOeTVy AfynLP7gB7aveRLiVR8UffdNX9GpwRB2b6EMykrSl6Y7lxa+B13wu7nIf7SvvZqORyAt OJsq7GTG8KLUq8hyppKr1fAP7GIbeYK8PvaWkDi9gMGwAOA/BGR6FuHno6DJOKV1kSaV vK4g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si5312878pgs.824.2017.10.23.14.07.50; Mon, 23 Oct 2017 14:07:50 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751711AbdJWVHt (ORCPT + 27 others); Mon, 23 Oct 2017 17:07:49 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:52700 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751344AbdJWVHj (ORCPT ); Mon, 23 Oct 2017 17:07:39 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9NL7MDs101220 for ; Mon, 23 Oct 2017 17:07:39 -0400 Received: from e19.ny.us.ibm.com (e19.ny.us.ibm.com [129.33.205.209]) by mx0b-001b2d01.pphosted.com with ESMTP id 2dskdjv62p-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 23 Oct 2017 17:07:39 -0400 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 23 Oct 2017 17:07:38 -0400 Received: from b01cxnp23033.gho.pok.ibm.com (9.57.198.28) by e19.ny.us.ibm.com (146.89.104.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 23 Oct 2017 17:07:34 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9NL7Ywp1835468; Mon, 23 Oct 2017 21:07:34 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DCB69B204E; Mon, 23 Oct 2017 17:04:48 -0400 (EDT) Received: from paulmck-ThinkPad-W541 (unknown [9.80.218.156]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id B25FEB2056; Mon, 23 Oct 2017 17:04:48 -0400 (EDT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 955CC16C2B55; Mon, 23 Oct 2017 14:07:33 -0700 (PDT) From: "Paul E. McKenney" To: mingo@kernel.org Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, will.deacon@arm.com, mark.rutland@arm.com, snitzer@redhat.com, thor.thayer@linux.intel.com, viro@zeniv.linux.org.uk, davem@davemloft.net, shuah@kernel.org, mpe@ellerman.id.au, tj@kernel.org, torvalds@linux-foundation.org Subject: [PATCH 01/19] dm integrity: Kill off ACCESS_ONCE() Date: Mon, 23 Oct 2017 14:07:11 -0700 X-Mailer: git-send-email 2.5.2 In-Reply-To: <20171023210408.GA2930@linux.vnet.ibm.com> References: <20171023210408.GA2930@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17102321-0056-0000-0000-000003DDCB00 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007941; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000239; SDB=6.00935454; UDB=6.00471299; IPR=6.00715720; BA=6.00005656; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017676; XFM=3.00000015; UTC=2017-10-23 21:07:38 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17102321-0057-0000-0000-00000814D5DA Message-Id: <1508792849-3115-1-git-send-email-paulmck@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-23_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710230296 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland For several reasons, it is desirable to use {READ,WRITE}_ONCE() in preference to ACCESS_ONCE(), and new code is expected to use one of the former. So far, there's been no reason to change most existing uses of ACCESS_ONCE(), as these aren't currently harmful. However, for some features it is necessary to instrument reads and writes separately, which is not possible with ACCESS_ONCE(). This distinction is critical to correct operation. It's possible to transform the bulk of kernel code using the Coccinelle script below. However, this doesn't pick up some uses, including those in dm-integrity.c. As a preparatory step, this patch converts the driver to use {READ,WRITE}_ONCE() consistently. At the same time, this patch adds the missing include of necessary for the {READ,WRITE}_ONCE() definitions. ---- virtual patch @ depends on patch @ expression E1, E2; @@ - ACCESS_ONCE(E1) = E2 + WRITE_ONCE(E1, E2) @ depends on patch @ expression E; @@ - ACCESS_ONCE(E) + READ_ONCE(E) ---- Signed-off-by: Mark Rutland Cc: Mike Snitzer --- drivers/md/dm-integrity.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) -- 2.5.2 diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c index 096fe9b66c50..8c5756e1df94 100644 --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -6,6 +6,7 @@ * This file is released under the GPL. */ +#include #include #include #include @@ -80,13 +81,13 @@ struct journal_entry { #define journal_entry_tag(ic, je) ((__u8 *)&(je)->last_bytes[(ic)->sectors_per_block]) #if BITS_PER_LONG == 64 -#define journal_entry_set_sector(je, x) do { smp_wmb(); ACCESS_ONCE((je)->u.sector) = cpu_to_le64(x); } while (0) +#define journal_entry_set_sector(je, x) do { smp_wmb(); WRITE_ONCE((je)->u.sector, cpu_to_le64(x)); } while (0) #define journal_entry_get_sector(je) le64_to_cpu((je)->u.sector) #elif defined(CONFIG_LBDAF) -#define journal_entry_set_sector(je, x) do { (je)->u.s.sector_lo = cpu_to_le32(x); smp_wmb(); ACCESS_ONCE((je)->u.s.sector_hi) = cpu_to_le32((x) >> 32); } while (0) +#define journal_entry_set_sector(je, x) do { (je)->u.s.sector_lo = cpu_to_le32(x); smp_wmb(); WRITE_ONCE((je)->u.s.sector_hi, cpu_to_le32((x) >> 32)); } while (0) #define journal_entry_get_sector(je) le64_to_cpu((je)->u.sector) #else -#define journal_entry_set_sector(je, x) do { (je)->u.s.sector_lo = cpu_to_le32(x); smp_wmb(); ACCESS_ONCE((je)->u.s.sector_hi) = cpu_to_le32(0); } while (0) +#define journal_entry_set_sector(je, x) do { (je)->u.s.sector_lo = cpu_to_le32(x); smp_wmb(); WRITE_ONCE((je)->u.s.sector_hi, cpu_to_le32(0)); } while (0) #define journal_entry_get_sector(je) le32_to_cpu((je)->u.s.sector_lo) #endif #define journal_entry_is_unused(je) ((je)->u.s.sector_hi == cpu_to_le32(-1)) @@ -320,7 +321,7 @@ static void dm_integrity_io_error(struct dm_integrity_c *ic, const char *msg, in static int dm_integrity_failed(struct dm_integrity_c *ic) { - return ACCESS_ONCE(ic->failed); + return READ_ONCE(ic->failed); } static commit_id_t dm_integrity_commit_id(struct dm_integrity_c *ic, unsigned i, @@ -1545,7 +1546,7 @@ static bool __journal_read_write(struct dm_integrity_io *dio, struct bio *bio, smp_mb(); if (unlikely(waitqueue_active(&ic->copy_to_journal_wait))) wake_up(&ic->copy_to_journal_wait); - if (ACCESS_ONCE(ic->free_sectors) <= ic->free_sectors_threshold) { + if (READ_ONCE(ic->free_sectors) <= ic->free_sectors_threshold) { queue_work(ic->commit_wq, &ic->commit_work); } else { schedule_autocommit(ic); @@ -1798,7 +1799,7 @@ static void integrity_commit(struct work_struct *w) ic->n_committed_sections += commit_sections; spin_unlock_irq(&ic->endio_wait.lock); - if (ACCESS_ONCE(ic->free_sectors) <= ic->free_sectors_threshold) + if (READ_ONCE(ic->free_sectors) <= ic->free_sectors_threshold) queue_work(ic->writer_wq, &ic->writer_work); release_flush_bios: @@ -1980,7 +1981,7 @@ static void integrity_writer(struct work_struct *w) unsigned prev_free_sectors; /* the following test is not needed, but it tests the replay code */ - if (ACCESS_ONCE(ic->suspending)) + if (READ_ONCE(ic->suspending)) return; spin_lock_irq(&ic->endio_wait.lock);