linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/kasan: fix kasan_check_read() compiler warning
@ 2019-07-09 18:35 Arnd Bergmann
  2019-07-09 18:46 ` Marco Elver
  2019-07-09 18:51 ` Nick Desaulniers
  0 siblings, 2 replies; 4+ messages in thread
From: Arnd Bergmann @ 2019-07-09 18:35 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Arnd Bergmann, Marco Elver, Mark Rutland, Andrey Ryabinin,
	Dmitry Vyukov, Alexander Potapenko, Andrey Konovalov,
	Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Kees Cook, Stephen Rothwell, Luc Van Oostenryck, ndesaulniers,
	Miguel Ojeda, Ingo Molnar, Josh Poimboeuf, linux-kernel

The kasan_check_read() is marked 'inline', which usually includes
the 'always_inline' attribute. In some configuration, gcc decides that
it cannot inline this, causing a build failure:

In file included from include/linux/compiler.h:257,
                 from arch/x86/include/asm/current.h:5,
                 from include/linux/sched.h:12,
                 from include/linux/ratelimit.h:6,
                 from fs/dcache.c:18:
include/linux/compiler.h: In function 'read_word_at_a_time':
include/linux/kasan-checks.h:31:20: error: inlining failed in call to always_inline 'kasan_check_read': function attribute mismatch
 static inline bool kasan_check_read(const volatile void *p, unsigned int size)
                    ^~~~~~~~~~~~~~~~
In file included from arch/x86/include/asm/current.h:5,
                 from include/linux/sched.h:12,
                 from include/linux/ratelimit.h:6,
                 from fs/dcache.c:18:
include/linux/compiler.h:280:2: note: called from here
  kasan_check_read(addr, 1);
  ^~~~~~~~~~~~~~~~~~~~~~~~~

While I have no idea why it does this, but changing the call to the
internal __kasan_check_read() fixes the issue.

Fixes: dc55b51f312c ("mm/kasan: introduce __kasan_check_{read,write}")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 include/linux/compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index f0fd5636fddb..22909500ba1d 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -277,7 +277,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 static __no_kasan_or_inline
 unsigned long read_word_at_a_time(const void *addr)
 {
-	kasan_check_read(addr, 1);
+	__kasan_check_read(addr, 1);
 	return *(unsigned long *)addr;
 }
 
-- 
2.20.0


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

* Re: [PATCH] mm/kasan: fix kasan_check_read() compiler warning
  2019-07-09 18:35 [PATCH] mm/kasan: fix kasan_check_read() compiler warning Arnd Bergmann
@ 2019-07-09 18:46 ` Marco Elver
  2019-07-09 19:35   ` Arnd Bergmann
  2019-07-09 18:51 ` Nick Desaulniers
  1 sibling, 1 reply; 4+ messages in thread
From: Marco Elver @ 2019-07-09 18:46 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Andrew Morton, Mark Rutland, Andrey Ryabinin, Dmitry Vyukov,
	Alexander Potapenko, Andrey Konovalov, Christoph Lameter,
	Pekka Enberg, David Rientjes, Joonsoo Kim, Kees Cook,
	Stephen Rothwell, Luc Van Oostenryck, ndesaulniers, Miguel Ojeda,
	Ingo Molnar, Josh Poimboeuf, LKML

On Tue, 9 Jul 2019 at 20:36, Arnd Bergmann <arnd@arndb.de> wrote:
>
> The kasan_check_read() is marked 'inline', which usually includes
> the 'always_inline' attribute. In some configuration, gcc decides that
> it cannot inline this, causing a build failure:
>
> In file included from include/linux/compiler.h:257,
>                  from arch/x86/include/asm/current.h:5,
>                  from include/linux/sched.h:12,
>                  from include/linux/ratelimit.h:6,
>                  from fs/dcache.c:18:
> include/linux/compiler.h: In function 'read_word_at_a_time':
> include/linux/kasan-checks.h:31:20: error: inlining failed in call to always_inline 'kasan_check_read': function attribute mismatch
>  static inline bool kasan_check_read(const volatile void *p, unsigned int size)
>                     ^~~~~~~~~~~~~~~~
> In file included from arch/x86/include/asm/current.h:5,
>                  from include/linux/sched.h:12,
>                  from include/linux/ratelimit.h:6,
>                  from fs/dcache.c:18:
> include/linux/compiler.h:280:2: note: called from here
>   kasan_check_read(addr, 1);
>   ^~~~~~~~~~~~~~~~~~~~~~~~~
>
> While I have no idea why it does this, but changing the call to the
> internal __kasan_check_read() fixes the issue.

Thanks, this was fixed more generally in v5:
http://lkml.kernel.org/r/20190708170706.174189-1-elver@google.com

>
> Fixes: dc55b51f312c ("mm/kasan: introduce __kasan_check_{read,write}")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  include/linux/compiler.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index f0fd5636fddb..22909500ba1d 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -277,7 +277,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
>  static __no_kasan_or_inline
>  unsigned long read_word_at_a_time(const void *addr)
>  {
> -       kasan_check_read(addr, 1);
> +       __kasan_check_read(addr, 1);
>         return *(unsigned long *)addr;
>  }
>
> --
> 2.20.0
>

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

* Re: [PATCH] mm/kasan: fix kasan_check_read() compiler warning
  2019-07-09 18:35 [PATCH] mm/kasan: fix kasan_check_read() compiler warning Arnd Bergmann
  2019-07-09 18:46 ` Marco Elver
