Skip to content

Commit 2a198bb

Browse files
qsnklassert
authored andcommitted
Revert "xfrm: destroy xfrm_state synchronously on net exit path"
This reverts commit f75a280. With all states (whether user or kern) removed from the hashtables during deletion, there's no need for synchronous destruction of states. xfrm6_tunnel states still need to have been destroyed (which will be the case when its last user is deleted (not destroyed)) so that xfrm6_tunnel_free_spi removes it from the per-netns hashtable before the netns is destroyed. This has the benefit of skipping one synchronize_rcu per state (in __xfrm_state_destroy(sync=true)) when we exit a netns. Signed-off-by: Sabrina Dubroca <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent b441cf3 commit 2a198bb

File tree

5 files changed

+15
-26
lines changed

5 files changed

+15
-26
lines changed

include/net/xfrm.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ static inline void xfrm_pols_put(struct xfrm_policy **pols, int npols)
915915
xfrm_pol_put(pols[i]);
916916
}
917917

918-
void __xfrm_state_destroy(struct xfrm_state *, bool);
918+
void __xfrm_state_destroy(struct xfrm_state *);
919919

920920
static inline void __xfrm_state_put(struct xfrm_state *x)
921921
{
@@ -925,13 +925,7 @@ static inline void __xfrm_state_put(struct xfrm_state *x)
925925
static inline void xfrm_state_put(struct xfrm_state *x)
926926
{
927927
if (refcount_dec_and_test(&x->refcnt))
928-
__xfrm_state_destroy(x, false);
929-
}
930-
931-
static inline void xfrm_state_put_sync(struct xfrm_state *x)
932-
{
933-
if (refcount_dec_and_test(&x->refcnt))
934-
__xfrm_state_destroy(x, true);
928+
__xfrm_state_destroy(x);
935929
}
936930

937931
static inline void xfrm_state_hold(struct xfrm_state *x)
@@ -1769,7 +1763,7 @@ struct xfrmk_spdinfo {
17691763

17701764
struct xfrm_state *xfrm_find_acq_byseq(struct net *net, u32 mark, u32 seq, u32 pcpu_num);
17711765
int xfrm_state_delete(struct xfrm_state *x);
1772-
int xfrm_state_flush(struct net *net, u8 proto, bool task_valid, bool sync);
1766+
int xfrm_state_flush(struct net *net, u8 proto, bool task_valid);
17731767
int xfrm_dev_state_flush(struct net *net, struct net_device *dev, bool task_valid);
17741768
int xfrm_dev_policy_flush(struct net *net, struct net_device *dev,
17751769
bool task_valid);

net/ipv6/xfrm6_tunnel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static void __net_exit xfrm6_tunnel_net_exit(struct net *net)
334334
struct xfrm6_tunnel_net *xfrm6_tn = xfrm6_tunnel_pernet(net);
335335
unsigned int i;
336336

337-
xfrm_state_flush(net, 0, false, true);
337+
xfrm_state_flush(net, IPSEC_PROTO_ANY, false);
338338
xfrm_flush_gc();
339339

340340
for (i = 0; i < XFRM6_TUNNEL_SPI_BYADDR_HSIZE; i++)

net/key/af_key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ static int pfkey_flush(struct sock *sk, struct sk_buff *skb, const struct sadb_m
17661766
if (proto == 0)
17671767
return -EINVAL;
17681768

1769-
err = xfrm_state_flush(net, proto, true, false);
1769+
err = xfrm_state_flush(net, proto, true);
17701770
err2 = unicast_flush_resp(sk, hdr);
17711771
if (err || err2) {
17721772
if (err == -ESRCH) /* empty table - go quietly */

net/xfrm/xfrm_state.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ void xfrm_state_free(struct xfrm_state *x)
592592
}
593593
EXPORT_SYMBOL(xfrm_state_free);
594594

595-
static void ___xfrm_state_destroy(struct xfrm_state *x)
595+
static void xfrm_state_gc_destroy(struct xfrm_state *x)
596596
{
597597
if (x->mode_cbs && x->mode_cbs->destroy_state)
598598
x->mode_cbs->destroy_state(x);
@@ -631,7 +631,7 @@ static void xfrm_state_gc_task(struct work_struct *work)
631631
synchronize_rcu();
632632

633633
hlist_for_each_entry_safe(x, tmp, &gc_list, gclist)
634-
___xfrm_state_destroy(x);
634+
xfrm_state_gc_destroy(x);
635635
}
636636

637637
static enum hrtimer_restart xfrm_timer_handler(struct hrtimer *me)
@@ -795,19 +795,14 @@ void xfrm_dev_state_free(struct xfrm_state *x)
795795
}
796796
#endif
797797

798-
void __xfrm_state_destroy(struct xfrm_state *x, bool sync)
798+
void __xfrm_state_destroy(struct xfrm_state *x)
799799
{
800800
WARN_ON(x->km.state != XFRM_STATE_DEAD);
801801

802-
if (sync) {
803-
synchronize_rcu();
804-
___xfrm_state_destroy(x);
805-
} else {
806-
spin_lock_bh(&xfrm_state_gc_lock);
807-
hlist_add_head(&x->gclist, &xfrm_state_gc_list);
808-
spin_unlock_bh(&xfrm_state_gc_lock);
809-
schedule_work(&xfrm_state_gc_work);
810-
}
802+
spin_lock_bh(&xfrm_state_gc_lock);
803+
hlist_add_head(&x->gclist, &xfrm_state_gc_list);
804+
spin_unlock_bh(&xfrm_state_gc_lock);
805+
schedule_work(&xfrm_state_gc_work);
811806
}
812807
EXPORT_SYMBOL(__xfrm_state_destroy);
813808

@@ -922,7 +917,7 @@ xfrm_dev_state_flush_secctx_check(struct net *net, struct net_device *dev, bool
922917
}
923918
#endif
924919

925-
int xfrm_state_flush(struct net *net, u8 proto, bool task_valid, bool sync)
920+
int xfrm_state_flush(struct net *net, u8 proto, bool task_valid)
926921
{
927922
int i, err = 0, cnt = 0;
928923

@@ -3283,7 +3278,7 @@ void xfrm_state_fini(struct net *net)
32833278
unsigned int sz;
32843279

32853280
flush_work(&net->xfrm.state_hash_work);
3286-
xfrm_state_flush(net, 0, false, true);
3281+
xfrm_state_flush(net, IPSEC_PROTO_ANY, false);
32873282
flush_work(&xfrm_state_gc_work);
32883283

32893284
WARN_ON(!list_empty(&net->xfrm.state_all));

net/xfrm/xfrm_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,7 @@ static int xfrm_flush_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
26352635
struct xfrm_usersa_flush *p = nlmsg_data(nlh);
26362636
int err;
26372637

2638-
err = xfrm_state_flush(net, p->proto, true, false);
2638+
err = xfrm_state_flush(net, p->proto, true);
26392639
if (err) {
26402640
if (err == -ESRCH) /* empty table */
26412641
return 0;

0 commit comments

Comments
 (0)