Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kho: relocate vmalloc preservation structure to KHO ABI header

The `struct kho_vmalloc` defines the in-memory layout for preserving
vmalloc regions across kexec. This layout is a contract between kernels
and part of the KHO ABI.

To reflect this relationship, the related structs and helper macros are
relocated to the ABI header, `include/linux/kho/abi/kexec_handover.h`.
This move places the structure's definition under the protection of the
KHO_FDT_COMPATIBLE version string.

The structure and its components are now also documented within the ABI
header to describe the contract and prevent ABI breaks.

[rppt@kernel.org: update comment, per Pratyush]
Link: https://lkml.kernel.org/r/aW_Mqp6HcqLwQImS@kernel.org
Link: https://lkml.kernel.org/r/20260105165839.285270-6-rppt@kernel.org
Signed-off-by: Jason Miu <jasonmiu@google.com>
Co-developed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Alexander Graf <graf@amazon.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Pratyush Yadav <pratyush@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Jason Miu and committed by
Andrew Morton
ac2d8102 5e1ea1e2

+88 -41
+6
Documentation/core-api/kho/abi.rst
··· 10 10 .. kernel-doc:: include/linux/kho/abi/kexec_handover.h 11 11 :doc: Kexec Handover ABI 12 12 13 + vmalloc preservation ABI 14 + ======================== 15 + 16 + .. kernel-doc:: include/linux/kho/abi/kexec_handover.h 17 + :doc: Kexec Handover ABI for vmalloc Preservation 18 + 13 19 See Also 14 20 ======== 15 21
+2 -25
include/linux/kexec_handover.h
··· 11 11 phys_addr_t size; 12 12 }; 13 13 14 + struct kho_vmalloc; 15 + 14 16 struct folio; 15 17 struct page; 16 - 17 - #define DECLARE_KHOSER_PTR(name, type) \ 18 - union { \ 19 - phys_addr_t phys; \ 20 - type ptr; \ 21 - } name 22 - #define KHOSER_STORE_PTR(dest, val) \ 23 - ({ \ 24 - typeof(val) v = val; \ 25 - typecheck(typeof((dest).ptr), v); \ 26 - (dest).phys = virt_to_phys(v); \ 27 - }) 28 - #define KHOSER_LOAD_PTR(src) \ 29 - ({ \ 30 - typeof(src) s = src; \ 31 - (typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \ 32 - }) 33 - 34 - struct kho_vmalloc_chunk; 35 - struct kho_vmalloc { 36 - DECLARE_KHOSER_PTR(first, struct kho_vmalloc_chunk *); 37 - unsigned int total_pages; 38 - unsigned short flags; 39 - unsigned short order; 40 - }; 41 18 42 19 #ifdef CONFIG_KEXEC_HANDOVER 43 20 bool kho_is_enabled(void);
+78
include/linux/kho/abi/kexec_handover.h
··· 10 10 #ifndef _LINUX_KHO_ABI_KEXEC_HANDOVER_H 11 11 #define _LINUX_KHO_ABI_KEXEC_HANDOVER_H 12 12 13 + #include <linux/types.h> 14 + 13 15 /** 14 16 * DOC: Kexec Handover ABI 15 17 * ··· 83 81 84 82 /* The FDT property for sub-FDTs. */ 85 83 #define KHO_FDT_SUB_TREE_PROP_NAME "fdt" 84 + 85 + /** 86 + * DOC: Kexec Handover ABI for vmalloc Preservation 87 + * 88 + * The Kexec Handover ABI for preserving vmalloc'ed memory is defined by 89 + * a set of structures and helper macros. The layout of these structures is a 90 + * stable contract between kernels and is versioned by the KHO_FDT_COMPATIBLE 91 + * string. 92 + * 93 + * The preservation is managed through a main descriptor &struct kho_vmalloc, 94 + * which points to a linked list of &struct kho_vmalloc_chunk structures. These 95 + * chunks contain the physical addresses of the preserved pages, allowing the 96 + * next kernel to reconstruct the vmalloc area with the same content and layout. 97 + * Helper macros are also defined for storing and loading pointers within 98 + * these structures. 99 + */ 100 + 101 + /* Helper macro to define a union for a serializable pointer. */ 102 + #define DECLARE_KHOSER_PTR(name, type) \ 103 + union { \ 104 + u64 phys; \ 105 + type ptr; \ 106 + } name 107 + 108 + /* Stores the physical address of a serializable pointer. */ 109 + #define KHOSER_STORE_PTR(dest, val) \ 110 + ({ \ 111 + typeof(val) v = val; \ 112 + typecheck(typeof((dest).ptr), v); \ 113 + (dest).phys = virt_to_phys(v); \ 114 + }) 115 + 116 + /* Loads the stored physical address back to a pointer. */ 117 + #define KHOSER_LOAD_PTR(src) \ 118 + ({ \ 119 + typeof(src) s = src; \ 120 + (typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \ 121 + }) 122 + 123 + /* 124 + * This header is embedded at the beginning of each `kho_vmalloc_chunk` 125 + * and contains a pointer to the next chunk in the linked list, 126 + * stored as a physical address for handover. 127 + */ 128 + struct kho_vmalloc_hdr { 129 + DECLARE_KHOSER_PTR(next, struct kho_vmalloc_chunk *); 130 + }; 131 + 132 + #define KHO_VMALLOC_SIZE \ 133 + ((PAGE_SIZE - sizeof(struct kho_vmalloc_hdr)) / \ 134 + sizeof(u64)) 135 + 136 + /* 137 + * Each chunk is a single page and is part of a linked list that describes 138 + * a preserved vmalloc area. It contains the header with the link to the next 139 + * chunk and a zero terminated array of physical addresses of the pages that 140 + * make up the preserved vmalloc area. 141 + */ 142 + struct kho_vmalloc_chunk { 143 + struct kho_vmalloc_hdr hdr; 144 + u64 phys[KHO_VMALLOC_SIZE]; 145 + }; 146 + 147 + static_assert(sizeof(struct kho_vmalloc_chunk) == PAGE_SIZE); 148 + 149 + /* 150 + * Describes a preserved vmalloc memory area, including the 151 + * total number of pages, allocation flags, page order, and a pointer to the 152 + * first chunk of physical page addresses. 153 + */ 154 + struct kho_vmalloc { 155 + DECLARE_KHOSER_PTR(first, struct kho_vmalloc_chunk *); 156 + unsigned int total_pages; 157 + unsigned short flags; 158 + unsigned short order; 159 + }; 86 160 87 161 #endif /* _LINUX_KHO_ABI_KEXEC_HANDOVER_H */
+1 -1
include/linux/kho/abi/memfd.h
··· 12 12 #define _LINUX_KHO_ABI_MEMFD_H 13 13 14 14 #include <linux/types.h> 15 - #include <linux/kexec_handover.h> 15 + #include <linux/kho/abi/kexec_handover.h> 16 16 17 17 /** 18 18 * DOC: memfd Live Update ABI
-15
kernel/liveupdate/kexec_handover.c
··· 876 876 } 877 877 EXPORT_SYMBOL_GPL(kho_unpreserve_pages); 878 878 879 - struct kho_vmalloc_hdr { 880 - DECLARE_KHOSER_PTR(next, struct kho_vmalloc_chunk *); 881 - }; 882 - 883 - #define KHO_VMALLOC_SIZE \ 884 - ((PAGE_SIZE - sizeof(struct kho_vmalloc_hdr)) / \ 885 - sizeof(phys_addr_t)) 886 - 887 - struct kho_vmalloc_chunk { 888 - struct kho_vmalloc_hdr hdr; 889 - phys_addr_t phys[KHO_VMALLOC_SIZE]; 890 - }; 891 - 892 - static_assert(sizeof(struct kho_vmalloc_chunk) == PAGE_SIZE); 893 - 894 879 /* vmalloc flags KHO supports */ 895 880 #define KHO_VMALLOC_SUPPORTED_FLAGS (VM_ALLOC | VM_ALLOW_HUGE_VMAP) 896 881
+1
lib/test_kho.c
··· 19 19 #include <linux/printk.h> 20 20 #include <linux/vmalloc.h> 21 21 #include <linux/kexec_handover.h> 22 + #include <linux/kho/abi/kexec_handover.h> 22 23 23 24 #include <net/checksum.h> 24 25