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;