linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: Fix static memory detection
@ 2020-01-31  2:11 Guenter Roeck
  2020-03-17 13:44 ` Guenter Roeck
  2020-03-19 14:17 ` [tip: x86/boot] x86/setup: " tip-bot2 for Guenter Roeck
  0 siblings, 2 replies; 3+ messages in thread
From: Guenter Roeck @ 2020-01-31  2:11 UTC (permalink / raw)
  To: x86
  Cc: Thomas Gleixner, Ingo Molnar, linux-kernel, Borislav Petkov,
	H . Peter Anvin, Guenter Roeck

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 7a5da02de8d6e
("locking/lockdep: check for freed initmem in static_obj()"), which
introduced arch_is_kernel_initmem_freed().

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 arch/x86/include/asm/sections.h | 20 ++++++++++++++++++++
 arch/x86/kernel/setup.c         |  1 -
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h
index 036c360910c5..a6e8373a5170 100644
--- a/arch/x86/include/asm/sections.h
+++ b/arch/x86/include/asm/sections.h
@@ -2,6 +2,8 @@
 #ifndef _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/extable.h>
 
@@ -14,4 +16,22 @@ extern char __end_rodata_hpage_align[];
 
 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 */
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 1e4c20a1efec..08f5ceed70e0 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -64,7 +64,6 @@ RESERVE_BRK(dmi_alloc, 65536);
  * at link time, with RESERVE_BRK*() facility reserving additional
  * chunks.
  */
-static __initdata
 unsigned long _brk_start = (unsigned long)__brk_base;
 unsigned long _brk_end   = (unsigned long)__brk_base;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86: Fix static memory detection
  2020-01-31  2:11 [PATCH] x86: Fix static memory detection Guenter Roeck
@ 2020-03-17 13:44 ` Guenter Roeck
  2020-03-19 14:17 ` [tip: x86/boot] x86/setup: " tip-bot2 for Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2020-03-17 13:44 UTC (permalink / raw)
  To: x86
  Cc: Thomas Gleixner, Ingo Molnar, linux-kernel, Borislav Petkov,
	H . Peter Anvin

ping ... I still see this problem.

Guenter

On Thu, Jan 30, 2020 at 06:11:59PM -0800, Guenter Roeck wrote:
> 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 7a5da02de8d6e
> ("locking/lockdep: check for freed initmem in static_obj()"), which
> introduced arch_is_kernel_initmem_freed().
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
>  arch/x86/include/asm/sections.h | 20 ++++++++++++++++++++
>  arch/x86/kernel/setup.c         |  1 -
>  2 files changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h
> index 036c360910c5..a6e8373a5170 100644
> --- a/arch/x86/include/asm/sections.h
> +++ b/arch/x86/include/asm/sections.h
> @@ -2,6 +2,8 @@
>  #ifndef _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/extable.h>
>  
> @@ -14,4 +16,22 @@ extern char __end_rodata_hpage_align[];
>  
>  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 */
> diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> index 1e4c20a1efec..08f5ceed70e0 100644
> --- a/arch/x86/kernel/setup.c
> +++ b/arch/x86/kernel/setup.c
> @@ -64,7 +64,6 @@ RESERVE_BRK(dmi_alloc, 65536);
>   * at link time, with RESERVE_BRK*() facility reserving additional
>   * chunks.
>   */
> -static __initdata
>  unsigned long _brk_start = (unsigned long)__brk_base;
>  unsigned long _brk_end   = (unsigned long)__brk_base;
>  

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: x86/boot] x86/setup: Fix static memory detection
  2020-01-31  2:11 [PATCH] x86: Fix static memory detection Guenter Roeck
  2020-03-17 13:44 ` Guenter Roeck
@ 2020-03-19 14:17 ` tip-bot2 for Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Guenter Roeck @ 2020-03-19 14:17 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Guenter Roeck, Borislav Petkov, Peter Zijlstra, x86, LKML

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     bac59d18c7018a2fd5e800a1e72a8271bf404977
Gitweb:        https://git.kernel.org/tip/bac59d18c7018a2fd5e800a1e72a8271bf404977
Author:        Guenter Roeck <linux@roeck-us.net>
AuthorDate:    Thu, 30 Jan 2020 18:11:59 -08:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Thu, 19 Mar 2020 11:58:13 +01:00

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

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

which introduced arch_is_kernel_initmem_freed().

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200131021159.9178-1-linux@roeck-us.net
---
 arch/x86/include/asm/sections.h | 20 ++++++++++++++++++++
 arch/x86/kernel/setup.c         |  1 -
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h
index 036c360..a6e8373 100644
--- a/arch/x86/include/asm/sections.h
+++ b/arch/x86/include/asm/sections.h
@@ -2,6 +2,8 @@
 #ifndef _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/extable.h>
 
@@ -14,4 +16,22 @@ extern char __end_rodata_hpage_align[];
 
 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 */
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index a74262c..e6b5450 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -64,7 +64,6 @@ RESERVE_BRK(dmi_alloc, 65536);
  * at link time, with RESERVE_BRK*() facility reserving additional
  * chunks.
  */
-static __initdata
 unsigned long _brk_start = (unsigned long)__brk_base;
 unsigned long _brk_end   = (unsigned long)__brk_base;
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-19 14:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-31  2:11 [PATCH] x86: Fix static memory detection Guenter Roeck
2020-03-17 13:44 ` Guenter Roeck
2020-03-19 14:17 ` [tip: x86/boot] x86/setup: " tip-bot2 for Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).