summaryrefslogtreecommitdiff
path: root/net/sunrpc
diff options
context:
space:
mode:
authorJ. Bruce Fields <bfields@redhat.com>2011-01-04 14:12:47 -0500
committerJ. Bruce Fields <bfields@redhat.com>2011-01-04 16:49:25 -0500
commitfdef7aa5d4020fd94ffcbf0078d6bd9e5a111e19 (patch)
tree270c2b03e9cb5cf5451b0e229c5a328727ef743a /net/sunrpc
parent6bab93f87ec703bf6650875881b11f9f27d7da56 (diff)
downloadlinux-3.10-fdef7aa5d4020fd94ffcbf0078d6bd9e5a111e19.tar.gz
linux-3.10-fdef7aa5d4020fd94ffcbf0078d6bd9e5a111e19.tar.bz2
linux-3.10-fdef7aa5d4020fd94ffcbf0078d6bd9e5a111e19.zip
svcrpc: ensure cache_check caller sees updated entry
Supposes cache_check runs simultaneously with an update on a different CPU: cache_check task doing update ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ 1. test for CACHE_VALID 1'. set entry->data & !CACHE_NEGATIVE 2. use entry->data 2'. set CACHE_VALID If the two memory writes performed in step 1' and 2' appear misordered with respect to the reads in step 1 and 2, then the caller could get stale data at step 2 even though it saw CACHE_VALID set on the cache entry. Add memory barriers to prevent this. Reviewed-by: NeilBrown <neilb@suse.de> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'net/sunrpc')
-rw-r--r--net/sunrpc/cache.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index a6c57334fa1..72ad836e4fe 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -128,6 +128,7 @@ static void cache_fresh_locked(struct cache_head *head, time_t expiry)
{
head->expiry_time = expiry;
head->last_refresh = seconds_since_boot();
+ smp_wmb(); /* paired with smp_rmb() in cache_is_valid() */
set_bit(CACHE_VALID, &head->flags);
}
@@ -208,8 +209,16 @@ static inline int cache_is_valid(struct cache_detail *detail, struct cache_head
/* entry is valid */
if (test_bit(CACHE_NEGATIVE, &h->flags))
return -ENOENT;
- else
+ else {
+ /*
+ * In combination with write barrier in
+ * sunrpc_cache_update, ensures that anyone
+ * using the cache entry after this sees the
+ * updated contents:
+ */
+ smp_rmb();
return 0;
+ }
}
}