Skip to content

Commit 8201d92

Browse files
a-darwishPeter Zijlstra
authored andcommitted
netfilter: conntrack: Use sequence counter with associated spinlock
A sequence counter write side critical section must be protected by some form of locking to serialize writers. A plain seqcount_t does not contain the information of which lock must be held when entering a write side critical section. Use the new seqcount_spinlock_t data type, which allows to associate a spinlock with the sequence counter. This enables lockdep to verify that the spinlock used for writer serialization is held when the write side critical section is entered. If lockdep is disabled this lock association is compiled out and has neither storage size nor runtime overhead. Signed-off-by: Ahmed S. Darwish <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b750586 commit 8201d92

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

include/net/netfilter/nf_conntrack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ int nf_conntrack_hash_resize(unsigned int hashsize);
286286

287287
extern struct hlist_nulls_head *nf_conntrack_hash;
288288
extern unsigned int nf_conntrack_htable_size;
289-
extern seqcount_t nf_conntrack_generation;
289+
extern seqcount_spinlock_t nf_conntrack_generation;
290290
extern unsigned int nf_conntrack_max;
291291

292292
/* must be called with rcu read lock held */

net/netfilter/nf_conntrack_core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(nf_conntrack_htable_size);
180180

181181
unsigned int nf_conntrack_max __read_mostly;
182182
EXPORT_SYMBOL_GPL(nf_conntrack_max);
183-
seqcount_t nf_conntrack_generation __read_mostly;
183+
seqcount_spinlock_t nf_conntrack_generation __read_mostly;
184184
static unsigned int nf_conntrack_hash_rnd __read_mostly;
185185

186186
static u32 hash_conntrack_raw(const struct nf_conntrack_tuple *tuple,
@@ -2600,7 +2600,8 @@ int nf_conntrack_init_start(void)
26002600
/* struct nf_ct_ext uses u8 to store offsets/size */
26012601
BUILD_BUG_ON(total_extension_size() > 255u);
26022602

2603-
seqcount_init(&nf_conntrack_generation);
2603+
seqcount_spinlock_init(&nf_conntrack_generation,
2604+
&nf_conntrack_locks_all_lock);
26042605

26052606
for (i = 0; i < CONNTRACK_LOCKS; i++)
26062607
spin_lock_init(&nf_conntrack_locks[i]);

0 commit comments

Comments
 (0)