Skip to content

Commit e5ae372

Browse files
chleroytorvalds
authored andcommitted
mm: make generic arch_is_kernel_initmem_freed() do what it says
Commit 7a5da02 ("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. To ease the use of system_state, move it out of line into its only caller which is lockdep.c Link: https://lkml.kernel.org/r/1d40783e676e07858be97d881f449ee7ea8adfb1.1633001016.git.christophe.leroy@csgroup.eu Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Paul Mackerras <paulus@ozlabs.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d2635f2 commit e5ae372

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

‎include/asm-generic/sections.h‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,6 @@ static inline int arch_is_kernel_data(unsigned long addr)
8080
}
8181
#endif
8282

83-
/*
84-
* Check if an address is part of freed initmem. This is needed on architectures
85-
* with virt == phys kernel mapping, for code that wants to check if an address
86-
* is part of a static object within [_stext, _end]. After initmem is freed,
87-
* memory can be allocated from it, and such allocations would then have
88-
* addresses within the range [_stext, _end].
89-
*/
90-
#ifndef arch_is_kernel_initmem_freed
91-
static inline int arch_is_kernel_initmem_freed(unsigned long addr)
92-
{
93-
return 0;
94-
}
95-
#endif
96-
9783
/**
9884
* memory_contains - checks if an object is contained within a memory region
9985
* @begin: virtual address of the beginning of the memory region

‎kernel/locking/lockdep.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,21 @@ static int very_verbose(struct lock_class *class)
788788
* Is this the address of a static object:
789789
*/
790790
#ifdef __KERNEL__
791+
/*
792+
* Check if an address is part of freed initmem. After initmem is freed,
793+
* memory can be allocated from it, and such allocations would then have
794+
* addresses within the range [_stext, _end].
795+
*/
796+
#ifndef arch_is_kernel_initmem_freed
797+
static int arch_is_kernel_initmem_freed(unsigned long addr)
798+
{
799+
if (system_state < SYSTEM_FREEING_INITMEM)
800+
return 0;
801+
802+
return init_section_contains((void *)addr, 1);
803+
}
804+
#endif
805+
791806
static int static_obj(const void *obj)
792807
{
793808
unsigned long start = (unsigned long) &_stext,

0 commit comments

Comments
 (0)