Skip to content

Commit bac59d1

Browse files
groecksuryasaimadhu
authored andcommitted
x86/setup: Fix static memory detection
When booting x86 images in qemu, the following warning is seen randomly if DEBUG_LOCKDEP is enabled. WARNING: CPU: 0 PID: 1 at kernel/locking/lockdep.c:1119 lockdep_register_key+0xc0/0x100 static_obj() returns true if an address is between _stext and _end. On x86, this includes the brk memory space. Problem is that this memory block is not static on x86; its unused portions are released after init and can be allocated. This results in the observed warning if a lockdep object is allocated from this memory. Solve the problem by implementing arch_is_kernel_initmem_freed() for x86 and have it return true if an address is within the released memory range. The same problem was solved for s390 with commit 7a5da02 ("locking/lockdep: check for freed initmem in static_obj()"), which introduced arch_is_kernel_initmem_freed(). Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 6f8f0dc commit bac59d1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

arch/x86/include/asm/sections.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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+
57
#include <asm-generic/sections.h>
68
#include <asm/extable.h>
79

@@ -14,4 +16,22 @@ extern char __end_rodata_hpage_align[];
1416

1517
extern char __end_of_kernel_reserve[];
1618

19+
extern unsigned long _brk_start, _brk_end;
20+
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+
1737
#endif /* _ASM_X86_SECTIONS_H */

arch/x86/kernel/setup.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ RESERVE_BRK(dmi_alloc, 65536);
6464
* at link time, with RESERVE_BRK*() facility reserving additional
6565
* chunks.
6666
*/
67-
static __initdata
6867
unsigned long _brk_start = (unsigned long)__brk_base;
6968
unsigned long _brk_end = (unsigned long)__brk_base;
7069

0 commit comments

Comments
 (0)