2021-05-14 19:26:13

by Marco Elver

[permalink] [raw]
Subject: Re: [PATCH] kcsan: fix debugfs initcall return type

On Fri, 14 May 2021 at 16:10, Greg Kroah-Hartman
<[email protected]> wrote:
> On Fri, May 14, 2021 at 04:00:08PM +0200, Arnd Bergmann wrote:
> > From: Arnd Bergmann <[email protected]>
> >
> > clang points out that an initcall funciton should return an 'int':
> >
> > kernel/kcsan/debugfs.c:274:15: error: returning 'void' from a function with incompatible result type 'int'
> > late_initcall(kcsan_debugfs_init);
> > ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
> > include/linux/init.h:292:46: note: expanded from macro 'late_initcall'
> > #define late_initcall(fn) __define_initcall(fn, 7)
> >
> > Fixes: e36299efe7d7 ("kcsan, debugfs: Move debugfs file creation out of early init")
> > Signed-off-by: Arnd Bergmann <[email protected]>
[...]
> >
> Reviewed-by: Greg Kroah-Hartman <[email protected]>

Reviewed-by: Marco Elver <[email protected]>

Thanks for catching this -- it boggles my mind why gcc nor clang
wouldn't warn about this by default...
Is this a new clang?

Paul, please also add a "Cc: stable <[email protected]>" because
e36299efe7d7 is, too.

Thanks,
-- Marco


2021-05-14 19:31:56

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH] kcsan: fix debugfs initcall return type

On Fri, May 14, 2021 at 4:45 PM 'Marco Elver' via Clang Built Linux
<[email protected]> wrote:
> On Fri, 14 May 2021 at 16:10, Greg Kroah-Hartman
> <[email protected]> wrote:
> > On Fri, May 14, 2021 at 04:00:08PM +0200, Arnd Bergmann wrote:
> > > From: Arnd Bergmann <[email protected]>
> > >
> > > clang points out that an initcall funciton should return an 'int':
> > >
> > > kernel/kcsan/debugfs.c:274:15: error: returning 'void' from a function with incompatible result type 'int'
> > > late_initcall(kcsan_debugfs_init);
> > > ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
> > > include/linux/init.h:292:46: note: expanded from macro 'late_initcall'
> > > #define late_initcall(fn) __define_initcall(fn, 7)
> > >
> > > Fixes: e36299efe7d7 ("kcsan, debugfs: Move debugfs file creation out of early init")
> > > Signed-off-by: Arnd Bergmann <[email protected]>
> [...]
> > >
> > Reviewed-by: Greg Kroah-Hartman <[email protected]>
>
> Reviewed-by: Marco Elver <[email protected]>
>
> Thanks for catching this -- it boggles my mind why gcc nor clang
> wouldn't warn about this by default...
> Is this a new clang?

It was clang-13, not sure if that made a difference.

Arnd

2021-05-15 07:11:47

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] kcsan: fix debugfs initcall return type

On 5/14/2021 7:45 AM, Marco Elver wrote:
> On Fri, 14 May 2021 at 16:10, Greg Kroah-Hartman
> <[email protected]> wrote:
>> On Fri, May 14, 2021 at 04:00:08PM +0200, Arnd Bergmann wrote:
>>> From: Arnd Bergmann <[email protected]>
>>>
>>> clang points out that an initcall funciton should return an 'int':
>>>
>>> kernel/kcsan/debugfs.c:274:15: error: returning 'void' from a function with incompatible result type 'int'
>>> late_initcall(kcsan_debugfs_init);
>>> ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
>>> include/linux/init.h:292:46: note: expanded from macro 'late_initcall'
>>> #define late_initcall(fn) __define_initcall(fn, 7)
>>>
>>> Fixes: e36299efe7d7 ("kcsan, debugfs: Move debugfs file creation out of early init")
>>> Signed-off-by: Arnd Bergmann <[email protected]>
> [...]
>>>
>> Reviewed-by: Greg Kroah-Hartman <[email protected]>
>
> Reviewed-by: Marco Elver <[email protected]>
>
> Thanks for catching this -- it boggles my mind why gcc nor clang
> wouldn't warn about this by default...
> Is this a new clang?

KCSAN appears to only support x86_64, which also selects
HAVE_ARCH_PREL32_RELOCATIONS, meaning that the initcalls never have
their types validated because there is no assignment:

https://elixir.bootlin.com/linux/v5.12.4/source/include/linux/init.h#L240

In the case of CONFIG_LTO_CLANG, the initcall function is called in the
stub function, resulting in the error that we see here.

Hopefully that makes sense :)

Cheers,
Nathan