[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250717032828.500146-2-yangfeng59949@163.com>
Date: Thu, 17 Jul 2025 11:28:27 +0800
From: Feng Yang <yangfeng59949@....com>
To: ast@...nel.org,
daniel@...earbox.net,
andrii@...nel.org,
martin.lau@...ux.dev,
eddyz87@...il.com,
song@...nel.org,
yonghong.song@...ux.dev,
john.fastabend@...il.com,
kpsingh@...nel.org,
sdf@...ichev.me,
haoluo@...gle.com,
jolsa@...nel.org,
memxor@...il.com
Cc: bpf@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v2 bpf-next 1/2] bpf: Fix macro redefined
From: Feng Yang <yangfeng@...inos.cn>
When compiling a program that include <linux/bpf.h> and <bpf/bpf_helpers.h>, (For example: make samples/bpf)
the following warning will be generated:
In file included from tcp_dumpstats_kern.c:7:
samples/bpf/libbpf/include/bpf/bpf_helpers.h:321:9: warning: 'bpf_stream_printk' macro redefined [-Wmacro-redefined]
321 | #define bpf_stream_printk(stream_id, fmt, args...) \
| ^
include/linux/bpf.h:3626:9: note: previous definition is here
3626 | #define bpf_stream_printk(ss, ...) bpf_stream_stage_printk(&ss, __VA_ARGS__)
| ^
The main reason is due to below in sample/bpf/Makefile:
$(obj)/%.o: $(src)/%.c
@echo " CLANG-bpf " $@
$(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(BPF_EXTRA_CFLAGS) \
-I$(obj) -I$(srctree)/tools/testing/selftests/bpf/ \
-I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES) \
-D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
-D__TARGET_ARCH_$(SRCARCH) -Wno-compare-distinct-pointer-types \
-Wno-gnu-variable-sized-type-not-at-end \
-Wno-address-of-packed-member -Wno-tautological-compare \
-Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
-fno-asynchronous-unwind-tables \
-I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \
-O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \
$(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \
$(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
Here, some kernel data structure is needed for some particular architecture so
the initial from source to IR is compiled with native arch and after IR optimization
is done, it is switched to bpf.
So remove this line
#define bpf_stream_printk(ss, ...) bpf_stream_stage_printk(&ss, __VA_ARGS__)
and directly use bpf_stream_stage_printk(&ss, ...)
Fixes: 21a3afc76a31 ("libbpf: Add bpf_stream_printk() macro")
Signed-off-by: Feng Yang <yangfeng@...inos.cn>
---
include/linux/bpf.h | 1 -
kernel/bpf/core.c | 2 +-
kernel/bpf/rqspinlock.c | 8 ++++----
3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index bc887831eaa5..d010a0c4e374 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -3623,7 +3623,6 @@ int bpf_stream_stage_commit(struct bpf_stream_stage *ss, struct bpf_prog *prog,
enum bpf_stream_id stream_id);
int bpf_stream_stage_dump_stack(struct bpf_stream_stage *ss);
-#define bpf_stream_printk(ss, ...) bpf_stream_stage_printk(&ss, __VA_ARGS__)
#define bpf_stream_dump_stack(ss) bpf_stream_stage_dump_stack(&ss)
#define bpf_stream_stage(ss, prog, stream_id, expr) \
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 61613785bdd0..cc8e076f6d54 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -3178,7 +3178,7 @@ static noinline void bpf_prog_report_may_goto_violation(void)
if (!prog)
return;
bpf_stream_stage(ss, prog, BPF_STDERR, ({
- bpf_stream_printk(ss, "ERROR: Timeout detected for may_goto instruction\n");
+ bpf_stream_stage_printk(&ss, "ERROR: Timeout detected for may_goto instruction\n");
bpf_stream_dump_stack(ss);
}));
#endif
diff --git a/kernel/bpf/rqspinlock.c b/kernel/bpf/rqspinlock.c
index 5ab354d55d82..b176a6f9e431 100644
--- a/kernel/bpf/rqspinlock.c
+++ b/kernel/bpf/rqspinlock.c
@@ -676,11 +676,11 @@ static void bpf_prog_report_rqspinlock_violation(const char *str, void *lock, bo
if (!prog)
return;
bpf_stream_stage(ss, prog, BPF_STDERR, ({
- bpf_stream_printk(ss, "ERROR: %s for bpf_res_spin_lock%s\n", str, irqsave ? "_irqsave" : "");
- bpf_stream_printk(ss, "Attempted lock = 0x%px\n", lock);
- bpf_stream_printk(ss, "Total held locks = %d\n", rqh->cnt);
+ bpf_stream_stage_printk(&ss, "ERROR: %s for bpf_res_spin_lock%s\n", str, irqsave ? "_irqsave" : "");
+ bpf_stream_stage_printk(&ss, "Attempted lock = 0x%px\n", lock);
+ bpf_stream_stage_printk(&ss, "Total held locks = %d\n", rqh->cnt);
for (int i = 0; i < min(RES_NR_HELD, rqh->cnt); i++)
- bpf_stream_printk(ss, "Held lock[%2d] = 0x%px\n", i, rqh->locks[i]);
+ bpf_stream_stage_printk(&ss, "Held lock[%2d] = 0x%px\n", i, rqh->locks[i]);
bpf_stream_dump_stack(ss);
}));
}
--
2.43.0
Powered by blists - more mailing lists