Commit bac59d18 authored by Guenter Roeck's avatar Guenter Roeck Committed by Borislav Petkov

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

  7a5da02d ("locking/lockdep: check for freed initmem in static_obj()"),

which introduced arch_is_kernel_initmem_freed().
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Acked-by: default avatarPeter Zijlstra <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200131021159.9178-1-linux@roeck-us.net
parent 6f8f0dc9
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#ifndef _ASM_X86_SECTIONS_H #ifndef _ASM_X86_SECTIONS_H
#define _ASM_X86_SECTIONS_H #define _ASM_X86_SECTIONS_H
#define arch_is_kernel_initmem_freed arch_is_kernel_initmem_freed
#include <asm-generic/sections.h> #include <asm-generic/sections.h>
#include <asm/extable.h> #include <asm/extable.h>
...@@ -14,4 +16,22 @@ extern char __end_rodata_hpage_align[]; ...@@ -14,4 +16,22 @@ extern char __end_rodata_hpage_align[];
extern char __end_of_kernel_reserve[]; extern char __end_of_kernel_reserve[];
extern unsigned long _brk_start, _brk_end;
static inline bool arch_is_kernel_initmem_freed(unsigned long addr)
{
/*
* If _brk_start has not been cleared, brk allocation is incomplete,
* and we can not make assumptions about its use.
*/
if (_brk_start)
return 0;
/*
* After brk allocation is complete, space between _brk_end and _end
* is available for allocation.
*/
return addr >= _brk_end && addr < (unsigned long)&_end;
}
#endif /* _ASM_X86_SECTIONS_H */ #endif /* _ASM_X86_SECTIONS_H */
...@@ -64,7 +64,6 @@ RESERVE_BRK(dmi_alloc, 65536); ...@@ -64,7 +64,6 @@ RESERVE_BRK(dmi_alloc, 65536);
* at link time, with RESERVE_BRK*() facility reserving additional * at link time, with RESERVE_BRK*() facility reserving additional
* chunks. * chunks.
*/ */
static __initdata
unsigned long _brk_start = (unsigned long)__brk_base; unsigned long _brk_start = (unsigned long)__brk_base;
unsigned long _brk_end = (unsigned long)__brk_base; unsigned long _brk_end = (unsigned long)__brk_base;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment