core_kernel_text() considers that until system_state in at least
SYSTEM_RUNNING, init memory is valid.
But init memory is freed a few lines before setting SYSTEM_RUNNING,
so we have a small period of time when core_kernel_text() is wrong.
Create an intermediate system state called SYSTEM_FREEING_INIT that
is set before starting freeing init memory, and use it in
core_kernel_text() to report init memory invalid earlier.
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Christophe Leroy <redacted>
---
v2: New
---
include/linux/kernel.h | 1 +
init/main.c | 2 ++
kernel/extable.c | 2 +-
3 files changed, 4 insertions(+), 1 deletion(-)
@@ -1505,6 +1505,8 @@ static int __ref kernel_init(void *unused)kernel_init_freeable();/* need to finish all async __init code before freeing the memory */async_synchronize_full();++system_state=SYSTEM_FREEING_INITMEM;kprobe_free_init_mem();ftrace_free_init_mem();kgdb_free_init_mem();
@@ -76,7 +76,7 @@ int notrace core_kernel_text(unsigned long addr)addr<(unsignedlong)_etext)return1;-if(system_state<SYSTEM_RUNNING&&+if(system_state<SYSTEM_FREEING_INITMEM&&init_kernel_text(addr))return1;return0;
Generic version of arch_is_kernel_initmem_freed() now does the same
as s390 version.
Remove the s390 version.
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Christophe Leroy <redacted>
---
v2: No change
---
arch/s390/include/asm/sections.h | 12 ------------
arch/s390/mm/init.c | 3 ---
2 files changed, 15 deletions(-)
Generic version of arch_is_kernel_initmem_freed() now does the same
as powerpc version.
Remove the powerpc version.
Signed-off-by: Christophe Leroy <redacted>
---
v2: No change
---
arch/powerpc/include/asm/sections.h | 13 -------------
1 file changed, 13 deletions(-)
Commit 7a5da02de8d6 ("locking/lockdep: check for freed initmem in
static_obj()") added arch_is_kernel_initmem_freed() which is supposed
to report whether an object is part of already freed init memory.
For the time being, the generic version of arch_is_kernel_initmem_freed()
always reports 'false', allthough free_initmem() is generically called
on all architectures.
Therefore, change the generic version of arch_is_kernel_initmem_freed()
to check whether free_initmem() has been called. If so, then check
if a given address falls into init memory.
In order to use function init_section_contains(), the fonction is
moved at the end of asm-generic/section.h
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Christophe Leroy <redacted>
---
v2: Change to using the new SYSTEM_FREEING_INITMEM state
---
include/asm-generic/sections.h | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
On Tue, Sep 28, 2021 at 09:15:37AM +0200, Christophe Leroy wrote:
Generic version of arch_is_kernel_initmem_freed() now does the same
as s390 version.
Remove the s390 version.
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Christophe Leroy <redacted>
---
v2: No change
---
arch/s390/include/asm/sections.h | 12 ------------
arch/s390/mm/init.c | 3 ---
2 files changed, 15 deletions(-)
Looks good. Thanks for cleaning this up!
Acked-by: Heiko Carstens <hca@linux.ibm.com>
Commit 7a5da02de8d6 ("locking/lockdep: check for freed initmem in
static_obj()") added arch_is_kernel_initmem_freed() which is supposed
to report whether an object is part of already freed init memory.
For the time being, the generic version of arch_is_kernel_initmem_freed()
always reports 'false', allthough free_initmem() is generically called
on all architectures.
Therefore, change the generic version of arch_is_kernel_initmem_freed()
to check whether free_initmem() has been called. If so, then check
if a given address falls into init memory.
In order to use function init_section_contains(), the fonction is
moved at the end of asm-generic/section.h
i386 allmodconfig:
In file included from arch/x86/platform/intel-quark/imr.c:28:
./include/asm-generic/sections.h: In function 'arch_is_kernel_initmem_freed':
./include/asm-generic/sections.h:171:6: error: 'system_state' undeclared (first use in this function)
171 | if (system_state < SYSTEM_FREEING_INITMEM)
| ^~~~~~~~~~~~
./include/asm-generic/sections.h:171:6: note: each undeclared identifier is reported only once for each function it appears in
./include/asm-generic/sections.h:171:21: error: 'SYSTEM_FREEING_INITMEM' undeclared (first use in this function)
171 | if (system_state < SYSTEM_FREEING_INITMEM)
| ^~~~~~~~~~~~~~~~~~~~~~
I don't think it would be a good idea to include kernel.h from
sections.h - it's unclear to me which is the "innermost" of those two.
It would be better to uninline arch_is_kernel_initmem_freed(). Surely
there's no real reason for inlining it?
Anyway, I'll drop the series for now.