Skip to contentSkip to conversation

mm/kasan: fix kasan_check_read() compiler warning

PATCH In review Arnd Bergmann 3 participants 4 messages Jul 9, 2019 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/kasan: fix kasan_check_read() compiler warning

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}")
---
 include/linux/compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/compiler.h +1 -1
index f0fd5636fddb..22909500ba1d 100644
@@ -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;
 }
 
Signature · 1 line
2.20.0
#1 lore raw
Quoted 18 lines · Arnd Bergmann

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:
Quoted 6 lines

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/[email protected]

Quoted 23 lines
Fixes dc55b51f312c ("mm/kasan: introduce __kasan_check_{read,write}")
---
 include/linux/compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/compiler.h +1 -2
index f0fd5636fddb..22909500ba1d 100644
@@ -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

#2 lore raw
Quoted 24 lines · Marco Elver
Quoted 22 lines · Arnd Bergmann

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); ^~~~~~~~~~~~~~~~~~~~~~~~~

Quoted 5 lines
Quoted 2 lines

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/[email protected]

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

Arnd

#3 lore raw
In reply to Arnd Bergmann
Quoted 5 lines · Arnd Bergmann

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:

Quoted 7 lines

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?

Quoted 35 lines

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}")
---
 include/linux/compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/compiler.h +1 -2
index f0fd5636fddb..22909500ba1d 100644
@@ -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

Signature · 2 lines
Thanks,
~Nick Desaulniers