@@ -884,42 +884,25 @@ get_counters(const struct xt_table_info *t,
884884 struct ipt_entry * iter ;
885885 unsigned int cpu ;
886886 unsigned int i ;
887- unsigned int curcpu = get_cpu ();
888-
889- /* Instead of clearing (by a previous call to memset())
890- * the counters and using adds, we set the counters
891- * with data used by 'current' CPU.
892- *
893- * Bottom half has to be disabled to prevent deadlock
894- * if new softirq were to run and call ipt_do_table
895- */
896- local_bh_disable ();
897- i = 0 ;
898- xt_entry_foreach (iter , t -> entries [curcpu ], t -> size ) {
899- SET_COUNTER (counters [i ], iter -> counters .bcnt ,
900- iter -> counters .pcnt );
901- ++ i ;
902- }
903- local_bh_enable ();
904- /* Processing counters from other cpus, we can let bottom half enabled,
905- * (preemption is disabled)
906- */
907887
908888 for_each_possible_cpu (cpu ) {
909- if ( cpu == curcpu )
910- continue ;
889+ seqlock_t * lock = & per_cpu ( xt_info_locks , cpu ). lock ;
890+
911891 i = 0 ;
912- local_bh_disable ();
913- xt_info_wrlock (cpu );
914892 xt_entry_foreach (iter , t -> entries [cpu ], t -> size ) {
915- ADD_COUNTER (counters [i ], iter -> counters .bcnt ,
916- iter -> counters .pcnt );
893+ u64 bcnt , pcnt ;
894+ unsigned int start ;
895+
896+ do {
897+ start = read_seqbegin (lock );
898+ bcnt = iter -> counters .bcnt ;
899+ pcnt = iter -> counters .pcnt ;
900+ } while (read_seqretry (lock , start ));
901+
902+ ADD_COUNTER (counters [i ], bcnt , pcnt );
917903 ++ i ; /* macro does multi eval of i */
918904 }
919- xt_info_wrunlock (cpu );
920- local_bh_enable ();
921905 }
922- put_cpu ();
923906}
924907
925908static struct xt_counters * alloc_counters (const struct xt_table * table )
@@ -932,7 +915,7 @@ static struct xt_counters *alloc_counters(const struct xt_table *table)
932915 (other than comefrom, which userspace doesn't care
933916 about). */
934917 countersize = sizeof (struct xt_counters ) * private -> number ;
935- counters = vmalloc (countersize );
918+ counters = vzalloc (countersize );
936919
937920 if (counters == NULL )
938921 return ERR_PTR (- ENOMEM );
@@ -1203,7 +1186,7 @@ __do_replace(struct net *net, const char *name, unsigned int valid_hooks,
12031186 struct ipt_entry * iter ;
12041187
12051188 ret = 0 ;
1206- counters = vmalloc (num_counters * sizeof (struct xt_counters ));
1189+ counters = vzalloc (num_counters * sizeof (struct xt_counters ));
12071190 if (!counters ) {
12081191 ret = - ENOMEM ;
12091192 goto out ;
0 commit comments