Commit 375d9696 authored by Eric Dumazet's avatar Eric Dumazet Committed by Wang Liang
Browse files

tcp/dccp: bypass empty buckets in inet_twsk_purge()

stable inclusion
from stable-v6.6.48
commit 9624febd6968ad8174ab6236b82d5c1b1639db99
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IAOXZW
CVE: CVE-2024-44991

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9624febd6968ad8174ab6236b82d5c1b1639db99



--------------------------------

[ Upstream commit 50e2907ef8bb52cf80ecde9eec5c4dac07177146 ]

TCP ehash table is often sparsely populated.

inet_twsk_purge() spends too much time calling cond_resched().

This patch can reduce time spent in inet_twsk_purge() by 20x.

Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Link: https://lore.kernel.org/r/20240327191206.508114-1-edumazet@google.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Stable-dep-of: 565d121b6998 ("tcp: prevent concurrent execution of tcp_sk_exit_batch")
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarWang Liang <wangliang74@huawei.com>
parent 7ab021d4
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -281,12 +281,17 @@ EXPORT_SYMBOL_GPL(__inet_twsk_schedule);
/* Remove all non full sockets (TIME_WAIT and NEW_SYN_RECV) for dead netns */
void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)
{
	struct inet_ehash_bucket *head = &hashinfo->ehash[0];
	unsigned int ehash_mask = hashinfo->ehash_mask;
	struct hlist_nulls_node *node;
	unsigned int slot;
	struct sock *sk;

	for (slot = 0; slot <= hashinfo->ehash_mask; slot++) {
		struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
	for (slot = 0; slot <= ehash_mask; slot++, head++) {

		if (hlist_nulls_empty(&head->chain))
			continue;

restart_rcu:
		cond_resched();
		rcu_read_lock();