nfs: add memory barriers around NFS_INO_INVALID_DATA and NFS_INO_INVALIDATING
authorJeff Layton <jlayton@redhat.com>
Tue, 28 Jan 2014 18:47:46 +0000 (13:47 -0500)
committerJiri Slaby <jslaby@suse.cz>
Thu, 3 Apr 2014 08:32:18 +0000 (10:32 +0200)
commit 4db72b40fdbc706f8957e9773ae73b1574b8c694 upstream.

If the setting of NFS_INO_INVALIDATING gets reordered to before the
clearing of NFS_INO_INVALID_DATA, then another task may hit a race
window where both appear to be clear, even though the inode's pages are
still in need of invalidation. Fix this by adding the appropriate memory
barriers.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
fs/nfs/dir.c
fs/nfs/inode.c
fs/nfs/write.c

index 4d9f098614bc6c955b348b12b6494ecf7d5fb9bc..1402806233484f48770c491f45f656c2449690be 100644 (file)
@@ -276,6 +276,15 @@ out_eof:
        return -EBADCOOKIE;
 }
 
+static bool
+nfs_readdir_inode_mapping_valid(struct nfs_inode *nfsi)
+{
+       if (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA))
+               return false;
+       smp_rmb();
+       return !test_bit(NFS_INO_INVALIDATING, &nfsi->flags);
+}
+
 static
 int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_descriptor_t *desc)
 {
@@ -289,9 +298,8 @@ int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_des
                        struct nfs_open_dir_context *ctx = desc->file->private_data;
 
                        new_pos = desc->current_index + i;
-                       if (ctx->attr_gencount != nfsi->attr_gencount
-                           || (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA))
-                           || test_bit(NFS_INO_INVALIDATING, &nfsi->flags)) {
+                       if (ctx->attr_gencount != nfsi->attr_gencount ||
+                           !nfs_readdir_inode_mapping_valid(nfsi)) {
                                ctx->duped = 0;
                                ctx->attr_gencount = nfsi->attr_gencount;
                        } else if (new_pos < desc->ctx->pos) {
index 12c0fa8ae0042e8b35bbac1130148cce9881b490..fdeeb28f287bcecd4d283e458044b94eea11e4ad 100644 (file)
@@ -1060,6 +1060,7 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
        }
 
        set_bit(NFS_INO_INVALIDATING, bitlock);
+       smp_wmb();
        nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
        spin_unlock(&inode->i_lock);
        trace_nfs_invalidate_mapping_enter(inode);
index d69e789f19083590ae624edbad8c8a7f40beadb0..c6aa89f925581593fad3d1cd1830ac1a00d74265 100644 (file)
@@ -915,6 +915,7 @@ static bool nfs_write_pageuptodate(struct page *page, struct inode *inode)
                goto out;
        if (nfsi->cache_validity & (NFS_INO_INVALID_DATA|NFS_INO_REVAL_PAGECACHE))
                return false;
+       smp_rmb();
        if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags))
                return false;
 out: