From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202408 header.b=boGjfkP3; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id F0AED5A0278 for ; Fri, 06 Sep 2024 07:17:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1725599833; bh=RwKdRg5H79sjf/6SG3DCabYD1Cr66q11Zm3uWfb77KI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=boGjfkP3M0ctzWTM4cqXEV9C6IEnFZjJ3WQui0+9D6IA59ktK94EEiitJ3mGkQm+v lalKdJLWcJxjp2kk2OmIq3sA7BUgTb5tPABxEQsP6gN+1PACoWRLeOvfr4F+ILqX+1 GnaV9h5uC0yZ/y7S/F6SZ0ehyFhL4sqC1VG59LLbD1kCIUVXKMLGBpyQa5Da1Z8apR inSVO5ZJ5ofJ6evPCkRODFFAEabXQ3mdHOFguEMPflppmJpmKivlpmtksMo6vYUwvK a8YeaI1KTDGAPO8G6t3Ni4lzBktoP/m+j7UybkSjgSOOa7vOHG+81xjTX5RQkND5cK CZ92UwhpsxGYg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4X0Pc94gRnz4x8H; Fri, 6 Sep 2024 15:17:13 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 1/6] flow: Fix incorrect hash probe in flowside_lookup() Date: Fri, 6 Sep 2024 15:17:05 +1000 Message-ID: <20240906051710.3863211-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240906051710.3863211-1-david@gibson.dropbear.id.au> References: <20240906051710.3863211-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: YJULK4GWCA3VQNEB3YJZGF3KZGRG4S6H X-Message-ID-Hash: YJULK4GWCA3VQNEB3YJZGF3KZGRG4S6H X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Our flow hash table uses linear probing in which we step backwards through clusters of adjacent hash entries when we have near collisions. Usually that's implemented by flow_hash_probe(). However, due to some details we need a second implementation in flowside_lookup(). An embarrassing oversight in rebasing from earlier versions has mean that version is incorrect, trying to step forward through clusters rather than backward. In situations with the right sorts of has near-collisions this can lead to us not associating an ACK from the tap device with the right flow, leaving it in a not-quite-established state. If the remote peer does a shutdown() at the right time, this can lead to a storm of EPOLLRDHUP events causing high CPU load. Fixes: acca4235c ("flow, tcp: Generalise TCP hash table to general...") Link: https://bugs.passt.top/show_bug.cgi?id=94 Suggested-by: Stefano Brivio Signed-off-by: David Gibson --- flow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow.c b/flow.c index 02631eb2..a00e01d1 100644 --- a/flow.c +++ b/flow.c @@ -697,7 +697,7 @@ static flow_sidx_t flowside_lookup(const struct ctx *c, uint8_t proto, !(FLOW_PROTO(&flow->f) == proto && flow->f.pif[sidx.sidei] == pif && flowside_eq(&flow->f.side[sidx.sidei], side))) - b = (b + 1) % FLOW_HASH_SIZE; + b = mod_sub(b, 1, FLOW_HASH_SIZE); return flow_hashtab[b]; } -- 2.46.0