Commit 6c9bef32 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'inet-fix-defrag-units-dismantle-races'



Eric Dumazet says:

====================
inet: fix defrag units dismantle races

This series add a new pre_exit() method to struct pernet_operations
to solve a race in defrag units dismantle, without adding extra
delays to netns dismantles.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 2a54003e d5dd8879
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ struct fqdir {

	/* Keep atomic mem on separate cachelines in structs that include it */
	atomic_long_t		mem ____cacheline_aligned_in_smp;
	struct rcu_work		destroy_rwork;
	struct work_struct	destroy_work;
};

/**
@@ -113,6 +113,12 @@ int inet_frags_init(struct inet_frags *);
void inet_frags_fini(struct inet_frags *);

int fqdir_init(struct fqdir **fqdirp, struct inet_frags *f, struct net *net);

static void inline fqdir_pre_exit(struct fqdir *fqdir)
{
	fqdir->high_thresh = 0; /* prevent creation of new frags */
	fqdir->dead = true;
}
void fqdir_exit(struct fqdir *fqdir);

void inet_frag_kill(struct inet_frag_queue *q);
+2 −0
Original line number Diff line number Diff line
@@ -67,6 +67,8 @@ ip6frag_expire_frag_queue(struct net *net, struct frag_queue *fq)
	struct sk_buff *head;

	rcu_read_lock();
	if (fq->q.fqdir->dead)
		goto out_rcu_unlock;
	spin_lock(&fq->q.lock);

	if (fq->q.flags & INET_FRAG_COMPLETE)
+5 −0
Original line number Diff line number Diff line
@@ -355,8 +355,13 @@ struct pernet_operations {
	 * synchronize_rcu() related to these pernet_operations,
	 * instead of separate synchronize_rcu() for every net.
	 * Please, avoid synchronize_rcu() at all, where it's possible.
	 *
	 * Note that a combination of pre_exit() and exit() can
	 * be used, since a synchronize_rcu() is guaranteed between
	 * the calls.
	 */
	int (*init)(struct net *net);
	void (*pre_exit)(struct net *net);
	void (*exit)(struct net *net);
	void (*exit_batch)(struct list_head *net_exit_list);
	unsigned int *id;
+28 −0
Original line number Diff line number Diff line
@@ -145,6 +145,17 @@ static void ops_free(const struct pernet_operations *ops, struct net *net)
	}
}

static void ops_pre_exit_list(const struct pernet_operations *ops,
			      struct list_head *net_exit_list)
{
	struct net *net;

	if (ops->pre_exit) {
		list_for_each_entry(net, net_exit_list, exit_list)
			ops->pre_exit(net);
	}
}

static void ops_exit_list(const struct pernet_operations *ops,
			  struct list_head *net_exit_list)
{
@@ -328,6 +339,12 @@ out_undo:
	 * for the pernet modules whose init functions did not fail.
	 */
	list_add(&net->exit_list, &net_exit_list);
	saved_ops = ops;
	list_for_each_entry_continue_reverse(ops, &pernet_list, list)
		ops_pre_exit_list(ops, &net_exit_list);

	synchronize_rcu();

	saved_ops = ops;
	list_for_each_entry_continue_reverse(ops, &pernet_list, list)
		ops_exit_list(ops, &net_exit_list);
@@ -541,10 +558,15 @@ static void cleanup_net(struct work_struct *work)
		list_add_tail(&net->exit_list, &net_exit_list);
	}

	/* Run all of the network namespace pre_exit methods */
	list_for_each_entry_reverse(ops, &pernet_list, list)
		ops_pre_exit_list(ops, &net_exit_list);

	/*
	 * Another CPU might be rcu-iterating the list, wait for it.
	 * This needs to be before calling the exit() notifiers, so
	 * the rcu_barrier() below isn't sufficient alone.
	 * Also the pre_exit() and exit() methods need this barrier.
	 */
	synchronize_rcu();

@@ -1101,6 +1123,8 @@ static int __register_pernet_operations(struct list_head *list,
out_undo:
	/* If I have an error cleanup all namespaces I initialized */
	list_del(&ops->list);
	ops_pre_exit_list(ops, &net_exit_list);
	synchronize_rcu();
	ops_exit_list(ops, &net_exit_list);
	ops_free_list(ops, &net_exit_list);
	return error;
@@ -1115,6 +1139,8 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
	/* See comment in __register_pernet_operations() */
	for_each_net(net)
		list_add_tail(&net->exit_list, &net_exit_list);
	ops_pre_exit_list(ops, &net_exit_list);
	synchronize_rcu();
	ops_exit_list(ops, &net_exit_list);
	ops_free_list(ops, &net_exit_list);
}
@@ -1139,6 +1165,8 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
	} else {
		LIST_HEAD(net_exit_list);
		list_add(&init_net.exit_list, &net_exit_list);
		ops_pre_exit_list(ops, &net_exit_list);
		synchronize_rcu();
		ops_exit_list(ops, &net_exit_list);
		ops_free_list(ops, &net_exit_list);
	}
+11 −2
Original line number Diff line number Diff line
@@ -459,6 +459,14 @@ static int __net_init lowpan_frags_init_net(struct net *net)
	return res;
}

static void __net_exit lowpan_frags_pre_exit_net(struct net *net)
{
	struct netns_ieee802154_lowpan *ieee802154_lowpan =
		net_ieee802154_lowpan(net);

	fqdir_pre_exit(ieee802154_lowpan->fqdir);
}

static void __net_exit lowpan_frags_exit_net(struct net *net)
{
	struct netns_ieee802154_lowpan *ieee802154_lowpan =
@@ -470,6 +478,7 @@ static void __net_exit lowpan_frags_exit_net(struct net *net)

static struct pernet_operations lowpan_frags_ops = {
	.init		= lowpan_frags_init_net,
	.pre_exit	= lowpan_frags_pre_exit_net,
	.exit		= lowpan_frags_exit_net,
};

Loading