Skip to content

Commit af8d27b

Browse files
olsajirianakryiko
authored andcommitted
selftests/bpf: Mark uprobe trigger functions with nocf_check attribute
Some distros seem to enable the -fcf-protection=branch by default, which breaks our setup on first instruction of uprobe trigger functions and place there endbr64 instruction. Marking them with nocf_check attribute to skip that. Ignoring unknown attribute warning in gcc for bench objects, because nocf_check can be used only when -fcf-protection=branch is enabled, otherwise we get a warning and break compilation. Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 1684d6e commit af8d27b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

tools/include/linux/compiler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
#define noinline
5959
#endif
6060

61+
#ifndef __nocf_check
62+
#define __nocf_check __attribute__((nocf_check))
63+
#endif
64+
6165
/* Are two types/vars the same type (ignoring qualifiers)? */
6266
#ifndef __same_type
6367
# define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))

tools/testing/selftests/bpf/benchs/bench_trigger.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* adjust slot shift in inc_hits() if changing */
1010
#define MAX_BUCKETS 256
1111

12+
#pragma GCC diagnostic ignored "-Wattributes"
13+
1214
/* BPF triggering benchmarks */
1315
static struct trigger_ctx {
1416
struct trigger_bench *skel;
@@ -167,7 +169,7 @@ static void trigger_fmodret_setup(void)
167169
* GCC doesn't generate stack setup preample for these functions due to them
168170
* having no input arguments and doing nothing in the body.
169171
*/
170-
__weak void uprobe_target_nop(void)
172+
__nocf_check __weak void uprobe_target_nop(void)
171173
{
172174
asm volatile ("nop");
173175
}
@@ -176,7 +178,7 @@ __weak void opaque_noop_func(void)
176178
{
177179
}
178180

179-
__weak int uprobe_target_push(void)
181+
__nocf_check __weak int uprobe_target_push(void)
180182
{
181183
/* overhead of function call is negligible compared to uprobe
182184
* triggering, so this shouldn't affect benchmark results much
@@ -185,7 +187,7 @@ __weak int uprobe_target_push(void)
185187
return 1;
186188
}
187189

188-
__weak void uprobe_target_ret(void)
190+
__nocf_check __weak void uprobe_target_ret(void)
189191
{
190192
asm volatile ("");
191193
}

0 commit comments

Comments
 (0)