Skip to contentSkip to conversation

libbpf: Move BPF_SEQ_PRINTF and BPF_SNPRINTF to bpf_helpers.h

PATCH Superseded Florent Revest 3 participants 8 messages May 25, 2021 – May 26, 2021

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libbpf: Move BPF_SEQ_PRINTF and BPF_SNPRINTF to bpf_helpers.h

These macros are convenient wrappers around the bpf_seq_printf and bpf_snprintf helpers. They are currently provided by bpf_tracing.h which targets low level tracing primitives. bpf_helpers.h is a better fit.

The __bpf_narg and __bpf_apply macros are needed in both files so provided twice and guarded by ifndefs.

---
 kernel/bpf/preload/iterators/iterators.bpf.c  |  1 -
 tools/lib/bpf/bpf_helpers.h                   | 70 +++++++++++++++++++
 tools/lib/bpf/bpf_tracing.h                   | 62 +++-------------
 .../bpf/progs/bpf_iter_bpf_hash_map.c         |  1 -
 .../selftests/bpf/progs/bpf_iter_bpf_map.c    |  1 -
 .../selftests/bpf/progs/bpf_iter_ipv6_route.c |  1 -
 .../selftests/bpf/progs/bpf_iter_netlink.c    |  1 -
 .../selftests/bpf/progs/bpf_iter_task.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_task_btf.c   |  1 -
 .../selftests/bpf/progs/bpf_iter_task_file.c  |  1 -
 .../selftests/bpf/progs/bpf_iter_task_stack.c |  1 -
 .../selftests/bpf/progs/bpf_iter_task_vma.c   |  1 -
 .../selftests/bpf/progs/bpf_iter_tcp4.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_tcp6.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_udp4.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_udp6.c       |  1 -
 .../selftests/bpf/progs/test_snprintf.c       |  1 -
 17 files changed, 80 insertions(+), 67 deletions(-)
kernel/bpf/preload/iterators/iterators.bpf.c +0 -1
index 52aa7b38e8b8..03af863314ea 100644
@@ -2,7 +2,6 @@
 /* Copyright (c) 2020 Facebook */
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 #include <bpf/bpf_core_read.h>
 
 #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
tools/lib/bpf/bpf_helpers.h +70 -0

74 lines not on this page · raw message

tools/lib/bpf/bpf_tracing.h +10 -52

79 lines not on this page · raw message

tools/testing/selftests/bpf/progs/bpf_iter_bpf_hash_map.c +0 -1
index 6dfce3fd68bc..0aa3cd34cbe3 100644
@@ -2,7 +2,6 @@
 /* Copyright (c) 2020 Facebook */
 #include "bpf_iter.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 
 char _license[] SEC("license") = "GPL";
 
tools/testing/selftests/bpf/progs/bpf_iter_bpf_map.c +0 -1
index b83b5d2e17dc..6c39e86b666f 100644
@@ -2,7 +2,6 @@
 /* Copyright (c) 2020 Facebook */
 #include "bpf_iter.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 
 char _license[] SEC("license") = "GPL";
 
tools/testing/selftests/bpf/progs/bpf_iter_ipv6_route.c +0 -1
index d58d9f1642b5..784a610ce039 100644
@@ -3,7 +3,6 @@
 #include "bpf_iter.h"
 #include "bpf_tracing_net.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 
 char _license[] SEC("license") = "GPL";
 
tools/testing/selftests/bpf/progs/bpf_iter_netlink.c +0 -1
index 95989f4c99b5..a28e51e2dcee 100644
@@ -3,7 +3,6 @@
 #include "bpf_iter.h"
 #include "bpf_tracing_net.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 
 char _license[] SEC("license") = "GPL";
 
tools/testing/selftests/bpf/progs/bpf_iter_task.c +0 -1
index b7f32c160f4e..c86b93f33b32 100644
@@ -2,7 +2,6 @@
 /* Copyright (c) 2020 Facebook */
 #include "bpf_iter.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 
 char _license[] SEC("license") = "GPL";
 
