Skip to content

Commit

Permalink
net: xfrm: Use sequence counter with associated spinlock
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
a-darwish authored and klassert committed Mar 22, 2021
1 parent e88add1 commit bc8e0ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/net/netns/xfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct netns_xfrm {
struct dst_ops xfrm6_dst_ops;
#endif
spinlock_t xfrm_state_lock;
seqcount_t xfrm_state_hash_generation;
seqcount_spinlock_t xfrm_state_hash_generation;

spinlock_t xfrm_policy_lock;
struct mutex xfrm_cfg_mutex;
Expand Down
3 changes: 2 additions & 1 deletion net/xfrm/xfrm_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -2665,7 +2665,8 @@ int __net_init xfrm_state_init(struct net *net)
net->xfrm.state_num = 0;
INIT_WORK(&net->xfrm.state_hash_work, xfrm_hash_resize);
spin_lock_init(&net->xfrm.xfrm_state_lock);
seqcount_init(&net->xfrm.xfrm_state_hash_generation);
seqcount_spinlock_init(&net->xfrm.xfrm_state_hash_generation,
&net->xfrm.xfrm_state_lock);
return 0;

out_byspi:
Expand Down

0 comments on commit bc8e0ad

Please sign in to comment.