--- x/include/net/xfrm.h +++ y/include/net/xfrm.h @@ -202,6 +202,7 @@ struct xfrm_state { refcount_t refcnt; spinlock_t lock; + int deleted; u32 pcpu_num; struct xfrm_id id; --- x/net/xfrm/xfrm_state.c +++ y/net/xfrm/xfrm_state.c @@ -615,6 +615,7 @@ static void xfrm_state_gc_destroy(struct put_page(x->xfrag.page); xfrm_dev_state_free(x); security_xfrm_state_free(x); + xfrm_state_delete(x); xfrm_state_free(x); } @@ -812,10 +813,16 @@ int __xfrm_state_delete(struct xfrm_stat struct net *net = xs_net(x); int err = -ESRCH; - if (x->km.state != XFRM_STATE_DEAD) { - x->km.state = XFRM_STATE_DEAD; + for (;;) { + if (x->km.state != XFRM_STATE_DEAD) + x->km.state = XFRM_STATE_DEAD; spin_lock(&net->xfrm.xfrm_state_lock); + if (x->deleted) { + spin_unlock(&net->xfrm.xfrm_state_lock); + return 0; + } + x->deleted++; list_del(&x->km.all); hlist_del_rcu(&x->bydst); hlist_del_rcu(&x->bysrc);