2019-01-28 04:42:35

by Valdis Klētnieks

[permalink] [raw]
Subject: [PATCH] bpf/core.c - silence warning messages

Compiling kernel/bpf/core.c with W=1 causes a flood of warnings:

kernel/bpf/core.c:1198:65: warning: initialized field overwritten [-Woverride-init]
1198 | #define BPF_INSN_3_TBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = true
| ^~~~
kernel/bpf/core.c:1087:2: note: in expansion of macro 'BPF_INSN_3_TBL'
1087 | INSN_3(ALU, ADD, X), \
| ^~~~~~
kernel/bpf/core.c:1202:3: note: in expansion of macro 'BPF_INSN_MAP'
1202 | BPF_INSN_MAP(BPF_INSN_2_TBL, BPF_INSN_3_TBL),
| ^~~~~~~~~~~~
kernel/bpf/core.c:1198:65: note: (near initialization for 'public_insntable[12]')
1198 | #define BPF_INSN_3_TBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = true
| ^~~~
kernel/bpf/core.c:1087:2: note: in expansion of macro 'BPF_INSN_3_TBL'
1087 | INSN_3(ALU, ADD, X), \
| ^~~~~~
kernel/bpf/core.c:1202:3: note: in expansion of macro 'BPF_INSN_MAP'
1202 | BPF_INSN_MAP(BPF_INSN_2_TBL, BPF_INSN_3_TBL),
| ^~~~~~~~~~~~

98 copies of the above.

The attached patch silences the warnings, because we *know* we're overwriting
the default initializer. That leaves bpf/core.c with only 6 other warnings,
which become more visible in comparison.

Signed-off-by: Valdis Kletnieks <[email protected]>

diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
index 4c2fa3ac56f6..2606665f2cb5 100644
--- a/kernel/bpf/Makefile
+++ b/kernel/bpf/Makefile
@@ -21,3 +21,4 @@ obj-$(CONFIG_CGROUP_BPF) += cgroup.o
ifeq ($(CONFIG_INET),y)
obj-$(CONFIG_BPF_SYSCALL) += reuseport_array.o
endif
+CFLAGS_core.o += $(call cc-disable-warning, override-init)



2019-01-28 17:21:21

by Song Liu

[permalink] [raw]
Subject: Re: [PATCH] bpf/core.c - silence warning messages

On Sun, Jan 27, 2019 at 8:43 PM <[email protected]> wrote:
>
> Compiling kernel/bpf/core.c with W=1 causes a flood of warnings:
>
> kernel/bpf/core.c:1198:65: warning: initialized field overwritten [-Woverride-init]
> 1198 | #define BPF_INSN_3_TBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = true
> | ^~~~
> kernel/bpf/core.c:1087:2: note: in expansion of macro 'BPF_INSN_3_TBL'
> 1087 | INSN_3(ALU, ADD, X), \
> | ^~~~~~
> kernel/bpf/core.c:1202:3: note: in expansion of macro 'BPF_INSN_MAP'
> 1202 | BPF_INSN_MAP(BPF_INSN_2_TBL, BPF_INSN_3_TBL),
> | ^~~~~~~~~~~~
> kernel/bpf/core.c:1198:65: note: (near initialization for 'public_insntable[12]')
> 1198 | #define BPF_INSN_3_TBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = true
> | ^~~~
> kernel/bpf/core.c:1087:2: note: in expansion of macro 'BPF_INSN_3_TBL'
> 1087 | INSN_3(ALU, ADD, X), \
> | ^~~~~~
> kernel/bpf/core.c:1202:3: note: in expansion of macro 'BPF_INSN_MAP'
> 1202 | BPF_INSN_MAP(BPF_INSN_2_TBL, BPF_INSN_3_TBL),
> | ^~~~~~~~~~~~
>
> 98 copies of the above.
>
> The attached patch silences the warnings, because we *know* we're overwriting
> the default initializer. That leaves bpf/core.c with only 6 other warnings,
> which become more visible in comparison.

My concern is that this will also mute the warning for other parts of
bpf/core.c.

Maybe we should move bpf_opcode_in_insntable() to a separate file, and mute
warning for that file?

Daniel and Alexei, what do you think?

Thanks,
Song


>
> Signed-off-by: Valdis Kletnieks <[email protected]>
>
> diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
> index 4c2fa3ac56f6..2606665f2cb5 100644
> --- a/kernel/bpf/Makefile
> +++ b/kernel/bpf/Makefile
> @@ -21,3 +21,4 @@ obj-$(CONFIG_CGROUP_BPF) += cgroup.o
> ifeq ($(CONFIG_INET),y)
> obj-$(CONFIG_BPF_SYSCALL) += reuseport_array.o
> endif
> +CFLAGS_core.o += $(call cc-disable-warning, override-init)
>

2019-01-28 23:22:54

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH] bpf/core.c - silence warning messages

