All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: Add explicit cast to 'void *' for __BPF_DISPATCHER_UPDATE()
@ 2022-11-07 17:07 Nathan Chancellor
  2022-11-07 17:51 ` Björn Töpel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nathan Chancellor @ 2022-11-07 17:07 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: John Fastabend, Jiri Olsa, Peter Zijlstra, Björn Töpel,
	Nick Desaulniers, Tom Rix, bpf, linux-kernel, llvm, patches,
	Nathan Chancellor, kernel test robot, kernelci.org bot

When building with clang:

  kernel/bpf/dispatcher.c:126:33: error: pointer type mismatch ('void *' and 'unsigned int (*)(const void *, const struct bpf_insn *, bpf_func_t)' (aka 'unsigned int (*)(const void *, const struct bpf_insn *, unsigned int (*)(const void *, const struct bpf_insn *))')) [-Werror,-Wpointer-type-mismatch]
          __BPF_DISPATCHER_UPDATE(d, new ?: &bpf_dispatcher_nop_func);
                                     ~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~
  ./include/linux/bpf.h:1045:54: note: expanded from macro '__BPF_DISPATCHER_UPDATE'
          __static_call_update((_d)->sc_key, (_d)->sc_tramp, (_new))
                                                              ^~~~
  1 error generated.

The warning is pointing out that the type of new ('void *') and
&bpf_dispatcher_nop_func are not compatible, which could have side
effects coming out of a conditional operator due to promotion rules.

Add the explicit cast to 'void *' to make it clear that this is
expected, as __BPF_DISPATCHER_UPDATE() expands to a call to
__static_call_update(), which expects a 'void *' as its final argument.

Fixes: c86df29d11df ("bpf: Convert BPF_DISPATCHER to use static_call() (not ftrace)")
Link: https://github.com/ClangBuiltLinux/linux/issues/1755
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: "kernelci.org bot" <bot@kernelci.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 kernel/bpf/dispatcher.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/dispatcher.c b/kernel/bpf/dispatcher.c
index 7dfb8d0d5202..c19719f48ce0 100644
--- a/kernel/bpf/dispatcher.c
+++ b/kernel/bpf/dispatcher.c
@@ -123,7 +123,7 @@ static void bpf_dispatcher_update(struct bpf_dispatcher *d, int prev_num_progs)
 			return;
 	}
 
-	__BPF_DISPATCHER_UPDATE(d, new ?: &bpf_dispatcher_nop_func);
+	__BPF_DISPATCHER_UPDATE(d, new ?: (void *)&bpf_dispatcher_nop_func);
 
 	if (new)
 		d->image_off = noff;

base-commit: c86df29d11dfba27c0a1f5039cd6fe387fbf4239
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] bpf: Add explicit cast to 'void *' for __BPF_DISPATCHER_UPDATE()
  2022-11-07 17:07 [PATCH bpf] bpf: Add explicit cast to 'void *' for __BPF_DISPATCHER_UPDATE() Nathan Chancellor
@ 2022-11-07 17:51 ` Björn Töpel
  2022-11-07 18:45 ` Yonghong Song
  2022-11-08  0:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Björn Töpel @ 2022-11-07 17:51 UTC (permalink / raw)
  To: Nathan Chancellor, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: John Fastabend, Jiri Olsa, Peter Zijlstra, Nick Desaulniers,
	Tom Rix, bpf, linux-kernel, llvm, patches, Nathan Chancellor,
	kernel test robot, kernelci.org bot

Nathan Chancellor <nathan@kernel.org> writes:

> When building with clang:
>
>   kernel/bpf/dispatcher.c:126:33: error: pointer type mismatch ('void *' and 'unsigned int (*)(const void *, const struct bpf_insn *, bpf_func_t)' (aka 'unsigned int (*)(const void *, const struct bpf_insn *, unsigned int (*)(const void *, const struct bpf_insn *))')) [-Werror,-Wpointer-type-mismatch]
>           __BPF_DISPATCHER_UPDATE(d, new ?: &bpf_dispatcher_nop_func);
>                                      ~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~
>   ./include/linux/bpf.h:1045:54: note: expanded from macro '__BPF_DISPATCHER_UPDATE'
>           __static_call_update((_d)->sc_key, (_d)->sc_tramp, (_new))
>                                                               ^~~~
>   1 error generated.
>
> The warning is pointing out that the type of new ('void *') and
> &bpf_dispatcher_nop_func are not compatible, which could have side
> effects coming out of a conditional operator due to promotion rules.
>
> Add the explicit cast to 'void *' to make it clear that this is
> expected, as __BPF_DISPATCHER_UPDATE() expands to a call to
> __static_call_update(), which expects a 'void *' as its final argument.
>
> Fixes: c86df29d11df ("bpf: Convert BPF_DISPATCHER to use static_call() (not ftrace)")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1755
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: "kernelci.org bot" <bot@kernelci.org>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Acked-by: Björn Töpel <bjorn@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] bpf: Add explicit cast to 'void *' for __BPF_DISPATCHER_UPDATE()
  2022-11-07 17:07 [PATCH bpf] bpf: Add explicit cast to 'void *' for __BPF_DISPATCHER_UPDATE() Nathan Chancellor
  2022-11-07 17:51 ` Björn Töpel
