All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mm: disable kernelcore=mirror when no mirror memory
@ 2023-08-02  7:23 Wupeng Ma
  2023-08-02 18:44 ` Mike Rapoport
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Wupeng Ma @ 2023-08-02  7:23 UTC (permalink / raw)
  To: akpm, rppt, wangkefeng.wang; +Cc: linux-mm, mawupeng1

From: Ma Wupeng <mawupeng1@huawei.com>

For system with kernelcore=mirror enabled while no mirrored memory is
reported by efi. This could lead to kernel OOM during startup since
all memory beside zone DMA are in the movable zone and this prevents
the kernel to use it.

Zone DMA/DMA32 initialization is independent of mirrored memory and
their max pfn is set in zone_sizes_init(). Since kernel can fallback
to zone DMA/DMA32 if there is no memory in zone Normal, these zones
are seen as mirrored memory no mather their memory attributes are.

To solve this problem, disable kernelcore=mirror when there is no real
mirrored memory exists.

Suggested-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Suggested-by: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 mm/internal.h | 1 +
 mm/memblock.c | 5 +++++
 mm/mm_init.c  | 5 +++++
 3 files changed, 11 insertions(+)

diff --git a/mm/internal.h b/mm/internal.h
index a7d9e980429a..b8aaf9cac87e 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -1005,6 +1005,7 @@ static inline bool gup_must_unshare(struct vm_area_struct *vma,
 }
 
 extern bool mirrored_kernelcore;
+extern bool memblock_has_mirror(void);
 
 static inline bool vma_soft_dirty_enabled(struct vm_area_struct *vma)
 {
diff --git a/mm/memblock.c b/mm/memblock.c
index f9e61e565a53..913b2520a9a0 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -161,6 +161,11 @@ static int memblock_can_resize __initdata_memblock;
 static int memblock_memory_in_slab __initdata_memblock;
 static int memblock_reserved_in_slab __initdata_memblock;
 
+bool __init_memblock memblock_has_mirror(void)
+{
+	return system_has_some_mirror;
+}
+
 static enum memblock_flags __init_memblock choose_memblock_flags(void)
 {
 	return system_has_some_mirror ? MEMBLOCK_MIRROR : MEMBLOCK_NONE;
diff --git a/mm/mm_init.c b/mm/mm_init.c
index a1963c3322af..e8af1b628430 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -377,6 +377,11 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 	if (mirrored_kernelcore) {
 		bool mem_below_4gb_not_mirrored = false;
 
+		if (!memblock_has_mirror()) {
+			pr_warn("The system has no mirror memory, ignore kernelcore=mirror.\n");
+			goto out;
+		}
+
 		for_each_mem_region(r) {
 			if (memblock_is_mirror(r))
 				continue;
-- 
2.25.1



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

* Re: [PATCH v2] mm: disable kernelcore=mirror when no mirror memory
  2023-08-02  7:23 [PATCH v2] mm: disable kernelcore=mirror when no mirror memory Wupeng Ma
@ 2023-08-02 18:44 ` Mike Rapoport
  2023-08-03  3:06 ` Kefeng Wang
  2023-08-03 17:53 ` Andrew Morton
  2 siblings, 0 replies; 6+ messages in thread
From: Mike Rapoport @ 2023-08-02 18:44 UTC (permalink / raw)
  To: Wupeng Ma; +Cc: akpm, wangkefeng.wang, linux-mm

On Wed, Aug 02, 2023 at 03:23:28PM +0800, Wupeng Ma wrote:
> From: Ma Wupeng <mawupeng1@huawei.com>
> 
> For system with kernelcore=mirror enabled while no mirrored memory is
> reported by efi. This could lead to kernel OOM during startup since
> all memory beside zone DMA are in the movable zone and this prevents
> the kernel to use it.
> 
> Zone DMA/DMA32 initialization is independent of mirrored memory and
> their max pfn is set in zone_sizes_init(). Since kernel can fallback
> to zone DMA/DMA32 if there is no memory in zone Normal, these zones
> are seen as mirrored memory no mather their memory attributes are.
> 
> To solve this problem, disable kernelcore=mirror when there is no real
> mirrored memory exists.
> 
> Suggested-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> Suggested-by: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>

Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org>

