From: Ma Wupeng <[email protected]>
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
From: Ma Wupeng <[email protected]>
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 <[email protected]>
---
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
From: Ma Wupeng <[email protected]>
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 <[email protected]>
---
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
From: Ma Wupeng <[email protected]>
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 <[email protected]>
---
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
From: Ma Wupeng <[email protected]>
Make efi_print_memmap() public in preparation for adding fake memory
support for architecture with efi support, eg, arm64.
Signed-off-by: Ma Wupeng <[email protected]>
---
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
From: Ma Wupeng <[email protected]>
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 <[email protected]>
---
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
From: Ma Wupeng <[email protected]>
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 <[email protected]>
---
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
From: Ma Wupeng <[email protected]>
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 <[email protected]>
---
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
From: Ma Wupeng <[email protected]>
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 <[email protected]>
---
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
From: Ma Wupeng <[email protected]>
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 <[email protected]>
---
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
On 26.03.22 07:46, Wupeng Ma wrote:
> From: Ma Wupeng <[email protected]>
>
> 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 <[email protected]>
> ---
> 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
在 2022/3/28 20:33, David Hildenbrand 写道:
> On 26.03.22 07:46, Wupeng Ma wrote:
>> From: Ma Wupeng <[email protected]>
>>
>> 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 <[email protected]>
>> ---
>> 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;
>> }
>
>
在 2022/3/29 16:26, Ard Biesheuvel 写道:
> On Sat, 26 Mar 2022 at 07:27, Wupeng Ma <[email protected]> wrote:
>>
>> From: Ma Wupeng <[email protected]>
>>
>> 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
>>
> .
On Sat, 26 Mar 2022 at 07:27, Wupeng Ma <[email protected]> wrote:
>
> From: Ma Wupeng <[email protected]>
>
> 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
>