Linux-OMAP Archive on lore.kernel.org
 help / color / 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	[flat|nested] 2+ messages in thread

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

A ping on this as there is no reply yet. I'm not entirely sure who 
should be on the CC list, or maybe this patch is just forgotten for some 
reason, maybe I should have written a better subject? I don't mean to 
complain, I do know that core developers are very busy!

//Jan

Jan Kardell skrev:
> 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


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

end of thread, back to index

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

Linux-OMAP Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-omap/0 linux-omap/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-omap linux-omap/ https://lore.kernel.org/linux-omap \
		linux-omap@vger.kernel.org
	public-inbox-index linux-omap

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-omap


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git