tree: https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master head: 34d360415a921406e622f60e202892af8cf4c57b commit: 9fbf2fcf1734cbcd01ea3818242b6ed0c4d32869 [37/48] netfilter: nf_tables: atomic dump and reset for stateful objects config: i386-allmodconfig (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: git checkout 9fbf2fcf1734cbcd01ea3818242b6ed0c4d32869 # save the attached .config to linux build tree make ARCH=i386 All error/warnings (new ones prefixed by >>): net/netfilter/nft_counter.c: In function 'nft_counter_fetch': >> net/netfilter/nft_counter.c:128:18: warning: 'packets' may be used uninitialized in this function [-Wmaybe-uninitialized] total->packets += packets; ^~ >> net/netfilter/nft_counter.c:129:16: warning: 'bytes' may be used uninitialized in this function [-Wmaybe-uninitialized] total->bytes += bytes; ^~ In file included from arch/x86/include/asm/atomic.h:7:0, from arch/x86/include/asm/msr.h:66, from arch/x86/include/asm/processor.h:20, from arch/x86/include/asm/cpufeature.h:4, from arch/x86/include/asm/thread_info.h:52, from include/linux/thread_info.h:58, from arch/x86/include/asm/preempt.h:6, from include/linux/preempt.h:59, from include/linux/spinlock.h:50, from include/linux/seqlock.h:35, from include/linux/time.h:5, from include/linux/stat.h:18, from include/linux/module.h:10, from net/netfilter/nft_counter.c:13: >> arch/x86/include/asm/cmpxchg.h:66:4: error: call to '__xchg_wrong_size' declared with attribute error: Bad argument size for xchg __ ## op ## _wrong_size(); \ ^~~~~~~~~~~~~~~~~~~~~~~~~ arch/x86/include/asm/cmpxchg.h:77:22: note: in expansion of macro '__xchg_op' #define xchg(ptr, v) __xchg_op((ptr), (v), xchg, "") ^~~~~~~~~ >> net/netfilter/nft_counter.c:120:16: note: in expansion of macro 'xchg' packets += xchg(&cpu_stats->counter.packets, 0); ^~~~ >> arch/x86/include/asm/cmpxchg.h:66:4: error: call to '__xchg_wrong_size' declared with attribute error: Bad argument size for xchg __ ## op ## _wrong_size(); \ ^~~~~~~~~~~~~~~~~~~~~~~~~ arch/x86/include/asm/cmpxchg.h:77:22: note: in expansion of macro '__xchg_op' #define xchg(ptr, v) __xchg_op((ptr), (v), xchg, "") ^~~~~~~~~ net/netfilter/nft_counter.c:121:14: note: in expansion of macro 'xchg' bytes += xchg(&cpu_stats->counter.bytes, 0); ^~~~ vim +/packets +128 net/netfilter/nft_counter.c 96518518 Patrick McHardy 2013-10-14 7 * 96518518 Patrick McHardy 2013-10-14 8 * Development of this code funded by Astaro AG (http://www.astaro.com/) 96518518 Patrick McHardy 2013-10-14 9 */ 96518518 Patrick McHardy 2013-10-14 10 96518518 Patrick McHardy 2013-10-14 11 #include <linux/kernel.h> 96518518 Patrick McHardy 2013-10-14 12 #include <linux/init.h> 96518518 Patrick McHardy 2013-10-14 @13 #include <linux/module.h> 96518518 Patrick McHardy 2013-10-14 14 #include <linux/seqlock.h> 96518518 Patrick McHardy 2013-10-14 15 #include <linux/netlink.h> 96518518 Patrick McHardy 2013-10-14 16 #include <linux/netfilter.h> 96518518 Patrick McHardy 2013-10-14 17 #include <linux/netfilter/nf_tables.h> 96518518 Patrick McHardy 2013-10-14 18 #include <net/netfilter/nf_tables.h> 96518518 Patrick McHardy 2013-10-14 19 96518518 Patrick McHardy 2013-10-14 20 struct nft_counter { 96518518 Patrick McHardy 2013-10-14 21 u64 bytes; 96518518 Patrick McHardy 2013-10-14 22 u64 packets; 96518518 Patrick McHardy 2013-10-14 23 }; 96518518 Patrick McHardy 2013-10-14 24 0c45e769 Pablo Neira Ayuso 2015-06-08 25 struct nft_counter_percpu { 0c45e769 Pablo Neira Ayuso 2015-06-08 26 struct nft_counter counter; 0c45e769 Pablo Neira Ayuso 2015-06-08 27 struct u64_stats_sync syncp; 0c45e769 Pablo Neira Ayuso 2015-06-08 28 }; 0c45e769 Pablo Neira Ayuso 2015-06-08 29 0c45e769 Pablo Neira Ayuso 2015-06-08 30 struct nft_counter_percpu_priv { 0c45e769 Pablo Neira Ayuso 2015-06-08 31 struct nft_counter_percpu __percpu *counter; 0c45e769 Pablo Neira Ayuso 2015-06-08 32 }; 0c45e769 Pablo Neira Ayuso 2015-06-08 33 225b8725 Pablo Neira Ayuso 2016-11-28 34 static inline void nft_counter_do_eval(struct nft_counter_percpu_priv *priv, a55e22e9 Patrick McHardy 2015-04-11 35 struct nft_regs *regs, 96518518 Patrick McHardy 2013-10-14 36 const struct nft_pktinfo *pkt) 96518518 Patrick McHardy 2013-10-14 37 { 0c45e769 Pablo Neira Ayuso 2015-06-08 38 struct nft_counter_percpu *this_cpu; 0c45e769 Pablo Neira Ayuso 2015-06-08 39 0c45e769 Pablo Neira Ayuso 2015-06-08 40 local_bh_disable(); 0c45e769 Pablo Neira Ayuso 2015-06-08 41 this_cpu = this_cpu_ptr(priv->counter); 0c45e769 Pablo Neira Ayuso 2015-06-08 42 u64_stats_update_begin(&this_cpu->syncp); 0c45e769 Pablo Neira Ayuso 2015-06-08 43 this_cpu->counter.bytes += pkt->skb->len; 0c45e769 Pablo Neira Ayuso 2015-06-08 44 this_cpu->counter.packets++; 0c45e769 Pablo Neira Ayuso 2015-06-08 45 u64_stats_update_end(&this_cpu->syncp); 0c45e769 Pablo Neira Ayuso 2015-06-08 46 local_bh_enable(); 96518518 Patrick McHardy 2013-10-14 47 } 96518518 Patrick McHardy 2013-10-14 48 225b8725 Pablo Neira Ayuso 2016-11-28 49 static inline void nft_counter_obj_eval(struct nft_object *obj, 225b8725 Pablo Neira Ayuso 2016-11-28 50 struct nft_regs *regs, 225b8725 Pablo Neira Ayuso 2016-11-28 51 const struct nft_pktinfo *pkt) 225b8725 Pablo Neira Ayuso 2016-11-28 52 { 225b8725 Pablo Neira Ayuso 2016-11-28 53 struct nft_counter_percpu_priv *priv = nft_obj_data(obj); 225b8725 Pablo Neira Ayuso 2016-11-28 54 225b8725 Pablo Neira Ayuso 2016-11-28 55 nft_counter_do_eval(priv, regs, pkt); 225b8725 Pablo Neira Ayuso 2016-11-28 56 } 225b8725 Pablo Neira Ayuso 2016-11-28 57 225b8725 Pablo Neira Ayuso 2016-11-28 58 static int nft_counter_do_init(const struct nlattr * const tb[], 225b8725 Pablo Neira Ayuso 2016-11-28 59 struct nft_counter_percpu_priv *priv) 225b8725 Pablo Neira Ayuso 2016-11-28 60 { 225b8725 Pablo Neira Ayuso 2016-11-28 61 struct nft_counter_percpu __percpu *cpu_stats; 225b8725 Pablo Neira Ayuso 2016-11-28 62 struct nft_counter_percpu *this_cpu; 225b8725 Pablo Neira Ayuso 2016-11-28 63 225b8725 Pablo Neira Ayuso 2016-11-28 64 cpu_stats = netdev_alloc_pcpu_stats(struct nft_counter_percpu); 225b8725 Pablo Neira Ayuso 2016-11-28 65 if (cpu_stats == NULL) 225b8725 Pablo Neira Ayuso 2016-11-28 66 return -ENOMEM; 225b8725 Pablo Neira Ayuso 2016-11-28 67 225b8725 Pablo Neira Ayuso 2016-11-28 68 preempt_disable(); 225b8725 Pablo Neira Ayuso 2016-11-28 69 this_cpu = this_cpu_ptr(cpu_stats); 225b8725 Pablo Neira Ayuso 2016-11-28 70 if (tb[NFTA_COUNTER_PACKETS]) { 225b8725 Pablo Neira Ayuso 2016-11-28 71 this_cpu->counter.packets = 225b8725 Pablo Neira Ayuso 2016-11-28 72 be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_PACKETS])); 225b8725 Pablo Neira Ayuso 2016-11-28 73 } 225b8725 Pablo Neira Ayuso 2016-11-28 74 if (tb[NFTA_COUNTER_BYTES]) { 225b8725 Pablo Neira Ayuso 2016-11-28 75 this_cpu->counter.bytes = 225b8725 Pablo Neira Ayuso 2016-11-28 76 be64_to_cpu(nla_get_be64(tb[NFTA_COUNTER_BYTES])); 225b8725 Pablo Neira Ayuso 2016-11-28 77 } 225b8725 Pablo Neira Ayuso 2016-11-28 78 preempt_enable(); 225b8725 Pablo Neira Ayuso 2016-11-28 79 priv->counter = cpu_stats; 225b8725 Pablo Neira Ayuso 2016-11-28 80 return 0; 225b8725 Pablo Neira Ayuso 2016-11-28 81 } 225b8725 Pablo Neira Ayuso 2016-11-28 82 225b8725 Pablo Neira Ayuso 2016-11-28 83 static int nft_counter_obj_init(const struct nlattr * const tb[], 225b8725 Pablo Neira Ayuso 2016-11-28 84 struct nft_object *obj) 225b8725 Pablo Neira Ayuso 2016-11-28 85 { 225b8725 Pablo Neira Ayuso 2016-11-28 86 struct nft_counter_percpu_priv *priv = nft_obj_data(obj); 225b8725 Pablo Neira Ayuso 2016-11-28 87 225b8725 Pablo Neira Ayuso 2016-11-28 88 return nft_counter_do_init(tb, priv); 225b8725 Pablo Neira Ayuso 2016-11-28 89 } 225b8725 Pablo Neira Ayuso 2016-11-28 90 225b8725 Pablo Neira Ayuso 2016-11-28 91 static void nft_counter_do_destroy(struct nft_counter_percpu_priv *priv) 225b8725 Pablo Neira Ayuso 2016-11-28 92 { 225b8725 Pablo Neira Ayuso 2016-11-28 93 free_percpu(priv->counter); 225b8725 Pablo Neira Ayuso 2016-11-28 94 } 225b8725 Pablo Neira Ayuso 2016-11-28 95 225b8725 Pablo Neira Ayuso 2016-11-28 96 static void nft_counter_obj_destroy(struct nft_object *obj) 225b8725 Pablo Neira Ayuso 2016-11-28 97 { 225b8725 Pablo Neira Ayuso 2016-11-28 98 struct nft_counter_percpu_priv *priv = nft_obj_data(obj); 225b8725 Pablo Neira Ayuso 2016-11-28 99 225b8725 Pablo Neira Ayuso 2016-11-28 100 nft_counter_do_destroy(priv); 225b8725 Pablo Neira Ayuso 2016-11-28 101 } 225b8725 Pablo Neira Ayuso 2016-11-28 102 9fbf2fcf Pablo Neira Ayuso 2016-11-28 103 static void nft_counter_fetch(struct nft_counter_percpu __percpu *counter, 9fbf2fcf Pablo Neira Ayuso 2016-11-28 104 struct nft_counter *total, bool reset) 96518518 Patrick McHardy 2013-10-14 105 { 9fbf2fcf Pablo Neira Ayuso 2016-11-28 106 struct nft_counter_percpu *cpu_stats; 0c45e769 Pablo Neira Ayuso 2015-06-08 107 u64 bytes, packets; 96518518 Patrick McHardy 2013-10-14 108 unsigned int seq; 0c45e769 Pablo Neira Ayuso 2015-06-08 109 int cpu; 96518518 Patrick McHardy 2013-10-14 110 086f3321 Pablo Neira Ayuso 2015-11-10 111 memset(total, 0, sizeof(*total)); 0c45e769 Pablo Neira Ayuso 2015-06-08 112 for_each_possible_cpu(cpu) { 9fbf2fcf Pablo Neira Ayuso 2016-11-28 113 if (reset) 9fbf2fcf Pablo Neira Ayuso 2016-11-28 114 bytes = packets = 0; 9fbf2fcf Pablo Neira Ayuso 2016-11-28 115 086f3321 Pablo Neira Ayuso 2015-11-10 116 cpu_stats = per_cpu_ptr(counter, cpu); 96518518 Patrick McHardy 2013-10-14 117 do { 0c45e769 Pablo Neira Ayuso 2015-06-08 118 seq = u64_stats_fetch_begin_irq(&cpu_stats->syncp); 9fbf2fcf Pablo Neira Ayuso 2016-11-28 119 if (reset) { 9fbf2fcf Pablo Neira Ayuso 2016-11-28 @120 packets += xchg(&cpu_stats->counter.packets, 0); 9fbf2fcf Pablo Neira Ayuso 2016-11-28 121 bytes += xchg(&cpu_stats->counter.bytes, 0); 9fbf2fcf Pablo Neira Ayuso 2016-11-28 122 } else { 0c45e769 Pablo Neira Ayuso 2015-06-08 123 bytes = cpu_stats->counter.bytes; 0c45e769 Pablo Neira Ayuso 2015-06-08 124 packets = cpu_stats->counter.packets; 9fbf2fcf Pablo Neira Ayuso 2016-11-28 125 } 0c45e769 Pablo Neira Ayuso 2015-06-08 126 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, seq)); 96518518 Patrick McHardy 2013-10-14 127 086f3321 Pablo Neira Ayuso 2015-11-10 @128 total->packets += packets; 086f3321 Pablo Neira Ayuso 2015-11-10 @129 total->bytes += bytes; 086f3321 Pablo Neira Ayuso 2015-11-10 130 } 0c45e769 Pablo Neira Ayuso 2015-06-08 131 } 0c45e769 Pablo Neira Ayuso 2015-06-08 132 :::::: The code at line 128 was first introduced by commit :::::: 086f332167d64b645d37405854f049b9ad7371ab netfilter: nf_tables: add clone interface to expression operations :::::: TO: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> :::::: CC: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
Attachment:
.config.gz
Description: application/gzip