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); From patchwork Mon Oct 9 18:28:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115293 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2864871qgn; Mon, 9 Oct 2017 11:33:44 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCVjbS+TE3ksRMDpT+Xz1SoiZYLtsxUHtW5ZR0FIQ0nL5LQAMWjfs9xAvGH6PCoCZylrW6U X-Received: by 10.84.130.67 with SMTP id 61mr10005425plc.131.1507574024326; Mon, 09 Oct 2017 11:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507574024; cv=none; d=google.com; s=arc-20160816; b=ze5jTxYRPKmKBKLy2EJrLJ6Bky+KtTOVkBk79DyfVNERTv7aWVngJLMcAp93Wl+i0m X5OqRzIDVqNI0xTO1QjnTfdryK+jpV8cgP/HSDSf1tzBO/JeYThKREMRb+o0DLlGJhwT DdNsnMwRhzvG8a42N95UoXbdQggBEGC5S7tzbHIWeq2Ej7QpSyTrE6IL/HkU0mpB4QFD Lay887gs3yzq17xQVKlqdohq0EFb1lsKNtjT/sDhn28UVYLcwL2UaW4BUFVkqQ1KHQhI Su9mfGeqv5mdSgWIvPFL9ljZclqKrLKCaXpInmmr1nuGNrCbenXvk6J1M+xJA4On6wTF DGlQ== 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=DGU8g+qVvoZCf0N3KcgoHczOwnUzfrYXUg55RL+UoVY=; b=evBGj3/2J/lfK5dBCsmZU96tXVRpqqs8lkzZ7aXaO7yxKYYwKvdKOjcrGT7HfZSG0c soh1amEkellj8W2bJqLscVFuQUyoovc1yc/ablZ0jRQka3sAogj1zNhk3g5PzU4wb5SE L4YGlOHyGcB0PUzpjPWMdgyRPgMYcyCd+XsDQW4oLwgGqZ4HUU/NY7klGZCfnQIKLuXN aZRivKHIlzoS+ueZ51Ehq+Ns7jRunj24SgJfbOhyyyWZlLYUF9itru22olvslEk67M1p 8Igh/vFdomJ404rxhMzcU0U/HicNujeWLXfzmu6KOD2G2BpwVPyYwOmhM9W5+vXTazDY IMdQ== 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 f1si3318731pld.151.2017.10.09.11.33.44; Mon, 09 Oct 2017 11:33:44 -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 S1755419AbdJISdl (ORCPT + 26 others); Mon, 9 Oct 2017 14:33:41 -0400 Received: from foss.arm.com ([217.140.101.70]:33752 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755111AbdJISai (ORCPT ); Mon, 9 Oct 2017 14:30:38 -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 827061596; Mon, 9 Oct 2017 11:30:38 -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 8DC583F483; Mon, 9 Oct 2017 11:30:37 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Borislav Petkov , Thor Thayer Subject: [PATCH 02/13] EDAC, altera: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:39 +0100 Message-Id: <1507573730-8083-3-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 handle comments, leaving references to ACCESS_ONCE() instances which have been removed. As a preparatory step, this patch converts the Altera EDAC code and comments to use {READ,WRITE}_ONCE() consistently. ---- 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: Borislav Petkov Cc: Thor Thayer --- drivers/edac/altera_edac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 1.9.1 Acked-by: Thor Thayer diff --git a/drivers/edac/altera_edac.c b/drivers/edac/altera_edac.c index 346c498..11d6419 100644 --- a/drivers/edac/altera_edac.c +++ b/drivers/edac/altera_edac.c @@ -175,11 +175,11 @@ static ssize_t altr_sdr_mc_err_inject_write(struct file *file, /* * To trigger the error, we need to read the data back * (the data was written with errors above). - * The ACCESS_ONCE macros and printk are used to prevent the + * The READ_ONCE macros and printk are used to prevent the * the compiler optimizing these reads out. */ - reg = ACCESS_ONCE(ptemp[0]); - read_reg = ACCESS_ONCE(ptemp[1]); + reg = READ_ONCE(ptemp[0]); + read_reg = READ_ONCE(ptemp[1]); /* Force Read */ rmb(); @@ -618,7 +618,7 @@ static ssize_t altr_edac_device_trig(struct file *file, for (i = 0; i < (priv->trig_alloc_sz / sizeof(*ptemp)); i++) { /* Read data so we're in the correct state */ rmb(); - if (ACCESS_ONCE(ptemp[i])) + if (READ_ONCE(ptemp[i])) result = -1; /* Toggle Error bit (it is latched), leave ECC enabled */ writel(error_mask, (drvdata->base + priv->set_err_ofst)); @@ -635,7 +635,7 @@ static ssize_t altr_edac_device_trig(struct file *file, /* Read out written data. ECC error caused here */ for (i = 0; i < ALTR_TRIGGER_READ_WRD_CNT; i++) - if (ACCESS_ONCE(ptemp[i]) != i) + if (READ_ONCE(ptemp[i]) != i) edac_printk(KERN_ERR, EDAC_DEVICE, "Read doesn't match written data\n"); From patchwork Mon Oct 9 18:28:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115283 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2862320qgn; Mon, 9 Oct 2017 11:30:47 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBpA1EVDHEf7VR1hRoy6ujDGes5arsR3t7CqGnyDRPDwrkn9qLBFHHx+a33GqyraytvubxM X-Received: by 10.98.141.215 with SMTP id p84mr10850019pfk.160.1507573847465; Mon, 09 Oct 2017 11:30:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573847; cv=none; d=google.com; s=arc-20160816; b=a7VNTuf/T7S8g+qEduFQ8LhYXVdSUk/86cBC+iAxwX9l0Wnd76DKrX2mWW4G3x/FOU y5fLB4QD9dVspEZ3mxJhYrhJR5ej6Cx9BunjyRPHVWaWSs0VtSok7OgLOzmZT3JT3UA6 hVmzH06j7xLcF5KM58FDfrsKjjhCab/9au64LQ3UHRq+Xz2F2JFPfRL5SjYrZ84e0hLQ kgyhU5L5Vo7+Zp1gSPvzr1b0cl3rouzw2RYW2tD25M+D2mF4/slxT/fUwg7DfDNSnlzu QeJ0SWhSWUS6T3JkBZdJc8MGLUoHG6UlfYwg2j0DGU6NpzHIgf+CPFvDCGA/6lX/8Ewu A6Tw== 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=xsLc8Kl2+L2/R8dyHmh1HcunntQwrxIssb3AjvUw6as=; b=z1KlWIP56veIjaGK72Oh8gfBProVVpWjXMz6G1Tp4guyRJl6LuYXPWMfNtvDOk38SW kdiIgsOItPofKB0FwVm9K6+SzOcXtCumHwiQSV5lMhIyrRNmSQTxI7EHiNIsW8wmjoPc d52/XKBHFE4EIGlv24VAz3vKlKGou/MllfQV/oyFArmIV41mnczuRoeRudzJOjPknY0J F9Yr56v9g2/yDptZWFOTPfAq3gPxAN2MFC7CLkQOpiJSnIz8BudLYMeLHCZKJcGwDgQf +wL50wwvRAJVMYNhA4ktPULGz30dejPvWkrUyZTGasgvYPo9vuMNdDEw9tIFRpB6KrLP cnxQ== 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 r25si7451145pfk.524.2017.10.09.11.30.47; Mon, 09 Oct 2017 11:30:47 -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 S1755224AbdJISap (ORCPT + 26 others); Mon, 9 Oct 2017 14:30:45 -0400 Received: from foss.arm.com ([217.140.101.70]:33756 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755110AbdJISak (ORCPT ); Mon, 9 Oct 2017 14:30:40 -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 7114815AD; Mon, 9 Oct 2017 11:30:40 -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 8649F3F483; Mon, 9 Oct 2017 11:30:39 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Jonathan Hunter , Thierry Reding Subject: [PATCH 03/13] firmware/ivc: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:40 +0100 Message-Id: <1507573730-8083-4-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 workqueue: kill off ACCESS_ONCE() 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 handle comments, leaving references to ACCESS_ONCE() instances which have been removed. As a preparatory step, this patch converts the Tegra IVC code and comments to use {READ,WRITE}_ONCE() consistently. ---- 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: Jonathan Hunter Cc: Thierry Reding --- drivers/firmware/tegra/ivc.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) -- 1.9.1 diff --git a/drivers/firmware/tegra/ivc.c b/drivers/firmware/tegra/ivc.c index a01461d..00de793 100644 --- a/drivers/firmware/tegra/ivc.c +++ b/drivers/firmware/tegra/ivc.c @@ -99,11 +99,11 @@ static inline bool tegra_ivc_empty(struct tegra_ivc *ivc, { /* * This function performs multiple checks on the same values with - * security implications, so create snapshots with ACCESS_ONCE() to + * security implications, so create snapshots with READ_ONCE() to * ensure that these checks use the same values. */ - u32 tx = ACCESS_ONCE(header->tx.count); - u32 rx = ACCESS_ONCE(header->rx.count); + u32 tx = READ_ONCE(header->tx.count); + u32 rx = READ_ONCE(header->rx.count); /* * Perform an over-full check to prevent denial of service attacks @@ -124,8 +124,8 @@ static inline bool tegra_ivc_empty(struct tegra_ivc *ivc, static inline bool tegra_ivc_full(struct tegra_ivc *ivc, struct tegra_ivc_header *header) { - u32 tx = ACCESS_ONCE(header->tx.count); - u32 rx = ACCESS_ONCE(header->rx.count); + u32 tx = READ_ONCE(header->tx.count); + u32 rx = READ_ONCE(header->rx.count); /* * Invalid cases where the counters indicate that the queue is over @@ -137,8 +137,8 @@ static inline bool tegra_ivc_full(struct tegra_ivc *ivc, static inline u32 tegra_ivc_available(struct tegra_ivc *ivc, struct tegra_ivc_header *header) { - u32 tx = ACCESS_ONCE(header->tx.count); - u32 rx = ACCESS_ONCE(header->rx.count); + u32 tx = READ_ONCE(header->tx.count); + u32 rx = READ_ONCE(header->rx.count); /* * This function isn't expected to be used in scenarios where an @@ -151,8 +151,8 @@ static inline u32 tegra_ivc_available(struct tegra_ivc *ivc, static inline void tegra_ivc_advance_tx(struct tegra_ivc *ivc) { - ACCESS_ONCE(ivc->tx.channel->tx.count) = - ACCESS_ONCE(ivc->tx.channel->tx.count) + 1; + WRITE_ONCE(ivc->tx.channel->tx.count, + READ_ONCE(ivc->tx.channel->tx.count) + 1); if (ivc->tx.position == ivc->num_frames - 1) ivc->tx.position = 0; @@ -162,8 +162,8 @@ static inline void tegra_ivc_advance_tx(struct tegra_ivc *ivc) static inline void tegra_ivc_advance_rx(struct tegra_ivc *ivc) { - ACCESS_ONCE(ivc->rx.channel->rx.count) = - ACCESS_ONCE(ivc->rx.channel->rx.count) + 1; + WRITE_ONCE(ivc->rx.channel->rx.count, + READ_ONCE(ivc->rx.channel->rx.count) + 1); if (ivc->rx.position == ivc->num_frames - 1) ivc->rx.position = 0; @@ -428,7 +428,7 @@ int tegra_ivc_notified(struct tegra_ivc *ivc) /* Copy the receiver's state out of shared memory. */ tegra_ivc_invalidate(ivc, ivc->rx.phys + offset); - state = ACCESS_ONCE(ivc->rx.channel->tx.state); + state = READ_ONCE(ivc->rx.channel->tx.state); if (state == TEGRA_IVC_STATE_SYNC) { offset = offsetof(struct tegra_ivc_header, tx.count); From patchwork Mon Oct 9 18:28:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115282 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2862344qgn; Mon, 9 Oct 2017 11:30:49 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBeEnKDT2hq//wo1wnUk4nNyjsucLHV/CchLgANkidbSm5Ar12H/+g62sTWhc6/m9zR0whC X-Received: by 10.98.71.132 with SMTP id p4mr11190918pfi.274.1507573849721; Mon, 09 Oct 2017 11:30:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573849; cv=none; d=google.com; s=arc-20160816; b=yL+Prxi6IiJiMZ+kcf+wk/0GmP57p+6EwvaaJEUO7oDZLD0y+QXz8rxZKgOsp1JcMV 9v8S2K4a/As8RLgjux8ZDmMTglRkZctfPsK6dtIFggmhNN4jEup1m838Ic2jB/JSFc67 6KoQzg5fmbEFQdUFIB4C1wlHNU4uOjnk19LAugMiij4kePAuxBU/1lhQwJ1xhyK31p9V T3OcQ5vJAC4OOlcUz8Zl58+a88cdaY1PQmRC9Pe1Vqb4aCuiqHmqOQgUKzk/LuU2Mvh6 XkvJfFHe2eusne/Dl4i1L9NRyuUsHPVWH0W9UrycWafWImikiiVZ7ZeQ9QEpVWyLCPj/ RYpw== 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=wSjySLisXfdfwUsnth64XtFzBnmhw94HVWKtVKTfT3A=; b=DfaHC0Tn0iyVVPd9y1YH8VEFKpP5CGsQVWvuaCPV9RH6w39H554lka/cgHhU2ViZwt NTeqiXXuI1EQ7Jay2T/2j3ZHe1HhTN4RTz5cn7evIMnvkrZJDGHDgFbdnUhVPHiss1oe cKbOM8Ic4GwuI6sliSLfCjMHr5CJ/sSUGhKb82IirvO3p0Lzp4ht6EOLj+NTCj6IwrSr CrdSef5JC0CCPVa+lut4KyjXfqahDa5xEWJ1zmnem1RUI0v8lS1QZGyN1vIMTDEyRPD2 cIXtkLl30MYo36VlIwjg405cS5Ifz3xVOHFEXB7gR9tW2FmiNCg3+CmssX27/j223gnr W4Jw== 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 r25si7451145pfk.524.2017.10.09.11.30.49; Mon, 09 Oct 2017 11:30:49 -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 S1755272AbdJISas (ORCPT + 26 others); Mon, 9 Oct 2017 14:30:48 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33766 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755110AbdJISaq (ORCPT ); Mon, 9 Oct 2017 14:30:46 -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 16C141596; Mon, 9 Oct 2017 11:30:46 -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 4F4E93F483; Mon, 9 Oct 2017 11:30:45 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Al Viro , Andrew Morton Subject: [PATCH 04/13] fs: dcache: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:41 +0100 Message-Id: <1507573730-8083-5-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 handle comments, leaving references to ACCESS_ONCE() instances which have been removed. As a preparatory step, this patch converts the dcache code and comments to use {READ,WRITE}_ONCE() consistently. ---- 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: Al Viro Cc: Andrew Morton --- fs/dcache.c | 18 +++++++++--------- include/linux/dcache.h | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) -- 1.9.1 diff --git a/fs/dcache.c b/fs/dcache.c index f901413..f283cd3 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -630,7 +630,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry) rcu_read_lock(); spin_unlock(&dentry->d_lock); again: - parent = ACCESS_ONCE(dentry->d_parent); + parent = READ_ONCE(dentry->d_parent); spin_lock(&parent->d_lock); /* * We can't blindly lock dentry until we are sure @@ -721,7 +721,7 @@ static inline bool fast_dput(struct dentry *dentry) * around with a zero refcount. */ smp_rmb(); - d_flags = ACCESS_ONCE(dentry->d_flags); + d_flags = READ_ONCE(dentry->d_flags); d_flags &= DCACHE_REFERENCED | DCACHE_LRU_LIST | DCACHE_DISCONNECTED; /* Nothing to do? Dropping the reference was all we needed? */ @@ -850,11 +850,11 @@ struct dentry *dget_parent(struct dentry *dentry) * locking. */ rcu_read_lock(); - ret = ACCESS_ONCE(dentry->d_parent); + ret = READ_ONCE(dentry->d_parent); gotref = lockref_get_not_zero(&ret->d_lockref); rcu_read_unlock(); if (likely(gotref)) { - if (likely(ret == ACCESS_ONCE(dentry->d_parent))) + if (likely(ret == READ_ONCE(dentry->d_parent))) return ret; dput(ret); } @@ -3040,7 +3040,7 @@ static int prepend(char **buffer, int *buflen, const char *str, int namelen) * @buflen: allocated length of the buffer * @name: name string and length qstr structure * - * With RCU path tracing, it may race with d_move(). Use ACCESS_ONCE() to + * With RCU path tracing, it may race with d_move(). Use READ_ONCE() to * make sure that either the old or the new name pointer and length are * fetched. However, there may be mismatch between length and pointer. * The length cannot be trusted, we need to copy it byte-by-byte until @@ -3054,8 +3054,8 @@ static int prepend(char **buffer, int *buflen, const char *str, int namelen) */ static int prepend_name(char **buffer, int *buflen, const struct qstr *name) { - const char *dname = ACCESS_ONCE(name->name); - u32 dlen = ACCESS_ONCE(name->len); + const char *dname = READ_ONCE(name->name); + u32 dlen = READ_ONCE(name->len); char *p; smp_read_barrier_depends(); @@ -3120,7 +3120,7 @@ static int prepend_path(const struct path *path, struct dentry * parent; if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) { - struct mount *parent = ACCESS_ONCE(mnt->mnt_parent); + struct mount *parent = READ_ONCE(mnt->mnt_parent); /* Escaped? */ if (dentry != vfsmnt->mnt_root) { bptr = *buffer; @@ -3130,7 +3130,7 @@ static int prepend_path(const struct path *path, } /* Global root? */ if (mnt != parent) { - dentry = ACCESS_ONCE(mnt->mnt_mountpoint); + dentry = READ_ONCE(mnt->mnt_mountpoint); mnt = parent; vfsmnt = &mnt->mnt; continue; diff --git a/include/linux/dcache.h b/include/linux/dcache.h index ed1a7cf..1d8f581 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -519,7 +519,7 @@ static inline struct inode *d_inode(const struct dentry *dentry) } /** - * d_inode_rcu - Get the actual inode of this dentry with ACCESS_ONCE() + * d_inode_rcu - Get the actual inode of this dentry with READ_ONCE() * @dentry: The dentry to query * * This is the helper normal filesystems should use to get at their own inodes @@ -527,7 +527,7 @@ static inline struct inode *d_inode(const struct dentry *dentry) */ static inline struct inode *d_inode_rcu(const struct dentry *dentry) { - return ACCESS_ONCE(dentry->d_inode); + return READ_ONCE(dentry->d_inode); } /** From patchwork Mon Oct 9 18:28:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115284 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2862447qgn; Mon, 9 Oct 2017 11:30:55 -0700 (PDT) X-Google-Smtp-Source: AOwi7QC87z5+F/nePZ5cedGr//FvDy400jpBxo0X7kh1K5Tzl/vY9zpcxi6ILECE07+29Bx+yhkS X-Received: by 10.84.248.152 with SMTP id q24mr9534161pll.75.1507573855176; Mon, 09 Oct 2017 11:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573855; cv=none; d=google.com; s=arc-20160816; b=zBnfyyEVi03FUynoanUkn6xlTeY9FJcoEtYwOkMTfAgNThj4A/dF7zzIpBc1xgtWhm xVW+3/PXvis3MjWFUl4K8BeAFZ1BjhOX+cxOy5h5sO3j05nLdUa/isfo6paPKZZsFWSc v7DWsymAjhZLPo870u+IgEowavnk5lngkGDYE4w107HVdiPc02pjxHIxCN2h/6kt3R+P O9Xad1LwBpdO6vh0zAUY6NpBfRtMFtRVv/lNCAguUAFfm5xWkbGg+UdYFeEA1F1dQYfh qFTh98bCRvtrZduo/6YA+5KosHTyJ7N118RKxbF4equ3kkgqiovCYQwZTs7l7kB0zGQb Ua4w== 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=xaj//vOUy7O9OuG4yN7+O5NG8ODdK2sRoQuxKhDHKEw=; b=uNP7TDdES8j+/M19BJioE47PtrZb6iTohnPrMnHhOZ4H787DTGfIx7U78ruiBCm4/9 e+yC2S5RUYMYyjBDokIXMIg1LvHkTklZCTbjRggrkX1MVhcGV62F8lgWB8kA7YKCpMfF VRjVUhh1J1QyhqD3qfNZnnaMnP82zxGMdUGT2Gv3pK7Uo5DNf0oo8hg+IZH3+OSkh5CX y6Ygjd2A8jL5a1IT7of1qBokxS1T9QUWvnRvB4cAh9QLb4DQAZo4ozNBMkz41nQW9fM+ tnI3R4NzUwBVAyXX9rwZgvwro/xwU+4Q1RljyQiliVeh++gBIvzYmANIjIkVoFcapZsu 6uZA== 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 e72si7432058pfm.35.2017.10.09.11.30.54; Mon, 09 Oct 2017 11:30:55 -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 S1755301AbdJISaw (ORCPT + 26 others); Mon, 9 Oct 2017 14:30:52 -0400 Received: from foss.arm.com ([217.140.101.70]:33776 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755246AbdJISas (ORCPT ); Mon, 9 Oct 2017 14:30:48 -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 D047E15AD; Mon, 9 Oct 2017 11:30:47 -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 E5AD03F483; Mon, 9 Oct 2017 11:30:46 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Alexander Viro , Petr Vandrovec Subject: [PATCH 05/13] fs: ncpfs: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:42 +0100 Message-Id: <1507573730-8083-6-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 The NCPFS code has some stale comments regarding ACCESS_ONCE() uses which were removed a long time ago. Let's remove the stale comments. Signed-off-by: Mark Rutland Cc: Alexander Viro Cc: Petr Vandrovec --- fs/ncpfs/dir.c | 9 --------- 1 file changed, 9 deletions(-) -- 1.9.1 diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c index 088f524..72cfaa2 100644 --- a/fs/ncpfs/dir.c +++ b/fs/ncpfs/dir.c @@ -119,10 +119,6 @@ static inline int ncp_case_sensitive(const struct inode *i) /* * Note: leave the hash unchanged if the directory * is case-sensitive. - * - * Accessing the parent inode can be racy under RCU pathwalking. - * Use ACCESS_ONCE() to make sure we use _one_ particular inode, - * the callers will handle races. */ static int ncp_hash_dentry(const struct dentry *dentry, struct qstr *this) @@ -147,11 +143,6 @@ static inline int ncp_case_sensitive(const struct inode *i) return 0; } -/* - * Accessing the parent inode can be racy under RCU pathwalking. - * Use ACCESS_ONCE() to make sure we use _one_ particular inode, - * the callers will handle races. - */ static int ncp_compare_dentry(const struct dentry *dentry, unsigned int len, const char *str, const struct qstr *name) From patchwork Mon Oct 9 18:28:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115292 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2864329qgn; Mon, 9 Oct 2017 11:33:07 -0700 (PDT) X-Google-Smtp-Source: AOwi7QChaBMW4jddUtep/QcIlzvl0DGR2oDQOEGgOdjiK/0sZUVH9kLztIfvQzMdRjaV3NsmWE94 X-Received: by 10.99.182.5 with SMTP id j5mr9644609pgf.71.1507573987419; Mon, 09 Oct 2017 11:33:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573987; cv=none; d=google.com; s=arc-20160816; b=UQXMayCMSIuvJvDLriklmq2M7qrr+nOfjt1yDL9VwtP8FX1Edg3N0aj3UAAKxzkm81 az80/m92YkUOSAbdpdiuhHWltNM9EBYNi8m7DaONuvsvvNu0SCt7Pu8cc4gepCTWvpwY YVy4Q8z1+YenAJO3Xosb5SP+hqLYrywG54gkpt+EPOUvIzYc9f3FSmPPcwjzoXP4xV5L cgYPu9CGAJ5VXkYbRfvTyjTbK56XF7JR5RQOhQiK/X4S1UyvazZaGV/0RjgzBaKjQeHx uYQATv3opdvEv9eMza6LOpu27Z3QglbH1OviNBcSRLyBKJJ1yrQ1q9dSi+TxkMMu+OMQ lZGw== 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=4C7pszClGLwmFqurPVudYBjw91iyOSCKkWvSlXTmgaA=; b=EcSFPbIRBgWleDAdqTH460vC8ptQn1O8DAH7pOg+pNINy8NWCNAk4k1InIRJ4N5aSX lrlOG8OtKIHcx1kvlEH6iwsKvSsr3GvIAdgVvYcGQt2dqBnhw9/7JfFQp6T0aowJ1JMA 5V6dJYlSm6SZZtfoQpNRh6oSiYPXrFelSwuCvIdx3h2t3nUv8dhmPmkG3zxZ6Mpm54ou tksMwlHcESmX0veM3Bq0UKVnMMgm9BMnr/AyHmtJjx8F+0ZWZI7aPm5/yzQKu0/Yp8Jq BgYvE51eicO5JH+CE/J7Tj8N1EAa9AcnaD1ZIIGsdS5y/pSNV3yj8f1NT3zN4sMJBVpU 1lJA== 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 f1si3318731pld.151.2017.10.09.11.33.07; Mon, 09 Oct 2017 11:33:07 -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 S1755455AbdJISdF (ORCPT + 26 others); Mon, 9 Oct 2017 14:33:05 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33788 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751050AbdJISau (ORCPT ); Mon, 9 Oct 2017 14:30:50 -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 2BF6D15BF; Mon, 9 Oct 2017 11:30:50 -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 37D553F483; Mon, 9 Oct 2017 11:30:49 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Mauro Carvalho Chehab , Sakari Ailus Subject: [PATCH 06/13] media: dvb_ringbuffer: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:43 +0100 Message-Id: <1507573730-8083-7-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 handle comments, leaving references to ACCESS_ONCE() instances which have been removed. As a preparatory step, this patch converts the DVB ringbuffer code and comments to use {READ,WRITE}_ONCE() consistently. ---- 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: Mauro Carvalho Chehab Cc: Sakari Ailus --- drivers/media/dvb-core/dvb_ringbuffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 1.9.1 diff --git a/drivers/media/dvb-core/dvb_ringbuffer.c b/drivers/media/dvb-core/dvb_ringbuffer.c index 2322af1..5301162 100644 --- a/drivers/media/dvb-core/dvb_ringbuffer.c +++ b/drivers/media/dvb-core/dvb_ringbuffer.c @@ -66,12 +66,12 @@ ssize_t dvb_ringbuffer_free(struct dvb_ringbuffer *rbuf) { ssize_t free; - /* ACCESS_ONCE() to load read pointer on writer side + /* READ_ONCE() to load read pointer on writer side * this pairs with smp_store_release() in dvb_ringbuffer_read(), * dvb_ringbuffer_read_user(), dvb_ringbuffer_flush(), * or dvb_ringbuffer_reset() */ - free = ACCESS_ONCE(rbuf->pread) - rbuf->pwrite; + free = READ_ONCE(rbuf->pread) - rbuf->pwrite; if (free <= 0) free += rbuf->size; return free-1; @@ -143,7 +143,7 @@ ssize_t dvb_ringbuffer_read_user(struct dvb_ringbuffer *rbuf, u8 __user *buf, si todo -= split; /* smp_store_release() for read pointer update to ensure * that buf is not overwritten until read is complete, - * this pairs with ACCESS_ONCE() in dvb_ringbuffer_free() + * this pairs with READ_ONCE() in dvb_ringbuffer_free() */ smp_store_release(&rbuf->pread, 0); } @@ -168,7 +168,7 @@ void dvb_ringbuffer_read(struct dvb_ringbuffer *rbuf, u8 *buf, size_t len) todo -= split; /* smp_store_release() for read pointer update to ensure * that buf is not overwritten until read is complete, - * this pairs with ACCESS_ONCE() in dvb_ringbuffer_free() + * this pairs with READ_ONCE() in dvb_ringbuffer_free() */ smp_store_release(&rbuf->pread, 0); } From patchwork Mon Oct 9 18:28:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115290 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2863497qgn; Mon, 9 Oct 2017 11:32:05 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAeWa1lhtIVpprnd9tNCUHBva8Y7D8dZzcEPsUuvBNVBgSwwzYrxRJD/rPw5lc+XUwxOk5e X-Received: by 10.99.117.10 with SMTP id q10mr9613252pgc.288.1507573925397; Mon, 09 Oct 2017 11:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573925; cv=none; d=google.com; s=arc-20160816; b=j77OfOyBAygcdslGpEdrPghFS71l3t10OT3ngwp/jygcXVTGo2Jn36wlWhjfoZnec9 9R8QExiHUiW+0C362aaL0V4zKDO3K0PF/iBVfUuj2TNxr7gjQXBcqaIwLNAoL4I/Czdu jIrwh7FOKBDj1xTzh7o4BI/98+IjBjv517g/8zVYH6Z6QDlzsqSxglj3pkuslJryJs66 ufATK26G/Pf7LqW22UUnujOtPlkXu/l8Na9o5/LRAuD2BW4pzsJFQ1AkG9vdByk5qteD 0vbBHWYgGdytz/6YTfAKiJg6wM1yPJauc3glAFMyhlF9nQ+jqA4R/w7fW2UeYlXbEvT+ tGKw== 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=ki9149lWosVSHbeIwf+iejijj5lOXKsBHFIG4je56Cc=; b=EWvZdjqR+kwM1uRTv3oiRC0XC8HG0NAZyOkIcehmbyFQR850G3sMAYq1KpnllExkkp PzAc1yabO8XEJ+LAipuQ8UiEmzA6uAE/nGaMAVWYDJiYL3GBksHBfGkuKke4txjgl/vq n/3vK54M2Oy4tD6ZZNc4ifJhhMHeIMnWK0D4q71FiXZT7r4CyDeSLJQ4eT5Hg0o9pGKc Rt8apaDkPDjinCu/aB4ymd/QIG4kjxnxVv5NqtuS8Hf147NpE60Efy99paEqXoCuxPm7 W0rtv4xagj/wQRBmQpFbDWokIiE7cBjsCJz840xuoSnbmZ0xFLwPPGeUfUOgxACaVPyG dX7Q== 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 o32si3238670pld.448.2017.10.09.11.32.05; Mon, 09 Oct 2017 11:32:05 -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 S1755339AbdJISa4 (ORCPT + 26 others); Mon, 9 Oct 2017 14:30:56 -0400 Received: from foss.arm.com ([217.140.101.70]:33796 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755246AbdJISaw (ORCPT ); Mon, 9 Oct 2017 14:30:52 -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 EC3A31610; Mon, 9 Oct 2017 11:30:51 -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 DDD0D3F483; Mon, 9 Oct 2017 11:30:50 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , "David S. Miller" , Florian Westphal , Jozsef Kadlecsik , Pablo Neira Ayuso Subject: [PATCH 07/13] net: netlink/netfilter: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:44 +0100 Message-Id: <1507573730-8083-8-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 handle comments, leaving references to ACCESS_ONCE() instances which have been removed. As a preparatory step, this patch converts netlink and netfilter code and comments to use {READ,WRITE}_ONCE() consistently. ---- 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: David S. Miller Cc: Florian Westphal Cc: Jozsef Kadlecsik Cc: Pablo Neira Ayuso --- include/linux/genetlink.h | 2 +- include/linux/netfilter/nfnetlink.h | 2 +- include/linux/rtnetlink.h | 2 +- include/net/netfilter/nf_tables.h | 4 ++-- net/netfilter/ipvs/ip_vs_sync.c | 2 +- net/netfilter/nfnetlink_queue.c | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) -- 1.9.1 diff --git a/include/linux/genetlink.h b/include/linux/genetlink.h index a4c61cb..0e694cf 100644 --- a/include/linux/genetlink.h +++ b/include/linux/genetlink.h @@ -30,7 +30,7 @@ * @p: The pointer to read, prior to dereferencing * * Return the value of the specified RCU-protected pointer, but omit - * both the smp_read_barrier_depends() and the ACCESS_ONCE(), because + * both the smp_read_barrier_depends() and the READ_ONCE(), because * caller holds genl mutex. */ #define genl_dereference(p) \ diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h index 41d04e9..0f47a4a 100644 --- a/include/linux/netfilter/nfnetlink.h +++ b/include/linux/netfilter/nfnetlink.h @@ -66,7 +66,7 @@ static inline bool lockdep_nfnl_is_held(__u8 subsys_id) * @ss: The nfnetlink subsystem ID * * Return the value of the specified RCU-protected pointer, but omit - * both the smp_read_barrier_depends() and the ACCESS_ONCE(), because + * both the smp_read_barrier_depends() and the READ_ONCE(), because * caller holds the NFNL subsystem mutex. */ #define nfnl_dereference(p, ss) \ diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index dea59c8..765f7b9 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -67,7 +67,7 @@ static inline bool lockdep_rtnl_is_held(void) * @p: The pointer to read, prior to dereferencing * * Return the value of the specified RCU-protected pointer, but omit - * both the smp_read_barrier_depends() and the ACCESS_ONCE(), because + * both the smp_read_barrier_depends() and the READ_ONCE(), because * caller holds RTNL. */ #define rtnl_dereference(p) \ diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h index 0f5b12a..5c68e27 100644 --- a/include/net/netfilter/nf_tables.h +++ b/include/net/netfilter/nf_tables.h @@ -1164,8 +1164,8 @@ static inline u8 nft_genmask_next(const struct net *net) static inline u8 nft_genmask_cur(const struct net *net) { - /* Use ACCESS_ONCE() to prevent refetching the value for atomicity */ - return 1 << ACCESS_ONCE(net->nft.gencursor); + /* Use READ_ONCE() to prevent refetching the value for atomicity */ + return 1 << READ_ONCE(net->nft.gencursor); } #define NFT_GENMASK_ANY ((1 << 0) | (1 << 1)) diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c index 0e5b64a..1cfffd4 100644 --- a/net/netfilter/ipvs/ip_vs_sync.c +++ b/net/netfilter/ipvs/ip_vs_sync.c @@ -457,7 +457,7 @@ static inline bool in_persistence(struct ip_vs_conn *cp) static int ip_vs_sync_conn_needed(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts) { - unsigned long orig = ACCESS_ONCE(cp->sync_endtime); + unsigned long orig = READ_ONCE(cp->sync_endtime); unsigned long now = jiffies; unsigned long n = (now + cp->timeout) & ~3UL; unsigned int sync_refresh_period; diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c index c979662..a16356c 100644 --- a/net/netfilter/nfnetlink_queue.c +++ b/net/netfilter/nfnetlink_queue.c @@ -401,7 +401,7 @@ static int nfqnl_put_bridge(struct nf_queue_entry *entry, struct sk_buff *skb) outdev = entry->state.out; - switch ((enum nfqnl_config_mode)ACCESS_ONCE(queue->copy_mode)) { + switch ((enum nfqnl_config_mode)READ_ONCE(queue->copy_mode)) { case NFQNL_COPY_META: case NFQNL_COPY_NONE: break; @@ -412,7 +412,7 @@ static int nfqnl_put_bridge(struct nf_queue_entry *entry, struct sk_buff *skb) skb_checksum_help(entskb)) return NULL; - data_len = ACCESS_ONCE(queue->copy_range); + data_len = READ_ONCE(queue->copy_range); if (data_len > entskb->len) data_len = entskb->len; From patchwork Mon Oct 9 18:28:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115285 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2862538qgn; Mon, 9 Oct 2017 11:31:00 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAULHNkkKxkMPGaiFfcGq8BnF+vwNSwR/4sCKS2ihHdZG+stuJPRsK4rvmzP2YVszvlt6XS X-Received: by 10.99.63.199 with SMTP id m190mr9957868pga.275.1507573860864; Mon, 09 Oct 2017 11:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573860; cv=none; d=google.com; s=arc-20160816; b=eyqoHaPVjrVFH6HxZFVhTaH01ZljjWqnBcFgqi52H1Co+rimECfKlxrhKLAz5XVfPu yIH4xo6sEb9pDoFNxRQL1U2ckpxoA9mCYEtaoD4v8QEyetXrW9xAIJTVW6LA4Jh+OhAu 61Jby8WuMclqPD0Knukyo3jnxtaDxZPhh3HDWaoRwbX2dgLZg6JZcc6dwkQ3wV2YwpMW I7H+omDL0wygRDWQBnr2ak3+l9ccZ0H/q+dYmKcITfMCTc/Ty77Iq8F0K0MyM7nvGdEp ZFOn8enrgxGARg5hSj6SsBSn9dvnDUwjiZvrcF2UfGyLrXMbh43Hhlpbr9fSZR2ME4h4 D0Rg== 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=xvXabnzEX4Hk0OmSP1cDO/UiXm4jiS1mQ9FpDzdwETI=; b=IfMSHEBmBjiyIbyk753l4QqUTqmjA/fNLWez/ww5pcrc1tSFDAZ6o2JUEpjfVSDKEq AFA3sJBP6lqutTiJkm+hxtlAhzu3yER0OD+PrC6hFtvzoAU1OiaG0ScGyTfckmeTmDuh toTc6wPDJ+5CvnHA/oaz65rWWM3iB9DiFFMji0HpSw45+tNvNEAEHoVrWhArf34zG/tX e5ITh4uADZEciWYAVFA+BqBqISyX/RGYb7FtxrT8Dl7K60PeRk32Wvx5yeGughgjo1vO itofDs3nmmel0/ipGXyhNHG9UxnXq7PB8uo0GTdGEi7f+Np7XoGxzkLsBa+GRREed9QE spiQ== 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 e72si7432058pfm.35.2017.10.09.11.31.00; Mon, 09 Oct 2017 11:31:00 -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 S1755371AbdJISa5 (ORCPT + 26 others); Mon, 9 Oct 2017 14:30:57 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33802 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754216AbdJISax (ORCPT ); Mon, 9 Oct 2017 14:30:53 -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 6A8BC165C; Mon, 9 Oct 2017 11:30:53 -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 A34413F483; Mon, 9 Oct 2017 11:30:52 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , "David S. Miller" Subject: [PATCH 08/13] net/ipv4/tcp_input.c: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:45 +0100 Message-Id: <1507573730-8083-9-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 handle comments, leaving references to ACCESS_ONCE() instances which have been removed. As a preparatory step, this patch converts the IPv4 TCP input code and comments to use {READ,WRITE}_ONCE() consistently. ---- 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: David S. Miller --- net/ipv4/tcp_input.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 1.9.1 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index c5d7656..0b3bb19 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -815,12 +815,12 @@ static void tcp_update_pacing_rate(struct sock *sk) if (likely(tp->srtt_us)) do_div(rate, tp->srtt_us); - /* ACCESS_ONCE() is needed because sch_fq fetches sk_pacing_rate + /* WRITE_ONCE() is needed because sch_fq fetches sk_pacing_rate * without any lock. We want to make sure compiler wont store * intermediate values in this location. */ - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate, - sk->sk_max_pacing_rate); + WRITE_ONCE(sk->sk_pacing_rate) = min_t(u64, rate, + sk->sk_max_pacing_rate); } /* Calculate rto without backoff. This is the second half of Van Jacobson's From patchwork Mon Oct 9 18:28:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115291 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2864010qgn; Mon, 9 Oct 2017 11:32:43 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCIaol7fCW0tWp8lRHbwtg4koLxSiecXyZyd0yf1Y+YKX+7WccyrQht/w+ag/7OOhTOyDtC X-Received: by 10.84.238.136 with SMTP id v8mr9792675plk.37.1507573963477; Mon, 09 Oct 2017 11:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573963; cv=none; d=google.com; s=arc-20160816; b=d04LZDLlMTlF3chnDcOjA0jWvXAR4y/v8S3RmGs0swbRdSJNoAEWdcw8BWsAmwybAV xvHdAavTWD+xKHbUQdtQxm9hCuVQ71iRCNgR7TKIXzzge5p+jjMtuoXj85jAt5aQaags 8NOuYC93E8mmof6kyxQxEWaOpsCmGzxWPJcO2+g+8MBNKACXNHNUdwF+nQxFQ+Tx4/wG 1YBIZD1RerHiQLCdSCmCwrO9uzn6CtWUSfwDvjq+LWLIFfPZJfG2cyjUm6W3zzDgDNk9 zgaDvzqDMQWi77FfXKMznfJejFCN8so+UlS7THMYs6YQt8w+pG4OrZ/e2TLfq7N9tf/f nZQQ== 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=P24Qhvs5Qy0oE+Hw3MQXAjw1CwbTYTbGAo8l466hS1o=; b=BF73oZfsd53TEsC/LDfwwUsa6VA3slQT4Z7BEaobUzTSf6/CDnIsSvPmfgPLCb3crY fY5AEoBz1NDDCqFT7yIiWQl59dw5r2XNzjeuwP0TdS18KeTUzhO+duOOxy1HSshJ/VAN ht5zUdqK+EVXJxZaC2Uu+VGMIxh8ivOMXP22E/J9q3XDQ47Hgh+FTCWzZnnsqpJF1/jz PYux0RsvMBqjMdTR4JbOfscxOKwLsdHuK2pR5Lc0i57MAJ/uTlG4VAMS4A1bXC5sIoDQ c+SrZhpWS+qYN79JlFlA5wKKyKC2g1yTHELE3WXumNU3mDGYjfeAoNXo+B6tRgqUVnhi 5ENQ== 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 h128si7460402pfb.194.2017.10.09.11.32.43; Mon, 09 Oct 2017 11:32:43 -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 S1755453AbdJIScm (ORCPT + 26 others); Mon, 9 Oct 2017 14:32:42 -0400 Received: from foss.arm.com ([217.140.101.70]:33810 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755310AbdJISaz (ORCPT ); Mon, 9 Oct 2017 14:30:55 -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 E98B6165D; Mon, 9 Oct 2017 11:30:54 -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 2E1643F483; Mon, 9 Oct 2017 11:30:54 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Johannes Berg , "David S. Miller" Subject: [PATCH 09/13] net: average: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:46 +0100 Message-Id: <1507573730-8083-10-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 . As a preparatory step, this patch converts the file to use {READ,WRITE}_ONCE() consistently. At the same time, this patch addds missing includes necessary for {READ,WRITE}_ONCE(), *BUG_ON*(), and ilog2(). ---- 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: Johannes Berg Cc: David S. Miller --- include/linux/average.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) -- 1.9.1 diff --git a/include/linux/average.h b/include/linux/average.h index 7ddaf34..7a72de4 100644 --- a/include/linux/average.h +++ b/include/linux/average.h @@ -1,6 +1,10 @@ #ifndef _LINUX_AVERAGE_H #define _LINUX_AVERAGE_H +#include +#include +#include + /* * Exponentially weighted moving average (EWMA) * @@ -48,7 +52,7 @@ static inline void ewma_##name##_add(struct ewma_##name *e, \ unsigned long val) \ { \ - unsigned long internal = ACCESS_ONCE(e->internal); \ + unsigned long internal = READ_ONCE(e->internal); \ unsigned long weight_rcp = ilog2(_weight_rcp); \ unsigned long precision = _precision; \ \ @@ -57,10 +61,10 @@ BUILD_BUG_ON((_precision) > 30); \ BUILD_BUG_ON_NOT_POWER_OF_2(_weight_rcp); \ \ - ACCESS_ONCE(e->internal) = internal ? \ + WRITE_ONCE(e->internal, internal ? \ (((internal << weight_rcp) - internal) + \ (val << precision)) >> weight_rcp : \ - (val << precision); \ + (val << precision)); \ } #endif /* _LINUX_AVERAGE_H */ From patchwork Mon Oct 9 18:28:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115289 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2863308qgn; Mon, 9 Oct 2017 11:31:51 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCRvdePDRV3EuSXqLSKnkJwbs9RQSwIrRiD+icwhJn6ga7V7K56VlnQ+NARENvE+zMMjrUC X-Received: by 10.101.88.142 with SMTP id d14mr9696715pgu.36.1507573911178; Mon, 09 Oct 2017 11:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573911; cv=none; d=google.com; s=arc-20160816; b=swWm5ezcHqoMZL7cj1gNX7guTY0QxpohceXLvhU7p0cKRtvVUeT6w+iY8wPnQbVqDB Ht+p6X/06fmh8zZOLadyXiee3RQllnH9W0S67Kce+wSsr0UvfD15d/qA8mtuJDTBHLxQ QrAT3WzhpwiZtpz8MoJR58quuhrWKnhCjrQqYqsMsQSHiLzrZbt5GEVZIl1ytkUNYVCN u3LvvxwtbtnqIKhtq/M+zYqFS8Rx9sC+uKVT/5pR18w9eisJss5/MloRA18Fz4SFgdwo FodlDnP4QivQg5zFR3P3GlWqq7d5wIycnnMo0JXDRCBK7exIzXwWRSvz3bCH4rXZ1JAJ zQ/w== 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=E/QFAxyDk0C/AxXreYU9Z1KKgYA+uJV2mfT6BN6hn6Q=; b=VM1jkfu0gNknJFm6BYgGB6oGcpBv5tFXRU+nfhK+rQ0Dgme/ED9V9vfKen3fPOPKVK szZuA9iT2KztxXt6xV9Z4id7DtYn9BMwbzYPMMP+iA9jwPVvjrJKTAbrRTPzgx2YltZ8 h/yhPGMQGQS6dxkyGUTZQggZkCjs93D4FcUCkcp0gVu2v8nspBCZ1mahecfSyzDeGza7 rUOA+rHE3XpnPFChqM2G+a88QrUFai6s1bUklZghy9yTBGpchIi2qFRTFL+vB8xnlQ7h X4rie8ADwGzaPr3uA5t/R/OGUVxmKyuC1ySPJFWVgXJdVKUgp4F6maO6cq+g5Esbgnzs jccg== 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 o29si3658752pfi.90.2017.10.09.11.31.50; Mon, 09 Oct 2017 11:31:51 -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 S1755438AbdJISbs (ORCPT + 26 others); Mon, 9 Oct 2017 14:31:48 -0400 Received: from foss.arm.com ([217.140.101.70]:33820 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755341AbdJISa4 (ORCPT ); Mon, 9 Oct 2017 14:30:56 -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 49146165C; Mon, 9 Oct 2017 11:30:56 -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 A53923F483; Mon, 9 Oct 2017 11:30:55 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Shuah Khan Subject: [PATCH 10/13] samples: mic/mpssd/mpssd.c: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:47 +0100 Message-Id: <1507573730-8083-11-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. The bulk of the kernel code can be transformed via Coccinelle to use {READ,WRITE}_ONCE(), though this only modifies users of ACCESS_ONCE(), and not the implementation itself. As such, it has the potential to break homebrew ACCESS_ONCE() macros seen in some user code in the kernel tree (e.g. the virtio code, as fixed in commit ea9156fb3b71d9f7). To avoid fragility if/when that transformation occurs, and to align with the preferred usage of {READ,WRITE}_ONCE(), this patch updates the MPSSD sample code to use READ_ONCE() rather than ACCESS_ONCE(). There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland Cc: Shuah Khan --- samples/mic/mpssd/mpssd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 1.9.1 diff --git a/samples/mic/mpssd/mpssd.c b/samples/mic/mpssd/mpssd.c index 49db1de..f42ce55 100644 --- a/samples/mic/mpssd/mpssd.c +++ b/samples/mic/mpssd/mpssd.c @@ -65,7 +65,7 @@ /* to align the pointer to the (next) page boundary */ #define PAGE_ALIGN(addr) _ALIGN(addr, PAGE_SIZE) -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) +#define READ_ONCE(x) (*(volatile typeof(x) *)&(x)) #define GSO_ENABLED 1 #define MAX_GSO_SIZE (64 * 1024) @@ -382,7 +382,7 @@ static inline void verify_out_len(struct mic_info *mic, static inline __u16 read_avail_idx(struct mic_vring *vr) { - return ACCESS_ONCE(vr->info->avail_idx); + return READ_ONCE(vr->info->avail_idx); } static inline void txrx_prepare(int type, bool tx, struct mic_vring *vr, @@ -523,7 +523,7 @@ static inline unsigned _vring_size(unsigned int num, unsigned long align) { __u16 avail_idx = read_avail_idx(vr); - while (avail_idx == le16toh(ACCESS_ONCE(vr->vr.avail->idx))) { + while (avail_idx == le16toh(READ_ONCE(vr->vr.avail->idx))) { #ifdef DEBUG mpsslog("%s %s waiting for desc avail %d info_avail %d\n", mic->name, __func__, From patchwork Mon Oct 9 18:28:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115287 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2862755qgn; Mon, 9 Oct 2017 11:31:14 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDxF9dNd7iJqdZT/vmhz+R8AdWxWg5k9sxTaM3JarTi02GheFueNIDnITYbtEVh6MIsV/Jd X-Received: by 10.99.168.76 with SMTP id i12mr10001283pgp.427.1507573874442; Mon, 09 Oct 2017 11:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573874; cv=none; d=google.com; s=arc-20160816; b=N7VMsGYLqJSLYJBpiKMLoqcDR7uhTSAFc+oL3FkO52es7XO5Qnn+Tl5x5rduGE3lPh hVpAS0nSkjrdcrCN+ogycvxNvKDvHRUYmV81Gme4c1YzrClNVd8ZlLOpDXMYhLfD7IbB t+G4q8X+4sI2u/jv4AJk4HOK/nrPk4dSPL9SEk5hZaKZ6+dD6EB3Fvc2QK+EFqrAIM9X OVtk2n1Jy4Wx0sHTjqbYkbTQDCECYgNKm9k2RZoaZRFoo5ejIM/Ul7eOrKcgu/nUdnnW QeJLI6qv0YqrtMQ6NDySsfOQseXax8LsLoAcSm+TiRTNn7Cr/55ZF8DqUeLo4syQgbYj Z7ng== 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=n4OaV4mMAvopicOHTZe+woX0pVx25TZrcqkpkKMtFWs=; b=sc+Dt9btihHfC1lIYezgmFOIP23JC50SlyPPlQDmDD+psvlXkpDY0lEbRWgKsznkfr jqrPNiyS7enNfVRlR2Jg/kCVv8HzebZ/N2rioDPMe1f1g7j2ZCz9K2NlfZItBpvVsBwS 2YXGSVdRDEXFPlwGcqFYvJqQZG1WHT6LC37zZfyyL8XSAxZlZ6caaRCG2ZqMHRBMCNWl 0DbmVTYG5539fH0u+e0gMBR0hsaa9S5FYB1KAV/l+WaANt31h/p3YwJ/s8nnHXLhS5lR BsfSfmPq38JwEtjHq1pMDWWiOB41LR7wtmW3WxtLKJmIHZhK/DssyXthKz+TgeeO1nUg W/EQ== 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 e72si7432058pfm.35.2017.10.09.11.31.14; Mon, 09 Oct 2017 11:31:14 -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 S1755396AbdJISbB (ORCPT + 26 others); Mon, 9 Oct 2017 14:31:01 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33828 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754216AbdJISa6 (ORCPT ); Mon, 9 Oct 2017 14:30:58 -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 271DA165C; Mon, 9 Oct 2017 11:30:58 -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 189EB3F483; Mon, 9 Oct 2017 11:30:56 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Benjamin Herrenschmidt , Michael Ellerman , Paul Mackerras , Shuah Khan Subject: [PATCH 11/13] selftests/powerpc: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:48 +0100 Message-Id: <1507573730-8083-12-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. The bulk of the kernel code can be transformed via Coccinelle to use {READ,WRITE}_ONCE(), though this only modifies users of ACCESS_ONCE(), and not the implementation itself. As such, it has the potential to break homebrew ACCESS_ONCE() macros seen in some user code in the kernel tree (e.g. the virtio code, as fixed in commit ea9156fb3b71d9f7). To avoid fragility if/when that transformation occurs, and to align with the preferred usage of {READ,WRITE}_ONCE(), this patch updates the DSCR selftest code to use READ_ONCE() rather than ACCESS_ONCE(). There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland Cc: Benjamin Herrenschmidt Cc: Michael Ellerman Cc: Paul Mackerras Cc: Shuah Khan --- tools/testing/selftests/powerpc/dscr/dscr.h | 2 +- tools/testing/selftests/powerpc/dscr/dscr_default_test.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- 1.9.1 Acked-by: Michael Ellerman diff --git a/tools/testing/selftests/powerpc/dscr/dscr.h b/tools/testing/selftests/powerpc/dscr/dscr.h index 18ea223b..cdb840b 100644 --- a/tools/testing/selftests/powerpc/dscr/dscr.h +++ b/tools/testing/selftests/powerpc/dscr/dscr.h @@ -39,7 +39,7 @@ #define rmb() asm volatile("lwsync":::"memory") #define wmb() asm volatile("lwsync":::"memory") -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) +#define READ_ONCE(x) (*(volatile typeof(x) *)&(x)) /* Prilvilege state DSCR access */ inline unsigned long get_dscr(void) diff --git a/tools/testing/selftests/powerpc/dscr/dscr_default_test.c b/tools/testing/selftests/powerpc/dscr/dscr_default_test.c index df17c3b..9e1a37e 100644 --- a/tools/testing/selftests/powerpc/dscr/dscr_default_test.c +++ b/tools/testing/selftests/powerpc/dscr/dscr_default_test.c @@ -27,7 +27,7 @@ static void *do_test(void *in) unsigned long d, cur_dscr, cur_dscr_usr; unsigned long s1, s2; - s1 = ACCESS_ONCE(sequence); + s1 = READ_ONCE(sequence); if (s1 & 1) continue; rmb(); From patchwork Mon Oct 9 18:28:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115286 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2862611qgn; Mon, 9 Oct 2017 11:31:04 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBeIfRN4hS/iPiD8lNo20laXdT74XpW+NDTMyfzgVAjtTUiZdl0FezFjk8IcAcWwN6YTgpE X-Received: by 10.99.107.73 with SMTP id g70mr9705426pgc.279.1507573864795; Mon, 09 Oct 2017 11:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573864; cv=none; d=google.com; s=arc-20160816; b=I8Ynu0yPtahEGChw9OBKijBwVnMlkJFekqjNRpn0aPlPGsV3AYP9KH3H9JORS70VpF ZtGenvvtv2oBMdA+oSNRuNRevwkoMCZDdrg5RZLpJcGDeeXcdQDstMf0Ro4vYdQapIcP /EJ3o/Ff/cmQbKlnAe70MD2gsEJdHSr9YBWbsgZ2ZQmC4btlql5AjMG5/TBqE+v/By0+ bMTi05WgOdoufN4mHeckwG0+8WYujGEjjEf2N9T4njltIozms7KgIhSnZxqiZhmI4LRi YRpAgT8d6LNxvQX7Nxxt0d7mdKYKUEe9YoParJxMpDOsxuKsd8EHdoO+1wWPK4dLq+AG 2Ayw== 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=/YRTTht65u4X6k6ScfrE4pfLraxmdN18u1G14kcQvj8=; b=q/36qA+aGhgiXIFg75geNc/n63KXTlLe7hMuN+nM4w6RFpJeA+okI+4RgUgLgao1GL dQ4Ol7o+fksjuu0zpjL4XOtp5gHiwgjVEDRopu+JUW+OzUfMQTKNnXX0x2zvyz89VmK2 sVHERNXeHa9NzlCsKEvvb3QL3kt7+CLwhziHB4rY/MXVSjgv/KW01DGOD0xxEXS4I3Xh FEPdnhJvYqqCvLp+GmOHfpnXVGYROIv/h5JADP4PUSJN+8xdnXIdRGyiE6PfTSGsE2LA NZwn9kmhw+puSnJc7cyQS5ye+Bi8EY2C8BAGycY44jYoZGZ6AXpp2Z27x/K2+4NXGHT6 LG6A== 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 e72si7432058pfm.35.2017.10.09.11.31.04; Mon, 09 Oct 2017 11:31:04 -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 S1755418AbdJISbC (ORCPT + 26 others); Mon, 9 Oct 2017 14:31:02 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:33840 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755176AbdJISbA (ORCPT ); Mon, 9 Oct 2017 14:31:00 -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 B9296165D; Mon, 9 Oct 2017 11:30:59 -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 CE44B3F483; Mon, 9 Oct 2017 11:30:58 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Lai Jiangshan , Tejun Heo Subject: [PATCH 12/13] workqueue: kill off ACCESS_ONCE() Date: Mon, 9 Oct 2017 19:28:49 +0100 Message-Id: <1507573730-8083-13-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 handle comments, leaving references to ACCESS_ONCE() instances which have been removed. As a preparatory step, this patch converts the workqueue code and comments to use {READ,WRITE}_ONCE() consistently. ---- 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: Lai Jiangshan Cc: Tejun Heo --- kernel/workqueue.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 1.9.1 Acked-by: Tejun Heo diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 64d0edf..39831b2 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4647,7 +4647,7 @@ static void rebind_workers(struct worker_pool *pool) * concurrency management. Note that when or whether * @worker clears REBOUND doesn't affect correctness. * - * ACCESS_ONCE() is necessary because @worker->flags may be + * WRITE_ONCE() is necessary because @worker->flags may be * tested without holding any lock in * wq_worker_waking_up(). Without it, NOT_RUNNING test may * fail incorrectly leading to premature concurrency @@ -4656,7 +4656,7 @@ static void rebind_workers(struct worker_pool *pool) WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND)); worker_flags |= WORKER_REBOUND; worker_flags &= ~WORKER_UNBOUND; - ACCESS_ONCE(worker->flags) = worker_flags; + WRITE_ONCE(worker->flags, worker_flags); } spin_unlock_irq(&pool->lock); From patchwork Mon Oct 9 18:28:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 115288 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp2862796qgn; Mon, 9 Oct 2017 11:31:17 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDiDoUzPvC/Nm9rIE89yH1S39HiLXGjO7sdDWKrVEt78QjMxqva6f7qDM5yvJMpMT1qYkxa X-Received: by 10.99.47.6 with SMTP id v6mr9904737pgv.452.1507573876932; Mon, 09 Oct 2017 11:31:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507573876; cv=none; d=google.com; s=arc-20160816; b=b1UoOZ9wxbbhpb1nDq3/sPuorD/N/Wm9OzpekaPhmYx+eHdn9mxhAryP1FXuNWLBRp NIfJtj0uT/5huGIJiBrTkPHjrbmVBeEn70nM+jyH2NMHPiMgU1O9HG+zpfbK8VYtH1my /+sQWhU6UGGctyQmscrxTgVO0iV5kqwi5SV5rENTfvhMf/iA2gB/rN1uGpLPfr2I66NS p2q2wKYbgiIWDB2HrkeDTNawaXFomvOX1nUh7hwjsxT+0xgyxmk1xAmYYfNZUq9+PKSB +9813LnklAQWSUnR5m+h42WxYJl2vuKxBgQuQ92baPf+74eWbgFakKhf/7hcJ/ROLqjH KZtw== 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=PwSqlqgpaSIxPSHYYIb/1W2S+k792QfoMF/ZbzIqa7k=; b=JQTAH6B4rWGbOlbHxTMkB6K+sdDgVyRLZiaJyEnDf+7Ev3wTY3lbvKADEQmYidKCtj pZiQUiDzkDaOhw+qrKqZvbDaKXvjm5/beF06VSQH12piSC1u0TwRrlWHHkF47xJLOk7i NlPWckBakim770Spva7uql/NmVTU0z5bxccWVhZmW1Q1VcDPZjrBzFmoOw++Jrp7lmlG 0Ft8EFiGlZ1P8dO5ZvvTKetoluBrf2z5ovC0+Fp63G6cF2X0dvb7FSPINU0jgpPkexaG Ho6gRsqVSLRPzCFcGyf/q+epYzc/7uGsnnyTzXLaEBa/hGupbFfPY/urPQXrDFX205zr y0SQ== 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 o29si3658752pfi.90.2017.10.09.11.31.16; Mon, 09 Oct 2017 11:31:16 -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 S1755430AbdJISbO (ORCPT + 26 others); Mon, 9 Oct 2017 14:31:14 -0400 Received: from foss.arm.com ([217.140.101.70]:33848 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754216AbdJISbB (ORCPT ); Mon, 9 Oct 2017 14:31:01 -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 83D341688; Mon, 9 Oct 2017 11:31:01 -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 BAB7B3F483; Mon, 9 Oct 2017 11:31:00 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , "Paul E. McKenney" Subject: [PATCH 13/13] rcutorture: formal: prepare for ACCESS_ONCE() removal Date: Mon, 9 Oct 2017 19:28:50 +0100 Message-Id: <1507573730-8083-14-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. The bulk of the kernel code can be transformed via Coccinelle to use {READ,WRITE}_ONCE(), though this only modifies users of ACCESS_ONCE(), and not the implementation itself. As such, it has the potential to break homebrew ACCESS_ONCE() macros seen in some user code in the kernel tree (e.g. the virtio code, as fixed in commit ea9156fb3b71d9f7). To avoid fragility if/when that transformation occurs, this patch reworks the rcutorture formal tests to use an intermediate __ACCESS_ONCE() helper, which will avoid {READ,WRITE}_ONCE() being turned into tautological definitions. There should be no functional change as a result of this patch. Cc: Paul E. McKenney Signed-off-by: Mark Rutland --- tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 1.9.1 diff --git a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h index 6687acc..ee4e4f8 100644 --- a/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h +++ b/tools/testing/selftests/rcutorture/formal/srcu-cbmc/src/barriers.h @@ -34,8 +34,9 @@ #define rs_smp_mb() do {} while (0) #endif -#define ACCESS_ONCE(x) (*(volatile typeof(x) *) &(x)) -#define READ_ONCE(x) ACCESS_ONCE(x) -#define WRITE_ONCE(x, val) (ACCESS_ONCE(x) = (val)) +#define __ACCESS_ONCE(x) (*(volatile typeof(x) *) &(x)) +#define ACCESS_ONCE(x) __ACCESS_ONCE(x) +#define READ_ONCE(x) __ACCESS_ONCE(x) +#define WRITE_ONCE(x, val) (__ACCESS_ONCE(x) = (val)) #endif