Re: [PATCH 2/2 V2] livepatch: handle kzalloc failure properly

From: Josh Poimboeuf
Date: Thu Dec 13 2018 - 15:50:07 EST


On Thu, Dec 13, 2018 at 03:39:20PM -0500, Joe Lawrence wrote:
> Ahh, I understand the question now. Yeah, by making those routines local
> static, the compiler applied optimizations that renamed the symbols:
>
> noinline static
> % readelf --syms samples/livepatch/livepatch-shadow-mod.o | grep dummy_
> 5: 0000000000000000 20 FUNC LOCAL DEFAULT 1 dummy_check.isra.0
> 7: 0000000000000020 52 FUNC LOCAL DEFAULT 1 dummy_free.constprop.1
> 12: 00000000000000c0 32 OBJECT LOCAL DEFAULT 3 dummy_list_mutex
> 13: 00000000000000e0 16 OBJECT LOCAL DEFAULT 3 dummy_list
> 15: 0000000000000160 115 FUNC LOCAL DEFAULT 1 dummy_alloc
>
>
> I can avoid that optimization (and successfully load all the modules)
> by using either:
>
> __attribute__((optimize("O0"))) noinline static
> % readelf --syms samples/livepatch/livepatch-shadow-mod.o | grep dummy_
> 6: 0000000000000000 6016 FUNC LOCAL DEFAULT 1 dummy_alloc
> 11: 00000000000000c0 32 OBJECT LOCAL DEFAULT 3 dummy_list_mutex
> 12: 00000000000000e0 16 OBJECT LOCAL DEFAULT 3 dummy_list
> 14: 0000000000001810 73 FUNC LOCAL DEFAULT 1 dummy_free
> 16: 0000000000001860 108 FUNC LOCAL DEFAULT 1 dummy_check
>
> or:
>
> __noclone noinline static
> % readelf --syms samples/livepatch/livepatch-shadow-mod.o | grep dummy_
> 5: 0000000000000000 22 FUNC LOCAL DEFAULT 1 dummy_check
> 7: 0000000000000020 51 FUNC LOCAL DEFAULT 1 dummy_free
> 12: 00000000000000c0 32 OBJECT LOCAL DEFAULT 3 dummy_list_mutex
> 13: 00000000000000e0 16 OBJECT LOCAL DEFAULT 3 dummy_list
> 15: 0000000000000160 115 FUNC LOCAL DEFAULT 1 dummy_alloc
>
> but I'm not sure if either is the definitive way to avoid such
> optimization. Anyone know for sure?

Yeah, for now I think "static __noclone" is the way to go. Soon we'll
have a GCC flag which disables such optimizations for all functions.

And the dummy_list* variables can just be "static".

--
Josh