From 0fc925d7c790e1c130e127dead90ce15a011037d Mon Sep 17 00:00:00 2001
From: Pim van den Berg <pim@nethuis.nl>
Date: Sun, 30 Dec 2012 17:32:05 +0100
Subject: [PATCH] grsec: patch bcache counters to be of the atomic_unchecked_t
 type

False positive refcount overflows got detected.

Reference: http://article.gmane.org/gmane.linux.kernel.bcache.devel/1408
---
 drivers/md/bcache/request.c |    8 ++++----
 drivers/md/bcache/stats.c   |   22 +++++++++++-----------
 drivers/md/bcache/stats.h   |   14 +++++++-------
 3 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index 2a7f0dd..1534856 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -91,27 +91,27 @@ static int bch_verify_write(struct cgroup *cgrp, struct cftype *cft, u64 val)
 static u64 bch_cache_hits_read(struct cgroup *cgrp, struct cftype *cft)
 {
 	struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
-	return atomic_read(&bcachecg->stats.cache_hits);
+	return atomic_read_unchecked(&bcachecg->stats.cache_hits);
 }
 
 static u64 bch_cache_misses_read(struct cgroup *cgrp, struct cftype *cft)
 {
 	struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
-	return atomic_read(&bcachecg->stats.cache_misses);
+	return atomic_read_unchecked(&bcachecg->stats.cache_misses);
 }
 
 static u64 bch_cache_bypass_hits_read(struct cgroup *cgrp,
 					 struct cftype *cft)
 {
 	struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
-	return atomic_read(&bcachecg->stats.cache_bypass_hits);
+	return atomic_read_unchecked(&bcachecg->stats.cache_bypass_hits);
 }
 
 static u64 bch_cache_bypass_misses_read(struct cgroup *cgrp,
 					   struct cftype *cft)
 {
 	struct bch_cgroup *bcachecg = cgroup_to_bcache(cgrp);
-	return atomic_read(&bcachecg->stats.cache_bypass_misses);
+	return atomic_read_unchecked(&bcachecg->stats.cache_bypass_misses);
 }
 
 static struct cftype bch_files[] = {
diff --git a/drivers/md/bcache/stats.c b/drivers/md/bcache/stats.c
index b8730e7..fd3ad53 100644
--- a/drivers/md/bcache/stats.c
+++ b/drivers/md/bcache/stats.c
@@ -152,7 +152,7 @@ static void scale_accounting(unsigned long data)
 	struct cache_accounting *acc = (struct cache_accounting *) data;
 
 #define move_stat(name) do {						\
-	unsigned t = atomic_xchg(&acc->collector.name, 0);		\
+	unsigned t = atomic_xchg_unchecked(&acc->collector.name, 0);		\
 	t <<= 16;							\
 	acc->five_minute.name += t;					\
 	acc->hour.name += t;						\
@@ -186,14 +186,14 @@ static void mark_cache_stats(struct cache_stat_collector *stats,
 {
 	if (!bypass)
 		if (hit)
-			atomic_inc(&stats->cache_hits);
+			atomic_inc_unchecked(&stats->cache_hits);
 		else
-			atomic_inc(&stats->cache_misses);
+			atomic_inc_unchecked(&stats->cache_misses);
 	else
 		if (hit)
-			atomic_inc(&stats->cache_bypass_hits);
+			atomic_inc_unchecked(&stats->cache_bypass_hits);
 		else
-			atomic_inc(&stats->cache_bypass_misses);
+			atomic_inc_unchecked(&stats->cache_bypass_misses);
 }
 
 void bch_mark_cache_accounting(struct search *s, bool hit, bool bypass)
@@ -209,22 +209,22 @@ void bch_mark_cache_accounting(struct search *s, bool hit, bool bypass)
 void bch_mark_cache_readahead(struct search *s)
 {
 	struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
-	atomic_inc(&dc->accounting.collector.cache_readaheads);
-	atomic_inc(&s->op.c->accounting.collector.cache_readaheads);
+	atomic_inc_unchecked(&dc->accounting.collector.cache_readaheads);
+	atomic_inc_unchecked(&s->op.c->accounting.collector.cache_readaheads);
 }
 
 void bch_mark_cache_miss_collision(struct search *s)
 {
 	struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
-	atomic_inc(&dc->accounting.collector.cache_miss_collisions);
-	atomic_inc(&s->op.c->accounting.collector.cache_miss_collisions);
+	atomic_inc_unchecked(&dc->accounting.collector.cache_miss_collisions);
+	atomic_inc_unchecked(&s->op.c->accounting.collector.cache_miss_collisions);
 }
 
 void bch_mark_sectors_bypassed(struct search *s, int sectors)
 {
 	struct cached_dev *dc = container_of(s->d, struct cached_dev, disk);
-	atomic_add(sectors, &dc->accounting.collector.sectors_bypassed);
-	atomic_add(sectors, &s->op.c->accounting.collector.sectors_bypassed);
+	atomic_add_unchecked(sectors, &dc->accounting.collector.sectors_bypassed);
+	atomic_add_unchecked(sectors, &s->op.c->accounting.collector.sectors_bypassed);
 }
 
 void bch_cache_accounting_init(struct cache_accounting *acc,
diff --git a/drivers/md/bcache/stats.h b/drivers/md/bcache/stats.h
index c7c7a8f..3b67caf 100644
--- a/drivers/md/bcache/stats.h
+++ b/drivers/md/bcache/stats.h
@@ -2,13 +2,13 @@
 #define _BCACHE_STATS_H_
 
 struct cache_stat_collector {
-	atomic_t cache_hits;
-	atomic_t cache_misses;
-	atomic_t cache_bypass_hits;
-	atomic_t cache_bypass_misses;
-	atomic_t cache_readaheads;
-	atomic_t cache_miss_collisions;
-	atomic_t sectors_bypassed;
+	atomic_unchecked_t cache_hits;
+	atomic_unchecked_t cache_misses;
+	atomic_unchecked_t cache_bypass_hits;
+	atomic_unchecked_t cache_bypass_misses;
+	atomic_unchecked_t cache_readaheads;
+	atomic_unchecked_t cache_miss_collisions;
+	atomic_unchecked_t sectors_bypassed;
 };
 
 struct cache_stats {
-- 
1.7.10.4

