diff options
author | KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> | 2011-03-23 16:42:18 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-03-23 19:46:22 -0700 |
commit | 6c191cd01a935e5b53ef43c9403c771bb7a32b60 (patch) | |
tree | 70c49b4cb52406ea1d8c60f73ad7733f60f9cee9 | |
parent | 61f2e7b0f474225b4226772830ae4b29a3a21f8d (diff) | |
download | blackbird-op-linux-6c191cd01a935e5b53ef43c9403c771bb7a32b60.tar.gz blackbird-op-linux-6c191cd01a935e5b53ef43c9403c771bb7a32b60.zip |
memcg: res_counter_read_u64(): fix potential races on 32-bit machines
res_counter_read_u64 reads u64 value without lock. It's dangerous in a
32bit environment. Add locking.
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Rientjes <rientjes@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Minchan Kim <minchan.kim@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | kernel/res_counter.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/kernel/res_counter.c b/kernel/res_counter.c index c7eaa37a768b..34683efa2cce 100644 --- a/kernel/res_counter.c +++ b/kernel/res_counter.c @@ -126,10 +126,24 @@ ssize_t res_counter_read(struct res_counter *counter, int member, pos, buf, s - buf); } +#if BITS_PER_LONG == 32 +u64 res_counter_read_u64(struct res_counter *counter, int member) +{ + unsigned long flags; + u64 ret; + + spin_lock_irqsave(&counter->lock, flags); + ret = *res_counter_member(counter, member); + spin_unlock_irqrestore(&counter->lock, flags); + + return ret; +} +#else u64 res_counter_read_u64(struct res_counter *counter, int member) { return *res_counter_member(counter, member); } +#endif int res_counter_memparse_write_strategy(const char *buf, unsigned long long *res) |