selftests/bpf: Few fixes for selftests/bpf built in release mode
authorAndrii Nakryiko <andrii@kernel.org>
Tue, 16 Aug 2022 00:19:29 +0000 (17:19 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 17 Aug 2022 20:43:58 +0000 (22:43 +0200)
Fix few issues found when building and running test_progs in
release mode.

First, potentially uninitialized idx variable in xskxceiver,
force-initialize to zero to satisfy compiler.

Few instances of defining uprobe trigger functions break in release mode
unless marked as noinline, due to being static. Add noinline to make
sure everything works.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Hao Luo <haoluo@google.com>
Link: https://lore.kernel.org/bpf/20220816001929.369487-5-andrii@kernel.org
tools/testing/selftests/bpf/prog_tests/attach_probe.c
tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
tools/testing/selftests/bpf/prog_tests/task_pt_regs.c
tools/testing/selftests/bpf/xskxceiver.c

index 0b899d2d8ea70fa39e3a171e77536d6ed538790f..9566d9d2f6eebecbd5eda3a3825b8edca3510665 100644 (file)
@@ -6,19 +6,19 @@
 volatile unsigned short uprobe_ref_ctr __attribute__((unused)) __attribute((section(".probes")));
 
 /* uprobe attach point */
-static void trigger_func(void)
+static noinline void trigger_func(void)
 {
        asm volatile ("");
 }
 
 /* attach point for byname uprobe */
-static void trigger_func2(void)
+static noinline void trigger_func2(void)
 {
        asm volatile ("");
 }
 
 /* attach point for byname sleepable uprobe */
-static void trigger_func3(void)
+static noinline void trigger_func3(void)
 {
        asm volatile ("");
 }
index 2974b44f80faf17a16ab6a012dac07ad925a1f6e..2be2d61954bc63f0f77fce9a72aae7885c75c103 100644 (file)
@@ -13,7 +13,7 @@
 #include "kprobe_multi.skel.h"
 
 /* uprobe attach point */
-static void trigger_func(void)
+static noinline void trigger_func(void)
 {
        asm volatile ("");
 }
index 61935e7e056a41725a711ea00c2232f387299dab..f000734a3d1f283639192a92133ed404aa4ff125 100644 (file)
@@ -4,7 +4,7 @@
 #include "test_task_pt_regs.skel.h"
 
 /* uprobe attach point */
-static void trigger_func(void)
+static noinline void trigger_func(void)
 {
        asm volatile ("");
 }
index 20b44ab32a062b4ed1f4fb4732a5e7cb7cfcbd19..14b4737b223c5dad09eec8d4ed50f0fc2934ab0a 100644 (file)
@@ -922,7 +922,7 @@ static int __send_pkts(struct ifobject *ifobject, u32 *pkt_nb, struct pollfd *fd
 {
        struct xsk_socket_info *xsk = ifobject->xsk;
        bool use_poll = ifobject->use_poll;
-       u32 i, idx, ret, valid_pkts = 0;
+       u32 i, idx = 0, ret, valid_pkts = 0;
 
        while (xsk_ring_prod__reserve(&xsk->tx, BATCH_SIZE, &idx) < BATCH_SIZE) {
                if (use_poll) {