linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm: Define arch_is_kernel_initmem_freed() for lockdep
@ 2021-03-29 17:53 Jan Kardell
  2021-06-15 14:35 ` Jan Kardell
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kardell @ 2021-03-29 17:53 UTC (permalink / raw)
  To: Linux ARM; +Cc: linux-kernel, Russell King, linux-omap, Andrew Morton, linux-mm

This fixes the warning:

WARNING: CPU: 0 PID: 1994 at kernel/locking/lockdep.c:1119 alloc_netdev_mqs+0xb4/0x3b0

This warning is because the check in static_obj() assumes that all
memory within [_stext, _end] belongs to static objects. The init
section is also part of this range, and freeing it allows the buddy
allocator to allocate memory from it.

To fix this, define arch_is_kernel_initmem_freed() for arm, it will
return 1 if initmem has been freed and the address is in the range
[__init_begin, __init_end], and this function is called by the
static_obj() function in lockdep.

Tested on TI am3352 (Cortex A8).

This change is modelled after commit 7a5da02de8d6eafba995
("locking/lockdep: check for freed initmem in static_obj()") for s390 by
Gerald Schaefer <gerald.schaefer@linux.ibm.com>

Signed-off-by: Jan Kardell <jan.kardell@telliq.com>
---
 arch/arm/include/asm/sections.h | 13 +++++++++++++
 arch/arm/mm/init.c              |  6 +++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/sections.h b/arch/arm/include/asm/sections.h
index 700b8bcdf9bd..1dd64c90c1ac 100644
--- a/arch/arm/include/asm/sections.h
+++ b/arch/arm/include/asm/sections.h
@@ -2,6 +2,8 @@
 #ifndef _ASM_ARM_SECTIONS_H
 #define _ASM_ARM_SECTIONS_H
 
+#define arch_is_kernel_initmem_freed arch_is_kernel_initmem_freed
+
 #include <asm-generic/sections.h>
 
 extern char _exiprom[];
@@ -11,6 +13,17 @@ extern char __idmap_text_end[];
 extern char __entry_text_start[];
 extern char __entry_text_end[];
 
+extern bool initmem_freed;
+
+static inline int arch_is_kernel_initmem_freed(unsigned long addr)
+{
+	if (!initmem_freed)
+		return 0;
+	return addr >= (unsigned long)__init_begin &&
+	       addr < (unsigned long)__init_end;
+}
+
+
 static inline bool in_entry_text(unsigned long addr)
 {
 	return memory_contains(__entry_text_start, __entry_text_end,
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index 828a2561b229..cd7a4273797a 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -41,6 +41,8 @@
 
 #include "mm.h"
 
+bool initmem_freed;
+
 #ifdef CONFIG_CPU_CP15_MMU
 unsigned long __init __clear_cr(unsigned long mask)
 {
@@ -523,8 +525,10 @@ void free_initmem(void)
 	fix_kernmem_perms();
 
 	poison_init_mem(__init_begin, __init_end - __init_begin);
-	if (!machine_is_integrator() && !machine_is_cintegrator())
+	if (!machine_is_integrator() && !machine_is_cintegrator()) {
+		initmem_freed = true;
 		free_initmem_default(-1);
+	}
 }
 
 #ifdef CONFIG_BLK_DEV_INITRD
-- 
2.26.2



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

end of thread, other threads:[~2021-06-15 14:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-29 17:53 [PATCH] arm: Define arch_is_kernel_initmem_freed() for lockdep Jan Kardell
2021-06-15 14:35 ` Jan Kardell

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).