linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] introduce mirrored memory support for arm64
@ 2022-03-26  6:46 Wupeng Ma
  2022-03-26  6:46 ` [PATCH 1/9] efi: Make efi_print_memmap() public Wupeng Ma
                   ` (9 more replies)
  0 siblings, 10 replies; 14+ messages in thread
From: Wupeng Ma @ 2022-03-26  6:46 UTC (permalink / raw)
  To: akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	david, gpiccoli, mark.rutland, wangkefeng.wang, mawupeng1,
	linux-doc, linux-kernel, linux-arm-kernel, linux-efi, linux-ia64,
	platform-driver-x86, linux-mm

From: Ma Wupeng <mawupeng1@huawei.com>

Commit b05b9f5f9dcf ("x86, mirror: x86 enabling - find mirrored memory ranges")
introduced mirrored memory support for x86. This support rely on UEFI to
report mirrored memory address ranges.  See UEFI 2.5 spec pages 157-158:

  http://www.uefi.org/sites/default/files/resources/UEFI%202_5.pdf

Arm64 can support this too. So mirrored memory support is added to support
arm64.

Patch #1-#2 introduce efi_fake_mem support for arm64.
Patch #3-#4 introduce mirrored memory support form arm64.
Patch #5-#7 fix some bugs for arm64 if memory reliable is enabled.
Patch #8 disable mirror feature if kernelcore is not specified.
Patch #9 remove some redundant code in ia64 efi_init.

Ma Wupeng (9):
  efi: Make efi_print_memmap() public
  arm64: efi: Add fake memory support
  efi: Make efi_find_mirror() public
  arm64/mirror: arm64 enabling - find mirrored memory ranges
  mm: Ratelimited mirrored memory related warning messages
  mm: Demote warning message in vmemmap_verify() to debug level
  mm: Calc the right pfn if page size is not 4K
  efi: Disable mirror feature if kernelcore is not specified
  ia64/efi: Code simplification in efi_init

 .../admin-guide/kernel-parameters.txt         |  4 +-
 arch/arm64/kernel/setup.c                     |  3 ++
 arch/ia64/kernel/efi.c                        | 37 +-----------------
 arch/x86/include/asm/efi.h                    |  5 ---
 arch/x86/platform/efi/efi.c                   | 39 -------------------
 drivers/firmware/efi/Kconfig                  |  2 +-
 drivers/firmware/efi/efi.c                    | 26 +++++++++++++
 drivers/firmware/efi/memmap.c                 | 16 ++++++++
 include/linux/efi.h                           |  4 ++
 include/linux/mm.h                            |  2 +
 mm/memblock.c                                 |  4 +-
 mm/page_alloc.c                               |  4 +-
 mm/sparse-vmemmap.c                           |  2 +-
 13 files changed, 60 insertions(+), 88 deletions(-)

-- 
2.18.0.huawei.25



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

* [PATCH 1/9] efi: Make efi_print_memmap() public
  2022-03-26  6:46 [PATCH 0/9] introduce mirrored memory support for arm64 Wupeng Ma
@ 2022-03-26  6:46 ` Wupeng Ma
  2022-03-26  6:46 ` [PATCH 2/9] arm64: efi: Add fake memory support Wupeng Ma
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Wupeng Ma @ 2022-03-26  6:46 UTC (permalink / raw)
  To: akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	david, gpiccoli, mark.rutland, wangkefeng.wang, mawupeng1,
	linux-doc, linux-kernel, linux-arm-kernel, linux-efi, linux-ia64,
	platform-driver-x86, linux-mm

From: Ma Wupeng <mawupeng1@huawei.com>

Make efi_print_memmap() public in preparation for adding fake memory
support for architecture with efi support, eg, arm64.

Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 arch/x86/include/asm/efi.h    |  1 -
 arch/x86/platform/efi/efi.c   | 16 ----------------
 drivers/firmware/efi/memmap.c | 16 ++++++++++++++++
 include/linux/efi.h           |  1 +
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index 03cb12775043..f0cc7766f53c 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -145,7 +145,6 @@ extern asmlinkage u64 __efi_call(void *fp, ...);
 #endif /* CONFIG_X86_32 */
 
 extern int __init efi_memblock_x86_reserve_range(void);
-extern void __init efi_print_memmap(void);
 extern void __init efi_map_region(efi_memory_desc_t *md);
 extern void __init efi_map_region_fixed(efi_memory_desc_t *md);
 extern void efi_sync_low_kernel_mappings(void);
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 147c30a81f15..7b130f39d841 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -323,22 +323,6 @@ static void __init efi_clean_memmap(void)
 	}
 }
 
-void __init efi_print_memmap(void)
-{
-	efi_memory_desc_t *md;
-	int i = 0;
-
-	for_each_efi_memory_desc(md) {
-		char buf[64];
-
-		pr_info("mem%02u: %s range=[0x%016llx-0x%016llx] (%lluMB)\n",
-			i++, efi_md_typeattr_format(buf, sizeof(buf), md),
-			md->phys_addr,
-			md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - 1,
-			(md->num_pages >> (20 - EFI_PAGE_SHIFT)));
-	}
-}
-
 static int __init efi_systab_init(unsigned long phys)
 {
 	int size = efi_enabled(EFI_64BIT) ? sizeof(efi_system_table_64_t)
diff --git a/drivers/firmware/efi/memmap.c b/drivers/firmware/efi/memmap.c
index 4df55a55da84..04cc1f2cdfa4 100644
--- a/drivers/firmware/efi/memmap.c
+++ b/drivers/firmware/efi/memmap.c
@@ -376,3 +376,19 @@ void __init efi_memmap_insert(struct efi_memory_map *old_memmap, void *buf,
 		}
 	}
 }
