* [PATCH bpf-next 1/4] bpf: fix a comment describing bpf_attr
2025-03-31 8:13 [PATCH bpf-next 0/4] likely/unlikely for bpf_helpers Anton Protopopov
@ 2025-03-31 8:13 ` Anton Protopopov
2025-03-31 8:13 ` [PATCH bpf-next 2/4] selftests/bpf: add guard macros around likely/unlikely Anton Protopopov
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Anton Protopopov @ 2025-03-31 8:13 UTC (permalink / raw)
To: bpf; +Cc: Andrii Nakryiko, Anton Protopopov
The map_fd field of the bpf_attr union is used in the BPF_MAP_FREEZE
syscall. Explicitly mention this in the comments.
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
include/uapi/linux/bpf.h | 2 +-
tools/include/uapi/linux/bpf.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 661de2444965..1388db053d9e 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1506,7 +1506,7 @@ union bpf_attr {
__s32 map_token_fd;
};
- struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
+ struct { /* anonymous struct used by BPF_MAP_*_ELEM and BPF_MAP_FREEZE commands */
__u32 map_fd;
__aligned_u64 key;
union {
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 661de2444965..1388db053d9e 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1506,7 +1506,7 @@ union bpf_attr {
__s32 map_token_fd;
};
- struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
+ struct { /* anonymous struct used by BPF_MAP_*_ELEM and BPF_MAP_FREEZE commands */
__u32 map_fd;
__aligned_u64 key;
union {
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH bpf-next 2/4] selftests/bpf: add guard macros around likely/unlikely
2025-03-31 8:13 [PATCH bpf-next 0/4] likely/unlikely for bpf_helpers Anton Protopopov
2025-03-31 8:13 ` [PATCH bpf-next 1/4] bpf: fix a comment describing bpf_attr Anton Protopopov
@ 2025-03-31 8:13 ` Anton Protopopov
2025-03-31 8:13 ` [PATCH bpf-next 3/4] libbpf: add likely/unlikely macros Anton Protopopov
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Anton Protopopov @ 2025-03-31 8:13 UTC (permalink / raw)
To: bpf; +Cc: Andrii Nakryiko, Anton Protopopov
Add guard macros around likely/unlikely definitions such that, if defined
previously, the compilation doesn't break. (Those macros, actually,
will be defined in libbpf in a consequent commit.)
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
tools/testing/selftests/bpf/bpf_arena_spin_lock.h | 5 +++++
tools/testing/selftests/bpf/progs/iters.c | 2 ++
2 files changed, 7 insertions(+)
diff --git a/tools/testing/selftests/bpf/bpf_arena_spin_lock.h b/tools/testing/selftests/bpf/bpf_arena_spin_lock.h
index fb8dc0768999..d60d899dd9da 100644
--- a/tools/testing/selftests/bpf/bpf_arena_spin_lock.h
+++ b/tools/testing/selftests/bpf/bpf_arena_spin_lock.h
@@ -95,8 +95,13 @@ struct arena_qnode {
#define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)
#define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)
+#ifndef likely
#define likely(x) __builtin_expect(!!(x), 1)
+#endif
+
+#ifndef unlikely
#define unlikely(x) __builtin_expect(!!(x), 0)
+#endif
struct arena_qnode __arena qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
diff --git a/tools/testing/selftests/bpf/progs/iters.c b/tools/testing/selftests/bpf/progs/iters.c
index 427b72954b87..1b9a908f2607 100644
--- a/tools/testing/selftests/bpf/progs/iters.c
+++ b/tools/testing/selftests/bpf/progs/iters.c
@@ -7,7 +7,9 @@
#include "bpf_misc.h"
#include "bpf_compiler.h"
+#ifndef unlikely
#define unlikely(x) __builtin_expect(!!(x), 0)
+#endif
static volatile int zero = 0;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH bpf-next 3/4] libbpf: add likely/unlikely macros
2025-03-31 8:13 [PATCH bpf-next 0/4] likely/unlikely for bpf_helpers Anton Protopopov
2025-03-31 8:13 ` [PATCH bpf-next 1/4] bpf: fix a comment describing bpf_attr Anton Protopopov
2025-03-31 8:13 ` [PATCH bpf-next 2/4] selftests/bpf: add guard macros around likely/unlikely Anton Protopopov
@ 2025-03-31 8:13 ` Anton Protopopov
2025-03-31 8:13 ` [PATCH bpf-next 4/4] selftests/bpf: remove likely/unlikely definitions Anton Protopopov
2025-03-31 20:12 ` [PATCH bpf-next 0/4] likely/unlikely for bpf_helpers Andrii Nakryiko
4 siblings, 0 replies; 7+ messages in thread
From: Anton Protopopov @ 2025-03-31 8:13 UTC (permalink / raw)
To: bpf; +Cc: Andrii Nakryiko, Anton Protopopov
A few selftests and, more importantly, a consequent changes to the
bpf_helpers.h file use likely/unlikely macros. So define them here.
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
tools/lib/bpf/bpf_helpers.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h
index 686824b8b413..a50773d4616e 100644
--- a/tools/lib/bpf/bpf_helpers.h
+++ b/tools/lib/bpf/bpf_helpers.h
@@ -15,6 +15,14 @@
#define __array(name, val) typeof(val) *name[]
#define __ulong(name, val) enum { ___bpf_concat(__unique_value, __COUNTER__) = val } name
+#ifndef likely
+#define likely(x) (__builtin_expect(!!(x), 1))
+#endif
+
+#ifndef unlikely
+#define unlikely(x) (__builtin_expect(!!(x), 0))
+#endif
+
/*
* Helper macro to place programs, maps, license in
* different sections in elf_bpf file. Section names
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH bpf-next 4/4] selftests/bpf: remove likely/unlikely definitions
2025-03-31 8:13 [PATCH bpf-next 0/4] likely/unlikely for bpf_helpers Anton Protopopov
` (2 preceding siblings ...)
2025-03-31 8:13 ` [PATCH bpf-next 3/4] libbpf: add likely/unlikely macros Anton Protopopov
@ 2025-03-31 8:13 ` Anton Protopopov
2025-03-31 20:12 ` [PATCH bpf-next 0/4] likely/unlikely for bpf_helpers Andrii Nakryiko
4 siblings, 0 replies; 7+ messages in thread
From: Anton Protopopov @ 2025-03-31 8:13 UTC (permalink / raw)
To: bpf; +Cc: Andrii Nakryiko, Anton Protopopov
Now likely/unlikely macros are defined in tools/lib/bpf/bpf_helpers.h
and thus can be removed from selftests.
Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
---
tools/testing/selftests/bpf/bpf_arena_spin_lock.h | 8 --------
tools/testing/selftests/bpf/progs/iters.c | 4 ----
2 files changed, 12 deletions(-)
diff --git a/tools/testing/selftests/bpf/bpf_arena_spin_lock.h b/tools/testing/selftests/bpf/bpf_arena_spin_lock.h
index d60d899dd9da..4e29c31c4ef8 100644
--- a/tools/testing/selftests/bpf/bpf_arena_spin_lock.h
+++ b/tools/testing/selftests/bpf/bpf_arena_spin_lock.h
@@ -95,14 +95,6 @@ struct arena_qnode {
#define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)
#define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)
-#ifndef likely
-#define likely(x) __builtin_expect(!!(x), 1)
-#endif
-
-#ifndef unlikely
-#define unlikely(x) __builtin_expect(!!(x), 0)
-#endif
-
struct arena_qnode __arena qnodes[_Q_MAX_CPUS][_Q_MAX_NODES];
static inline u32 encode_tail(int cpu, int idx)
diff --git a/tools/testing/selftests/bpf/progs/iters.c b/tools/testing/selftests/bpf/progs/iters.c
index 1b9a908f2607..76adf4a8f2da 100644
--- a/tools/testing/selftests/bpf/progs/iters.c
+++ b/tools/testing/selftests/bpf/progs/iters.c
@@ -7,10 +7,6 @@
#include "bpf_misc.h"
#include "bpf_compiler.h"
-#ifndef unlikely
-#define unlikely(x) __builtin_expect(!!(x), 0)
-#endif
-
static volatile int zero = 0;
int my_pid;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH bpf-next 0/4] likely/unlikely for bpf_helpers
2025-03-31 8:13 [PATCH bpf-next 0/4] likely/unlikely for bpf_helpers Anton Protopopov
` (3 preceding siblings ...)
2025-03-31 8:13 ` [PATCH bpf-next 4/4] selftests/bpf: remove likely/unlikely definitions Anton Protopopov
@ 2025-03-31 20:12 ` Andrii Nakryiko
2025-03-31 20:38 ` Anton Protopopov
4 siblings, 1 reply; 7+ messages in thread
From: Andrii Nakryiko @ 2025-03-31 20:12 UTC (permalink / raw)
To: Anton Protopopov; +Cc: bpf, Andrii Nakryiko
On Mon, Mar 31, 2025 at 1:08 AM Anton Protopopov
<a.s.protopopov@gmail.com> wrote:
>
> Andrii suggested to send this piece with small fixes
> separately from the insn set rfc.
>
> The first patch fixes a comment in <linux/bpf.h>, and the latter
> three patches add likely/unlikely macros to <bph/bpf_helpers.h>.
> The reason there are three patches and not one is to separate
> libbpf changes such that userspace libbpf can be updated more
> easily, and the order is such that each commit can be built.
>
> Anton Protopopov (4):
> bpf: fix a comment describing bpf_attr
> selftests/bpf: add guard macros around likely/unlikely
> libbpf: add likely/unlikely macros
> selftests/bpf: remove likely/unlikely definitions
let's just collapse the last 3 patches into one? libbpf sync process
will be totally fine with that.
pw-bot: cr
>
> include/uapi/linux/bpf.h | 2 +-
> tools/include/uapi/linux/bpf.h | 2 +-
> tools/lib/bpf/bpf_helpers.h | 8 ++++++++
> tools/testing/selftests/bpf/bpf_arena_spin_lock.h | 3 ---
> tools/testing/selftests/bpf/progs/iters.c | 2 --
> 5 files changed, 10 insertions(+), 7 deletions(-)
>
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH bpf-next 0/4] likely/unlikely for bpf_helpers
2025-03-31 20:12 ` [PATCH bpf-next 0/4] likely/unlikely for bpf_helpers Andrii Nakryiko
@ 2025-03-31 20:38 ` Anton Protopopov
0 siblings, 0 replies; 7+ messages in thread
From: Anton Protopopov @ 2025-03-31 20:38 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: Anton Protopopov, bpf, Andrii Nakryiko
On 25/03/31 01:12PM, Andrii Nakryiko wrote:
> On Mon, Mar 31, 2025 at 1:08 AM Anton Protopopov
> <a.s.protopopov@gmail.com> wrote:
> >
> > Andrii suggested to send this piece with small fixes
> > separately from the insn set rfc.
> >
> > The first patch fixes a comment in <linux/bpf.h>, and the latter
> > three patches add likely/unlikely macros to <bph/bpf_helpers.h>.
> > The reason there are three patches and not one is to separate
> > libbpf changes such that userspace libbpf can be updated more
> > easily, and the order is such that each commit can be built.
> >
> > Anton Protopopov (4):
> > bpf: fix a comment describing bpf_attr
> > selftests/bpf: add guard macros around likely/unlikely
> > libbpf: add likely/unlikely macros
> > selftests/bpf: remove likely/unlikely definitions
>
> let's just collapse the last 3 patches into one? libbpf sync process
> will be totally fine with that.
Thanks, I've squashed them in v2.
> pw-bot: cr
>
> >
> > include/uapi/linux/bpf.h | 2 +-
> > tools/include/uapi/linux/bpf.h | 2 +-
> > tools/lib/bpf/bpf_helpers.h | 8 ++++++++
> > tools/testing/selftests/bpf/bpf_arena_spin_lock.h | 3 ---
> > tools/testing/selftests/bpf/progs/iters.c | 2 --
> > 5 files changed, 10 insertions(+), 7 deletions(-)
> >
> > --
> > 2.34.1
> >
^ permalink raw reply [flat|nested] 7+ messages in thread