lkml.org 
[lkml]   [2023]   [May]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] bpf: add bpf_probe_read_kernel declaration
Date
From: Arnd Bergmann <arnd@arndb.de>

bpf_probe_read_kernel() has a __weak definition in core.c and another
definition with an incompatible prototype in kernel/trace/bpf_trace.c,
when CONFIG_BPF_EVENTS is enabled.

Since the two are incompatible, there cannot be a shared declaration
in a header file, but the lack of a prototype causes a W=1 warning:

kernel/bpf/core.c:1638:12: error: no previous prototype for 'bpf_probe_read_kernel' [-Werror=missing-prototypes]

Add a prototype directly in front of the function instead to shut
up the warning. Also, to avoid having an incompatible function override
the __weak definition, use an #ifdef to ensure that only one of the
two is ever defined.

I'm not sure what can be done to make the two prototypes match.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
kernel/bpf/core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 6f5ede31e471..38762a784b86 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1635,11 +1635,14 @@ bool bpf_opcode_in_insntable(u8 code)
}

#ifndef CONFIG_BPF_JIT_ALWAYS_ON
-u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
+u64 bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr);
+#ifndef CONFIG_BPF_EVENTS
+u64 bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
{
memset(dst, 0, size);
return -EFAULT;
}
+#endif

/**
* ___bpf_prog_run - run eBPF program on a given context
--
2.39.2
\
 
 \ /
  Last update: 2023-05-17 14:57    [W:0.376 / U:0.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site