+
+void __init efi_print_memmap(void)
+{
+	efi_memory_desc_t *md;
+	int i = 0;
+
+	for_each_efi_memory_desc(md) {
+		char buf[64];
+
+		pr_info("mem%02u: %s range=[0x%016llx-0x%016llx] (%lluMB)\n",
+			i++, efi_md_typeattr_format(buf, sizeof(buf), md),
+			md->phys_addr,
+			md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - 1,
+			(md->num_pages >> (20 - EFI_PAGE_SHIFT)));
+	}
+}
diff --git a/include/linux/efi.h b/include/linux/efi.h
index ccd4d3f91c98..de05682b233b 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -684,6 +684,7 @@ extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
 					 struct range *range);
 extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap,
 				     void *buf, struct efi_mem_range *mem);
+extern void __init efi_print_memmap(void);
 
 #ifdef CONFIG_EFI_ESRT
 extern void __init efi_esrt_init(void);
-- 
2.18.0.huawei.25



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

* [PATCH 2/9] arm64: efi: Add fake memory support
  2022-03-26  6:46 [PATCH 0/9] introduce mirrored memory support for arm64 Wupeng Ma
  2022-03-26  6:46 ` [PATCH 1/9] efi: Make efi_print_memmap() public Wupeng Ma
@ 2022-03-26  6:46 ` Wupeng Ma
  2022-03-26  6:46 ` [PATCH 3/9] efi: Make efi_find_mirror() public Wupeng Ma
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Wupeng Ma @ 2022-03-26  6:46 UTC (permalink / raw)
  To: akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	david, gpiccoli, mark.rutland, wangkefeng.wang, mawupeng1,
	linux-doc, linux-kernel, linux-arm-kernel, linux-efi, linux-ia64,
	platform-driver-x86, linux-mm

From: Ma Wupeng <mawupeng1@huawei.com>

Fake memory map is used for faking memory's attribute values.
Commit 0f96a99dab36 ("efi: Add "efi_fake_mem" boot option") introduce the
efi_fake_mem function. Now it can support arm64 with this patch.
For example you can mark 0-6G memory as EFI_MEMORY_MORE_RELIABLE by adding
efi_fake_mem=6G@0:0x10000 in the bootarg. You find more info about
fake memmap in kernel-parameters.txt.

Variable memstart_addr is only confirmed after arm64_memblock_init(). So
efi_fake_memmap() is needed to add after arm64_memblock_init().

Otherwise:

efi_memmap_alloc
   memblock_phys_alloc
     kmemleak_alloc_phys
        kmemleak_alloc(__va(phys), size, min_count, gfp);

this __va() will convert phys to a fault va and lead to a kmemleak error.

Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 Documentation/admin-guide/kernel-parameters.txt | 2 +-
 arch/arm64/kernel/setup.c                       | 2 ++
 drivers/firmware/efi/Kconfig                    | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index b7ccaa2ea867..e064839895ee 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1357,7 +1357,7 @@
 			you are really sure that your UEFI does sane gc and
 			fulfills the spec otherwise your board may brick.
 
-	efi_fake_mem=	nn[KMG]@ss[KMG]:aa[,nn[KMG]@ss[KMG]:aa,..] [EFI; X86]
+	efi_fake_mem=	nn[KMG]@ss[KMG]:aa[,nn[KMG]@ss[KMG]:aa,..] [EFI; X86; ARM64]
 			Add arbitrary attribute to specific memory range by
 			updating original EFI memory map.
 			Region of memory which aa attribute is added to is
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 3505789cf4bd..daade64889ff 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -344,6 +344,8 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)
 
 	arm64_memblock_init();
 
+	efi_fake_memmap();
+
 	paging_init();
 
 	acpi_table_upgrade();
diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig
index 2c3dac5ecb36..3c91bbd4097a 100644
--- a/drivers/firmware/efi/Kconfig
+++ b/drivers/firmware/efi/Kconfig
@@ -50,7 +50,7 @@ config EFI_RUNTIME_MAP
 
 config EFI_FAKE_MEMMAP
 	bool "Enable EFI fake memory map"
-	depends on EFI && X86
+	depends on EFI && (X86 || ARM64)
 	default n
 	help
 	  Saying Y here will enable "efi_fake_mem" boot option.
-- 
2.18.0.huawei.25



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

* [PATCH 3/9] efi: Make efi_find_mirror() public
  2022-03-26  6:46 [PATCH 0/9] introduce mirrored memory support for arm64 Wupeng Ma
  2022-03-26  6:46 ` [PATCH 1/9] efi: Make efi_print_memmap() public Wupeng Ma
  2022-03-26  6:46 ` [PATCH 2/9] arm64: efi: Add fake memory support Wupeng Ma
@ 2022-03-26  6:46 ` Wupeng Ma
  2022-03-26  6:46 ` [PATCH 4/9] arm64/mirror: arm64 enabling - find mirrored memory ranges Wupeng Ma
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Wupeng Ma @ 2022-03-26  6:46 UTC (permalink / raw)
  To: akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	david, gpiccoli, mark.rutland, wangkefeng.wang, mawupeng1,
	linux-doc, linux-kernel, linux-arm-kernel, linux-efi, linux-ia64,
	platform-driver-x86, linux-mm

From: Ma Wupeng <mawupeng1@huawei.com>

Commit b05b9f5f9dcf ("x86, mirror: x86 enabling - find mirrored memory
ranges") introduce the efi_find_mirror function on x86. In order to reuse
the API we make it public in preparation for arm64 to support mirrord
memory.

Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 arch/x86/include/asm/efi.h  |  4 ----
 arch/x86/platform/efi/efi.c | 23 -----------------------
 drivers/firmware/efi/efi.c  | 23 +++++++++++++++++++++++
 include/linux/efi.h         |  3 +++
 4 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index f0cc7766f53c..aae5933b7954 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -363,7 +363,6 @@ static inline bool efi_is_64bit(void)
 extern bool efi_reboot_required(void);
 extern bool efi_is_table_address(unsigned long phys_addr);
 
-extern void efi_find_mirror(void);
 extern void efi_reserve_boot_services(void);
 #else
 static inline void parse_efi_setup(u64 phys_addr, u32 data_len) {}
@@ -375,9 +374,6 @@ static inline  bool efi_is_table_address(unsigned long phys_addr)
 {
 	return false;
 }
-static inline void efi_find_mirror(void)
-{
-}
 static inline void efi_reserve_boot_services(void)
 {
 }
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 7b130f39d841..fedbb228faea 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -105,29 +105,6 @@ static int __init setup_add_efi_memmap(char *arg)
 }
 early_param("add_efi_memmap", setup_add_efi_memmap);
 
-void __init efi_find_mirror(void)
-{
-	efi_memory_desc_t *md;
-	u64 mirror_size = 0, total_size = 0;
-
-	if (!efi_enabled(EFI_MEMMAP))
-		return;
-
-	for_each_efi_memory_desc(md) {
-		unsigned long long start = md->phys_addr;
-		unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
-
-		total_size += size;
-		if (md->attribute & EFI_MEMORY_MORE_RELIABLE) {
-			memblock_mark_mirror(start, size);
-			mirror_size += size;
-		}
-	}
-	if (mirror_size)
-		pr_info("Memory: %lldM/%lldM mirrored memory\n",
-			mirror_size>>20, total_size>>20);
-}
-
 /*
  * Tell the kernel about the EFI memory map.  This might include
  * more than the max 128 entries that can fit in the passed in e820
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 5502e176d51b..eb9ebf4efea1 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -438,6 +438,29 @@ static int __init efisubsys_init(void)
 
 subsys_initcall(efisubsys_init);
 
+void __init efi_find_mirror(void)
+{
+	efi_memory_desc_t *md;
+	u64 mirror_size = 0, total_size = 0;
+
+	if (!efi_enabled(EFI_MEMMAP))
+		return;
+
+	for_each_efi_memory_desc(md) {
+		unsigned long long start = md->phys_addr;
+		unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
+
+		total_size += size;
+		if (md->attribute & EFI_MEMORY_MORE_RELIABLE) {
+			memblock_mark_mirror(start, size);
+			mirror_size += size;
+		}
+	}
+	if (mirror_size)
+		pr_info("Memory: %lldM/%lldM mirrored memory\n",
+			mirror_size>>20, total_size>>20);
+}
+
 /*
  * Find the efi memory descriptor for a given physical address.  Given a
  * physical address, determine if it exists within an EFI Memory Map entry,
diff --git a/include/linux/efi.h b/include/linux/efi.h
index de05682b233b..950c84ce3f16 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -853,6 +853,7 @@ static inline bool efi_rt_services_supported(unsigned int mask)
 {
 	return (efi.runtime_supported_mask & mask) == mask;
 }
+extern void efi_find_mirror(void);
 #else
 static inline bool efi_enabled(int feature)
 {
@@ -870,6 +871,8 @@ static inline bool efi_rt_services_supported(unsigned int mask)
 {
 	return false;
 }
+
+static inline void efi_find_mirror(void) {}
 #endif
 
 extern int efi_status_to_err(efi_status_t status);
-- 
2.18.0.huawei.25



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

* [PATCH 4/9] arm64/mirror: arm64 enabling - find mirrored memory ranges
  2022-03-26  6:46 [PATCH 0/9] introduce mirrored memory support for arm64 Wupeng Ma
                   ` (2 preceding siblings ...)
  2022-03-26  6:46 ` [PATCH 3/9] efi: Make efi_find_mirror() public Wupeng Ma
@ 2022-03-26  6:46 ` Wupeng Ma
  2022-03-26  6:46 ` [PATCH 5/9] mm: Ratelimited mirrored memory related warning messages Wupeng Ma
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Wupeng Ma @ 2022-03-26  6:46 UTC (permalink / raw)
  To: akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	david, gpiccoli, mark.rutland, wangkefeng.wang, mawupeng1,
	linux-doc, linux-kernel, linux-arm-kernel, linux-efi, linux-ia64,
	platform-driver-x86, linux-mm

From: Ma Wupeng <mawupeng1@huawei.com>

Commit b05b9f5f9dcf ("x86, mirror: x86 enabling - find mirrored memory ranges")
introduced mirrored memory support for x86 and this could be used on arm64.

So efi_find_mirror() is added in efi_init() so on EFI enabled systems scan
the memory map and tell memblock about any mirrored ranges.

Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 Documentation/admin-guide/kernel-parameters.txt | 2 +-
 arch/arm64/kernel/setup.c                       | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index e064839895ee..0af91e0aafea 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2270,7 +2270,7 @@
 
 	keepinitrd	[HW,ARM]
 
-	kernelcore=	[KNL,X86,IA-64,PPC]
+	kernelcore=	[KNL,X86,IA-64,PPC,ARM64]
 			Format: nn[KMGTPE] | nn% | "mirror"
 			This parameter specifies the amount of memory usable by
 			the kernel for non-movable allocations.  The requested
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index daade64889ff..3957290d9ade 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -345,6 +345,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)
 	arm64_memblock_init();
 
 	efi_fake_memmap();
+	efi_find_mirror();
 
 	paging_init();
 
-- 
2.18.0.huawei.25



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

* [PATCH 5/9] mm: Ratelimited mirrored memory related warning messages
  2022-03-26  6:46 [PATCH 0/9] introduce mirrored memory support for arm64 Wupeng Ma
                   ` (3 preceding siblings ...)
  2022-03-26  6:46 ` [PATCH 4/9] arm64/mirror: arm64 enabling - find mirrored memory ranges Wupeng Ma
@ 2022-03-26  6:46 ` Wupeng Ma
  2022-03-26  6:46 ` [PATCH 6/9] mm: Demote warning message in vmemmap_verify() to debug level Wupeng Ma
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Wupeng Ma @ 2022-03-26  6:46 UTC (permalink / raw)
  To: akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	david, gpiccoli, mark.rutland, wangkefeng.wang, mawupeng1,
	linux-doc, linux-kernel, linux-arm-kernel, linux-efi, linux-ia64,
	platform-driver-x86, linux-mm

From: Ma Wupeng <mawupeng1@huawei.com>

If system has mirrored memory, memblock will try to allocate mirrored
memory firstly and fallback to non-mirrored memory when fails, but if with
limited mirrored memory or some numa node without mirrored memory, lots of
warning message about memblock allocation will occur.

This patch ratelimit the warning message to avoid a very long print during
bootup.

Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 mm/memblock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index b12a364f2766..19ae4a63fc08 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -327,7 +327,7 @@ static phys_addr_t __init_memblock memblock_find_in_range(phys_addr_t start,
 					    NUMA_NO_NODE, flags);
 
 	if (!ret && (flags & MEMBLOCK_MIRROR)) {
-		pr_warn("Could not allocate %pap bytes of mirrored memory\n",
+		pr_warn_ratelimited("Could not allocate %pap bytes of mirrored memory\n",
 			&size);
 		flags &= ~MEMBLOCK_MIRROR;
 		goto again;
@@ -1385,7 +1385,7 @@ phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size,
 
 	if (flags & MEMBLOCK_MIRROR) {
 		flags &= ~MEMBLOCK_MIRROR;
-		pr_warn("Could not allocate %pap bytes of mirrored memory\n",
+		pr_warn_ratelimited("Could not allocate %pap bytes of mirrored memory\n",
 			&size);
 		goto again;
 	}
-- 
2.18.0.huawei.25



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

* [PATCH 6/9] mm: Demote warning message in vmemmap_verify() to debug level
  2022-03-26  6:46 [PATCH 0/9] introduce mirrored memory support for arm64 Wupeng Ma
                   ` (4 preceding siblings ...)
  2022-03-26  6:46 ` [PATCH 5/9] mm: Ratelimited mirrored memory related warning messages Wupeng Ma
@ 2022-03-26  6:46 ` Wupeng Ma
  2022-03-26  6:46 ` [PATCH 7/9] mm: Calc the right pfn if page size is not 4K Wupeng Ma
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 14+ messages in thread
From: Wupeng Ma @ 2022-03-26  6:46 UTC (permalink / raw)
  To: akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	david, gpiccoli, mark.rutland, wangkefeng.wang, mawupeng1,
	linux-doc, linux-kernel, linux-arm-kernel, linux-efi, linux-ia64,
	platform-driver-x86, linux-mm

From: Ma Wupeng <mawupeng1@huawei.com>

For a system only have limited mirrored memory or some numa node without
mirrored memory, the per node vmemmap page_structs prefer to allocate
memory from mirrored region, which will lead to vmemmap_verify() report
lots of warning message.

This patch demote the "potential offnode page_structs" warning messages
to debug level to avoid a very long print during bootup.

Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 mm/sparse-vmemmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
index 8aecd6b3896c..a63470dafc35 100644
--- a/mm/sparse-vmemmap.c
+++ b/mm/sparse-vmemmap.c
@@ -528,7 +528,7 @@ void __meminit vmemmap_verify(pte_t *pte, int node,
 	int actual_node = early_pfn_to_nid(pfn);
 
 	if (node_distance(actual_node, node) > LOCAL_DISTANCE)
-		pr_warn("[%lx-%lx] potential offnode page_structs\n",
+		pr_debug("[%lx-%lx] potential offnode page_structs\n",
 			start, end - 1);
 }
 
-- 
2.18.0.huawei.25



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

* [PATCH 7/9] mm: Calc the right pfn if page size is not 4K
  2022-03-26  6:46 [PATCH 0/9] introduce mirrored memory support for arm64 Wupeng Ma
                   ` (5 preceding siblings ...)
  2022-03-26  6:46 ` [PATCH 6/9] mm: Demote warning message in vmemmap_verify() to debug level Wupeng Ma
@ 2022-03-26  6:46 ` Wupeng Ma
  2022-03-28 12:33   ` David Hildenbrand
  2022-03-26  6:46 ` [PATCH 8/9] efi: Disable mirror feature if kernelcore is not specified Wupeng Ma
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 14+ messages in thread
From: Wupeng Ma @ 2022-03-26  6:46 UTC (permalink / raw)
  To: akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	david, gpiccoli, mark.rutland, wangkefeng.wang, mawupeng1,
	linux-doc, linux-kernel, linux-arm-kernel, linux-efi, linux-ia64,
	platform-driver-x86, linux-mm

