[PATCH] bpf: Fix undeclared function 'barrier_nospec' warning

Viresh Kumar posted 1 patch 2 years, 6 months ago
kernel/bpf/core.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] bpf: Fix undeclared function 'barrier_nospec' warning
Posted by Viresh Kumar 2 years, 6 months ago
Add the missing header for architectures that don't define
the barrier_nospec() macro. The nospec.h header is added after the
inclusion of barrier.h to avoid redefining the macro for architectures
that already define barrier_nospec() in their respective barrier.h
headers.

Fixes: 74e19ef0ff80 ("uaccess: Add speculation barrier to copy_from_user()")
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
Linus's master branch fails currently to build for arm64 without this commit.

 kernel/bpf/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 933869983e2a..92aeb388e422 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -38,6 +38,8 @@
 #include <linux/memcontrol.h>
 
 #include <asm/barrier.h>
+#include <linux/nospec.h>
+
 #include <asm/unaligned.h>
 
 /* Registers */
-- 
2.31.1.272.g89b43f80a514
Re: [PATCH] bpf: Fix undeclared function 'barrier_nospec' warning
Posted by Daniel Borkmann 2 years, 6 months ago
On 2/22/23 9:24 AM, Viresh Kumar wrote:
> Add the missing header for architectures that don't define
> the barrier_nospec() macro. The nospec.h header is added after the
> inclusion of barrier.h to avoid redefining the macro for architectures
> that already define barrier_nospec() in their respective barrier.h
> headers.
> 
> Fixes: 74e19ef0ff80 ("uaccess: Add speculation barrier to copy_from_user()")
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> Linus's master branch fails currently to build for arm64 without this commit.
> 
>   kernel/bpf/core.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 933869983e2a..92aeb388e422 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -38,6 +38,8 @@
>   #include <linux/memcontrol.h>
>   
>   #include <asm/barrier.h>
> +#include <linux/nospec.h>
> +

nit: The asm/barrier.h include could have just been removed. linux/nospec.h
internally includes asm/barrier.h already.

>   #include <asm/unaligned.h>
>   
>   /* Registers */
>
Re: [PATCH] bpf: Fix undeclared function 'barrier_nospec' warning
Posted by Geert Uytterhoeven 2 years, 6 months ago
On Wed, Feb 22, 2023 at 9:26 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> Add the missing header for architectures that don't define
> the barrier_nospec() macro. The nospec.h header is added after the
> inclusion of barrier.h to avoid redefining the macro for architectures
> that already define barrier_nospec() in their respective barrier.h
> headers.
>
> Fixes: 74e19ef0ff80 ("uaccess: Add speculation barrier to copy_from_user()")
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> Linus's master branch fails currently to build for arm64 without this commit.

Not just arm64 :-(
http://kisskb.ellerman.id.au/kisskb/head/5b7c4cabbb65f5c469464da6c5f614cbd7f730f2

Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH] bpf: Fix undeclared function 'barrier_nospec' warning
Posted by Dave Hansen 2 years, 6 months ago
On 2/22/23 07:03, Geert Uytterhoeven wrote:
> On Wed, Feb 22, 2023 at 9:26 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>> Add the missing header for architectures that don't define
>> the barrier_nospec() macro. The nospec.h header is added after the
>> inclusion of barrier.h to avoid redefining the macro for architectures
>> that already define barrier_nospec() in their respective barrier.h
>> headers.
>>
>> Fixes: 74e19ef0ff80 ("uaccess: Add speculation barrier to copy_from_user()")
>> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
>> ---
>> Linus's master branch fails currently to build for arm64 without this commit.
> Not just arm64 🙁
> http://kisskb.ellerman.id.au/kisskb/head/5b7c4cabbb65f5c469464da6c5f614cbd7f730f2

Thanks for the fix, and sorry for the breakage, folks!  Obviously:

Tested-by: Dave Hansen <dave.hansen@linux.intel.com>

Now time to go make sure I have bpf turned on in all my cross builds.


Re: [PATCH] bpf: Fix undeclared function 'barrier_nospec' warning
Posted by Alexei Starovoitov 2 years, 6 months ago
On Wed, Feb 22, 2023 at 7:33 AM Dave Hansen <dave.hansen@intel.com> wrote:
>
> On 2/22/23 07:03, Geert Uytterhoeven wrote:
> > On Wed, Feb 22, 2023 at 9:26 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> >> Add the missing header for architectures that don't define
> >> the barrier_nospec() macro. The nospec.h header is added after the
> >> inclusion of barrier.h to avoid redefining the macro for architectures
> >> that already define barrier_nospec() in their respective barrier.h
> >> headers.
> >>
> >> Fixes: 74e19ef0ff80 ("uaccess: Add speculation barrier to copy_from_user()")
> >> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> >> ---
> >> Linus's master branch fails currently to build for arm64 without this commit.
> > Not just arm64 🙁
> > http://kisskb.ellerman.id.au/kisskb/head/5b7c4cabbb65f5c469464da6c5f614cbd7f730f2
>
> Thanks for the fix, and sorry for the breakage, folks!  Obviously:
>
> Tested-by: Dave Hansen <dave.hansen@linux.intel.com>
>
> Now time to go make sure I have bpf turned on in all my cross builds.

Not clear why the broken commit got applied bypassing bpf@vger and not
going through BPF CI. :(

Yesterday I applied pretty much the same fix from Huacai Chen.

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=345d24a91c79f408e355c8b7e873ccde0f097eea

and BPF CI is now back to green.

Linus,
Since the blast radius is big, may be apply the fix directly ?
Re: [PATCH] bpf: Fix undeclared function 'barrier_nospec' warning
Posted by Linus Torvalds 2 years, 6 months ago
On Wed, Feb 22, 2023 at 8:29 AM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> Linus,
> Since the blast radius is big, may be apply the fix directly ?

Yup, done. Of the different patches I picked the same location you had
taken so that there shouldn't be any conflicts if that ends making it
to me later.

                  Linus