From: Sun Jian <sun.jian.kdev@gmail.com>
To: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, ast@kernel.org,
daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev,
eddyz87@gmail.com, memxor@gmail.com, song@kernel.org,
yonghong.song@linux.dev, jolsa@kernel.org, shuah@kernel.org,
paul.chaignon@gmail.com, Sun Jian <sun.jian.kdev@gmail.com>
Subject: [PATCH bpf 2/2] selftests/bpf: Cover partial copy of non-linear skb test_run output
Date: Mon, 15 Jun 2026 15:38:56 +0800 [thread overview]
Message-ID: <20260615073856.152479-3-sun.jian.kdev@gmail.com> (raw)
In-Reply-To: <20260615073856.152479-1-sun.jian.kdev@gmail.com>
Add a test case for BPF_PROG_TEST_RUN with a non-linear skb and a short
data_out buffer.
The test verifies that test_run returns -ENOSPC, reports the full packet
length through data_size_out, and copies the packet prefix into data_out.
The test uses a 100-byte data_out buffer with a 64-byte linear head, so the
expected output spans both the skb head and the first fragment.
Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
.../selftests/bpf/prog_tests/skb_load_bytes.c | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/skb_load_bytes.c b/tools/testing/selftests/bpf/prog_tests/skb_load_bytes.c
index d7f83c0a40a5..134be0ea8ed7 100644
--- a/tools/testing/selftests/bpf/prog_tests/skb_load_bytes.c
+++ b/tools/testing/selftests/bpf/prog_tests/skb_load_bytes.c
@@ -3,6 +3,39 @@
#include <network_helpers.h>
#include "skb_load_bytes.skel.h"
+#define NONLINEAR_PKT_LEN 9000
+#define NONLINEAR_HEAD_LEN 64
+#define SHORT_OUT_LEN 100
+
+static void test_nonlinear_data_out_partial(int prog_fd)
+{
+ LIBBPF_OPTS(bpf_test_run_opts, tattr);
+ __u8 pkt[NONLINEAR_PKT_LEN];
+ __u8 out[SHORT_OUT_LEN];
+ struct __sk_buff skb = {};
+ int err, i;
+
+ for (i = 0; i < sizeof(pkt); i++)
+ pkt[i] = i & 0xff;
+
+ memset(out, 0xa5, sizeof(out));
+
+ skb.data_end = NONLINEAR_HEAD_LEN;
+
+ tattr.data_in = pkt;
+ tattr.data_size_in = sizeof(pkt);
+ tattr.data_out = out;
+ tattr.data_size_out = sizeof(out);
+ tattr.ctx_in = &skb;
+ tattr.ctx_size_in = sizeof(skb);
+
+ err = bpf_prog_test_run_opts(prog_fd, &tattr);
+
+ ASSERT_EQ(err, -ENOSPC, "nonlinear_partial_err");
+ ASSERT_EQ(tattr.data_size_out, sizeof(pkt), "nonlinear_partial_data_size_out");
+ ASSERT_OK(memcmp(out, pkt, sizeof(out)), "nonlinear_partial_data_out");
+}
+
void test_skb_load_bytes(void)
{
struct skb_load_bytes *skel;
@@ -40,6 +73,8 @@ void test_skb_load_bytes(void)
if (!ASSERT_EQ(test_result, 0, "offset 10"))
goto out;
+ test_nonlinear_data_out_partial(prog_fd);
+
out:
skb_load_bytes__destroy(skel);
}
--
2.43.0
prev parent reply other threads:[~2026-06-15 7:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 7:38 [PATCH bpf 0/2] Fix partial copy of non-linear skb test_run output Sun Jian
2026-06-15 7:38 ` [PATCH bpf 1/2] bpf: " Sun Jian
2026-06-15 7:38 ` Sun Jian [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260615073856.152479-3-sun.jian.kdev@gmail.com \
--to=sun.jian.kdev@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=paul.chaignon@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox