arch/x86/kvm/mmu/mmu.c
Source file repositories/reference/linux-study-clean/arch/x86/kvm/mmu/mmu.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kvm/mmu/mmu.c- Extension
.c- Size
- 238526 bytes
- Lines
- 8205
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
irq.hioapic.hmmu.hmmu_internal.htdp_mmu.hx86.hregs.hsmm.hkvm_emulate.hpage_track.hcpuid.hspte.hlinux/kvm_host.hlinux/types.hlinux/string.hlinux/mm.hlinux/highmem.hlinux/moduleparam.hlinux/export.hlinux/swap.hlinux/hugetlb.hlinux/compiler.hlinux/srcu.hlinux/slab.hlinux/sched/signal.hlinux/uaccess.hlinux/hash.hlinux/kern_levels.hlinux/kstrtox.hlinux/kthread.hlinux/wordpart.hasm/page.h
Detected Declarations
struct pte_list_descstruct kvm_shadow_walk_iteratorstruct kvm_mmu_role_regsstruct rmap_iteratorstruct slot_rmap_walk_iteratorstruct kvm_mmu_pagesstruct mmu_page_and_offsetstruct mmu_page_pathstruct shadow_page_cachesfunction has_pferr_fetchfunction is_cr0_pgfunction is_cr4_paefunction vcpu_to_role_regsfunction get_guest_cr3function kvm_mmu_get_guest_pgdfunction kvm_available_flush_remote_tlbs_rangefunction kvm_flush_remote_tlbs_sptepfunction mark_mmio_sptefunction get_mmio_spte_gfnfunction get_mmio_spte_accessfunction check_mmio_sptefunction is_cpuid_PSE36function __set_sptefunction __update_clear_spte_fastfunction __update_clear_spte_slowfunction __get_spte_locklessfunction count_spte_clearfunction __set_sptefunction __update_clear_spte_fastfunction __update_clear_spte_slowfunction gup_get_ptefunction mmu_spte_setfunction mmu_spte_updatefunction mmu_spte_clear_track_bitsfunction mmu_spte_clear_no_trackfunction mmu_spte_get_locklessfunction is_tdp_mmu_activefunction walk_shadow_page_lockless_beginfunction walk_shadow_page_lockless_endfunction mmu_topup_memory_cachesfunction mmu_free_memory_cachesfunction mmu_free_pte_list_descfunction kvm_mmu_page_get_gfnfunction kvm_mmu_page_get_accessfunction kvm_mmu_page_set_translationfunction kvm_mmu_page_set_accessfunction update_gfn_disallow_lpage_countfunction kvm_mmu_gfn_disallow_lpage
Annotated Snippet
struct pte_list_desc {
struct pte_list_desc *more;
/* The number of PTEs stored in _this_ descriptor. */
u32 spte_count;
/* The number of PTEs stored in all tails of this descriptor. */
u32 tail_count;
u64 *sptes[PTE_LIST_EXT];
};
struct kvm_shadow_walk_iterator {
u64 addr;
hpa_t shadow_addr;
u64 *sptep;
int level;
unsigned index;
};
#define for_each_shadow_entry_using_root(_vcpu, _root, _addr, _walker) \
for (shadow_walk_init_using_root(&(_walker), (_vcpu), \
(_root), (_addr)); \
shadow_walk_okay(&(_walker)); \
shadow_walk_next(&(_walker)))
#define for_each_shadow_entry(_vcpu, _addr, _walker) \
for (shadow_walk_init(&(_walker), _vcpu, _addr); \
shadow_walk_okay(&(_walker)); \
shadow_walk_next(&(_walker)))
#define for_each_shadow_entry_lockless(_vcpu, _addr, _walker, spte) \
for (shadow_walk_init(&(_walker), _vcpu, _addr); \
shadow_walk_okay(&(_walker)) && \
({ spte = mmu_spte_get_lockless(_walker.sptep); 1; }); \
__shadow_walk_next(&(_walker), spte))
static struct kmem_cache *pte_list_desc_cache;
struct kmem_cache *mmu_page_header_cache;
static void mmu_spte_set(u64 *sptep, u64 spte);
static int mmu_page_zap_pte(struct kvm *kvm, struct kvm_mmu_page *sp,
u64 *spte, struct list_head *invalid_list);
struct kvm_mmu_role_regs {
const unsigned long cr0;
const unsigned long cr4;
const u64 efer;
};
#define CREATE_TRACE_POINTS
#include "mmutrace.h"
/*
* Yes, lot's of underscores. They're a hint that you probably shouldn't be
* reading from the role_regs. Once the root_role is constructed, it becomes
* the single source of truth for the MMU's state.
*/
#define BUILD_MMU_ROLE_REGS_ACCESSOR(reg, name, flag) \
static inline bool __maybe_unused \
____is_##reg##_##name(const struct kvm_mmu_role_regs *regs) \
{ \
return !!(regs->reg & flag); \
}
BUILD_MMU_ROLE_REGS_ACCESSOR(cr0, pg, X86_CR0_PG);
BUILD_MMU_ROLE_REGS_ACCESSOR(cr0, wp, X86_CR0_WP);
BUILD_MMU_ROLE_REGS_ACCESSOR(cr4, pse, X86_CR4_PSE);
BUILD_MMU_ROLE_REGS_ACCESSOR(cr4, pae, X86_CR4_PAE);
BUILD_MMU_ROLE_REGS_ACCESSOR(cr4, smep, X86_CR4_SMEP);
BUILD_MMU_ROLE_REGS_ACCESSOR(cr4, smap, X86_CR4_SMAP);
BUILD_MMU_ROLE_REGS_ACCESSOR(cr4, pke, X86_CR4_PKE);
BUILD_MMU_ROLE_REGS_ACCESSOR(cr4, la57, X86_CR4_LA57);
BUILD_MMU_ROLE_REGS_ACCESSOR(efer, nx, EFER_NX);
BUILD_MMU_ROLE_REGS_ACCESSOR(efer, lma, EFER_LMA);
/*
* The MMU itself (with a valid role) is the single source of truth for the
* MMU. Do not use the regs used to build the MMU/role, nor the vCPU. The
* regs don't account for dependencies, e.g. clearing CR4 bits if CR0.PG=1,
* and the vCPU may be incorrect/irrelevant.
*/
#define BUILD_MMU_ROLE_ACCESSOR(base_or_ext, reg, name) \
static inline bool __maybe_unused is_##reg##_##name(struct kvm_mmu *mmu) \
{ \
return !!(mmu->cpu_role. base_or_ext . reg##_##name); \
}
BUILD_MMU_ROLE_ACCESSOR(base, cr0, wp);
BUILD_MMU_ROLE_ACCESSOR(ext, cr4, pse);
BUILD_MMU_ROLE_ACCESSOR(base, cr4, smep);
BUILD_MMU_ROLE_ACCESSOR(ext, cr4, smap);
BUILD_MMU_ROLE_ACCESSOR(ext, cr4, pke);
BUILD_MMU_ROLE_ACCESSOR(ext, cr4, la57);
BUILD_MMU_ROLE_ACCESSOR(base, efer, nx);
Annotation
- Immediate include surface: `irq.h`, `ioapic.h`, `mmu.h`, `mmu_internal.h`, `tdp_mmu.h`, `x86.h`, `regs.h`, `smm.h`.
- Detected declarations: `struct pte_list_desc`, `struct kvm_shadow_walk_iterator`, `struct kvm_mmu_role_regs`, `struct rmap_iterator`, `struct slot_rmap_walk_iterator`, `struct kvm_mmu_pages`, `struct mmu_page_and_offset`, `struct mmu_page_path`, `struct shadow_page_caches`, `function has_pferr_fetch`.
- 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.