kho: rename "scratch" to "bootmem"
Subsystems (12)
Pratyush Yadav
maintainerv3 cover kho: rename "scratch" to "bootmem"
From: "Pratyush Yadav (Google)" <[email protected]>
The term "KHO scratch" is vague and overloaded. It does not accurately describe what the memory is for. This was discussed previously at [0]. The conclusion was to rename "KHO scratch" to "KHO bootmem", since this is memory passed by the previous kernel for early boot allocations.
In addition, memblock does not care about the provenance of the memory. It cares more about how it should use it. Use MEMBLOCK_KHO_NOPRSRV, instead of MEMBLOCK_KHO_SCRATCH, to describe this memory to memblock.
This series does the renames. It also gets rid of a redundant Kconfig.
While the diffstat is big and scary, most of the changes are mechanical. The most interesting functional change is in patch 4.
This series touches a lot of files across a lot of trees. But since all of that is purely KHO-related code, I would like to collect ACKs from the maintainers and take it via the liveupdate tree.
Ideally we should queue it in liveupdate/next early in the v7.4 cycle since it will cause a lot of conflicts with other patches throughout the KHO tree.
[0] https://lore.kernel.org/kexec/[email protected]/T/#u
Changes in v3:
- Fixup some typos and update some leftover comments still referring to "scratch".
- Update early_init_dt_check_kho() to use bootmem instead of scratch.
Changes in v2:
- Rebase on latest liveupdate/next.
Pratyush Yadav (Google) (4):
memblock: get rid of CONFIG_MEMBLOCK_KHO_SCRATCH
memblock: rename KHO_SCRATCH to KHO_NOPRSRV
kho: rename KHO scratch to KHO bootmem
kho: rename kho_scratch= commandline parameter to kho_bootmem=
.../admin-guide/kernel-parameters.txt | 15 +- Documentation/admin-guide/mm/kho.rst | 18 +- Documentation/core-api/kho/index.rst | 36 +- arch/x86/boot/compressed/kaslr.c | 12 +- arch/x86/include/uapi/asm/setup_data.h | 4 +- arch/x86/kernel/e820.c | 11 +- arch/x86/kernel/kexec-bzimage64.c | 6 +- arch/x86/kernel/setup.c | 2 +- arch/x86/realmode/init.c | 2 +- drivers/firmware/efi/efi-init.c | 6 +- drivers/of/fdt.c | 8 +- drivers/of/kexec.c | 16 +- include/asm-generic/kexec_handover.h | 2 +- include/linux/kexec.h | 2 +- include/linux/kexec_handover.h | 16 +- include/linux/memblock.h | 30 +- kernel/kexec_file.c | 4 +- kernel/liveupdate/Kconfig | 1 - kernel/liveupdate/kexec_handover.c | 340 +++++++++--------- kernel/liveupdate/kexec_handover_debugfs.c | 24 +- kernel/liveupdate/kexec_handover_internal.h | 4 +- mm/Kconfig | 4 - mm/memblock.c | 56 +-- mm/memfd_luo.c | 3 +- mm/mm_init.c | 6 +- tools/testing/memblock/internal.h | 2 +- 26 files changed, 313 insertions(+), 317 deletions(-)
base-commit: db3db4c33a1cf89a201ad1a11c63f503b248ee32
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Pratyush Yadav
maintainerPATCH v3 1/4 memblock: get rid of CONFIG_MEMBLOCK_KHO_SCRATCH
From: "Pratyush Yadav (Google)" <[email protected]>
This config is only a proxy for CONFIG_KEXEC_HANDOVER. It is only enabled by KHO. No point in the indirection. Use CONFIG_KEXEC_HANDOVER directly.
--- include/linux/memblock.h | 2 +- kernel/liveupdate/Kconfig | 1 - mm/Kconfig | 4 ---- mm/memblock.c | 4 ++-- 4 files changed, 3 insertions(+), 8 deletions(-)
include/linux/memblock.h +1 -1
@@ -614,7 +614,7 @@ 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 +#ifdef CONFIG_KEXEC_HANDOVER void memblock_set_kho_scratch_only (void );void memblock_clear_kho_scratch_only (void );#else
kernel/liveupdate/Kconfig +0 -1
@@ -5,7 +5,6 @@ menu "Live Update and Kexec HandOver" config KEXEC_HANDOVER bool "kexec handover" depends on ARCH_SUPPORTS_KEXEC_HANDOVER && ARCH_SUPPORTS_KEXEC_FILE - select MEMBLOCK_KHO_SCRATCH select KEXEC_FILE select LIBFDT select CMA
mm/Kconfig +0 -4
@@ -483,10 +483,6 @@ 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 +2 -2
@@ -113,7 +113,7 @@ unsigned long min_low_pfn;unsigned long max_pfn;unsigned long long max_possible_pfn; -#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH +#ifdef CONFIG_KEXEC_HANDOVER /* When set to true, only allocate from MEMBLOCK_KHO_SCRATCH ranges */ static bool kho_scratch_only;#else
@@ -2596,7 +2596,7 @@ int reserve_mem_release_by_name(const char *name)return 1 ; } -#ifdef CONFIG_MEMBLOCK_KHO_SCRATCH +#ifdef CONFIG_KEXEC_HANDOVER __init void memblock_set_kho_scratch_only (void ) { kho_scratch_only = true;
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Pratyush Yadav
maintainerPATCH v3 2/4 memblock: rename KHO_SCRATCH to KHO_NOPRSRV
In reply to Pratyush YadavFrom: "Pratyush Yadav (Google)" <[email protected]>
The term "KHO scratch" is vague. It does not accurately describe what the memory is for. Generally, scratch is for things that don't contain anything useful. This is not true.
For memblock, KHO_SCRATCH is the _only_ useful memory during a KHO boot. It is memory passed by the previous kernel that is guaranteed to have no preserved pages, and so is the only thing safe to allocate from early in boot.
In addition, KHO now has the ability to discover other "scratch" areas. These aren't directly passed by the previous kernel. Instead, they are found by searching the KHO preserved memory map.
Memblock does not care about the difference between the two. From memblock's perspective, both are memory areas with no preservations and so they are safe to allocate from before KHO fully initializes.
Rename MEMBLOCK_KHO_SCRATCH to MEMBLOCK_KHO_NOPRSRV. This name clearly shows what the memory is for from memblock's perspective. Update memblock functions and comments that refer to scratch to use noprsrv.
There are no functional changes apart from the flag name change in debugfs.
--- arch/x86/kernel/e820.c | 11 ++++---- arch/x86/realmode/init.c | 2 +- drivers/firmware/efi/efi-init.c | 2 +- include/linux/memblock.h | 28 +++++++++---------- kernel/liveupdate/kexec_handover.c | 8 +++--- mm/memblock.c | 44 +++++++++++++++--------------- 6 files changed, 47 insertions(+), 48 deletions(-)
arch/x86/kernel/e820.c +5 -6
@@ -1352,18 +1352,17 @@ __init void e820__memblock_setup(void)* 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 +* KHO kernels are special and use only NOPRSRV memory for memblock * allocations, but memory below 1M is ignored by kernel after early -* boot and cannot be naturally marked as scratch. +* boot and cannot be naturally marked as NOPRSRV. * * 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. +* below 1M as NOPRSRV. * -* After real mode trampoline is allocated, we clear that scratch -* marking. +* After real mode trampoline is allocated, we clear that marking. */ -memblock_mark_kho_scratch (0 ,SZ_1M ); +memblock_mark_kho_noprsrv (0 ,SZ_1M );/* * 32-bit systems are limited to 4BG of memory even with HIGHMEM and
arch/x86/realmode/init.c +1 -1
@@ -66,7 +66,7 @@ void __init reserve_real_mode(void)*/ memblock_reserve (0 ,SZ_1M ); -memblock_clear_kho_scratch (0 ,SZ_1M ); +memblock_clear_kho_noprsrv (0 ,SZ_1M ); }static void __init sme_sev_setup_real_mode (struct trampoline_header *th)
drivers/firmware/efi/efi-init.c +1 -1
@@ -178,7 +178,7 @@ static __init void reserve_regions(void)/* Remove all non-KHO regions */ for_each_mem_region (r) { -if (!memblock_is_kho_scratch (r)) { +if (!memblock_is_kho_noprsrv (r)) {memblock_remove (r->base, r->size); r--; }
include/linux/memblock.h +14 -14
@@ -46,11 +46,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. +* @MEMBLOCK_KHO_NOPRSRV: memory region with no preservation from kexec +* handover. During early boot, we do not know about all memory preservations +* yet, so we get memory with no preservations from the previous kernel that we +* know is good to use. It is the only memory that allocations may happen from +* in this phase. * @MEMBLOCK_RSRV_HUGETLB: memory is reserved for hugetlb pages */ enum memblock_flags {
@@ -61,7 +61,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 */ +MEMBLOCK_KHO_NOPRSRV =0x40 ,/* memory with no KHO preservations */ MEMBLOCK_RSRV_HUGETLB = 0x80, /* memory reserved for hugetlb pages */ };
@@ -158,8 +158,8 @@ 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_reserved_mark_kern (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); +int memblock_mark_kho_noprsrv (phys_addr_t base,phys_addr_t size); +int memblock_clear_kho_noprsrv (phys_addr_t base,phys_addr_t size);void memblock_free (void *ptr,size_t size);void reset_all_zones_managed_pages (void );
@@ -301,9 +301,9 @@ 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) +static inline bool memblock_is_kho_noprsrv (struct memblock_region *m) { -return m->flags &MEMBLOCK_KHO_SCRATCH ; +return m->flags &MEMBLOCK_KHO_NOPRSRV ; } int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn,
@@ -615,11 +615,11 @@ static inline void memtest_report_meminfo(struct seq_file *m) { }#endif #ifdef CONFIG_KEXEC_HANDOVER -void memblock_set_kho_scratch_only (void ); -void memblock_clear_kho_scratch_only (void ); +void memblock_set_kho_noprsrv_only (void ); +void memblock_clear_kho_noprsrv_only (void );#else -static inline void memblock_set_kho_scratch_only (void ) { } -static inline void memblock_clear_kho_scratch_only (void ) { } +static inline void memblock_set_kho_noprsrv_only (void ) { } +static inline void memblock_clear_kho_noprsrv_only (void ) { }#endif #endif /* _LINUX_MEMBLOCK_H */
kernel/liveupdate/kexec_handover.c +4 -4
@@ -958,7 +958,7 @@ static int __init kho_ext_mark_scratch(unsigned long key, void *data)int err;if (start > *prev_end) { - err =memblock_mark_kho_scratch (*prev_end, start - *prev_end); + err =memblock_mark_kho_noprsrv (*prev_end, start - *prev_end);if (err)return err; }
@@ -1031,7 +1031,7 @@ static void __init kho_extend_scratch(void)/* Mark everything from last busy block to end of DRAM. */ if (prev_end <memblock_end_of_DRAM ()) - err =memblock_mark_kho_scratch (prev_end,memblock_end_of_DRAM () - prev_end); + err =memblock_mark_kho_noprsrv (prev_end,memblock_end_of_DRAM () - prev_end);/* fallthrough */ out:
@@ -2002,7 +2002,7 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,u64 size = area->size;memblock_add (area->addr, size); - err =memblock_mark_kho_scratch (area->addr, size); + err =memblock_mark_kho_noprsrv (area->addr, size);if (err) {pr_warn ("failed to mark the scratch region 0x%pa+0x%pa: %pe" , &area->addr, &size,ERR_PTR (err));
@@ -2020,7 +2020,7 @@ void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,* we initialize the page tables which we will need to ingest all * memory reservations from the previous kernel. */ -memblock_set_kho_scratch_only (); +memblock_set_kho_noprsrv_only (); kho_in.fdt_phys = fdt_phys; kho_in.scratch_phys = scratch_phys;
mm/memblock.c +22 -22
118 lines not on this page · raw message
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Pratyush Yadav
maintainerPATCH v3 3/4 kho: rename KHO scratch to KHO bootmem
In reply to Pratyush YadavFrom: "Pratyush Yadav (Google)" <[email protected]>
The term "KHO scratch" is vague and overloaded.
For one, it does not accurately describe what the memory is for. From KHO's perspective, it is memory passed by the previous kernel that is guaranteed to have no allocations and hence it is safe to allocate from.
For another, the term is overloaded. KHO also knows to discover other ranges of memory that don't have any preservations and are safe to allocate from. This is done by kho_extend_scratch(). These areas, while called "scratch", are completely different from the chunk of memory passed by the previous kernel for early boot allocations.
Rename "KHO scratch" to "KHO boot memory", or "KHO bootmem" in short. Update all function names, variable names, comments, and documentation to use this.
Call the discovered areas "noprsrv", matching what memblock would see them as. Rename kho_extend_scratch() to reflect this.
This patch largely has no functional changes. The only functional changes are renames of debugfs files from "scratch_phys" and "scratch_len" to "bootmem_phys" and "bootmem_len" respectively.
---
Note that while all the documentation and internal naming around the kho_scratch= parameter have changed, the parameter name stays the same. This is to avoid functional changes (outside debugfs) in this big commit. The name will be changed in the next patch.
--- .../admin-guide/kernel-parameters.txt | 13 +- Documentation/admin-guide/mm/kho.rst | 16 +- Documentation/core-api/kho/index.rst | 36 +- arch/x86/boot/compressed/kaslr.c | 12 +- arch/x86/include/uapi/asm/setup_data.h | 4 +- arch/x86/kernel/kexec-bzimage64.c | 6 +- arch/x86/kernel/setup.c | 2 +- drivers/firmware/efi/efi-init.c | 4 +- drivers/of/fdt.c | 8 +- drivers/of/kexec.c | 16 +- include/asm-generic/kexec_handover.h | 2 +- include/linux/kexec.h | 2 +- include/linux/kexec_handover.h | 16 +- kernel/kexec_file.c | 4 +- kernel/liveupdate/kexec_handover.c | 328 +++++++++--------- kernel/liveupdate/kexec_handover_debugfs.c | 24 +- kernel/liveupdate/kexec_handover_internal.h | 4 +- mm/memblock.c | 8 +- mm/memfd_luo.c | 3 +- mm/mm_init.c | 6 +- tools/testing/memblock/internal.h | 2 +- 21 files changed, 259 insertions(+), 257 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +7 -6
@@ -3033,9 +3033,10 @@ Kernel parameters 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 + + Defines the size of the KHO boot memory region. The + KHO boot memory 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
@@ -3044,10 +3045,10 @@ Kernel parameters 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 + memory bootmem area, the second parameter defines + the size of a global bootmem area and the third parameter defines the size of additional per-node - scratch areas. The form "nn%" defines scale factor + bootmem areas. The form "nn%" defines scale factor (in percents) of memory that was used during boot. kmac= [MIPS] Korina ethernet MAC address.
Documentation/admin-guide/mm/kho.rst +8 -8
@@ -21,9 +21,9 @@ kexec. To use KHO, please boot the kernel with the ``kho=on`` command line parameter. You may use ``kho_scratch`` parameter to define size of the -scratch regions. For example ``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. +boot memory regions. For example ``kho_scratch=16M,512M,256M`` will reserve a +16 MiB low memory bootmem area, a 512 MiB global bootmem region, and 256 MiB +per NUMA node bootmem regions on boot. Perform a KHO kexec ===================
@@ -96,15 +96,15 @@ stabilized. current KHO state in this file. Kexec user space tooling can use this as input file for the KHO payload image. -``/sys/kernel/debug/kho/out/scratch_len`` - Lengths of KHO scratch regions, which are physically contiguous +``/sys/kernel/debug/kho/out/bootmem_len`` + Lengths of KHO bootmem regions, which are physically contiguous memory regions that will always stay available for future kexec allocations. Kexec user space tools can use this file to determine where it should place its payload images. -``/sys/kernel/debug/kho/out/scratch_phys`` - Physical locations of KHO scratch regions. Kexec user space tools - can use this file in conjunction to scratch_len to determine where +``/sys/kernel/debug/kho/out/bootmem_phys`` + Physical locations of KHO bootmem regions. Kexec user space tools + can use this file in conjunction to bootmem_len to determine where it should place its payload images. ``/sys/kernel/debug/kho/out/sub_fdts/``
Documentation/core-api/kho/index.rst +18 -18
@@ -13,8 +13,8 @@ Kexec HandOver (KHO) is a mechanism that allows Linux to preserve memory regions, which could contain serialized system states, across kexec. KHO uses :ref:`flattened device tree (FDT) <kho_fdt>` to pass information about -the preserved state from pre-exec kernel to post-kexec kernel and :ref:`scratch -memory regions <kho_scratch>` to ensure integrity of the preserved memory. +the preserved state from pre-exec kernel to post-kexec kernel and :ref:`boot +memory regions <kho_bootmem>` to ensure integrity of the preserved memory. .. _kho_fdt:
@@ -40,31 +40,31 @@ and post-kexec kernels. This ABI is defined by header files in abi.rst -.. _kho_scratch: +.. _kho_bootmem: -Scratch Regions -=============== +Boot Memory Regions +=================== To boot into kexec, we need to have a physically contiguous memory range that contains no handed over memory. Kexec then places the target kernel and initrd into that region. The new kernel exclusively uses this region for memory allocations before during boot up to the initialization of the page allocator. -We guarantee that we always have such regions through the scratch regions: On -first boot KHO allocates several physically contiguous memory regions. Since +We guarantee that we always have such regions through the boot memory regions: +On first boot KHO allocates several physically contiguous memory regions. Since after kexec these regions will be used by early memory allocations, there is a -scratch region per NUMA node plus a scratch region to satisfy allocations -requests that do not require particular NUMA node assignment. -By default, size of the scratch region is calculated based on amount of memory -allocated during boot. The ``kho_scratch`` kernel command line option may be -used to explicitly define size of the scratch regions. -The scratch regions are declared as CMA when page allocator is initialized so -that their memory can be used during system lifetime. CMA gives us the -guarantee that no handover pages land in that region, because handover pages -must be at a static physical memory location and CMA enforces that only -movable pages can be located inside. +boot memory region per NUMA node plus a boot memory region to satisfy +allocations requests that do not require particular NUMA node assignment. By +default, size of the boot memory region is calculated based on amount of memory +allocated during boot. The ``kho_bootmem`` kernel command line option may be +used to explicitly define size of the boot memory regions. The boot memory +regions are declared as CMA when page allocator is initialized so that their +memory can be used during system lifetime. CMA gives us the guarantee that no +handover pages land in that region, because handover pages must be at a static +physical memory location and CMA enforces that only movable pages can be located +inside. -After KHO kexec, we ignore the ``kho_scratch`` kernel command line option and +After KHO kexec, we ignore the ``kho_bootmem`` kernel command line option and instead reuse the exact same region that was originally allocated. This allows us to recursively execute any amount of KHO kexecs. Because we used this region for boot memory allocations and as target memory for kexec blobs, some parts
arch/x86/boot/compressed/kaslr.c +6 -6
@@ -764,12 +764,12 @@ static void process_e820_entries(unsigned long minimum, }/* -* If KHO is active, only process its scratch areas to ensure we are not +* If KHO is active, only process its bootmem 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 kho_bootmem *kho_bootmem;struct setup_data *ptr;struct kho_data *kho;int i, nr_areas =0 ;
@@ -781,8 +781,8 @@ static bool process_kho_entries(unsigned long minimum, unsigned long image_size)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); + kho_bootmem = (void *)(unsigned long )kho->bootmem_addr; + nr_areas = kho->bootmem_size /sizeof (*kho_bootmem);break ; }
@@ -793,7 +793,7 @@ static bool process_kho_entries(unsigned long minimum, unsigned long image_size)return false;for (i =0 ; i < nr_areas; i++) { -struct kho_scratch *area = &kho_scratch[i]; +struct kho_bootmem *area = &kho_bootmem[i];struct mem_vector region = { .start = area->addr, .size = area->size,
@@ -822,7 +822,7 @@ static unsigned long find_random_phys_addr(unsigned long minimum, }/* -* During kexec handover only process KHO scratch areas that are known +* During kexec handover only process KHO bootmem areas that are known * not to contain any data that must be preserved. */ if (!process_kho_entries(minimum, image_size) &&
arch/x86/include/uapi/asm/setup_data.h +2 -2
@@ -85,8 +85,8 @@ struct ima_setup_data {struct kho_data {__u64 fdt_addr;__u64 fdt_size; -__u64 scratch_addr; -__u64 scratch_size; +__u64 bootmem_addr; +__u64 bootmem_size; } __attribute__((packed));#endif /* __ASSEMBLER__ */
arch/x86/kernel/kexec-bzimage64.c +3 -3
@@ -285,14 +285,14 @@ static void setup_kho(const struct kimage *image, struct boot_params *params, sd->len =sizeof (struct kho_data );/* Only add if we have all KHO images in place */ -if (!image->kho.fdt || !image->kho.scratch) +if (!image->kho.fdt || !image->kho.bootmem)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; + kho->bootmem_addr = image->kho.bootmem->mem; + kho->bootmem_size = image->kho.bootmem->bufsz; sd->next = params->hdr.setup_data; params->hdr.setup_data = params_load_addr + setup_data_offset; }
arch/x86/kernel/setup.c +1 -1
@@ -472,7 +472,7 @@ static void __init add_kho(u64 phys_addr, u32 data_len)return ; } -kho_populate (kho->fdt_addr, kho->fdt_size, kho->scratch_addr, kho->scratch_size); +kho_populate (kho->fdt_addr, kho->fdt_size, kho->bootmem_addr, kho->bootmem_size);early_memunmap (kho, size); }
drivers/firmware/efi/efi-init.c +2 -2
@@ -165,10 +165,10 @@ static __init void reserve_regions(void)pr_info ("Processing EFI memory map:\n" );/* -* Discard memblocks discovered so far except for KHO scratch +* Discard memblocks discovered so far except for KHO bootmem * regions. Most memblocks at this point originate from memory nodes * in the DT and UEFI uses its own memory map instead. However, if -* KHO is enabled, scratch regions, which are good known memory +* KHO is enabled, bootmem regions, which are good known memory * must be preserved. */ memblock_dump_all ();
drivers/of/fdt.c +4 -4
@@ -929,7 +929,7 @@ void __init early_init_dt_check_for_usable_mem_range(void)static void __init early_init_dt_check_kho (void ) {unsigned long node = chosen_node_offset; -u64 fdt_start, fdt_size, scratch_start, scratch_size; +u64 fdt_start, fdt_size, bootmem_start, bootmem_size;if (!IS_ENABLED (CONFIG_KEXEC_HANDOVER ) || (long )node <0 )return ;
@@ -938,11 +938,11 @@ static void __init early_init_dt_check_kho(void) &fdt_start, &fdt_size))return ; -if (!of_flat_dt_get_addr_size (node,"linux,kho-scratch" , - &scratch_start, &scratch_size)) +if (!of_flat_dt_get_addr_size (node,"linux,kho-bootmem" , + &bootmem_start, &bootmem_size))return ; -kho_populate (fdt_start, fdt_size, scratch_start, scratch_size); +kho_populate (fdt_start, fdt_size, bootmem_start, bootmem_size); }#ifdef CONFIG_SERIAL_EARLYCON
drivers/of/kexec.c +8 -8
@@ -261,23 +261,23 @@ static int kho_add_chosen(const struct kimage *image, void *fdt, int chosen_node#ifdef CONFIG_KEXEC_HANDOVER phys_addr_t fdt_mem =0 ;phys_addr_t fdt_len =0 ; -phys_addr_t scratch_mem =0 ; -phys_addr_t scratch_len =0 ; +phys_addr_t bootmem_arr =0 ; +phys_addr_t bootmem_len =0 ; ret =fdt_delprop (fdt, chosen_node,"linux,kho-fdt" );if (ret && ret != -FDT_ERR_NOTFOUND )return ret; - ret =fdt_delprop (fdt, chosen_node,"linux,kho-scratch" ); + ret =fdt_delprop (fdt, chosen_node,"linux,kho-bootmem" );if (ret && ret != -FDT_ERR_NOTFOUND )return ret; -if (!image->kho.fdt || !image->kho.scratch) +if (!image->kho.fdt || !image->kho.bootmem)return 0 ; fdt_mem = image->kho.fdt; fdt_len =PAGE_SIZE ; - scratch_mem = image->kho.scratch->mem; - scratch_len = image->kho.scratch->bufsz; + bootmem_arr = image->kho.bootmem->mem; + bootmem_len = image->kho.bootmem->bufsz;pr_debug ("Adding kho metadata to DT" );
@@ -285,8 +285,8 @@ static int kho_add_chosen(const struct kimage *image, void *fdt, int chosen_node fdt_mem, fdt_len);if (ret)return ret; - ret =fdt_appendprop_addrrange (fdt,0 , chosen_node,"linux,kho-scratch" , - scratch_mem, scratch_len); + ret =fdt_appendprop_addrrange (fdt,0 , chosen_node,"linux,kho-bootmem" , + bootmem_arr, bootmem_len);#endif /* CONFIG_KEXEC_HANDOVER */ return ret;
include/asm-generic/kexec_handover.h +1 -1
@@ -4,7 +4,7 @@#include <linux/types.h> -struct kho_scratch { +struct kho_bootmem {phys_addr_t addr;phys_addr_t size; };
include/linux/kexec.h +1 -1
@@ -403,7 +403,7 @@ struct kimage {#endif struct { -struct kexec_segment *scratch; +struct kexec_segment *bootmem;phys_addr_t fdt; } kho;
include/linux/kexec_handover.h +8 -8
@@ -36,15 +36,15 @@ int kho_retrieve_subtree(const char *name, phys_addr_t *phys, size_t *size);void kho_memory_init (void );void kho_memory_init_early (void ); -void kho_populate (phys_addr_t fdt_phys,u64 fdt_len,phys_addr_t scratch_phys, -u64 scratch_len); +void kho_populate (phys_addr_t fdt_phys,u64 fdt_len,phys_addr_t bootmem_phys, +u64 bootmem_len); -bool kho_scratch_overlap (phys_addr_t phys,size_t size); +bool kho_bootmem_overlap (phys_addr_t phys,size_t size); -static inline enum migratetype kho_scratch_migratetype (unsigned long pfn, +static inline enum migratetype kho_bootmem_migratetype (unsigned long pfn,enum migratetype mt) { -if (kho_scratch_overlap (PFN_PHYS (pfn), pageblock_nr_pages <<PAGE_SHIFT )) +if (kho_bootmem_overlap (PFN_PHYS (pfn), pageblock_nr_pages <<PAGE_SHIFT ))return MIGRATE_CMA ;return mt; }
@@ -123,16 +123,16 @@ static inline void kho_memory_init(void) { }static inline void kho_memory_init_early (void ) { }static inline void kho_populate (phys_addr_t fdt_phys,u64 fdt_len, -phys_addr_t scratch_phys,u64 scratch_len) +phys_addr_t bootmem_phys,u64 bootmem_len) { } -static inline bool kho_scratch_overlap (phys_addr_t phys,size_t size) +static inline bool kho_bootmem_overlap (phys_addr_t phys,size_t size) {return false; } -static inline enum migratetype kho_scratch_migratetype (unsigned long pfn, +static inline enum migratetype kho_bootmem_migratetype (unsigned long pfn,enum migratetype mt) {return mt;
kernel/kexec_file.c +2 -2
@@ -742,8 +742,8 @@ int kexec_locate_mem_hole(struct kexec_buf *kbuf)return 0 ;/* -* If KHO is active, only use KHO scratch memory. All other memory -* could potentially be handed over. +* If KHO is active, only use KHO bootmem. All other memory could +* potentially be handed over. */ ret =kho_locate_mem_hole (kbuf, locate_mem_hole_callback);if (ret <=0 )
kernel/liveupdate/kexec_handover.c +165 -163
695 lines not on this page · raw message
kernel/liveupdate/kexec_handover_debugfs.c +12 -12
@@ -77,23 +77,23 @@ void kho_debugfs_blob_remove(struct kho_debugfs *dbg, void *blob) } } -static int scratch_phys_show (struct seq_file *m,void *v) +static int bootmem_phys_show (struct seq_file *m,void *v) { -for (int i =0 ; i < kho_scratch_cnt; i++) -seq_printf (m,"0x%llx\n" , kho_scratch[i].addr); +for (int i =0 ; i < kho_bootmem_cnt; i++) +seq_printf (m,"0x%llx\n" , kho_bootmem[i].addr);return 0 ; } -DEFINE_SHOW_ATTRIBUTE (scratch_phys); +DEFINE_SHOW_ATTRIBUTE (bootmem_phys); -static int scratch_len_show (struct seq_file *m,void *v) +static int bootmem_len_show (struct seq_file *m,void *v) { -for (int i =0 ; i < kho_scratch_cnt; i++) -seq_printf (m,"0x%llx\n" , kho_scratch[i].size); +for (int i =0 ; i < kho_bootmem_cnt; i++) +seq_printf (m,"0x%llx\n" , kho_bootmem[i].size);return 0 ; } -DEFINE_SHOW_ATTRIBUTE (scratch_len); +DEFINE_SHOW_ATTRIBUTE (bootmem_len);__init void kho_in_debugfs_init (struct kho_debugfs *dbg,const void *fdt) {
@@ -186,13 +186,13 @@ __init int kho_out_debugfs_init(struct kho_debugfs *dbg)if (IS_ERR (sub_fdt_dir)) goto err_rmdir; - f =debugfs_create_file ("scratch_phys" ,0400 , dir,NULL , - &scratch_phys_fops); + f =debugfs_create_file ("bootmem_phys" ,0400 , dir,NULL , + &bootmem_phys_fops);if (IS_ERR (f)) goto err_rmdir; - f =debugfs_create_file ("scratch_len" ,0400 , dir,NULL , - &scratch_len_fops); + f =debugfs_create_file ("bootmem_len" ,0400 , dir,NULL , + &bootmem_len_fops);if (IS_ERR (f)) goto err_rmdir;
kernel/liveupdate/kexec_handover_internal.h +2 -2
@@ -19,8 +19,8 @@ struct kho_debugfs {struct kho_debugfs {};#endif -extern struct kho_scratch *kho_scratch; -extern unsigned int kho_scratch_cnt; +extern struct kho_bootmem *kho_bootmem; +extern unsigned int kho_bootmem_cnt;#ifdef CONFIG_KEXEC_HANDOVER_DEBUGFS int kho_debugfs_init (void );
mm/memblock.c +4 -4
@@ -1794,7 +1794,7 @@ void * __init memblock_alloc_hugetlb(phys_addr_t size, int nid, bool exact_nid)if (numa_valid_node (nid) && !exact_nid) { nid =NUMA_NO_NODE ;/* -* If a previous candidate overlapped with KHO scratch, it would +* If a previous candidate overlapped with KHO bootmem, it would * update start or end. Now that the search is opening to all * nodes, reset them. */
@@ -1810,12 +1810,12 @@ void * __init memblock_alloc_hugetlb(phys_addr_t size, int nid, bool exact_nid) found:/* * HugeTLB pages can be preserved with KHO and no preserved memory can -* be in scratch. So retry if found address overlaps with scratch. +* be in bootmem. So retry if found address overlaps with bootmem. * -* Scratch areas are normally not very large, so this shouldn't take too +* Bootmem areas are normally not very large, so this shouldn't take too * many retries. */ -if (kho_scratch_overlap (addr, size)) { +if (kho_bootmem_overlap (addr, size)) {if (memblock_bottom_up ()) start = addr + size;else
mm/memfd_luo.c +1 -2
@@ -121,8 +121,7 @@ static int memfd_luo_preserve_folios(struct file *file,/* * Pin the folios so they don't move around behind our back. This also * ensures none of the folios are in CMA -- which ensures they don't -* fall in KHO scratch memory. It also moves swapped out folios back to -* memory. +* fall in KHO bootmem. It also moves swapped out folios back to memory. * * A side effect of doing this is that it allocates a folio for all * indices in the file. This might waste memory on sparse memfds. If
mm/mm_init.c +3 -3
@@ -684,7 +684,7 @@ static __meminit void pageblock_migratetype_init_range(unsigned long pfn,const unsigned long end = pfn + nr_pages;for (pfn =pageblock_align (pfn); pfn < end; pfn += pageblock_nr_pages) { -enum migratetype mt =kho_scratch_migratetype (pfn, migratetype); +enum migratetype mt =kho_bootmem_migratetype (pfn, migratetype);init_pageblock_migratetype (pfn_to_page (pfn), mt, false);if (!atomic &&IS_ALIGNED (pfn,PAGES_PER_SECTION ))
@@ -767,7 +767,7 @@ static void __meminit __init_deferred_page(unsigned long pfn, int nid)if (pageblock_aligned (pfn)) {enum migratetype mt = -kho_scratch_migratetype (pfn,MIGRATE_MOVABLE ); +kho_bootmem_migratetype (pfn,MIGRATE_MOVABLE );init_pageblock_migratetype (pfn_to_page (pfn), mt, false); } }
@@ -903,7 +903,7 @@ void __meminit memmap_init_range(unsigned long size, int nid, unsigned long zone* over the place during system boot. */ if (pageblock_aligned (pfn)) { -enum migratetype mt =kho_scratch_migratetype (pfn, migratetype); +enum migratetype mt =kho_bootmem_migratetype (pfn, migratetype);init_pageblock_migratetype (page, mt, isolate_pageblock);cond_resched ();
tools/testing/memblock/internal.h +1 -1
@@ -46,7 +46,7 @@ static inline bool __is_kernel(unsigned long addr)#define __SetPageReserved (p) ((void)(p)) -static inline bool kho_scratch_overlap (phys_addr_t phys,size_t size) +static inline bool kho_bootmem_overlap (phys_addr_t phys,size_t size) {return false; }
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Pratyush Yadav
maintainerPATCH v3 4/4 kho: rename kho_scratch= commandline parameter to kho_bootmem=
In reply to Pratyush YadavFrom: "Pratyush Yadav (Google)" <[email protected]>
KHO now no longer uses "scratch" to describe the memory areas passed by previous kernel. Instead, it calls them boot memory, or bootmem in short. Rename the kho_scratch= commandline parameter to reflect this terminology change.
--- Documentation/admin-guide/kernel-parameters.txt | 2 +- Documentation/admin-guide/mm/kho.rst | 4 ++-- kernel/liveupdate/kexec_handover.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +1 -1
@@ -3031,7 +3031,7 @@ Kernel parameters "0" | "off" | "n" - kexec handover is disabled "1" | "on" | "y" - kexec handover is enabled - kho_scratch= [KEXEC,EARLY] + kho_bootmem= [KEXEC,EARLY] Format: ll[KMG],mm[KMG],nn[KMG] | nn% Defines the size of the KHO boot memory region. The
Documentation/admin-guide/mm/kho.rst +2 -2
@@ -20,8 +20,8 @@ need to enable if you would like to preserve their respective state across kexec. To use KHO, please boot the kernel with the ``kho=on`` command line -parameter. You may use ``kho_scratch`` parameter to define size of the -boot memory regions. For example ``kho_scratch=16M,512M,256M`` will reserve a +parameter. You may use ``kho_bootmem`` parameter to define size of the +boot memory regions. For example ``kho_bootmem=16M,512M,256M`` will reserve a 16 MiB low memory bootmem area, a 512 MiB global bootmem region, and 256 MiB per NUMA node bootmem regions on boot.
kernel/liveupdate/kexec_handover.c +3 -3
@@ -671,12 +671,12 @@ unsigned int kho_bootmem_cnt;* The bootmem areas are scaled by default as percent of memory allocated from * memblock. A user can override the scale with command line parameter: * -* kho_scratch=N% +* kho_bootmem=N% * * It is also possible to explicitly define size for a lowmem, a global and * per-node bootmem areas: * -* kho_scratch=l[KMG],n[KMG],m[KMG] +* kho_bootmem=l[KMG],n[KMG],m[KMG] * * The explicit size definition takes precedence over scale definition. */
@@ -751,7 +751,7 @@ static int __init kho_parse_bootmem_size(char *p)return 0 ; } -early_param ("kho_scratch" , kho_parse_bootmem_size); +early_param ("kho_bootmem" , kho_parse_bootmem_size);static void __init bootmem_size_update (void ) {
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewRe: [PATCH v3 2/4] memblock: rename KHO_SCRATCH to KHO_NOPRSRV
In reply to Pratyush YadavSashiko has reviewed this patch and found no issues. It looks great!
Quoted 19 lines
From: "Pratyush Yadav (Google)" <[email protected]>
The term "KHO scratch" is vague. It does not accurately describe what the memory is for. Generally, scratch is for things that don't contain anything useful. This is not true.
For memblock,
KHO_SCRATCHis the _only_ useful memory during a KHO boot. It is memory passed by the previous kernel that is guaranteed to have no preserved pages, and so is the only thing safe to allocate from early in boot.In addition, KHO now has the ability to discover other "scratch" areas. These aren't directly passed by the previous kernel. Instead, they are found by searching the KHO preserved memory map.
Memblock does not care about the difference between the two. From memblock's perspective, both are memory areas with no preservations and so they are safe to allocate from before KHO fully initializes.
Quoted 8 lines
Rename
MEMBLOCK_KHO_SCRATCHtoMEMBLOCK_KHO_NOPRSRV. This name clearly shows what the memory is for from memblock's perspective. Update memblock functions and comments that refer to scratch to use noprsrv.There are no functional changes apart from the flag name change in debugfs.
Signed-off-by Pratyush Yadav (Google) <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v3 4/4] kho: rename kho_scratch= commandline parameter to kho_bootmem=
In reply to Pratyush YadavSashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
From: "Pratyush Yadav (Google)" <[email protected]>
KHO now no longer uses "scratch" to describe the memory areas passed by previous kernel. Instead, it calls them boot memory, or bootmem in short. Rename the kho_scratch= commandline parameter to reflect this terminology change.
Signed-off-by Pratyush Yadav (Google) <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v3 1/4] memblock: get rid of CONFIG_MEMBLOCK_KHO_SCRATCH
In reply to Pratyush YadavSashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
From: "Pratyush Yadav (Google)" <[email protected]>
This config is only a proxy for
CONFIG_KEXEC_HANDOVER. It is only enabled by KHO. No point in the indirection. UseCONFIG_KEXEC_HANDOVERdirectly.Signed-off-by Pratyush Yadav (Google) <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v3 3/4] kho: rename KHO scratch to KHO bootmem
In reply to Pratyush YadavSashiko has reviewed this patch and found no issues. It looks great!
Quoted 18 lines
From: "Pratyush Yadav (Google)" <[email protected]>
The term "KHO scratch" is vague and overloaded.
For one, it does not accurately describe what the memory is for. From KHO's perspective, it is memory passed by the previous kernel that is guaranteed to have no allocations and hence it is safe to allocate from.
For another, the term is overloaded. KHO also knows to discover other ranges of memory that don't have any preservations and are safe to allocate from. This is done by
kho_extend_scratch(). These areas, while called "scratch", are completely different from the chunk of memory passed by the previous kernel for early boot allocations.Rename "KHO scratch" to "KHO boot memory", or "KHO bootmem" in short. Update all function names, variable names, comments, and documentation to use this.
Quoted 8 lines
Call the discovered areas "noprsrv", matching what memblock would see them as. Rename
kho_extend_scratch()to reflect this.This patch largely has no functional changes. The only functional changes are renames of debugfs files from "
scratch_phys" and "scratch_len" to "bootmem_phys" and "bootmem_len" respectively.Signed-off-by Pratyush Yadav (Google) <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Mike Rapoport
maintainerQuoted 10 lines · Pratyush Yadav
kho: rename "scratch" to "bootmem"
From: "Pratyush Yadav (Google)" <[email protected]>
The term "KHO scratch" is vague and overloaded. It does not accurately describe what the memory is for. This was discussed previously at [0]. The conclusion was to rename "KHO scratch" to "KHO bootmem", since this is memory passed by the previous kernel for early boot allocations.
[...]
Applied to kho-bootmem branch of liveupdate/linux.git tree, thanks!
[1/4] memblock: get rid of CONFIG_MEMBLOCK_KHO_SCRATCH
commit: 5e309f53050f33faf74f55332f359099d7346464
[2/4] memblock: rename KHO_SCRATCH to KHO_NOPRSRV
commit: 05a84ceadf7024be320e2ba82fe709db4a4180bd
[3/4] kho: rename KHO scratch to KHO bootmem
commit: 85d3615cea17968788aa6581fd242e34d8953e58
[4/4] kho: rename kho_scratch= commandline parameter to kho_bootmem=
commit: 8fe64603a47506c3b357002460c3a9c0d8d4d321tree: https://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux
branch: kho-bootmem
--
Sincerely yours,
Mike.