arch/x86/kvm/mmu/spte.h
Source file repositories/reference/linux-study-clean/arch/x86/kvm/mmu/spte.h
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kvm/mmu/spte.h- Extension
.h- Size
- 21550 bytes
- Lines
- 583
- 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
asm/vmx.hmmu.hmmu_internal.h
Detected Declarations
function is_frozen_sptefunction spte_indexfunction kvm_mmu_get_dummy_rootfunction kvm_mmu_is_dummy_rootfunction is_mirror_sptepfunction kvm_vcpu_can_access_host_mmiofunction is_mmio_sptefunction is_shadow_present_ptefunction is_ept_ve_possiblefunction sp_ad_disabledfunction spte_ad_enabledfunction spte_ad_need_write_protectfunction is_access_track_sptefunction is_large_ptefunction is_last_sptefunction is_executable_ptefunction spte_to_pfnfunction is_accessed_sptefunction get_rsvd_bitsfunction __is_rsvd_bits_setfunction __is_bad_mt_xwrfunction is_rsvd_sptefunction granularityfunction check_spte_writable_invariantsfunction is_mmu_writable_sptefunction is_access_allowedfunction loggingfunction get_mmio_spte_generationfunction restore_acc_track_spte
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
#ifndef KVM_X86_MMU_SPTE_H
#define KVM_X86_MMU_SPTE_H
#include <asm/vmx.h>
#include "mmu.h"
#include "mmu_internal.h"
/*
* A MMU present SPTE is backed by actual memory and may or may not be present
* in hardware. E.g. MMIO SPTEs are not considered present. Use bit 11, as it
* is ignored by all flavors of SPTEs and checking a low bit often generates
* better code than for a high bit, e.g. 56+. MMU present checks are pervasive
* enough that the improved code generation is noticeable in KVM's footprint.
*/
#define SPTE_MMU_PRESENT_MASK BIT_ULL(11)
/*
* The ignored high bits are allocated as follows:
* - bits 52, 54: saved X-R bits for access tracking when EPT does not have A/D
* - bits 53 (EPT only): host writable
* - bits 55 (EPT only): MMU-writable
* - bits 56-59: unused
* - bits 60-61: type of A/D tracking
* - bits 62 (EPT only): saved XU bit for disabled AD
*/
/*
* TDP SPTES (more specifically, EPT SPTEs) may not have A/D bits, and may also
* be restricted to using write-protection (for L2 when CPU dirty logging, i.e.
* PML, is enabled). Use bits 60 and 61 to hold the type of A/D tracking that
* is must be employed for a given TDP SPTE.
*
* Note, the "enabled" mask must be '0', as bits 62:52 are _reserved_ for PAE
* paging, including NPT PAE. This scheme works because legacy shadow paging
* is guaranteed to have A/D bits and write-protection is forced only for
* TDP with CPU dirty logging (PML). If NPT ever gains PML-like support, it
* must be restricted to 64-bit KVM.
*/
#define SPTE_TDP_AD_SHIFT 60
#define SPTE_TDP_AD_MASK (3ULL << SPTE_TDP_AD_SHIFT)
#define SPTE_TDP_AD_ENABLED (0ULL << SPTE_TDP_AD_SHIFT)
#define SPTE_TDP_AD_DISABLED (1ULL << SPTE_TDP_AD_SHIFT)
#define SPTE_TDP_AD_WRPROT_ONLY (2ULL << SPTE_TDP_AD_SHIFT)
static_assert(SPTE_TDP_AD_ENABLED == 0);
#ifdef CONFIG_DYNAMIC_PHYSICAL_MASK
#define SPTE_BASE_ADDR_MASK (physical_mask & ~(u64)(PAGE_SIZE-1))
#else
#define SPTE_BASE_ADDR_MASK (((1ULL << 52) - 1) & ~(u64)(PAGE_SIZE-1))
#endif
#define SPTE_LEVEL_BITS 9
#define SPTE_LEVEL_SHIFT(level) __PT_LEVEL_SHIFT(level, SPTE_LEVEL_BITS)
#define SPTE_INDEX(address, level) __PT_INDEX(address, level, SPTE_LEVEL_BITS)
#define SPTE_ENT_PER_PAGE __PT_ENT_PER_PAGE(SPTE_LEVEL_BITS)
/*
* The mask/shift to use for saving the original R/X bits when marking the PTE
* as not-present for access tracking purposes. We do not save the W bit as the
* PTEs being access tracked also need to be dirty tracked, so the W bit will be
* restored only when a write is attempted to the page. This mask obviously
* must not overlap the A/D type mask.
*/
#define SHADOW_ACC_TRACK_SAVED_BITS_MASK (VMX_EPT_READABLE_MASK | \
VMX_EPT_EXECUTABLE_MASK | \
VMX_EPT_USER_EXECUTABLE_MASK)
#define SHADOW_ACC_TRACK_SAVED_BITS_SHIFT 52
#define SHADOW_ACC_TRACK_SAVED_MASK (SHADOW_ACC_TRACK_SAVED_BITS_MASK << \
SHADOW_ACC_TRACK_SAVED_BITS_SHIFT)
static_assert(!(SPTE_TDP_AD_MASK & SHADOW_ACC_TRACK_SAVED_MASK));
/*
* {DEFAULT,EPT}_SPTE_{HOST,MMU}_WRITABLE are used to keep track of why a given
* SPTE is write-protected. See is_writable_pte() for details.
*/
/* Bits 9 and 10 are ignored by all non-EPT PTEs. */
#define DEFAULT_SPTE_HOST_WRITABLE BIT_ULL(9)
#define DEFAULT_SPTE_MMU_WRITABLE BIT_ULL(10)
/*
* Low ignored bits are at a premium for EPT, use high ignored bits, taking care
* to not overlap the A/D type mask or the saved access bits of access-tracked
* SPTEs when A/D bits are disabled.
*/
#define EPT_SPTE_HOST_WRITABLE BIT_ULL(53)
#define EPT_SPTE_MMU_WRITABLE BIT_ULL(55)
Annotation
- Immediate include surface: `asm/vmx.h`, `mmu.h`, `mmu_internal.h`.
- Detected declarations: `function is_frozen_spte`, `function spte_index`, `function kvm_mmu_get_dummy_root`, `function kvm_mmu_is_dummy_root`, `function is_mirror_sptep`, `function kvm_vcpu_can_access_host_mmio`, `function is_mmio_spte`, `function is_shadow_present_pte`, `function is_ept_ve_possible`, `function sp_ad_disabled`.
- 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.