Skip to content

Commit 67c619c

Browse files
bpf: use bpf_core_enum_value_exists() for HAVE_SET_RETVAL
Avoid probing in the agent, and do the feature detection straight from BPF. Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
1 parent 8737697 commit 67c619c

7 files changed

Lines changed: 8 additions & 14 deletions

File tree

bpf/complexity-tests/61/bpf_sock/1.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
-DHAVE_SET_RETVAL=1
21
-DSKIP_DEBUG=1
32
-DENABLE_IPV4=1
43
-DENABLE_IPV6=1

bpf/complexity-tests/61/bpf_sock/2.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
-DHAVE_SET_RETVAL=1
21
-DSKIP_DEBUG=1
32
-DENABLE_IPV4=1
43
-DENABLE_IPV6=1

bpf/complexity-tests/netnext/bpf_sock/1.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
-DHAVE_SET_RETVAL=1
21
-DSKIP_DEBUG=1
32
-DENABLE_IPV4=1
43
-DENABLE_IPV6=1

bpf/complexity-tests/netnext/bpf_sock/2.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
-DHAVE_SET_RETVAL=1
21
-DSKIP_DEBUG=1
32
-DENABLE_IPV4=1
43
-DENABLE_IPV6=1

bpf/include/bpf/builtins.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,6 @@ static __always_inline __nobuiltin("memmove") void memmove(void *d,
552552
{
553553
return __bpf_memmove(d, s, len);
554554
}
555+
556+
#define bpf_core_enum_value_exists(enum_type, enum_value) \
557+
__builtin_preserve_enum_value(*(typeof(enum_type) *)enum_value, 0)

bpf/include/bpf/helpers.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/bpf.h>
77

88
#include "ctx/ctx.h"
9+
#include "builtins.h"
910
#include "compiler.h"
1011

1112
#ifndef BPF_FUNC
@@ -107,11 +108,10 @@ static int BPF_FUNC(set_retval, int retval);
107108

108109
static inline int try_set_retval(int retval __maybe_unused)
109110
{
110-
#ifdef HAVE_SET_RETVAL
111-
return set_retval(retval);
112-
#else
111+
if (bpf_core_enum_value_exists(enum bpf_func_id, BPF_FUNC_set_retval))
112+
return set_retval(retval);
113+
113114
return 0;
114-
#endif
115115
}
116116

117117
static long BPF_FUNC(loop, __u32 nr_loops, void *callback_fn, void *callback_ctx, __u64 flags);

pkg/datapath/linux/probes/probes.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,6 @@ func ExecuteHeaderProbes(logger *slog.Logger) *FeatureProbes {
700700
}
701701

702702
progHelpers := []ProgramHelper{
703-
// common probes
704-
{ebpf.CGroupSock, asm.FnSetRetval},
705-
706703
// xdp related probes
707704
{ebpf.XDP, asm.FnXdpGetBuffLen},
708705
{ebpf.XDP, asm.FnXdpLoadBytes},
@@ -717,9 +714,7 @@ func ExecuteHeaderProbes(logger *slog.Logger) *FeatureProbes {
717714

718715
// writeCommonHeader defines macross for bpf/include/bpf/features.h
719716
func writeCommonHeader(writer io.Writer, probes *FeatureProbes) error {
720-
features := map[string]bool{
721-
"HAVE_SET_RETVAL": probes.ProgramHelpers[ProgramHelper{ebpf.CGroupSock, asm.FnSetRetval}],
722-
}
717+
features := map[string]bool{}
723718

724719
return writeFeatureHeader(writer, features, true)
725720
}

0 commit comments

Comments
 (0)