Re: [PATCH 2/2] [v3] bpf: fix bpf_probe_read_kernel prototype mismatch

Yonghong Song
2023-06-06T22:50:47Z

On 6/2/23 6:50 AM, Arnd Bergmann wrote:
> 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]
>
> On 32-bit architectures, the local prototype
>
> u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
>
> passes arguments in other registers as the one in bpf_trace.c
>
> BPF_CALL_3(bpf_probe_read_kernel, void *, dst, u32, size,
> const void *, unsafe_ptr)
>
> which uses 64-bit arguments in pairs of registers.
>
> Change the core.c file to only reference the inner
> bpf_probe_read_kernel_common() helper and provide a prototype for that,
> to ensure this is compatible with both definitions.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Yonghong Song <yhs@fb.com>