Skip to contentSkip to conversation

netfilter: nft_counter: use cmpxchg64 instead of xchg

PATCH New Pablo Neira Ayuso 1 participant 1 message Dec 7, 2016

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nft_counter: use cmpxchg64 instead of xchg

xchg cannot be used on 32bit, use cmpxchg64 to reset counters.

call to '__xchg_wrong_size' declared with attribute error: Bad argument size for xchg

---
I'm going to fold this in the local rebase that I have prepared.

 net/netfilter/nft_counter.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
net/netfilter/nft_counter.c +14 -2
index 3d2ff23be8d6..f6a02c5071c2 100644
@@ -122,6 +122,18 @@ static void nft_counter_fetch(struct nft_counter_percpu __percpu *counter,
 	}
 }
 
+static u64 __nft_counter_reset(u64 *counter)
+{
+	u64 ret, old;
+
+	do {
+		old = *counter;
+		ret = cmpxchg64(counter, old, 0);
+	} while (ret != old);
+
+	return ret;
+}
+
 static void nft_counter_reset(struct nft_counter_percpu __percpu *counter,
 			      struct nft_counter *total)
 {
@@ -137,8 +149,8 @@ static void nft_counter_reset(struct nft_counter_percpu __percpu *counter,
 		cpu_stats = per_cpu_ptr(counter, cpu);
 		do {
 			seq	= u64_stats_fetch_begin_irq(&cpu_stats->syncp);
-			packets += xchg(&cpu_stats->counter.packets, 0);
-			bytes	+= xchg(&cpu_stats->counter.bytes, 0);
+			packets	+= __nft_counter_reset(&cpu_stats->counter.packets);
+			bytes	+= __nft_counter_reset(&cpu_stats->counter.bytes);
 		} while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, seq));
 
 		total->packets += packets;
Signature · 1 line
2.1.4