tools/testing/selftests/bpf/progs/bpf_iter_task_btf.c +0 -1
index a1ddc36f13ec..bca8b889cb10 100644
@@ -2,7 +2,6 @@
 /* Copyright (c) 2020, Oracle and/or its affiliates. */
 #include "bpf_iter.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 #include <bpf/bpf_core_read.h>
 
 #include <errno.h>
tools/testing/selftests/bpf/progs/bpf_iter_task_file.c +0 -1
index b2f7c7c5f952..6e7b400888fe 100644
@@ -2,7 +2,6 @@
 /* Copyright (c) 2020 Facebook */
 #include "bpf_iter.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 
 char _license[] SEC("license") = "GPL";
 
tools/testing/selftests/bpf/progs/bpf_iter_task_stack.c +0 -1
index 43c36f5f7649..f2b8167b72a8 100644
@@ -2,7 +2,6 @@
 /* Copyright (c) 2020 Facebook */
 #include "bpf_iter.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 
 char _license[] SEC("license") = "GPL";
 
tools/testing/selftests/bpf/progs/bpf_iter_task_vma.c +0 -1
index 11d1aa37cf11..4ea6a37d1345 100644
@@ -2,7 +2,6 @@
 /* Copyright (c) 2020 Facebook */
 #include "bpf_iter.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 
 char _license[] SEC("license") = "GPL";
 
tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c +0 -1
index 54380c5e1069..2e4775c35414 100644
@@ -3,7 +3,6 @@
 #include "bpf_iter.h"
 #include "bpf_tracing_net.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 #include <bpf/bpf_endian.h>
 
 char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/progs/bpf_iter_tcp6.c +0 -1
index b4fbddfa4e10..943f7bba180e 100644
@@ -3,7 +3,6 @@
 #include "bpf_iter.h"
 #include "bpf_tracing_net.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 #include <bpf/bpf_endian.h>
 
 char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/progs/bpf_iter_udp4.c +0 -1
index f258583afbbd..cf0c485b1ed7 100644
@@ -3,7 +3,6 @@
 #include "bpf_iter.h"
 #include "bpf_tracing_net.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 #include <bpf/bpf_endian.h>
 
 char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/progs/bpf_iter_udp6.c +0 -1
index 65f93bb03f0f..5031e21c433f 100644
@@ -3,7 +3,6 @@
 #include "bpf_iter.h"
 #include "bpf_tracing_net.h"
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 #include <bpf/bpf_endian.h>
 
 char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/progs/test_snprintf.c +0 -1
index e35129bea0a0..e2ad26150f9b 100644
@@ -3,7 +3,6 @@
 
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 
 __u32 pid = 0;
 
Signature · 1 line
2.31.1.818.g46aad6cb9e-goog
maintainer
#1 lore raw
Quoted 9 lines · Florent Revest

These macros are convenient wrappers around the bpf_seq_printf and bpf_snprintf helpers. They are currently provided by bpf_tracing.h which targets low level tracing primitives. bpf_helpers.h is a better fit.

The __bpf_narg and __bpf_apply macros are needed in both files so provided twice and guarded by ifndefs.

Given v1/v2 both target bpf tree in the subject, do you really mean bpf or rather bpf-next?

Thanks,
Daniel

#2 lore raw
Quoted 6 lines · Daniel Borkmann
Quoted 4 lines · Florent Revest

These macros are convenient wrappers around the bpf_seq_printf and bpf_snprintf helpers. They are currently provided by bpf_tracing.h which targets low level tracing primitives. bpf_helpers.h is a better fit.

Quoted 8 lines
Quoted 5 lines

The __bpf_narg and __bpf_apply macros are needed in both files so provided twice and guarded by ifndefs.

Given v1/v2 both target bpf tree in the subject, do you really mean bpf or rather bpf-next?

