linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: suppress -Wcast-function-type warning
@ 2020-10-26 21:03 Arnd Bergmann
  2020-10-26 22:20 ` David Laight
  2020-10-26 22:26 ` Andrii Nakryiko
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2020-10-26 21:03 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: Arnd Bergmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	Andrii Nakryiko, John Fastabend, KP Singh, David Miller,
	Thomas Gleixner, Jakub Sitnicki, Björn Töpel,
	Toke Høiland-Jørgensen, Jiri Olsa, Pankaj Bharadiya,
	netdev, bpf, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

Building with -Wextra shows lots of warnings in the bpf
code such as

kernel/bpf/verifier.c: In function ‘jit_subprogs’:
include/linux/filter.h:345:4: warning: cast between incompatible function types from ‘unsigned int (*)(const void *, const struct bpf_insn *)’ to ‘u64 (*)(u64,  u64,  u64,  u64,  u64)’ {aka ‘long long unsigned int (*)(long long unsigned int,  long long unsigned int,  long long unsigned int,  long long unsigned int,  long long unsigned int)’} [-Wcast-function-type]
  345 |   ((u64 (*)(u64, u64, u64, u64, u64))(x))
      |    ^
kernel/bpf/verifier.c:10706:16: note: in expansion of macro ‘BPF_CAST_CALL’
10706 |    insn->imm = BPF_CAST_CALL(func[subprog]->bpf_func) -
      |                ^~~~~~~~~~~~~

This appears to be intentional, so change the cast in a way that
suppresses the warning.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 include/linux/filter.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/filter.h b/include/linux/filter.h
index 1b62397bd124..20ba04583eaa 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -342,7 +342,7 @@ static inline bool insn_is_zext(const struct bpf_insn *insn)
 /* Function call */
 
 #define BPF_CAST_CALL(x)					\
-		((u64 (*)(u64, u64, u64, u64, u64))(x))
+		((u64 (*)(u64, u64, u64, u64, u64))(uintptr_t)(x))
 
 #define BPF_EMIT_CALL(FUNC)					\
 	((struct bpf_insn) {					\
-- 
2.27.0


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

* RE: [PATCH] bpf: suppress -Wcast-function-type warning
  2020-10-26 21:03 [PATCH] bpf: suppress -Wcast-function-type warning Arnd Bergmann
@ 2020-10-26 22:20 ` David Laight
  2020-10-26 22:26 ` Andrii Nakryiko
  1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2020-10-26 22:20 UTC (permalink / raw)
  To: 'Arnd Bergmann', Alexei Starovoitov, Daniel Borkmann
  Cc: Arnd Bergmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	Andrii Nakryiko, John Fastabend, KP Singh, David Miller,
	Thomas Gleixner, Jakub Sitnicki, Björn Töpel,
	Toke Høiland-Jørgensen, Jiri Olsa, Pankaj Bharadiya,
	netdev, bpf, linux-kernel

From: Arnd Bergmann
> Sent: 26 October 2020 21:03
> 
> From: Arnd Bergmann <arnd@arndb.de>
> 
> Building with -Wextra shows lots of warnings in the bpf
> code such as
> 
> kernel/bpf/verifier.c: In function ‘jit_subprogs’:
> include/linux/filter.h:345:4: warning: cast between incompatible function types from ‘unsigned int
> (*)(const void *, const struct bpf_insn *)’ to ‘u64 (*)(u64,  u64,  u64,  u64,  u64)’ {aka ‘long long
> unsigned int (*)(long long unsigned int,  long long unsigned int,  long long unsigned int,  long long
> unsigned int,  long long unsigned int)’} [-Wcast-function-type]
>   345 |   ((u64 (*)(u64, u64, u64, u64, u64))(x))
>       |    ^
> kernel/bpf/verifier.c:10706:16: note: in expansion of macro ‘BPF_CAST_CALL’
> 10706 |    insn->imm = BPF_CAST_CALL(func[subprog]->bpf_func) -
>       |                ^~~~~~~~~~~~~
> 
> This appears to be intentional, so change the cast in a way that
> suppresses the warning.

It is also utterly horrid.
If the value is ever cast back then there is a lot of scope
for it going badly wrong somewhere.
It certainly isn't valid to use the target type to call the original function.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

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

* Re: [PATCH] bpf: suppress -Wcast-function-type warning
  2020-10-26 21:03 [PATCH] bpf: suppress -Wcast-function-type warning Arnd Bergmann
  2020-10-26 22:20 ` David Laight
@ 2020-10-26 22:26 ` Andrii Nakryiko
  1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2020-10-26 22:26 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Alexei Starovoitov, Daniel Borkmann, Arnd Bergmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	John Fastabend, KP Singh, David Miller, Thomas Gleixner,
	Jakub Sitnicki, Björn Töpel,
	Toke Høiland-Jørgensen, Jiri Olsa, Pankaj Bharadiya,
	Networking, bpf, open list

On Mon, Oct 26, 2020 at 2:03 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> Building with -Wextra shows lots of warnings in the bpf
> code such as
>
> kernel/bpf/verifier.c: In function ‘jit_subprogs’:
> include/linux/filter.h:345:4: warning: cast between incompatible function types from ‘unsigned int (*)(const void *, const struct bpf_insn *)’ to ‘u64 (*)(u64,  u64,  u64,  u64,  u64)’ {aka ‘long long unsigned int (*)(long long unsigned int,  long long unsigned int,  long long unsigned int,  long long unsigned int,  long long unsigned int)’} [-Wcast-function-type]
>   345 |   ((u64 (*)(u64, u64, u64, u64, u64))(x))
>       |    ^
> kernel/bpf/verifier.c:10706:16: note: in expansion of macro ‘BPF_CAST_CALL’
> 10706 |    insn->imm = BPF_CAST_CALL(func[subprog]->bpf_func) -
>       |                ^~~~~~~~~~~~~
>
> This appears to be intentional, so change the cast in a way that
> suppresses the warning.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---

LGTM.

Acked-by: Andrii Nakryiko <andrii@kernel.org>

>  include/linux/filter.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/filter.h b/include/linux/filter.h
> index 1b62397bd124..20ba04583eaa 100644
> --- a/include/linux/filter.h
> +++ b/include/linux/filter.h
> @@ -342,7 +342,7 @@ static inline bool insn_is_zext(const struct bpf_insn *insn)
>  /* Function call */
>
>  #define BPF_CAST_CALL(x)                                       \
> -               ((u64 (*)(u64, u64, u64, u64, u64))(x))
> +               ((u64 (*)(u64, u64, u64, u64, u64))(uintptr_t)(x))
>
>  #define BPF_EMIT_CALL(FUNC)                                    \
>         ((struct bpf_insn) {                                    \
> --
> 2.27.0
>

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

end of thread, other threads:[~2020-10-26 22:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 21:03 [PATCH] bpf: suppress -Wcast-function-type warning Arnd Bergmann
2020-10-26 22:20 ` David Laight
2020-10-26 22:26 ` Andrii Nakryiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).