arch/arm64/kernel/patching.c
Source file repositories/reference/linux-study-clean/arch/arm64/kernel/patching.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kernel/patching.c- Extension
.c- Size
- 5397 bytes
- Lines
- 239
- Domain
- Architecture Layer
- Bucket
- arch/arm64
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/kernel.hlinux/mm.hlinux/smp.hlinux/spinlock.hlinux/stop_machine.hlinux/uaccess.hasm/cacheflush.hasm/fixmap.hasm/insn.hasm/kprobes.hasm/text-patching.hasm/sections.h
Detected Declarations
struct aarch64_insn_patchfunction is_exit_textfunction is_image_textfunction patch_unmapfunction aarch64_insn_readfunction __aarch64_insn_writefunction aarch64_insn_writefunction aarch64_insn_write_literal_u64function text_poke_memcpyfunction text_poke_memsetfunction aarch64_insn_patch_text_nosyncfunction aarch64_insn_patch_text_cbfunction aarch64_insn_patch_text
Annotated Snippet
struct aarch64_insn_patch {
void **text_addrs;
u32 *new_insns;
int insn_cnt;
atomic_t cpu_count;
};
static int __kprobes aarch64_insn_patch_text_cb(void *arg)
{
int i, ret = 0;
struct aarch64_insn_patch *pp = arg;
/* The last CPU becomes master */
if (atomic_inc_return(&pp->cpu_count) == num_online_cpus()) {
for (i = 0; ret == 0 && i < pp->insn_cnt; i++)
ret = aarch64_insn_patch_text_nosync(pp->text_addrs[i],
pp->new_insns[i]);
/* Notify other processors with an additional increment. */
atomic_inc(&pp->cpu_count);
} else {
while (atomic_read(&pp->cpu_count) <= num_online_cpus())
cpu_relax();
isb();
}
return ret;
}
int __kprobes aarch64_insn_patch_text(void *addrs[], u32 insns[], int cnt)
{
struct aarch64_insn_patch patch = {
.text_addrs = addrs,
.new_insns = insns,
.insn_cnt = cnt,
.cpu_count = ATOMIC_INIT(0),
};
if (cnt <= 0)
return -EINVAL;
return stop_machine_cpuslocked(aarch64_insn_patch_text_cb, &patch,
cpu_online_mask);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/mm.h`, `linux/smp.h`, `linux/spinlock.h`, `linux/stop_machine.h`, `linux/uaccess.h`, `asm/cacheflush.h`, `asm/fixmap.h`.
- Detected declarations: `struct aarch64_insn_patch`, `function is_exit_text`, `function is_image_text`, `function patch_unmap`, `function aarch64_insn_read`, `function __aarch64_insn_write`, `function aarch64_insn_write`, `function aarch64_insn_write_literal_u64`, `function text_poke_memcpy`, `function text_poke_memset`.
- Atlas domain: Architecture Layer / arch/arm64.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.