I don't have a preference, it's up to you :)

On one hand, I see no urgency in fixing this: BPF_SEQ_PRINTF has been in bpf_tracing.h for a while already so it can wait for another kernel release. Applying this to bpf-next would do.
On the other hand, BPF_SNPRINTF hasn't made it to a kernel release yet so we still have a chance to do it right before users start including bpf_tracing.h and we'd break them in the next release. That's why I tagged it as bpf.

The patch applies cleanly on both trees so if you prefer landing it in bpf-next it's fine by me.

#3 lore raw
Quoted 27 lines · Florent Revest
Quoted 6 lines · Daniel Borkmann
Quoted 4 lines · Florent Revest

These macros are convenient wrappers around the bpf_seq_printf and bpf_snprintf helpers. They are currently provided by bpf_tracing.h which targets low level tracing primitives. bpf_helpers.h is a better fit.

Quoted 8 lines
Quoted 5 lines

The __bpf_narg and __bpf_apply macros are needed in both files so provided twice and guarded by ifndefs.

Given v1/v2 both target bpf tree in the subject, do you really mean bpf or rather bpf-next?

I don't have a preference, it's up to you :)

On one hand, I see no urgency in fixing this: BPF_SEQ_PRINTF has been in bpf_tracing.h for a while already so it can wait for another kernel release. Applying this to bpf-next would do.
On the other hand, BPF_SNPRINTF hasn't made it to a kernel release yet so we still have a chance to do it right before users start including bpf_tracing.h and we'd break them in the next release. That's why I tagged it as bpf.

Quoted 2 lines

The patch applies cleanly on both trees so if you prefer landing it in bpf-next it's fine by me.

I think it should go through bpf-next. It's not really a bug fix. And we are not going to break anyone with this move. And libbpf 0.4 is officially released without this change anyway. So, bpf-next.

#4 lore raw
Quoted 29 lines · Andrii Nakryiko
Quoted 27 lines · Florent Revest
Quoted 6 lines · Daniel Borkmann
Quoted 4 lines · Florent Revest

These macros are convenient wrappers around the bpf_seq_printf and bpf_snprintf helpers. They are currently provided by bpf_tracing.h which targets low level tracing primitives. bpf_helpers.h is a better fit.

Quoted 8 lines
Quoted 5 lines

The __bpf_narg and __bpf_apply macros are needed in both files so provided twice and guarded by ifndefs.

Given v1/v2 both target bpf tree in the subject, do you really mean bpf or rather bpf-next?

I don't have a preference, it's up to you :)

On one hand, I see no urgency in fixing this: BPF_SEQ_PRINTF has been in bpf_tracing.h for a while already so it can wait for another kernel release. Applying this to bpf-next would do.
On the other hand, BPF_SNPRINTF hasn't made it to a kernel release yet so we still have a chance to do it right before users start including bpf_tracing.h and we'd break them in the next release. That's why I tagged it as bpf.

Quoted 6 lines
Quoted 2 lines

The patch applies cleanly on both trees so if you prefer landing it in bpf-next it's fine by me.

I think it should go through bpf-next. It's not really a bug fix. And we are not going to break anyone with this move. And libbpf 0.4 is officially released without this change anyway. So, bpf-next.

Sounds good, I'll send a v3 tagged with bpf-next ;)

#5 lore raw
In reply to Florent Revest
Quoted 57 lines · Florent Revest

These macros are convenient wrappers around the bpf_seq_printf and bpf_snprintf helpers. They are currently provided by bpf_tracing.h which targets low level tracing primitives. bpf_helpers.h is a better fit.

The __bpf_narg and __bpf_apply macros are needed in both files so provided twice and guarded by ifndefs.

