kexec: introduce Kexec HandOver (KHO)
Subsystems (11)
v8 cover kexec: introduce Kexec HandOver (KHO)
Hi,
This is the version 8 of "kexec: introduce Kexec HandOver (KHO)" series
(https://lore.kernel.org/all/[email protected]/)
form Alexander Graf, Mike Rapoport, and Changyuan Lyu.
The patches are also available in git:
https://github.com/googleprodkernel/linux-liveupdate/tree/kho/v8.
Section "How to Use" below includes steps for you to try KHO.
v7 -> v8:
- Add kho prefix to reference labels in documentation and adjust the wording slightly [1]
- Fold the fix from Arnd Bergmann into the base patch [2]
- Remove the #ifdef in KASLR, update comments and changelog, as requested [3]
- Remove kho_restore_folio() from reserve_mem_kho_retrieve_fdt() as at that stage, kho_mem_deserialize() has not been called yet.
- In kho_memory_init(), call kho_restore_folio() to restore the KHO root FDT's folio.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
Best,
Changyuan
= Original cover letter =
Kexec today considers itself purely a boot loader: When we enter the new kernel, any state the previous kernel left behind is irrelevant and the new kernel reinitializes the system.
However, there are use cases where this mode of operation is not what we actually want. In virtualization hosts for example, we want to use kexec to update the host kernel while virtual machine memory stays untouched. When we add device assignment to the mix, we also need to ensure that IOMMU and VFIO states are untouched. If we add PCIe peer to peer DMA, we need to do the same for the PCI subsystem. If we want to kexec while an SEV-SNP enabled virtual machine is running, we need to preserve the VM context pages and physical memory. See "pkernfs: Persisting guest memory and kernel/device state safely across kexec" Linux Plumbers Conference 2023 presentation for details:
https://lpc.events/event/17/contributions/1485/
To start us on the journey to support all the use cases above, this patch implements basic infrastructure to allow hand over of kernel state across kexec (Kexec HandOver, aka KHO). As a really simple example target, we use memblock's reserve_mem.
With this patch set applied, memory that was reserved using "reserve_mem" command line options remains intact after kexec and it is guaranteed to reside at the same physical address.
== Alternatives ==
There are alternative approaches to (parts of) the problems above:
* Memory Pools [1] - preallocated persistent memory region + allocator
* PRMEM [2] - resizable persistent memory regions with fixed metadata pointer on the kernel command line + allocator
* Pkernfs [3] - preallocated file system for in-kernel data with fixed address location on the kernel command line
* PKRAM [4] - handover of user space pages using a fixed metadata page specified via command line
All of the approaches above fundamentally have the same problem: They require the administrator to explicitly carve out a physical memory location because they have no mechanism outside of the kernel command line to pass data (including memory reservations) between kexec'ing kernels.
KHO provides that base foundation. We will determine later whether we still need any of the approaches above for fast bulk memory handover of for example IOMMU page tables. But IMHO they would all be users of KHO, with KHO providing the foundational primitive to pass metadata and bulk memory reservations as well as provide easy versioning for data.
== Overview ==
We introduce a metadata file that the kernels pass between each other. How they pass it is architecture specific. The file's format is a Flattened Device Tree (fdt) which has a generator and parser already included in Linux. KHO is enabled in the kernel command line by kho=on. When the root user enables KHO through /sys/kernel/debug/kho/out/finalize, the kernel invokes callbacks to every KHO users to register preserved memory regions, which contain drivers' states.
When the actual kexec happens, the fdt is part of the image
set that we boot into. In addition, we keep "scratch regions" available for kexec: physically contiguous memory regions that are guaranteed to not have any memory that KHO would preserve. The new kernel bootstraps itself using the scratch regions and sets all handed over memory as in use. When drivers initialize that support KHO, they introspect the fdt, restore preserved memory regions, and retrieve their states stored in the preserved memory.
== Limitations ==
Currently KHO is only implemented for file based kexec. The kernel interfaces in the patch set are already in place to support user space kexec as well, but it is still not implemented it yet inside kexec tools.
== How to Use ==
To use the code, please boot the kernel with the "kho=on" command line parameter. KHO will automatically create scratch regions. If you want to set the scratch size explicitly you can use "kho_scratch=" command line parameter. For instance, "kho_scratch=16M,512M,256M" will reserve a 16 MiB low memory scratch area, a 512 MiB global scratch region, and 256 MiB per NUMA node scratch regions on boot.
Make sure to have a reserved memory range requested with reserv_mem command line option, for example, "reserve_mem=64m:4k:n1".
Then before you invoke file based "kexec -l", finalize KHO FDT:
# echo 1 > /sys/kernel/debug/kho/out/finalize
You can preview the generated FDT using dtc,
# dtc /sys/kernel/debug/kho/out/fdt # dtc /sys/kernel/debug/kho/out/sub_fdts/memblock
dtc is available on ubuntu by sudo apt-get install device-tree-compiler.
Now kexec into the new kernel,
# kexec -l Image --initrd=initrd -s # kexec -e
(The order of KHO finalization and "kexec -l" does not matter.)
The new kernel will boot up and contain the previous kernel's reserve_mem contents at the same physical address as the first kernel.
You can also review the FDT passed from the old kernel,
# dtc /sys/kernel/debug/kho/in/fdt # dtc /sys/kernel/debug/kho/in/sub_fdts/memblock
== Changelog ==
v6 -> v7:
- Remove struct kho_serialization * from kho_preserve_phys() and kho_preserve_folio() parameter list, which allows KHO users to preserve memory anytime before KHO finalization, not only just in notifier callbacks (v6).
- Include the change [1] suggested by [2]
- Split "x86: add KHO support" into small patches suggested by [3]
- Include asm/early_ioremap.h [4]
- Make KHO depend on 64BIT on x86 [5]
- KHO fields (16 bytes) are defined in struct kimage unconditionally [5], replace a few #ifdef with IS_ENABLED().
- Rebase the patchset to v6.15-rc4 such that tests in tools/testing/memblock can pass.
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/[email protected]/
[4] https://lore.kernel.org/lkml/[email protected]/
[5] https://lore.kernel.org/lkml/[email protected]/
v5 -> v6:
- Rebase the patchset on v6.15-rc1.
- Revert hashtable-based API introduced in V5.
- In kho_parse_scratch_size(), replace simple_strtoul() with kstrtouint().
- Make KHO focus on memory preservation. Subsystem's metadata is not saved into KHO root tree, instead Subsystems allocate and create their own FDT and use KHO to preserve the FDT's underlying folios, suggested by [6].
- Subsystem's own FDT is presented at debugfs kho/(in|out)/sub_fdts/$name.
- Remove fdt_max, limit KHO root FDT to 1 page [6].
- Move linked pages of bitmaps of preserved memory from /preserved-memory.metadata to preserved-memory-map of KHO root FDT as suggested in [1].
- Add struct kho_serialization to hold the root FDT and struct kho_mem_track, and pass it through notifiers, as suggested in [2].
- Update the KHO example of memblock. memblock now prepares its own FDT early. In the notifier callback, it only preserves the memory and saves its own FDT blob address to KHO root tree.
- Add the doc of KHO property in node 'chosen' to github.com/devicetree-org/dt-schema [3] as requested in [4].
- Add back YAML files to describe KHO and memblock FDT bindings as requested
in [2]
- Remove kho_restore_phys().
- Move documentations to Documentation/admin-guide/kho.rst and
Documentation/core-api/kho as requested in [5].
- Split KHO from kexec in MAINTAINERS.
- kho_restore_folio() refuses to create folios larger than
MAX_PAGE_ORDER [7]. - Fix the bug on arm64 reported in [8].
- Fix the bug in kho_preserve_phys() reported in [9].
- Check KHO root node "compatible" in kho_populate().
Since the discussion of the data format for serializing preserved memory [10] is still going on, this version goes with the original xarray+bitmap approach and save the optimization for future versions/patches.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://github.com/devicetree-org/dt-schema/pull/158
[4] https://lore.kernel.org/all/[email protected]/
[5] https://lore.kernel.org/all/[email protected]/
[6] https://lore.kernel.org/all/[email protected]/
[7] https://lore.kernel.org/all/[email protected]/
[8] https://lore.kernel.org/all/[email protected]/
[9] https://lore.kernel.org/all/[email protected]/
[10] https://lore.kernel.org/all/[email protected]/
v4 -> v5:
- New: Preserve folios and address ranges in bitmaps [1]. Removed the mem property.
- New: Hash table based API for manipulating the KHO state tree.
- Change the concept of "active phase" to "finalization phase". KHO users can add/remove data into/from KHO DT anytime before the finalization phase.
- Decouple kexec_file_load and KHO FDT creation. kexec_file_load can be done before KHO FDT is created.
- Update the example usecase (reserve_mem) using the new KHO API, replace underscores with dashes in reserve-mem fdt generation.
- Drop the YAMLs for now and add a brief description of KHO FDT before KHO schema is stable.
- Move all sysfs interfaces to debugfs.
- Fixed the memblock test reported in [2].
- Incorporate fix for kho_locate_mem_hole() with !CONFIG_KEXEC_HANDOVER
[3] into "kexec: Add KHO support to kexec file loads".
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/20250217040448.56xejbvsr2a73h4c@master/
[3] https://lore.kernel.org/all/[email protected]/
v3 -> v4:
- Major rework of scrach management. Rather than force scratch memory allocations only very early in boot now we rely on scratch for all memblock allocations.
- Use simple example usecase (reserv_mem instead of ftrace)
- merge all KHO functionality into a single kernel/kexec_handover.c file
- rename CONFIG_KEXEC_KHO to CONFIG_KEXEC_HANDOVER
v2 -> v3:
- Fix make dt_binding_check
- Add descriptions for each object
- s/trace_flags/trace-flags/
- s/global_trace/global-trace/
- Make all additionalProperties false
- Change subject to reflect subsysten (dt-bindings)
- Fix indentation
- Remove superfluous examples
- Convert to 64bit syntax
- Move to kho directory
- s/"global_trace"/"global-trace"/
- s/"global_trace"/"global-trace"/
- s/"trace_flags"/"trace-flags"/
- Fix wording
- Add Documentation to MAINTAINERS file
- Remove kho reference on read error
- Move handover_dt unmap up
- s/reserve_scratch_mem/mark_phys_as_cma/
- Remove ifdeffery
- Remove superfluous comment
v1 -> v2:
- Removed: tracing: Introduce names for ring buffers
- Removed: tracing: Introduce names for events
- New: kexec: Add config option for KHO
- New: kexec: Add documentation for KHO
- New: tracing: Initialize fields before registering
- New: devicetree: Add bindings for ftrace KHO
- test bot warning fixes
- Change kconfig option to ARCH_SUPPORTS_KEXEC_KHO
- s/kho_reserve_mem/kho_reserve_previous_mem/g
- s/kho_reserve/kho_reserve_scratch/g
- Remove / reduce ifdefs
- Select crc32
- Leave anything that requires a name in trace.c to keep buffers unnamed entities
- Put events as array into a property, use fingerprint instead of names to identify them
- Reduce footprint without CONFIG_FTRACE_KHO
- s/kho_reserve_mem/kho_reserve_previous_mem/g
- make kho_get_fdt() const
- Add stubs for return_mem and claim_mem
- make kho_get_fdt() const
- Get events as array from a property, use fingerprint instead of names to identify events
- Change kconfig option to ARCH_SUPPORTS_KEXEC_KHO
- s/kho_reserve_mem/kho_reserve_previous_mem/g
- s/kho_reserve/kho_reserve_scratch/g
- Leave the node generation code that needs to know the name in trace.c so that ring buffers can stay anonymous
- s/kho_reserve/kho_reserve_scratch/g
- Move kho enums out of ifdef
- Move from names to fdt offsets. That way, trace.c can find the trace array offset and then the ring buffer code only needs to read out its per-CPU data. That way it can stay oblivient to its name.
- Make kho_get_fdt() const
Alexander Graf (12):
memblock: Add support for scratch memory
kexec: add Kexec HandOver (KHO) generation helpers
kexec: add KHO parsing support
kexec: add KHO support to kexec file loads
kexec: add config option for KHO
arm64: add KHO support
x86/kexec: add support for passing kexec handover (KHO) data x86/e820: temporarily enable KHO scratch for memory below 1M x86/boot: make sure KASLR does not step over KHO preserved memory x86/Kconfig: enable kexec handover for 64 bits
memblock: add KHO support for reserve_mem
Documentation: add documentation for KHO
Mike Rapoport (Microsoft) (5):
memblock: add MEMBLOCK_RSRV_KERN flag
memblock: introduce memmap_init_kho_scratch()
kexec: enable KHO support for memory preservation x86/setup: use memblock_reserve_kern for memory used by kernel
Documentation: KHO: Add memblock bindings
.../admin-guide/kernel-parameters.txt | 25 + Documentation/admin-guide/mm/index.rst | 1 + Documentation/admin-guide/mm/kho.rst | 115 ++ Documentation/core-api/index.rst | 1 + Documentation/core-api/kho/bindings/kho.yaml | 43 + .../kho/bindings/memblock/memblock.yaml | 39 + .../kho/bindings/memblock/reserve-mem.yaml | 40 + .../core-api/kho/bindings/sub-fdt.yaml | 27 + Documentation/core-api/kho/concepts.rst | 74 + Documentation/core-api/kho/fdt.rst | 80 ++ Documentation/core-api/kho/index.rst | 13 + MAINTAINERS | 12 + arch/arm64/Kconfig | 3 + arch/x86/Kconfig | 3 + arch/x86/boot/compressed/kaslr.c | 50 +- arch/x86/include/asm/setup.h | 2 + arch/x86/include/uapi/asm/setup_data.h | 13 +- arch/x86/kernel/e820.c | 18 + arch/x86/kernel/kexec-bzimage64.c | 37 + arch/x86/kernel/setup.c | 42 +- arch/x86/realmode/init.c | 2 + drivers/of/fdt.c | 34 + drivers/of/kexec.c | 42 + include/linux/kexec.h | 5 + include/linux/kexec_handover.h | 109 ++ include/linux/memblock.h | 41 +- kernel/Kconfig.kexec | 14 + kernel/Makefile | 1 + kernel/kexec_file.c | 13 + kernel/kexec_handover.c | 1266 +++++++++++++++++ kernel/kexec_internal.h | 16 + mm/Kconfig | 4 + mm/internal.h | 2 + mm/memblock.c | 317 ++++- mm/mm_init.c | 19 +- tools/testing/memblock/tests/alloc_api.c | 22 +- .../memblock/tests/alloc_helpers_api.c | 4 +- tools/testing/memblock/tests/alloc_nid_api.c | 20 +- 38 files changed, 2524 insertions(+), 45 deletions(-) create mode 100644 Documentation/admin-guide/mm/kho.rst create mode 100644 Documentation/core-api/kho/bindings/kho.yaml create mode 100644 Documentation/core-api/kho/bindings/memblock/memblock.yaml create mode 100644 Documentation/core-api/kho/bindings/memblock/reserve-mem.yaml create mode 100644 Documentation/core-api/kho/bindings/sub-fdt.yaml create mode 100644 Documentation/core-api/kho/concepts.rst create mode 100644 Documentation/core-api/kho/fdt.rst create mode 100644 Documentation/core-api/kho/index.rst create mode 100644 include/linux/kexec_handover.h create mode 100644 kernel/kexec_handover.c
base-commit: b4432656b36e5cc1d50a1f2dc15357543add530e --
2.49.0.1015.ga840276032-goog
PATCH v8 1/17 memblock: add MEMBLOCK_RSRV_KERN flag
From: "Mike Rapoport (Microsoft)" <[email protected]>
to denote areas that were reserved for kernel use either directly with memblock_reserve_kern() or via memblock allocations.
--- include/linux/memblock.h | 19 ++++++++- mm/memblock.c | 40 +++++++++++++++---- tools/testing/memblock/tests/alloc_api.c | 22 +++++----- .../memblock/tests/alloc_helpers_api.c | 4 +- tools/testing/memblock/tests/alloc_nid_api.c | 20 +++++----- 5 files changed, 73 insertions(+), 32 deletions(-)
include/linux/memblock.h +18 -1
@@ -42,6 +42,9 @@ extern unsigned long long max_possible_pfn;* kernel resource tree. * @MEMBLOCK_RSRV_NOINIT: memory region for which struct pages are * not initialized (only for reserved regions). +* @MEMBLOCK_RSRV_KERN: memory region that is reserved for kernel use, +* either explictitly with memblock_reserve_kern() or via memblock +* allocation APIs. All memblock allocations set this flag. */ enum memblock_flags {MEMBLOCK_NONE =0x0 ,/* No special request */
@@ -50,6 +53,7 @@ enum memblock_flags {MEMBLOCK_NOMAP =0x4 ,/* don't add to kernel direct mapping */ MEMBLOCK_DRIVER_MANAGED =0x8 ,/* always detected via a driver */ MEMBLOCK_RSRV_NOINIT =0x10 ,/* don't initialize struct pages */ + MEMBLOCK_RSRV_KERN = 0x20, /* memory reserved for kernel use */ };/**
@@ -116,7 +120,19 @@ int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid,int memblock_add (phys_addr_t base,phys_addr_t size);int memblock_remove (phys_addr_t base,phys_addr_t size);int memblock_phys_free (phys_addr_t base,phys_addr_t size); -int memblock_reserve (phys_addr_t base,phys_addr_t size); +int __memblock_reserve (phys_addr_t base,phys_addr_t size,int nid, +enum memblock_flags flags); + +static __always_inline int memblock_reserve(phys_addr_t base, phys_addr_t size) +{ +return __memblock_reserve (base, size,NUMA_NO_NODE ,0 ); +} + +static __always_inline int memblock_reserve_kern(phys_addr_t base, phys_addr_t size) +{ +return __memblock_reserve (base, size,NUMA_NO_NODE ,MEMBLOCK_RSRV_KERN ); +} +#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP int memblock_physmem_add (phys_addr_t base,phys_addr_t size);#endif
@@ -476,6 +492,7 @@ static inline __init_memblock bool memblock_bottom_up(void)phys_addr_t memblock_phys_mem_size (void );phys_addr_t memblock_reserved_size (void ); +phys_addr_t memblock_reserved_kern_size (phys_addr_t limit,int nid);unsigned long memblock_estimated_nr_free_pages (void );phys_addr_t memblock_start_of_DRAM (void );phys_addr_t memblock_end_of_DRAM (void );
mm/memblock.c +32 -8
@@ -492,7 +492,7 @@ static int __init_memblock memblock_double_array(struct memblock_type *type,* needn't do it */ if (!use_slab) -BUG_ON (memblock_reserve (addr, new_alloc_size)); +BUG_ON (memblock_reserve_kern (addr, new_alloc_size));/* Update slab flag */ *in_slab = use_slab;
@@ -642,7 +642,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,#ifdef CONFIG_NUMA WARN_ON (nid !=memblock_get_region_node (rgn));#endif -WARN_ON (flags != rgn->flags); +WARN_ON (flags !=MEMBLOCK_NONE && flags != rgn->flags); nr_new++;if (insert) {if (start_rgn ==-1 )
@@ -902,14 +902,15 @@ int __init_memblock memblock_phys_free(phys_addr_t base, phys_addr_t size)return memblock_remove_range (&memblock.reserved, base, size); } -int __init_memblock memblock_reserve(phys_addr_t base, phys_addr_t size) +int __init_memblock __memblock_reserve(phys_addr_t base, phys_addr_t size, +int nid,enum memblock_flags flags) {phys_addr_t end = base + size -1 ; -memblock_dbg ("%s: [%pa-%pa] %pS\n" , __func__, - &base, &end, (void *)_RET_IP_); +memblock_dbg ("%s: [%pa-%pa] nid=%d flags=%x %pS\n" , __func__, + &base, &end, nid, flags, (void *)_RET_IP_); -return memblock_add_range (&memblock.reserved, base, size,MAX_NUMNODES ,0 ); +return memblock_add_range (&memblock.reserved, base, size, nid, flags); }#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
@@ -1460,14 +1461,14 @@ phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size, again: found =memblock_find_in_range_node (size, align, start, end, nid, flags); -if (found && !memblock_reserve (found, size)) +if (found && !__memblock_reserve (found, size, nid,MEMBLOCK_RSRV_KERN )) goto done;if (numa_valid_node (nid) && !exact_nid) { found =memblock_find_in_range_node (size, align, start, end,NUMA_NO_NODE , flags); -if (found && !memblock_reserve (found, size)) +if (found && !memblock_reserve_kern (found, size)) goto done; }
@@ -1752,6 +1753,28 @@ phys_addr_t __init_memblock memblock_reserved_size(void)return memblock.reserved.total_size; } +phys_addr_t __init_memblock memblock_reserved_kern_size(phys_addr_t limit, int nid) +{ +struct memblock_region *r; +phys_addr_t total =0 ; + +for_each_reserved_mem_region (r) { +phys_addr_t size = r->size; + +if (r->base > limit) +break ; + +if (r->base + r->size > limit) + size = limit - r->base; + +if (nid ==memblock_get_region_node (r) || !numa_valid_node (nid)) +if (r->flags &MEMBLOCK_RSRV_KERN ) + total += size; + } + +return total; +} +/** * memblock_estimated_nr_free_pages - return estimated number of free pages * from memblock point of view
@@ -2441,6 +2464,7 @@ static const char * const flagname[] = { [ilog2(MEMBLOCK_NOMAP)] = "NOMAP", [ilog2(MEMBLOCK_DRIVER_MANAGED)] = "DRV_MNG", [ilog2(MEMBLOCK_RSRV_NOINIT)] = "RSV_NIT", + [ilog2(MEMBLOCK_RSRV_KERN)] = "RSV_KERN", };static int memblock_debug_show (struct seq_file *m,void *private)
tools/testing/memblock/tests/alloc_api.c +11 -11
@@ -134,7 +134,7 @@ static int alloc_top_down_before_check(void)PREFIX_PUSH ();setup_memblock (); -memblock_reserve (memblock_end_of_DRAM () - total_size, r1_size); +memblock_reserve_kern (memblock_end_of_DRAM () - total_size, r1_size); allocated_ptr =run_memblock_alloc (r2_size,SMP_CACHE_BYTES );
@@ -182,7 +182,7 @@ static int alloc_top_down_after_check(void) total_size = r1.size + r2_size; -memblock_reserve (r1.base, r1.size); +memblock_reserve_kern (r1.base, r1.size); allocated_ptr =run_memblock_alloc (r2_size,SMP_CACHE_BYTES );
@@ -231,8 +231,8 @@ static int alloc_top_down_second_fit_check(void) total_size = r1.size + r2.size + r3_size; -memblock_reserve (r1.base, r1.size); -memblock_reserve (r2.base, r2.size); +memblock_reserve_kern (r1.base, r1.size); +memblock_reserve_kern (r2.base, r2.size); allocated_ptr =run_memblock_alloc (r3_size,SMP_CACHE_BYTES );
@@ -285,8 +285,8 @@ static int alloc_in_between_generic_check(void) total_size = r1.size + r2.size + r3_size; -memblock_reserve (r1.base, r1.size); -memblock_reserve (r2.base, r2.size); +memblock_reserve_kern (r1.base, r1.size); +memblock_reserve_kern (r2.base, r2.size); allocated_ptr =run_memblock_alloc (r3_size,SMP_CACHE_BYTES );
@@ -422,7 +422,7 @@ static int alloc_limited_space_generic_check(void)setup_memblock ();/* Simulate almost-full memory */ -memblock_reserve (memblock_start_of_DRAM (), reserved_size); +memblock_reserve_kern (memblock_start_of_DRAM (), reserved_size); allocated_ptr =run_memblock_alloc (available_size,SMP_CACHE_BYTES );
@@ -608,7 +608,7 @@ static int alloc_bottom_up_before_check(void)PREFIX_PUSH ();setup_memblock (); -memblock_reserve (memblock_start_of_DRAM () + r1_size, r2_size); +memblock_reserve_kern (memblock_start_of_DRAM () + r1_size, r2_size); allocated_ptr =run_memblock_alloc (r1_size,SMP_CACHE_BYTES );
@@ -655,7 +655,7 @@ static int alloc_bottom_up_after_check(void) total_size = r1.size + r2_size; -memblock_reserve (r1.base, r1.size); +memblock_reserve_kern (r1.base, r1.size); allocated_ptr =run_memblock_alloc (r2_size,SMP_CACHE_BYTES );
@@ -705,8 +705,8 @@ static int alloc_bottom_up_second_fit_check(void) total_size = r1.size + r2.size + r3_size; -memblock_reserve (r1.base, r1.size); -memblock_reserve (r2.base, r2.size); +memblock_reserve_kern (r1.base, r1.size); +memblock_reserve_kern (r2.base, r2.size); allocated_ptr =run_memblock_alloc (r3_size,SMP_CACHE_BYTES );
tools/testing/memblock/tests/alloc_helpers_api.c +2 -2
@@ -163,7 +163,7 @@ static int alloc_from_top_down_no_space_above_check(void) min_addr =memblock_end_of_DRAM () -SMP_CACHE_BYTES *2 ;/* No space above this address */ -memblock_reserve (min_addr, r2_size); +memblock_reserve_kern (min_addr, r2_size); allocated_ptr =memblock_alloc_from (r1_size,SMP_CACHE_BYTES , min_addr);
@@ -199,7 +199,7 @@ static int alloc_from_top_down_min_addr_cap_check(void) start_addr = (phys_addr_t )memblock_start_of_DRAM (); min_addr = start_addr -SMP_CACHE_BYTES *3 ; -memblock_reserve (start_addr + r1_size,MEM_SIZE - r1_size); +memblock_reserve_kern (start_addr + r1_size,MEM_SIZE - r1_size); allocated_ptr =memblock_alloc_from (r1_size,SMP_CACHE_BYTES , min_addr);
tools/testing/memblock/tests/alloc_nid_api.c +10 -10
@@ -324,7 +324,7 @@ static int alloc_nid_min_reserved_generic_check(void) min_addr = max_addr - r2_size; reserved_base = min_addr - r1_size; -memblock_reserve (reserved_base, r1_size); +memblock_reserve_kern (reserved_base, r1_size); allocated_ptr = run_memblock_alloc_nid(r2_size, SMP_CACHE_BYTES, min_addr, max_addr,
@@ -374,7 +374,7 @@ static int alloc_nid_max_reserved_generic_check(void) max_addr =memblock_end_of_DRAM () - r1_size; min_addr = max_addr - r2_size; -memblock_reserve (max_addr, r1_size); +memblock_reserve_kern (max_addr, r1_size); allocated_ptr = run_memblock_alloc_nid(r2_size, SMP_CACHE_BYTES, min_addr, max_addr,
@@ -436,8 +436,8 @@ static int alloc_nid_top_down_reserved_with_space_check(void) min_addr = r2.base + r2.size; max_addr = r1.base; -memblock_reserve (r1.base, r1.size); -memblock_reserve (r2.base, r2.size); +memblock_reserve_kern (r1.base, r1.size); +memblock_reserve_kern (r2.base, r2.size); allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES, min_addr, max_addr,
@@ -499,8 +499,8 @@ static int alloc_nid_reserved_full_merge_generic_check(void) min_addr = r2.base + r2.size; max_addr = r1.base; -memblock_reserve (r1.base, r1.size); -memblock_reserve (r2.base, r2.size); +memblock_reserve_kern (r1.base, r1.size); +memblock_reserve_kern (r2.base, r2.size); allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES, min_addr, max_addr,
@@ -563,8 +563,8 @@ static int alloc_nid_top_down_reserved_no_space_check(void) min_addr = r2.base + r2.size; max_addr = r1.base; -memblock_reserve (r1.base, r1.size); -memblock_reserve (r2.base, r2.size); +memblock_reserve_kern (r1.base, r1.size); +memblock_reserve_kern (r2.base, r2.size); allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES, min_addr, max_addr,
@@ -909,8 +909,8 @@ static int alloc_nid_bottom_up_reserved_with_space_check(void) min_addr = r2.base + r2.size; max_addr = r1.base; -memblock_reserve (r1.base, r1.size); -memblock_reserve (r2.base, r2.size); +memblock_reserve_kern (r1.base, r1.size); +memblock_reserve_kern (r2.base, r2.size); allocated_ptr = run_memblock_alloc_nid(r3_size, SMP_CACHE_BYTES, min_addr, max_addr,
Signature · 1 line
2.49.0.1015.ga840276032-goog
Re: [PATCH v8 01/17] memblock: add MEMBLOCK_RSRV_KERN flag
Hello Chanyuan, Mike,
Quoted 12 lines · Changyuan Lyu
mm/memblock.c +1
-1@@ -492,7 +492,7 @@ static int __init_memblock memblock_double_array(struct memblock_type *type,* needn't do it */ if (!use_slab) -BUG_ON (memblock_reserve (addr, new_alloc_size)); +BUG_ON (memblock_reserve_kern (addr, new_alloc_size));/* Update slab flag */ *in_slab = use_slab;
mm/memblock.c static int __init_memblock memblock_add_range(struct memblock_type *type, · line 645
Quoted 5 lines
mm/memblock.c +1
-1@@ -642,7 +642,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,#ifdef CONFIG_NUMA WARN_ON (nid !=memblock_get_region_node (rgn));#endif -WARN_ON (flags != rgn->flags); +WARN_ON (flags !=MEMBLOCK_NONE && flags != rgn->flags);
I am hitting some sporadic warnings at early boot on a production kernel (6.16). Unfortunately this issue is not easily reproduce for me to test on upstream.
09:14:44 BIOS-provided physical RAM map: 09:14:44 BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable 09:14:44 BIOS-e820: [mem 0x00000000000a0000-0x00000000000fffff] reserved 09:14:44 BIOS-e820: [mem 0x0000000000100000-0x0000000064cb7fff] usable 09:14:44 BIOS-e820: [mem 0x0000000064cb8000-0x0000000064dc3fff] reserved 09:14:44 BIOS-e820: [mem 0x0000000064dc4000-0x0000000065b13fff] usable 09:14:44 BIOS-e820: [mem 0x0000000065b14000-0x0000000065b61fff] reserved 09:14:44 BIOS-e820: [mem 0x0000000065b62000-0x0000000065ed0fff] usable 09:14:44 BIOS-e820: [mem 0x0000000065ed1000-0x0000000065f2bfff] reserved 09:14:44 BIOS-e820: [mem 0x0000000065f2c000-0x0000000066621fff] usable 09:14:44 BIOS-e820: [mem 0x0000000066622000-0x0000000066630fff] reserved 09:14:44 BIOS-e820: [mem 0x0000000066631000-0x0000000068107fff] usable 09:14:44 BIOS-e820: [mem 0x0000000068108000-0x000000006819dfff] ACPI data 09:14:44 BIOS-e820: [mem 0x000000006819e000-0x000000006a48cfff] usable 09:14:44 BIOS-e820: [mem 0x000000006a48d000-0x000000006c58cfff] reserved 09:14:44 BIOS-e820: [mem 0x000000006c58d000-0x000000006c5dcfff] ACPI data 09:14:44 BIOS-e820: [mem 0x000000006c5dd000-0x000000006cfdcfff] ACPI NVS 09:14:44 BIOS-e820: [mem 0x000000006cfdd000-0x000000006e9fcfff] reserved 09:14:44 BIOS-e820: [mem 0x000000006e9fd000-0x000000006fffffff] usable 09:14:44 BIOS-e820: [mem 0x0000000070000000-0x000000008fffffff] reserved 09:14:44 BIOS-e820: [mem 0x00000000fd000000-0x00000000fe7fffff] reserved 09:14:44 BIOS-e820: [mem 0x00000000fed20000-0x00000000fed44fff] reserved 09:14:44 BIOS-e820: [mem 0x00000000ff000000-0x00000000ffffffff] reserved 09:14:44 BIOS-e820: [mem 0x0000000100000000-0x000000107fff655f] usable 09:14:44 BIOS-e820: [mem 0x000000107fff6560-0x000000107fff656f] type 128 09:14:44 BIOS-e820: [mem 0x000000107fff6570-0x000000107fffffff] usable 09:14:44 random: crng init done 09:14:44 ------------[ cut here ]------------ 09:14:44 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range (mm/memblock.c:668) 09:14:44 Modules linked in: 09:14:44 Tainted: [S]=CPU_OUT_OF_SPEC 09:14:44 RIP: 0010:memblock_add_range (mm/memblock.c:668) 09:14:44 Code: 28 80 3c 01 00 0f 84 04 fd ff ff 4c 89 ef e8 6c 77 09 00 e9 f7 fc ff ff 0f 0b 83 7c 24 1c 00 0f 85 9c fd ff ff e9 c5 fd ff ff <0f> 0b e9 be fd ff ff 44 89 f1 80 e1 07 80 c1 03 38 c1 0f 8c 6b fd All code ======== 0: 28 80 3c 01 00 0f sub %al,0xf00013c(%rax) 6: 84 04 fd ff ff 4c 89 test %al,-0x76b30001(,%rdi,8) d: ef out %eax,(%dx) e: e8 6c 77 09 00 call 0x9777f 13: e9 f7 fc ff ff jmp 0xfffffffffffffd0f 18: 0f 0b ud2 1a: 83 7c 24 1c 00 cmpl $0x0,0x1c(%rsp) 1f: 0f 85 9c fd ff ff jne 0xfffffffffffffdc1 25: e9 c5 fd ff ff jmp 0xfffffffffffffdef 2a:* 0f 0b ud2 <-- trapping instruction 2c: e9 be fd ff ff jmp 0xfffffffffffffdef 31: 44 89 f1 mov %r14d,%ecx 34: 80 e1 07 and $0x7,%cl 37: 80 c1 03 add $0x3,%cl 3a: 38 c1 cmp %al,%cl 3c: 0f .byte 0xf 3d: 8c 6b fd mov %gs,-0x3(%rbx) Code starting with the faulting instruction =========================================== 0: 0f 0b ud2 2: e9 be fd ff ff jmp 0xfffffffffffffdc5 7: 44 89 f1 mov %r14d,%ecx a: 80 e1 07 and $0x7,%cl d: 80 c1 03 add $0x3,%cl 10: 38 c1 cmp %al,%cl 12: 0f .byte 0xf 13: 8c 6b fd mov %gs,-0x3(%rbx) 09:14:44 RSP: 0000:ffffffff85e07d48 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 09:14:44 RAX: 0000000000000020 RBX: 0000000000001c00 RCX: dffffc0000000000 09:14:44 RDX: 000000000009f000 RSI: 000000000009d000 RDI: ffffffff8685ebf8 09:14:44 RBP: 0000000000000002 R08: 0000000000000020 R09: 0000000000000000 09:14:44 R10: ffffffffff200570 R11: fffffbffffe400b2 R12: 000000000009d000 09:14:44 R13: 0000000000100000 R14: ffffffff8edf5ce4 R15: ffffffff8edf5ce0 09:14:44 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 09:14:44 CR2: ffff888059e2dff8 CR3: 000000005bc1d000 CR4: 00000000000000b0 09:14:44 Call Trace: 09:14:44 <TASK> 09:14:44 ? __memblock_reserve (mm/memblock.c:936) 09:14:44 ? add_early_ima_buffer (arch/x86/kernel/setup.c:413) 09:14:44 ? parse_setup_data (arch/x86/kernel/setup.c:500) 09:14:44 ? setup_arch (arch/x86/kernel/setup.c:245 arch/x86/kernel/setup.c:958) 09:14:44 ? start_kernel (init/main.c:922) 09:14:44 ? x86_64_start_reservations (arch/x86/kernel/ebda.c:57) 09:14:44 ? x86_64_start_kernel (arch/x86/kernel/head64.c:231) 09:14:44 ? common_startup_64 (arch/x86/kernel/head_64.S:419) 09:14:44 </TASK> .... Memory: 49640988K/66772816K available (54946K kernel code, 19058K rwdata, 22636K rodata, 2940K init, 120968K bss, 10650188K reserved, 6291456K cma-reserved)
So, there is a memory override, and I am curious about it. Do you think it would be useful to expand this warning to dump more information about the issue? (only compiled tested)
if (flags != MEMBLOCK_NONE && flags != rgn->flags) {
pr_warn("memblock: Flag mismatch at region [%pa-%pa]\n",
&rgn->base, &rend);
pr_warn(" Existing region flags: %#x\n", rgn->flags);
pr_warn(" New range flags: %#x\n", flags);
pr_warn(" New range: [%pa-%pa]\n", &base, &end);
WARN_ON_ONCE(1);
}Thanks
--breno
Pratyush Yadav
maintainerRe: [PATCH v8 01/17] memblock: add MEMBLOCK_RSRV_KERN flag
Quoted 110 lines · Breno Leitao
Hello Chanyuan, Mike,
Quoted 12 lines · Changyuan Lyu
mm/memblock.c +1
-1@@ -492,7 +492,7 @@ static int __init_memblock memblock_double_array(struct memblock_type *type,* needn't do it */ if (!use_slab) -BUG_ON (memblock_reserve (addr, new_alloc_size)); +BUG_ON (memblock_reserve_kern (addr, new_alloc_size));/* Update slab flag */ *in_slab = use_slab;mm/memblock.c static int __init_memblock memblock_add_range(struct memblock_type *type, · line 645
Quoted 5 lines
mm/memblock.c +1
-1@@ -642,7 +642,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,#ifdef CONFIG_NUMA WARN_ON (nid !=memblock_get_region_node (rgn));#endif -WARN_ON (flags != rgn->flags); +WARN_ON (flags !=MEMBLOCK_NONE && flags != rgn->flags);I am hitting some sporadic warnings at early boot on a production kernel (6.16). Unfortunately this issue is not easily reproduce for me to test on upstream.
09:14:44 BIOS-provided physical RAM map: 09:14:44 BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable 09:14:44 BIOS-e820: [mem 0x00000000000a0000-0x00000000000fffff] reserved 09:14:44 BIOS-e820: [mem 0x0000000000100000-0x0000000064cb7fff] usable 09:14:44 BIOS-e820: [mem 0x0000000064cb8000-0x0000000064dc3fff] reserved 09:14:44 BIOS-e820: [mem 0x0000000064dc4000-0x0000000065b13fff] usable 09:14:44 BIOS-e820: [mem 0x0000000065b14000-0x0000000065b61fff] reserved 09:14:44 BIOS-e820: [mem 0x0000000065b62000-0x0000000065ed0fff] usable 09:14:44 BIOS-e820: [mem 0x0000000065ed1000-0x0000000065f2bfff] reserved 09:14:44 BIOS-e820: [mem 0x0000000065f2c000-0x0000000066621fff] usable 09:14:44 BIOS-e820: [mem 0x0000000066622000-0x0000000066630fff] reserved 09:14:44 BIOS-e820: [mem 0x0000000066631000-0x0000000068107fff] usable 09:14:44 BIOS-e820: [mem 0x0000000068108000-0x000000006819dfff] ACPI data 09:14:44 BIOS-e820: [mem 0x000000006819e000-0x000000006a48cfff] usable 09:14:44 BIOS-e820: [mem 0x000000006a48d000-0x000000006c58cfff] reserved 09:14:44 BIOS-e820: [mem 0x000000006c58d000-0x000000006c5dcfff] ACPI data 09:14:44 BIOS-e820: [mem 0x000000006c5dd000-0x000000006cfdcfff] ACPI NVS 09:14:44 BIOS-e820: [mem 0x000000006cfdd000-0x000000006e9fcfff] reserved 09:14:44 BIOS-e820: [mem 0x000000006e9fd000-0x000000006fffffff] usable 09:14:44 BIOS-e820: [mem 0x0000000070000000-0x000000008fffffff] reserved 09:14:44 BIOS-e820: [mem 0x00000000fd000000-0x00000000fe7fffff] reserved 09:14:44 BIOS-e820: [mem 0x00000000fed20000-0x00000000fed44fff] reserved 09:14:44 BIOS-e820: [mem 0x00000000ff000000-0x00000000ffffffff] reserved 09:14:44 BIOS-e820: [mem 0x0000000100000000-0x000000107fff655f] usable 09:14:44 BIOS-e820: [mem 0x000000107fff6560-0x000000107fff656f] type 128 09:14:44 BIOS-e820: [mem 0x000000107fff6570-0x000000107fffffff] usable 09:14:44 random: crng init done 09:14:44 ------------[ cut here ]------------ 09:14:44 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range (mm/memblock.c:668) 09:14:44 Modules linked in: 09:14:44 Tainted: [S]=CPU_OUT_OF_SPEC 09:14:44 RIP: 0010:memblock_add_range (mm/memblock.c:668) 09:14:44 Code: 28 80 3c 01 00 0f 84 04 fd ff ff 4c 89 ef e8 6c 77 09 00 e9 f7 fc ff ff 0f 0b 83 7c 24 1c 00 0f 85 9c fd ff ff e9 c5 fd ff ff <0f> 0b e9 be fd ff ff 44 89 f1 80 e1 07 80 c1 03 38 c1 0f 8c 6b fd All code ======== 0: 28 80 3c 01 00 0f sub %al,0xf00013c(%rax) 6: 84 04 fd ff ff 4c 89 test %al,-0x76b30001(,%rdi,8) d: ef out %eax,(%dx) e: e8 6c 77 09 00 call 0x9777f 13: e9 f7 fc ff ff jmp 0xfffffffffffffd0f 18: 0f 0b ud2 1a: 83 7c 24 1c 00 cmpl $0x0,0x1c(%rsp) 1f: 0f 85 9c fd ff ff jne 0xfffffffffffffdc1 25: e9 c5 fd ff ff jmp 0xfffffffffffffdef 2a:* 0f 0b ud2 <-- trapping instruction 2c: e9 be fd ff ff jmp 0xfffffffffffffdef 31: 44 89 f1 mov %r14d,%ecx 34: 80 e1 07 and $0x7,%cl 37: 80 c1 03 add $0x3,%cl 3a: 38 c1 cmp %al,%cl 3c: 0f .byte 0xf 3d: 8c 6b fd mov %gs,-0x3(%rbx) Code starting with the faulting instruction =========================================== 0: 0f 0b ud2 2: e9 be fd ff ff jmp 0xfffffffffffffdc5 7: 44 89 f1 mov %r14d,%ecx a: 80 e1 07 and $0x7,%cl d: 80 c1 03 add $0x3,%cl 10: 38 c1 cmp %al,%cl 12: 0f .byte 0xf 13: 8c 6b fd mov %gs,-0x3(%rbx) 09:14:44 RSP: 0000:ffffffff85e07d48 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 09:14:44 RAX: 0000000000000020 RBX: 0000000000001c00 RCX: dffffc0000000000 09:14:44 RDX: 000000000009f000 RSI: 000000000009d000 RDI: ffffffff8685ebf8 09:14:44 RBP: 0000000000000002 R08: 0000000000000020 R09: 0000000000000000 09:14:44 R10: ffffffffff200570 R11: fffffbffffe400b2 R12: 000000000009d000 09:14:44 R13: 0000000000100000 R14: ffffffff8edf5ce4 R15: ffffffff8edf5ce0 09:14:44 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 09:14:44 CR2: ffff888059e2dff8 CR3: 000000005bc1d000 CR4: 00000000000000b0 09:14:44 Call Trace: 09:14:44 <TASK> 09:14:44 ? __memblock_reserve (mm/memblock.c:936) 09:14:44 ? add_early_ima_buffer (arch/x86/kernel/setup.c:413) 09:14:44 ? parse_setup_data (arch/x86/kernel/setup.c:500) 09:14:44 ? setup_arch (arch/x86/kernel/setup.c:245 arch/x86/kernel/setup.c:958) 09:14:44 ? start_kernel (init/main.c:922) 09:14:44 ? x86_64_start_reservations (arch/x86/kernel/ebda.c:57) 09:14:44 ? x86_64_start_kernel (arch/x86/kernel/head64.c:231) 09:14:44 ? common_startup_64 (arch/x86/kernel/head_64.S:419) 09:14:44 </TASK> .... Memory: 49640988K/66772816K available (54946K kernel code, 19058K rwdata, 22636K rodata, 2940K init, 120968K bss, 10650188K reserved, 6291456K cma-reserved)
Quoted 1 line
So, there is a memory override, and I am curious about it. Do you think it
Yeah, it seems IMA is reserving a region that overlaps a region reserved by something else that doesn't use memblock_reserve_kern().
Quoted 11 lines
would be useful to expand this warning to dump more information about the issue? (only compiled tested)
if (flags != MEMBLOCK_NONE && flags != rgn->flags) { pr_warn("memblock: Flag mismatch at region [%pa-%pa]\n", &rgn->base, &rend); pr_warn(" Existing region flags: %#x\n", rgn->flags); pr_warn(" New range flags: %#x\n", flags); pr_warn(" New range: [%pa-%pa]\n", &base, &end); WARN_ON_ONCE(1); }
I suppose this would be useful. I think enabling memblock debug prints would also be helpful (using the "memblock=debug" commandline parameter) if it doesn't impact your production environment too much.
Signature · 2 lines
Regards, Pratyush Yadav
Pratyush Yadav
maintainerRe: [PATCH v8 01/17] memblock: add MEMBLOCK_RSRV_KERN flag
Quoted 129 lines · Pratyush Yadav
Quoted 110 lines · Breno Leitao
Hello Chanyuan, Mike,
Quoted 12 lines · Changyuan Lyu
mm/memblock.c +1
-1@@ -492,7 +492,7 @@ static int __init_memblock memblock_double_array(struct memblock_type *type,* needn't do it */ if (!use_slab) -BUG_ON (memblock_reserve (addr, new_alloc_size)); +BUG_ON (memblock_reserve_kern (addr, new_alloc_size));/* Update slab flag */ *in_slab = use_slab;mm/memblock.c static int __init_memblock memblock_add_range(struct memblock_type *type, · line 645
Quoted 5 lines
mm/memblock.c +1
-1@@ -642,7 +642,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,#ifdef CONFIG_NUMA WARN_ON (nid !=memblock_get_region_node (rgn));#endif -WARN_ON (flags != rgn->flags); +WARN_ON (flags !=MEMBLOCK_NONE && flags != rgn->flags);I am hitting some sporadic warnings at early boot on a production kernel (6.16). Unfortunately this issue is not easily reproduce for me to test on upstream.
09:14:44 BIOS-provided physical RAM map: 09:14:44 BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable 09:14:44 BIOS-e820: [mem 0x00000000000a0000-0x00000000000fffff] reserved 09:14:44 BIOS-e820: [mem 0x0000000000100000-0x0000000064cb7fff] usable 09:14:44 BIOS-e820: [mem 0x0000000064cb8000-0x0000000064dc3fff] reserved 09:14:44 BIOS-e820: [mem 0x0000000064dc4000-0x0000000065b13fff] usable 09:14:44 BIOS-e820: [mem 0x0000000065b14000-0x0000000065b61fff] reserved 09:14:44 BIOS-e820: [mem 0x0000000065b62000-0x0000000065ed0fff] usable 09:14:44 BIOS-e820: [mem 0x0000000065ed1000-0x0000000065f2bfff] reserved 09:14:44 BIOS-e820: [mem 0x0000000065f2c000-0x0000000066621fff] usable 09:14:44 BIOS-e820: [mem 0x0000000066622000-0x0000000066630fff] reserved 09:14:44 BIOS-e820: [mem 0x0000000066631000-0x0000000068107fff] usable 09:14:44 BIOS-e820: [mem 0x0000000068108000-0x000000006819dfff] ACPI data 09:14:44 BIOS-e820: [mem 0x000000006819e000-0x000000006a48cfff] usable 09:14:44 BIOS-e820: [mem 0x000000006a48d000-0x000000006c58cfff] reserved 09:14:44 BIOS-e820: [mem 0x000000006c58d000-0x000000006c5dcfff] ACPI data 09:14:44 BIOS-e820: [mem 0x000000006c5dd000-0x000000006cfdcfff] ACPI NVS 09:14:44 BIOS-e820: [mem 0x000000006cfdd000-0x000000006e9fcfff] reserved 09:14:44 BIOS-e820: [mem 0x000000006e9fd000-0x000000006fffffff] usable 09:14:44 BIOS-e820: [mem 0x0000000070000000-0x000000008fffffff] reserved 09:14:44 BIOS-e820: [mem 0x00000000fd000000-0x00000000fe7fffff] reserved 09:14:44 BIOS-e820: [mem 0x00000000fed20000-0x00000000fed44fff] reserved 09:14:44 BIOS-e820: [mem 0x00000000ff000000-0x00000000ffffffff] reserved 09:14:44 BIOS-e820: [mem 0x0000000100000000-0x000000107fff655f] usable 09:14:44 BIOS-e820: [mem 0x000000107fff6560-0x000000107fff656f] type 128 09:14:44 BIOS-e820: [mem 0x000000107fff6570-0x000000107fffffff] usable 09:14:44 random: crng init done 09:14:44 ------------[ cut here ]------------ 09:14:44 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range (mm/memblock.c:668) 09:14:44 Modules linked in: 09:14:44 Tainted: [S]=CPU_OUT_OF_SPEC 09:14:44 RIP: 0010:memblock_add_range (mm/memblock.c:668) 09:14:44 Code: 28 80 3c 01 00 0f 84 04 fd ff ff 4c 89 ef e8 6c 77 09 00 e9 f7 fc ff ff 0f 0b 83 7c 24 1c 00 0f 85 9c fd ff ff e9 c5 fd ff ff <0f> 0b e9 be fd ff ff 44 89 f1 80 e1 07 80 c1 03 38 c1 0f 8c 6b fd All code ======== 0: 28 80 3c 01 00 0f sub %al,0xf00013c(%rax) 6: 84 04 fd ff ff 4c 89 test %al,-0x76b30001(,%rdi,8) d: ef out %eax,(%dx) e: e8 6c 77 09 00 call 0x9777f 13: e9 f7 fc ff ff jmp 0xfffffffffffffd0f 18: 0f 0b ud2 1a: 83 7c 24 1c 00 cmpl $0x0,0x1c(%rsp) 1f: 0f 85 9c fd ff ff jne 0xfffffffffffffdc1 25: e9 c5 fd ff ff jmp 0xfffffffffffffdef 2a:* 0f 0b ud2 <-- trapping instruction 2c: e9 be fd ff ff jmp 0xfffffffffffffdef 31: 44 89 f1 mov %r14d,%ecx 34: 80 e1 07 and $0x7,%cl 37: 80 c1 03 add $0x3,%cl 3a: 38 c1 cmp %al,%cl 3c: 0f .byte 0xf 3d: 8c 6b fd mov %gs,-0x3(%rbx) Code starting with the faulting instruction =========================================== 0: 0f 0b ud2 2: e9 be fd ff ff jmp 0xfffffffffffffdc5 7: 44 89 f1 mov %r14d,%ecx a: 80 e1 07 and $0x7,%cl d: 80 c1 03 add $0x3,%cl 10: 38 c1 cmp %al,%cl 12: 0f .byte 0xf 13: 8c 6b fd mov %gs,-0x3(%rbx) 09:14:44 RSP: 0000:ffffffff85e07d48 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 09:14:44 RAX: 0000000000000020 RBX: 0000000000001c00 RCX: dffffc0000000000 09:14:44 RDX: 000000000009f000 RSI: 000000000009d000 RDI: ffffffff8685ebf8 09:14:44 RBP: 0000000000000002 R08: 0000000000000020 R09: 0000000000000000 09:14:44 R10: ffffffffff200570 R11: fffffbffffe400b2 R12: 000000000009d000 09:14:44 R13: 0000000000100000 R14: ffffffff8edf5ce4 R15: ffffffff8edf5ce0 09:14:44 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 09:14:44 CR2: ffff888059e2dff8 CR3: 000000005bc1d000 CR4: 00000000000000b0 09:14:44 Call Trace: 09:14:44 <TASK> 09:14:44 ? __memblock_reserve (mm/memblock.c:936) 09:14:44 ? add_early_ima_buffer (arch/x86/kernel/setup.c:413) 09:14:44 ? parse_setup_data (arch/x86/kernel/setup.c:500) 09:14:44 ? setup_arch (arch/x86/kernel/setup.c:245 arch/x86/kernel/setup.c:958) 09:14:44 ? start_kernel (init/main.c:922) 09:14:44 ? x86_64_start_reservations (arch/x86/kernel/ebda.c:57) 09:14:44 ? x86_64_start_kernel (arch/x86/kernel/head64.c:231) 09:14:44 ? common_startup_64 (arch/x86/kernel/head_64.S:419) 09:14:44 </TASK> .... Memory: 49640988K/66772816K available (54946K kernel code, 19058K rwdata, 22636K rodata, 2940K init, 120968K bss, 10650188K reserved, 6291456K cma-reserved)Quoted 1 line
So, there is a memory override, and I am curious about it. Do you think it
Yeah, it seems IMA is reserving a region that overlaps a region reserved by something else that doesn't use
memblock_reserve_kern().Quoted 11 lines
would be useful to expand this warning to dump more information about the issue? (only compiled tested)
if (flags != MEMBLOCK_NONE && flags != rgn->flags) { pr_warn("memblock: Flag mismatch at region [%pa-%pa]\n", &rgn->base, &rend); pr_warn(" Existing region flags: %#x\n", rgn->flags); pr_warn(" New range flags: %#x\n", flags); pr_warn(" New range: [%pa-%pa]\n", &base, &end); WARN_ON_ONCE(1); }
Quoted 3 lines
I suppose this would be useful. I think enabling memblock debug prints would also be helpful (using the "memblock=debug" commandline parameter) if it doesn't impact your production environment too much.
Actually, I think "memblock=debug" is going to be the more useful thing since it would also show what function allocated the overlapping range and the flags it was allocated with.
On my qemu VM with KVM, this results in around 70 prints from memblock. So it adds a bit of extra prints but nothing that should be too disrupting I think. Plus, only at boot so the worst thing you get is slightly slower boot times.
Signature · 2 lines
Regards, Pratyush Yadav
Re: [PATCH v8 01/17] memblock: add MEMBLOCK_RSRV_KERN flag
Hello Pratyush,
Quoted 6 lines · Pratyush Yadav
Quoted 4 lines · Pratyush Yadav
I suppose this would be useful. I think enabling memblock debug prints would also be helpful (using the "memblock=debug" commandline parameter) if it doesn't impact your production environment too much.
Quoted 8 lines
Actually, I think "memblock=debug" is going to be the more useful thing since it would also show what function allocated the overlapping range and the flags it was allocated with.
On my qemu VM with KVM, this results in around 70 prints from memblock. So it adds a bit of extra prints but nothing that should be too disrupting I think. Plus, only at boot so the worst thing you get is slightly slower boot times.
Unfortunately this issue is happening on production systems, and I don't have an easy way to reproduce it _yet_.
At the same time, "memblock=debug" has two problems:
1) It slows the boot time as you suggested. Boot time at large environments is SUPER critical and time sensitive. It is a bit weird, but it is common for machines in production to kexec _thousands_ of times, and kexecing is considered downtime.
This would be useful if I find some hosts getting this issue, and then I can easily enable the extra information to collect what I need, but, this didn't pan out because the hosts I got memblock=debug didn't collaborate.
2) "memblock=debug" is verbose for all cases, which also not necessary the desired behaviour. I am more interested in only being verbose when there is a known problem.
That said, my suggestion is to only dump extra information when something goes wrong, not affecting the boot time neither boot verbosity.
Pratyush Yadav
maintainerRe: [PATCH v8 01/17] memblock: add MEMBLOCK_RSRV_KERN flag
Quoted 21 lines · Breno Leitao
Hello Pratyush,
Quoted 6 lines · Pratyush Yadav
Quoted 4 lines · Pratyush Yadav
I suppose this would be useful. I think enabling memblock debug prints would also be helpful (using the "memblock=debug" commandline parameter) if it doesn't impact your production environment too much.
Quoted 8 lines
Actually, I think "memblock=debug" is going to be the more useful thing since it would also show what function allocated the overlapping range and the flags it was allocated with.
On my qemu VM with KVM, this results in around 70 prints from memblock. So it adds a bit of extra prints but nothing that should be too disrupting I think. Plus, only at boot so the worst thing you get is slightly slower boot times.
Unfortunately this issue is happening on production systems, and I don't have an easy way to reproduce it _yet_.
Quoted 6 lines
At the same time, "memblock=debug" has two problems:
1) It slows the boot time as you suggested. Boot time at large environments is SUPER critical and time sensitive. It is a bit weird, but it is common for machines in production to kexec _thousands_ of times, and kexecing is considered downtime.
I don't know if it would make a real enough difference on boot times, only that it should theoretically affect it, mainly if you are using serial for dmesg logs. Anyway, that's your production environment so you know best.
Quoted 6 lines
This would be useful if I find some hosts getting this issue, and then I can easily enable the extra information to collect what I need, but, this didn't pan out because the hosts I got
memblock=debugdidn't collaborate.
Quoted 7 lines
2) "memblock=debug" is verbose for all cases, which also not necessary the desired behaviour. I am more interested in only being verbose when there is a known problem.
That said, my suggestion is to only dump extra information when something goes wrong, not affecting the boot time neither boot verbosity.
With your proposed change, we only know what the overlapping area is, but not who allocated it. I don't see how that can be done when the error is detected. memblock debug lets us know that, which is why I suggested it.
Signature · 2 lines
Regards, Pratyush Yadav
Re: [PATCH v8 01/17] memblock: add MEMBLOCK_RSRV_KERN flag
Hello Pratyush,
Quoted 27 lines · Pratyush Yadav
Quoted 19 lines · Breno Leitao
Quoted 6 lines · Pratyush Yadav
Quoted 4 lines · Pratyush Yadav
I suppose this would be useful. I think enabling memblock debug prints would also be helpful (using the "memblock=debug" commandline parameter) if it doesn't impact your production environment too much.
Quoted 8 lines
Actually, I think "memblock=debug" is going to be the more useful thing since it would also show what function allocated the overlapping range and the flags it was allocated with.
On my qemu VM with KVM, this results in around 70 prints from memblock. So it adds a bit of extra prints but nothing that should be too disrupting I think. Plus, only at boot so the worst thing you get is slightly slower boot times.
Unfortunately this issue is happening on production systems, and I don't have an easy way to reproduce it _yet_.
Quoted 6 lines
At the same time, "memblock=debug" has two problems:
1) It slows the boot time as you suggested. Boot time at large environments is SUPER critical and time sensitive. It is a bit weird, but it is common for machines in production to kexec _thousands_ of times, and kexecing is considered downtime.
Quoted 14 lines
I don't know if it would make a real enough difference on boot times, only that it should theoretically affect it, mainly if you are using serial for dmesg logs. Anyway, that's your production environment so you know best.
Quoted 9 lines
This would be useful if I find some hosts getting this issue, and then I can easily enable the extra information to collect what I need, but, this didn't pan out because the hosts I got
memblock=debugdidn't collaborate.2) "memblock=debug" is verbose for all cases, which also not necessary the desired behaviour. I am more interested in only being verbose when there is a known problem.
I am still interested in this problem, and I finally found a host that constantly reproduce the issue and I was able to get memblock=debug cmdline. I am running 6.18-rc4 with some debug options enabled.
DMA-API: exceeded 7 overlapping mappings of cacheline 0x0000000006d6e400 WARNING: CPU: 58 PID: 828 at kernel/dma/debug.c:463 add_dma_entry+0x2e4/0x330 pc : add_dma_entry+0x2e4/0x330 lr : add_dma_entry+0x2e4/0x330 sp : ffff8000b036f7f0 x29: ffff8000b036f800 x28: 0000000000000001 x27: 0000000000000008 x26: ffff8000835f7fb8 x25: ffff8000835f7000 x24: ffff8000835f7ee0 x23: 0000000000000000 x22: 0000000006d6e400 x21: 0000000000000000 x20: 0000000006d6e400 x19: ffff0003f70c1100 x18: 00000000ffffffff x17: ffff80008019a2d8 x16: ffff80008019a08c x15: 0000000000000000 x14: 0000000000000000 x13: 0000000000000820 x12: ffff00011faeaf00 x11: 0000000000000000 x10: ffff8000834633d8 x9 : ffff8000801979d4 x8 : 00000000fffeffff x7 : ffff8000834633d8 x6 : 0000000000000000 x5 : 00000000000bfff4 x4 : 0000000000000000 x3 : ffff0001075eb7c0 x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0001075eb7c0 Call trace: add_dma_entry+0x2e4/0x330 (P) debug_dma_map_phys+0xc4/0xf0 dma_map_phys (/home/leit/Devel/upstream/./include/linux/dma-direct.h:138 /home/leit/Devel/upstream/kernel/dma/direct.h:102 /home/leit/Devel/upstream/kernel/dma/mapping.c:169) dma_map_page_attrs (/home/leit/Devel/upstream/kernel/dma/mapping.c:387) blk_dma_map_direct.isra.0 (/home/leit/Devel/upstream/block/blk-mq-dma.c:102) blk_dma_map_iter_start (/home/leit/Devel/upstream/block/blk-mq-dma.c:123 /home/leit/Devel/upstream/block/blk-mq-dma.c:196) blk_rq_dma_map_iter_start (/home/leit/Devel/upstream/block/blk-mq-dma.c:228) nvme_prep_rq+0xb8/0x9b8 nvme_queue_rq+0x44/0x1b0 blk_mq_dispatch_rq_list (/home/leit/Devel/upstream/block/blk-mq.c:2129) __blk_mq_sched_dispatch_requests (/home/leit/Devel/upstream/block/blk-mq-sched.c:314) blk_mq_sched_dispatch_requests (/home/leit/Devel/upstream/block/blk-mq-sched.c:329) blk_mq_run_work_fn (/home/leit/Devel/upstream/block/blk-mq.c:219 /home/leit/Devel/upstream/block/blk-mq.c:231) process_one_work (/home/leit/Devel/upstream/kernel/workqueue.c:991 /home/leit/Devel/upstream/kernel/workqueue.c:3213) worker_thread (/home/leit/Devel/upstream/./include/linux/list.h:163 /home/leit/Devel/upstream/./include/linux/list.h:191 /home/leit/Devel/upstream/./include/linux/list.h:319 /home/leit/Devel/upstream/kernel/workqueue.c:1153 /home/leit/Devel/upstream/kernel/workqueue.c:1205 /home/leit/Devel/upstream/kernel/workqueue.c:3426) kthread (/home/leit/Devel/upstream/kernel/kthread.c:386 /home/leit/Devel/upstream/kernel/kthread.c:457) ret_from_fork (/home/leit/Devel/upstream/entry.S:861)
Looking at memblock debug logs, I haven't seen anything related to 0x0000000006d6e400.
I got the output of dmesg | grep memblock in, in case you are curious:
https://github.com/leitao/debug/blob/main/pastebin/memblock/dmesg_grep_memblock.txt
Thanks
--breno
Mike Rapoport
maintainerRe: [PATCH v8 01/17] memblock: add MEMBLOCK_RSRV_KERN flag
Hello Breno,
Quoted 84 lines · Breno Leitao
Hello Pratyush,
Quoted 27 lines · Pratyush Yadav
Quoted 19 lines · Breno Leitao
Quoted 6 lines · Pratyush Yadav
Quoted 4 lines · Pratyush Yadav
I suppose this would be useful. I think enabling memblock debug prints would also be helpful (using the "memblock=debug" commandline parameter) if it doesn't impact your production environment too much.
Quoted 8 lines
Actually, I think "memblock=debug" is going to be the more useful thing since it would also show what function allocated the overlapping range and the flags it was allocated with.
On my qemu VM with KVM, this results in around 70 prints from memblock. So it adds a bit of extra prints but nothing that should be too disrupting I think. Plus, only at boot so the worst thing you get is slightly slower boot times.
Unfortunately this issue is happening on production systems, and I don't have an easy way to reproduce it _yet_.
Quoted 6 lines
At the same time, "memblock=debug" has two problems:
1) It slows the boot time as you suggested. Boot time at large environments is SUPER critical and time sensitive. It is a bit weird, but it is common for machines in production to kexec _thousands_ of times, and kexecing is considered downtime.
Quoted 14 lines
I don't know if it would make a real enough difference on boot times, only that it should theoretically affect it, mainly if you are using serial for dmesg logs. Anyway, that's your production environment so you know best.
Quoted 9 lines
This would be useful if I find some hosts getting this issue, and then I can easily enable the extra information to collect what I need, but, this didn't pan out because the hosts I got
memblock=debugdidn't collaborate.2) "memblock=debug" is verbose for all cases, which also not necessary the desired behaviour. I am more interested in only being verbose when there is a known problem.
I am still interested in this problem, and I finally found a host that constantly reproduce the issue and I was able to get
memblock=debugcmdline. I am running 6.18-rc4 with some debug options enabled.DMA-API: exceeded 7 overlapping mappings of cacheline 0x0000000006d6e400 WARNING: CPU: 58 PID: 828 at kernel/dma/debug.c:463 add_dma_entry+0x2e4/0x330 pc : add_dma_entry+0x2e4/0x330 lr : add_dma_entry+0x2e4/0x330 sp : ffff8000b036f7f0 x29: ffff8000b036f800 x28: 0000000000000001 x27: 0000000000000008 x26: ffff8000835f7fb8 x25: ffff8000835f7000 x24: ffff8000835f7ee0 x23: 0000000000000000 x22: 0000000006d6e400 x21: 0000000000000000 x20: 0000000006d6e400 x19: ffff0003f70c1100 x18: 00000000ffffffff x17: ffff80008019a2d8 x16: ffff80008019a08c x15: 0000000000000000 x14: 0000000000000000 x13: 0000000000000820 x12: ffff00011faeaf00 x11: 0000000000000000 x10: ffff8000834633d8 x9 : ffff8000801979d4 x8 : 00000000fffeffff x7 : ffff8000834633d8 x6 : 0000000000000000 x5 : 00000000000bfff4 x4 : 0000000000000000 x3 : ffff0001075eb7c0 x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0001075eb7c0 Call trace: add_dma_entry+0x2e4/0x330 (P) debug_dma_map_phys+0xc4/0xf0 dma_map_phys (/home/leit/Devel/upstream/./include/linux/dma-direct.h:138 /home/leit/Devel/upstream/kernel/dma/direct.h:102 /home/leit/Devel/upstream/kernel/dma/mapping.c:169) dma_map_page_attrs (/home/leit/Devel/upstream/kernel/dma/mapping.c:387) blk_dma_map_direct.isra.0 (/home/leit/Devel/upstream/block/blk-mq-dma.c:102) blk_dma_map_iter_start (/home/leit/Devel/upstream/block/blk-mq-dma.c:123 /home/leit/Devel/upstream/block/blk-mq-dma.c:196) blk_rq_dma_map_iter_start (/home/leit/Devel/upstream/block/blk-mq-dma.c:228) nvme_prep_rq+0xb8/0x9b8 nvme_queue_rq+0x44/0x1b0 blk_mq_dispatch_rq_list (/home/leit/Devel/upstream/block/blk-mq.c:2129) __blk_mq_sched_dispatch_requests (/home/leit/Devel/upstream/block/blk-mq-sched.c:314) blk_mq_sched_dispatch_requests (/home/leit/Devel/upstream/block/blk-mq-sched.c:329) blk_mq_run_work_fn (/home/leit/Devel/upstream/block/blk-mq.c:219 /home/leit/Devel/upstream/block/blk-mq.c:231) process_one_work (/home/leit/Devel/upstream/kernel/workqueue.c:991 /home/leit/Devel/upstream/kernel/workqueue.c:3213) worker_thread (/home/leit/Devel/upstream/./include/linux/list.h:163 /home/leit/Devel/upstream/./include/linux/list.h:191 /home/leit/Devel/upstream/./include/linux/list.h:319 /home/leit/Devel/upstream/kernel/workqueue.c:1153 /home/leit/Devel/upstream/kernel/workqueue.c:1205 /home/leit/Devel/upstream/kernel/workqueue.c:3426) kthread (/home/leit/Devel/upstream/kernel/kthread.c:386 /home/leit/Devel/upstream/kernel/kthread.c:457) ret_from_fork (/home/leit/Devel/upstream/entry.S:861)
Quoted 2 lines
Looking at memblock debug logs, I haven't seen anything related to
0x0000000006d6e400.
It looks like the crash happens way after memblock passed all the memory to buddy. Why do you think this is related to memblock?
Quoted 7 lines
I got the output of
dmesg | grep memblockin, in case you are curious:https://github.com/leitao/debug/blob/main/pastebin/memblock/dmesg_grep_memblock.txt
Thanks
--breno
Signature · 2 lines
Sincerely yours, Mike.
PATCH v8 2/17 memblock: Add support for scratch memory
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
With KHO (Kexec HandOver), we need a way to ensure that the new kernel does not allocate memory on top of any memory regions that the previous kernel was handing over. But to know where those are, we need to include them in the memblock.reserved array which may not be big enough to hold all ranges that need to be persisted across kexec. To resize the array, we need to allocate memory. That brings us into a catch 22 situation.
The solution to that is limit memblock allocations to the scratch regions:
safe regions to operate in the case when there is memory that should remain intact across kexec.
KHO provides several "scratch regions" as part of its metadata. These scratch regions are contiguous memory blocks that known not to contain any memory that should be persisted across kexec. These regions should be large enough to accommodate all memblock allocations done by the kexeced kernel.
We introduce a new memblock_set_scratch_only() function that allows KHO to indicate that any memblock allocation must happen from the scratch regions.
Later, we may want to perform another KHO kexec. For that, we reuse the same scratch regions. To ensure that no eventually handed over data gets allocated inside a scratch region, we flip the semantics of the scratch region with memblock_clear_scratch_only(): After that call, no allocations may happen from scratch memblock regions. We will lift that restriction in the next patch.
--- include/linux/memblock.h | 20 +++++++++++++ mm/Kconfig | 4 +++ mm/memblock.c | 61 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+)
include/linux/memblock.h +20 -0
@@ -45,6 +45,11 @@ extern unsigned long long max_possible_pfn;* @MEMBLOCK_RSRV_KERN: memory region that is reserved for kernel use, * either explictitly with memblock_reserve_kern() or via memblock * allocation APIs. All memblock allocations set this flag. +* @MEMBLOCK_KHO_SCRATCH: memory region that kexec can pass to the next +* kernel in handover mode. During early boot, we do not know about all +* memory reservations yet, so we get scratch memory from the previous +* kernel that we know is good to use. It is the only memory that +* allocations may happen from in this phase. */ enum memblock_flags {MEMBLOCK_NONE =0x0 ,/* No special request */
@@ -54,6 +59,7 @@ enum memblock_flags {MEMBLOCK_DRIVER_MANAGED =0x8 ,/* always detected via a driver */ MEMBLOCK_RSRV_NOINIT =0x10 ,/* don't initialize struct pages */ MEMBLOCK_RSRV_KERN =0x20 ,/* memory reserved for kernel use */ + MEMBLOCK_KHO_SCRATCH = 0x40, /* scratch memory for kexec handover */ };/**
@@ -148,6 +154,8 @@ int memblock_mark_mirror(phys_addr_t base, phys_addr_t size);int memblock_mark_nomap (phys_addr_t base,phys_addr_t size);int memblock_clear_nomap (phys_addr_t base,phys_addr_t size);int memblock_reserved_mark_noinit (phys_addr_t base,phys_addr_t size); +int memblock_mark_kho_scratch (phys_addr_t base,phys_addr_t size); +int memblock_clear_kho_scratch (phys_addr_t base,phys_addr_t size);void memblock_free (void *ptr,size_t size);void reset_all_zones_managed_pages (void );
@@ -291,6 +299,11 @@ static inline bool memblock_is_driver_managed(struct memblock_region *m)return m->flags &MEMBLOCK_DRIVER_MANAGED ; } +static inline bool memblock_is_kho_scratch (struct memblock_region *m) +{ +return m->flags &MEMBLOCK_KHO_SCRATCH ; +} +int memblock_search_pfn_nid (unsigned long pfn,unsigned long *start_pfn,unsigned long *end_pfn); void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
@@ -619,5 +632,12 @@ static inline void early_memtest(phys_addr_t start, phys_addr_t end) { }static inline void memtest_report_meminfo (struct seq_file *m) { }#endif +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH +void memblock_set_kho_scratch_only (void ); +void memblock_clear_kho_scratch_only (void ); +#else +static inline void memblock_set_kho_scratch_only (void ) { } +static inline void memblock_clear_kho_scratch_only (void ) { } +#endif #endif /* _LINUX_MEMBLOCK_H */
mm/Kconfig +4 -0
@@ -469,6 +469,10 @@ config HAVE_GUP_FAST depends on MMU bool +# Enable memblock support for scratch memory which is needed for kexec handover +config MEMBLOCK_KHO_SCRATCH + bool + # Don't discard allocated memory used to track "memory" and "reserved" memblocks # after early boot, so it can still be used to test for validity of memory. # Also, memblocks are updated with memory hot(un)plug.
mm/memblock.c +61 -0
97 lines not on this page · raw message
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 3/17 memblock: introduce memmap_init_kho_scratch()
In reply to Changyuan LyuFrom: "Mike Rapoport (Microsoft)" <[email protected]>
With deferred initialization of struct page it will be necessary to initialize memory map for KHO scratch regions early.
Add memmap_init_kho_scratch() method that will allow such initialization in upcoming patches.
--- include/linux/memblock.h | 2 ++ mm/internal.h | 2 ++ mm/memblock.c | 22 ++++++++++++++++++++++ mm/mm_init.c | 11 ++++++++--- 4 files changed, 34 insertions(+), 3 deletions(-)
include/linux/memblock.h +2 -0
@@ -635,9 +635,11 @@ static inline void memtest_report_meminfo(struct seq_file *m) { }#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH void memblock_set_kho_scratch_only (void );void memblock_clear_kho_scratch_only (void ); +void memmap_init_kho_scratch_pages (void );#else static inline void memblock_set_kho_scratch_only (void ) { }static inline void memblock_clear_kho_scratch_only (void ) { } +static inline void memmap_init_kho_scratch_pages (void ) {}#endif #endif /* _LINUX_MEMBLOCK_H */
mm/internal.h +2 -0
@@ -1121,6 +1121,8 @@ DECLARE_STATIC_KEY_TRUE(deferred_pages);bool __init deferred_grow_zone (struct zone *zone,unsigned int order);#endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */ +void init_deferred_page (unsigned long pfn,int nid); +enum mminit_level {MMINIT_WARNING ,MMINIT_VERIFY ,
mm/memblock.c +22 -0
@@ -946,6 +946,28 @@ __init void memblock_clear_kho_scratch_only(void) { kho_scratch_only = false; } + +__init void memmap_init_kho_scratch_pages (void ) +{ +phys_addr_t start, end; +unsigned long pfn; +int nid; +u64 i; + +if (!IS_ENABLED (CONFIG_DEFERRED_STRUCT_PAGE_INIT )) +return ; + +/* +* Initialize struct pages for free scratch memory. +* The struct pages for reserved scratch memory will be set up in +* reserve_bootmem_region() +*/ +__for_each_mem_range (i, &memblock.memory,NULL ,NUMA_NO_NODE , +MEMBLOCK_KHO_SCRATCH , &start, &end, &nid) { +for (pfn =PFN_UP (start); pfn <PFN_DOWN (end); pfn++) +init_deferred_page (pfn, nid); + } +}#endif /**
mm/mm_init.c +8 -3
@@ -743,7 +743,7 @@ defer_init(int nid, unsigned long pfn, unsigned long end_pfn)return false; } -static void __meminit init_deferred_page (unsigned long pfn,int nid) +static void __meminit __init_deferred_page (unsigned long pfn,int nid) {if (early_page_initialised (pfn, nid))return ;
@@ -763,11 +763,16 @@ static inline bool defer_init(int nid, unsigned long pfn, unsigned long end_pfn) return false; } -static inline void init_deferred_page (unsigned long pfn,int nid) +static inline void __init_deferred_page (unsigned long pfn,int nid) { }#endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */ +void __meminit init_deferred_page (unsigned long pfn,int nid) +{ +__init_deferred_page (pfn, nid); +} +/* * Initialised pages do not have PageReserved set. This function is * called for each range allocated by the bootmem allocator and
@@ -784,7 +789,7 @@ void __meminit reserve_bootmem_region(phys_addr_t start,if (pfn_valid (start_pfn)) {struct page *page =pfn_to_page (start_pfn); -init_deferred_page (start_pfn, nid); +__init_deferred_page (start_pfn, nid);/* * no need for atomic set_bit because the struct
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 4/17 kexec: add Kexec HandOver (KHO) generation helpers
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
Add the infrastructure to generate Kexec HandOver metadata. Kexec HandOver is a mechanism that allows Linux to preserve state - arbitrary properties as well as memory locations - across kexec.
It does so using 2 concepts:
1) KHO FDT - Every KHO kexec carries a KHO specific flattened device tree blob that describes preserved memory regions. Device drivers can register to KHO to serialize and preserve their states before kexec.
2) Scratch Regions - CMA regions that we allocate in the first kernel. CMA gives us the guarantee that no handover pages land in those regions, because handover pages must be at a static physical memory location. We use these regions as the place to load future kexec images so that they won't collide with any handover data.
--- MAINTAINERS | 9 + include/linux/kexec_handover.h | 59 ++++ kernel/Makefile | 1 + kernel/kexec_handover.c | 557 +++++++++++++++++++++++++++++++++ mm/mm_init.c | 8 + 5 files changed, 634 insertions(+) create mode 100644 include/linux/kexec_handover.h create mode 100644 kernel/kexec_handover.c
MAINTAINERS +9 -0
@@ -13138,6 +13138,15 @@ F: include/linux/kexec.h F: include/uapi/linux/kexec.h F: kernel/kexec* +KEXEC HANDOVER (KHO) +M: Alexander Graf <[email protected]> +M: Mike Rapoport <[email protected]> +M: Changyuan Lyu <[email protected]> +L: [email protected] +S: Maintained +F: include/linux/kexec_handover.h +F: kernel/kexec_handover.c + KEYS-ENCRYPTED M: Mimi Zohar <[email protected]> L: [email protected]
include/linux/kexec_handover.h new file +59 -0
59 lines not on this page · raw message
kernel/Makefile +1 -0
@@ -80,6 +80,7 @@ obj-$(CONFIG_CRASH_DUMP) += crash_core.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_KEXEC_FILE) += kexec_file.o obj-$(CONFIG_KEXEC_ELF) += kexec_elf.o +obj-$(CONFIG_KEXEC_HANDOVER) += kexec_handover.o obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o obj-$(CONFIG_COMPAT) += compat.o obj-$(CONFIG_CGROUPS) += cgroup/
kernel/kexec_handover.c new file +557 -0
557 lines not on this page · raw message
mm/mm_init.c +8 -0
@@ -30,6 +30,7 @@#include <linux/crash_dump.h> #include <linux/execmem.h> #include <linux/vmstat.h> +#include <linux/kexec_handover.h> #include <linux/hugetlb.h> #include "internal.h" #include "slab.h"
@@ -2771,6 +2772,13 @@ void __init mm_core_init(void)report_meminit ();kmsan_init_shadow ();stack_depot_early_init (); + +/* +* KHO memory setup must happen while memblock is still active, but +* as close as possible to buddy initialization +*/ +kho_memory_init (); +memblock_free_all ();mem_init ();kmem_cache_init ();
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 5/17 kexec: add KHO parsing support
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
When we have a KHO kexec, we get an FDT blob and scratch region to populate the state of the system. Provide helper functions that allow architecture code to easily handle memory reservations based on them and give device drivers visibility into the KHO FDT and memory reservations so they can recover their own state.
Include a fix from Arnd Bergmann <[email protected]>
https://lore.kernel.org/lkml/[email protected]/.
--- include/linux/kexec_handover.h | 14 ++ kernel/kexec_handover.c | 233 ++++++++++++++++++++++++++++++++- mm/memblock.c | 1 + 3 files changed, 247 insertions(+), 1 deletion(-)
include/linux/kexec_handover.h +14 -0
@@ -24,11 +24,15 @@ struct kho_serialization;bool kho_is_enabled (void );int kho_add_subtree (struct kho_serialization *ser,const char *name,void *fdt); +int kho_retrieve_subtree (const char *name,phys_addr_t *phys);int register_kho_notifier (struct notifier_block *nb);int unregister_kho_notifier (struct notifier_block *nb);void kho_memory_init (void ); + +void kho_populate (phys_addr_t fdt_phys,u64 fdt_len,phys_addr_t scratch_phys, +u64 scratch_len);#else static inline bool kho_is_enabled (void ) {
@@ -41,6 +45,11 @@ static inline int kho_add_subtree(struct kho_serialization *ser,return -EOPNOTSUPP ; } +static inline int kho_retrieve_subtree (const char *name,phys_addr_t *phys) +{ +return -EOPNOTSUPP ; +} +static inline int register_kho_notifier (struct notifier_block *nb) {return -EOPNOTSUPP ;
@@ -54,6 +63,11 @@ static inline int unregister_kho_notifier(struct notifier_block *nb)static inline void kho_memory_init (void ) { } + +static inline void kho_populate (phys_addr_t fdt_phys,u64 fdt_len, +phys_addr_t scratch_phys,u64 scratch_len) +{ +}#endif /* CONFIG_KEXEC_HANDOVER */ #endif /* LINUX_KEXEC_HANDOVER_H */
kernel/kexec_handover.c +232 -1
260 lines not on this page · raw message
mm/memblock.c +1 -0
@@ -2377,6 +2377,7 @@ void __init memblock_free_all(void)free_unused_memmap ();reset_all_zones_managed_pages (); +memblock_clear_kho_scratch_only (); pages =free_low_memory_core_early ();totalram_pages_add (pages); }
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 6/17 kexec: enable KHO support for memory preservation
In reply to Changyuan LyuFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Introduce APIs allowing KHO users to preserve memory across kexec and get access to that memory after boot of the kexeced kernel
kho_preserve_folio() - record a folio to be preserved over kexec kho_restore_folio() - recreates the folio from the preserved memory kho_preserve_phys() - record physically contiguous range to be preserved over kexec.
The memory preservations are tracked by two levels of xarrays to manage chunks of per-order 512 byte bitmaps. For instance if PAGE_SIZE = 4096, the entire 1G order of a 1TB x86 system would fit inside a single 512 byte bitmap. For order 0 allocations each bitmap will cover 16M of address space. Thus, for 16G of memory at most 512K of bitmap memory will be needed for order 0.
At serialization time all bitmaps are recorded in a linked list of pages for the next kernel to process and the physical address of the list is recorded in KHO FDT.
The next kernel then processes that list, reserves the memory ranges and later, when a user requests a folio or a physical range, KHO restores corresponding memory map entries.
--- include/linux/kexec_handover.h | 36 +++ kernel/kexec_handover.c | 411 +++++++++++++++++++++++++++++++++ 2 files changed, 447 insertions(+)
include/linux/kexec_handover.h +36 -0
@@ -16,13 +16,34 @@ enum kho_event { KEXEC_KHO_ABORT = 1, }; +struct folio ;struct notifier_block ; +#define DECLARE_KHOSER_PTR (name, type) \ + union { \ + phys_addr_t phys; \ + type ptr; \ + } name +#define KHOSER_STORE_PTR (dest, val) \ + ({ \ + typeof(val) v = val; \ + typecheck(typeof((dest).ptr), v); \ + (dest).phys = virt_to_phys(v); \ + }) +#define KHOSER_LOAD_PTR (src) \ + ({ \ + typeof(src) s = src; \ + (typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \ + }) +struct kho_serialization ;#ifdef CONFIG_KEXEC_HANDOVER bool kho_is_enabled (void ); +int kho_preserve_folio (struct folio *folio); +int kho_preserve_phys (phys_addr_t phys,size_t size); +struct folio *kho_restore_folio (phys_addr_t phys);int kho_add_subtree (struct kho_serialization *ser,const char *name,void *fdt);int kho_retrieve_subtree (const char *name,phys_addr_t *phys);
@@ -39,6 +60,21 @@ static inline bool kho_is_enabled(void)return false; } +static inline int kho_preserve_folio (struct folio *folio) +{ +return -EOPNOTSUPP ; +} + +static inline int kho_preserve_phys (phys_addr_t phys,size_t size) +{ +return -EOPNOTSUPP ; +} + +static inline struct folio *kho_restore_folio (phys_addr_t phys) +{ +return NULL ; +} +static inline int kho_add_subtree (struct kho_serialization *ser,const char *name,void *fdt) {
kernel/kexec_handover.c +411 -0
474 lines not on this page · raw message
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 7/17 kexec: add KHO support to kexec file loads
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
Kexec has 2 modes: A user space driven mode and a kernel driven mode. For the kernel driven mode, kernel code determines the physical addresses of all target buffers that the payload gets copied into.
With KHO, we can only safely copy payloads into the "scratch area". Teach the kexec file loader about it, so it only allocates for that area. In addition, enlighten it with support to ask the KHO subsystem for its respective payloads to copy into target memory. Also teach the KHO subsystem how to fill the images for file loads.
--- include/linux/kexec.h | 5 +++ kernel/kexec_file.c | 13 ++++++++ kernel/kexec_handover.c | 67 +++++++++++++++++++++++++++++++++++++++++ kernel/kexec_internal.h | 16 ++++++++++ 4 files changed, 101 insertions(+)
include/linux/kexec.h +5 -0
@@ -371,6 +371,11 @@ struct kimage {size_t ima_buffer_size;#endif +struct { +struct kexec_segment *scratch; +phys_addr_t fdt; + } kho; +/* Core ELF header buffer */ void *elf_headers;unsigned long elf_headers_sz;
kernel/kexec_file.c +13 -0
@@ -253,6 +253,11 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd,/* IMA needs to pass the measurement list to the next kernel. */ ima_add_kexec_buffer (image); +/* If KHO is active, add its images to the list */ + ret =kho_fill_kimage (image); +if (ret) + goto out; +/* Call image load handler */ ldata =kexec_image_load_default (image);
@@ -648,6 +653,14 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf)if (kbuf->mem !=KEXEC_BUF_MEM_UNKNOWN )return 0 ; +/* +* If KHO is active, only use KHO scratch memory. All other memory +* could potentially be handed over. +*/ + ret =kho_locate_mem_hole (kbuf, locate_mem_hole_callback); +if (ret <=0 ) +return ret; +if (!IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) ret =kexec_walk_resources (kbuf, locate_mem_hole_callback);else
kernel/kexec_handover.c +67 -0
76 lines not on this page · raw message
kernel/kexec_internal.h +16 -0
@@ -39,4 +39,20 @@ extern size_t kexec_purgatory_size;#else /* CONFIG_KEXEC_FILE */ static inline void kimage_file_post_load_cleanup (struct kimage *image) { }#endif /* CONFIG_KEXEC_FILE */ + +struct kexec_buf ; + +#ifdef CONFIG_KEXEC_HANDOVER +int kho_locate_mem_hole (struct kexec_buf *kbuf, +int (*func)(struct resource *,void *)); +int kho_fill_kimage (struct kimage *image); +#else +static inline int kho_locate_mem_hole (struct kexec_buf *kbuf, +int (*func)(struct resource *,void *)) +{ +return 1 ; +} + +static inline int kho_fill_kimage (struct kimage *image) {return 0 ; } +#endif /* CONFIG_KEXEC_HANDOVER */ #endif /* LINUX_KEXEC_INTERNAL_H */
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 8/17 kexec: add config option for KHO
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
We have all generic code in place now to support Kexec with KHO. This patch adds a config option that depends on architecture support to enable KHO support.
--- kernel/Kconfig.kexec | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
kernel/Kconfig.kexec +14 -0
@@ -95,6 +95,20 @@ config KEXEC_JUMP Jump between original kernel and kexeced kernel and invoke code in physical address mode via KEXEC +config KEXEC_HANDOVER + bool "kexec handover" + depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE + select MEMBLOCK_KHO_SCRATCH + select KEXEC_FILE + select DEBUG_FS + select LIBFDT + select CMA + help + Allow kexec to hand over state across kernels by generating and + passing additional metadata to the target kernel. This is useful + to keep data or state alive across the kexec. For this to work, + both source and target kernels need to have this option enabled. + config CRASH_DUMP bool "kernel crash dumps" default ARCH_DEFAULT_CRASH_DUMP
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 9/17 arm64: add KHO support
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
We now have all bits in place to support KHO kexecs. Add awareness of KHO in the kexec file as well as boot path for arm64 and adds the respective kconfig option to the architecture so that it can use KHO successfully.
Changes to the "chosen" node have been sent to
https://github.com/devicetree-org/dt-schema/pull/158.
--- arch/arm64/Kconfig | 3 +++ drivers/of/fdt.c | 34 ++++++++++++++++++++++++++++++++++ drivers/of/kexec.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+)
arch/arm64/Kconfig +3 -0
@@ -1602,6 +1602,9 @@ config ARCH_SUPPORTS_KEXEC_IMAGE_VERIFY_SIG config ARCH_DEFAULT_KEXEC_IMAGE_VERIFY_SIG def_bool y +config ARCH_SUPPORTS_KEXEC_HANDOVER + def_bool y + config ARCH_SUPPORTS_CRASH_DUMP def_bool y
drivers/of/fdt.c +34 -0
@@ -25,6 +25,7 @@#include <linux/serial_core.h> #include <linux/sysfs.h> #include <linux/random.h> +#include <linux/kexec_handover.h> #include <asm/setup.h> /* for COMMAND_LINE_SIZE */ #include <asm/page.h>
@@ -875,6 +876,36 @@ void __init early_init_dt_check_for_usable_mem_range(void)memblock_add (rgn[i].base, rgn[i].size); } +/** +* early_init_dt_check_kho - Decode info required for kexec handover from DT +*/ +static void __init early_init_dt_check_kho (void ) +{ +unsigned long node = chosen_node_offset; +u64 fdt_start, fdt_size, scratch_start, scratch_size; +const __be32 *p; +int l; + +if (!IS_ENABLED (CONFIG_KEXEC_HANDOVER ) || (long )node <0 ) +return ; + + p =of_get_flat_dt_prop (node,"linux,kho-fdt" , &l); +if (l != (dt_root_addr_cells + dt_root_size_cells) *sizeof (__be32)) +return ; + + fdt_start =dt_mem_next_cell (dt_root_addr_cells, &p); + fdt_size =dt_mem_next_cell (dt_root_addr_cells, &p); + + p =of_get_flat_dt_prop (node,"linux,kho-scratch" , &l); +if (l != (dt_root_addr_cells + dt_root_size_cells) *sizeof (__be32)) +return ; + + scratch_start =dt_mem_next_cell (dt_root_addr_cells, &p); + scratch_size =dt_mem_next_cell (dt_root_addr_cells, &p); + +kho_populate (fdt_start, fdt_size, scratch_start, scratch_size); +} +#ifdef CONFIG_SERIAL_EARLYCON int __init early_init_dt_scan_chosen_stdout (void )
@@ -1169,6 +1200,9 @@ void __init early_init_dt_scan_nodes(void)/* Handle linux,usable-memory-range property */ early_init_dt_check_for_usable_mem_range (); + +/* Handle kexec handover */ +early_init_dt_check_kho (); }bool __init early_init_dt_scan (void *dt_virt,phys_addr_t dt_phys)
drivers/of/kexec.c +42 -0
54 lines not on this page · raw message
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 10/17 x86/setup: use memblock_reserve_kern for memory used by kernel
In reply to Changyuan LyuFrom: "Mike Rapoport (Microsoft)" <[email protected]>
memblock_reserve() does not distinguish memory used by firmware from memory used by kernel.
The distinction is nice to have for accounting of early memory allocations and reservations, but it is essential for kexec handover (kho) to know how much memory kernel consumes during boot.
Use memblock_reserve_kern() to reserve kernel memory, such as kernel image, initrd and setup data.
--- arch/x86/kernel/setup.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/x86/kernel/setup.c +8 -8
@@ -286,8 +286,8 @@ static void __init cleanup_highmap(void)static void __init reserve_brk (void ) {if (_brk_end > _brk_start) -memblock_reserve (__pa_symbol (_brk_start), - _brk_end - _brk_start); +memblock_reserve_kern (__pa_symbol (_brk_start), + _brk_end - _brk_start);/* Mark brk area as locked down and no longer taking any new allocations */
@@ -360,7 +360,7 @@ static void __init early_reserve_initrd(void) !ramdisk_image || !ramdisk_size)return ;/* No initrd provided by bootloader */ -memblock_reserve (ramdisk_image, ramdisk_end - ramdisk_image); +memblock_reserve_kern (ramdisk_image, ramdisk_end - ramdisk_image); }static void __init reserve_initrd (void )
@@ -413,7 +413,7 @@ static void __init add_early_ima_buffer(u64 phys_addr) }if (data->size) { -memblock_reserve (data->addr, data->size); +memblock_reserve_kern (data->addr, data->size); ima_kexec_buffer_phys = data->addr; ima_kexec_buffer_size = data->size; }
@@ -553,7 +553,7 @@ static void __init memblock_x86_reserve_range_setup_data(void) len =sizeof (*data); pa_next = data->next; -memblock_reserve (pa_data,sizeof (*data) + data->len); +memblock_reserve_kern (pa_data,sizeof (*data) + data->len);if (data->type ==SETUP_INDIRECT ) { len += data->len;
@@ -567,7 +567,7 @@ static void __init memblock_x86_reserve_range_setup_data(void) indirect = (struct setup_indirect *)data->data;if (indirect->type !=SETUP_INDIRECT ) -memblock_reserve (indirect->addr, indirect->len); +memblock_reserve_kern (indirect->addr, indirect->len); } pa_data = pa_next;
@@ -770,8 +770,8 @@ static void __init early_reserve_memory(void)* __end_of_kernel_reserve symbol must be explicitly reserved with a * separate memblock_reserve() or they will be discarded. */ -memblock_reserve (__pa_symbol (_text), - (unsigned long )__end_of_kernel_reserve - (unsigned long )_text); +memblock_reserve_kern (__pa_symbol (_text), + (unsigned long )__end_of_kernel_reserve - (unsigned long )_text);/* * The first 4Kb of memory is a BIOS owned area, but generally it is
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 11/17 x86/kexec: add support for passing kexec handover (KHO) data
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
kexec handover (KHO) creates a metadata that the kernels pass between each other during kexec. This metadata is stored in memory and kexec image contains a (physical) pointer to that memory.
In addition, KHO keeps "scratch regions" available for kexec: physically contiguous memory regions that are guaranteed to not have any memory that KHO would preserve. The new kernel bootstraps itself using the scratch regions and sets all handed over memory as in use. When subsystems that support KHO initialize, they introspect the KHO metadata, restore preserved memory regions, and retrieve their state stored in the preserved memory.
Enlighten x86 kexec-file and boot path about the KHO metadata and make sure it gets passed along to the next kernel.
--- arch/x86/include/asm/setup.h | 2 ++ arch/x86/include/uapi/asm/setup_data.h | 13 ++++++++- arch/x86/kernel/kexec-bzimage64.c | 37 ++++++++++++++++++++++++++ arch/x86/kernel/setup.c | 26 ++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-)
arch/x86/include/asm/setup.h +2 -0
@@ -67,6 +67,8 @@ extern void x86_ce4100_early_setup(void);static inline void x86_ce4100_early_setup (void ) { }#endif +#include <linux/kexec_handover.h> +#ifndef _SETUP#include <asm/espfix.h>
arch/x86/include/uapi/asm/setup_data.h +12 -1
@@ -13,7 +13,8 @@#define SETUP_CC_BLOB 7#define SETUP_IMA 8#define SETUP_RNG_SEED 9 -#define SETUP_ENUM_MAX SETUP_RNG_SEED +#define SETUP_KEXEC_KHO 10 +#define SETUP_ENUM_MAX SETUP_KEXEC_KHO#define SETUP_INDIRECT (1<<31)#define SETUP_TYPE_MAX (SETUP_ENUM_MAX | SETUP_INDIRECT)
@@ -78,6 +79,16 @@ struct ima_setup_data {__u64 size; } __attribute__((packed)); +/* +* Locations of kexec handover metadata +*/ +struct kho_data { +__u64 fdt_addr; +__u64 fdt_size; +__u64 scratch_addr; +__u64 scratch_size; +} __attribute__((packed)); +#endif /* __ASSEMBLER__ */ #endif /* _UAPI_ASM_X86_SETUP_DATA_H */
arch/x86/kernel/kexec-bzimage64.c +37 -0
@@ -233,6 +233,32 @@ setup_ima_state(const struct kimage *image, struct boot_params *params,#endif /* CONFIG_IMA_KEXEC */ } +static void setup_kho (const struct kimage *image,struct boot_params *params, +unsigned long params_load_addr, +unsigned int setup_data_offset) +{ +struct setup_data *sd = (void *)params + setup_data_offset; +struct kho_data *kho = (void *)sd +sizeof (*sd); + +if (!IS_ENABLED (CONFIG_KEXEC_HANDOVER )) +return ; + + sd->type =SETUP_KEXEC_KHO ; + sd->len =sizeof (struct kho_data ); + +/* Only add if we have all KHO images in place */ +if (!image->kho.fdt || !image->kho.scratch) +return ; + +/* Add setup data */ + kho->fdt_addr = image->kho.fdt; + kho->fdt_size =PAGE_SIZE ; + kho->scratch_addr = image->kho.scratch->mem; + kho->scratch_size = image->kho.scratch->bufsz; + sd->next = params->hdr.setup_data; + params->hdr.setup_data = params_load_addr + setup_data_offset; +} + static int setup_boot_parameters(struct kimage *image, struct boot_params *params, unsigned long params_load_addr,
@@ -312,6 +338,13 @@ setup_boot_parameters(struct kimage *image, struct boot_params *params,sizeof (struct ima_setup_data ); } +if (IS_ENABLED (CONFIG_KEXEC_HANDOVER )) { +/* Setup space to store preservation metadata */ +setup_kho (image, params, params_load_addr, setup_data_offset); + setup_data_offset +=sizeof (struct setup_data ) + +sizeof (struct kho_data ); + } +/* Setup RNG seed */ setup_rng_seed (params, params_load_addr, setup_data_offset);
@@ -479,6 +512,10 @@ static void *bzImage64_load(struct kimage *image, char *kernel, kbuf.bufsz +=sizeof (struct setup_data ) +sizeof (struct ima_setup_data ); +if (IS_ENABLED (CONFIG_KEXEC_HANDOVER )) + kbuf.bufsz +=sizeof (struct setup_data ) + +sizeof (struct kho_data ); + params =kzalloc (kbuf.bufsz,GFP_KERNEL );if (!params)return ERR_PTR (-ENOMEM );
arch/x86/kernel/setup.c +26 -0
@@ -451,6 +451,29 @@ int __init ima_get_kexec_buffer(void **addr, size_t *size) }#endif +static void __init add_kho (u64 phys_addr,u32 data_len) +{ +struct kho_data *kho; +u64 addr = phys_addr +sizeof (struct setup_data ); +u64 size = data_len -sizeof (struct setup_data ); + +if (!IS_ENABLED (CONFIG_KEXEC_HANDOVER )) { +pr_warn ("Passed KHO data, but CONFIG_KEXEC_HANDOVER not set. Ignoring.\n" ); +return ; + } + + kho =early_memremap (addr, size); +if (!kho) { +pr_warn ("setup: failed to memremap kho data (0x%llx, 0x%llx)\n" , + addr, size); +return ; + } + +kho_populate (kho->fdt_addr, kho->fdt_size, kho->scratch_addr, kho->scratch_size); + +early_memunmap (kho, size); +} +static void __init parse_setup_data (void ) {struct setup_data *data;
@@ -479,6 +502,9 @@ static void __init parse_setup_data(void)case SETUP_IMA :add_early_ima_buffer (pa_data);break ; +case SETUP_KEXEC_KHO : +add_kho (pa_data, data_len); +break ;case SETUP_RNG_SEED : data =early_memremap (pa_data, data_len);add_bootloader_randomness (data->data, data->len);
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 12/17 x86/e820: temporarily enable KHO scratch for memory below 1M
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
KHO kernels are special and use only scratch memory for memblock allocations, but memory below 1M is ignored by kernel after early boot and cannot be naturally marked as scratch.
To allow allocation of the real-mode trampoline and a few (if any) other very early allocations from below 1M forcibly mark the memory below 1M as scratch.
After real mode trampoline is allocated, clear that scratch marking.
--- arch/x86/kernel/e820.c | 18 ++++++++++++++++++ arch/x86/realmode/init.c | 2 ++ 2 files changed, 20 insertions(+)
arch/x86/kernel/e820.c +18 -0
@@ -1299,6 +1299,24 @@ void __init e820__memblock_setup(void)memblock_add (entry->addr, entry->size); } +/* +* At this point memblock is only allowed to allocate from memory +* below 1M (aka ISA_END_ADDRESS) up until direct map is completely set +* up in init_mem_mapping(). +* +* KHO kernels are special and use only scratch memory for memblock +* allocations, but memory below 1M is ignored by kernel after early +* boot and cannot be naturally marked as scratch. +* +* To allow allocation of the real-mode trampoline and a few (if any) +* other very early allocations from below 1M forcibly mark the memory +* below 1M as scratch. +* +* After real mode trampoline is allocated, we clear that scratch +* marking. +*/ +memblock_mark_kho_scratch (0 ,SZ_1M ); +/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and * to even less without it.
arch/x86/realmode/init.c +2 -0
@@ -65,6 +65,8 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); + +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)
Signature · 1 line
2.49.0.1015.ga840276032-goog
Re: [PATCH v8 12/17] x86/e820: temporarily enable KHO scratch for memory below 1M
Quoted 57 lines · Changyuan Lyu
From: Alexander Graf <[email protected]>
KHO kernels are special and use only scratch memory for memblock allocations, but memory below 1M is ignored by kernel after early boot and cannot be naturally marked as scratch.
To allow allocation of the real-mode trampoline and a few (if any) other very early allocations from below 1M forcibly mark the memory below 1M as scratch.
After real mode trampoline is allocated, clear that scratch marking.
Signed-off-by Alexander Graf <[email protected]>Co-developed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by Mike Rapoport (Microsoft) <[email protected]>Co-developed-by Changyuan Lyu <[email protected]>Signed-off-by Changyuan Lyu <[email protected]>Acked-by Dave Hansen <[email protected]>--- arch/x86/kernel/e820.c | 18 ++++++++++++++++++ arch/x86/realmode/init.c | 2 ++ 2 files changed, 20 insertions(+)arch/x86/kernel/e820.c +18
-0@@ -1299,6 +1299,24 @@ void __init e820__memblock_setup(void)memblock_add (entry->addr, entry->size); } +/* +* At this point memblock is only allowed to allocate from memory +* below 1M (aka ISA_END_ADDRESS) up until direct map is completely set +* up in init_mem_mapping(). +* +* KHO kernels are special and use only scratch memory for memblock +* allocations, but memory below 1M is ignored by kernel after early +* boot and cannot be naturally marked as scratch. +* +* To allow allocation of the real-mode trampoline and a few (if any) +* other very early allocations from below 1M forcibly mark the memory +* below 1M as scratch. +* +* After real mode trampoline is allocated, we clear that scratch +* marking. +*/ +memblock_mark_kho_scratch (0 ,SZ_1M ); +/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and * to even less without it. arch/x86/realmode/init.c +0
-0
arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 72
Quoted 8 lines
arch/x86/realmode/init.c +2
-0@@ -65,6 +65,8 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); + +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)
Hello!
I am working with Breno who reported that we are seeing the below warning at boot when rolling out 6.16 in Meta fleet. It is difficult to reproduce on a single host manually but we are seeing this several times a day inside the fleet.
20:16:33 ------------[ cut here ]------------ 20:16:33 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range+0x316/0x330 20:16:33 Modules linked in: 20:16:33 CPU: 0 UID: 0 PID: 0 Comm: swapper Tainted: G S 6.16.1-0_fbk0_0_gc0739ee5037a #1 NONE 20:16:33 Tainted: [S]=CPU_OUT_OF_SPEC 20:16:33 RIP: 0010:memblock_add_range+0x316/0x330 20:16:33 Code: ff ff ff 89 5c 24 08 41 ff c5 44 89 6c 24 10 48 63 74 24 08 48 63 54 24 10 e8 26 0c 00 00 e9 41 ff ff ff 0f 0b e9 af fd ff ff <0f> 0b e9 b7 fd ff ff 0f 0b 0f 0b cc cc cc cc cc cc cc cc cc cc cc 20:16:33 RSP: 0000:ffffffff83403dd8 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 20:16:33 RAX: ffffffff8476ff90 RBX: 0000000000001c00 RCX: 0000000000000002 20:16:33 RDX: 00000000ffffffff RSI: 0000000000000000 RDI: ffffffff83bad4d8 20:16:33 RBP: 000000000009f000 R08: 0000000000000020 R09: 8000000000097101 20:16:33 R10: ffffffffff2004b0 R11: 203a6d6f646e6172 R12: 000000000009ec00 20:16:33 R13: 0000000000000002 R14: 0000000000100000 R15: 000000000009d000 20:16:33 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 20:16:33 CR2: ffff888065413ff8 CR3: 00000000663b7000 CR4: 00000000000000b0 20:16:33 Call Trace: 20:16:33 <TASK> 20:16:33 ? __memblock_reserve+0x75/0x80 20:16:33 ? setup_arch+0x30f/0xb10 20:16:33 ? start_kernel+0x58/0x960 20:16:33 ? x86_64_start_reservations+0x20/0x20 20:16:33 ? x86_64_start_kernel+0x13d/0x140 20:16:33 ? common_startup_64+0x13e/0x140 20:16:33 </TASK>
20:16:33 ---[ end trace 0000000000000000 ]---
Rolling out with memblock=debug is not really an option in a large scale fleet due to the time added to boot. But I did try on one of the hosts (without reproducing the issue) and I see:
[ 0.000616] memory.cnt = 0x6 [ 0.000617] memory[0x0] [0x0000000000001000-0x000000000009bfff], 0x000000000009b000 bytes flags: 0x40 [ 0.000620] memory[0x1] [0x000000000009f000-0x000000000009ffff], 0x0000000000001000 bytes flags: 0x40 [ 0.000621] memory[0x2] [0x0000000000100000-0x000000005ed09fff], 0x000000005ec0a000 bytes flags: 0x0
...
The 0x40 (MEMBLOCK_KHO_SCRATCH) is coming from memblock_mark_kho_scratch in e820__memblock_setup. I believe this should be under ifdef like the diff at the end? (Happy to send this as a patch for review if it makes sense). We have KEXEC_HANDOVER disabled in our defconfig, therefore MEMBLOCK_KHO_SCRATCH shouldnt be selected and we shouldnt have any MEMBLOCK_KHO_SCRATCH type regions in our memblock reservations.
The other thing I did was insert a while(1) just before the warning and inspected the registers in qemu. R14 held the base register, and R15 held the size at that point.
In the warning R14 is 0x100000 meaning that someone is reserving a region with a different flag to MEMBLOCK_NONE at the boundary of MEMBLOCK_KHO_SCRATCH.
arch/x86/kernel/e820.c +2 -1
@@ -1299,6 +1299,7 @@ void __init e820__memblock_setup(void)memblock_add (entry->addr, entry->size); } +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH /* * At this point memblock is only allowed to allocate from memory * below 1M (aka ISA_END_ADDRESS) up until direct map is completely set
@@ -1316,7 +1317,7 @@ void __init e820__memblock_setup(void)* marking. */ memblock_mark_kho_scratch (0 ,SZ_1M ); - +#endif /* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and * to even less without it.
arch/x86/realmode/init.c +2 -1
@@ -66,8 +66,9 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); - +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH memblock_clear_kho_scratch (0 ,SZ_1M ); +#endif }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)
H. Peter Anvin
reviewerRe: [PATCH v8 12/17] x86/e820: temporarily enable KHO scratch for memory below 1M
Quoted 147 lines · Usama Arif
Quoted 57 lines · Changyuan Lyu
From: Alexander Graf <[email protected]>
KHO kernels are special and use only scratch memory for memblock allocations, but memory below 1M is ignored by kernel after early boot and cannot be naturally marked as scratch.
To allow allocation of the real-mode trampoline and a few (if any) other very early allocations from below 1M forcibly mark the memory below 1M as scratch.
After real mode trampoline is allocated, clear that scratch marking.
Signed-off-by Alexander Graf <[email protected]>Co-developed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by Mike Rapoport (Microsoft) <[email protected]>Co-developed-by Changyuan Lyu <[email protected]>Signed-off-by Changyuan Lyu <[email protected]>Acked-by Dave Hansen <[email protected]>--- arch/x86/kernel/e820.c | 18 ++++++++++++++++++ arch/x86/realmode/init.c | 2 ++ 2 files changed, 20 insertions(+)arch/x86/kernel/e820.c +18
-0@@ -1299,6 +1299,24 @@ void __init e820__memblock_setup(void)memblock_add (entry->addr, entry->size); } +/* +* At this point memblock is only allowed to allocate from memory +* below 1M (aka ISA_END_ADDRESS) up until direct map is completely set +* up in init_mem_mapping(). +* +* KHO kernels are special and use only scratch memory for memblock +* allocations, but memory below 1M is ignored by kernel after early +* boot and cannot be naturally marked as scratch. +* +* To allow allocation of the real-mode trampoline and a few (if any) +* other very early allocations from below 1M forcibly mark the memory +* below 1M as scratch. +* +* After real mode trampoline is allocated, we clear that scratch +* marking. +*/ +memblock_mark_kho_scratch (0 ,SZ_1M ); +/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and * to even less without it. arch/x86/realmode/init.c +0
-0arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 72
Quoted 8 lines
arch/x86/realmode/init.c +2
-0@@ -65,6 +65,8 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); + +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)Hello!
I am working with Breno who reported that we are seeing the below warning at boot when rolling out 6.16 in Meta fleet. It is difficult to reproduce on a single host manually but we are seeing this several times a day inside the fleet.
20:16:33 ------------[ cut here ]------------ 20:16:33 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range+0x316/0x330 20:16:33 Modules linked in: 20:16:33 CPU: 0 UID: 0 PID: 0 Comm: swapper Tainted: G S 6.16.1-0_fbk0_0_gc0739ee5037a #1 NONE 20:16:33 Tainted: [S]=CPU_OUT_OF_SPEC 20:16:33 RIP: 0010:memblock_add_range+0x316/0x330 20:16:33 Code: ff ff ff 89 5c 24 08 41 ff c5 44 89 6c 24 10 48 63 74 24 08 48 63 54 24 10 e8 26 0c 00 00 e9 41 ff ff ff 0f 0b e9 af fd ff ff <0f> 0b e9 b7 fd ff ff 0f 0b 0f 0b cc cc cc cc cc cc cc cc cc cc cc 20:16:33 RSP: 0000:ffffffff83403dd8 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 20:16:33 RAX: ffffffff8476ff90 RBX: 0000000000001c00 RCX: 0000000000000002 20:16:33 RDX: 00000000ffffffff RSI: 0000000000000000 RDI: ffffffff83bad4d8 20:16:33 RBP: 000000000009f000 R08: 0000000000000020 R09: 8000000000097101 20:16:33 R10: ffffffffff2004b0 R11: 203a6d6f646e6172 R12: 000000000009ec00 20:16:33 R13: 0000000000000002 R14: 0000000000100000 R15: 000000000009d000 20:16:33 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 20:16:33 CR2: ffff888065413ff8 CR3: 00000000663b7000 CR4: 00000000000000b0 20:16:33 Call Trace: 20:16:33 <TASK> 20:16:33 ? __memblock_reserve+0x75/0x80 20:16:33 ? setup_arch+0x30f/0xb10 20:16:33 ? start_kernel+0x58/0x960 20:16:33 ? x86_64_start_reservations+0x20/0x20 20:16:33 ? x86_64_start_kernel+0x13d/0x140 20:16:33 ? common_startup_64+0x13e/0x140 20:16:33 </TASK>20:16:33 ---[ end trace 0000000000000000 ]---
Rolling out with memblock=debug is not really an option in a large scale fleet due to the time added to boot. But I did try on one of the hosts (without reproducing the issue) and I see:
[ 0.000616] memory.cnt = 0x6 [ 0.000617] memory[0x0] [0x0000000000001000-0x000000000009bfff], 0x000000000009b000 bytes flags: 0x40 [ 0.000620] memory[0x1] [0x000000000009f000-0x000000000009ffff], 0x0000000000001000 bytes flags: 0x40 [ 0.000621] memory[0x2] [0x0000000000100000-0x000000005ed09fff], 0x000000005ec0a000 bytes flags: 0x0...
The
0x40(MEMBLOCK_KHO_SCRATCH) is coming frommemblock_mark_kho_scratchine820__memblock_setup. I believe this should be under ifdef like the diff at the end? (Happy to send this as a patch for review if it makes sense). We haveKEXEC_HANDOVERdisabled in our defconfig, thereforeMEMBLOCK_KHO_SCRATCHshouldnt be selected and we shouldnt have anyMEMBLOCK_KHO_SCRATCHtype regions in our memblock reservations.The other thing I did was insert a while(1) just before the warning and inspected the registers in qemu. R14 held the base register, and R15 held the size at that point.
In the warning R14 is0x100000meaning that someone is reserving a region with a different flag toMEMBLOCK_NONEat the boundary ofMEMBLOCK_KHO_SCRATCH.arch/x86/kernel/e820.c +2
-1@@ -1299,6 +1299,7 @@ void __init e820__memblock_setup(void)memblock_add (entry->addr, entry->size); } +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH /* * At this point memblock is only allowed to allocate from memory * below 1M (aka ISA_END_ADDRESS) up until direct map is completely set @@ -1316,7 +1317,7 @@ void __init e820__memblock_setup(void)* marking. */ memblock_mark_kho_scratch (0 ,SZ_1M ); - +#endif /* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and * to even less without it. arch/x86/realmode/init.c +0
-0
arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 74
Quoted 10 lines
arch/x86/realmode/init.c +2
-1@@ -66,8 +66,9 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); - +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH memblock_clear_kho_scratch (0 ,SZ_1M ); +#endif }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)
What does "scratch" mean in this exact context? (Sorry, don't have the code in front of me.)
Pratyush Yadav
maintainerRe: [PATCH v8 12/17] x86/e820: temporarily enable KHO scratch for memory below 1M
Quoted 157 lines · H. Peter Anvin
Quoted 156 lines · Usama Arif
Quoted 57 lines · Changyuan Lyu
From: Alexander Graf <[email protected]>
KHO kernels are special and use only scratch memory for memblock allocations, but memory below 1M is ignored by kernel after early boot and cannot be naturally marked as scratch.
To allow allocation of the real-mode trampoline and a few (if any) other very early allocations from below 1M forcibly mark the memory below 1M as scratch.
After real mode trampoline is allocated, clear that scratch marking.
Signed-off-by Alexander Graf <[email protected]>Co-developed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by Mike Rapoport (Microsoft) <[email protected]>Co-developed-by Changyuan Lyu <[email protected]>Signed-off-by Changyuan Lyu <[email protected]>Acked-by Dave Hansen <[email protected]>--- arch/x86/kernel/e820.c | 18 ++++++++++++++++++ arch/x86/realmode/init.c | 2 ++ 2 files changed, 20 insertions(+)arch/x86/kernel/e820.c +18
-0@@ -1299,6 +1299,24 @@ void __init e820__memblock_setup(void)memblock_add (entry->addr, entry->size); } +/* +* At this point memblock is only allowed to allocate from memory +* below 1M (aka ISA_END_ADDRESS) up until direct map is completely set +* up in init_mem_mapping(). +* +* KHO kernels are special and use only scratch memory for memblock +* allocations, but memory below 1M is ignored by kernel after early +* boot and cannot be naturally marked as scratch. +* +* To allow allocation of the real-mode trampoline and a few (if any) +* other very early allocations from below 1M forcibly mark the memory +* below 1M as scratch. +* +* After real mode trampoline is allocated, we clear that scratch +* marking. +*/ +memblock_mark_kho_scratch (0 ,SZ_1M ); +/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and * to even less without it. arch/x86/realmode/init.c +0
-0arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 72
Quoted 8 lines
arch/x86/realmode/init.c +2
-0@@ -65,6 +65,8 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); + +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)Hello!
I am working with Breno who reported that we are seeing the below warning at boot when rolling out 6.16 in Meta fleet. It is difficult to reproduce on a single host manually but we are seeing this several times a day inside the fleet.
20:16:33 ------------[ cut here ]------------ 20:16:33 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range+0x316/0x330 20:16:33 Modules linked in: 20:16:33 CPU: 0 UID: 0 PID: 0 Comm: swapper Tainted: G S 6.16.1-0_fbk0_0_gc0739ee5037a #1 NONE 20:16:33 Tainted: [S]=CPU_OUT_OF_SPEC 20:16:33 RIP: 0010:memblock_add_range+0x316/0x330 20:16:33 Code: ff ff ff 89 5c 24 08 41 ff c5 44 89 6c 24 10 48 63 74 24 08 48 63 54 24 10 e8 26 0c 00 00 e9 41 ff ff ff 0f 0b e9 af fd ff ff <0f> 0b e9 b7 fd ff ff 0f 0b 0f 0b cc cc cc cc cc cc cc cc cc cc cc 20:16:33 RSP: 0000:ffffffff83403dd8 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 20:16:33 RAX: ffffffff8476ff90 RBX: 0000000000001c00 RCX: 0000000000000002 20:16:33 RDX: 00000000ffffffff RSI: 0000000000000000 RDI: ffffffff83bad4d8 20:16:33 RBP: 000000000009f000 R08: 0000000000000020 R09: 8000000000097101 20:16:33 R10: ffffffffff2004b0 R11: 203a6d6f646e6172 R12: 000000000009ec00 20:16:33 R13: 0000000000000002 R14: 0000000000100000 R15: 000000000009d000 20:16:33 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 20:16:33 CR2: ffff888065413ff8 CR3: 00000000663b7000 CR4: 00000000000000b0 20:16:33 Call Trace: 20:16:33 <TASK> 20:16:33 ? __memblock_reserve+0x75/0x80 20:16:33 ? setup_arch+0x30f/0xb10 20:16:33 ? start_kernel+0x58/0x960 20:16:33 ? x86_64_start_reservations+0x20/0x20 20:16:33 ? x86_64_start_kernel+0x13d/0x140 20:16:33 ? common_startup_64+0x13e/0x140 20:16:33 </TASK>20:16:33 ---[ end trace 0000000000000000 ]---
Rolling out with memblock=debug is not really an option in a large scale fleet due to the time added to boot. But I did try on one of the hosts (without reproducing the issue) and I see:
[ 0.000616] memory.cnt = 0x6 [ 0.000617] memory[0x0] [0x0000000000001000-0x000000000009bfff], 0x000000000009b000 bytes flags: 0x40 [ 0.000620] memory[0x1] [0x000000000009f000-0x000000000009ffff], 0x0000000000001000 bytes flags: 0x40 [ 0.000621] memory[0x2] [0x0000000000100000-0x000000005ed09fff], 0x000000005ec0a000 bytes flags: 0x0...
The
0x40(MEMBLOCK_KHO_SCRATCH) is coming frommemblock_mark_kho_scratchine820__memblock_setup. I believe this should be under ifdef like the diff at the end? (Happy to send this as a patch for review if it makes sense). We haveKEXEC_HANDOVERdisabled in our defconfig, thereforeMEMBLOCK_KHO_SCRATCHshouldnt be selected and we shouldnt have anyMEMBLOCK_KHO_SCRATCHtype regions in our memblock reservations.The other thing I did was insert a while(1) just before the warning and inspected the registers in qemu. R14 held the base register, and R15 held the size at that point.
In the warning R14 is0x100000meaning that someone is reserving a region with a different flag toMEMBLOCK_NONEat the boundary ofMEMBLOCK_KHO_SCRATCH.arch/x86/kernel/e820.c +2
-1@@ -1299,6 +1299,7 @@ void __init e820__memblock_setup(void)memblock_add (entry->addr, entry->size); } +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH /* * At this point memblock is only allowed to allocate from memory * below 1M (aka ISA_END_ADDRESS) up until direct map is completely set @@ -1316,7 +1317,7 @@ void __init e820__memblock_setup(void)* marking. */ memblock_mark_kho_scratch (0 ,SZ_1M ); - +#endif /* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and * to even less without it. arch/x86/realmode/init.c +2
-1@@ -66,8 +66,9 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); - +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH memblock_clear_kho_scratch (0 ,SZ_1M ); +#endif }
Quoted 3 lines
arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 74
Quoted 1 line
arch/x86/realmode/init.c +0
-0static void __init sme_sev_setup_real_mode (struct trampoline_header *th)What does "scratch" mean in this exact context? (Sorry, don't have the code in front of me.)
See https://docs.kernel.org/core-api/kho/concepts.html#scratch-regions
Signature · 2 lines
Regards, Pratyush Yadav
Mike Rapoport
maintainerRe: [PATCH v8 12/17] x86/e820: temporarily enable KHO scratch for memory below 1M
In reply to H. Peter AnvinQuoted 16 lines · H. Peter Anvin
Quoted 14 lines · Usama Arif
arch/x86/realmode/init.c +2
-1@@ -66,8 +66,9 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); - +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH memblock_clear_kho_scratch (0 ,SZ_1M ); +#endif }
Quoted 3 lines
arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 74
Quoted 1 line
arch/x86/realmode/init.c +0
-0static void __init sme_sev_setup_real_mode (struct trampoline_header *th)What does "scratch" mean in this exact context? (Sorry, don't have the code in front of me.)
In this context it's the memory kexec handover used to bootstrap the kexec'ed kernel. Everything beyond these scratch areas could contain preserved data and kexec handover limits all early memory allocations to these scratch areas.
Signature · 2 lines
Sincerely yours, Mike.
Pratyush Yadav
maintainerRe: [PATCH v8 12/17] x86/e820: temporarily enable KHO scratch for memory below 1M
In reply to Usama ArifQuoted 114 lines · Usama Arif
Quoted 57 lines · Changyuan Lyu
From: Alexander Graf <[email protected]>
KHO kernels are special and use only scratch memory for memblock allocations, but memory below 1M is ignored by kernel after early boot and cannot be naturally marked as scratch.
To allow allocation of the real-mode trampoline and a few (if any) other very early allocations from below 1M forcibly mark the memory below 1M as scratch.
After real mode trampoline is allocated, clear that scratch marking.
Signed-off-by Alexander Graf <[email protected]>Co-developed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by Mike Rapoport (Microsoft) <[email protected]>Co-developed-by Changyuan Lyu <[email protected]>Signed-off-by Changyuan Lyu <[email protected]>Acked-by Dave Hansen <[email protected]>--- arch/x86/kernel/e820.c | 18 ++++++++++++++++++ arch/x86/realmode/init.c | 2 ++ 2 files changed, 20 insertions(+)arch/x86/kernel/e820.c +18
-0@@ -1299,6 +1299,24 @@ void __init e820__memblock_setup(void)memblock_add (entry->addr, entry->size); } +/* +* At this point memblock is only allowed to allocate from memory +* below 1M (aka ISA_END_ADDRESS) up until direct map is completely set +* up in init_mem_mapping(). +* +* KHO kernels are special and use only scratch memory for memblock +* allocations, but memory below 1M is ignored by kernel after early +* boot and cannot be naturally marked as scratch. +* +* To allow allocation of the real-mode trampoline and a few (if any) +* other very early allocations from below 1M forcibly mark the memory +* below 1M as scratch. +* +* After real mode trampoline is allocated, we clear that scratch +* marking. +*/ +memblock_mark_kho_scratch (0 ,SZ_1M ); +/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and * to even less without it. arch/x86/realmode/init.c +0
-0arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 72
Quoted 8 lines
arch/x86/realmode/init.c +2
-0@@ -65,6 +65,8 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); + +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)Hello!
I am working with Breno who reported that we are seeing the below warning at boot when rolling out 6.16 in Meta fleet. It is difficult to reproduce on a single host manually but we are seeing this several times a day inside the fleet.
20:16:33 ------------[ cut here ]------------ 20:16:33 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range+0x316/0x330 20:16:33 Modules linked in: 20:16:33 CPU: 0 UID: 0 PID: 0 Comm: swapper Tainted: G S 6.16.1-0_fbk0_0_gc0739ee5037a #1 NONE 20:16:33 Tainted: [S]=CPU_OUT_OF_SPEC 20:16:33 RIP: 0010:memblock_add_range+0x316/0x330 20:16:33 Code: ff ff ff 89 5c 24 08 41 ff c5 44 89 6c 24 10 48 63 74 24 08 48 63 54 24 10 e8 26 0c 00 00 e9 41 ff ff ff 0f 0b e9 af fd ff ff <0f> 0b e9 b7 fd ff ff 0f 0b 0f 0b cc cc cc cc cc cc cc cc cc cc cc 20:16:33 RSP: 0000:ffffffff83403dd8 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 20:16:33 RAX: ffffffff8476ff90 RBX: 0000000000001c00 RCX: 0000000000000002 20:16:33 RDX: 00000000ffffffff RSI: 0000000000000000 RDI: ffffffff83bad4d8 20:16:33 RBP: 000000000009f000 R08: 0000000000000020 R09: 8000000000097101 20:16:33 R10: ffffffffff2004b0 R11: 203a6d6f646e6172 R12: 000000000009ec00 20:16:33 R13: 0000000000000002 R14: 0000000000100000 R15: 000000000009d000 20:16:33 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 20:16:33 CR2: ffff888065413ff8 CR3: 00000000663b7000 CR4: 00000000000000b0 20:16:33 Call Trace: 20:16:33 <TASK> 20:16:33 ? __memblock_reserve+0x75/0x80 20:16:33 ? setup_arch+0x30f/0xb10 20:16:33 ? start_kernel+0x58/0x960 20:16:33 ? x86_64_start_reservations+0x20/0x20 20:16:33 ? x86_64_start_kernel+0x13d/0x140 20:16:33 ? common_startup_64+0x13e/0x140 20:16:33 </TASK>20:16:33 ---[ end trace 0000000000000000 ]---
Rolling out with memblock=debug is not really an option in a large scale fleet due to the time added to boot. But I did try on one of the hosts (without reproducing the issue) and I see:
[ 0.000616] memory.cnt = 0x6 [ 0.000617] memory[0x0] [0x0000000000001000-0x000000000009bfff], 0x000000000009b000 bytes flags: 0x40 [ 0.000620] memory[0x1] [0x000000000009f000-0x000000000009ffff], 0x0000000000001000 bytes flags: 0x40 [ 0.000621] memory[0x2] [0x0000000000100000-0x000000005ed09fff], 0x000000005ec0a000 bytes flags: 0x0...
The
0x40(MEMBLOCK_KHO_SCRATCH) is coming frommemblock_mark_kho_scratchine820__memblock_setup. I believe this should be under ifdef like the diff at the end? (Happy to send this as a patch for review if it makes sense). We haveKEXEC_HANDOVERdisabled in our defconfig, thereforeMEMBLOCK_KHO_SCRATCHshouldnt be selected and we shouldnt have anyMEMBLOCK_KHO_SCRATCHtype regions in our memblock reservations.
Quoted 4 lines
The other thing I did was insert a while(1) just before the warning and inspected the registers in qemu. R14 held the base register, and R15 held the size at that point.
In the warning R14 is0x100000meaning that someone is reserving a region with a different flag toMEMBLOCK_NONEat the boundary ofMEMBLOCK_KHO_SCRATCH.
I don't get this... The WARN_ON() is only triggered when the regions overlap. Here, there should be no overlap, since the scratch region should end at 0x100000 (SZ_1M) and the new region starts at 0x100000 (SZ_1M).
Anyway, you do indeed point at a bug. memblock_mark_kho_scratch() should only be called on a KHO boot, not unconditionally. So even with CONFIG_MEMBLOCK_KHO_SCRATCH enabled, this should only be called on a KHO boot, not every time.
I think the below diff should fix the warning for you by making sure the scratch areas are not present on non-KHO boot. I still don't know why you hit the warning in the first place though. If you'd be willing to dig deeper into that, it would be great.
Can you give the below a try and if it fixes the problem for you I can send it on the list.
arch/x86/kernel/e820.c +3 -1
@@ -16,6 +16,7 @@#include <linux/firmware-map.h> #include <linux/sort.h> #include <linux/memory_hotplug.h> +#include <linux/kexec_handover.h> #include <asm/e820/api.h> #include <asm/setup.h>
@@ -1315,7 +1316,8 @@ void __init e820__memblock_setup(void)* After real mode trampoline is allocated, we clear that scratch * marking. */ -memblock_mark_kho_scratch (0 ,SZ_1M ); +if (is_kho_boot ()) +memblock_mark_kho_scratch (0 ,SZ_1M );/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and
arch/x86/realmode/init.c +3 -1
@@ -4,6 +4,7 @@#include <linux/memblock.h> #include <linux/cc_platform.h> #include <linux/pgtable.h> +#include <linux/kexec_handover.h> #include <asm/set_memory.h> #include <asm/realmode.h>
@@ -67,7 +68,8 @@ void __init reserve_real_mode(void)*/ memblock_reserve (0 ,SZ_1M ); -memblock_clear_kho_scratch (0 ,SZ_1M ); +if (is_kho_boot ()) +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)
Signature · 2 lines
Regards, Pratyush Yadav
Mike Rapoport
maintainerRe: [PATCH v8 12/17] x86/e820: temporarily enable KHO scratch for memory below 1M
Hi,
Quoted 30 lines · Pratyush Yadav
Quoted 28 lines · Usama Arif
arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 72
Quoted 11 lines
arch/x86/realmode/init.c +2
-0@@ -65,6 +65,8 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); + +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)Hello!
I am working with Breno who reported that we are seeing the below warning at boot when rolling out 6.16 in Meta fleet. It is difficult to reproduce on a single host manually but we are seeing this several times a day inside the fleet.
20:16:33 ------------[ cut here ]------------ 20:16:33 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range+0x316/0x330 20:16:33 Modules linked in: 20:16:33 CPU: 0 UID: 0 PID: 0 Comm: swapper Tainted: G S 6.16.1-0_fbk0_0_gc0739ee5037a #1 NONE 20:16:33 Tainted: [S]=CPU_OUT_OF_SPEC 20:16:33 RIP: 0010:memblock_add_range+0x316/0x330 20:16:33 Code: ff ff ff 89 5c 24 08 41 ff c5 44 89 6c 24 10 48 63 74 24 08 48 63 54 24 10 e8 26 0c 00 00 e9 41 ff ff ff 0f 0b e9 af fd ff ff <0f> 0b e9 b7 fd ff ff 0f 0b 0f 0b cc cc cc cc cc cc cc cc cc cc cc 20:16:33 RSP: 0000:ffffffff83403dd8 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 20:16:33 RAX: ffffffff8476ff90 RBX: 0000000000001c00 RCX: 0000000000000002 20:16:33 RDX: 00000000ffffffff RSI: 0000000000000000 RDI: ffffffff83bad4d8
Quoted 8 lines
Quoted 8 lines
20:16:33 RBP: 000000000009f000 R08: 0000000000000020 R09: 8000000000097101 20:16:33 R10: ffffffffff2004b0 R11: 203a6d6f646e6172 R12: 000000000009ec00 20:16:33 R13: 0000000000000002 R14: 0000000000100000 R15: 000000000009d000 20:16:33 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 20:16:33 CR2: ffff888065413ff8 CR3: 00000000663b7000 CR4: 00000000000000b0 20:16:33 Call Trace:20:16:33 <TASK>
20:16:33 ?__memblock_reserve+0x75/0x80
Do you have faddr2line for this?
Quoted 1 line
Quoted 1 line
20:16:33 ?
setup_arch+0x30f/0xb10
And this?
Quoted 10 lines
Quoted 10 lines
20:16:33 ? start_kernel+0x58/0x960 20:16:33 ? x86_64_start_reservations+0x20/0x20 20:16:33 ? x86_64_start_kernel+0x13d/0x140 20:16:33 ? common_startup_64+0x13e/0x140 20:16:33 </TASK>20:16:33 ---[ end trace 0000000000000000 ]---
Rolling out with memblock=debug is not really an option in a large scale fleet due to the time added to boot. But I did try on one of the hosts (without reproducing the issue) and I see:
Is it a problem to roll out a kernel that has additional debug printouts as Breno suggested earlier? I.e.
if (flags != MEMBLOCK_NONE && flags != rgn->flags) {
pr_warn("memblock: Flag mismatch at region [%pa-%pa]\n",
&rgn->base, &rend);
pr_warn(" Existing region flags: %#x\n", rgn->flags);
pr_warn(" New range flags: %#x\n", flags);
pr_warn(" New range: [%pa-%pa]\n", &base, &end);
WARN_ON_ONCE(1);
}Quoted 11 lines
Quoted 11 lines
[ 0.000616] memory.cnt = 0x6 [ 0.000617] memory[0x0] [0x0000000000001000-0x000000000009bfff], 0x000000000009b000 bytes flags: 0x40 [ 0.000620] memory[0x1] [0x000000000009f000-0x000000000009ffff], 0x0000000000001000 bytes flags: 0x40 [ 0.000621] memory[0x2] [0x0000000000100000-0x000000005ed09fff], 0x000000005ec0a000 bytes flags: 0x0...
The
0x40(MEMBLOCK_KHO_SCRATCH) is coming frommemblock_mark_kho_scratchine820__memblock_setup. I believe this should be under ifdef like the diff at the end? (Happy to send this as a patch for review if it makes sense). We haveKEXEC_HANDOVERdisabled in our defconfig, thereforeMEMBLOCK_KHO_SCRATCHshouldnt be selected and we shouldnt have anyMEMBLOCK_KHO_SCRATCHtype regions in our memblock reservations.
Quoted 4 lines
Quoted 4 lines
The other thing I did was insert a while(1) just before the warning and inspected the registers in qemu. R14 held the base register, and R15 held the size at that point.
In the warning R14 is0x100000meaning that someone is reserving a region with a different flag toMEMBLOCK_NONEat the boundary ofMEMBLOCK_KHO_SCRATCH.
Judging by the register values, flags could be in %rcx or %r13 (0x2 - MEMBLOCK_MIRROR) or in %r8 (0x20 - MEMBLOCK_RSRV_KERN)
Since WARN_ON() is triggered in __memblock_reserve() I'd bet on MEMBLOCK_RSRV_KERN.
And apparently the warning triggers for some memory that was initially reserved with memblock_reserve() and than some of it was reserved with memblock_reserve_kern().
If you have the logs from failing boots up to the point where SLUB reports about it's initialization, e.g.
[ 0.134377] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
something there may hint about what's the issue.
Quoted 4 lines
I don't get this... The
WARN_ON()is only triggered when the regions overlap. Here, there should be no overlap, since the scratch region should end at0x100000(SZ_1M) and the new region starts at0x100000(SZ_1M).
Not only that, the warning is from __memblock_reserve() that works with memblock.reserved and the dump is for memblock.memory.
Quoted 26 lines
Anyway, you do indeed point at a bug.
memblock_mark_kho_scratch()should only be called on a KHO boot, not unconditionally. So even withCONFIG_MEMBLOCK_KHO_SCRATCHenabled, this should only be called on a KHO boot, not every time.I think the below diff should fix the warning for you by making sure the scratch areas are not present on non-KHO boot. I still don't know why you hit the warning in the first place though. If you'd be willing to dig deeper into that, it would be great.
Can you give the below a try and if it fixes the problem for you I can send it on the list.
arch/x86/kernel/e820.c +1
-0@@ -16,6 +16,7 @@#include <linux/firmware-map.h> #include <linux/sort.h> #include <linux/memory_hotplug.h> +#include <linux/kexec_handover.h> #include <asm/e820/api.h> #include <asm/setup.h>
arch/x86/kernel/e820.c void __init e820__memblock_setup(void) · line 1320
Quoted 6 lines
arch/x86/kernel/e820.c +2
-1@@ -1315,7 +1316,8 @@ void __init e820__memblock_setup(void)* After real mode trampoline is allocated, we clear that scratch * marking. */ -memblock_mark_kho_scratch (0 ,SZ_1M ); +if (is_kho_boot ()) +memblock_mark_kho_scratch (0 ,SZ_1M );
We'd better add an inline stub to memblock.h for
!CONFIG_MEMBLOCK_KHO_SCRATCH
and move is_kho_boot() inside memblock_{mark,clear}_kho_scratch. This might require moving them out of line, but it's not that they are on the hot paths.
BTW, this makes sense even if it does not help with the issue Breno and Usama are working on.
Quoted 30 lines
arch/x86/kernel/e820.c +0
-0/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and arch/x86/realmode/init.c +3
-1@@ -4,6 +4,7 @@#include <linux/memblock.h> #include <linux/cc_platform.h> #include <linux/pgtable.h> +#include <linux/kexec_handover.h> #include <asm/set_memory.h> #include <asm/realmode.h> @@ -67,7 +68,8 @@ void __init reserve_real_mode(void)*/ memblock_reserve (0 ,SZ_1M ); -memblock_clear_kho_scratch (0 ,SZ_1M ); +if (is_kho_boot ()) +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)Signature · 3 lines
-- Regards, Pratyush Yadav
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH v8 12/17] x86/e820: temporarily enable KHO scratch for memory below 1M
Quoted 42 lines · Mike Rapoport
Hi,
Quoted 30 lines · Pratyush Yadav
Quoted 28 lines · Usama Arif
arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 72
Quoted 11 lines
arch/x86/realmode/init.c +2
-0@@ -65,6 +65,8 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); + +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)Hello!
I am working with Breno who reported that we are seeing the below warning at boot when rolling out 6.16 in Meta fleet. It is difficult to reproduce on a single host manually but we are seeing this several times a day inside the fleet.
20:16:33 ------------[ cut here ]------------ 20:16:33 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range+0x316/0x330 20:16:33 Modules linked in: 20:16:33 CPU: 0 UID: 0 PID: 0 Comm: swapper Tainted: G S 6.16.1-0_fbk0_0_gc0739ee5037a #1 NONE 20:16:33 Tainted: [S]=CPU_OUT_OF_SPEC 20:16:33 RIP: 0010:memblock_add_range+0x316/0x330 20:16:33 Code: ff ff ff 89 5c 24 08 41 ff c5 44 89 6c 24 10 48 63 74 24 08 48 63 54 24 10 e8 26 0c 00 00 e9 41 ff ff ff 0f 0b e9 af fd ff ff <0f> 0b e9 b7 fd ff ff 0f 0b 0f 0b cc cc cc cc cc cc cc cc cc cc cc 20:16:33 RSP: 0000:ffffffff83403dd8 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 20:16:33 RAX: ffffffff8476ff90 RBX: 0000000000001c00 RCX: 0000000000000002 20:16:33 RDX: 00000000ffffffff RSI: 0000000000000000 RDI: ffffffff83bad4d8Quoted 8 lines
Quoted 8 lines
20:16:33 RBP: 000000000009f000 R08: 0000000000000020 R09: 8000000000097101 20:16:33 R10: ffffffffff2004b0 R11: 203a6d6f646e6172 R12: 000000000009ec00 20:16:33 R13: 0000000000000002 R14: 0000000000100000 R15: 000000000009d000 20:16:33 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 20:16:33 CR2: ffff888065413ff8 CR3: 00000000663b7000 CR4: 00000000000000b0 20:16:33 Call Trace:20:16:33 <TASK>
20:16:33 ?__memblock_reserve+0x75/0x80
Quoted 5 lines
Do you have faddr2line for this?
Quoted 1 line
Quoted 1 line
Quoted 1 line
20:16:33 ?
setup_arch+0x30f/0xb10And this?
Thanks for this! I think it helped narrow down the problem.
The stack is:
20:16:33 ? __memblock_reserve (mm/memblock.c:936)
20:16:33 ? setup_arch (arch/x86/kernel/setup.c:413 arch/x86/kernel/setup.c:499 arch/x86/kernel/setup.c:956) 20:16:33 ? start_kernel (init/main.c:922)
20:16:33 ? x86_64_start_reservations (arch/x86/kernel/ebda.c:57)
20:16:33 ? x86_64_start_kernel (arch/x86/kernel/head64.c:231)
20:16:33 ? common_startup_64 (arch/x86/kernel/head_64.S:419)
This is 6.16 kernel.
20:16:33 ? __memblock_reserve (mm/memblock.c:936)
Thats memblock_add_range call in memblock_reserve
20:16:33 ? setup_arch (arch/x86/kernel/setup.c:413 arch/x86/kernel/setup.c:499 arch/x86/kernel/setup.c:956) That is parse_setup_data -> add_early_ima_buffer -> add_early_ima_buffer -> memblock_reserve_kern
I put a simple print like below:
arch/x86/kernel/setup.c +1 -0
@@ -409,6 +409,7 @@ static void __init add_early_ima_buffer(u64 phys_addr) }if (data->size) { +pr_err ("PPP %s %s %d data->addr %llx, data->size %llx \n" , __FILE__, __func__, __LINE__, data->addr, data->size);memblock_reserve_kern (data->addr, data->size); ima_kexec_buffer_phys = data->addr; ima_kexec_buffer_size = data->size;
and I see (without replicating the warning):
[ 0.000000] PPP arch/x86/kernel/setup.c add_early_ima_buffer 412 data->addr 9e000, data->size 1000
....
[ 0.000348] MEMBLOCK configuration: [ 0.000348] memory size = 0x0000003fea329ff0 reserved size = 0x00000000050c969b [ 0.000350] memory.cnt = 0x5 [ 0.000351] memory[0x0] [0x0000000000001000-0x000000000009ffff], 0x000000000009f000 bytes flags: 0x40 [ 0.000353] memory[0x1] [0x0000000000100000-0x0000000067c65fff], 0x0000000067b66000 bytes flags: 0x0 [ 0.000355] memory[0x2] [0x000000006d8db000-0x000000006fffffff], 0x0000000002725000 bytes flags: 0x0 [ 0.000356] memory[0x3] [0x0000000100000000-0x000000407fff8fff], 0x0000003f7fff9000 bytes flags: 0x0 [ 0.000358] memory[0x4] [0x000000407fffa000-0x000000407fffffff], 0x0000000000006000 bytes flags: 0x0 [ 0.000359] reserved.cnt = 0x7
So MEMBLOCK_RSRV_KERN and MEMBLOCK_KHO_SCRATCH seem to overlap..
Quoted 14 lines
Quoted 10 lines
Quoted 10 lines
20:16:33 ? start_kernel+0x58/0x960 20:16:33 ? x86_64_start_reservations+0x20/0x20 20:16:33 ? x86_64_start_kernel+0x13d/0x140 20:16:33 ? common_startup_64+0x13e/0x140 20:16:33 </TASK>20:16:33 ---[ end trace 0000000000000000 ]---
Rolling out with memblock=debug is not really an option in a large scale fleet due to the time added to boot. But I did try on one of the hosts (without reproducing the issue) and I see:
Is it a problem to roll out a kernel that has additional debug printouts as Breno suggested earlier? I.e.
Quoted 9 lines
if (flags != MEMBLOCK_NONE && flags != rgn->flags) {
pr_warn("memblock: Flag mismatch at region [%pa-%pa]\n",
&rgn->base, &rend);
pr_warn(" Existing region flags: %#x\n", rgn->flags);
pr_warn(" New range flags: %#x\n", flags);
pr_warn(" New range: [%pa-%pa]\n", &base, &end);
WARN_ON_ONCE(1);
}I can add this, but the only thing is that it might be several weeks between me putting this in the kernel and that kernel being deployed to enough machines that it starts to show up. I think the IMA coinciding with memblock_mark_kho_scratch in e820__memblock_setup could be the reason for the warning. It might be better to fix that case and deploy it to see if the warnings still show up?
I can add these prints as well incase it doesnt fix the problem.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
[ 0.000616] memory.cnt = 0x6 [ 0.000617] memory[0x0] [0x0000000000001000-0x000000000009bfff], 0x000000000009b000 bytes flags: 0x40 [ 0.000620] memory[0x1] [0x000000000009f000-0x000000000009ffff], 0x0000000000001000 bytes flags: 0x40 [ 0.000621] memory[0x2] [0x0000000000100000-0x000000005ed09fff], 0x000000005ec0a000 bytes flags: 0x0...
The
0x40(MEMBLOCK_KHO_SCRATCH) is coming frommemblock_mark_kho_scratchine820__memblock_setup. I believe this should be under ifdef like the diff at the end? (Happy to send this as a patch for review if it makes sense). We haveKEXEC_HANDOVERdisabled in our defconfig, thereforeMEMBLOCK_KHO_SCRATCHshouldnt be selected and we shouldnt have anyMEMBLOCK_KHO_SCRATCHtype regions in our memblock reservations.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
The other thing I did was insert a while(1) just before the warning and inspected the registers in qemu. R14 held the base register, and R15 held the size at that point.
In the warning R14 is0x100000meaning that someone is reserving a region with a different flag toMEMBLOCK_NONEat the boundary ofMEMBLOCK_KHO_SCRATCH.Judging by the register values, flags could be in %rcx or %r13 (
0x2-MEMBLOCK_MIRROR) or in %r8 (0x20-MEMBLOCK_RSRV_KERN)
I feel like it might be r8 (MEMBLOCK_RSRV_KERN) from IMA.
Quoted 8 lines
Since
WARN_ON()is triggered in__memblock_reserve()I'd bet onMEMBLOCK_RSRV_KERN.And apparently the warning triggers for some memory that was initially reserved with
memblock_reserve()and than some of it was reserved withmemblock_reserve_kern().
Quoted 6 lines
If you have the logs from failing boots up to the point where SLUB reports about it's initialization, e.g.
[ 0.134377] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1something there may hint about what's the issue.
So the boot doesnt fail, its just giving warnings in the fleet. I have added the dmesg to the end of the mail.
Quoted 45 lines
Quoted 5 lines
I don't get this... The
WARN_ON()is only triggered when the regions overlap. Here, there should be no overlap, since the scratch region should end at0x100000(SZ_1M) and the new region starts at0x100000(SZ_1M).Not only that, the warning is from
__memblock_reserve()that works with memblock.reserved and the dump is for memblock.memory.Quoted 26 lines
Anyway, you do indeed point at a bug.
memblock_mark_kho_scratch()should only be called on a KHO boot, not unconditionally. So even withCONFIG_MEMBLOCK_KHO_SCRATCHenabled, this should only be called on a KHO boot, not every time.I think the below diff should fix the warning for you by making sure the scratch areas are not present on non-KHO boot. I still don't know why you hit the warning in the first place though. If you'd be willing to dig deeper into that, it would be great.
Can you give the below a try and if it fixes the problem for you I can send it on the list.
arch/x86/kernel/e820.c +1
-0@@ -16,6 +16,7 @@#include <linux/firmware-map.h> #include <linux/sort.h> #include <linux/memory_hotplug.h> +#include <linux/kexec_handover.h> #include <asm/e820/api.h> #include <asm/setup.h> arch/x86/kernel/e820.c void __init e820__memblock_setup(void) · line 1320
Quoted 6 lines
arch/x86/kernel/e820.c +2
-1@@ -1315,7 +1316,8 @@ void __init e820__memblock_setup(void)* After real mode trampoline is allocated, we clear that scratch * marking. */ -memblock_mark_kho_scratch (0 ,SZ_1M ); +if (is_kho_boot ()) +memblock_mark_kho_scratch (0 ,SZ_1M );We'd better add an inline stub to
memblock.hfor
!CONFIG_MEMBLOCK_KHO_SCRATCH
Quoted 7 lines
and move
is_kho_boot()inside memblock_{mark,clear}_kho_scratch. This might require moving them out of line, but it's not that they are on the hot paths.BTW, this makes sense even if it does not help with the issue Breno and Usama are working on.
Does something like this look good? I can try deploying this (although it will take sometime to find out). We can get it upstream as well as that makes backports easier.
mm/memblock.c +14 -4
@@ -1119,8 +1119,13 @@ int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t*/ __init int memblock_mark_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,1 , -MEMBLOCK_KHO_SCRATCH ); +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH +if (is_kho_boot ()) +return memblock_setclr_flag (&memblock.memory, base, size,1 , +MEMBLOCK_KHO_SCRATCH ); +#else +return 0 ; +#endif }/**
@@ -1133,8 +1138,13 @@ __init int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size)*/ __init int memblock_clear_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,0 , -MEMBLOCK_KHO_SCRATCH ); +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH +if (is_kho_boot ()) +return memblock_setclr_flag (&memblock.memory, base, size,0 , +MEMBLOCK_KHO_SCRATCH ); +#else +return 0 ; +#endif } static bool should_skip_region(struct memblock_type *type,
Quoted 19 lines
Quoted 19 lines
arch/x86/kernel/e820.c +0
-0/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and arch/x86/realmode/init.c +1
-0@@ -4,6 +4,7 @@#include <linux/memblock.h> #include <linux/cc_platform.h> #include <linux/pgtable.h> +#include <linux/kexec_handover.h> #include <asm/set_memory.h> #include <asm/realmode.h> @@ -67,7 +68,8 @@ void __init reserve_real_mode(void)*/ memblock_reserve (0 ,SZ_1M );
Quoted 6 lines
arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 75
Quoted 6 lines
arch/x86/realmode/init.c +2
-1-memblock_clear_kho_scratch (0 ,SZ_1M ); +if (is_kho_boot ()) +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)
The dmesg from one of the hosts with the warning is:
20:16:33 BIOS-provided physical RAM map: 20:16:33 BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable 20:16:33 BIOS-e820: [mem 0x00000000000a0000-0x00000000000fffff] reserved 20:16:33 BIOS-e820: [mem 0x0000000000100000-0x0000000069ca3fff] usable 20:16:33 BIOS-e820: [mem 0x0000000069ca4000-0x000000006bda3fff] reserved 20:16:33 BIOS-e820: [mem 0x000000006bda4000-0x000000006be5efff] ACPI data 20:16:33 BIOS-e820: [mem 0x000000006be5f000-0x000000006c9b8fff] ACPI NVS 20:16:33 BIOS-e820: [mem 0x000000006c9b9000-0x000000006ebedfff] reserved 20:16:33 BIOS-e820: [mem 0x000000006ebee000-0x000000006fffffff] usable 20:16:33 BIOS-e820: [mem 0x0000000070000000-0x000000008fffffff] reserved 20:16:33 BIOS-e820: [mem 0x00000000fd000000-0x00000000fe7fffff] reserved 20:16:33 BIOS-e820: [mem 0x00000000fed20000-0x00000000fed44fff] reserved 20:16:33 BIOS-e820: [mem 0x00000000ff000000-0x00000000ffffffff] reserved 20:16:33 BIOS-e820: [mem 0x0000000100000000-0x000000107fff847f] usable 20:16:33 BIOS-e820: [mem 0x000000107fff8480-0x000000107fff848f] type 128 20:16:33 BIOS-e820: [mem 0x000000107fff8490-0x000000107fffffff] usable 20:16:33 random: crng init done 20:16:33 ------------[ cut here ]------------ 20:16:33 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range+0x316/0x330 20:16:33 Modules linked in: 20:16:33 CPU: 0 UID: 0 PID: 0 Comm: swapper Tainted: G S 6.16.1-0_fbk0_0_gc0739ee5037a #1 NONE 20:16:33 Tainted: [S]=CPU_OUT_OF_SPEC 20:16:33 RIP: 0010:memblock_add_range+0x316/0x330 20:16:33 Code: ff ff ff 89 5c 24 08 41 ff c5 44 89 6c 24 10 48 63 74 24 08 48 63 54 24 10 e8 26 0c 00 00 e9 41 ff ff ff 0f 0b e9 af fd ff ff <0f> 0b e9 b7 fd ff ff 0f 0b 0f 0b cc cc cc cc cc cc cc cc cc cc cc 20:16:33 RSP: 0000:ffffffff83403dd8 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 20:16:33 RAX: ffffffff8476ff90 RBX: 0000000000001c00 RCX: 0000000000000002 20:16:33 RDX: 00000000ffffffff RSI: 0000000000000000 RDI: ffffffff83bad4d8 20:16:33 RBP: 000000000009f000 R08: 0000000000000020 R09: 8000000000097101 20:16:33 R10: ffffffffff2004b0 R11: 203a6d6f646e6172 R12: 000000000009ec00 20:16:33 R13: 0000000000000002 R14: 0000000000100000 R15: 000000000009d000 20:16:33 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 20:16:33 CR2: ffff888065413ff8 CR3: 00000000663b7000 CR4: 00000000000000b0 20:16:33 Call Trace: 20:16:33 <TASK> 20:16:33 ? __memblock_reserve+0x75/0x80 20:16:33 ? setup_arch+0x30f/0xb10 20:16:33 ? start_kernel+0x58/0x960 20:16:33 ? x86_64_start_reservations+0x20/0x20 20:16:33 ? x86_64_start_kernel+0x13d/0x140 20:16:33 ? common_startup_64+0x13e/0x140 20:16:33 </TASK> 20:16:33 ---[ end trace 0000000000000000 ]--- 20:16:33 Memory allocation profiling is enabled with compression and is turned on! 20:16:33 NX (Execute Disable) protection: active 20:16:33 APIC: Static calls initialized 20:16:33 efi: EFI v2.6 by American Megatrends 20:16:33 efi: ACPI 2.0=0x6c5ec000 ACPI=0x6c5ec000 TPMFinalLog=0x6c987000 SMBIOS=0x6e69d000 SMBIOS 3.0=0x6e69c000 MEMATTR=0xffffffffffffffff ESRT=0x67d97918 INITRD=0x5f275d18 TPMEventLog=0x6be5d018 20:16:33 efi: Remove mem00: MMIO range=[0xff000000-0xffffffff] (16MB) from e820 map 20:16:33 efi: Not removing mem01: MMIO range=[0xfed20000-0xfed44fff] (148KB) from e820 map 20:16:33 efi: Remove mem02: MMIO range=[0xfd000000-0xfe7fffff] (24MB) from e820 map 20:16:33 efi: Remove mem03: MMIO range=[0x80000000-0x8fffffff] (256MB) from e820 map 20:16:33 SMBIOS 3.1.1 present. 20:16:33 DMI: Quanta Twin Lakes MP/Twin Lakes Passive MP, BIOS F09_3A23 12/08/2020 20:16:33 DMI: Memory slots populated: 4/8 20:16:33 tsc: Detected 1600.000 MHz processor 20:16:33 last_pfn = 0x1080000 max_arch_pfn = 0x400000000 20:16:33 MTRR map: 8 entries (3 fixed + 5 variable; max 23), built from 10 variable MTRRs 20:16:33 x86/PAT: Configuration [0-7]: WB WC UC- UC WB WP UC- WT 20:16:33 last_pfn = 0x70000 max_arch_pfn = 0x400000000 20:16:33 esrt: Reserving ESRT space from 0x0000000067d97918 to 0x0000000067d97978. 20:16:33 Using GB pages for direct mapping 20:16:33 RAMDISK: [mem 0x5ed81000-0x62ffffff] 20:16:33 ACPI: Early table checksum verification disabled 20:16:33 ACPI: RSDP 0x000000006C5EC000 000024 (v02 ALASKA) 20:16:33 ACPI: XSDT 0x000000006C5EC0C0 000104 (v01 ALASKA A M I 01072009 AMI 00010013) 20:16:33 ACPI: FACP 0x000000006C62E590 000114 (v06 ALASKA A M I 01072009 INTL 20091013) 20:16:33 ACPI: DSDT 0x000000006C5EC260 04232D (v02 ALASKA A M I 01072009 INTL 20091013) 20:16:33 ACPI: FACS 0x000000006C9B7080 000040 20:16:33 ACPI: FPDT 0x000000006C62E6A8 000044 (v01 ALASKA A M I 01072009 AMI 00010013) 20:16:33 ACPI: FIDT 0x000000006C62E6F0 00009C (v01 ALASKA A M I 01072009 AMI 00010013) 20:16:33 ACPI: SPMI 0x000000006C62E790 000041 (v05 ALASKA A M I 00000000 AMI. 00000000) 20:16:33 ACPI: UEFI 0x000000006C62E7D8 000048 (v01 ALASKA A M I 01072009 01000013) 20:16:33 ACPI: MCFG 0x000000006C62E820 00003C (v01 ALASKA A M I 01072009 MSFT 00000097) 20:16:33 ACPI: HPET 0x000000006C62E860 000038 (v01 ALASKA A M I 00000001 INTL 20091013) 20:16:33 ACPI: APIC 0x000000006C62E898 00071E (v03 ALASKA A M I 00000000 INTL 20091013) 20:16:33 ACPI: MIGT 0x000000006C62EFB8 000040 (v01 ALASKA A M I 00000000 INTL 20091013) 20:16:33 ACPI: PCAT 0x000000006C62EFF8 000068 (v02 ALASKA A M I 00000002 INTL 20091013) 20:16:33 ACPI: PCCT 0x000000006C62F060 00006E (v01 ALASKA A M I 00000002 INTL 20091013) 20:16:33 ACPI: RASF 0x000000006C62F0D0 000030 (v01 ALASKA A M I 00000001 INTL 20091013) 20:16:33 ACPI: SVOS 0x000000006C62F100 000032 (v01 ALASKA A M I 00000000 INTL 20091013) 20:16:33 ACPI: WDDT 0x000000006C62F138 000040 (v01 ALASKA A M I 00000000 INTL 20091013) 20:16:33 ACPI: OEM4 0x000000006C62F178 028A0C (v02 INTEL CPU CST 00003000 INTL 20140828) 20:16:33 ACPI: OEM1 0x000000006C657B88 00A8CC (v02 INTEL CPU EIST 00003000 INTL 20140828) 20:16:33 ACPI: OEM2 0x000000006C662458 006534 (v02 INTEL CPU HWP 00003000 INTL 20140828) 20:16:33 ACPI: SSDT 0x000000006C668990 00CEB8 (v02 INTEL SSDT PM 00004000 INTL 20140828) 20:16:33 ACPI: SSDT 0x000000006C675848 00065B (v02 ALASKA A M I 00000000 INTL 20091013) 20:16:33 ACPI: SPCR 0x000000006C675EA8 000050 (v02 A M I APTIO V 01072009 AMI. 0005000E) 20:16:33 ACPI: TPM2 0x000000006C675EF8 000034 (v04 ALASKA A M I 00000001 AMI 00000000) 20:16:33 ACPI: SSDT 0x000000006C675F30 001368 (v02 INTEL SpsNm 00000002 INTL 20140828) 20:16:33 ACPI: DMAR 0x000000006C677298 0000E8 (v01 ALASKA A M I 00000001 INTL 20091013) 20:16:33 ACPI: HEST 0x000000006C677380 0000A8 (v01 ALASKA A M I 00000001 INTL 00000001) 20:16:33 ACPI: BERT 0x000000006C677428 000030 (v01 ALASKA A M I 00000001 INTL 00000001) 20:16:33 ACPI: ERST 0x000000006C677458 000230 (v01 ALASKA A M I 00000001 INTL 00000001) 20:16:33 ACPI: EINJ 0x000000006C677688 000150 (v01 ALASKA A M I 00000001 INTL 00000001) 20:16:33 ACPI: WSMT 0x000000006C6777D8 000028 (v01 ALASKA A M I 01072009 AMI 00010013) 20:16:33 ACPI: Reserving FACP table memory at [mem 0x6c62e590-0x6c62e6a3] 20:16:33 ACPI: Reserving DSDT table memory at [mem 0x6c5ec260-0x6c62e58c] 20:16:33 ACPI: Reserving FACS table memory at [mem 0x6c9b7080-0x6c9b70bf] 20:16:33 ACPI: Reserving FPDT table memory at [mem 0x6c62e6a8-0x6c62e6eb] 20:16:33 ACPI: Reserving FIDT table memory at [mem 0x6c62e6f0-0x6c62e78b] 20:16:33 ACPI: Reserving SPMI table memory at [mem 0x6c62e790-0x6c62e7d0] 20:16:33 ACPI: Reserving UEFI table memory at [mem 0x6c62e7d8-0x6c62e81f] 20:16:33 ACPI: Reserving MCFG table memory at [mem 0x6c62e820-0x6c62e85b] 20:16:33 ACPI: Reserving HPET table memory at [mem 0x6c62e860-0x6c62e897] 20:16:33 ACPI: Reserving APIC table memory at [mem 0x6c62e898-0x6c62efb5] 20:16:33 ACPI: Reserving MIGT table memory at [mem 0x6c62efb8-0x6c62eff7] 20:16:33 ACPI: Reserving PCAT table memory at [mem 0x6c62eff8-0x6c62f05f] 20:16:33 ACPI: Reserving PCCT table memory at [mem 0x6c62f060-0x6c62f0cd] 20:16:33 ACPI: Reserving RASF table memory at [mem 0x6c62f0d0-0x6c62f0ff] 20:16:33 ACPI: Reserving SVOS table memory at [mem 0x6c62f100-0x6c62f131] 20:16:33 ACPI: Reserving WDDT table memory at [mem 0x6c62f138-0x6c62f177] 20:16:33 ACPI: Reserving OEM4 table memory at [mem 0x6c62f178-0x6c657b83] 20:16:33 ACPI: Reserving OEM1 table memory at [mem 0x6c657b88-0x6c662453] 20:16:33 ACPI: Reserving OEM2 table memory at [mem 0x6c662458-0x6c66898b] 20:16:33 ACPI: Reserving SSDT table memory at [mem 0x6c668990-0x6c675847] 20:16:33 ACPI: Reserving SSDT table memory at [mem 0x6c675848-0x6c675ea2] 20:16:33 ACPI: Reserving SPCR table memory at [mem 0x6c675ea8-0x6c675ef7] 20:16:33 ACPI: Reserving TPM2 table memory at [mem 0x6c675ef8-0x6c675f2b] 20:16:33 ACPI: Reserving SSDT table memory at [mem 0x6c675f30-0x6c677297] 20:16:33 ACPI: Reserving DMAR table memory at [mem 0x6c677298-0x6c67737f] 20:16:33 ACPI: Reserving HEST table memory at [mem 0x6c677380-0x6c677427] 20:16:33 ACPI: Reserving BERT table memory at [mem 0x6c677428-0x6c677457] 20:16:33 ACPI: Reserving ERST table memory at [mem 0x6c677458-0x6c677687] 20:16:33 ACPI: Reserving EINJ table memory at [mem 0x6c677688-0x6c6777d7] 20:16:33 ACPI: Reserving WSMT table memory at [mem 0x6c6777d8-0x6c6777ff] 20:16:33 No NUMA configuration found 20:16:33 Faking a node at [mem 0x0000000000000000-0x000000107fffffff] 20:16:33 NODE_DATA(0) allocated [mem 0x107fffcfc0-0x107fffffff] 20:16:33 hugetlb_cma: reserve 6144 MiB, up to 6144 MiB per node 20:16:33 cma: Reserved 6144 MiB in 1 range 20:16:33 hugetlb_cma: reserved 6144 MiB on node 0 20:16:33 crashkernel reserved: 0x0000000052000000 - 0x000000005e000000 (192 MB) 20:16:33 Zone ranges: 20:16:33 DMA [mem 0x0000000000001000-0x0000000000ffffff] 20:16:33 DMA32 [mem 0x0000000001000000-0x00000000ffffffff] 20:16:33 Normal [mem 0x0000000100000000-0x000000107fffffff] 20:16:33 Device empty 20:16:33 Movable zone start for each node 20:16:33 Early memory node ranges 20:16:33 node 0: [mem 0x0000000000001000-0x000000000009ffff] 20:16:33 node 0: [mem 0x0000000000100000-0x0000000069ca3fff] 20:16:33 node 0: [mem 0x000000006ebee000-0x000000006fffffff] 20:16:33 node 0: [mem 0x0000000100000000-0x000000107fff7fff] 20:16:33 node 0: [mem 0x000000107fff9000-0x000000107fffffff] 20:16:33 Initmem setup node 0 [mem 0x0000000000001000-0x000000107fffffff] 20:16:33 On node 0, zone DMA: 1 pages in unavailable ranges 20:16:33 On node 0, zone DMA: 96 pages in unavailable ranges 20:16:33 On node 0, zone DMA32: 20298 pages in unavailable ranges 20:16:33 On node 0, zone Normal: 1 pages in unavailable ranges 20:16:33 ACPI: PM-Timer IO Port: 0x508 20:16:33 ACPI: X2APIC_NMI (uid[0xffffffff] high level lint[0x1]) 20:16:33 ACPI: LAPIC_NMI (acpi_id[0xff] high level lint[0x1]) 20:16:33 IOAPIC[0]: apic_id 8, version 32, address 0xfec00000, GSI 0-23 20:16:33 IOAPIC[1]: apic_id 9, version 32, address 0xfec01000, GSI 24-31 20:16:33 IOAPIC[2]: apic_id 10, version 32, address 0xfec08000, GSI 32-39 20:16:33 IOAPIC[3]: apic_id 11, version 32, address 0xfec10000, GSI 40-47 20:16:33 IOAPIC[4]: apic_id 12, version 32, address 0xfec18000, GSI 48-55 20:16:33 ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl) 20:16:33 ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level) 20:16:33 ACPI: Using ACPI (MADT) for SMP configuration information 20:16:33 ACPI: HPET id: 0x8086a701 base: 0xfed00000 20:16:33 TSC deadline timer available 20:16:33 CPU topo: Max. logical packages: 1 20:16:33 CPU topo: Max. logical dies: 1 20:16:33 CPU topo: Max. dies per package: 1 20:16:33 CPU topo: Max. threads per core: 2 20:16:33 CPU topo: Num. cores per package: 18 20:16:33 CPU topo: Num. threads per package: 36 20:16:33 CPU topo: Allowing 36 present CPUs plus 0 hotplug CPUs 20:16:33 [mem 0x80000000-0xfed1ffff] available for PCI devices 20:16:33 Booting paravirtualized kernel on bare hardware 20:16:33 clocksource: refined-jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1910969940391419 ns 20:16:33 Load bootconfig: 46 bytes 5 nodes 20:16:33 setup_percpu: NR_CPUS:512 nr_cpumask_bits:36 nr_cpu_ids:36 nr_node_ids:1 20:16:33 percpu: Embedded 78 pages/cpu s282624 r8192 d28672 u524288 20:16:33 Unknown kernel command line parameters "biosdevname=0", will be passed to user space. 20:16:33 printk: log buffer data + meta data: 2097152 + 7340032 = 9437184 bytes 20:16:33 Dentry cache hash table entries: 8388608 (order: 14, 67108864 bytes, linear) 20:16:33 Inode-cache hash table entries: 4194304 (order: 13, 33554432 bytes, linear) 20:16:33 software IO TLB: area num 64. 20:16:33 software IO TLB: SWIOTLB bounce buffer size roundup to 16MB 20:16:33 Fallback order for Node 0: 0 20:16:33 Built 1 zonelists, mobility grouping on. Total pages: 16691284 20:16:33 Policy zone: Normal 20:16:33 mem auto-init: stack:off, heap alloc:off, heap free:off 20:16:33 SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=36, Nodes=1
Mike Rapoport
maintainerRe: [PATCH v8 12/17] x86/e820: temporarily enable KHO scratch for memory below 1M
Quoted 88 lines · Usama Arif
Quoted 42 lines · Mike Rapoport
Hi,
Quoted 30 lines · Pratyush Yadav
Quoted 28 lines · Usama Arif
arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 72
Quoted 11 lines
arch/x86/realmode/init.c +2
-0@@ -65,6 +65,8 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); + +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)Hello!
I am working with Breno who reported that we are seeing the below warning at boot when rolling out 6.16 in Meta fleet. It is difficult to reproduce on a single host manually but we are seeing this several times a day inside the fleet.
20:16:33 ------------[ cut here ]------------ 20:16:33 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range+0x316/0x330 20:16:33 Modules linked in: 20:16:33 CPU: 0 UID: 0 PID: 0 Comm: swapper Tainted: G S 6.16.1-0_fbk0_0_gc0739ee5037a #1 NONE 20:16:33 Tainted: [S]=CPU_OUT_OF_SPEC 20:16:33 RIP: 0010:memblock_add_range+0x316/0x330 20:16:33 Code: ff ff ff 89 5c 24 08 41 ff c5 44 89 6c 24 10 48 63 74 24 08 48 63 54 24 10 e8 26 0c 00 00 e9 41 ff ff ff 0f 0b e9 af fd ff ff <0f> 0b e9 b7 fd ff ff 0f 0b 0f 0b cc cc cc cc cc cc cc cc cc cc cc 20:16:33 RSP: 0000:ffffffff83403dd8 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 20:16:33 RAX: ffffffff8476ff90 RBX: 0000000000001c00 RCX: 0000000000000002 20:16:33 RDX: 00000000ffffffff RSI: 0000000000000000 RDI: ffffffff83bad4d8Quoted 8 lines
Quoted 8 lines
20:16:33 RBP: 000000000009f000 R08: 0000000000000020 R09: 8000000000097101 20:16:33 R10: ffffffffff2004b0 R11: 203a6d6f646e6172 R12: 000000000009ec00 20:16:33 R13: 0000000000000002 R14: 0000000000100000 R15: 000000000009d000 20:16:33 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 20:16:33 CR2: ffff888065413ff8 CR3: 00000000663b7000 CR4: 00000000000000b0 20:16:33 Call Trace:20:16:33 <TASK>
20:16:33 ?__memblock_reserve+0x75/0x80Quoted 5 lines
Do you have faddr2line for this?
Quoted 1 line
Quoted 1 line
Quoted 1 line
20:16:33 ?
setup_arch+0x30f/0xb10And this?
Thanks for this! I think it helped narrow down the problem.
The stack is:
20:16:33 ?
__memblock_reserve(mm/memblock.c:936)
20:16:33 ?setup_arch(arch/x86/kernel/setup.c:413arch/x86/kernel/setup.c:499arch/x86/kernel/setup.c:956) 20:16:33 ?start_kernel(init/main.c:922)
20:16:33 ?x86_64_start_reservations(arch/x86/kernel/ebda.c:57)
20:16:33 ?x86_64_start_kernel(arch/x86/kernel/head64.c:231)
20:16:33 ?common_startup_64(arch/x86/kernel/head_64.S:419)This is 6.16 kernel.
20:16:33 ?
__memblock_reserve(mm/memblock.c:936)
Thatsmemblock_add_rangecall inmemblock_reserve20:16:33 ?
setup_arch(arch/x86/kernel/setup.c:413arch/x86/kernel/setup.c:499arch/x86/kernel/setup.c:956) That isparse_setup_data->add_early_ima_buffer->add_early_ima_buffer->memblock_reserve_kernI put a simple print like below:
arch/x86/kernel/setup.c +1
-0@@ -409,6 +409,7 @@ static void __init add_early_ima_buffer(u64 phys_addr) }if (data->size) { +pr_err ("PPP %s %s %d data->addr %llx, data->size %llx \n" , __FILE__, __func__, __LINE__, data->addr, data->size);memblock_reserve_kern (data->addr, data->size); ima_kexec_buffer_phys = data->addr; ima_kexec_buffer_size = data->size;
Quoted 4 lines
and I see (without replicating the warning):
[ 0.000000] PPP arch/x86/kernel/setup.c add_early_ima_buffer 412 data->addr 9e000, data->size 1000....
So it looks like in cases when the warning reproduces there's something that reserves memory overlapping with IMA buffer before add_early_ima_buffer().
Quoted 12 lines
[ 0.000348] MEMBLOCK configuration: [ 0.000348] memory size = 0x0000003fea329ff0 reserved size = 0x00000000050c969b [ 0.000350] memory.cnt = 0x5 [ 0.000351] memory[0x0] [0x0000000000001000-0x000000000009ffff], 0x000000000009f000 bytes flags: 0x40 [ 0.000353] memory[0x1] [0x0000000000100000-0x0000000067c65fff], 0x0000000067b66000 bytes flags: 0x0 [ 0.000355] memory[0x2] [0x000000006d8db000-0x000000006fffffff], 0x0000000002725000 bytes flags: 0x0 [ 0.000356] memory[0x3] [0x0000000100000000-0x000000407fff8fff], 0x0000003f7fff9000 bytes flags: 0x0 [ 0.000358] memory[0x4] [0x000000407fffa000-0x000000407fffffff], 0x0000000000006000 bytes flags: 0x0 [ 0.000359] reserved.cnt = 0x7
Quoted 1 line
So
MEMBLOCK_RSRV_KERNandMEMBLOCK_KHO_SCRATCHseem to overlap..
It does not matter, they are set on different arrays. RSRV_KERN is set on regions in memblock.reserved and KHO_SCRATCH is set on regions in memblock.memory.
So dumping memblock.memory is completely irrelevant, you need to check memblock.reserved for potential conflicts.
Quoted 24 lines
Quoted 14 lines
Quoted 10 lines
Quoted 10 lines
20:16:33 ? start_kernel+0x58/0x960 20:16:33 ? x86_64_start_reservations+0x20/0x20 20:16:33 ? x86_64_start_kernel+0x13d/0x140 20:16:33 ? common_startup_64+0x13e/0x140 20:16:33 </TASK>20:16:33 ---[ end trace 0000000000000000 ]---
Rolling out with memblock=debug is not really an option in a large scale fleet due to the time added to boot. But I did try on one of the hosts (without reproducing the issue) and I see:
Is it a problem to roll out a kernel that has additional debug printouts as Breno suggested earlier? I.e.
Quoted 9 lines
if (flags != MEMBLOCK_NONE && flags != rgn->flags) { pr_warn("memblock: Flag mismatch at region [%pa-%pa]\n", &rgn->base, &rend); pr_warn(" Existing region flags: %#x\n", rgn->flags); pr_warn(" New range flags: %#x\n", flags); pr_warn(" New range: [%pa-%pa]\n", &base, &end); WARN_ON_ONCE(1); }
Quoted 5 lines
I can add this, but the only thing is that it might be several weeks between me putting this in the kernel and that kernel being deployed to enough machines that it starts to show up. I think the IMA coinciding with
memblock_mark_kho_scratchine820__memblock_setupcould be the reason for the warning. It might be better to fix that case and deploy it to see if the warnings still show up?
I can add these prints as well incase it doesnt fix the problem.
I really don't think that effectively disabling memblock_mark_kho_scratch() when KHO is disabled will solve the problem because as I said the flags it sets are on different structure than the flags set by memblock_reserve_kern().
Quoted 9 lines
Quoted 6 lines
If you have the logs from failing boots up to the point where SLUB reports about it's initialization, e.g.
[ 0.134377] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1something there may hint about what's the issue.
So the boot doesnt fail, its just giving warnings in the fleet. I have added the dmesg to the end of the mail.
Thanks, unfortunately nothing jumped at me there.
Quoted 8 lines
Does something like this look good? I can try deploying this (although it will take sometime to find out). We can get it upstream as well as that makes backports easier.
mm/memblock.c +0
-0
mm/memblock.c int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t · line 1123
Quoted 7 lines
mm/memblock.c +2
-2@@ -1119,8 +1119,13 @@ int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t*/ __init int memblock_mark_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,1 , -MEMBLOCK_KHO_SCRATCH ); +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH +if (is_kho_boot ())
Please use
if (IS_ENABLED(CONFIG_MEMBLOCK_KHO_SCRATCH)
instead of indef.
If you send a formal patch with it, I'll take it.
I'd suggest still deploying additional debug printouts internally.
Quoted 9 lines
mm/memblock.c +5
-0+return memblock_setclr_flag (&memblock.memory, base, size,1 , +MEMBLOCK_KHO_SCRATCH ); +#else +return 0 ; +#endif }/**
mm/memblock.c __init int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size) · line 1145
Quoted 10 lines
mm/memblock.c +5
-2@@ -1133,8 +1138,13 @@ __init int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size)*/ __init int memblock_clear_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,0 , -MEMBLOCK_KHO_SCRATCH ); +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH +if (is_kho_boot ()) +return memblock_setclr_flag (&memblock.memory, base, size,0 , +MEMBLOCK_KHO_SCRATCH ); +#else
If nothing sets the flag _clear is anyway nop, but let's update it as well for symmetry.
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH v8 12/17] x86/e820: temporarily enable KHO scratch for memory below 1M
Quoted 184 lines · Mike Rapoport
Quoted 88 lines · Usama Arif
Quoted 42 lines · Mike Rapoport
Hi,
Quoted 30 lines · Pratyush Yadav
Quoted 28 lines · Usama Arif
arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 72
Quoted 11 lines
arch/x86/realmode/init.c +2
-0@@ -65,6 +65,8 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); + +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)Hello!
I am working with Breno who reported that we are seeing the below warning at boot when rolling out 6.16 in Meta fleet. It is difficult to reproduce on a single host manually but we are seeing this several times a day inside the fleet.
20:16:33 ------------[ cut here ]------------ 20:16:33 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range+0x316/0x330 20:16:33 Modules linked in: 20:16:33 CPU: 0 UID: 0 PID: 0 Comm: swapper Tainted: G S 6.16.1-0_fbk0_0_gc0739ee5037a #1 NONE 20:16:33 Tainted: [S]=CPU_OUT_OF_SPEC 20:16:33 RIP: 0010:memblock_add_range+0x316/0x330 20:16:33 Code: ff ff ff 89 5c 24 08 41 ff c5 44 89 6c 24 10 48 63 74 24 08 48 63 54 24 10 e8 26 0c 00 00 e9 41 ff ff ff 0f 0b e9 af fd ff ff <0f> 0b e9 b7 fd ff ff 0f 0b 0f 0b cc cc cc cc cc cc cc cc cc cc cc 20:16:33 RSP: 0000:ffffffff83403dd8 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 20:16:33 RAX: ffffffff8476ff90 RBX: 0000000000001c00 RCX: 0000000000000002 20:16:33 RDX: 00000000ffffffff RSI: 0000000000000000 RDI: ffffffff83bad4d8Quoted 8 lines
Quoted 8 lines
20:16:33 RBP: 000000000009f000 R08: 0000000000000020 R09: 8000000000097101 20:16:33 R10: ffffffffff2004b0 R11: 203a6d6f646e6172 R12: 000000000009ec00 20:16:33 R13: 0000000000000002 R14: 0000000000100000 R15: 000000000009d000 20:16:33 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 20:16:33 CR2: ffff888065413ff8 CR3: 00000000663b7000 CR4: 00000000000000b0 20:16:33 Call Trace:20:16:33 <TASK>
20:16:33 ?__memblock_reserve+0x75/0x80Quoted 5 lines
Do you have faddr2line for this?
Quoted 1 line
Quoted 1 line
Quoted 1 line
20:16:33 ?
setup_arch+0x30f/0xb10And this?
Thanks for this! I think it helped narrow down the problem.
The stack is:
20:16:33 ?
__memblock_reserve(mm/memblock.c:936)
20:16:33 ?setup_arch(arch/x86/kernel/setup.c:413arch/x86/kernel/setup.c:499arch/x86/kernel/setup.c:956) 20:16:33 ?start_kernel(init/main.c:922)
20:16:33 ?x86_64_start_reservations(arch/x86/kernel/ebda.c:57)
20:16:33 ?x86_64_start_kernel(arch/x86/kernel/head64.c:231)
20:16:33 ?common_startup_64(arch/x86/kernel/head_64.S:419)This is 6.16 kernel.
20:16:33 ?
__memblock_reserve(mm/memblock.c:936)
Thatsmemblock_add_rangecall inmemblock_reserve20:16:33 ?
setup_arch(arch/x86/kernel/setup.c:413arch/x86/kernel/setup.c:499arch/x86/kernel/setup.c:956) That isparse_setup_data->add_early_ima_buffer->add_early_ima_buffer->memblock_reserve_kernI put a simple print like below:
arch/x86/kernel/setup.c +1
-0@@ -409,6 +409,7 @@ static void __init add_early_ima_buffer(u64 phys_addr) }if (data->size) { +pr_err ("PPP %s %s %d data->addr %llx, data->size %llx \n" , __FILE__, __func__, __LINE__, data->addr, data->size);memblock_reserve_kern (data->addr, data->size); ima_kexec_buffer_phys = data->addr; ima_kexec_buffer_size = data->size;Quoted 4 lines
and I see (without replicating the warning):
[ 0.000000] PPP arch/x86/kernel/setup.c add_early_ima_buffer 412 data->addr 9e000, data->size 1000....
So it looks like in cases when the warning reproduces there's something that reserves memory overlapping with IMA buffer before
add_early_ima_buffer().Quoted 12 lines
[ 0.000348] MEMBLOCK configuration: [ 0.000348] memory size = 0x0000003fea329ff0 reserved size = 0x00000000050c969b [ 0.000350] memory.cnt = 0x5 [ 0.000351] memory[0x0] [0x0000000000001000-0x000000000009ffff], 0x000000000009f000 bytes flags: 0x40 [ 0.000353] memory[0x1] [0x0000000000100000-0x0000000067c65fff], 0x0000000067b66000 bytes flags: 0x0 [ 0.000355] memory[0x2] [0x000000006d8db000-0x000000006fffffff], 0x0000000002725000 bytes flags: 0x0 [ 0.000356] memory[0x3] [0x0000000100000000-0x000000407fff8fff], 0x0000003f7fff9000 bytes flags: 0x0 [ 0.000358] memory[0x4] [0x000000407fffa000-0x000000407fffffff], 0x0000000000006000 bytes flags: 0x0 [ 0.000359] reserved.cnt = 0x7Quoted 1 line
So
MEMBLOCK_RSRV_KERNandMEMBLOCK_KHO_SCRATCHseem to overlap..It does not matter, they are set on different arrays.
RSRV_KERNis set on regions in memblock.reserved andKHO_SCRATCHis set on regions in memblock.memory.So dumping memblock.memory is completely irrelevant, you need to check memblock.reserved for potential conflicts.
Quoted 24 lines
Quoted 14 lines
Quoted 10 lines
Quoted 10 lines
20:16:33 ? start_kernel+0x58/0x960 20:16:33 ? x86_64_start_reservations+0x20/0x20 20:16:33 ? x86_64_start_kernel+0x13d/0x140 20:16:33 ? common_startup_64+0x13e/0x140 20:16:33 </TASK>20:16:33 ---[ end trace 0000000000000000 ]---
Rolling out with memblock=debug is not really an option in a large scale fleet due to the time added to boot. But I did try on one of the hosts (without reproducing the issue) and I see:
Is it a problem to roll out a kernel that has additional debug printouts as Breno suggested earlier? I.e.
Quoted 9 lines
if (flags != MEMBLOCK_NONE && flags != rgn->flags) { pr_warn("memblock: Flag mismatch at region [%pa-%pa]\n", &rgn->base, &rend); pr_warn(" Existing region flags: %#x\n", rgn->flags); pr_warn(" New range flags: %#x\n", flags); pr_warn(" New range: [%pa-%pa]\n", &base, &end); WARN_ON_ONCE(1); }Quoted 5 lines
I can add this, but the only thing is that it might be several weeks between me putting this in the kernel and that kernel being deployed to enough machines that it starts to show up. I think the IMA coinciding with
memblock_mark_kho_scratchine820__memblock_setupcould be the reason for the warning. It might be better to fix that case and deploy it to see if the warnings still show up?
I can add these prints as well incase it doesnt fix the problem.I really don't think that effectively disabling
memblock_mark_kho_scratch()when KHO is disabled will solve the problem because as I said the flags it sets are on different structure than the flags set bymemblock_reserve_kern().Quoted 9 lines
Quoted 6 lines
If you have the logs from failing boots up to the point where SLUB reports about it's initialization, e.g.
[ 0.134377] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1something there may hint about what's the issue.
So the boot doesnt fail, its just giving warnings in the fleet. I have added the dmesg to the end of the mail.
Thanks, unfortunately nothing jumped at me there.
Quoted 8 lines
Does something like this look good? I can try deploying this (although it will take sometime to find out). We can get it upstream as well as that makes backports easier.
mm/memblock.c +0
-0mm/memblock.c int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t · line 1123
Quoted 7 lines
mm/memblock.c +2
-2@@ -1119,8 +1119,13 @@ int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t*/ __init int memblock_mark_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,1 , -MEMBLOCK_KHO_SCRATCH ); +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH +if (is_kho_boot ())Please use
Quoted 6 lines
if (
IS_ENABLED(CONFIG_MEMBLOCK_KHO_SCRATCH)instead of indef.
If you send a formal patch with it, I'll take it.
I'd suggest still deploying additional debug printouts internally.
Thanks! I will add the additional debug prints and [1] in the next release. It will be sometime before it makes it into production, so I will try to debug this more using the information you provided above.
[1] https://lore.kernel.org/all/[email protected]/
Quoted 24 lines
Quoted 10 lines
mm/memblock.c +5
-0+return memblock_setclr_flag (&memblock.memory, base, size,1 , +MEMBLOCK_KHO_SCRATCH ); +#else +return 0 ; +#endif }/** mm/memblock.c __init int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size) · line 1145
Quoted 10 lines
mm/memblock.c +5
-2@@ -1133,8 +1138,13 @@ __init int memblock_mark_kho_scratch(phys_addr_t base, phys_addr_t size)*/ __init int memblock_clear_kho_scratch (phys_addr_t base,phys_addr_t size) { -return memblock_setclr_flag (&memblock.memory, base, size,0 , -MEMBLOCK_KHO_SCRATCH ); +#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH +if (is_kho_boot ()) +return memblock_setclr_flag (&memblock.memory, base, size,0 , +MEMBLOCK_KHO_SCRATCH ); +#else If nothing sets the flag
_clearis anyway nop, but let's update it as well for symmetry.
Re: [PATCH v8 12/17] x86/e820: temporarily enable KHO scratch for memory below 1M
In reply to Pratyush YadavQuoted 121 lines · Pratyush Yadav
Quoted 114 lines · Usama Arif
Quoted 57 lines · Changyuan Lyu
From: Alexander Graf <[email protected]>
KHO kernels are special and use only scratch memory for memblock allocations, but memory below 1M is ignored by kernel after early boot and cannot be naturally marked as scratch.
To allow allocation of the real-mode trampoline and a few (if any) other very early allocations from below 1M forcibly mark the memory below 1M as scratch.
After real mode trampoline is allocated, clear that scratch marking.
Signed-off-by Alexander Graf <[email protected]>Co-developed-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by Mike Rapoport (Microsoft) <[email protected]>Co-developed-by Changyuan Lyu <[email protected]>Signed-off-by Changyuan Lyu <[email protected]>Acked-by Dave Hansen <[email protected]>--- arch/x86/kernel/e820.c | 18 ++++++++++++++++++ arch/x86/realmode/init.c | 2 ++ 2 files changed, 20 insertions(+)arch/x86/kernel/e820.c +18
-0@@ -1299,6 +1299,24 @@ void __init e820__memblock_setup(void)memblock_add (entry->addr, entry->size); } +/* +* At this point memblock is only allowed to allocate from memory +* below 1M (aka ISA_END_ADDRESS) up until direct map is completely set +* up in init_mem_mapping(). +* +* KHO kernels are special and use only scratch memory for memblock +* allocations, but memory below 1M is ignored by kernel after early +* boot and cannot be naturally marked as scratch. +* +* To allow allocation of the real-mode trampoline and a few (if any) +* other very early allocations from below 1M forcibly mark the memory +* below 1M as scratch. +* +* After real mode trampoline is allocated, we clear that scratch +* marking. +*/ +memblock_mark_kho_scratch (0 ,SZ_1M ); +/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and * to even less without it. arch/x86/realmode/init.c +0
-0arch/x86/realmode/init.c void __init reserve_real_mode(void) · line 72
Quoted 8 lines
arch/x86/realmode/init.c +2
-0@@ -65,6 +65,8 @@ void __init reserve_real_mode(void)* setup_arch(). */ memblock_reserve (0 ,SZ_1M ); + +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)Hello!
I am working with Breno who reported that we are seeing the below warning at boot when rolling out 6.16 in Meta fleet. It is difficult to reproduce on a single host manually but we are seeing this several times a day inside the fleet.
20:16:33 ------------[ cut here ]------------ 20:16:33 WARNING: CPU: 0 PID: 0 at mm/memblock.c:668 memblock_add_range+0x316/0x330 20:16:33 Modules linked in: 20:16:33 CPU: 0 UID: 0 PID: 0 Comm: swapper Tainted: G S 6.16.1-0_fbk0_0_gc0739ee5037a #1 NONE 20:16:33 Tainted: [S]=CPU_OUT_OF_SPEC 20:16:33 RIP: 0010:memblock_add_range+0x316/0x330 20:16:33 Code: ff ff ff 89 5c 24 08 41 ff c5 44 89 6c 24 10 48 63 74 24 08 48 63 54 24 10 e8 26 0c 00 00 e9 41 ff ff ff 0f 0b e9 af fd ff ff <0f> 0b e9 b7 fd ff ff 0f 0b 0f 0b cc cc cc cc cc cc cc cc cc cc cc 20:16:33 RSP: 0000:ffffffff83403dd8 EFLAGS: 00010083 ORIG_RAX: 0000000000000000 20:16:33 RAX: ffffffff8476ff90 RBX: 0000000000001c00 RCX: 0000000000000002 20:16:33 RDX: 00000000ffffffff RSI: 0000000000000000 RDI: ffffffff83bad4d8 20:16:33 RBP: 000000000009f000 R08: 0000000000000020 R09: 8000000000097101 20:16:33 R10: ffffffffff2004b0 R11: 203a6d6f646e6172 R12: 000000000009ec00 20:16:33 R13: 0000000000000002 R14: 0000000000100000 R15: 000000000009d000 20:16:33 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 20:16:33 CR2: ffff888065413ff8 CR3: 00000000663b7000 CR4: 00000000000000b0 20:16:33 Call Trace: 20:16:33 <TASK> 20:16:33 ? __memblock_reserve+0x75/0x80 20:16:33 ? setup_arch+0x30f/0xb10 20:16:33 ? start_kernel+0x58/0x960 20:16:33 ? x86_64_start_reservations+0x20/0x20 20:16:33 ? x86_64_start_kernel+0x13d/0x140 20:16:33 ? common_startup_64+0x13e/0x140 20:16:33 </TASK>20:16:33 ---[ end trace 0000000000000000 ]---
Rolling out with memblock=debug is not really an option in a large scale fleet due to the time added to boot. But I did try on one of the hosts (without reproducing the issue) and I see:
[ 0.000616] memory.cnt = 0x6 [ 0.000617] memory[0x0] [0x0000000000001000-0x000000000009bfff], 0x000000000009b000 bytes flags: 0x40 [ 0.000620] memory[0x1] [0x000000000009f000-0x000000000009ffff], 0x0000000000001000 bytes flags: 0x40 [ 0.000621] memory[0x2] [0x0000000000100000-0x000000005ed09fff], 0x000000005ec0a000 bytes flags: 0x0...
The
0x40(MEMBLOCK_KHO_SCRATCH) is coming frommemblock_mark_kho_scratchine820__memblock_setup. I believe this should be under ifdef like the diff at the end? (Happy to send this as a patch for review if it makes sense). We haveKEXEC_HANDOVERdisabled in our defconfig, thereforeMEMBLOCK_KHO_SCRATCHshouldnt be selected and we shouldnt have anyMEMBLOCK_KHO_SCRATCHtype regions in our memblock reservations.Quoted 4 lines
The other thing I did was insert a while(1) just before the warning and inspected the registers in qemu. R14 held the base register, and R15 held the size at that point.
In the warning R14 is0x100000meaning that someone is reserving a region with a different flag toMEMBLOCK_NONEat the boundary ofMEMBLOCK_KHO_SCRATCH.
Quoted 5 lines
I don't get this... The
WARN_ON()is only triggered when the regions overlap. Here, there should be no overlap, since the scratch region should end at0x100000(SZ_1M) and the new region starts at0x100000(SZ_1M).
Yes, this is likely a separate problem. I just discovered flags = 0x40 while trying to debug it with KEXEC_HANDOVER disabled.
Quoted 5 lines
Anyway, you do indeed point at a bug.
memblock_mark_kho_scratch()should only be called on a KHO boot, not unconditionally. So even withCONFIG_MEMBLOCK_KHO_SCRATCHenabled, this should only be called on a KHO boot, not every time.
Quoted 7 lines
I think the below diff should fix the warning for you by making sure the scratch areas are not present on non-KHO boot. I still don't know why you hit the warning in the first place though. If you'd be willing to dig deeper into that, it would be great.
Can you give the below a try and if it fixes the problem for you I can send it on the list.
Is there a reason for compiling this code with is_kho_boot, when we have disabled KEXEC_HANDOVER and dont want this in? i.e. why not just ifdef it with MEMBLOCK_KHO_SCRATCH when that defconfig is designed for it?
Quoted 47 lines
arch/x86/kernel/e820.c +3
-1@@ -16,6 +16,7 @@#include <linux/firmware-map.h> #include <linux/sort.h> #include <linux/memory_hotplug.h> +#include <linux/kexec_handover.h> #include <asm/e820/api.h> #include <asm/setup.h> @@ -1315,7 +1316,8 @@ void __init e820__memblock_setup(void)* After real mode trampoline is allocated, we clear that scratch * marking. */ -memblock_mark_kho_scratch (0 ,SZ_1M ); +if (is_kho_boot ()) +memblock_mark_kho_scratch (0 ,SZ_1M );/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and arch/x86/realmode/init.c +3
-1@@ -4,6 +4,7 @@#include <linux/memblock.h> #include <linux/cc_platform.h> #include <linux/pgtable.h> +#include <linux/kexec_handover.h> #include <asm/set_memory.h> #include <asm/realmode.h> @@ -67,7 +68,8 @@ void __init reserve_real_mode(void)*/ memblock_reserve (0 ,SZ_1M ); -memblock_clear_kho_scratch (0 ,SZ_1M ); +if (is_kho_boot ()) +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)
Pratyush Yadav
maintainerRe: [PATCH v8 12/17] x86/e820: temporarily enable KHO scratch for memory below 1M
Quoted 17 lines · Usama Arif
Quoted 16 lines · Pratyush Yadav
Quoted 14 lines · Usama Arif
Quoted 13 lines · Changyuan Lyu
From: Alexander Graf <[email protected]>
KHO kernels are special and use only scratch memory for memblock allocations, but memory below 1M is ignored by kernel after early boot and cannot be naturally marked as scratch.
To allow allocation of the real-mode trampoline and a few (if any) other very early allocations from below 1M forcibly mark the memory below 1M as scratch.
After real mode trampoline is allocated, clear that scratch marking.
Signed-off-by Alexander Graf <[email protected]>
[...]
Quoted 10 lines
Quoted 10 lines
Anyway, you do indeed point at a bug.
memblock_mark_kho_scratch()should only be called on a KHO boot, not unconditionally. So even withCONFIG_MEMBLOCK_KHO_SCRATCHenabled, this should only be called on a KHO boot, not every time.I think the below diff should fix the warning for you by making sure the scratch areas are not present on non-KHO boot. I still don't know why you hit the warning in the first place though. If you'd be willing to dig deeper into that, it would be great.
Quoted 6 lines
Quoted 2 lines
Can you give the below a try and if it fixes the problem for you I can send it on the list.
Is there a reason for compiling this code with
is_kho_boot, when we have disabledKEXEC_HANDOVERand dont want this in? i.e. why not just ifdef it withMEMBLOCK_KHO_SCRATCHwhen that defconfig is designed for it?
is_kho_boot() will always be false when CONFIG_KEXEC_HANDOVER is not enabled. So the compiler should optimize this out.
Only using the ifdef is not enough. Just because the config is enabled doesn't mean every boot will be a KHO boot. You can do regular reboots or even regular kexec, without ever having KHO involved. We only want to call this for a KHO boot. So a runtime check is needed anyway.
Quoted 49 lines
Quoted 48 lines
arch/x86/kernel/e820.c +3
-1@@ -16,6 +16,7 @@#include <linux/firmware-map.h> #include <linux/sort.h> #include <linux/memory_hotplug.h> +#include <linux/kexec_handover.h> #include <asm/e820/api.h> #include <asm/setup.h> @@ -1315,7 +1316,8 @@ void __init e820__memblock_setup(void)* After real mode trampoline is allocated, we clear that scratch * marking. */ -memblock_mark_kho_scratch (0 ,SZ_1M ); +if (is_kho_boot ()) +memblock_mark_kho_scratch (0 ,SZ_1M );/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and arch/x86/realmode/init.c +3
-1@@ -4,6 +4,7 @@#include <linux/memblock.h> #include <linux/cc_platform.h> #include <linux/pgtable.h> +#include <linux/kexec_handover.h> #include <asm/set_memory.h> #include <asm/realmode.h> @@ -67,7 +68,8 @@ void __init reserve_real_mode(void)*/ memblock_reserve (0 ,SZ_1M ); -memblock_clear_kho_scratch (0 ,SZ_1M ); +if (is_kho_boot ()) +memblock_clear_kho_scratch (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)
Signature · 2 lines
Regards, Pratyush Yadav
PATCH v8 13/17 x86/boot: make sure KASLR does not step over KHO preserved memory
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
During kexec handover (KHO) memory contains data that should be preserved and this data would be consumed by kexec'ed kernel.
To make sure that the preserved memory is not overwritten, KHO uses "scratch regions" to bootstrap kexec'ed kernel. These regions are guaranteed to not have any memory that KHO would preserve and are used as the only memory the kernel sees during the early boot.
The scratch regions are passed in the setup_data by the first kernel with other KHO parameters. If the setup_data contains the KHO parameters, limit randomization to scratch areas only to make sure preserved memory won't get overwritten.
Since all the pointers in setup_data are represented by u64, they require double casting (first to unsigned long and then to the actual pointer type) to compile on 32-bits. This looks goofy out of context, but it is unfortunately the way that this is handled across the tree. There are at least a dozen instances of casting like this.
--- arch/x86/boot/compressed/kaslr.c | 50 +++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/kaslr.c +49 -1
@@ -760,6 +760,49 @@ static void process_e820_entries(unsigned long minimum, } } +/* +* If KHO is active, only process its scratch areas to ensure we are not +* stepping onto preserved memory. +*/ +static bool process_kho_entries (unsigned long minimum,unsigned long image_size) +{ +struct kho_scratch *kho_scratch; +struct setup_data *ptr; +struct kho_data *kho; +int i, nr_areas =0 ; + +if (!IS_ENABLED (CONFIG_KEXEC_HANDOVER )) +return false; + + ptr = (struct setup_data *)(unsigned long )boot_params_ptr->hdr.setup_data; +while (ptr) { +if (ptr->type ==SETUP_KEXEC_KHO ) { + kho = (struct kho_data *)(unsigned long )ptr->data; + kho_scratch = (void *)(unsigned long )kho->scratch_addr; + nr_areas = kho->scratch_size /sizeof (*kho_scratch); +break ; + } + + ptr = (struct setup_data *)(unsigned long )ptr->next; + } + +if (!nr_areas) +return false; + +for (i =0 ; i < nr_areas; i++) { +struct kho_scratch *area = &kho_scratch[i]; +struct mem_vector region = { + .start = area->addr, + .size = area->size, + }; + +if (process_mem_region (®ion, minimum, image_size)) +break ; + } + +return true; +} +static unsigned long find_random_phys_addr (unsigned long minimum,unsigned long image_size) {
@@ -775,7 +818,12 @@ static unsigned long find_random_phys_addr(unsigned long minimum,return 0 ; } -if (!process_efi_entries (minimum, image_size)) +/* +* During kexec handover only process KHO scratch areas that are known +* not to contain any data that must be preserved. +*/ +if (!process_kho_entries (minimum, image_size) && + !process_efi_entries (minimum, image_size))process_e820_entries (minimum, image_size); phys_addr =slots_fetch_random ();
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 14/17 x86/Kconfig: enable kexec handover for 64 bits
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
Add ARCH_SUPPORTS_KEXEC_HANDOVER for 64 bits to allow enabling of KEXEC_HANDOVER configuration option.
--- arch/x86/Kconfig | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/Kconfig +3 -0
@@ -2029,6 +2029,9 @@ config ARCH_SUPPORTS_KEXEC_BZIMAGE_VERIFY_SIG config ARCH_SUPPORTS_KEXEC_JUMP def_bool y +config ARCH_SUPPORTS_KEXEC_HANDOVER + def_bool X86_64 + config ARCH_SUPPORTS_CRASH_DUMP def_bool X86_64 || (X86_32 && HIGHMEM)
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 15/17 memblock: add KHO support for reserve_mem
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
Linux has recently gained support for "reserve_mem": A mechanism to allocate a region of memory early enough in boot that we can cross our fingers and hope it stays at the same location during most boots, so we can store for example ftrace buffers into it.
Thanks to KASLR, we can never be really sure that "reserve_mem" allocations are static across kexec. Let's teach it KHO awareness so that it serializes its reservations on kexec exit and deserializes them again on boot, preserving the exact same mapping across kexec.
This is an example user for KHO in the KHO patch set to ensure we have at least one (not very controversial) user in the tree before extending KHO's use to more subsystems.
--- mm/memblock.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+)
mm/memblock.c +193 -0
@@ -18,6 +18,11 @@#include <linux/memblock.h> #include <linux/mutex.h> +#ifdef CONFIG_KEXEC_HANDOVER +#include <linux/libfdt.h> +#include <linux/kexec_handover.h> +#endif /* CONFIG_KEXEC_HANDOVER */ +#include <asm/sections.h> #include <linux/io.h>
@@ -2475,6 +2480,189 @@ int reserve_mem_release_by_name(const char *name)return 1 ; } +#ifdef CONFIG_KEXEC_HANDOVER +#define MEMBLOCK_KHO_FDT "memblock" +#define MEMBLOCK_KHO_NODE_COMPATIBLE "memblock-v1" +#define RESERVE_MEM_KHO_NODE_COMPATIBLE "reserve-mem-v1" +static struct page *kho_fdt; + +static int reserve_mem_kho_finalize (struct kho_serialization *ser) +{ +int err =0 , i; + +for (i =0 ; i < reserved_mem_count; i++) { +struct reserve_mem_table *map = &reserved_mem_table[i]; + + err |=kho_preserve_phys (map->start, map->size); + } + + err |=kho_preserve_folio (page_folio (kho_fdt)); + err |=kho_add_subtree (ser,MEMBLOCK_KHO_FDT ,page_to_virt (kho_fdt)); + +return notifier_from_errno (err); +} + +static int reserve_mem_kho_notifier (struct notifier_block *self, +unsigned long cmd,void *v) +{ +switch (cmd) { +case KEXEC_KHO_FINALIZE : +return reserve_mem_kho_finalize ((struct kho_serialization *)v); +case KEXEC_KHO_ABORT : +return NOTIFY_DONE ; +default : +return NOTIFY_BAD ; + } +} + +static struct notifier_block reserve_mem_kho_nb = { + .notifier_call = reserve_mem_kho_notifier, +}; + +static int __init prepare_kho_fdt (void ) +{ +int err =0 , i; +void *fdt; + + kho_fdt =alloc_page (GFP_KERNEL ); +if (!kho_fdt) +return -ENOMEM ; + + fdt =page_to_virt (kho_fdt); + + err |=fdt_create (fdt,PAGE_SIZE ); + err |=fdt_finish_reservemap (fdt); + + err |=fdt_begin_node (fdt,"" ); + err |=fdt_property_string (fdt,"compatible" ,MEMBLOCK_KHO_NODE_COMPATIBLE ); +for (i =0 ; i < reserved_mem_count; i++) { +struct reserve_mem_table *map = &reserved_mem_table[i]; + + err |=fdt_begin_node (fdt, map->name); + err |=fdt_property_string (fdt,"compatible" ,RESERVE_MEM_KHO_NODE_COMPATIBLE ); + err |=fdt_property (fdt,"start" , &map->start,sizeof (map->start)); + err |=fdt_property (fdt,"size" , &map->size,sizeof (map->size)); + err |=fdt_end_node (fdt); + } + err |=fdt_end_node (fdt); + + err |=fdt_finish (fdt); + +if (err) { +pr_err ("failed to prepare memblock FDT for KHO: %d\n" , err); +put_page (kho_fdt); + kho_fdt =NULL ; + } + +return err; +} + +static int __init reserve_mem_init (void ) +{ +int err; + +if (!kho_is_enabled () || !reserved_mem_count) +return 0 ; + + err =prepare_kho_fdt (); +if (err) +return err; + + err =register_kho_notifier (&reserve_mem_kho_nb); +if (err) { +put_page (kho_fdt); + kho_fdt =NULL ; + } + +return err; +} +late_initcall (reserve_mem_init); + +static void *__init reserve_mem_kho_retrieve_fdt (void ) +{ +phys_addr_t fdt_phys; +static void *fdt; +int err; + +if (fdt) +return fdt; + + err =kho_retrieve_subtree (MEMBLOCK_KHO_FDT , &fdt_phys); +if (err) { +if (err != -ENOENT ) +pr_warn ("failed to retrieve FDT '%s' from KHO: %d\n" , +MEMBLOCK_KHO_FDT , err); +return NULL ; + } + + fdt =phys_to_virt (fdt_phys); + + err =fdt_node_check_compatible (fdt,0 ,MEMBLOCK_KHO_NODE_COMPATIBLE ); +if (err) { +pr_warn ("FDT '%s' is incompatible with '%s': %d\n" , +MEMBLOCK_KHO_FDT ,MEMBLOCK_KHO_NODE_COMPATIBLE , err); + fdt =NULL ; + } + +return fdt; +} + +static bool __init reserve_mem_kho_revive (const char *name,phys_addr_t size, +phys_addr_t align) +{ +int err, len_start, len_size, offset; +const phys_addr_t *p_start, *p_size; +const void *fdt; + + fdt =reserve_mem_kho_retrieve_fdt (); +if (!fdt) +return false; + + offset =fdt_subnode_offset (fdt,0 , name); +if (offset <0 ) { +pr_warn ("FDT '%s' has no child '%s': %d\n" , +MEMBLOCK_KHO_FDT , name, offset); +return false; + } + err =fdt_node_check_compatible (fdt, offset,RESERVE_MEM_KHO_NODE_COMPATIBLE ); +if (err) { +pr_warn ("Node '%s' is incompatible with '%s': %d\n" , + name,RESERVE_MEM_KHO_NODE_COMPATIBLE , err); +return false; + } + + p_start =fdt_getprop (fdt, offset,"start" , &len_start); + p_size =fdt_getprop (fdt, offset,"size" , &len_size); +if (!p_start || len_start !=sizeof (*p_start) || !p_size || + len_size !=sizeof (*p_size)) { +return false; + } + +if (*p_start & (align -1 )) { +pr_warn ("KHO reserve-mem '%s' has wrong alignment (0x%lx, 0x%lx)\n" , + name, (long )align, (long )*p_start); +return false; + } + +if (*p_size != size) { +pr_warn ("KHO reserve-mem '%s' has wrong size (0x%lx != 0x%lx)\n" , + name, (long )*p_size, (long )size); +return false; + } + +reserved_mem_add (*p_start, size, name); +pr_info ("Revived memory reservation '%s' from KHO\n" , name); + +return true; +} +#else +static bool __init reserve_mem_kho_revive (const char *name,phys_addr_t size, +phys_addr_t align) +{ +return false; +} +#endif /* CONFIG_KEXEC_HANDOVER */ +/* * Parse reserve_mem=nn:align:name */
@@ -2530,6 +2718,11 @@ static int __init reserve_mem(char *p)if (reserve_mem_find_by_name (name, &start, &tmp))return -EBUSY ; +/* Pick previous allocations up from KHO if available */ +if (reserve_mem_kho_revive (name, size, align)) +return 1 ; + +/* TODO: Allocation must be outside of scratch region */ start =memblock_phys_alloc (size, align);if (!start)return -ENOMEM ;
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 16/17 Documentation: add documentation for KHO
In reply to Changyuan LyuFrom: Alexander Graf <[email protected]>
With KHO in place, let's add documentation that describes what it is and how to use it.
--- .../admin-guide/kernel-parameters.txt | 25 ++++ Documentation/admin-guide/mm/index.rst | 1 + Documentation/admin-guide/mm/kho.rst | 115 ++++++++++++++++++ Documentation/core-api/index.rst | 1 + Documentation/core-api/kho/bindings/kho.yaml | 43 +++++++ .../core-api/kho/bindings/sub-fdt.yaml | 27 ++++ Documentation/core-api/kho/concepts.rst | 74 +++++++++++ Documentation/core-api/kho/fdt.rst | 80 ++++++++++++ Documentation/core-api/kho/index.rst | 13 ++ MAINTAINERS | 2 + 10 files changed, 381 insertions(+) create mode 100644 Documentation/admin-guide/mm/kho.rst create mode 100644 Documentation/core-api/kho/bindings/kho.yaml create mode 100644 Documentation/core-api/kho/bindings/sub-fdt.yaml create mode 100644 Documentation/core-api/kho/concepts.rst create mode 100644 Documentation/core-api/kho/fdt.rst create mode 100644 Documentation/core-api/kho/index.rst
Documentation/admin-guide/kernel-parameters.txt +25 -0
@@ -2725,6 +2725,31 @@ kgdbwait [KGDB,EARLY] Stop kernel execution and enter the kernel debugger at the earliest opportunity. + kho= [KEXEC,EARLY] + Format: { "0" | "1" | "off" | "on" | "y" | "n" } + Enables or disables Kexec HandOver. + "0" | "off" | "n" - kexec handover is disabled + "1" | "on" | "y" - kexec handover is enabled + + kho_scratch= [KEXEC,EARLY] + Format: ll[KMG],mm[KMG],nn[KMG] | nn% + Defines the size of the KHO scratch region. The KHO + scratch regions are physically contiguous memory + ranges that can only be used for non-kernel + allocations. That way, even when memory is heavily + fragmented with handed over memory, the kexeced + kernel will always have enough contiguous ranges to + bootstrap itself. + + It is possible to specify the exact amount of + memory in the form of "ll[KMG],mm[KMG],nn[KMG]" + where the first parameter defines the size of a low + memory scratch area, the second parameter defines + the size of a global scratch area and the third + parameter defines the size of additional per-node + scratch areas. The form "nn%" defines scale factor + (in percents) of memory that was used during boot. + kmac= [MIPS] Korina ethernet MAC address. Configure the RouterBoard 532 series on-chip Ethernet adapter MAC address.
Documentation/admin-guide/mm/index.rst +1 -0
@@ -42,3 +42,4 @@ the Linux memory management. transhuge userfaultfd zswap + kho
Documentation/admin-guide/mm/kho.rst new file +115 -0
115 lines not on this page · raw message
Documentation/core-api/index.rst +1 -0
@@ -115,6 +115,7 @@ more memory-management documentation in Documentation/mm/index.rst. pin_user_pages boot-time-mm gfp_mask-from-fs-io + kho/index Interfaces for kernel debugging ===============================
Documentation/core-api/kho/bindings/kho.yaml new file +43 -0
43 lines not on this page · raw message
Documentation/core-api/kho/bindings/sub-fdt.yaml new file +27 -0
@@ -0,0 +1,27 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +title: KHO users' FDT address + +maintainers: + - Mike Rapoport <[email protected]> + - Changyuan Lyu <[email protected]> + +description: | + Physical address of an FDT blob registered by a KHO user. + +properties: + fdt: + description: | + physical address (u64) of an FDT blob. + +required: + - fdt + +additionalProperties: false + +examples: + - | + memblock { + fdt = <0x80cc16 0x1000000>; + };
Documentation/core-api/kho/concepts.rst new file +74 -0
74 lines not on this page · raw message
Documentation/core-api/kho/fdt.rst new file +80 -0
80 lines not on this page · raw message
Documentation/core-api/kho/index.rst new file +13 -0
@@ -0,0 +1,13 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +======================== +Kexec Handover Subsystem +======================== + +.. toctree:: + :maxdepth: 1 + + concepts + fdt + +.. only:: subproject and html
MAINTAINERS +2 -0
@@ -13144,6 +13144,8 @@ M: Mike Rapoport <[email protected]> M: Changyuan Lyu <[email protected]> L: [email protected] S: Maintained +F: Documentation/admin-guide/mm/kho.rst +F: Documentation/core-api/kho/* F: include/linux/kexec_handover.h F: kernel/kexec_handover.c
Signature · 1 line
2.49.0.1015.ga840276032-goog
PATCH v8 17/17 Documentation: KHO: Add memblock bindings
In reply to Changyuan LyuFrom: "Mike Rapoport (Microsoft)" <[email protected]>
We introduced KHO into Linux: A framework that allows Linux to pass metadata and memory across kexec from Linux to Linux. KHO reuses fdt as file format and shares a lot of the same properties of firmware-to- Linux boot formats: It needs a stable, documented ABI that allows for forward and backward compatibility as well as versioning.
As first user of KHO, we introduced memblock which can now preserve memory ranges reserved with reserve_mem command line options contents across kexec, so you can use the post-kexec kernel to read traces from the pre-kexec kernel.
This patch adds memblock schemas similar to "device" device tree ones to a new kho bindings directory. This allows us to force contributors to document the data that moves across KHO kexecs and catch breaking change during review.
--- .../kho/bindings/memblock/memblock.yaml | 39 ++++++++++++++++++ .../kho/bindings/memblock/reserve-mem.yaml | 40 +++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 80 insertions(+) create mode 100644 Documentation/core-api/kho/bindings/memblock/memblock.yaml create mode 100644 Documentation/core-api/kho/bindings/memblock/reserve-mem.yaml
Documentation/core-api/kho/bindings/memblock/memblock.yaml new file +39 -0
@@ -0,0 +1,39 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +title: Memblock reserved memory + +maintainers: + - Mike Rapoport <[email protected]> + +description: | + Memblock can serialize its current memory reservations created with + reserve_mem command line option across kexec through KHO. + The post-KHO kernel can then consume these reservations and they are + guaranteed to have the same physical address. + +properties: + compatible: + enum: + - reserve-mem-v1 + +patternProperties: + "$[0-9a-f_]+^": + $ref: reserve-mem.yaml# + description: reserved memory regions + +required: + - compatible + +additionalProperties: false + +examples: + - | + memblock { + compatible = "memblock-v1"; + n1 { + compatible = "reserve-mem-v1"; + start = <0xc06b 0x4000000>; + size = <0x04 0x00>; + }; + };
Documentation/core-api/kho/bindings/memblock/reserve-mem.yaml new file +40 -0
@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +title: Memblock reserved memory regions + +maintainers: + - Mike Rapoport <[email protected]> + +description: | + Memblock can serialize its current memory reservations created with + reserve_mem command line option across kexec through KHO. + This object describes each such region. + +properties: + compatible: + enum: + - reserve-mem-v1 + + start: + description: | + physical address (u64) of the reserved memory region. + + size: + description: | + size (u64) of the reserved memory region. + +required: + - compatible + - start + - size + +additionalProperties: false + +examples: + - | + n1 { + compatible = "reserve-mem-v1"; + start = <0xc06b 0x4000000>; + size = <0x04 0x00>; + };
MAINTAINERS +1 -0
@@ -15447,6 +15447,7 @@ M: Mike Rapoport <[email protected]> L: [email protected] S: Maintained F: Documentation/core-api/boot-time-mm.rst +F: Documentation/core-api/kho/bindings/memblock/* F: include/linux/memblock.h F: mm/memblock.c F: mm/mm_init.c
Signature · 1 line
2.49.0.1015.ga840276032-goog
Re: [PATCH v8 17/17] Documentation: KHO: Add memblock bindings
Quoted 39 lines · Changyuan Lyu
From: "Mike Rapoport (Microsoft)" <[email protected]>
We introduced KHO into Linux: A framework that allows Linux to pass metadata and memory across kexec from Linux to Linux. KHO reuses fdt as file format and shares a lot of the same properties of firmware-to- Linux boot formats: It needs a stable, documented ABI that allows for forward and backward compatibility as well as versioning.
As first user of KHO, we introduced memblock which can now preserve memory ranges reserved with
reserve_memcommand line options contents across kexec, so you can use the post-kexec kernel to read traces from the pre-kexec kernel.This patch adds memblock schemas similar to "device" device tree ones to a new kho bindings directory. This allows us to force contributors to document the data that moves across KHO kexecs and catch breaking change during review.
Co-developed-by Alexander Graf <[email protected]>Signed-off-by Alexander Graf <[email protected]>Signed-off-by Mike Rapoport (Microsoft) <[email protected]>Signed-off-by Changyuan Lyu <[email protected]>--- .../kho/bindings/memblock/memblock.yaml | 39 ++++++++++++++++++ .../kho/bindings/memblock/reserve-mem.yaml | 40 +++++++++++++++++++ MAINTAINERS | 1 + 3 files changed, 80 insertions(+) create mode 100644 Documentation/core-api/kho/bindings/memblock/memblock.yaml create mode 100644 Documentation/core-api/kho/bindings/memblock/reserve-mem.yamlDocumentation/core-api/kho/bindings/memblock/memblock.yaml new file +3
-0@@ -0,0 +1,39 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +---
Documentation/core-api/kho/bindings/memblock/memblock.yaml line 13
Quoted 10 lines
Documentation/core-api/kho/bindings/memblock/memblock.yaml new file +10
-0+title: Memblock reserved memory + +maintainers: + - Mike Rapoport <[email protected]> + +description: | + Memblock can serialize its current memory reservations created with + reserve_mem command line option across kexec through KHO. + The post-KHO kernel can then consume these reservations and they are + guaranteed to have the same physical address.
Hi Changyuan, Mike,
I am sorry I am late to this patchset. I am working on a patchset to use KHO to pass reserved memory regions to a driver after kexec and I have a few questions.
Documentation/core-api/kho/bindings/memblock/memblock.yaml line 18
Quoted 5 lines
Documentation/core-api/kho/bindings/memblock/memblock.yaml new file +5
-0+ +properties: + compatible: + enum: + - reserve-mem-v1
Shouldn't this be "memblock-v1". IIUC, the compatible "reserve-mem-v1" is to be used for the memblock reserved memory regions, not the memblock node.
Documentation/core-api/kho/bindings/memblock/memblock.yaml line 21
Quoted 3 lines
Documentation/core-api/kho/bindings/memblock/memblock.yaml new file +3
-0+ +patternProperties: + "$[0-9a-f_]+^":
Shouldn't this be "^[0-9a-f_]+$": ^ at the start of the pattern and $ at the end of it? Or is this a KHO-specific rule?
Also, IIUC, this means that names of the nodes are hexadecimal numbers whereas the example below has a "membloc" name. I assume this does not refer to the subnode named "n1" as this does not follow the pattern either Moreover, it should have been documented in the reserve-mem binding.
Quoted 8 lines
Documentation/core-api/kho/bindings/memblock/memblock.yaml new file +8
-0+ $ref: reserve-mem.yaml# + description: reserved memory regions + +required: + - compatible + +additionalProperties: false +
Documentation/core-api/kho/bindings/memblock/memblock.yaml line 39
Quoted 10 lines
Documentation/core-api/kho/bindings/memblock/memblock.yaml new file +10
-0+examples: + - | + memblock { + compatible = "memblock-v1"; + n1 { + compatible = "reserve-mem-v1"; + start = <0xc06b 0x4000000>; + size = <0x04 0x00>; + }; + };
Thanks and BR,
Ricardo