Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.231.130 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796100229; b=FHJtG6iCjhbfUGTHjsqNbFUazgpUJMOW1pxWyN3qL2EvLlu6IaTst3hFwflGL4iCsqQO 7E+Wrv1blq3gey5DHXI6Fi+rLNXNtb/PazmGpvALpFOH2xjRiRYkGBwmdbHpS5cktRM8R hrLIhjladSWZ7Q34zFpmy9bufYSiIdgeg2eJfp6rwfyKgOVjZamPdJ2XbY5a4xYHqA4Jy pzCPsHqiB+UG/8YLJ0mHdANR5zrASKj2atwoW8lsMuEKo1XToo5M6a7cnAmUdjD0DqDSO ueJn5D2WhMAR/RhOA70Sl7f688GncTczkpgup3s3WLYihscmG5Z4O6DhS9G/EtC8HFw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796100229; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: X-Developer-Signature:X-Developer-Key:Content-Transfer-Encoding; bh=TRP24cUhYVUemFhXIwCHRliGPhQFvLYgnIIn5ub50qg=; b=DkxEpTDbVRoNuqrp7hjTQslQy0xORnVF8SrU0lhBp9xs1RXYxcGfn+HXsJu1+6yThz9b l4wKKL4sMyI4nJP79HLjJ1WA0XIZrhDAMzZRyekSNvJCOCEfCxw/Ek14a09VDOVsuVMus wGXhC/39c2dXEo92vQiQ2ySEHahjwF1sA8VuB01pITDn5dLjIISiMCB0AUHetk1gCcSZ0 O/ZKcfZjTquQRo0rOYsruzB2VQEDHuk3mk6B5PZf1xQAg9+ZuhcA2Z/np9+2aUbmiUona n2Asv0sEAtFzCSxikrMjpqEwddweTv8h8LGZs9lCHodrf8sX8KsnTWFKUZdumT4FWlg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=CFzl5JrS; arc=none smtp.remote-ip=74.125.231.130 Received: from mail-oo2-f2.google.com (mail-oo2-f2.google.com [74.125.231.130]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BEB3606A320 for ; Tue, 1 Dec 2026 04:43:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1BEB3606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=CFzl5JrS Received: by mail-oo2-f2.google.com with SMTP id 46e09a7af769-862a50e0f92so1883373a34.1 for ; Mon, 30 Nov 2026 20:43:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796100228; x=1796705028; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TRP24cUhYVUemFhXIwCHRliGPhQFvLYgnIIn5ub50qg=; b=CFzl5JrSRJOYq2kc7KaifQ8QtbDhX7orZOIto+F2bfZ2Ww1zW7+vQp6vKLW9r6wsxY rge/9QSgz6ScPVAbNlE8TB3HXKWEqMWAyayfa/gbfZMUJ4BqSq215dTxFD0fcxobmhz0 YSO2mdR2Gr0lnO4SBXg7TknrFJdGgnXS3E/w1Gf5fb/tLGyF1lE1Q8XJTI3rSvxiVJGq lwVRawbu1xm3imsOdgB58uDuzX82HP2FnN/dkqt3v9qlJJwXkOwjB/57k6/Nc+LoliP2 J9GwhpdyHoC8RDf6IM3+/O25+jm3CoK5xvvSjDGjuOV3y5YDerA16qXeYdz7gZa4YIiC LKqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796100228; x=1796705028; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=TRP24cUhYVUemFhXIwCHRliGPhQFvLYgnIIn5ub50qg=; b=z9E360UPv5WnqxngVTRHvvdA6AAjDdLMJ2cZ/VOcPimwnOA7AzEzCeZYvL7Oa8QLQv fwguJKQLeBeR5qn20fp/WnVzyVxz0cRDsiN72DxaZStjZk2WNYOZW4CVfogyuVZsEO/F w1R4m4fz2DvUHgCmgs+BuocuKxR8ilKUsRou+LNMw/rZKJI8s/+A3a3uJO0EDbolxQU4 u9rolwU9K3pMBhCDXwntBj7t0zERbsVEUUYroCc5IlqoIhWZIlGQ+WI8I1XzNF7V9Get 7vlLeLIm+b09KKUAs8EGERr/dctq0uRY2DzXfxH126amHJ2BSQY8GP/g5VdKQ1rqithJ UUtA== X-Gm-Message-State: APuU4Z8jwCPhx0jzJwXQDo598tTXzgDlxwiA8aXxU6P2e1mGkFuawZFN RzH7bjfd39QsMzTezL5wc+cvHtMRLOfwRi4pakX3BVXSRvKMxHQMgKj9+I98yVxnVFU= X-Gm-Gg: AZFdTZeAX3CszozhM9d/xM7QYQauuU7E8cqmqhKGidS4UVlDgWNTAZt7L7zzZp2aNwI hxtwCvvydTihv20fup+SyDviAzp2rbT1msEq5ajH4m4Bb0Pdfaw2Mk/gTmmsH/J6zghbmiIUoG6 tjB2HQcQQO/FTjydEJ/G8xil48vCIE8swkPuGCxCtBXRHBNPwmQoN6iXqaaUi4LqTDUnRtHFW5I vEYzbVwkMemFVweGY/Dpu9jQl6BSQNtWzDNxJwMnP+bF9wDjuHTqssspqgr9G/27TtD2289Fx1o RYwq+zVYuKKPte+P08c/dVXXWpB5AFnqlTxIWfHNoKcAzAshAppZmm1udktDz8IVhHgv2sk4xXu 4cqZ4Y/NwWBrp9kEMcLNp45bNDsB15jQFxuIdWxV5DLg3ezd6c+0x5NbtJzyGCDLeLAxcJHrHnO pRkQcAqltgnZbYCTimJfab2fYnR1HQFJGgj61G6mVRU8GXyjo9e7pG2EyDUHqym7JJUz3w56Ycz ssJU+PY9arGb8UZ0l6hZuiY0W8322mFyCfNsHClRXIx7uAOorl6cGkkQxLeGaApN1DmnH+EE1ZE gUt1+L1bSv5PSNINlNIv5CF/9UJhXECS7dTRSZOe7nDyqz4jjiVJHZmbLIBrUVgQtzUzQ5VGh29 UsQE22ZYqV10yst/RvemwWmf7I8F80Ylq2FQZ X-Received: by 2002:a05:6830:4119:b0:862:f05c:2fd with SMTP id 46e09a7af769-863152c5e83mr37695846a34.3.1796100228097; Mon, 30 Nov 2026 20:43:48 -0800 (PST) Received: from localhost ([2a03:2880:10ff:54::]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863c11a7b3esm3282477a34.13.2026.11.30.20.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 20:43:46 -0800 (PST) From: Kumar Kartikeya Dwivedi To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eduard Zingerman , Emil Tsalapatis , Ihor Solodrai , kkd@meta.com, kernel-team@meta.com Subject: [PATCH bpf-next v1 72/73] bpf: Give cancelled tcp_congestion_ops programs values that TCP can take Date: Tue, 1 Dec 2026 05:39:39 +0100 Message-ID: X-Mailer: git-send-email 2.53.1 In-Reply-To: References: X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4131; h=from:subject:message-id; bh=vPDKTi/XQUr6sT67/zPlwHozRxokC+as7B13btBETKk=; b=owGbwMvMwCXmrmtenRyi38x4Wi2JIZvPb8mUtoXcQWxrH+89xx07aZb1td5nt7/NsjgTvC/RTEsu 6g5nRykLgxgXg6yYIkvJ/31MxicqfwfaLuOGmcPKBDKEgYtTACaSacHIcHOqoHmOk1Vsj4P6Q+nPnt dk5i1fwLVcKzT0Q8opuZgDqxkZZmitnxa1Y1JnujOH0dWjiW9TJxlY6AvtfnuAf5Nk/0ZVBgA= X-Developer-Key: i=memxor@gmail.com; a=openpgp; fpr=B34BD741DE8494B76E2F717880EF20021D46C59B Content-Transfer-Encoding: 8bit Currently a cancelled program of tcp_congestion_ops returns 0, and TCP cannot take 0 from every member. A congestion control that is reno, built from the kfuncs of the kernel, shows it on a connection over loopback when the kernel cancels one of its programs: - ->undo_cwnd() returns the window for a loss that TCP takes back. The window becomes 0, and tcp_snd_cwnd_set() warns. - ->ssthresh() returns the slow start threshold. When the recovery is over, TCP sets the window to it, and the same warning fires. Then ->cong_avoid() of the program calls tcp_reno_cong_avoid(), and tcp_cong_avoid_ai() divides by the window: Oops: divide error: 0000 [#1] SMP RIP: 0010:tcp_cong_avoid_ai+0x50/0x90 - ->sndbuf_expand() returns the factor by which TCP sizes the send buffer. With 0 the buffer keeps its first size, 16384 bytes where the same connection with reno has 2626560. Implement ->cancelled_retval() for tcp_congestion_ops. The value is a constant in the program, and the value that fits is in the socket. No constant is right, so give each member the least value that TCP can work with: ->ssthresh() 2 the least that tcp_reno_ssthresh() returns ->undo_cwnd() 1 the window that TCP itself sets after a timeout ->tso_segs() 1 what tcp_tso_segs() makes of 0 today ->sndbuf_expand() 2 the factor that TCP uses when the member is not set The price is a slow connection. After a cancelled ->undo_cwnd() it continues with a window of one segment, and after a cancelled ->ssthresh() the recovery ends with a window of two. The other programs of the congestion control grow the window again if they still run. The values do not apply to bpf_throw(), whose cookie is what the program returns. A program that returns 0 from these members that way, or with its own return, has a bug of its own. The other members return nothing. No program can implement ->get_info(). Signed-off-by: Kumar Kartikeya Dwivedi --- net/ipv4/bpf_tcp_ca.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/net/ipv4/bpf_tcp_ca.c b/net/ipv4/bpf_tcp_ca.c index 2a71dc81562f..4b9ea3058b6f 100644 --- a/net/ipv4/bpf_tcp_ca.c +++ b/net/ipv4/bpf_tcp_ca.c @@ -256,6 +256,36 @@ static int bpf_tcp_ca_validate(void *kdata) return tcp_validate_congestion_control(kdata); } +/* What a program returns when the kernel cancels it, which ends the program + * early, for example at a loop that runs out of time. The value is a constant, + * and TCP cannot take 0 from every program, so each one returns the least + * value that TCP can work with: + * + * ->ssthresh() 2, the least that tcp_reno_ssthresh() returns. With 0 + * the window is 0 when a recovery is over, and + * tcp_cong_avoid_ai() divides by the window. + * ->undo_cwnd() 1, the window that TCP itself sets after a timeout. + * ->tso_segs() 1, which is what tcp_tso_segs() makes of 0. + * ->sndbuf_expand() 2, the factor that tcp_sndbuf_expand() uses without + * this callback. With 0 the send buffer does not grow. + * + * The other programs return nothing, and no program can be ->get_info(). + */ +static int bpf_tcp_ca_cancelled_retval(const struct bpf_prog *prog) +{ + switch (prog->aux->attach_st_ops_member_off) { + case offsetof(struct tcp_congestion_ops, ssthresh): + return 2; + case offsetof(struct tcp_congestion_ops, undo_cwnd): + return 1; + case offsetof(struct tcp_congestion_ops, tso_segs): + return 1; + case offsetof(struct tcp_congestion_ops, sndbuf_expand): + return 2; + } + return 0; +} + static u32 bpf_tcp_ca_ssthresh(struct sock *sk) { return 0; @@ -338,6 +368,7 @@ static struct bpf_struct_ops bpf_tcp_congestion_ops = { .init_member = bpf_tcp_ca_init_member, .init = bpf_tcp_ca_init, .validate = bpf_tcp_ca_validate, + .cancelled_retval = bpf_tcp_ca_cancelled_retval, .name = "tcp_congestion_ops", .cfi_stubs = &__bpf_ops_tcp_congestion_ops, /* The struct_ops's function may switch to another struct_ops. -- 2.53.1-Meta