---
 kernel/bpf/preload/iterators/iterators.bpf.c  |  1 -
 tools/lib/bpf/bpf_helpers.h                   | 70 +++++++++++++++++++
 tools/lib/bpf/bpf_tracing.h                   | 62 +++-------------
 .../bpf/progs/bpf_iter_bpf_hash_map.c         |  1 -
 .../selftests/bpf/progs/bpf_iter_bpf_map.c    |  1 -
 .../selftests/bpf/progs/bpf_iter_ipv6_route.c |  1 -
 .../selftests/bpf/progs/bpf_iter_netlink.c    |  1 -
 .../selftests/bpf/progs/bpf_iter_task.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_task_btf.c   |  1 -
 .../selftests/bpf/progs/bpf_iter_task_file.c  |  1 -
 .../selftests/bpf/progs/bpf_iter_task_stack.c |  1 -
 .../selftests/bpf/progs/bpf_iter_task_vma.c   |  1 -
 .../selftests/bpf/progs/bpf_iter_tcp4.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_tcp6.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_udp4.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_udp6.c       |  1 -
 .../selftests/bpf/progs/test_snprintf.c       |  1 -
 17 files changed, 80 insertions(+), 67 deletions(-)
kernel/bpf/preload/iterators/iterators.bpf.c +0 -1
index 52aa7b38e8b8..03af863314ea 100644
@@ -2,7 +2,6 @@
 /* Copyright (c) 2020 Facebook */
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 #include <bpf/bpf_core_read.h>
 
 #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
