From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.91 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796127742; b=h0gUftnqnQWE4yBOAftgCAW4m/n37TaXTUXjwsXnUcFTrW4yNrYyAEPZjXMKB+7C3chs yKaLEhGV/DuNpmlmL7f307fnBtoeiXcxPP7P6KzK9M12AhO/ZYiDSwPOhRjDap3GrFhoM N4pc884FrHjEl2lWGMLFN2sCfEIDLonTOjUKBVrfr1E+SwcdY2MUK+cNxrM3GNxziOJlN PtCbCNM+R3jBAJaRe20nMFY6vd3aL2UFhTxR5/ic7/1CtPqD2vB/TPOP742GINmOFCIB8 ldfu5B0k6c7nwhTFsL7JeiB7tuEjgl0XWUmOz3BFXYj5oRsirlnCV1xGoFP7XmUMTrw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796127742; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=OjdBCZDacleOi4Fgi4Xz+Nz7dmVyt3ezJXHc40OCmEw=; b=ZeX3k6yZ2jxs48bdDPf5IyOEnC91GVbIrsWV36/axPX1lFLG5LmjTsm9eo2/Ih+G3uy0 85/d+MeMPCl1piUPB9WFJr+k+LXL4qfjhKdfm5w6XIkrC7F7LC+hE4YZ/GRxVf2BI+5fX pGRJPvBRHf2ttzfE5XP0aLBacfJ8yW6BEmaBqIlw9RLJPVje2aizftFRcukN7U/aYKTJv 1+yGFCytd4b8XfYvyXuuwflmC6suUVoVmXNuqVFoV5GWYIBiLdwIgnB7Vi53w4J5VYdM9 VnEbptaXobFtPq0ILNDV1UdNXVzbFMbgptbWrTfWeYoeaZ1rk9W5eXA2n9SVe8q1s8g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=cm9uJnc2; arc=none smtp.remote-ip=95.215.58.91 Received: from mta1.migadu.com (out-91.mta1.migadu.com [95.215.58.91]) (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 D7D27606A325 for ; Tue, 1 Dec 2026 12:22:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D7D27606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=cm9uJnc2 X-Envelope-To: linux-kselftest@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=oKTgIWjx3Nw3nvWW4e9C+zwAUUXCEaCJK/f++fgxIas=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796127740; v=1; x=1796732540; b=cm9uJnc2vUn84ekKfCGt8nI/LppPRqVAaaeuHNF9MrnTU3qSEjxHhXX4pqUsW0jrr/fnIvMm pLRNDupepbYlIIV7C4ZD3oBFv0ZDA5hGP0c1Irt8qp6P6/2/oN44EdI8nJDr8Vx3/ee5ZsPS8hP p4avxGqVT9YmbodkDFh9HW9Y= X-Envelope-To: linux-kselftest@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 57770fcca19fded8; Tue, 01 Dec 2026 12:22:19 +0000 X-Mizu-Trace-ID: 57770fcca19fded8 X-Migadu-Flow: FLOW_OUT From: Jiayuan Chen To: bpf@vger.kernel.org Cc: Jiayuan Chen , John Fastabend , Jakub Sitnicki , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Kuniyuki Iwashima , Willem de Bruijn , Neal Cardwell , Andrii Nakryiko , Eduard Zingerman , Ihor Solodrai , Alexei Starovoitov , Daniel Borkmann , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Shuah Khan , Sechang Lim , Michal Luczaj , Mattia Meleleo , Zijian Zhang , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf v2 02/10] selftests/bpf: Add test for unread SK_PASS data with strparser Date: Tue, 1 Dec 2026 20:18:50 +0800 Message-ID: <20261201122055.269577-3-jiayuan.chen@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261201122055.269577-1-jiayuan.chen@linux.dev> References: <20261201122055.269577-1-jiayuan.chen@linux.dev> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Send two packets and wait for each to reach ingress_msg before sending the next, so that the parser runs once per packet with the first one still unread. Read both, then send a third packet and expect it to be delivered. Without the fix the third packet is never read: copied_seq has passed rcv_nxt after the first recv(), so the parser is not woken anymore. Also drop a packet in the verdict test by redirecting to an empty slot, and expect the next packet to be delivered. Signed-off-by: Jiayuan Chen --- .../selftests/bpf/prog_tests/sockmap_strp.c | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_strp.c b/tools/testing/selftests/bpf/prog_tests/sockmap_strp.c index 1d7231728eafd..56832db867107 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_strp.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_strp.c @@ -364,6 +364,89 @@ static void test_sockmap_strp_pass(int family, int sotype, bool fionread) test_sockmap_strp__destroy(strp); } +static int sockmap_strp_wait_fionread(int fd, int expected) +{ + int err, avail = 0; + + /* No limit on the loop, test_progs has its own watchdog */ + while (1) { + err = ioctl(fd, FIONREAD, &avail); + if (!ASSERT_OK(err, "ioctl(FIONREAD) error")) + return -1; + if (avail >= expected) + break; + usleep(10000); + } + return ASSERT_EQ(avail, expected, "ioctl(FIONREAD)") ? 0 : -1; +} + +/* + * Let the parser run twice before the reader reads anything. Each round + * must keep the SK_PASS bytes of the earlier rounds out of copied_seq, + * otherwise copied_seq runs past rcv_nxt and the stream stalls. + */ +static void test_sockmap_strp_pass_unread(int family, int sotype) +{ + int zero = 0, one = 1, pkt_size = STRP_PKT_FULL_LEN, sent, recvd; + int err, map, i; + int c = -1, p = -1; + struct test_sockmap_strp *strp = NULL; + char rcv[STRP_PKT_FULL_LEN * 2 + 1] = "0"; + + strp = sockmap_strp_init(&map, true, true); + if (!ASSERT_TRUE(strp, "sockmap_strp_init")) + return; + + err = create_pair(family, sotype, &c, &p); + if (err) + goto out; + + err = bpf_map_update_elem(map, &zero, &p, BPF_NOEXIST); + if (!ASSERT_OK(err, "bpf_map_update_elem(p)")) + goto out_close; + + err = setsockopt(c, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one)); + if (!ASSERT_OK(err, "setsockopt(TCP_NODELAY)")) + goto out_close; + + /* + * wait for each packet to reach ingress_msg before sending the + * next one, so that the parser runs once per packet + */ + for (i = 1; i <= 2; i++) { + sent = xsend(c, packet, pkt_size, 0); + if (!ASSERT_EQ(sent, pkt_size, "xsend(c)")) + goto out_close; + if (sockmap_strp_wait_fionread(p, pkt_size * i)) + goto out_close; + } + + recvd = recv_timeout(p, rcv, sizeof(rcv), MSG_DONTWAIT, IO_TIMEOUT_SEC); + if (!ASSERT_EQ(recvd, pkt_size * 2, "recv_timeout(p)") || + !ASSERT_OK(memcmp(packet, rcv, pkt_size), "memcmp, data mismatch") || + !ASSERT_OK(memcmp(packet, rcv + pkt_size, pkt_size), + "memcmp, second data mismatch")) + goto out_close; + + /* the next packet must still wake the parser */ + sent = xsend(c, packet, pkt_size, 0); + if (!ASSERT_EQ(sent, pkt_size, "xsend(c) after read")) + goto out_close; + + recvd = recv_timeout(p, rcv, sizeof(rcv), MSG_DONTWAIT, IO_TIMEOUT_SEC); + if (!ASSERT_EQ(recvd, pkt_size, "recv_timeout(p) after read") || + !ASSERT_OK(memcmp(packet, rcv, pkt_size), + "memcmp, data mismatch after read")) + goto out_close; + +out_close: + close(c); + close(p); + +out: + test_sockmap_strp__destroy(strp); +} + /* Test strparser with verdict mode */ static void test_sockmap_strp_verdict(int family, int sotype) { @@ -422,6 +505,28 @@ static void test_sockmap_strp_verdict(int family, int sotype) "partial received data does not match the sent data")) goto out_close; + /* a redirect to an empty slot is SK_DROP, the next one must pass */ + err = bpf_map_delete_elem(map, &one); + if (!ASSERT_OK(err, "bpf_map_delete_elem(p1)")) + goto out_close; + + sent = xsend(c0, packet, STRP_PKT_FULL_LEN, 0); + if (!ASSERT_EQ(sent, STRP_PKT_FULL_LEN, "dropped xsend(c0)")) + goto out_close; + + err = bpf_map_update_elem(map, &one, &p1, BPF_NOEXIST); + if (!ASSERT_OK(err, "bpf_map_update_elem(p1) again")) + goto out_close; + + sent = xsend(c0, packet, STRP_PKT_FULL_LEN, 0); + if (!ASSERT_EQ(sent, STRP_PKT_FULL_LEN, "xsend(c0) after drop")) + goto out_close; + + recvd = recv_timeout(c1, rcv, sizeof(rcv), MSG_DONTWAIT, + IO_TIMEOUT_SEC); + if (!ASSERT_EQ(recvd, STRP_PKT_FULL_LEN, "recv_timeout(c1) after drop")) + goto out_close; + out_close: close(c0); close(c1); @@ -470,6 +575,10 @@ void test_sockmap_strp(void) test_sockmap_strp_pass(AF_INET, SOCK_STREAM, true); if (test__start_subtest("sockmap strp tcp v6 pass fionread")) test_sockmap_strp_pass(AF_INET6, SOCK_STREAM, true); + if (test__start_subtest("sockmap strp tcp pass unread")) + test_sockmap_strp_pass_unread(AF_INET, SOCK_STREAM); + if (test__start_subtest("sockmap strp tcp v6 pass unread")) + test_sockmap_strp_pass_unread(AF_INET6, SOCK_STREAM); if (test__start_subtest("sockmap strp tcp verdict")) test_sockmap_strp_verdict(AF_INET, SOCK_STREAM); if (test__start_subtest("sockmap strp tcp v6 verdict")) -- 2.43.0