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: remove global preserved_mem_map and store state in FDT

Currently, the serialized memory map is tracked via
kho_out.preserved_mem_map and copied to the FDT during finalization. This
double tracking is redundant.

Remove preserved_mem_map from kho_out. Instead, maintain the physical
address of the head chunk directly in the preserved-memory-map FDT
property.

Introduce kho_update_memory_map() to manage this property. This function
handles:
1. Retrieving and freeing any existing serialized map (handling the
abort/retry case).
2. Updating the FDT property with the new chunk address.

This establishes the FDT as the single source of truth for the handover
state.

Link: https://lkml.kernel.org/r/20251114190002.3311679-9-pasha.tatashin@soleen.com
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Cc: Alexander Graf <graf@amazon.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Baoquan He <bhe@redhat.com>
Cc: Coiby Xu <coxu@redhat.com>
Cc: Dave Vasilevsky <dave@vasilevsky.ca>
Cc: Eric Biggers <ebiggers@google.com>
Cc: Kees Cook <kees@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pasha Tatashin and committed by
Andrew Morton
efa3a977 71960fe1

+26 -17
+26 -17
kernel/liveupdate/kexec_handover.c
··· 119 119 struct mutex fdts_lock; 120 120 121 121 struct kho_mem_track track; 122 - /* First chunk of serialized preserved memory map */ 123 - struct khoser_mem_chunk *preserved_mem_map; 124 - 125 122 struct kho_debugfs dbg; 126 123 }; 127 124 ··· 379 382 } 380 383 } 381 384 385 + /* 386 + * Update memory map property, if old one is found discard it via 387 + * kho_mem_ser_free(). 388 + */ 389 + static void kho_update_memory_map(struct khoser_mem_chunk *first_chunk) 390 + { 391 + void *ptr; 392 + u64 phys; 393 + 394 + ptr = fdt_getprop_w(kho_out.fdt, 0, PROP_PRESERVED_MEMORY_MAP, NULL); 395 + 396 + /* Check and discard previous memory map */ 397 + phys = get_unaligned((u64 *)ptr); 398 + if (phys) 399 + kho_mem_ser_free((struct khoser_mem_chunk *)phys_to_virt(phys)); 400 + 401 + /* Update with the new value */ 402 + phys = first_chunk ? (u64)virt_to_phys(first_chunk) : 0; 403 + put_unaligned(phys, (u64 *)ptr); 404 + } 405 + 382 406 static int kho_mem_serialize(struct kho_out *kho_out) 383 407 { 384 408 struct khoser_mem_chunk *first_chunk = NULL; ··· 440 422 } 441 423 } 442 424 443 - kho_out->preserved_mem_map = first_chunk; 425 + kho_update_memory_map(first_chunk); 444 426 445 427 return 0; 446 428 ··· 1241 1223 if (!kho_out.finalized) 1242 1224 return -ENOENT; 1243 1225 1244 - kho_mem_ser_free(kho_out.preserved_mem_map); 1245 - kho_out.preserved_mem_map = NULL; 1226 + kho_update_memory_map(NULL); 1246 1227 kho_out.finalized = false; 1247 1228 1248 1229 return 0; ··· 1251 1234 { 1252 1235 void *root = kho_out.fdt; 1253 1236 struct kho_sub_fdt *fdt; 1254 - u64 *preserved_mem_map; 1237 + u64 empty_mem_map = 0; 1255 1238 int err; 1256 1239 1257 1240 err = fdt_create(root, PAGE_SIZE); 1258 1241 err |= fdt_finish_reservemap(root); 1259 1242 err |= fdt_begin_node(root, ""); 1260 1243 err |= fdt_property_string(root, "compatible", KHO_FDT_COMPATIBLE); 1261 - /** 1262 - * Reserve the preserved-memory-map property in the root FDT, so 1263 - * that all property definitions will precede subnodes created by 1264 - * KHO callers. 1265 - */ 1266 - err |= fdt_property_placeholder(root, PROP_PRESERVED_MEMORY_MAP, 1267 - sizeof(*preserved_mem_map), 1268 - (void **)&preserved_mem_map); 1244 + err |= fdt_property(root, PROP_PRESERVED_MEMORY_MAP, &empty_mem_map, 1245 + sizeof(empty_mem_map)); 1269 1246 if (err) 1270 1247 goto err_exit; 1271 1248 ··· 1281 1270 err = kho_mem_serialize(&kho_out); 1282 1271 if (err) 1283 1272 goto err_exit; 1284 - 1285 - *preserved_mem_map = (u64)virt_to_phys(kho_out.preserved_mem_map); 1286 1273 1287 1274 return 0; 1288 1275