]> git.baikalelectronics.ru Git - kernel.git/commit
net: skb: prevent the split of kfree_skb_reason() by gcc
authorMenglong Dong <imagedong@tencent.com>
Sun, 21 Aug 2022 05:18:58 +0000 (13:18 +0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 24 Aug 2022 08:47:51 +0000 (09:47 +0100)
commitd269e798d1bf3957cc69a778b93610235a2661b3
tree3d3bef30360bef6fa79771d761fa2b1a21803eed
parentf559b1f4fd29310d699a6a2601c3bffbbd867810
net: skb: prevent the split of kfree_skb_reason() by gcc

Sometimes, gcc will optimize the function by spliting it to two or
more functions. In this case, kfree_skb_reason() is splited to
kfree_skb_reason and kfree_skb_reason.part.0. However, the
function/tracepoint trace_kfree_skb() in it needs the return address
of kfree_skb_reason().

This split makes the call chains becomes:
  kfree_skb_reason() -> kfree_skb_reason.part.0 -> trace_kfree_skb()

which makes the return address that passed to trace_kfree_skb() be
kfree_skb().

Therefore, introduce '__fix_address', which is the combination of
'__noclone' and 'noinline', and apply it to kfree_skb_reason() to
prevent to from being splited or made inline.

(Is it better to simply apply '__noclone oninline' to kfree_skb_reason?
I'm thinking maybe other functions have the same problems)

Meanwhile, wrap 'skb_unref()' with 'unlikely()', as the compiler thinks
it is likely return true and splits kfree_skb_reason().

Signed-off-by: Menglong Dong <imagedong@tencent.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/compiler_attributes.h
include/linux/skbuff.h
net/core/skbuff.c