kernel/liveupdate/kho_block.c
Source file repositories/reference/linux-study-clean/kernel/liveupdate/kho_block.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/liveupdate/kho_block.c- Extension
.c- Size
- 10786 bytes
- Lines
- 417
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/io.hlinux/kexec_handover.hlinux/kho/abi/block.hlinux/kho_block.hlinux/slab.h
Detected Declarations
function Copyrightfunction kho_block_free_serfunction kho_block_addfunction kho_block_set_grow_onefunction kho_block_set_shrink_onefunction kho_block_set_growfunction kho_block_set_shrinkfunction kho_block_set_is_cyclicfunction kho_block_set_restorefunction kho_block_set_destroyfunction list_for_each_entry_safefunction kho_block_set_clearfunction list_for_each_entryfunction kho_block_set_it_init
Annotated Snippet
if (count++ >= KHO_MAX_BLOCKS) {
pr_err("Block set is corrupted\n");
return true;
}
if (!fast->next)
break;
fast = phys_to_virt(fast->next);
if (!fast->next)
break;
fast = phys_to_virt(fast->next);
slow = phys_to_virt(slow->next);
if (slow == fast) {
pr_err("Block set is corrupted\n");
return true;
}
}
return false;
}
/**
* kho_block_set_restore - Restore a block set from a physical address.
* @bs: The block set to restore.
* @head_pa: Physical address of the first block header.
*
* Restores a serialized block set from a given physical address. The caller is
* responsible for ensuring that the block set @bs has been allocated and
* initialized prior to calling this function.
*
* Return: 0 on success, or a negative errno on failure.
*/
int kho_block_set_restore(struct kho_block_set *bs, u64 head_pa)
{
struct kho_block_header_ser *ser;
u64 next_pa = head_pa;
int err;
/* Restored block sets use size from the previous kernel */
bs->incoming = true;
if (!head_pa)
return 0;
bs->head_pa = head_pa;
if (kho_block_set_is_cyclic(bs)) {
bs->head_pa = 0;
return -EINVAL;
}
while (next_pa) {
ser = phys_to_virt(next_pa);
if (!ser->count || ser->count > bs->count_per_block) {
pr_warn("Block contains invalid entry count: %llu\n",
ser->count);
err = -EINVAL;
goto err_destroy;
}
err = kho_block_add(bs, ser);
if (err)
goto err_destroy;
next_pa = ser->next;
}
return 0;
err_destroy:
kho_block_set_destroy(bs);
/* Free the remaining un-restored blocks in the physical chain */
while (next_pa) {
struct kho_block_header_ser *next_ser = phys_to_virt(next_pa);
next_pa = next_ser->next;
kho_block_free_ser(bs, next_ser);
}
return err;
}
/**
* kho_block_set_destroy - Destroy all blocks in a block set.
* @bs: The block set.
*/
void kho_block_set_destroy(struct kho_block_set *bs)
{
struct kho_block *block, *tmp;
list_for_each_entry_safe(block, tmp, &bs->blocks, list) {
Annotation
- Immediate include surface: `linux/io.h`, `linux/kexec_handover.h`, `linux/kho/abi/block.h`, `linux/kho_block.h`, `linux/slab.h`.
- Detected declarations: `function Copyright`, `function kho_block_free_ser`, `function kho_block_add`, `function kho_block_set_grow_one`, `function kho_block_set_shrink_one`, `function kho_block_set_grow`, `function kho_block_set_shrink`, `function kho_block_set_is_cyclic`, `function kho_block_set_restore`, `function kho_block_set_destroy`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.