> ---
>  mm/internal.h | 1 +
>  mm/memblock.c | 5 +++++
>  mm/mm_init.c  | 5 +++++
>  3 files changed, 11 insertions(+)
> 
> diff --git a/mm/internal.h b/mm/internal.h
> index a7d9e980429a..b8aaf9cac87e 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -1005,6 +1005,7 @@ static inline bool gup_must_unshare(struct vm_area_struct *vma,
>  }
>  
>  extern bool mirrored_kernelcore;
> +extern bool memblock_has_mirror(void);
>  
>  static inline bool vma_soft_dirty_enabled(struct vm_area_struct *vma)
>  {
> diff --git a/mm/memblock.c b/mm/memblock.c
> index f9e61e565a53..913b2520a9a0 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -161,6 +161,11 @@ static int memblock_can_resize __initdata_memblock;
>  static int memblock_memory_in_slab __initdata_memblock;
>  static int memblock_reserved_in_slab __initdata_memblock;
>  
> +bool __init_memblock memblock_has_mirror(void)
> +{
> +	return system_has_some_mirror;
> +}
> +
>  static enum memblock_flags __init_memblock choose_memblock_flags(void)
>  {
>  	return system_has_some_mirror ? MEMBLOCK_MIRROR : MEMBLOCK_NONE;
> diff --git a/mm/mm_init.c b/mm/mm_init.c
> index a1963c3322af..e8af1b628430 100644
> --- a/mm/mm_init.c
> +++ b/mm/mm_init.c
> @@ -377,6 +377,11 @@ static void __init find_zone_movable_pfns_for_nodes(void)
>  	if (mirrored_kernelcore) {
>  		bool mem_below_4gb_not_mirrored = false;
>  
> +		if (!memblock_has_mirror()) {
> +			pr_warn("The system has no mirror memory, ignore kernelcore=mirror.\n");
> +			goto out;
> +		}
> +
>  		for_each_mem_region(r) {
>  			if (memblock_is_mirror(r))
>  				continue;
> -- 
> 2.25.1
> 

-- 
Sincerely yours,
Mike.


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

* Re: [PATCH v2] mm: disable kernelcore=mirror when no mirror memory
  2023-08-02  7:23 [PATCH v2] mm: disable kernelcore=mirror when no mirror memory Wupeng Ma
  2023-08-02 18:44 ` Mike Rapoport
@ 2023-08-03  3:06 ` Kefeng Wang
  2023-08-03 17:53 ` Andrew Morton
  2 siblings, 0 replies; 6+ messages in thread
From: Kefeng Wang @ 2023-08-03  3:06 UTC (permalink / raw)
  To: Wupeng Ma, akpm, rppt; +Cc: linux-mm



On 2023/8/2 15:23, Wupeng Ma wrote:
> From: Ma Wupeng <mawupeng1@huawei.com>
> 
> For system with kernelcore=mirror enabled while no mirrored memory is
> reported by efi. This could lead to kernel OOM during startup since
> all memory beside zone DMA are in the movable zone and this prevents
> the kernel to use it.
> 
> Zone DMA/DMA32 initialization is independent of mirrored memory and
> their max pfn is set in zone_sizes_init(). Since kernel can fallback
> to zone DMA/DMA32 if there is no memory in zone Normal, these zones
> are seen as mirrored memory no mather their memory attributes are.
> 
> To solve this problem, disable kernelcore=mirror when there is no real
> mirrored memory exists.
> 
> Suggested-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> Suggested-by: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>

Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>


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

* Re: [PATCH v2] mm: disable kernelcore=mirror when no mirror memory
  2023-08-02  7:23 [PATCH v2] mm: disable kernelcore=mirror when no mirror memory Wupeng Ma
  2023-08-02 18:44 ` Mike Rapoport
  2023-08-03  3:06 ` Kefeng Wang
@ 2023-08-03 17:53 ` Andrew Morton
  2023-08-04  1:44   ` Kefeng Wang
  2 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2023-08-03 17:53 UTC (permalink / raw)
  To: Wupeng Ma; +Cc: rppt, wangkefeng.wang, linux-mm, Levi Yun

On Wed, 2 Aug 2023 15:23:28 +0800 Wupeng Ma <mawupeng1@huawei.com> wrote:

> From: Ma Wupeng <mawupeng1@huawei.com>
> 
> For system with kernelcore=mirror enabled while no mirrored memory is
> reported by efi. This could lead to kernel OOM during startup since
> all memory beside zone DMA are in the movable zone and this prevents
> the kernel to use it.
> 
> Zone DMA/DMA32 initialization is independent of mirrored memory and
> their max pfn is set in zone_sizes_init(). Since kernel can fallback
> to zone DMA/DMA32 if there is no memory in zone Normal, these zones
> are seen as mirrored memory no mather their memory attributes are.
> 
> To solve this problem, disable kernelcore=mirror when there is no real
> mirrored memory exists.
> 
> ...
>
> diff --git a/mm/internal.h b/mm/internal.h
> index a7d9e980429a..b8aaf9cac87e 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -1005,6 +1005,7 @@ static inline bool gup_must_unshare(struct vm_area_struct *vma,
>  }
>  
>  extern bool mirrored_kernelcore;
> +extern bool memblock_has_mirror(void);
>  
>  static inline bool vma_soft_dirty_enabled(struct vm_area_struct *vma)
>  {
> diff --git a/mm/memblock.c b/mm/memblock.c
> index f9e61e565a53..913b2520a9a0 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -161,6 +161,11 @@ static int memblock_can_resize __initdata_memblock;
>  static int memblock_memory_in_slab __initdata_memblock;
>  static int memblock_reserved_in_slab __initdata_memblock;
>  
> +bool __init_memblock memblock_has_mirror(void)
> +{
> +	return system_has_some_mirror;
> +}
> +
>  static enum memblock_flags __init_memblock choose_memblock_flags(void)
>  {
>  	return system_has_some_mirror ? MEMBLOCK_MIRROR : MEMBLOCK_NONE;
> diff --git a/mm/mm_init.c b/mm/mm_init.c
> index a1963c3322af..e8af1b628430 100644
> --- a/mm/mm_init.c
> +++ b/mm/mm_init.c
> @@ -377,6 +377,11 @@ static void __init find_zone_movable_pfns_for_nodes(void)
>  	if (mirrored_kernelcore) {
>  		bool mem_below_4gb_not_mirrored = false;
>  
> +		if (!memblock_has_mirror()) {
> +			pr_warn("The system has no mirror memory, ignore kernelcore=mirror.\n");
> +			goto out;
> +		}
> +
>  		for_each_mem_region(r) {
>  			if (memblock_is_mirror(r))
>  				continue;

I've already queued Levi's "mm/mm_init: ignore kernelcore=mirror boot
option when no mirror memory presents."
(https://lkml.kernel.org/r/20230802183614.15520-1-ppbuk5246@gmail.com)

The main difference appears to be that Levi's patch zeroes out
zone_movable_pfn.

Please let's check each other's work and decide how to proceed?


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

* Re: [PATCH v2] mm: disable kernelcore=mirror when no mirror memory
  2023-08-03 17:53 ` Andrew Morton
@ 2023-08-04  1:44   ` Kefeng Wang
  2023-08-06 18:55     ` Yun Levi
  0 siblings, 1 reply; 6+ messages in thread
From: Kefeng Wang @ 2023-08-04  1:44 UTC (permalink / raw)
  To: Andrew Morton, Wupeng Ma; +Cc: rppt, linux-mm, Levi Yun



On 2023/8/4 1:53, Andrew Morton wrote:
> On Wed, 2 Aug 2023 15:23:28 +0800 Wupeng Ma <mawupeng1@huawei.com> wrote:
> 
>> From: Ma Wupeng <mawupeng1@huawei.com>
>>
>> For system with kernelcore=mirror enabled while no mirrored memory is
>> reported by efi. This could lead to kernel OOM during startup since
>> all memory beside zone DMA are in the movable zone and this prevents
>> the kernel to use it.
>>
>> Zone DMA/DMA32 initialization is independent of mirrored memory and
>> their max pfn is set in zone_sizes_init(). Since kernel can fallback
>> to zone DMA/DMA32 if there is no memory in zone Normal, these zones
>> are seen as mirrored memory no mather their memory attributes are.
>>
>> To solve this problem, disable kernelcore=mirror when there is no real
>> mirrored memory exists.
>>
>> ...
>>
>> diff --git a/mm/internal.h b/mm/internal.h
>> index a7d9e980429a..b8aaf9cac87e 100644
>> --- a/mm/internal.h
>> +++ b/mm/internal.h
>> @@ -1005,6 +1005,7 @@ static inline bool gup_must_unshare(struct vm_area_struct *vma,
>>   }
>>   
>>   extern bool mirrored_kernelcore;
>> +extern bool memblock_has_mirror(void);
>>   
>>   static inline bool vma_soft_dirty_enabled(struct vm_area_struct *vma)
>>   {
>> diff --git a/mm/memblock.c b/mm/memblock.c
>> index f9e61e565a53..913b2520a9a0 100644
>> --- a/mm/memblock.c
>> +++ b/mm/memblock.c
>> @@ -161,6 +161,11 @@ static int memblock_can_resize __initdata_memblock;
>>   static int memblock_memory_in_slab __initdata_memblock;
>>   static int memblock_reserved_in_slab __initdata_memblock;
>>   
>> +bool __init_memblock memblock_has_mirror(void)
>> +{
>> +	return system_has_some_mirror;
>> +}
>> +
>>   static enum memblock_flags __init_memblock choose_memblock_flags(void)
>>   {
>>   	return system_has_some_mirror ? MEMBLOCK_MIRROR : MEMBLOCK_NONE;
>> diff --git a/mm/mm_init.c b/mm/mm_init.c
>> index a1963c3322af..e8af1b628430 100644
>> --- a/mm/mm_init.c
>> +++ b/mm/mm_init.c
>> @@ -377,6 +377,11 @@ static void __init find_zone_movable_pfns_for_nodes(void)
>>   	if (mirrored_kernelcore) {
>>   		bool mem_below_4gb_not_mirrored = false;
>>   
>> +		if (!memblock_has_mirror()) {
>> +			pr_warn("The system has no mirror memory, ignore kernelcore=mirror.\n");
>> +			goto out;
>> +		}
>> +
>>   		for_each_mem_region(r) {
>>   			if (memblock_is_mirror(r))
>>   				continue;
> 
> I've already queued Levi's "mm/mm_init: ignore kernelcore=mirror boot
> option when no mirror memory presents."
> (https://lkml.kernel.org/r/20230802183614.15520-1-ppbuk5246@gmail.com)
> 
> The main difference appears to be that Levi's patch zeroes out
> zone_movable_pfn.
> 
> Please let's check each other's work and decide how to proceed?

We already know whether system has mirror memory or not, so no need 
recheck it again and no need to touch zone_movable_pfn.


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

* Re: [PATCH v2] mm: disable kernelcore=mirror when no mirror memory
  2023-08-04  1:44   ` Kefeng Wang
@ 2023-08-06 18:55     ` Yun Levi
  0 siblings, 0 replies; 6+ messages in thread
From: Yun Levi @ 2023-08-06 18:55 UTC (permalink / raw)
  To: Kefeng Wang; +Cc: Andrew Morton, Wupeng Ma, rppt, linux-mm

> We already know whether system has mirror memory or not, so no need
> recheck it again and no need to touch zone_movable_pfn.

Yes. I think Kefeng Wang's patch is better. :)

I missed the system_has_some_mirror.

Many thanks..!

---------
Sincerely,
Levi.


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

end of thread, other threads:[~2023-08-06 18:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-02  7:23 [PATCH v2] mm: disable kernelcore=mirror when no mirror memory Wupeng Ma
2023-08-02 18:44 ` Mike Rapoport
2023-08-03  3:06 ` Kefeng Wang
2023-08-03 17:53 ` Andrew Morton
2023-08-04  1:44   ` Kefeng Wang
2023-08-06 18:55     ` Yun Levi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.