[PATCH] arm: Define arch_is_kernel_initmem_freed() for lockdep
From: Jan Kardell
Date: Mon Mar 29 2021 - 13:54:16 EST
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@xxxxxxxxxxxxx>
Signed-off-by: Jan Kardell <jan.kardell@xxxxxxxxxx>
---
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