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: preserve FDT folio only once during initialization

Currently, the FDT folio is preserved inside __kho_finalize(). If the
user performs multiple finalize/abort cycles, kho_preserve_folio() is
called repeatedly for the same FDT folio.

Since the FDT folio is allocated once during kho_init(), it should be
marked for preservation at the same time. Move the preservation call to
kho_init() to align the preservation state with the object's lifecycle and
simplify the finalize path.

Also, pre-zero the FDT tree so we do not expose random bits to the user
and to the next kernel by using the new kho_alloc_preserve() api.

Link: https://lkml.kernel.org/r/20251114190002.3311679-5-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
85de0090 4c205677

+6 -12
+6 -12
kernel/liveupdate/kexec_handover.c
··· 1251 1251 if (err) 1252 1252 goto abort; 1253 1253 1254 - err = kho_preserve_folio(virt_to_folio(kho_out.fdt)); 1255 - if (err) 1256 - goto abort; 1257 - 1258 1254 err = kho_mem_serialize(&kho_out); 1259 1255 if (err) 1260 1256 goto abort; ··· 1380 1384 1381 1385 static __init int kho_init(void) 1382 1386 { 1383 - int err = 0; 1384 1387 const void *fdt = kho_get_fdt(); 1385 - struct page *fdt_page; 1388 + int err = 0; 1386 1389 1387 1390 if (!kho_enable) 1388 1391 return 0; 1389 1392 1390 - fdt_page = alloc_page(GFP_KERNEL); 1391 - if (!fdt_page) { 1392 - err = -ENOMEM; 1393 + kho_out.fdt = kho_alloc_preserve(PAGE_SIZE); 1394 + if (IS_ERR(kho_out.fdt)) { 1395 + err = PTR_ERR(kho_out.fdt); 1393 1396 goto err_free_scratch; 1394 1397 } 1395 - kho_out.fdt = page_to_virt(fdt_page); 1396 1398 1397 1399 err = kho_debugfs_init(); 1398 1400 if (err) ··· 1418 1424 return 0; 1419 1425 1420 1426 err_free_fdt: 1421 - put_page(fdt_page); 1422 - kho_out.fdt = NULL; 1427 + kho_unpreserve_free(kho_out.fdt); 1423 1428 err_free_scratch: 1429 + kho_out.fdt = NULL; 1424 1430 for (int i = 0; i < kho_scratch_cnt; i++) { 1425 1431 void *start = __va(kho_scratch[i].addr); 1426 1432 void *end = start + kho_scratch[i].size;