arch/mips/kernel/ftrace.c
Source file repositories/reference/linux-study-clean/arch/mips/kernel/ftrace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/mips/kernel/ftrace.c- Extension
.c- Size
- 11096 bytes
- Lines
- 420
- Domain
- Architecture Layer
- Bucket
- arch/mips
- 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/uaccess.hlinux/init.hlinux/ftrace.hlinux/syscalls.hasm/asm.hasm/asm-offsets.hasm/cacheflush.hasm/syscall.hasm/uasm.hasm/unistd.hasm-generic/sections.h
Detected Declarations
function Copyrightfunction ftrace_dyn_arch_init_insnsfunction ftrace_modify_codefunction ftrace_modify_code_2function ftrace_modify_code_2rfunction ftrace_make_nopfunction ftrace_make_callfunction ftrace_update_ftrace_funcfunction ftrace_dyn_arch_initfunction ftrace_enable_ftrace_graph_callerfunction ftrace_disable_ftrace_graph_callerfunction ftrace_get_parent_ra_addrfunction prepare_ftrace_returnfunction arch_syscall_addrfunction arch_syscall_addr
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Code for replacing ftrace calls with jumps.
*
* Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
* Copyright (C) 2009, 2010 DSLab, Lanzhou University, China
* Author: Wu Zhangjin <wuzhangjin@gmail.com>
*
* Thanks goes to Steven Rostedt for writing the original x86 version.
*/
#include <linux/uaccess.h>
#include <linux/init.h>
#include <linux/ftrace.h>
#include <linux/syscalls.h>
#include <asm/asm.h>
#include <asm/asm-offsets.h>
#include <asm/cacheflush.h>
#include <asm/syscall.h>
#include <asm/uasm.h>
#include <asm/unistd.h>
#include <asm-generic/sections.h>
#if defined(KBUILD_MCOUNT_RA_ADDRESS) && defined(CONFIG_32BIT)
#define MCOUNT_OFFSET_INSNS 5
#else
#define MCOUNT_OFFSET_INSNS 4
#endif
#ifdef CONFIG_DYNAMIC_FTRACE
/* Arch override because MIPS doesn't need to run this from stop_machine() */
void arch_ftrace_update_code(int command)
{
ftrace_modify_all_code(command);
}
#define JAL 0x0c000000 /* jump & link: ip --> ra, jump to target */
#define ADDR_MASK 0x03ffffff /* op_code|addr : 31...26|25 ....0 */
#define JUMP_RANGE_MASK ((1UL << 28) - 1)
#define INSN_NOP 0x00000000 /* nop */
#define INSN_JAL(addr) \
((unsigned int)(JAL | (((addr) >> 2) & ADDR_MASK)))
static unsigned int insn_jal_ftrace_caller __read_mostly;
static unsigned int insn_la_mcount[2] __read_mostly;
static unsigned int insn_j_ftrace_graph_caller __maybe_unused __read_mostly;
static inline void ftrace_dyn_arch_init_insns(void)
{
u32 *buf;
unsigned int v1;
/* If we are not in compat space, the number of generated
* instructions will exceed the maximum expected limit of 2.
* To prevent buffer overflow, we avoid generating them.
* insn_la_mcount will not be used later in ftrace_make_call.
*/
if (uasm_in_compat_space_p(MCOUNT_ADDR)) {
/* la v1, _mcount */
v1 = 3;
buf = (u32 *)&insn_la_mcount[0];
UASM_i_LA(&buf, v1, MCOUNT_ADDR);
} else {
pr_warn("ftrace: mcount address beyond 32 bits is not supported (%lX)\n",
MCOUNT_ADDR);
}
/* jal (ftrace_caller + 8), jump over the first two instruction */
buf = (u32 *)&insn_jal_ftrace_caller;
uasm_i_jal(&buf, (FTRACE_ADDR + 8) & JUMP_RANGE_MASK);
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
/* j ftrace_graph_caller */
buf = (u32 *)&insn_j_ftrace_graph_caller;
uasm_i_j(&buf, (unsigned long)ftrace_graph_caller & JUMP_RANGE_MASK);
#endif
}
static int ftrace_modify_code(unsigned long ip, unsigned int new_code)
{
int faulted;
/* *(unsigned int *)ip = new_code; */
safe_store_code(new_code, ip, faulted);
if (unlikely(faulted))
Annotation
- Immediate include surface: `linux/uaccess.h`, `linux/init.h`, `linux/ftrace.h`, `linux/syscalls.h`, `asm/asm.h`, `asm/asm-offsets.h`, `asm/cacheflush.h`, `asm/syscall.h`.
- Detected declarations: `function Copyright`, `function ftrace_dyn_arch_init_insns`, `function ftrace_modify_code`, `function ftrace_modify_code_2`, `function ftrace_modify_code_2r`, `function ftrace_make_nop`, `function ftrace_make_call`, `function ftrace_update_ftrace_func`, `function ftrace_dyn_arch_init`, `function ftrace_enable_ftrace_graph_caller`.
- Atlas domain: Architecture Layer / arch/mips.
- 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.