Skip to content

Commit bc8e0ad

Browse files
a-darwishklassert
authored andcommitted
net: xfrm: Use sequence counter with associated spinlock
A sequence counter write section must be serialized or its internal state can get corrupted. A plain seqcount_t does not contain the information of which lock must be held to guaranteee write side serialization. For xfrm_state_hash_generation, use seqcount_spinlock_t instead of plain seqcount_t. This allows to associate the spinlock used for write serialization with the sequence counter. It thus enables lockdep to verify that the write serialization lock is indeed held before entering the sequence counter write section. 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: Steffen Klassert <[email protected]>
1 parent e88add1 commit bc8e0ad

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

include/net/netns/xfrm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct netns_xfrm {
7373
struct dst_ops xfrm6_dst_ops;
7474
#endif
7575
spinlock_t xfrm_state_lock;
76-
seqcount_t xfrm_state_hash_generation;
76+
seqcount_spinlock_t xfrm_state_hash_generation;
7777

7878
spinlock_t xfrm_policy_lock;
7979
struct mutex xfrm_cfg_mutex;

net/xfrm/xfrm_state.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2665,7 +2665,8 @@ int __net_init xfrm_state_init(struct net *net)
26652665
net->xfrm.state_num = 0;
26662666
INIT_WORK(&net->xfrm.state_hash_work, xfrm_hash_resize);
26672667
spin_lock_init(&net->xfrm.xfrm_state_lock);
2668-
seqcount_init(&net->xfrm.xfrm_state_hash_generation);
2668+
seqcount_spinlock_init(&net->xfrm.xfrm_state_hash_generation,
2669+
&net->xfrm.xfrm_state_lock);
26692670
return 0;
26702671

26712672
out_byspi:

0 commit comments

Comments
 (0)