On 01/28/2019 06:18 PM, Song Liu wrote:
> On Sun, Jan 27, 2019 at 8:43 PM <[email protected]> wrote:
>>
>> Compiling kernel/bpf/core.c with W=1 causes a flood of warnings:
>>
>> kernel/bpf/core.c:1198:65: warning: initialized field overwritten [-Woverride-init]
>> 1198 | #define BPF_INSN_3_TBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = true
>> | ^~~~
>> kernel/bpf/core.c:1087:2: note: in expansion of macro 'BPF_INSN_3_TBL'
>> 1087 | INSN_3(ALU, ADD, X), \
>> | ^~~~~~
>> kernel/bpf/core.c:1202:3: note: in expansion of macro 'BPF_INSN_MAP'
>> 1202 | BPF_INSN_MAP(BPF_INSN_2_TBL, BPF_INSN_3_TBL),
>> | ^~~~~~~~~~~~
>> kernel/bpf/core.c:1198:65: note: (near initialization for 'public_insntable[12]')
>> 1198 | #define BPF_INSN_3_TBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = true
>> | ^~~~
>> kernel/bpf/core.c:1087:2: note: in expansion of macro 'BPF_INSN_3_TBL'
>> 1087 | INSN_3(ALU, ADD, X), \
>> | ^~~~~~
>> kernel/bpf/core.c:1202:3: note: in expansion of macro 'BPF_INSN_MAP'
>> 1202 | BPF_INSN_MAP(BPF_INSN_2_TBL, BPF_INSN_3_TBL),
>> | ^~~~~~~~~~~~
>>
>> 98 copies of the above.
>>
>> The attached patch silences the warnings, because we *know* we're overwriting
>> the default initializer. That leaves bpf/core.c with only 6 other warnings,
>> which become more visible in comparison.
>
> My concern is that this will also mute the warning for other parts of
> bpf/core.c.

Agree, valid concern.

> Maybe we should move bpf_opcode_in_insntable() to a separate file, and mute
> warning for that file?

I think moving in separate file would be overkill, imho. However, lets get
the kdoc and prototype warning fixed.

Thanks,
Daniel

2019-01-28 23:36:09

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: [PATCH] bpf/core.c - silence warning messages

On Mon, 28 Jan 2019 09:18:45 -0800, Song Liu said:
> On Sun, Jan 27, 2019 at 8:43 PM <[email protected]> wrote:

> > The attached patch silences the warnings, because we *know* we're overwriting
> > the default initializer. That leaves bpf/core.c with only 6 other warnings,
> > which become more visible in comparison.
>
> My concern is that this will also mute the warning for other parts of
> bpf/core.c.

I checked and there weren't any warnings for other parts of the file. Also, this message
doesn't even happen unless you build with W=1, which apparently happens so rarely
that nobody else has submitted a patch.

Is there a high likelihood that another overwrite of an initializer is going to
be included in the source?

> Maybe we should move bpf_opcode_in_insntable() to a separate file, and mute
> warning for that file?

Seems to be overkill - the intent of this patch was mostly to make the *other*
warnings issued with W=1 more noticable.


2019-01-28 23:49:30

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: [PATCH] bpf/core.c - silence warning messages

On Tue, 29 Jan 2019 00:22:26 +0100, Daniel Borkmann said:
> I think moving in separate file would be overkill, imho. However, lets get
> the kdoc and prototype warning fixed.

I have a bunch of spare time at the moment, so the kdoc and prototype
warnings are on my to-do list.



2019-01-28 23:55:21

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH] bpf/core.c - silence warning messages

On 01/29/2019 12:48 AM, [email protected] wrote:
> On Tue, 29 Jan 2019 00:22:26 +0100, Daniel Borkmann said:
>> I think moving in separate file would be overkill, imho. However, lets get
>> the kdoc and prototype warning fixed.
>
> I have a bunch of spare time at the moment, so the kdoc and prototype
> warnings are on my to-do list.

Great, thanks!

2019-01-29 03:13:40

by Song Liu

[permalink] [raw]
Subject: Re: [PATCH] bpf/core.c - silence warning messages

On Mon, Jan 28, 2019 at 3:35 PM <[email protected]> wrote:
>
> On Mon, 28 Jan 2019 09:18:45 -0800, Song Liu said:
> > On Sun, Jan 27, 2019 at 8:43 PM <[email protected]> wrote:
>
> > > The attached patch silences the warnings, because we *know* we're overwriting
> > > the default initializer. That leaves bpf/core.c with only 6 other warnings,
> > > which become more visible in comparison.
> >
> > My concern is that this will also mute the warning for other parts of
> > bpf/core.c.
>
> I checked and there weren't any warnings for other parts of the file. Also, this message
> doesn't even happen unless you build with W=1, which apparently happens so rarely
> that nobody else has submitted a patch.
>
> Is there a high likelihood that another overwrite of an initializer is going to
> be included in the source?
>
> > Maybe we should move bpf_opcode_in_insntable() to a separate file, and mute
> > warning for that file?
>
> Seems to be overkill - the intent of this patch was mostly to make the *other*
> warnings issued with W=1 more noticable.

Yeah, I also felt this might be overkill while asking initially.

Acked-by: Song Liu <[email protected]>