summaryrefslogtreecommitdiffstats
path: root/fs/dcache.c
diff options
context:
space:
mode:
authorMark Rutland <mark.rutland@arm.com>2017-10-23 17:07:14 -0400
committerIngo Molnar <mingo@kernel.org>2017-10-25 05:00:57 -0400
commit66702eb59064f1077e89cce8e7e3cd48ec4b486c (patch)
treebba2d6a8321865a9d25816d3e334960572a52dfe /fs/dcache.c
parenteeafcc5a5925d0819dad462eac1d42fda5fbe36f (diff)
locking/atomics, fs/dcache: Convert ACCESS_ONCE() to READ_ONCE()/WRITE_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 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 <mark.rutland@arm.com> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: davem@davemloft.net Cc: linux-arch@vger.kernel.org Cc: mpe@ellerman.id.au Cc: shuah@kernel.org Cc: snitzer@redhat.com Cc: thor.thayer@linux.intel.com Cc: tj@kernel.org Cc: will.deacon@arm.com Link: http://lkml.kernel.org/r/1508792849-3115-4-git-send-email-paulmck@linux.vnet.ibm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'fs/dcache.c')
-rw-r--r--fs/dcache.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/fs/dcache.c b/fs/dcache.c
index 34c852af215c..bcc9f6981569 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -630,7 +630,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
630 rcu_read_lock(); 630 rcu_read_lock();
631 spin_unlock(&dentry->d_lock); 631 spin_unlock(&dentry->d_lock);
632again: 632again:
633 parent = ACCESS_ONCE(dentry->d_parent); 633 parent = READ_ONCE(dentry->d_parent);
634 spin_lock(&parent->d_lock); 634 spin_lock(&parent->d_lock);
635 /* 635 /*
636 * We can't blindly lock dentry until we are sure 636 * We can't blindly lock dentry until we are sure
@@ -721,7 +721,7 @@ static inline bool fast_dput(struct dentry *dentry)
721 * around with a zero refcount. 721 * around with a zero refcount.
722 */ 722 */
723 smp_rmb(); 723 smp_rmb();
724 d_flags = ACCESS_ONCE(dentry->d_flags); 724 d_flags = READ_ONCE(dentry->d_flags);
725 d_flags &= DCACHE_REFERENCED | DCACHE_LRU_LIST | DCACHE_DISCONNECTED; 725 d_flags &= DCACHE_REFERENCED | DCACHE_LRU_LIST | DCACHE_DISCONNECTED;
726 726
727 /* Nothing to do? Dropping the reference was all we needed? */ 727 /* Nothing to do? Dropping the reference was all we needed? */
@@ -850,11 +850,11 @@ struct dentry *dget_parent(struct dentry *dentry)
850 * locking. 850 * locking.
851 */ 851 */
852 rcu_read_lock(); 852 rcu_read_lock();
853 ret = ACCESS_ONCE(dentry->d_parent); 853 ret = READ_ONCE(dentry->d_parent);
854 gotref = lockref_get_not_zero(&ret->d_lockref); 854 gotref = lockref_get_not_zero(&ret->d_lockref);
855 rcu_read_unlock(); 855 rcu_read_unlock();
856 if (likely(gotref)) { 856 if (likely(gotref)) {
857 if (likely(ret == ACCESS_ONCE(dentry->d_parent))) 857 if (likely(ret == READ_ONCE(dentry->d_parent)))
858 return ret; 858 return ret;
859 dput(ret); 859 dput(ret);
860 } 860 }
@@ -3040,7 +3040,7 @@ static int prepend(char **buffer, int *buflen, const char *str, int namelen)
3040 * @buflen: allocated length of the buffer 3040 * @buflen: allocated length of the buffer
3041 * @name: name string and length qstr structure 3041 * @name: name string and length qstr structure
3042 * 3042 *
3043 * With RCU path tracing, it may race with d_move(). Use ACCESS_ONCE() to 3043 * With RCU path tracing, it may race with d_move(). Use READ_ONCE() to
3044 * make sure that either the old or the new name pointer and length are 3044 * make sure that either the old or the new name pointer and length are
3045 * fetched. However, there may be mismatch between length and pointer. 3045 * fetched. However, there may be mismatch between length and pointer.
3046 * The length cannot be trusted, we need to copy it byte-by-byte until 3046 * 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)
3054 */ 3054 */
3055static int prepend_name(char **buffer, int *buflen, const struct qstr *name) 3055static int prepend_name(char **buffer, int *buflen, const struct qstr *name)
3056{ 3056{
3057 const char *dname = ACCESS_ONCE(name->name); 3057 const char *dname = READ_ONCE(name->name);
3058 u32 dlen = ACCESS_ONCE(name->len); 3058 u32 dlen = READ_ONCE(name->len);
3059 char *p; 3059 char *p;
3060 3060
3061 smp_read_barrier_depends(); 3061 smp_read_barrier_depends();
@@ -3120,7 +3120,7 @@ restart:
3120 struct dentry * parent; 3120 struct dentry * parent;
3121 3121
3122 if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) { 3122 if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
3123 struct mount *parent = ACCESS_ONCE(mnt->mnt_parent); 3123 struct mount *parent = READ_ONCE(mnt->mnt_parent);
3124 /* Escaped? */ 3124 /* Escaped? */
3125 if (dentry != vfsmnt->mnt_root) { 3125 if (dentry != vfsmnt->mnt_root) {
3126 bptr = *buffer; 3126 bptr = *buffer;
@@ -3130,7 +3130,7 @@ restart:
3130 } 3130 }
3131 /* Global root? */ 3131 /* Global root? */
3132 if (mnt != parent) { 3132 if (mnt != parent) {
3133 dentry = ACCESS_ONCE(mnt->mnt_mountpoint); 3133 dentry = READ_ONCE(mnt->mnt_mountpoint);
3134 mnt = parent; 3134 mnt = parent;
3135 vfsmnt = &mnt->mnt; 3135 vfsmnt = &mnt->mnt;
3136 continue; 3136 continue;