Skip to content

Commit 4d33dc1

Browse files
Saket Kumar Bhaskaranakryiko
Saket Kumar Bhaskar
authored andcommitted
selftests/bpf: Fix fill_link_info selftest on powerpc
With CONFIG_KPROBES_ON_FTRACE enabled on powerpc, ftrace_location_range returns ftrace location for bpf_fentry_test1 at offset of 4 bytes from function entry. This is because branch to _mcount function is at offset of 4 bytes in function profile sequence. To fix this, add entry_offset of 4 bytes while verifying the address for kprobe entry address of bpf_fentry_test1 in verify_perf_link_info in selftest, when CONFIG_KPROBES_ON_FTRACE is enabled. Disassemble of bpf_fentry_test1: c000000000e4b080 <bpf_fentry_test1>: c000000000e4b080: a6 02 08 7c mflr r0 c000000000e4b084: b9 e2 22 4b bl c00000000007933c <_mcount> c000000000e4b088: 01 00 63 38 addi r3,r3,1 c000000000e4b08c: b4 07 63 7c extsw r3,r3 c000000000e4b090: 20 00 80 4e blr When CONFIG_PPC_FTRACE_OUT_OF_LINE [1] is enabled, these function profile sequence is moved out of line with an unconditional branch at offset 0. So, the test works without altering the offset for 'CONFIG_KPROBES_ON_FTRACE && CONFIG_PPC_FTRACE_OUT_OF_LINE' case. Disassemble of bpf_fentry_test1: c000000000f95190 <bpf_fentry_test1>: c000000000f95190: 00 00 00 60 nop c000000000f95194: 01 00 63 38 addi r3,r3,1 c000000000f95198: b4 07 63 7c extsw r3,r3 c000000000f9519c: 20 00 80 4e blr [1] https://lore.kernel.org/all/[email protected]/ Fixes: 23cf7aa ("selftests/bpf: Add selftest for fill_link_info") Signed-off-by: Saket Kumar Bhaskar <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 82c1f13 commit 4d33dc1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

tools/testing/selftests/bpf/prog_tests/fill_link_info.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ static void test_kprobe_fill_link_info(struct test_fill_link_info *skel,
171171
/* See also arch_adjust_kprobe_addr(). */
172172
if (skel->kconfig->CONFIG_X86_KERNEL_IBT)
173173
entry_offset = 4;
174+
if (skel->kconfig->CONFIG_PPC64 &&
175+
skel->kconfig->CONFIG_KPROBES_ON_FTRACE &&
176+
!skel->kconfig->CONFIG_PPC_FTRACE_OUT_OF_LINE)
177+
entry_offset = 4;
174178
err = verify_perf_link_info(link_fd, type, kprobe_addr, 0, entry_offset);
175179
ASSERT_OK(err, "verify_perf_link_info");
176180
} else {

tools/testing/selftests/bpf/progs/test_fill_link_info.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
#include <stdbool.h>
77

88
extern bool CONFIG_X86_KERNEL_IBT __kconfig __weak;
9+
extern bool CONFIG_PPC_FTRACE_OUT_OF_LINE __kconfig __weak;
10+
extern bool CONFIG_KPROBES_ON_FTRACE __kconfig __weak;
11+
extern bool CONFIG_PPC64 __kconfig __weak;
912

10-
/* This function is here to have CONFIG_X86_KERNEL_IBT
11-
* used and added to object BTF.
13+
/* This function is here to have CONFIG_X86_KERNEL_IBT,
14+
* CONFIG_PPC_FTRACE_OUT_OF_LINE, CONFIG_KPROBES_ON_FTRACE,
15+
* CONFIG_PPC6 used and added to object BTF.
1216
*/
1317
int unused(void)
1418
{
15-
return CONFIG_X86_KERNEL_IBT ? 0 : 1;
19+
return CONFIG_X86_KERNEL_IBT ||
20+
CONFIG_PPC_FTRACE_OUT_OF_LINE ||
21+
CONFIG_KPROBES_ON_FTRACE ||
22+
CONFIG_PPC64 ? 0 : 1;
1623
}
1724

1825
SEC("kprobe")

0 commit comments

Comments
 (0)