mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kardell <jan.kardell@telliq.com>
To: Linux ARM <linux-arm-kernel@lists.infradead.org>
Cc: linux-kernel@vger.kernel.org,
	Russell King <linux@armlinux.org.uk>,
	linux-omap@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org
Subject: [PATCH] arm: Define arch_is_kernel_initmem_freed() for lockdep
Date: Mon, 29 Mar 2021 19:53:18 +0200	[thread overview]
Message-ID: <20210329175318.21393-1-jan.kardell@telliq.com> (raw)

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


             reply	other threads:[~2021-03-29 17:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-29 17:53 Jan Kardell [this message]
2021-06-15 14:35 ` Jan Kardell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210329175318.21393-1-jan.kardell@telliq.com \
    --to=jan.kardell@telliq.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®