]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
selftests/bpf: Fix the missing tramp_1 to tramp_40 ops in cfi_stubs
authorMartin KaFai Lau <martin.lau@kernel.org>
Mon, 22 Jul 2024 18:30:46 +0000 (11:30 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 29 Jul 2024 20:08:56 +0000 (13:08 -0700)
The tramp_1 to tramp_40 ops is not set in the cfi_stubs in the
bpf_testmod_ops. It fails the struct_ops_multi_pages test after
retiring the unsupported_ops in the earlier patch.

This patch initializes them in a loop during the bpf_testmod_init().

Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20240722183049.2254692-3-martin.lau@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c

index fd28c1157bd3d0f146f417728dc753790dd170ec..3687a40b61c635cae203d592e5b9b5f25d933055 100644 (file)
@@ -1024,6 +1024,11 @@ static void bpf_testmod_test_2(int a, int b)
 {
 }
 
+static int bpf_testmod_tramp(int value)
+{
+       return 0;
+}
+
 static int bpf_testmod_ops__test_maybe_null(int dummy,
                                            struct task_struct *task__nullable)
 {
@@ -1080,6 +1085,7 @@ static int bpf_testmod_init(void)
                        .kfunc_btf_id   = bpf_testmod_dtor_ids[1]
                },
        };
+       void **tramp;
        int ret;
 
        ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_UNSPEC, &bpf_testmod_common_kfunc_set);
@@ -1103,6 +1109,14 @@ static int bpf_testmod_init(void)
        ret = register_bpf_testmod_uprobe();
        if (ret < 0)
                return ret;
+
+       /* Ensure nothing is between tramp_1..tramp_40 */
+       BUILD_BUG_ON(offsetof(struct bpf_testmod_ops, tramp_1) + 40 * sizeof(long) !=
+                    offsetofend(struct bpf_testmod_ops, tramp_40));
+       tramp = (void **)&__bpf_testmod_ops.tramp_1;
+       while (tramp <= (void **)&__bpf_testmod_ops.tramp_40)
+               *tramp++ = bpf_testmod_tramp;
+
        return 0;
 }