Skip to content

Commit 0a6b58c

Browse files
hdellerakpm00
authored andcommitted
lockdep: fix static memory detection even more
On the parisc architecture, lockdep reports for all static objects which are in the __initdata section (e.g. "setup_done" in devtmpfs, "kthreadd_done" in init/main.c) this warning: INFO: trying to register non-static key. The warning itself is wrong, because those objects are in the __initdata section, but the section itself is on parisc outside of range from _stext to _end, which is why the static_obj() functions returns a wrong answer. While fixing this issue, I noticed that the whole existing check can be simplified a lot. Instead of checking against the _stext and _end symbols (which include code areas too) just check for the .data and .bss segments (since we check a data object). This can be done with the existing is_kernel_core_data() macro. In addition objects in the __initdata section can be checked with init_section_contains(), and is_kernel_rodata() allows keys to be in the _ro_after_init section. This partly reverts and simplifies commit bac59d1 ("x86/setup: Fix static memory detection"). Link: https://lkml.kernel.org/r/ZNqrLRaOi/3wPAdp@p100 Fixes: bac59d1 ("x86/setup: Fix static memory detection") Signed-off-by: Helge Deller <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: "Rafael J. Wysocki" <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 6655360 commit 0a6b58c

File tree

2 files changed

+14
-40
lines changed

2 files changed

+14
-40
lines changed

arch/x86/include/asm/sections.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#ifndef _ASM_X86_SECTIONS_H
33
#define _ASM_X86_SECTIONS_H
44

5-
#define arch_is_kernel_initmem_freed arch_is_kernel_initmem_freed
6-
75
#include <asm-generic/sections.h>
86
#include <asm/extable.h>
97

@@ -18,20 +16,4 @@ extern char __end_of_kernel_reserve[];
1816

1917
extern unsigned long _brk_start, _brk_end;
2018

21-
static inline bool arch_is_kernel_initmem_freed(unsigned long addr)
22-
{
23-
/*
24-
* If _brk_start has not been cleared, brk allocation is incomplete,
25-
* and we can not make assumptions about its use.
26-
*/
27-
if (_brk_start)
28-
return 0;
29-
30-
/*
31-
* After brk allocation is complete, space between _brk_end and _end
32-
* is available for allocation.
33-
*/
34-
return addr >= _brk_end && addr < (unsigned long)&_end;
35-
}
36-
3719
#endif /* _ASM_X86_SECTIONS_H */

kernel/locking/lockdep.c

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -819,34 +819,26 @@ static int very_verbose(struct lock_class *class)
819819
* Is this the address of a static object:
820820
*/
821821
#ifdef __KERNEL__
822-
/*
823-
* Check if an address is part of freed initmem. After initmem is freed,
824-
* memory can be allocated from it, and such allocations would then have
825-
* addresses within the range [_stext, _end].
826-
*/
827-
#ifndef arch_is_kernel_initmem_freed
828-
static int arch_is_kernel_initmem_freed(unsigned long addr)
829-
{
830-
if (system_state < SYSTEM_FREEING_INITMEM)
831-
return 0;
832-
833-
return init_section_contains((void *)addr, 1);
834-
}
835-
#endif
836-
837822
static int static_obj(const void *obj)
838823
{
839-
unsigned long start = (unsigned long) &_stext,
840-
end = (unsigned long) &_end,
841-
addr = (unsigned long) obj;
824+
unsigned long addr = (unsigned long) obj;
842825

843-
if (arch_is_kernel_initmem_freed(addr))
844-
return 0;
826+
if (is_kernel_core_data(addr))
827+
return 1;
828+
829+
/*
830+
* keys are allowed in the __ro_after_init section.
831+
*/
832+
if (is_kernel_rodata(addr))
833+
return 1;
845834

846835
/*
847-
* static variable?
836+
* in initdata section and used during bootup only?
837+
* NOTE: On some platforms the initdata section is
838+
* outside of the _stext ... _end range.
848839
*/
849-
if ((addr >= start) && (addr < end))
840+
if (system_state < SYSTEM_FREEING_INITMEM &&
841+
init_section_contains((void *)addr, 1))
850842
return 1;
851843

852844
/*

0 commit comments

Comments
 (0)