From: Ma Wupeng <mawupeng1@huawei.com>

Pervious 0x100000 is used to check the 4G limit in
find_zone_movable_pfns_for_nodes(). This is right in x86 because
the page size can only be 4K. But 16K and 64K are available in
arm64. So replate it with SIZE_4G >> PAGE_SHIFT.

Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 mm/page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 6e0b4596cde9..41fd987b5b93 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -7811,7 +7811,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
 
 			usable_startpfn = memblock_region_memory_base_pfn(r);
 
-			if (usable_startpfn < 0x100000) {
+			if (usable_startpfn < (SZ_4G >> PAGE_SHIFT)) {
 				mem_below_4gb_not_mirrored = true;
 				continue;
 			}
-- 
2.18.0.huawei.25



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

* [PATCH 8/9] efi: Disable mirror feature if kernelcore is not specified
  2022-03-26  6:46 [PATCH 0/9] introduce mirrored memory support for arm64 Wupeng Ma
                   ` (6 preceding siblings ...)
  2022-03-26  6:46 ` [PATCH 7/9] mm: Calc the right pfn if page size is not 4K Wupeng Ma
@ 2022-03-26  6:46 ` Wupeng Ma
  2022-03-26  6:46 ` [PATCH 9/9] ia64/efi: Code simplification in efi_init Wupeng Ma
  2022-03-29  8:26 ` [PATCH 0/9] introduce mirrored memory support for arm64 Ard Biesheuvel
  9 siblings, 0 replies; 14+ messages in thread
From: Wupeng Ma @ 2022-03-26  6:46 UTC (permalink / raw)
  To: akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	david, gpiccoli, mark.rutland, wangkefeng.wang, mawupeng1,
	linux-doc, linux-kernel, linux-arm-kernel, linux-efi, linux-ia64,
	platform-driver-x86, linux-mm

From: Ma Wupeng <mawupeng1@huawei.com>

With this patch, kernel will check mirrored_kernelcore before calling
efi_find_mirror() which will enable basic mirrored feature.

If system have some mirrored memory and mirrored feature is not specified
in boot parameter, the basic mirrored feature will be enabled and this will
lead to the following situations:

- memblock memory allocation perfers mirrored region. This may have some
  unexpected influence on numa affinity.

- contiguous memory will be splited into several parts if parts of them
  is mirrored memory via memblock_mark_mirror().

Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 drivers/firmware/efi/efi.c | 3 +++
 include/linux/mm.h         | 2 ++
 mm/page_alloc.c            | 2 +-
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index eb9ebf4efea1..18d86602424a 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -446,6 +446,9 @@ void __init efi_find_mirror(void)
 	if (!efi_enabled(EFI_MEMMAP))
 		return;
 
+	if (!mirrored_kernelcore)
+		return;
+
 	for_each_efi_memory_desc(md) {
 		unsigned long long start = md->phys_addr;
 		unsigned long long size = md->num_pages << EFI_PAGE_SHIFT;
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7a3dd7e617e4..4e266e03674d 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2541,6 +2541,8 @@ extern void get_pfn_range_for_nid(unsigned int nid,
 			unsigned long *start_pfn, unsigned long *end_pfn);
 extern unsigned long find_min_pfn_with_active_regions(void);
 
+extern bool mirrored_kernelcore;
+
 #ifndef CONFIG_NUMA
 static inline int early_pfn_to_nid(unsigned long pfn)
 {
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 41fd987b5b93..61af9e235e43 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -355,7 +355,7 @@ static unsigned long required_kernelcore_percent __initdata;
 static unsigned long required_movablecore __initdata;
 static unsigned long required_movablecore_percent __initdata;
 static unsigned long zone_movable_pfn[MAX_NUMNODES] __initdata;
-static bool mirrored_kernelcore __meminitdata;
+bool mirrored_kernelcore __meminitdata;
 
 /* movable_zone is the "real" zone pages in ZONE_MOVABLE are taken from */
 int movable_zone;
-- 
2.18.0.huawei.25



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

* [PATCH 9/9] ia64/efi: Code simplification in efi_init
  2022-03-26  6:46 [PATCH 0/9] introduce mirrored memory support for arm64 Wupeng Ma
                   ` (7 preceding siblings ...)
  2022-03-26  6:46 ` [PATCH 8/9] efi: Disable mirror feature if kernelcore is not specified Wupeng Ma
@ 2022-03-26  6:46 ` Wupeng Ma
  2022-03-29  8:26 ` [PATCH 0/9] introduce mirrored memory support for arm64 Ard Biesheuvel
  9 siblings, 0 replies; 14+ messages in thread
From: Wupeng Ma @ 2022-03-26  6:46 UTC (permalink / raw)
  To: akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	david, gpiccoli, mark.rutland, wangkefeng.wang, mawupeng1,
	linux-doc, linux-kernel, linux-arm-kernel, linux-efi, linux-ia64,
	platform-driver-x86, linux-mm

From: Ma Wupeng <mawupeng1@huawei.com>

Since efi_print_memmap() was made public, print EFI memory map in
efi_init() can be simplified by using efi_print_memmap().

Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
---
 arch/ia64/kernel/efi.c | 37 +------------------------------------
 1 file changed, 1 insertion(+), 36 deletions(-)

diff --git a/arch/ia64/kernel/efi.c b/arch/ia64/kernel/efi.c
index 31149e41f9be..4b8209b8797d 100644
--- a/arch/ia64/kernel/efi.c
+++ b/arch/ia64/kernel/efi.c
@@ -557,42 +557,7 @@ efi_init (void)
 
 #if EFI_DEBUG
 	/* print EFI memory map: */
-	{
-		efi_memory_desc_t *md;
-		void *p;
-		unsigned int i;
-
-		for (i = 0, p = efi_map_start; p < efi_map_end;
-		     ++i, p += efi_desc_size)
-		{
-			const char *unit;
-			unsigned long size;
-			char buf[64];
-
-			md = p;
-			size = md->num_pages << EFI_PAGE_SHIFT;
-
-			if ((size >> 40) > 0) {
-				size >>= 40;
-				unit = "TB";
-			} else if ((size >> 30) > 0) {
-				size >>= 30;
-				unit = "GB";
-			} else if ((size >> 20) > 0) {
-				size >>= 20;
-				unit = "MB";
-			} else {
-				size >>= 10;
-				unit = "KB";
-			}
-
-			printk("mem%02d: %s "
-			       "range=[0x%016llx-0x%016llx) (%4lu%s)\n",
-			       i, efi_md_typeattr_format(buf, sizeof(buf), md),
-			       md->phys_addr,
-			       md->phys_addr + efi_md_size(md), size, unit);
-		}
-	}
+	efi_print_memmap();
 #endif
 
 	efi_map_pal_code();
-- 
2.18.0.huawei.25



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

* Re: [PATCH 7/9] mm: Calc the right pfn if page size is not 4K
  2022-03-26  6:46 ` [PATCH 7/9] mm: Calc the right pfn if page size is not 4K Wupeng Ma
@ 2022-03-28 12:33   ` David Hildenbrand
  2022-03-29  1:14     ` mawupeng
  0 siblings, 1 reply; 14+ messages in thread
From: David Hildenbrand @ 2022-03-28 12:33 UTC (permalink / raw)
  To: Wupeng Ma, akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	gpiccoli, mark.rutland, wangkefeng.wang, linux-doc, linux-kernel,
	linux-arm-kernel, linux-efi, linux-ia64, platform-driver-x86,
	linux-mm

On 26.03.22 07:46, Wupeng Ma wrote:
> From: Ma Wupeng <mawupeng1@huawei.com>
> 
> Pervious 0x100000 is used to check the 4G limit in

s/Pervious/Previous/

> find_zone_movable_pfns_for_nodes(). This is right in x86 because
> the page size can only be 4K. But 16K and 64K are available in
> arm64. So replate it with SIZE_4G >> PAGE_SHIFT.

s/replate/replace/

> 
> Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
> ---
>  mm/page_alloc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index 6e0b4596cde9..41fd987b5b93 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7811,7 +7811,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
>  
>  			usable_startpfn = memblock_region_memory_base_pfn(r);
>  
> -			if (usable_startpfn < 0x100000) {
> +			if (usable_startpfn < (SZ_4G >> PAGE_SHIFT)) {

PHYS_PFN(SZ_4G)

?

>  				mem_below_4gb_not_mirrored = true;
>  				continue;
>  			}


-- 
Thanks,

David / dhildenb



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

* Re: [PATCH 7/9] mm: Calc the right pfn if page size is not 4K
  2022-03-28 12:33   ` David Hildenbrand
@ 2022-03-29  1:14     ` mawupeng
  0 siblings, 0 replies; 14+ messages in thread
From: mawupeng @ 2022-03-29  1:14 UTC (permalink / raw)
  To: david, akpm, catalin.marinas, will, corbet
  Cc: ardb, tglx, mingo, bp, dave.hansen, x86, hpa, dvhart, andy, rppt,
	paulmck, peterz, jroedel, songmuchun, macro, frederic, W_Armin,
	john.garry, seanjc, tsbogend, anshuman.khandual, chenhuacai,
	gpiccoli, mark.rutland, wangkefeng.wang, linux-doc, linux-kernel,
	linux-arm-kernel, linux-efi, linux-ia64, platform-driver-x86,
	linux-mm



在 2022/3/28 20:33, David Hildenbrand 写道:
> On 26.03.22 07:46, Wupeng Ma wrote:
>> From: Ma Wupeng <mawupeng1@huawei.com>
>>
>> Pervious 0x100000 is used to check the 4G limit in
> 
> s/Pervious/Previous/
> 
>> find_zone_movable_pfns_for_nodes(). This is right in x86 because
>> the page size can only be 4K. But 16K and 64K are available in
>> arm64. So replate it with SIZE_4G >> PAGE_SHIFT.
> 
> s/replate/replace/
> 
>>
>> Signed-off-by: Ma Wupeng <mawupeng1@huawei.com>
>> ---
>>   mm/page_alloc.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 6e0b4596cde9..41fd987b5b93 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -7811,7 +7811,7 @@ static void __init find_zone_movable_pfns_for_nodes(void)
>>   
>>   			usable_startpfn = memblock_region_memory_base_pfn(r);
>>   
>> -			if (usable_startpfn < 0x100000) {
>> +			if (usable_startpfn < (SZ_4G >> PAGE_SHIFT)) {
> 
> PHYS_PFN(SZ_4G)
> 
> ?
> 
Thanks for reviewing, will be fixed in the next version.

Thanks.
>>   				mem_below_4gb_not_mirrored = true;
>>   				continue;
>>   			}
> 
> 


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

* Re: [PATCH 0/9] introduce mirrored memory support for arm64
  2022-03-26  6:46 [PATCH 0/9] introduce mirrored memory support for arm64 Wupeng Ma
                   ` (8 preceding siblings ...)
  2022-03-26  6:46 ` [PATCH 9/9] ia64/efi: Code simplification in efi_init Wupeng Ma
@ 2022-03-29  8:26 ` Ard Biesheuvel
  2022-03-29 11:03   ` mawupeng
  9 siblings, 1 reply; 14+ messages in thread
From: Ard Biesheuvel @ 2022-03-29  8:26 UTC (permalink / raw)
  To: Wupeng Ma
  Cc: Andrew Morton, Catalin Marinas, Will Deacon, Jonathan Corbet,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	X86 ML, hpa, Darren Hart, Andy Shevchenko, Mike Rapoport,
	Paul E. McKenney, Peter Zijlstra, Joerg Roedel, songmuchun,
	macro, Frederic Weisbecker, W_Armin, John Garry,
	Sean Christopherson, Thomas Bogendoerfer, Anshuman Khandual,
	chenhuacai, David Hildenbrand, gpiccoli, Mark Rutland,
	Kefeng Wang, Linux Doc Mailing List, Linux Kernel Mailing List,
	Linux ARM, linux-efi, linux-ia64, platform-driver-x86,
	Linux Memory Management List

On Sat, 26 Mar 2022 at 07:27, Wupeng Ma <mawupeng1@huawei.com> wrote:
>
> From: Ma Wupeng <mawupeng1@huawei.com>
>
> Commit b05b9f5f9dcf ("x86, mirror: x86 enabling - find mirrored memory ranges")
> introduced mirrored memory support for x86. This support rely on UEFI to
> report mirrored memory address ranges.  See UEFI 2.5 spec pages 157-158:
>
>   http://www.uefi.org/sites/default/files/resources/UEFI%202_5.pdf
>
> Arm64 can support this too. So mirrored memory support is added to support
> arm64.
>

What is the point of this if the kernel itself is not loaded in
EFI_MORE_RELIABLE memory? On x86, this is handled by the decompressor,
but that does not exist on arm64.

The problem here is that UEFI defines this as a memory *attribute*
rather than a memory *type*, which means you cannot allocate
EFI_MORE_RELIABLE memory easily: you have to iterate over the memory
map and look for regions with the desired attribute, and allocate
those pages explicitly. I'd prefer to implement this in the
bootloader, and only add minimal logic to the stub to respect the
placement of the kernel by the loader if the loader signals it to do
so (there are other reasons for this - I will cc you on a patch
shortly that implements this)

This also means that the fake_mem stuff is not going to work: the
memory map observed by the stub comes straight from the firmware, and
if the stub needs to be involved in placing (or respecting the
placement by the loader of) the kernel image, it needs to observe
those EFI_MORE_RELIABLE regions too. If you don't have access to a
machine that actually exposes EFI_MORE_RELIABLE memory, I suggest you
prototype it in QEMU/edk2 instead.

In fact, we have been trying very hard not to touch the firmware
provided memory map at all on ARM, rather than use it as a scratchpad
for all kinds of annotations. This means, for instance, that kexec is
idempotent - the next kernel should not be affected by modifications
to the memory map applied by the previous kernel.

In summary, implementing kernelcore=mirror for arm64 is fine with me,
but there are some issues we need to address first.




> Patch #1-#2 introduce efi_fake_mem support for arm64.
> Patch #3-#4 introduce mirrored memory support form arm64.
> Patch #5-#7 fix some bugs for arm64 if memory reliable is enabled.
> Patch #8 disable mirror feature if kernelcore is not specified.
> Patch #9 remove some redundant code in ia64 efi_init.
>
> Ma Wupeng (9):
>   efi: Make efi_print_memmap() public
>   arm64: efi: Add fake memory support
>   efi: Make efi_find_mirror() public
>   arm64/mirror: arm64 enabling - find mirrored memory ranges
>   mm: Ratelimited mirrored memory related warning messages
>   mm: Demote warning message in vmemmap_verify() to debug level
>   mm: Calc the right pfn if page size is not 4K
>   efi: Disable mirror feature if kernelcore is not specified
>   ia64/efi: Code simplification in efi_init
>
>  .../admin-guide/kernel-parameters.txt         |  4 +-
>  arch/arm64/kernel/setup.c                     |  3 ++
>  arch/ia64/kernel/efi.c                        | 37 +-----------------
>  arch/x86/include/asm/efi.h                    |  5 ---
>  arch/x86/platform/efi/efi.c                   | 39 -------------------
>  drivers/firmware/efi/Kconfig                  |  2 +-
>  drivers/firmware/efi/efi.c                    | 26 +++++++++++++
>  drivers/firmware/efi/memmap.c                 | 16 ++++++++
>  include/linux/efi.h                           |  4 ++
>  include/linux/mm.h                            |  2 +
>  mm/memblock.c                                 |  4 +-
>  mm/page_alloc.c                               |  4 +-
>  mm/sparse-vmemmap.c                           |  2 +-
>  13 files changed, 60 insertions(+), 88 deletions(-)
>
> --
> 2.18.0.huawei.25
>


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

* Re: [PATCH 0/9] introduce mirrored memory support for arm64
  2022-03-29  8:26 ` [PATCH 0/9] introduce mirrored memory support for arm64 Ard Biesheuvel
@ 2022-03-29 11:03   ` mawupeng
  0 siblings, 0 replies; 14+ messages in thread
From: mawupeng @ 2022-03-29 11:03 UTC (permalink / raw)
  To: ardb
  Cc: akpm, catalin.marinas, will, corbet, tglx, mingo, bp,
	dave.hansen, x86, hpa, dvhart, andy, rppt, paulmck, peterz,
	jroedel, songmuchun, macro, frederic, W_Armin, john.garry,
	seanjc, tsbogend, anshuman.khandual, chenhuacai, david, gpiccoli,
	mark.rutland, wangkefeng.wang, linux-doc, linux-kernel,
	linux-arm-kernel, linux-efi, linux-ia64, platform-driver-x86,
	linux-mm



在 2022/3/29 16:26, Ard Biesheuvel 写道:
> On Sat, 26 Mar 2022 at 07:27, Wupeng Ma <mawupeng1@huawei.com> wrote:
>>
>> From: Ma Wupeng <mawupeng1@huawei.com>
>>
>> Commit b05b9f5f9dcf ("x86, mirror: x86 enabling - find mirrored memory ranges")
>> introduced mirrored memory support for x86. This support rely on UEFI to
>> report mirrored memory address ranges.  See UEFI 2.5 spec pages 157-158:
>>
>>    http://www.uefi.org/sites/default/files/resources/UEFI%202_5.pdf
>>
>> Arm64 can support this too. So mirrored memory support is added to support
>> arm64.
>>
> 
> What is the point of this if the kernel itself is not loaded in
> EFI_MORE_RELIABLE memory? On x86, this is handled by the decompressor,
> but that does not exist on arm64.

Do you mean this is x86, commit c05cd79750fb
("x86/boot/KASLR: Prefer mirrored memory regions for the kernel physical address").
This scenario is not considered.

>  
> The problem here is that UEFI defines this as a memory *attribute*
> rather than a memory *type*, which means you cannot allocate
> EFI_MORE_RELIABLE memory easily: you have to iterate over the memory
> map and look for regions with the desired attribute, and allocate
> those pages explicitly. I'd prefer to implement this in the
> bootloader, and only add minimal logic to the stub to respect the
> placement of the kernel by the loader if the loader signals it to do
> so (there are other reasons for this - I will cc you on a patch
> shortly that implements this)

Thanks for your incoming patch.

> 
> This also means that the fake_mem stuff is not going to work: the
> memory map observed by the stub comes straight from the firmware, and
> if the stub needs to be involved in placing (or respecting the
> placement by the loader of) the kernel image, it needs to observe
> those EFI_MORE_RELIABLE regions too. If you don't have access to a
> machine that actually exposes EFI_MORE_RELIABLE memory, I suggest you
> prototype it in QEMU/edk2 instead.

You are right fake_mem stuff is not going to work. But, efi_fake_mem is
used for testing mirrored features and will not be used in production
environment. This test features can fake memory's attribute values.

The reason why efi_fake_mem support is put first is that memory's attribute
is reported by BIOS which is hard to simulate. With this support, any arm64
machines with efi support can easily test mirrored features.

> 
> In fact, we have been trying very hard not to touch the firmware
> provided memory map at all on ARM, rather than use it as a scratchpad
> for all kinds of annotations. This means, for instance, that kexec is
> idempotent - the next kernel should not be affected by modifications
> to the memory map applied by the previous kernel.

Yes, you're absolutely right. Efi_fake_mem is incompatible with kdump which
will use kexec. But we can remove specify cmdline(efi_fake_mem=xx) by
modofing /etc/sysconfig/kdump. Efi_fake_mem is only used for testing and
will not be used in production environment.

> 
> In summary, implementing kernelcore=mirror for arm64 is fine with me,
> but there are some issues we need to address first.
>
Can you be clear what the issues are?

The main purpose of this patchset is to introduce mirrored support for
arm64 and we have already fixed the problems we had which is shown in
patch #5 to patch #7 and try to bring total isolation in patch #8 which
will disable mirror feature if kernelcore is not specified.

Thanks for reviewing.

> 
> 
> 
>> Patch #1-#2 introduce efi_fake_mem support for arm64.
>> Patch #3-#4 introduce mirrored memory support form arm64.
>> Patch #5-#7 fix some bugs for arm64 if memory reliable is enabled.
>> Patch #8 disable mirror feature if kernelcore is not specified.
>> Patch #9 remove some redundant code in ia64 efi_init.
>>
>> Ma Wupeng (9):
>>    efi: Make efi_print_memmap() public
>>    arm64: efi: Add fake memory support
>>    efi: Make efi_find_mirror() public
>>    arm64/mirror: arm64 enabling - find mirrored memory ranges
>>    mm: Ratelimited mirrored memory related warning messages
>>    mm: Demote warning message in vmemmap_verify() to debug level
>>    mm: Calc the right pfn if page size is not 4K
>>    efi: Disable mirror feature if kernelcore is not specified
>>    ia64/efi: Code simplification in efi_init
>>
>>   .../admin-guide/kernel-parameters.txt         |  4 +-
>>   arch/arm64/kernel/setup.c                     |  3 ++
>>   arch/ia64/kernel/efi.c                        | 37 +-----------------
>>   arch/x86/include/asm/efi.h                    |  5 ---
>>   arch/x86/platform/efi/efi.c                   | 39 -------------------
>>   drivers/firmware/efi/Kconfig                  |  2 +-
>>   drivers/firmware/efi/efi.c                    | 26 +++++++++++++
>>   drivers/firmware/efi/memmap.c                 | 16 ++++++++
>>   include/linux/efi.h                           |  4 ++
>>   include/linux/mm.h                            |  2 +
>>   mm/memblock.c                                 |  4 +-
>>   mm/page_alloc.c                               |  4 +-
>>   mm/sparse-vmemmap.c                           |  2 +-
>>   13 files changed, 60 insertions(+), 88 deletions(-)
>>
>> --
>> 2.18.0.huawei.25
>>
> .


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

end of thread, other threads:[~2022-03-29 11:03 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-26  6:46 [PATCH 0/9] introduce mirrored memory support for arm64 Wupeng Ma
2022-03-26  6:46 ` [PATCH 1/9] efi: Make efi_print_memmap() public Wupeng Ma
2022-03-26  6:46 ` [PATCH 2/9] arm64: efi: Add fake memory support Wupeng Ma
2022-03-26  6:46 ` [PATCH 3/9] efi: Make efi_find_mirror() public Wupeng Ma
2022-03-26  6:46 ` [PATCH 4/9] arm64/mirror: arm64 enabling - find mirrored memory ranges Wupeng Ma
2022-03-26  6:46 ` [PATCH 5/9] mm: Ratelimited mirrored memory related warning messages Wupeng Ma
2022-03-26  6:46 ` [PATCH 6/9] mm: Demote warning message in vmemmap_verify() to debug level Wupeng Ma
2022-03-26  6:46 ` [PATCH 7/9] mm: Calc the right pfn if page size is not 4K Wupeng Ma
2022-03-28 12:33   ` David Hildenbrand
2022-03-29  1:14     ` mawupeng
2022-03-26  6:46 ` [PATCH 8/9] efi: Disable mirror feature if kernelcore is not specified Wupeng Ma
2022-03-26  6:46 ` [PATCH 9/9] ia64/efi: Code simplification in efi_init Wupeng Ma
2022-03-29  8:26 ` [PATCH 0/9] introduce mirrored memory support for arm64 Ard Biesheuvel
2022-03-29 11:03   ` mawupeng

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