From patchwork Mon Oct 9 18:28:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115281 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2862211qgn; Mon, 9 Oct 2017 11:30:40 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCPrftFNpHrFMgEdGDNHp56J1nbngayWDNZwThPk52fb7KJS1Sp1cAfGd2IqWM+1R/+j7es X-Received: by 10.84.235.195 with SMTP id m3mr9960647plt.259.1507573840774; Mon, 09 Oct 2017 11:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573840; cv=none; d=google.com; s=arc-20160816; b=OF2VsQEmdSd+l7/I5Ci1dUxCd4NOwrve6Y5zb7QFzv9GbI8f7+BnAjl9ziiJ1h3Q+d szpIdxgx0ZLCFP059uwkcXlXrNurpE+K+pglmzk/7YdcQ/mtcp5TdJ0cdBAsxYrC4jOJ 1Id/hu75P+Ic36BiO6lODTJLcO7gB69Ub3h/+UkI8/OqC2vJqdF5+XnjTMIz7phSAGJ8 g1zzhqWjXaCZ9GiH1rM86cHRJXZj8le1b4VRzAOqtn3+vO2C2CGoo/tkmcajRt+Eq58o 8DzMlOcdF5uo2EhL0WSlL8TLuTIojwMaEegsXXpAXG4mVvPcVEo7ztNB5j3J0cgK2Lg0 QPTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=WHqecuEKlSpVAwa0kHt0fLKDHaOlRPXRYHN7S8k2TCg=; b=uDfN2vLGVZ7v+mXzARG54HT7FZBCI6bFaiAcj49S7VDejQ+/Rt0sJsKFIcuM1Ln8Ox 1xe3IlUMIRdOjqAbYPBXEN6TD/qeQ0r0GynMAfSKaC8FRdP9DyzPcm2U160cMWMn5Eth zpqj82AEbCF3GUN4l+RwFqpr9MTttdvfA2wE5do/zllruRmi/zPnQUAxnlEAlaGgsK0v D5yHr/Rm8PWZcbIXTct9XhL82Z1WsaYuLCjxkSW2K//VE8ha0CnglTcsZBmn3+iMxnbr Ja2+PhRn02VOCZsQGc+lJbTR2guYJdKG/XxNQAU3Nvl/az1QuUS45OKyElTnwA2BvYMg qzYQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1si3121764plb.48.2017.10.09.11.30.40; Mon, 09 Oct 2017 11:30:40 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755174AbdJISaj (ORCPT + 26 others); Mon, 9 Oct 2017 14:30:39 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33742 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755095AbdJISag (ORCPT ); Mon, 9 Oct 2017 14:30:36 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D82D31596; Mon, 9 Oct 2017 11:30:35 -0700 (PDT) Received: from leverpostej.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1C7AB3F483; Mon, 9 Oct 2017 11:30:34 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Mike Snitzer Subject: [PATCH 01/13] dm integrity: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:38 +0100 Message-Id: <1507573730-8083-2-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1507573730-8083-1-git-send-email-mark.rutland@arm.com> References: <1507573730-8083-1-git-send-email-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 1.9.1 diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c index 096fe9b..8c5756e 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);