arch/x86/mm/kmmio.c
Source file repositories/reference/linux-study-clean/arch/x86/mm/kmmio.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/mm/kmmio.c- Extension
.c- Size
- 16944 bytes
- Lines
- 633
- 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/list.hlinux/rculist.hlinux/spinlock.hlinux/hash.hlinux/export.hlinux/kernel.hlinux/uaccess.hlinux/ptrace.hlinux/preempt.hlinux/percpu.hlinux/kdebug.hlinux/mutex.hlinux/io.hlinux/slab.hasm/cacheflush.hasm/tlbflush.hlinux/errno.hasm/debugreg.hlinux/mmiotrace.h
Detected Declarations
struct kmmio_fault_pagestruct kmmio_delayed_releasestruct kmmio_contextfunction Pointfunction clear_pmd_presencefunction clear_pte_presencefunction clear_page_presencefunction addressfunction disarm_kmmio_fault_pagefunction do_page_faultfunction kmmio_handlerfunction add_kmmio_fault_pagefunction release_kmmio_fault_pagefunction register_kmmio_probefunction rcu_free_kmmio_fault_pagesfunction remove_kmmio_fault_pagesfunction unregister_kmmio_probefunction kmmio_die_notifierfunction kmmio_initfunction kmmio_cleanupexport register_kmmio_probeexport unregister_kmmio_probe
Annotated Snippet
struct kmmio_fault_page {
struct list_head list;
struct kmmio_fault_page *release_next;
unsigned long addr; /* the requested address */
pteval_t old_presence; /* page presence prior to arming */
bool armed;
/*
* Number of times this page has been registered as a part
* of a probe. If zero, page is disarmed and this may be freed.
* Used only by writers (RCU) and post_kmmio_handler().
* Protected by kmmio_lock, when linked into kmmio_page_table.
*/
int count;
bool scheduled_for_release;
};
struct kmmio_delayed_release {
struct rcu_head rcu;
struct kmmio_fault_page *release_list;
};
struct kmmio_context {
struct kmmio_fault_page *fpage;
struct kmmio_probe *probe;
unsigned long saved_flags;
unsigned long addr;
int active;
};
/*
* The kmmio_lock is taken in int3 context, which is treated as NMI context.
* This causes lockdep to complain about it bein in both NMI and normal
* context. Hide it from lockdep, as it should not have any other locks
* taken under it, and this is only enabled for debugging mmio anyway.
*/
static arch_spinlock_t kmmio_lock = __ARCH_SPIN_LOCK_UNLOCKED;
/* Protected by kmmio_lock */
unsigned int kmmio_count;
/* Read-protected by RCU, write-protected by kmmio_lock. */
static struct list_head kmmio_page_table[KMMIO_PAGE_TABLE_SIZE];
static LIST_HEAD(kmmio_probes);
static struct list_head *kmmio_page_list(unsigned long addr)
{
unsigned int l;
pte_t *pte = lookup_address(addr, &l);
if (!pte)
return NULL;
addr &= page_level_mask(l);
return &kmmio_page_table[hash_long(addr, KMMIO_PAGE_HASH_BITS)];
}
/* Accessed per-cpu */
static DEFINE_PER_CPU(struct kmmio_context, kmmio_ctx);
/*
* this is basically a dynamic stabbing problem:
* Could use the existing prio tree code or
* Possible better implementations:
* The Interval Skip List: A Data Structure for Finding All Intervals That
* Overlap a Point (might be simple)
* Space Efficient Dynamic Stabbing with Fast Queries - Mikkel Thorup
*/
/* Get the kmmio at this addr (if any). You must be holding RCU read lock. */
static struct kmmio_probe *get_kmmio_probe(unsigned long addr)
{
struct kmmio_probe *p;
list_for_each_entry_rcu(p, &kmmio_probes, list) {
if (addr >= p->addr && addr < (p->addr + p->len))
return p;
}
return NULL;
}
/* You must be holding RCU read lock. */
static struct kmmio_fault_page *get_kmmio_fault_page(unsigned long addr)
{
struct list_head *head;
struct kmmio_fault_page *f;
unsigned int l;
pte_t *pte = lookup_address(addr, &l);
if (!pte)
return NULL;
Annotation
- Immediate include surface: `linux/list.h`, `linux/rculist.h`, `linux/spinlock.h`, `linux/hash.h`, `linux/export.h`, `linux/kernel.h`, `linux/uaccess.h`, `linux/ptrace.h`.
- Detected declarations: `struct kmmio_fault_page`, `struct kmmio_delayed_release`, `struct kmmio_context`, `function Point`, `function clear_pmd_presence`, `function clear_pte_presence`, `function clear_page_presence`, `function address`, `function disarm_kmmio_fault_page`, `function do_page_fault`.
- 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.