tools/lib/bpf/bpf_helpers.h +7 -0
index 9720dc0b4605..68d992b30f26 100644
@@ -158,4 +158,74 @@ enum libbpf_tristate {
 #define __kconfig __attribute__((section(".kconfig")))
 #define __ksym __attribute__((section(".ksyms")))
 
+#ifndef ___bpf_concat
+#define ___bpf_concat(a, b) a ## b
+#endif
+#ifndef ___bpf_apply
+#define ___bpf_apply(fn, n) ___bpf_concat(fn, n)
+#endif
+#ifndef ___bpf_nth

tools/lib/bpf/bpf_helpers.h enum libbpf_tristate { · line 177

Quoted 10 lines
tools/lib/bpf/bpf_helpers.h +10 -0
+#define ___bpf_nth(_, _1, _2, _3, _4, _5, _6, _7, _8, _9, _a, _b, _c, N, ...) N
+#endif
+#ifndef ___bpf_narg
+#define ___bpf_narg(...) \
+       ___bpf_nth(_, ##__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
+#endif
+#ifndef ___bpf_empty
+#define ___bpf_empty(...) \
+       ___bpf_nth(_, ##__VA_ARGS__, N, N, N, N, N, N, N, N, N, N, 0)
+#endif

___bpf_empty doesn't seem to be used, let's remove it for now? Otherwise it looks good.

Quoted 17 lines
tools/lib/bpf/bpf_helpers.h +17 -0
+
+#define ___bpf_fill0(arr, p, x) do {} while (0)
+#define ___bpf_fill1(arr, p, x) arr[p] = x
+#define ___bpf_fill2(arr, p, x, args...) arr[p] = x; ___bpf_fill1(arr, p + 1, args)
+#define ___bpf_fill3(arr, p, x, args...) arr[p] = x; ___bpf_fill2(arr, p + 1, args)
+#define ___bpf_fill4(arr, p, x, args...) arr[p] = x; ___bpf_fill3(arr, p + 1, args)
+#define ___bpf_fill5(arr, p, x, args...) arr[p] = x; ___bpf_fill4(arr, p + 1, args)
+#define ___bpf_fill6(arr, p, x, args...) arr[p] = x; ___bpf_fill5(arr, p + 1, args)
+#define ___bpf_fill7(arr, p, x, args...) arr[p] = x; ___bpf_fill6(arr, p + 1, args)
+#define ___bpf_fill8(arr, p, x, args...) arr[p] = x; ___bpf_fill7(arr, p + 1, args)
+#define ___bpf_fill9(arr, p, x, args...) arr[p] = x; ___bpf_fill8(arr, p + 1, args)
+#define ___bpf_fill10(arr, p, x, args...) arr[p] = x; ___bpf_fill9(arr, p + 1, args)
+#define ___bpf_fill11(arr, p, x, args...) arr[p] = x; ___bpf_fill10(arr, p + 1, args)
+#define ___bpf_fill12(arr, p, x, args...) arr[p] = x; ___bpf_fill11(arr, p + 1, args)
+#define ___bpf_fill(arr, args...) \
+       ___bpf_apply(___bpf_fill, ___bpf_narg(args))(arr, 0, args)
+

[...]

#6 lore raw
Quoted 64 lines · Andrii Nakryiko
Quoted 62 lines · Florent Revest

These macros are convenient wrappers around the bpf_seq_printf and bpf_snprintf helpers. They are currently provided by bpf_tracing.h which targets low level tracing primitives. bpf_helpers.h is a better fit.

The __bpf_narg and __bpf_apply macros are needed in both files so provided twice and guarded by ifndefs.

---
 kernel/bpf/preload/iterators/iterators.bpf.c  |  1 -
 tools/lib/bpf/bpf_helpers.h                   | 70 +++++++++++++++++++
 tools/lib/bpf/bpf_tracing.h                   | 62 +++-------------
 .../bpf/progs/bpf_iter_bpf_hash_map.c         |  1 -
 .../selftests/bpf/progs/bpf_iter_bpf_map.c    |  1 -
 .../selftests/bpf/progs/bpf_iter_ipv6_route.c |  1 -
 .../selftests/bpf/progs/bpf_iter_netlink.c    |  1 -
 .../selftests/bpf/progs/bpf_iter_task.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_task_btf.c   |  1 -
 .../selftests/bpf/progs/bpf_iter_task_file.c  |  1 -
 .../selftests/bpf/progs/bpf_iter_task_stack.c |  1 -
 .../selftests/bpf/progs/bpf_iter_task_vma.c   |  1 -
 .../selftests/bpf/progs/bpf_iter_tcp4.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_tcp6.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_udp4.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_udp6.c       |  1 -
 .../selftests/bpf/progs/test_snprintf.c       |  1 -
 17 files changed, 80 insertions(+), 67 deletions(-)
kernel/bpf/preload/iterators/iterators.bpf.c +0 -1
index 52aa7b38e8b8..03af863314ea 100644
@@ -2,7 +2,6 @@
 /* Copyright (c) 2020 Facebook */
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 #include <bpf/bpf_core_read.h>
 
 #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
tools/lib/bpf/bpf_helpers.h +12 -0
index 9720dc0b4605..68d992b30f26 100644
@@ -158,4 +158,74 @@ enum libbpf_tristate {
 #define __kconfig __attribute__((section(".kconfig")))
 #define __ksym __attribute__((section(".ksyms")))
 
+#ifndef ___bpf_concat
+#define ___bpf_concat(a, b) a ## b
+#endif
+#ifndef ___bpf_apply
+#define ___bpf_apply(fn, n) ___bpf_concat(fn, n)
+#endif
+#ifndef ___bpf_nth
+#define ___bpf_nth(_, _1, _2, _3, _4, _5, _6, _7, _8, _9, _a, _b, _c, N, ...) N
+#endif
+#ifndef ___bpf_narg
+#define ___bpf_narg(...) \
+       ___bpf_nth(_, ##__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
Quoted 8 lines

tools/lib/bpf/bpf_helpers.h enum libbpf_tristate { · line 177

Quoted 5 lines
tools/lib/bpf/bpf_helpers.h +5 -0
+#endif
+#ifndef ___bpf_empty
+#define ___bpf_empty(...) \
+       ___bpf_nth(_, ##__VA_ARGS__, N, N, N, N, N, N, N, N, N, N, 0)
+#endif

___bpf_empty doesn't seem to be used, let's remove it for now? Otherwise it looks good.

Yes it's never been used, I thought it was introduced "just in case" so I kept it around but then I'll remove it from both bpf_helpers.h and bpf_tracing.h

#7 lore raw
Quoted 76 lines · Florent Revest
Quoted 64 lines · Andrii Nakryiko
Quoted 62 lines · Florent Revest

These macros are convenient wrappers around the bpf_seq_printf and bpf_snprintf helpers. They are currently provided by bpf_tracing.h which targets low level tracing primitives. bpf_helpers.h is a better fit.

The __bpf_narg and __bpf_apply macros are needed in both files so provided twice and guarded by ifndefs.

---
 kernel/bpf/preload/iterators/iterators.bpf.c  |  1 -
 tools/lib/bpf/bpf_helpers.h                   | 70 +++++++++++++++++++
 tools/lib/bpf/bpf_tracing.h                   | 62 +++-------------
 .../bpf/progs/bpf_iter_bpf_hash_map.c         |  1 -
 .../selftests/bpf/progs/bpf_iter_bpf_map.c    |  1 -
 .../selftests/bpf/progs/bpf_iter_ipv6_route.c |  1 -
 .../selftests/bpf/progs/bpf_iter_netlink.c    |  1 -
 .../selftests/bpf/progs/bpf_iter_task.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_task_btf.c   |  1 -
 .../selftests/bpf/progs/bpf_iter_task_file.c  |  1 -
 .../selftests/bpf/progs/bpf_iter_task_stack.c |  1 -
 .../selftests/bpf/progs/bpf_iter_task_vma.c   |  1 -
 .../selftests/bpf/progs/bpf_iter_tcp4.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_tcp6.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_udp4.c       |  1 -
 .../selftests/bpf/progs/bpf_iter_udp6.c       |  1 -
 .../selftests/bpf/progs/test_snprintf.c       |  1 -
 17 files changed, 80 insertions(+), 67 deletions(-)
kernel/bpf/preload/iterators/iterators.bpf.c +0 -1
index 52aa7b38e8b8..03af863314ea 100644
@@ -2,7 +2,6 @@
 /* Copyright (c) 2020 Facebook */
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
 #include <bpf/bpf_core_read.h>
 
 #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
tools/lib/bpf/bpf_helpers.h +12 -0
index 9720dc0b4605..68d992b30f26 100644
@@ -158,4 +158,74 @@ enum libbpf_tristate {
 #define __kconfig __attribute__((section(".kconfig")))
 #define __ksym __attribute__((section(".ksyms")))
 
+#ifndef ___bpf_concat
+#define ___bpf_concat(a, b) a ## b
+#endif
+#ifndef ___bpf_apply
+#define ___bpf_apply(fn, n) ___bpf_concat(fn, n)
+#endif
+#ifndef ___bpf_nth
+#define ___bpf_nth(_, _1, _2, _3, _4, _5, _6, _7, _8, _9, _a, _b, _c, N, ...) N
+#endif
+#ifndef ___bpf_narg
+#define ___bpf_narg(...) \
+       ___bpf_nth(_, ##__VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
Quoted 8 lines

tools/lib/bpf/bpf_helpers.h enum libbpf_tristate { · line 177

Quoted 5 lines
tools/lib/bpf/bpf_helpers.h +5 -0
+#endif
+#ifndef ___bpf_empty
+#define ___bpf_empty(...) \
+       ___bpf_nth(_, ##__VA_ARGS__, N, N, N, N, N, N, N, N, N, N, 0)
+#endif

___bpf_empty doesn't seem to be used, let's remove it for now? Otherwise it looks good.

Quoted 3 lines

Yes it's never been used, I thought it was introduced "just in case" so I kept it around but then I'll remove it from both bpf_helpers.h and bpf_tracing.h

Oh, I didn't realize it's not used in bpf_tracing.h as well. I think it was used at some point, but probably some subsequent macro refactorings got rid of it.