]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Reorder bpf_prog_test_run_skb initialization
authorPaul Chaignon <paul.chaignon@gmail.com>
Thu, 9 Oct 2025 20:11:22 +0000 (22:11 +0200)
committerMartin KaFai Lau <martin.lau@kernel.org>
Fri, 10 Oct 2025 17:43:03 +0000 (10:43 -0700)
This patch reorders the initialization of bpf_prog_test_run_skb to
simplify the subsequent patch. Program types are checked first, followed
by the ctx init, and finally the data init. With the subsequent patch,
program types and the ctx init provide information that is used in the
data init. Thus, we need the data init to happen last.

Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/063475176f15828a882c07846017394baf72f682.1760037899.git.paul.chaignon@gmail.com
net/bpf/test_run.c

index a39b26739a1ef9a0c6b73b6332678d7ce53077ec..b9b49d0c70146220c84f89cb3d45d8890c8cd46d 100644 (file)
@@ -1004,19 +1004,6 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
        if (size < ETH_HLEN)
                return -EINVAL;
 
-       data = bpf_test_init(kattr, kattr->test.data_size_in,
-                            size, NET_SKB_PAD + NET_IP_ALIGN,
-                            SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
-       if (IS_ERR(data))
-               return PTR_ERR(data);
-
-       ctx = bpf_ctx_init(kattr, sizeof(struct __sk_buff));
-       if (IS_ERR(ctx)) {
-               ret = PTR_ERR(ctx);
-               ctx = NULL;
-               goto out;
-       }
-
        switch (prog->type) {
        case BPF_PROG_TYPE_SCHED_CLS:
        case BPF_PROG_TYPE_SCHED_ACT:
@@ -1032,6 +1019,19 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
                break;
        }
 
+       ctx = bpf_ctx_init(kattr, sizeof(struct __sk_buff));
+       if (IS_ERR(ctx))
+               return PTR_ERR(ctx);
+
+       data = bpf_test_init(kattr, kattr->test.data_size_in,
+                            size, NET_SKB_PAD + NET_IP_ALIGN,
+                            SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
+       if (IS_ERR(data)) {
+               ret = PTR_ERR(data);
+               data = NULL;
+               goto out;
+       }
+
        sk = sk_alloc(net, AF_UNSPEC, GFP_USER, &bpf_dummy_proto, 1);
        if (!sk) {
                ret = -ENOMEM;