* [PATCH v3 RESEND 0/2] x86: add support for reserved memory defined by
@ 2025-06-18 21:06 Grzegorz Jaszczyk
2025-06-18 21:06 ` [PATCH v3 RESEND 1/2] x86/of: add support for reserved memory defined by DT Grzegorz Jaszczyk
2025-06-18 21:06 ` [PATCH v3 RESEND 2/2] x86/e820: reserve corresponding to DT reserved-memory nomap region Grzegorz Jaszczyk
0 siblings, 2 replies; 3+ messages in thread
From: Grzegorz Jaszczyk @ 2025-06-18 21:06 UTC (permalink / raw)
To: tglx, robh
Cc: mingo, bp, dave.hansen, x86, hpa, saravanak, dmaluka, bgrzesik,
jaszczyk, ilpo.jarvinen, usamaarif642, linux-kernel, devicetree,
tnowicki, mazurekm, vineethrp, rppt, agordeev, dyoung,
myrrhperiwinkle, guoweikang.kernel, kirill.shutemov, akpm,
joel.granados, sourabhjain
From: Grzegorz Jaszczyk <jaszczyk@google.com>
Currently x86 allows to boot with ACPI and DT at the same time and basic DT
support is already in place but processing DT reserved memory was missing.
The DT reserved-memory nodes can be present in DT as described in
Documentation/devicetree/bindings/reserved-memory/reserved-memory.yaml.
Similar to other architecture, which supports DT, there is a need to
scan and register reserved memory regions on x86 for such nodes. It is required
by drivers (e.g. open-dice driver) to process DT reserved-memory regions.
v2 -> v3:
- Patch #1 which extends of/reserved_mem and adds the possibility to register an
arch specific hook was dropped. Instead "x86/e820: reserve corresponding to DT
reserved-memory nomap region" was introduced.
- "x86/of: add support for reserved memory defined by DT" stop relying on arch
specific hook. Also calling x86_flattree_get_config was moved and is now called
earlier during memblock setup.
For more info please refer to commit log description and v2 discussion:
https://lore.kernel.org/all/20250418124718.1009563-1-jaszczyk@chromium.org/
Grzegorz Jaszczyk (2):
x86/of: add support for reserved memory defined by DT
x86/e820: reserve corresponding to DT reserved-memory nomap region
arch/x86/include/asm/e820/api.h | 1 +
arch/x86/kernel/devicetree.c | 1 +
arch/x86/kernel/e820.c | 19 +++++++++++++++++++
arch/x86/kernel/setup.c | 6 ++++--
4 files changed, 25 insertions(+), 2 deletions(-)
--
2.50.0.rc2.701.gf1e915cc24-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 RESEND 1/2] x86/of: add support for reserved memory defined by DT
2025-06-18 21:06 [PATCH v3 RESEND 0/2] x86: add support for reserved memory defined by Grzegorz Jaszczyk
@ 2025-06-18 21:06 ` Grzegorz Jaszczyk
2025-06-18 21:06 ` [PATCH v3 RESEND 2/2] x86/e820: reserve corresponding to DT reserved-memory nomap region Grzegorz Jaszczyk
1 sibling, 0 replies; 3+ messages in thread
From: Grzegorz Jaszczyk @ 2025-06-18 21:06 UTC (permalink / raw)
To: tglx, robh
Cc: mingo, bp, dave.hansen, x86, hpa, saravanak, dmaluka, bgrzesik,
jaszczyk, ilpo.jarvinen, usamaarif642, linux-kernel, devicetree,
tnowicki, mazurekm, vineethrp, rppt, agordeev, dyoung,
myrrhperiwinkle, guoweikang.kernel, kirill.shutemov, akpm,
joel.granados, sourabhjain
From: Grzegorz Jaszczyk <jaszczyk@google.com>
The DT reserved-memory nodes can be present in DT as described in
Documentation/devicetree/bindings/reserved-memory/reserved-memory.yaml.
Similar to other architecture, which supports DT, there is a need to
create reserved memory regions for such nodes.
Additionally this patch changes the sequence and calls
x86_flattree_get_config earlier during memblock setup, just after e820
memblock setup, so the DT reserved-memory can be properly reflected in
the memblock before it is used for allocation.
Signed-off-by: Grzegorz Jaszczyk <jaszczyk@google.com>
---
arch/x86/kernel/devicetree.c | 1 +
arch/x86/kernel/setup.c | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/devicetree.c b/arch/x86/kernel/devicetree.c
index dd8748c45529..f7db0e8f9c3e 100644
--- a/arch/x86/kernel/devicetree.c
+++ b/arch/x86/kernel/devicetree.c
@@ -307,6 +307,7 @@ void __init x86_flattree_get_config(void)
}
early_init_dt_verify(dt, __pa(dt));
+ early_init_fdt_scan_reserved_mem();
}
unflatten_and_copy_device_tree();
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index fb27be697128..1c6fcb0bc65e 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1069,6 +1069,8 @@ void __init setup_arch(char **cmdline_p)
e820__memblock_setup();
+ x86_flattree_get_config();
+
/*
* Needs to run after memblock setup because it needs the physical
* memory size.
@@ -1179,8 +1181,6 @@ void __init setup_arch(char **cmdline_p)
early_acpi_boot_init();
x86_init.mpparse.early_parse_smp_cfg();
- x86_flattree_get_config();
-
initmem_init();
dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT);
--
2.50.0.rc2.701.gf1e915cc24-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3 RESEND 2/2] x86/e820: reserve corresponding to DT reserved-memory nomap region
2025-06-18 21:06 [PATCH v3 RESEND 0/2] x86: add support for reserved memory defined by Grzegorz Jaszczyk
2025-06-18 21:06 ` [PATCH v3 RESEND 1/2] x86/of: add support for reserved memory defined by DT Grzegorz Jaszczyk
@ 2025-06-18 21:06 ` Grzegorz Jaszczyk
1 sibling, 0 replies; 3+ messages in thread
From: Grzegorz Jaszczyk @ 2025-06-18 21:06 UTC (permalink / raw)
To: tglx, robh
Cc: mingo, bp, dave.hansen, x86, hpa, saravanak, dmaluka, bgrzesik,
jaszczyk, ilpo.jarvinen, usamaarif642, linux-kernel, devicetree,
tnowicki, mazurekm, vineethrp, rppt, agordeev, dyoung,
myrrhperiwinkle, guoweikang.kernel, kirill.shutemov, akpm,
joel.granados, sourabhjain
From: Grzegorz Jaszczyk <jaszczyk@google.com>
The reserved-memory nomap region shouldn't be mapped and registered as an
IORESOURCE_SYSTEM_RAM resource. On the x86 platform the resource tree
map is built based on e820 entries (see e820__reserve_resources).
Aligning DT reserved-memory nomap region by adding corresponding e820
reserved range will allow x86 to build appropriate resource tree.
Similar thing is done during e.g. arm64 resource tree creation (see:
arm64's request_standard_resources()).
Adding a corresponding e820 entry also allows other parts of x86 early
kernel initialization to rely on it. E.g. e820__setup_pci_gap based on
the gap in the e820 memory table picks space and passes to the PCI
subsystem. Without adding corresponding e820 reserved entry, DT
reserved memory nomap region could conflict with such region assigned
later to PCI subsystem.
Additionally updating e820_table in this stage of the x86 setup seems
safe since it is performed before mentioned e820__reserve_resources and
e820__setup_pci_gap and there are also other functions, which updates
e820 table on the later stage of early x86 setup such as early_quirks()
and efi_arch_mem_reserve() (used by efi_esrt_init).
Signed-off-by: Grzegorz Jaszczyk <jaszczyk@google.com>
---
arch/x86/include/asm/e820/api.h | 1 +
arch/x86/kernel/e820.c | 19 +++++++++++++++++++
arch/x86/kernel/setup.c | 2 ++
3 files changed, 22 insertions(+)
diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index c83645d5b2a8..a3b39ec6c3b4 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -28,6 +28,7 @@ extern unsigned long e820__end_of_low_ram_pfn(void);
extern u64 e820__memblock_alloc_reserved(u64 size, u64 align);
extern void e820__memblock_setup(void);
+extern void e820__reserve_nomap_region(void);
extern void e820__finish_early_params(void);
extern void e820__reserve_resources(void);
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index c3acbd26408b..4e76e0ea3823 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1330,3 +1330,22 @@ void __init e820__memblock_setup(void)
memblock_dump_all();
}
+
+void __init e820__reserve_nomap_region(void)
+{
+ struct memblock_region *region;
+ resource_size_t start;
+
+ for_each_mem_region(region) {
+ if (memblock_is_nomap(region)) {
+ start = __pfn_to_phys(memblock_region_reserved_base_pfn(region));
+
+ /*
+ * Add corresponding e820 region and let
+ * e820__update_table sanitize e820 map
+ */
+ e820__range_add(start, region->size, E820_TYPE_RESERVED);
+ e820__update_table_print();
+ }
+ }
+}
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 1c6fcb0bc65e..27969c529c3f 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1071,6 +1071,8 @@ void __init setup_arch(char **cmdline_p)
x86_flattree_get_config();
+ e820__reserve_nomap_region();
+
/*
* Needs to run after memblock setup because it needs the physical
* memory size.
--
2.50.0.rc2.701.gf1e915cc24-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-18 21:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-18 21:06 [PATCH v3 RESEND 0/2] x86: add support for reserved memory defined by Grzegorz Jaszczyk
2025-06-18 21:06 ` [PATCH v3 RESEND 1/2] x86/of: add support for reserved memory defined by DT Grzegorz Jaszczyk
2025-06-18 21:06 ` [PATCH v3 RESEND 2/2] x86/e820: reserve corresponding to DT reserved-memory nomap region Grzegorz Jaszczyk
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).