arch/x86/mm/mmio-mod.c
Source file repositories/reference/linux-study-clean/arch/x86/mm/mmio-mod.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/mm/mmio-mod.c- Extension
.c- Size
- 11399 bytes
- Lines
- 464
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/moduleparam.hlinux/debugfs.hlinux/slab.hlinux/uaccess.hlinux/io.hlinux/mmiotrace.hlinux/pgtable.hasm/e820/api.hlinux/atomic.hlinux/percpu.hlinux/cpu.hpf_in.h
Detected Declarations
struct trap_reasonstruct remap_tracefunction is_enabledfunction print_ptefunction die_kmmio_nesting_errorfunction prefunction postfunction ioremap_trace_corefunction mmiotrace_ioremapfunction iounmap_trace_corefunction list_for_each_entry_safefunction mmiotrace_iounmapfunction mmiotrace_printkfunction clear_trace_listfunction is_enabledfunction list_for_each_entry_safefunction enter_uniprocessorfunction for_each_cpufunction leave_uniprocessorfunction enter_uniprocessorfunction leave_uniprocessorfunction disable_mmiotraceexport mmiotrace_printk
Annotated Snippet
struct trap_reason {
unsigned long addr;
unsigned long ip;
enum reason_type type;
int active_traces;
};
struct remap_trace {
struct list_head list;
struct kmmio_probe probe;
resource_size_t phys;
unsigned long id;
};
/* Accessed per-cpu. */
static DEFINE_PER_CPU(struct trap_reason, pf_reason);
static DEFINE_PER_CPU(struct mmiotrace_rw, cpu_trace);
static DEFINE_MUTEX(mmiotrace_mutex);
static DEFINE_SPINLOCK(trace_lock);
static atomic_t mmiotrace_enabled;
static LIST_HEAD(trace_list); /* struct remap_trace */
/*
* Locking in this file:
* - mmiotrace_mutex enforces enable/disable_mmiotrace() critical sections.
* - mmiotrace_enabled may be modified only when holding mmiotrace_mutex
* and trace_lock.
* - Routines depending on is_enabled() must take trace_lock.
* - trace_list users must hold trace_lock.
* - is_enabled() guarantees that mmio_trace_{rw,mapping} are allowed.
* - pre/post callbacks assume the effect of is_enabled() being true.
*/
/* module parameters */
static unsigned long filter_offset;
static bool nommiotrace;
static bool trace_pc;
module_param(filter_offset, ulong, 0);
module_param(nommiotrace, bool, 0);
module_param(trace_pc, bool, 0);
MODULE_PARM_DESC(filter_offset, "Start address of traced mappings.");
MODULE_PARM_DESC(nommiotrace, "Disable actual MMIO tracing.");
MODULE_PARM_DESC(trace_pc, "Record address of faulting instructions.");
static bool is_enabled(void)
{
return atomic_read(&mmiotrace_enabled);
}
static void print_pte(unsigned long address)
{
unsigned int level;
pte_t *pte = lookup_address(address, &level);
if (!pte) {
pr_err("Error in %s: no pte for page 0x%08lx\n",
__func__, address);
return;
}
if (level == PG_LEVEL_2M) {
pr_emerg("4MB pages are not currently supported: 0x%08lx\n",
address);
BUG();
}
pr_info("pte for 0x%lx: 0x%llx 0x%llx\n",
address,
(unsigned long long)pte_val(*pte),
(unsigned long long)pte_val(*pte) & _PAGE_PRESENT);
}
/*
* For some reason the pre/post pairs have been called in an
* unmatched order. Report and die.
*/
static void die_kmmio_nesting_error(struct pt_regs *regs, unsigned long addr)
{
const struct trap_reason *my_reason = &get_cpu_var(pf_reason);
pr_emerg("unexpected fault for address: 0x%08lx, last fault for address: 0x%08lx\n",
addr, my_reason->addr);
print_pte(addr);
pr_emerg("faulting IP is at %pS\n", (void *)regs->ip);
pr_emerg("last faulting IP was at %pS\n", (void *)my_reason->ip);
#ifdef __i386__
pr_emerg("eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n",
regs->ax, regs->bx, regs->cx, regs->dx);
pr_emerg("esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n",
Annotation
- Immediate include surface: `linux/moduleparam.h`, `linux/debugfs.h`, `linux/slab.h`, `linux/uaccess.h`, `linux/io.h`, `linux/mmiotrace.h`, `linux/pgtable.h`, `asm/e820/api.h`.
- Detected declarations: `struct trap_reason`, `struct remap_trace`, `function is_enabled`, `function print_pte`, `function die_kmmio_nesting_error`, `function pre`, `function post`, `function ioremap_trace_core`, `function mmiotrace_ioremap`, `function iounmap_trace_core`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration 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.