@ 2022-11-07 18:45 ` Yonghong Song
  2022-11-08  0:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Yonghong Song @ 2022-11-07 18:45 UTC (permalink / raw)
  To: Nathan Chancellor, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: John Fastabend, Jiri Olsa, Peter Zijlstra, Björn Töpel,
	Nick Desaulniers, Tom Rix, bpf, linux-kernel, llvm, patches,
	kernel test robot, kernelci.org bot



On 11/7/22 9:07 AM, Nathan Chancellor wrote:
> When building with clang:
> 
>    kernel/bpf/dispatcher.c:126:33: error: pointer type mismatch ('void *' and 'unsigned int (*)(const void *, const struct bpf_insn *, bpf_func_t)' (aka 'unsigned int (*)(const void *, const struct bpf_insn *, unsigned int (*)(const void *, const struct bpf_insn *))')) [-Werror,-Wpointer-type-mismatch]
>            __BPF_DISPATCHER_UPDATE(d, new ?: &bpf_dispatcher_nop_func);
>                                       ~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~
>    ./include/linux/bpf.h:1045:54: note: expanded from macro '__BPF_DISPATCHER_UPDATE'
>            __static_call_update((_d)->sc_key, (_d)->sc_tramp, (_new))
>                                                                ^~~~
>    1 error generated.
> 
> The warning is pointing out that the type of new ('void *') and
> &bpf_dispatcher_nop_func are not compatible, which could have side
> effects coming out of a conditional operator due to promotion rules.
> 
> Add the explicit cast to 'void *' to make it clear that this is
> expected, as __BPF_DISPATCHER_UPDATE() expands to a call to
> __static_call_update(), which expects a 'void *' as its final argument.
> 
> Fixes: c86df29d11df ("bpf: Convert BPF_DISPATCHER to use static_call() (not ftrace)")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1755
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: "kernelci.org bot" <bot@kernelci.org>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf] bpf: Add explicit cast to 'void *' for __BPF_DISPATCHER_UPDATE()
  2022-11-07 17:07 [PATCH bpf] bpf: Add explicit cast to 'void *' for __BPF_DISPATCHER_UPDATE() Nathan Chancellor
  2022-11-07 17:51 ` Björn Töpel
  2022-11-07 18:45 ` Yonghong Song
@ 2022-11-08  0:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-08  0:10 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: ast, daniel, andrii, john.fastabend, jolsa, peterz, bjorn,
	ndesaulniers, trix, bpf, linux-kernel, llvm, patches, lkp, bot

Hello:

This patch was applied to bpf/bpf.git (master)
by Martin KaFai Lau <martin.lau@kernel.org>:

On Mon,  7 Nov 2022 10:07:11 -0700 you wrote:
> When building with clang:
> 
>   kernel/bpf/dispatcher.c:126:33: error: pointer type mismatch ('void *' and 'unsigned int (*)(const void *, const struct bpf_insn *, bpf_func_t)' (aka 'unsigned int (*)(const void *, const struct bpf_insn *, unsigned int (*)(const void *, const struct bpf_insn *))')) [-Werror,-Wpointer-type-mismatch]
>           __BPF_DISPATCHER_UPDATE(d, new ?: &bpf_dispatcher_nop_func);
>                                      ~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~
>   ./include/linux/bpf.h:1045:54: note: expanded from macro '__BPF_DISPATCHER_UPDATE'
>           __static_call_update((_d)->sc_key, (_d)->sc_tramp, (_new))
>                                                               ^~~~
>   1 error generated.
> 
> [...]

Here is the summary with links:
  - [bpf] bpf: Add explicit cast to 'void *' for __BPF_DISPATCHER_UPDATE()
    https://git.kernel.org/bpf/bpf/c/a679120edfcf

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-08  0:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07 17:07 [PATCH bpf] bpf: Add explicit cast to 'void *' for __BPF_DISPATCHER_UPDATE() Nathan Chancellor
2022-11-07 17:51 ` Björn Töpel
2022-11-07 18:45 ` Yonghong Song
2022-11-08  0:10 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.