Unverified Commit d2901c3f authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files
parents 2c202fa7 df18700c
Loading
Loading
Loading
Loading
+37 −33
Original line number Diff line number Diff line
@@ -81,6 +81,9 @@ static __read_mostly spinlock_t nf_conntrack_locks_all_lock;
static __read_mostly DEFINE_SPINLOCK(nf_conntrack_locks_all_lock);
static __read_mostly bool nf_conntrack_locks_all;

/* serialize hash resizes and nf_ct_iterate_cleanup */
static DEFINE_MUTEX(nf_conntrack_mutex);

/* every gc cycle scans at most 1/GC_MAX_BUCKETS_DIV part of table */
#define GC_MAX_BUCKETS_DIV	128u
/* upper bound of full table scan */
@@ -2054,11 +2057,15 @@ get_next_corpse(int (*iter)(struct nf_conn *i, void *data),
	spinlock_t *lockp;

	for (; *bucket < nf_conntrack_htable_size; (*bucket)++) {
		struct hlist_nulls_head *hslot = &nf_conntrack_hash[*bucket];

		if (hlist_nulls_empty(hslot))
			continue;

		lockp = &nf_conntrack_locks[*bucket % CONNTRACK_LOCKS];
		local_bh_disable();
		nf_conntrack_lock(lockp);
		if (*bucket < nf_conntrack_htable_size) {
			hlist_nulls_for_each_entry(h, n, &nf_conntrack_hash[*bucket], hnnode) {
		hlist_nulls_for_each_entry(h, n, hslot, hnnode) {
			if (NF_CT_DIRECTION(h) != IP_CT_DIR_REPLY)
				continue;
			/* All nf_conn objects are added to hash table twice, one
@@ -2076,7 +2083,6 @@ get_next_corpse(int (*iter)(struct nf_conn *i, void *data),
			if (iter(ct, data))
				goto found;
		}
		}
		spin_unlock(lockp);
		local_bh_enable();
		cond_resched();
@@ -2093,14 +2099,12 @@ get_next_corpse(int (*iter)(struct nf_conn *i, void *data),
static void nf_ct_iterate_cleanup(int (*iter)(struct nf_conn *i, void *data),
				  void *data, u32 portid, int report)
{
	unsigned int bucket = 0, sequence;
	unsigned int bucket = 0;
	struct nf_conn *ct;

	might_sleep();

	for (;;) {
		sequence = read_seqcount_begin(&nf_conntrack_generation);

	mutex_lock(&nf_conntrack_mutex);
	while ((ct = get_next_corpse(iter, data, &bucket)) != NULL) {
		/* Time to push up daises... */

@@ -2108,11 +2112,7 @@ static void nf_ct_iterate_cleanup(int (*iter)(struct nf_conn *i, void *data),
		nf_ct_put(ct);
		cond_resched();
	}

		if (!read_seqcount_retry(&nf_conntrack_generation, sequence))
			break;
		bucket = 0;
	}
	mutex_unlock(&nf_conntrack_mutex);
}

struct iter_data {
@@ -2346,8 +2346,10 @@ int nf_conntrack_hash_resize(unsigned int hashsize)
	if (!hash)
		return -ENOMEM;

	mutex_lock(&nf_conntrack_mutex);
	old_size = nf_conntrack_htable_size;
	if (old_size == hashsize) {
		mutex_unlock(&nf_conntrack_mutex);
		kvfree(hash);
		return 0;
	}
@@ -2383,6 +2385,8 @@ int nf_conntrack_hash_resize(unsigned int hashsize)
	nf_conntrack_all_unlock();
	local_bh_enable();

	mutex_unlock(&nf_conntrack_mutex);

	synchronize_net();
	kvfree(old_hash);
	return 0;