From patchwork Tue Dec 3 08:12:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youngmin Nam X-Patchwork-Id: 13891890 X-Patchwork-Delegate: kuba@kernel.org Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EB5F1B0F1E for ; Tue, 3 Dec 2024 08:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733213418; cv=none; b=VI8SRy5BpfyQK+GUJo/PxcCaZOWKfhUos7uCnh+78hYqOoDFZOBEKxXK8c2/nLWgpbw6VYy2IOOcEwxBeGOurYzTJAKYQ9zwNwNxZ4yQCcYg/EJWGJEQyt8De/kwuvD90jQJcBgdCWolbWzuiUlI+R6FxDeD26gixDIoyxy432A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733213418; c=relaxed/simple; bh=QtnBsfYZa31/Qr1SPL0KCinYN2AJlNTIR403C8wr8XQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type: References; b=eSwhYAAfI1bZJmpMSa0PhdDxX1AuxiPP4n10DlHA2vbG9JbCz2GHhI2G1T0oisbA5eIziLFc42zU95yY9a6MU5zpu0Q08J/TNfjdacKWIaOz71iDid1dsWvr/gtpTTsbAdF+E3Tp0hsGrRrUo+IAagWbFIG+uhmTs8WxECwtN7I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=gC/M3U2d; arc=none smtp.client-ip=203.254.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="gC/M3U2d" Received: from epcas2p2.samsung.com (unknown [182.195.41.54]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20241203081007epoutp04faf5984978b2482b4847a70b64953820~NnGlVQDAt2661826618epoutp04C for ; Tue, 3 Dec 2024 08:10:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20241203081007epoutp04faf5984978b2482b4847a70b64953820~NnGlVQDAt2661826618epoutp04C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1733213407; bh=kxTPArR5B+jjKoq0idZWZS3H8GcXoNuskGgAVB4JQd0=; h=From:To:Cc:Subject:Date:References:From; b=gC/M3U2dm6nzQqDSTpe9FtnIrGONsa4sQpTka+y3gY0DdjBLFaQRxliRbrrGYsfk2 ofQTHLFNUWYslxJ592RNWfAxa/MWz9WjCDIDHxaW0uwe/swD0HPW5mWc4MSpgkyeZA A8EV+XCkAQ6Odl3thwNYxFrTANhMgeNEAI0uI50I= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p2.samsung.com (KnoxPortal) with ESMTP id 20241203081007epcas2p23b26a619f34bbf32a4eaf1b434d02518~NnGkvZ4OQ2492424924epcas2p2F; Tue, 3 Dec 2024 08:10:07 +0000 (GMT) Received: from epsmgec2p1-new.samsung.com (unknown [182.195.36.69]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4Y2YH22pGwz4x9Py; Tue, 3 Dec 2024 08:10:06 +0000 (GMT) Received: from epcas2p3.samsung.com ( [182.195.41.55]) by epsmgec2p1-new.samsung.com (Symantec Messaging Gateway) with SMTP id 18.46.32010.EDCBE476; Tue, 3 Dec 2024 17:10:06 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas2p2.samsung.com (KnoxPortal) with ESMTPA id 20241203081005epcas2p247b3d05bc767b1a50ba85c4433657295~NnGjalTmm2759327593epcas2p2Z; Tue, 3 Dec 2024 08:10:05 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20241203081005epsmtrp2cf697a4eb0d96f969d6e77ea8e963089~NnGjZbHAs2167021670epsmtrp2J; Tue, 3 Dec 2024 08:10:05 +0000 (GMT) X-AuditID: b6c32a4d-acffa70000007d0a-38-674ebcde09b3 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id D1.0C.18729.DDCBE476; Tue, 3 Dec 2024 17:10:05 +0900 (KST) Received: from perf.dsn.sec.samsung.com (unknown [10.229.95.91]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20241203081005epsmtip2139b10f98a9e4c7149a9a4baa8d680be~NnGjLdDaD2959429594epsmtip26; Tue, 3 Dec 2024 08:10:05 +0000 (GMT) From: Youngmin Nam To: edumazet@google.com, davem@davemloft.net, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, youngmin.nam@samsung.com, dujeong.lee@samsung.com, guo88.liu@samsung.com, yiwang.cai@samsung.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, joonki.min@samsung.com, hajun.sung@samsung.com, d7271.choe@samsung.com, sw.ju@samsung.com Subject: [PATCH] tcp: check socket state before calling WARN_ON Date: Tue, 3 Dec 2024 17:12:47 +0900 Message-Id: <20241203081247.1533534-1-youngmin.nam@samsung.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPJsWRmVeSWpSXmKPExsWy7bCmue69PX7pBvsmC1l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dtqjsKrzE5hLy7HTIVHi7dt01/ue/HUGZMwa/WH3jHKYnmWLUZde1aqr5vQMdkg 5K0T05+AJe9byxNnKrEUZyQaajEXFScCAMMob1fwAgAA X-CMS-MailID: 20241203081005epcas2p247b3d05bc767b1a50ba85c4433657295 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20241203081005epcas2p247b3d05bc767b1a50ba85c4433657295 References: X-Patchwork-Delegate: kuba@kernel.org We encountered the following WARNINGs in tcp_sacktag_write_queue()/tcp_fastretrans_alert() which triggered a kernel panic due to panic_on_warn. case 1. ------------[ cut here ]------------ WARNING: CPU: 4 PID: 453 at net/ipv4/tcp_input.c:2026 Call trace: tcp_sacktag_write_queue+0xae8/0xb60 tcp_ack+0x4ec/0x12b8 tcp_rcv_state_process+0x22c/0xd38 tcp_v4_do_rcv+0x220/0x300 tcp_v4_rcv+0xa5c/0xbb4 ip_protocol_deliver_rcu+0x198/0x34c ip_local_deliver_finish+0x94/0xc4 ip_local_deliver+0x74/0x10c ip_rcv+0xa0/0x13c Kernel panic - not syncing: kernel: panic_on_warn set ... case 2. ------------[ cut here ]------------ WARNING: CPU: 0 PID: 648 at net/ipv4/tcp_input.c:3004 Call trace: tcp_fastretrans_alert+0x8ac/0xa74 tcp_ack+0x904/0x12b8 tcp_rcv_state_process+0x22c/0xd38 tcp_v4_do_rcv+0x220/0x300 tcp_v4_rcv+0xa5c/0xbb4 ip_protocol_deliver_rcu+0x198/0x34c ip_local_deliver_finish+0x94/0xc4 ip_local_deliver+0x74/0x10c ip_rcv+0xa0/0x13c Kernel panic - not syncing: kernel: panic_on_warn set ... When we check the socket state value at the time of the issue, it was 0x4. skc_state = 0x4, This is "TCP_FIN_WAIT1" and which means the device closed its socket. enum { TCP_ESTABLISHED = 1, TCP_SYN_SENT, TCP_SYN_RECV, TCP_FIN_WAIT1, And also this means tp->packets_out was initialized as 0 by tcp_write_queue_purge(). In a congested network situation, a TCP ACK for an already closed session may be received with a delay from the peer. This can trigger the WARN_ON macro to help debug the situation. To make this situation more meaningful, we would like to call WARN_ON only when the state of the socket is "TCP_ESTABLISHED". This will prevent the kernel from triggering a panic due to panic_on_warn. Signed-off-by: Youngmin Nam --- net/ipv4/tcp_input.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 5bdf13ac26ef..62f4c285ab80 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -2037,7 +2037,8 @@ tcp_sacktag_write_queue(struct sock *sk, const struct sk_buff *ack_skb, WARN_ON((int)tp->sacked_out < 0); WARN_ON((int)tp->lost_out < 0); WARN_ON((int)tp->retrans_out < 0); - WARN_ON((int)tcp_packets_in_flight(tp) < 0); + if (sk->sk_state == TCP_ESTABLISHED) + WARN_ON((int)tcp_packets_in_flight(tp) < 0); #endif return state->flag; } @@ -3080,7 +3081,8 @@ static void tcp_fastretrans_alert(struct sock *sk, const u32 prior_snd_una, return; /* C. Check consistency of the current state. */ - tcp_verify_left_out(tp); + if (sk->sk_state == TCP_ESTABLISHED) + tcp_verify_left_out(tp); /* D. Check state exit conditions. State can be terminated * when high_seq is ACKed. */