arch/s390/kernel/ftrace.c
Source file repositories/reference/linux-study-clean/arch/s390/kernel/ftrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/s390/kernel/ftrace.c- Extension
.c- Size
- 9386 bytes
- Lines
- 337
- Domain
- Architecture Layer
- Bucket
- arch/s390
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/hardirq.hlinux/uaccess.hlinux/ftrace.hlinux/kernel.hlinux/types.hlinux/kmsan-checks.hlinux/cpufeature.hlinux/kprobes.hlinux/execmem.htrace/syscall.hasm/asm-offsets.hasm/text-patching.hasm/cacheflush.hasm/ftrace.lds.hasm/nospec-branch.hasm/set_memory.hentry.hftrace.h
Detected Declarations
struct ftrace_insnfunction ftrace_need_init_nopfunction ftrace_init_nopfunction ftrace_generate_branch_insnfunction ftrace_patch_branch_insnfunction ftrace_modify_trampoline_callfunction ftrace_modify_callfunction ftrace_patch_branch_maskfunction ftrace_make_nopfunction ftrace_make_trampoline_callfunction ftrace_make_callfunction ftrace_update_ftrace_funcfunction arch_ftrace_update_codefunction ftrace_arch_code_modify_post_processfunction ftrace_graph_funcfunction kprobe_ftrace_handlerfunction arch_prepare_kprobe_ftrace
Annotated Snippet
struct ftrace_insn {
u16 opc;
s32 disp;
} __packed;
static const char *ftrace_shared_hotpatch_trampoline(const char **end)
{
const char *tstart, *tend;
tstart = ftrace_shared_hotpatch_trampoline_br;
tend = ftrace_shared_hotpatch_trampoline_br_end;
#ifdef CONFIG_EXPOLINE
if (!nospec_disable) {
tstart = ftrace_shared_hotpatch_trampoline_exrl;
tend = ftrace_shared_hotpatch_trampoline_exrl_end;
}
#endif /* CONFIG_EXPOLINE */
if (end)
*end = tend;
return tstart;
}
bool ftrace_need_init_nop(void)
{
return !cpu_has_seq_insn();
}
int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec)
{
static struct ftrace_hotpatch_trampoline *next_vmlinux_trampoline =
__ftrace_hotpatch_trampolines_start;
static const struct ftrace_insn orig = { .opc = 0xc004, .disp = 0 };
static struct ftrace_hotpatch_trampoline *trampoline;
struct ftrace_hotpatch_trampoline **next_trampoline;
struct ftrace_hotpatch_trampoline *trampolines_end;
struct ftrace_hotpatch_trampoline tmp;
struct ftrace_insn *insn;
struct ftrace_insn old;
const char *shared;
s32 disp;
BUILD_BUG_ON(sizeof(struct ftrace_hotpatch_trampoline) !=
SIZEOF_FTRACE_HOTPATCH_TRAMPOLINE);
next_trampoline = &next_vmlinux_trampoline;
trampolines_end = __ftrace_hotpatch_trampolines_end;
shared = ftrace_shared_hotpatch_trampoline(NULL);
#ifdef CONFIG_MODULES
if (mod) {
next_trampoline = &mod->arch.next_trampoline;
trampolines_end = mod->arch.trampolines_end;
}
#endif
if (WARN_ON_ONCE(*next_trampoline >= trampolines_end))
return -ENOMEM;
trampoline = (*next_trampoline)++;
if (copy_from_kernel_nofault(&old, (void *)rec->ip, sizeof(old)))
return -EFAULT;
/* Check for the compiler-generated fentry nop (brcl 0, .). */
if (WARN_ON_ONCE(memcmp(&orig, &old, sizeof(old))))
return -EINVAL;
/* Generate the trampoline. */
tmp.brasl_opc = 0xc015; /* brasl %r1, shared */
tmp.brasl_disp = (shared - (const char *)&trampoline->brasl_opc) / 2;
tmp.interceptor = FTRACE_ADDR;
tmp.rest_of_intercepted_function = rec->ip + sizeof(struct ftrace_insn);
s390_kernel_write(trampoline, &tmp, sizeof(tmp));
/* Generate a jump to the trampoline. */
disp = ((char *)trampoline - (char *)rec->ip) / 2;
insn = (struct ftrace_insn *)rec->ip;
s390_kernel_write(&insn->disp, &disp, sizeof(disp));
return 0;
}
static struct ftrace_hotpatch_trampoline *ftrace_get_trampoline(struct dyn_ftrace *rec)
{
struct ftrace_hotpatch_trampoline *trampoline;
struct ftrace_insn insn;
s64 disp;
u16 opc;
if (copy_from_kernel_nofault(&insn, (void *)rec->ip, sizeof(insn)))
return ERR_PTR(-EFAULT);
disp = (s64)insn.disp * 2;
trampoline = (void *)(rec->ip + disp);
Annotation
- Immediate include surface: `linux/hardirq.h`, `linux/uaccess.h`, `linux/ftrace.h`, `linux/kernel.h`, `linux/types.h`, `linux/kmsan-checks.h`, `linux/cpufeature.h`, `linux/kprobes.h`.
- Detected declarations: `struct ftrace_insn`, `function ftrace_need_init_nop`, `function ftrace_init_nop`, `function ftrace_generate_branch_insn`, `function ftrace_patch_branch_insn`, `function ftrace_modify_trampoline_call`, `function ftrace_modify_call`, `function ftrace_patch_branch_mask`, `function ftrace_make_nop`, `function ftrace_make_trampoline_call`.
- Atlas domain: Architecture Layer / arch/s390.
- 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.