Re: [PATCH net-next v4] net: skb: prevent the split of kfree_skb_reason() by gcc

From: Menglong Dong
Date: Sat Aug 20 2022 - 07:01:00 EST


Hello,
On Fri, Aug 19, 2022 at 11:24 PM Segher Boessenkool
<segher@xxxxxxxxxxxxxxxxxxx> wrote:
>
> Hi!
>
> On Fri, Aug 19, 2022 at 10:55:42PM +0800, Menglong Dong wrote:
> > Thanks for your explanation about the usage of 'noinline' and 'no_icf'!
> > I think 'noclone' seems enough in this case? As the function
> > 'kfree_skb_reason' we talk about is a global function, I think that the
> > compiler has no reason to make it inline, or be merged with another
> > function.
>
> Whether something is inlined is decided per instance (except for
> always_inline and noinline functions). Of course the function body has
> to be available for anything to be inlined, so barring LTO this can only
> happen for function uses in the same source file. Not very likely
> indeed, but not entirely impossible either.
>

I understand it now, the global function is indeed possible to be
made inline by the compiler, and 'noinline' seems necessary
here too.

Maybe I can add a new compiler attribute like this:

/*
* Used by functions that use '__builtin_return_address'. These function
* don't want to be splited or made inline, which can make
* the '__builtin_return_address' got unexpected address.
*/
#define __fix_address noinline __noclone

> A function can be merged if there is another function that does exactly
> the same thing. This is unlikely with functions that do some serious
> work of course, but it is likely with stub-like functions.
>

I understand how 'icf'(Identical Code Folding) works now. In the case
we talk about, It seems fine even if the function is merged. The only
effect of 'icf' is the change of function name, which doesn't affect
the result of '__builtin_return_address(0)'.

Thanks!
Menglong Dong

> gl;hf,
>
>
> Segher