Skip to content

Commit 77cc278

Browse files
a-darwishPeter Zijlstra
authored andcommitted
xfrm: policy: Use sequence counters with associated lock
A sequence counter write side critical section must be protected by some form of locking to serialize writers. If the serialization primitive is not disabling preemption implicitly, preemption has to be explicitly disabled before entering the sequence counter write side critical section. 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 and seqcount_mutex_t data types instead, which allow to associate a lock with the sequence counter. This enables lockdep to verify that the lock 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 b901892 commit 77cc278

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

net/xfrm/xfrm_policy.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct xfrm_pol_inexact_bin {
122122
/* list containing '*:*' policies */
123123
struct hlist_head hhead;
124124

125-
seqcount_t count;
125+
seqcount_spinlock_t count;
126126
/* tree sorted by daddr/prefix */
127127
struct rb_root root_d;
128128

@@ -155,7 +155,7 @@ static struct xfrm_policy_afinfo const __rcu *xfrm_policy_afinfo[AF_INET6 + 1]
155155
__read_mostly;
156156

157157
static struct kmem_cache *xfrm_dst_cache __ro_after_init;
158-
static __read_mostly seqcount_t xfrm_policy_hash_generation;
158+
static __read_mostly seqcount_mutex_t xfrm_policy_hash_generation;
159159

160160
static struct rhashtable xfrm_policy_inexact_table;
161161
static const struct rhashtable_params xfrm_pol_inexact_params;
@@ -719,7 +719,7 @@ xfrm_policy_inexact_alloc_bin(const struct xfrm_policy *pol, u8 dir)
719719
INIT_HLIST_HEAD(&bin->hhead);
720720
bin->root_d = RB_ROOT;
721721
bin->root_s = RB_ROOT;
722-
seqcount_init(&bin->count);
722+
seqcount_spinlock_init(&bin->count, &net->xfrm.xfrm_policy_lock);
723723

724724
prev = rhashtable_lookup_get_insert_key(&xfrm_policy_inexact_table,
725725
&bin->k, &bin->head,
@@ -1906,7 +1906,7 @@ static int xfrm_policy_match(const struct xfrm_policy *pol,
19061906

19071907
static struct xfrm_pol_inexact_node *
19081908
xfrm_policy_lookup_inexact_addr(const struct rb_root *r,
1909-
seqcount_t *count,
1909+
seqcount_spinlock_t *count,
19101910
const xfrm_address_t *addr, u16 family)
19111911
{
19121912
const struct rb_node *parent;
@@ -4153,7 +4153,7 @@ void __init xfrm_init(void)
41534153
{
41544154
register_pernet_subsys(&xfrm_net_ops);
41554155
xfrm_dev_init();
4156-
seqcount_init(&xfrm_policy_hash_generation);
4156+
seqcount_mutex_init(&xfrm_policy_hash_generation, &hash_resize_mutex);
41574157
xfrm_input_init();
41584158

41594159
#ifdef CONFIG_INET_ESPINTCP

0 commit comments

Comments
 (0)