@ 2019-07-09 18:51 ` Nick Desaulniers
  1 sibling, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2019-07-09 18:51 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Andrew Morton, Marco Elver, Mark Rutland, Andrey Ryabinin,
	Dmitry Vyukov, Alexander Potapenko, Andrey Konovalov,
	Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Kees Cook, Stephen Rothwell, Luc Van Oostenryck, Miguel Ojeda,
	Ingo Molnar, Josh Poimboeuf, LKML

On Tue, Jul 9, 2019 at 11:36 AM Arnd Bergmann <arnd@arndb.de> wrote:
>
> The kasan_check_read() is marked 'inline', which usually includes
> the 'always_inline' attribute. In some configuration, gcc decides that
> it cannot inline this, causing a build failure:
>
> In file included from include/linux/compiler.h:257,
>                  from arch/x86/include/asm/current.h:5,
>                  from include/linux/sched.h:12,
>                  from include/linux/ratelimit.h:6,
>                  from fs/dcache.c:18:
> include/linux/compiler.h: In function 'read_word_at_a_time':
> include/linux/kasan-checks.h:31:20: error: inlining failed in call to always_inline 'kasan_check_read': function attribute mismatch

Sounds like the error `function attribute mismatch` is saying:
kasan_check_read has one set of function attributes, but the call site
read_word_at_a_time has different function attributes, so I wont
inline kasan_check_read into read_word_at_a_time.
__no_kasan_or_inline changes based on CONFIG_KASAN; was this from a
kasan build or not?

>  static inline bool kasan_check_read(const volatile void *p, unsigned int size)
>                     ^~~~~~~~~~~~~~~~
> In file included from arch/x86/include/asm/current.h:5,
>                  from include/linux/sched.h:12,
>                  from include/linux/ratelimit.h:6,
>                  from fs/dcache.c:18:
> include/linux/compiler.h:280:2: note: called from here
>   kasan_check_read(addr, 1);
>   ^~~~~~~~~~~~~~~~~~~~~~~~~
>
> While I have no idea why it does this, but changing the call to the
> internal __kasan_check_read() fixes the issue.
>
> Fixes: dc55b51f312c ("mm/kasan: introduce __kasan_check_{read,write}")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  include/linux/compiler.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index f0fd5636fddb..22909500ba1d 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -277,7 +277,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
>  static __no_kasan_or_inline
>  unsigned long read_word_at_a_time(const void *addr)
>  {
> -       kasan_check_read(addr, 1);
> +       __kasan_check_read(addr, 1);
>         return *(unsigned long *)addr;
>  }
>
> --
> 2.20.0
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] mm/kasan: fix kasan_check_read() compiler warning
  2019-07-09 18:46 ` Marco Elver
@ 2019-07-09 19:35   ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2019-07-09 19:35 UTC (permalink / raw)
  To: Marco Elver
  Cc: Andrew Morton, Mark Rutland, Andrey Ryabinin, Dmitry Vyukov,
	Alexander Potapenko, Andrey Konovalov, Christoph Lameter,
	Pekka Enberg, David Rientjes, Joonsoo Kim, Kees Cook,
	Stephen Rothwell, Luc Van Oostenryck, ndesaulniers, Miguel Ojeda,
	Ingo Molnar, Josh Poimboeuf, LKML

On Tue, Jul 9, 2019 at 8:46 PM Marco Elver <elver@google.com> wrote:
>
> On Tue, 9 Jul 2019 at 20:36, Arnd Bergmann <arnd@arndb.de> wrote:
> >
> > The kasan_check_read() is marked 'inline', which usually includes
> > the 'always_inline' attribute. In some configuration, gcc decides that
> > it cannot inline this, causing a build failure:
> >
> > In file included from include/linux/compiler.h:257,
> >                  from arch/x86/include/asm/current.h:5,
> >                  from include/linux/sched.h:12,
> >                  from include/linux/ratelimit.h:6,
> >                  from fs/dcache.c:18:
> > include/linux/compiler.h: In function 'read_word_at_a_time':
> > include/linux/kasan-checks.h:31:20: error: inlining failed in call to always_inline 'kasan_check_read': function attribute mismatch
> >  static inline bool kasan_check_read(const volatile void *p, unsigned int size)
> >                     ^~~~~~~~~~~~~~~~
> > In file included from arch/x86/include/asm/current.h:5,
> >                  from include/linux/sched.h:12,
> >                  from include/linux/ratelimit.h:6,
> >                  from fs/dcache.c:18:
> > include/linux/compiler.h:280:2: note: called from here
> >   kasan_check_read(addr, 1);
> >   ^~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > While I have no idea why it does this, but changing the call to the
> > internal __kasan_check_read() fixes the issue.
>
> Thanks, this was fixed more generally in v5:
> http://lkml.kernel.org/r/20190708170706.174189-1-elver@google.com

Ok, that looks like a better solution indeed. I tried something
similar at first but got it wrong.

      Arnd

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

end of thread, other threads:[~2019-07-09 19:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-09 18:35 [PATCH] mm/kasan: fix kasan_check_read() compiler warning Arnd Bergmann
2019-07-09 18:46 ` Marco Elver
2019-07-09 19:35   ` Arnd Bergmann
2019-07-09 18:51 ` Nick Desaulniers

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).