Skip to content

Commit 80055da

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: x_tables: make xt_replace_table wait until old rules are not used anymore
xt_replace_table relies on table replacement counter retrieval (which uses xt_recseq to synchronize pcpu counters). This is fine, however with large rule set get_counters() can take a very long time -- it needs to synchronize all counters because it has to assume concurrent modifications can occur. Make xt_replace_table synchronize by itself by waiting until all cpus had an even seqcount. This allows a followup patch to copy the counters of the old ruleset without any synchonization after xt_replace_table has completed. Cc: Dan Williams <dcbw@redhat.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent eb6fad5 commit 80055da

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎net/netfilter/x_tables.c‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ xt_replace_table(struct xt_table *table,
11531153
int *error)
11541154
{
11551155
struct xt_table_info *private;
1156+
unsigned int cpu;
11561157
int ret;
11571158

11581159
ret = xt_jumpstack_alloc(newinfo);
@@ -1182,14 +1183,28 @@ xt_replace_table(struct xt_table *table,
11821183
smp_wmb();
11831184
table->private = newinfo;
11841185

1186+
/* make sure all cpus see new ->private value */
1187+
smp_wmb();
1188+
11851189
/*
11861190
* Even though table entries have now been swapped, other CPU's
1187-
* may still be using the old entries. This is okay, because
1188-
* resynchronization happens because of the locking done
1189-
* during the get_counters() routine.
1191+
* may still be using the old entries...
11901192
*/
11911193
local_bh_enable();
11921194

1195+
/* ... so wait for even xt_recseq on all cpus */
1196+
for_each_possible_cpu(cpu) {
1197+
seqcount_t *s = &per_cpu(xt_recseq, cpu);
1198+
u32 seq = raw_read_seqcount(s);
1199+
1200+
if (seq & 1) {
1201+
do {
1202+
cond_resched();
1203+
cpu_relax();
1204+
} while (seq == raw_read_seqcount(s));
1205+
}
1206+
}
1207+
11931208
#ifdef CONFIG_AUDIT
11941209
if (audit_enabled) {
11951210
audit_log(current->audit_context, GFP_KERNEL,

0 commit comments

Comments
 (0)